From a120b01ab3894ca14f8b069c1505d0cca8b31e5c Mon Sep 17 00:00:00 2001 From: Ankith <46915066+ankith26@users.noreply.github.com> Date: Tue, 6 Sep 2022 15:32:04 +0530 Subject: [PATCH] [cmake] Generate pkg-config .pc files --- CMakeLists.txt | 65 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d4759ce13..97980ef59 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.12) project(harfbuzz) message(WARN "HarfBuzz has a Meson port and tries to migrate all the other build systems to it, please consider using it as we might remove our cmake port soon.") @@ -107,12 +107,17 @@ if (${HAVE_STDBOOL_H}) add_definitions(-DHAVE_STDBOOL_H) endif () +# These will be used while making pkg-config .pc files +set(PC_REQUIRES_PRIV "") +set(PC_LIBS_PRIV "") + if (NOT MSVC) set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads) if (CMAKE_USE_PTHREADS_INIT) add_definitions("-DHAVE_PTHREAD") list(APPEND THIRD_PARTY_LIBS Threads::Threads) + list(APPEND PC_LIBS_PRIV -pthread) endif () endif () @@ -208,6 +213,10 @@ if (HB_HAVE_FREETYPE AND NOT TARGET freetype) check_funcs(FT_Get_Var_Blend_Coordinates FT_Set_Var_Blend_Coordinates FT_Done_MM_Var) endif () +if (HB_HAVE_FREETYPE) + list(APPEND PC_REQUIRES_PRIV "freetype2 >= 12.0.6") +endif () + if (HB_HAVE_GRAPHITE2) add_definitions(-DHAVE_GRAPHITE2) @@ -220,6 +229,8 @@ if (HB_HAVE_GRAPHITE2) list(APPEND THIRD_PARTY_LIBS ${GRAPHITE2_LIBRARY}) + list(APPEND PC_REQUIRES_PRIV "graphite2 >= 1.2.0") + mark_as_advanced(GRAPHITE2_INCLUDE_DIR GRAPHITE2_LIBRARY) endif () @@ -240,6 +251,8 @@ if (HB_HAVE_GLIB) list(APPEND THIRD_PARTY_LIBS ${GLIB_LIBRARIES}) + list(APPEND PC_REQUIRES_PRIV "glib-2.0 >= 2.19.1") + mark_as_advanced(GLIB_LIBRARIES GLIBCONFIG_INCLUDE_DIR GLIB_INCLUDE_DIR) endif () @@ -272,24 +285,28 @@ if (APPLE AND HB_HAVE_CORETEXT) find_library(COREFOUNDATION CoreFoundation) if (COREFOUNDATION) list(APPEND THIRD_PARTY_LIBS ${COREFOUNDATION}) + list(APPEND PC_LIBS_PRIV "-framework CoreFoundation") endif () mark_as_advanced(COREFOUNDATION) find_library(CORETEXT CoreText) if (CORETEXT) list(APPEND THIRD_PARTY_LIBS ${CORETEXT}) + list(APPEND PC_LIBS_PRIV "-framework CoreText") endif () mark_as_advanced(CORETEXT) find_library(COREGRAPHICS CoreGraphics) if (COREGRAPHICS) list(APPEND THIRD_PARTY_LIBS ${COREGRAPHICS}) + list(APPEND PC_LIBS_PRIV "-framework CoreGraphics") endif () mark_as_advanced(COREGRAPHICS) else () find_library(APPLICATION_SERVICES_FRAMEWORK ApplicationServices) if (APPLICATION_SERVICES_FRAMEWORK) list(APPEND THIRD_PARTY_LIBS ${APPLICATION_SERVICES_FRAMEWORK}) + list(APPEND PC_LIBS_PRIV "-framework ApplicationServices") endif () mark_as_advanced(APPLICATION_SERVICES_FRAMEWORK) @@ -300,12 +317,14 @@ if (WIN32 AND HB_HAVE_GDI) add_definitions(-DHAVE_GDI) list(APPEND project_headers ${PROJECT_SOURCE_DIR}/src/hb-gdi.h) list(APPEND THIRD_PARTY_LIBS gdi32) + list(APPEND PC_LIBS_PRIV -lgdi32) endif () if (WIN32 AND HB_HAVE_UNISCRIBE) add_definitions(-DHAVE_UNISCRIBE) list(APPEND project_headers ${PROJECT_SOURCE_DIR}/src/hb-uniscribe.h) list(APPEND THIRD_PARTY_LIBS usp10 gdi32 rpcrt4) + list(APPEND PC_LIBS_PRIV -lusp10 -lgdi32 -lrpcrt4) endif () if (WIN32 AND HB_HAVE_DIRECTWRITE) @@ -701,6 +720,44 @@ if (NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL) endif () endif () +# get these variables in the required format +list(REMOVE_DUPLICATES PC_REQUIRES_PRIV) +string(REPLACE ";" ", " PC_REQUIRES_PRIV "${PC_REQUIRES_PRIV}") +list(REMOVE_DUPLICATES PC_LIBS_PRIV) +string(REPLACE ";" " " PC_LIBS_PRIV "${PC_LIBS_PRIV}") + +# Macro to write pkg-config .pc configuration files +macro ( make_pkgconfig_pc_file name ) + file(READ "${PROJECT_SOURCE_DIR}/src/${name}.pc.in" FSTR) + + string(REPLACE "%prefix%" "${CMAKE_INSTALL_PREFIX}" FSTR ${FSTR}) + string(REPLACE "%exec_prefix%" "\${prefix}" FSTR ${FSTR}) + + if (IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}") + string(REPLACE "%includedir%" "${CMAKE_INSTALL_INCLUDEDIR}" FSTR ${FSTR}) + else () + string(REPLACE "%includedir%" "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}" FSTR ${FSTR}) + endif () + + if (IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}") + string(REPLACE "%libdir%" "${CMAKE_INSTALL_LIBDIR}" FSTR ${FSTR}) + else () + string(REPLACE "%libdir%" "\${prefix}/${CMAKE_INSTALL_LIBDIR}" FSTR ${FSTR}) + endif () + + string(REPLACE "%VERSION%" "${HB_VERSION}" FSTR ${FSTR}) + string(REPLACE "%requires_private%" "${PC_REQUIRES_PRIV}" FSTR ${FSTR}) + string(REPLACE "%libs_private%" "${PC_LIBS_PRIV}" FSTR ${FSTR}) + + file(WRITE "${PROJECT_BINARY_DIR}/${name}.pc" ${FSTR}) + + install( + FILES "${PROJECT_BINARY_DIR}/${name}.pc" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" + COMPONENT pkgconfig + ) +endmacro ( make_pkgconfig_pc_file ) + if (NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL) install(TARGETS harfbuzz EXPORT harfbuzzConfig @@ -709,6 +766,7 @@ if (NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL) RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} FRAMEWORK DESTINATION Library/Frameworks ) + make_pkgconfig_pc_file("harfbuzz") install(EXPORT harfbuzzConfig NAMESPACE harfbuzz:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/harfbuzz @@ -720,11 +778,13 @@ if (NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL) RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} FRAMEWORK DESTINATION Library/Frameworks ) + make_pkgconfig_pc_file("harfbuzz-icu") endif () if (HB_BUILD_SUBSET) install(TARGETS harfbuzz-subset ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - ) + ) + make_pkgconfig_pc_file("harfbuzz-subset") endif () if (HB_BUILD_UTILS) if (WIN32 AND BUILD_SHARED_LIBS) @@ -753,6 +813,7 @@ if (NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL) LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) + make_pkgconfig_pc_file("harfbuzz-gobject") if (HB_HAVE_INTROSPECTION) if ("${CMAKE_GENERATOR}" MATCHES "Visual Studio*") set (hb_libpath "${CMAKE_CURRENT_BINARY_DIR}/$")