Allow building with C++17 and updated libxml++/pangomm/cairomm.
authorCarl Hetherington <cth@carlh.net>
Thu, 22 Feb 2024 21:51:44 +0000 (22:51 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 20 Mar 2024 17:25:09 +0000 (18:25 +0100)
hacks/text.cc
platform/osx/make_dmg.sh
src/lib/render_text.cc
test/film_metadata_test.cc
test/test.cc
test/test.h
wscript

index bf391a32548b1b76c4d5da38e493a090275c4895..ff5d6f8b8ff5f581b3cfa445bfcffa8ec6c6c2c3 100644 (file)
@@ -19,10 +19,10 @@ int main ()
 
        Cairo::RefPtr<Cairo::ImageSurface> surface = Cairo::ImageSurface::create (
                data,
-               Cairo::FORMAT_ARGB32,
+               Cairo::ImageSurface::Format::ARGB32,
                width, height,
                /* Cairo ARGB32 means first byte blue, second byte green, third byte red, fourth byte alpha */
-               Cairo::ImageSurface::format_stride_for_width (Cairo::FORMAT_ARGB32, width)
+               Cairo::ImageSurface::format_stride_for_width(Cairo::ImageSurface::Format::ARGB32, width)
                );
 
        Cairo::RefPtr<Cairo::Context> context = Cairo::Context::create (surface);
@@ -33,7 +33,7 @@ int main ()
        context->rectangle (0, 0, width, height);
        context->fill ();
 
-       layout->set_alignment (Pango::ALIGN_LEFT);
+       layout->set_alignment (Pango::Alignment::LEFT);
 
        context->set_line_width (1);
        // Cairo::FontOptions fo;
index 161261faae0241ada24235adf5289d5c2daddfb2..9f9cbdd37417f01d02b138497cf691bbd6af67e6 100644 (file)
@@ -168,7 +168,7 @@ function copy_libs {
     copy_lib_env libxml++ "$dest"
     copy_lib_env libxslt "$dest"
     copy_lib_env libxml2 "$dest"
-    copy_lib_env libglibmm-2.4 "$dest"
+    copy_lib_env libglibmm "$dest"
     copy_lib_env libgobject "$dest"
     copy_lib_env libgthread "$dest"
     copy_lib_env libgmodule "$dest"
index 870f3045d31340fb692c98cb65d8c858d6c4b38f..9f1f69edb248be30adc33d396861a92df27f18c7 100644 (file)
@@ -51,6 +51,15 @@ using boost::optional;
 using namespace dcpomatic;
 
 
+#if CAIROMM_MAJOR_VERSION == 1 && CAIROMM_MINOR_VERSION <= 14
+#define DCPOMATIC_OLD_CAIROMM_API
+#endif
+
+#if PANGOMM_MAJOR_VERSION == 2 && PANGOMM_MINOR_VERSION <= 46
+#define DCPOMATIC_OLD_PANGOMM_API
+#endif
+
+
 /** Create a Pango layout using a dummy context which we can use to calculate the size
  *  of the text we will render.  Then we can transfer the layout over to the real context
  *  for the actual render.
@@ -66,7 +75,11 @@ create_layout(string font_name, string markup)
        auto context = Glib::wrap (c_context);
        auto layout = Pango::Layout::create(context);
 
-       layout->set_alignment (Pango::ALIGN_LEFT);
+#ifdef DCPOMATIC_OLD_PANGOMM_API
+       layout->set_alignment(Pango::ALIGN_LEFT);
+#else
+       layout->set_alignment(Pango::Alignment::LEFT);
+#endif
        Pango::FontDescription font (font_name);
        layout->set_font_description (font);
        layout->set_markup (markup);
@@ -163,11 +176,22 @@ create_surface (shared_ptr<Image> image)
        DCPOMATIC_ASSERT (image->pixel_format() == AV_PIX_FMT_BGRA);
        return Cairo::ImageSurface::create (
                image->data()[0],
+#ifdef DCPOMATIC_OLD_CAIROMM_API
                Cairo::FORMAT_ARGB32,
+#else
+               Cairo::ImageSurface::Format::ARGB32,
+#endif
                image->size().width,
                image->size().height,
                /* Cairo ARGB32 means first byte blue, second byte green, third byte red, fourth byte alpha */
-               Cairo::ImageSurface::format_stride_for_width (Cairo::FORMAT_ARGB32, image->size().width)
+               Cairo::ImageSurface::format_stride_for_width(
+#ifdef DCPOMATIC_OLD_CAIROMM_API
+                       Cairo::FORMAT_ARGB32,
+#else
+                       Cairo::ImageSurface::Format::ARGB32,
+#endif
+                       image->size().width
+                       )
                );
 }
 
