From 1d86b844df9408efdf198c1bf230c717f07f195e Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Thu, 30 Nov 2023 16:05:51 +0800 Subject: [PATCH 1/5] CMake: Build libharfbuzz-cairo and fix hb-view build There is now a separate library that we build if Cairo support is enabled, which will also be used to build hb-view, so we: * Add support in the CMake build files to build libharfbuzz-cairo, if enabled via HB_HAVE_CAIRO. Move the Cairo detection bits around as a result. * Generate pkg-config file for libharfbuzz-cairo, and add 'cairo' to Requires.private. * Fix building hb-view, which will now depend on libharfbuzz-cairo, so Cairo support must be explicitly enabled. * Stop depending automatically on Cairo if HB_BUILD_UTILS is enabled unless Cairo support is enabled as a result. --- CMakeLists.txt | 63 ++++++++++++++++++++++++++++++---------- src/harfbuzz-cairo.pc.in | 1 + 2 files changed, 49 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e22f2cfdd..237cce7d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,7 @@ endif () ## HarfBuzz build configurations +option(HB_HAVE_CAIRO "Enable cairo interop helpers" OFF) option(HB_HAVE_FREETYPE "Enable freetype interop helpers" OFF) option(HB_HAVE_GRAPHITE2 "Enable Graphite2 complementary shaper" OFF) option(HB_HAVE_GLIB "Enable glib unicode functions" OFF) @@ -340,6 +341,23 @@ if (WIN32 AND HB_HAVE_DIRECTWRITE) list(APPEND project_headers ${PROJECT_SOURCE_DIR}/src/hb-directwrite.h) endif () +if (HB_HAVE_CAIRO) + # https://github.com/WebKit/webkit/blob/master/Source/cmake/FindCairo.cmake + find_package(PkgConfig) + pkg_check_modules(PC_CAIRO QUIET cairo) + + find_path(CAIRO_INCLUDE_DIRS NAMES cairo.h HINTS ${PC_CAIRO_INCLUDEDIR} ${PC_CAIRO_INCLUDE_DIRS} PATH_SUFFIXES cairo) + find_library(CAIRO_LIBRARIESNAMES cairo HINTS ${PC_CAIRO_LIBDIR} ${PC_CAIRO_LIBRARY_DIRS}) + if (NOT CAIRO_LIBRARIESNAMES) + message(FATAL_ERROR "HB_HAVE_CAIRO is ON but Cairo libraries are not found") + endif() + include_directories(${CAIRO_INCLUDE_DIRS}) + mark_as_advanced(CAIRO_INCLUDE_DIRS CAIRO_LIBRARIESNAMES) + add_definitions(-DHAVE_CAIRO=1) + list(APPEND project_headers ${PROJECT_SOURCE_DIR}/src/hb-cairo.h) + list(APPEND THIRD_PARTY_LIBS ${CAIRO_LIBRARIESNAMES}) +endif() + if (HB_HAVE_GOBJECT) add_definitions(-DHAVE_GOBJECT) include (FindPerl) @@ -531,6 +549,18 @@ if (HB_HAVE_GOBJECT) endif () endif () +## Define harfbuzz-cairo library +if (HB_HAVE_CAIRO) + include_directories(${CAIRO_INCLUDE_DIRS}) + add_library(harfbuzz-cairo ${PROJECT_SOURCE_DIR}/src/hb-cairo.cc ${PROJECT_SOURCE_DIR}/src/hb-static.cc ${PROJECT_SOURCE_DIR}/src/hb-cairo.h) + add_dependencies(harfbuzz-cairo harfbuzz) + target_link_libraries(harfbuzz-cairo harfbuzz ${THIRD_PARTY_LIBS}) + + if (BUILD_SHARED_LIBS) + set_target_properties(harfbuzz-cairo PROPERTIES VISIBILITY_INLINES_HIDDEN TRUE) + endif () +endif() + if (BUILD_SHARED_LIBS AND WIN32 AND NOT MINGW) add_definitions("-DHB_DLL_EXPORT") endif () @@ -683,19 +713,13 @@ endif () ## Additional harfbuzz build artifacts if (HB_BUILD_UTILS) - # https://github.com/WebKit/webkit/blob/master/Source/cmake/FindCairo.cmake - find_package(PkgConfig) - pkg_check_modules(PC_CAIRO QUIET cairo) - - find_path(CAIRO_INCLUDE_DIRS NAMES cairo.h HINTS ${PC_CAIRO_INCLUDEDIR} ${PC_CAIRO_INCLUDE_DIRS} PATH_SUFFIXES cairo) - find_library(CAIRO_LIBRARIESNAMES cairo HINTS ${PC_CAIRO_LIBDIR} ${PC_CAIRO_LIBRARY_DIRS}) - add_definitions("-DPACKAGE_NAME=\"HarfBuzz\"") add_definitions("-DPACKAGE_VERSION=\"${HB_VERSION}\"") - include_directories(${CAIRO_INCLUDE_DIRS}) - add_executable(hb-view ${HB_VIEW_sources}) - target_link_libraries(hb-view harfbuzz ${CAIRO_LIBRARIESNAMES}) + if (HB_HAVE_CAIRO) + add_executable(hb-view ${HB_VIEW_sources}) + target_link_libraries(hb-view harfbuzz-cairo harfbuzz ${CAIRO_LIBRARIESNAMES}) + endif() add_executable(hb-shape ${HB_SHAPE_sources}) target_link_libraries(hb-shape harfbuzz) @@ -705,8 +729,6 @@ if (HB_BUILD_UTILS) add_executable(hb-ot-shape-closure ${HB_OT_SHAPE_CLOSURE_sources}) target_link_libraries(hb-ot-shape-closure harfbuzz) - - mark_as_advanced(CAIRO_INCLUDE_DIRS CAIRO_LIBRARIESNAMES) endif () @@ -780,6 +802,15 @@ if (NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL) ) make_pkgconfig_pc_file("harfbuzz-icu") endif () + if (HB_HAVE_CAIRO) + install(TARGETS harfbuzz-cairo + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + FRAMEWORK DESTINATION Library/Frameworks + ) + make_pkgconfig_pc_file("harfbuzz-cairo") + endif () if (HB_BUILD_SUBSET) install(TARGETS harfbuzz-subset ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} @@ -792,9 +823,11 @@ if (NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL) RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) endif () - install(TARGETS hb-view - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - ) + if (HB_HAVE_CAIRO) + install(TARGETS hb-view + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + ) + endif() install(TARGETS hb-subset RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) diff --git a/src/harfbuzz-cairo.pc.in b/src/harfbuzz-cairo.pc.in index df97ff151..06ba8047c 100644 --- a/src/harfbuzz-cairo.pc.in +++ b/src/harfbuzz-cairo.pc.in @@ -8,5 +8,6 @@ Description: HarfBuzz cairo integration Version: %VERSION% Requires: harfbuzz = %VERSION% +Requires.private: cairo Libs: -L${libdir} -lharfbuzz-cairo Cflags: -I${includedir}/harfbuzz From d112ed40fcd0eb75ae68f05a0775e6426ebf4104 Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Thu, 30 Nov 2023 16:14:19 +0800 Subject: [PATCH 2/5] CMake: Install hb-subset-repacker.h It ought to be installed. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 237cce7d6..a3ffb6b91 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -490,7 +490,7 @@ endif () ## Define harfbuzz-subset library if (HB_BUILD_SUBSET) add_library(harfbuzz-subset ${subset_project_sources} ${subset_project_headers}) - list(APPEND project_headers ${PROJECT_SOURCE_DIR}/src/hb-subset.h) + list(APPEND project_headers ${PROJECT_SOURCE_DIR}/src/hb-subset.h ${PROJECT_SOURCE_DIR}/src/hb-subset-repacker.h) add_dependencies(harfbuzz-subset harfbuzz) target_link_libraries(harfbuzz-subset harfbuzz ${THIRD_PARTY_LIBS}) From 86fd6b10c48a1b635067ee0cc35e253bda0bcf0f Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Thu, 30 Nov 2023 16:39:10 +0800 Subject: [PATCH 3/5] CMake: Build the hb-info utility program ...if GObject support is enabled. --- CMakeLists.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index a3ffb6b91..1abffbc44 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -178,6 +178,8 @@ extract_make_variable(HB_SUBSET_CLI_sources ${UTILSOURCES}) add_prefix_to_list(HB_SUBSET_CLI_sources "${PROJECT_SOURCE_DIR}/util/") extract_make_variable(HB_OT_SHAPE_CLOSURE_sources ${UTILSOURCES}) add_prefix_to_list(HB_OT_SHAPE_CLOSURE_sources "${PROJECT_SOURCE_DIR}/util/") +extract_make_variable(HB_INFO_sources ${UTILSOURCES}) +add_prefix_to_list(HB_INFO_sources "${PROJECT_SOURCE_DIR}/util/") file(READ configure.ac CONFIGUREAC) @@ -729,6 +731,11 @@ if (HB_BUILD_UTILS) add_executable(hb-ot-shape-closure ${HB_OT_SHAPE_CLOSURE_sources}) target_link_libraries(hb-ot-shape-closure harfbuzz) + + if (HB_HAVE_GOBJECT) + add_executable(hb-info ${HB_INFO_sources}) + target_link_libraries(hb-info harfbuzz-gobject harfbuzz) + endif() endif () @@ -836,6 +843,12 @@ if (NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL) RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) + if (HB_HAVE_GOBJECT) + install(TARGETS hb-info + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + ) + endif() + install(TARGETS hb-ot-shape-closure RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) From ea526c3dcbf66955aba701d2e34bd2ec5782402e Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Thu, 30 Nov 2023 17:35:04 +0800 Subject: [PATCH 4/5] CMake: Generate and install hb-features.h By the features that are enabled for the build. The header is installed unless one chooses not to install it --- CMakeLists.txt | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1abffbc44..80ef66877 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -787,6 +787,28 @@ macro ( make_pkgconfig_pc_file name ) ) endmacro ( make_pkgconfig_pc_file ) +# Generate hb-features.h with the features we enabled +macro (make_hb_features_h) + file(READ "${PROJECT_SOURCE_DIR}/src/hb-features.h.in" feature_h_in) + foreach(arg cairo coretext directwrite freetype gdi glib gobject graphite icu uniscribe wasm) + string(TOUPPER ${arg} feature_caps) + set(feature_instring "#mesondefine HB_HAS_${feature_caps}") + if (HB_HAVE_${feature_caps}) + set(feature_outstring "#define HB_HAS_${feature_caps} 1") + else () + set(feature_outstring "/* #undef HB_HAS_${feature_caps} */") + endif() + string(REPLACE ${feature_instring} ${feature_outstring} feature_h_in ${feature_h_in}) + endforeach() + file(WRITE "${PROJECT_BINARY_DIR}/src/hb-features.h" ${feature_h_in}) + if (NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL) + install( + FILES "${PROJECT_BINARY_DIR}/src/hb-features.h" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/harfbuzz" + ) + endif() +endmacro (make_hb_features_h) + if (NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL) install(TARGETS harfbuzz EXPORT harfbuzzConfig @@ -876,4 +898,5 @@ if (NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL) ) endif () endif () + make_hb_features_h() endif () From 5e9710ffc0c6bd1975107c498ea81662cc2f7fb4 Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Thu, 30 Nov 2023 17:42:46 +0800 Subject: [PATCH 5/5] CMake: Update introspection cflags Make the flags between --cflags-[begin|end] correspond to the ones used in the Meson builds better. --- CMakeLists.txt | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 80ef66877..8d6deef30 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -667,14 +667,8 @@ if (HB_HAVE_INTROSPECTION) -I${PROJECT_BINARY_DIR}/src ${hb_includedir_cflags} ${hb_defines_cflags} - -DHB_H - -DHB_H_IN - -DHB_OT_H - -DHB_OT_H_IN - -DHB_AAT_H - -DHB_AAT_H_IN - -DHB_GOBJECT_H - -DHB_GOBJECT_H_IN + -DHB_NO_SINGLE_HEADER_ERROR + -DHB_HAVE_GOBJECT -DHB_EXTERN= --cflags-end --library=harfbuzz-gobject