@@ -394,7 +418,11 @@ render_line(vector<StringText> subtitles, dcp::Size target, DCPTime time, int fr
                /* Border effect */
                set_source_rgba (context, first.effect_colour(), fade_factor);
                context->set_line_width (border_width);
+#ifdef DCPOMATIC_OLD_CAIROMM_API
                context->set_line_join (Cairo::LINE_JOIN_ROUND);
+#else
+               context->set_line_join (Cairo::Context::LineJoin::ROUND);
+#endif
                context->move_to (x_offset, y_offset);
                layout.pango->add_to_cairo_context (context);
                context->stroke ();
index 878e6025422208c851e530953c41dc090d7b1925..2bd60dc81071e0b2180d66060c0f0cab40b8be45 100644 (file)
@@ -66,7 +66,7 @@ BOOST_AUTO_TEST_CASE (film_metadata_test)
        film->set_audio_channels(6);
        film->write_metadata ();
 
-       list<string> ignore = { "Key", "ContextID", "LastWrittenBy" };
+       list<Glib::ustring> ignore = { "Key", "ContextID", "LastWrittenBy" };
        check_xml ("test/data/metadata.xml.ref", dir.string() + "/metadata.xml", ignore);
 
        auto g = make_shared<Film>(dir);
index 57f4ae203afdf7574bae7fb7bb43c08928a9b249..9ab7fe4804b0a146880413707efa0c13373038ca 100644 (file)
@@ -584,7 +584,7 @@ check_dcp(boost::filesystem::path ref, boost::filesystem::path check, bool sound
 }
 
 void
-check_xml (xmlpp::Element* ref, xmlpp::Element* test, list<string> ignore)
+check_xml(xmlpp::Element* ref, xmlpp::Element* test, list<Glib::ustring> ignore)
 {
        BOOST_CHECK_EQUAL (ref->get_name (), test->get_name ());
        BOOST_CHECK_EQUAL (ref->get_namespace_prefix (), test->get_namespace_prefix ());
@@ -640,7 +640,7 @@ check_xml (xmlpp::Element* ref, xmlpp::Element* test, list<string> ignore)
 }
 
 void
-check_xml (boost::filesystem::path ref, boost::filesystem::path test, list<string> ignore)
+check_xml(boost::filesystem::path ref, boost::filesystem::path test, list<Glib::ustring> ignore)
 {
        auto ref_parser = new xmlpp::DomParser(ref.string());
        auto ref_root = ref_parser->get_document()->get_root_node();
index 6687affea6b41c1624db524e555589c58dc95f23..0776d6e5ae963436b6a577b2b979f11590b11606 100644 (file)
@@ -22,6 +22,7 @@
 #include "lib/video_frame_type.h"
 #include <dcp/types.h>
 #include <dcp/verify.h>
+#include <glibmm.h>
 #include <boost/filesystem.hpp>
 #include <vector>
 
@@ -66,7 +67,7 @@ extern void check_text_file (boost::filesystem::path ref, boost::filesystem::pat
 extern void check_wav_file (boost::filesystem::path ref, boost::filesystem::path check);
 extern void check_mxf_audio_file (boost::filesystem::path ref, boost::filesystem::path check);
 extern bool mxf_atmos_files_same (boost::filesystem::path ref, boost::filesystem::path check, bool verbose = false);
-extern void check_xml (boost::filesystem::path, boost::filesystem::path, std::list<std::string>);
+extern void check_xml(boost::filesystem::path, boost::filesystem::path, std::list<Glib::ustring>);
 extern void check_ffmpeg (boost::filesystem::path, boost::filesystem::path, int audio_tolerance);
 extern void check_image (boost::filesystem::path, boost::filesystem::path, double threshold = 4);
 extern boost::filesystem::path test_film_dir (std::string);
diff --git a/wscript b/wscript
index 6dd7417cda41fefa7cd0b76389a0f829820f7523..96d3c030c9302808084324b81f0bfee462c21c81 100644 (file)
--- a/wscript
+++ b/wscript
@@ -81,6 +81,7 @@ def options(opt):
     opt.add_option('--wx-config',         help='path to wx-config')
     opt.add_option('--enable-asan',       action='store_true', help='build with asan')
     opt.add_option('--disable-more-warnings', action='store_true', default=False, help='disable some warnings raised by Xcode 15 with the 2.16 branch')
+    opt.add_option('--c++17', action='store_true', default=False, help='build with C++17 and libxml++-4.0')
 
 def configure(conf):
     conf.load('compiler_cxx')
@@ -88,6 +89,17 @@ def configure(conf):
     if conf.options.target_windows_64 or conf.options.target_windows_32:
         conf.load('winres')
 
+    if vars(conf.options)['c++17']:
+        cpp_std = '17'
+        conf.env.XMLPP_API = '4.0'
+        conf.env.PANGOMM_API = '2.48'
+        conf.env.CAIROMM_API = '1.16'
+    else:
+        cpp_std = '11'
+        conf.env.XMLPP_API = '2.6'
+        conf.env.PANGOMM_API = '1.4'
+        conf.env.CAIROMM_API = '1.0'
+
     # Save conf.options that we need elsewhere in conf.env
     conf.env.DISABLE_GUI = conf.options.disable_gui
     conf.env.DISABLE_TESTS = conf.options.disable_tests
@@ -119,7 +131,7 @@ def configure(conf):
                                        # I tried and failed to ignore these with _Pragma
                                        '-Wno-ignored-qualifiers',
                                        '-D_FILE_OFFSET_BITS=64',
-                                       '-std=c++11'])
+                                       '-std=c++' + cpp_std])
 
     if conf.options.disable_more_warnings:
         # These are for Xcode 15.0.1 with the v2.16.x-era
@@ -328,10 +340,10 @@ def configure(conf):
     conf.check_cfg(package='fontconfig', args='--cflags --libs', uselib_store='FONTCONFIG', mandatory=True)
 
     # pangomm
-    conf.check_cfg(package='pangomm-1.4', args='--cflags --libs', uselib_store='PANGOMM', mandatory=True)
+    conf.check_cfg(package='pangomm-' + conf.env.PANGOMM_API, args='--cflags --libs', uselib_store='PANGOMM', mandatory=True)
 
     # cairomm
-    conf.check_cfg(package='cairomm-1.0', args='--cflags --libs', uselib_store='CAIROMM', mandatory=True)
+    conf.check_cfg(package='cairomm-' + conf.env.CAIROMM_API, args='--cflags --libs', uselib_store='CAIROMM', mandatory=True)
 
     # leqm_nrt
     conf.check_cfg(package='leqm_nrt', args='--cflags --libs', uselib_store='LEQM_NRT', mandatory=True)
@@ -382,10 +394,10 @@ def configure(conf):
 
     # libxml++
     if conf.options.static_xmlpp:
-        conf.env.STLIB_XMLPP = ['xml++-2.6']
+        conf.env.STLIB_XMLPP = ['xml++-' + conf.env.XMLPP_API]
         conf.env.LIB_XMLPP = ['xml2']
     else:
-        conf.check_cfg(package='libxml++-2.6', args='--cflags --libs', uselib_store='XMLPP', mandatory=True)
+        conf.check_cfg(package='libxml++-' + conf.env.XMLPP_API, args='--cflags --libs', uselib_store='XMLPP', mandatory=True)
 
     # libxmlsec
     if conf.options.static_xmlsec: