Merge pull request #3810 from ankith26/main

[cmake] Generate pkg-config .pc files
pull/3811/head
خالد حسني (Khaled Hosny) 2 years ago committed by GitHub
commit 7c0791d61a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 63
      CMakeLists.txt

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.1) cmake_minimum_required(VERSION 3.12)
project(harfbuzz) 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.") 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) add_definitions(-DHAVE_STDBOOL_H)
endif () endif ()
# These will be used while making pkg-config .pc files
set(PC_REQUIRES_PRIV "")
set(PC_LIBS_PRIV "")
if (NOT MSVC) if (NOT MSVC)
set(THREADS_PREFER_PTHREAD_FLAG ON) set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads) find_package(Threads)
if (CMAKE_USE_PTHREADS_INIT) if (CMAKE_USE_PTHREADS_INIT)
add_definitions("-DHAVE_PTHREAD") add_definitions("-DHAVE_PTHREAD")
list(APPEND THIRD_PARTY_LIBS Threads::Threads) list(APPEND THIRD_PARTY_LIBS Threads::Threads)
list(APPEND PC_LIBS_PRIV -pthread)
endif () endif ()
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) check_funcs(FT_Get_Var_Blend_Coordinates FT_Set_Var_Blend_Coordinates FT_Done_MM_Var)
endif () endif ()
if (HB_HAVE_FREETYPE)
list(APPEND PC_REQUIRES_PRIV "freetype2 >= 12.0.6")
endif ()
if (HB_HAVE_GRAPHITE2) if (HB_HAVE_GRAPHITE2)
add_definitions(-DHAVE_GRAPHITE2) add_definitions(-DHAVE_GRAPHITE2)
@ -220,6 +229,8 @@ if (HB_HAVE_GRAPHITE2)
list(APPEND THIRD_PARTY_LIBS ${GRAPHITE2_LIBRARY}) list(APPEND THIRD_PARTY_LIBS ${GRAPHITE2_LIBRARY})
list(APPEND PC_REQUIRES_PRIV "graphite2 >= 1.2.0")
mark_as_advanced(GRAPHITE2_INCLUDE_DIR GRAPHITE2_LIBRARY) mark_as_advanced(GRAPHITE2_INCLUDE_DIR GRAPHITE2_LIBRARY)
endif () endif ()
@ -240,6 +251,8 @@ if (HB_HAVE_GLIB)
list(APPEND THIRD_PARTY_LIBS ${GLIB_LIBRARIES}) 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) mark_as_advanced(GLIB_LIBRARIES GLIBCONFIG_INCLUDE_DIR GLIB_INCLUDE_DIR)
endif () endif ()
@ -272,24 +285,28 @@ if (APPLE AND HB_HAVE_CORETEXT)
find_library(COREFOUNDATION CoreFoundation) find_library(COREFOUNDATION CoreFoundation)
if (COREFOUNDATION) if (COREFOUNDATION)
list(APPEND THIRD_PARTY_LIBS ${COREFOUNDATION}) list(APPEND THIRD_PARTY_LIBS ${COREFOUNDATION})
list(APPEND PC_LIBS_PRIV "-framework CoreFoundation")
endif () endif ()
mark_as_advanced(COREFOUNDATION) mark_as_advanced(COREFOUNDATION)
find_library(CORETEXT CoreText) find_library(CORETEXT CoreText)
if (CORETEXT) if (CORETEXT)
list(APPEND THIRD_PARTY_LIBS ${CORETEXT}) list(APPEND THIRD_PARTY_LIBS ${CORETEXT})
list(APPEND PC_LIBS_PRIV "-framework CoreText")
endif () endif ()
mark_as_advanced(CORETEXT) mark_as_advanced(CORETEXT)
find_library(COREGRAPHICS CoreGraphics) find_library(COREGRAPHICS CoreGraphics)
if (COREGRAPHICS) if (COREGRAPHICS)
list(APPEND THIRD_PARTY_LIBS ${COREGRAPHICS}) list(APPEND THIRD_PARTY_LIBS ${COREGRAPHICS})
list(APPEND PC_LIBS_PRIV "-framework CoreGraphics")
endif () endif ()
mark_as_advanced(COREGRAPHICS) mark_as_advanced(COREGRAPHICS)
else () else ()
find_library(APPLICATION_SERVICES_FRAMEWORK ApplicationServices) find_library(APPLICATION_SERVICES_FRAMEWORK ApplicationServices)
if (APPLICATION_SERVICES_FRAMEWORK) if (APPLICATION_SERVICES_FRAMEWORK)
list(APPEND THIRD_PARTY_LIBS ${APPLICATION_SERVICES_FRAMEWORK}) list(APPEND THIRD_PARTY_LIBS ${APPLICATION_SERVICES_FRAMEWORK})
list(APPEND PC_LIBS_PRIV "-framework ApplicationServices")
endif () endif ()
mark_as_advanced(APPLICATION_SERVICES_FRAMEWORK) mark_as_advanced(APPLICATION_SERVICES_FRAMEWORK)
@ -300,12 +317,14 @@ if (WIN32 AND HB_HAVE_GDI)
add_definitions(-DHAVE_GDI) add_definitions(-DHAVE_GDI)
list(APPEND project_headers ${PROJECT_SOURCE_DIR}/src/hb-gdi.h) list(APPEND project_headers ${PROJECT_SOURCE_DIR}/src/hb-gdi.h)
list(APPEND THIRD_PARTY_LIBS gdi32) list(APPEND THIRD_PARTY_LIBS gdi32)
list(APPEND PC_LIBS_PRIV -lgdi32)
endif () endif ()
if (WIN32 AND HB_HAVE_UNISCRIBE) if (WIN32 AND HB_HAVE_UNISCRIBE)
add_definitions(-DHAVE_UNISCRIBE) add_definitions(-DHAVE_UNISCRIBE)
list(APPEND project_headers ${PROJECT_SOURCE_DIR}/src/hb-uniscribe.h) list(APPEND project_headers ${PROJECT_SOURCE_DIR}/src/hb-uniscribe.h)
list(APPEND THIRD_PARTY_LIBS usp10 gdi32 rpcrt4) list(APPEND THIRD_PARTY_LIBS usp10 gdi32 rpcrt4)
list(APPEND PC_LIBS_PRIV -lusp10 -lgdi32 -lrpcrt4)
endif () endif ()
if (WIN32 AND HB_HAVE_DIRECTWRITE) if (WIN32 AND HB_HAVE_DIRECTWRITE)
@ -701,6 +720,44 @@ if (NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL)
endif () endif ()
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) if (NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL)
install(TARGETS harfbuzz install(TARGETS harfbuzz
EXPORT harfbuzzConfig EXPORT harfbuzzConfig
@ -709,6 +766,7 @@ if (NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL)
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
FRAMEWORK DESTINATION Library/Frameworks FRAMEWORK DESTINATION Library/Frameworks
) )
make_pkgconfig_pc_file("harfbuzz")
install(EXPORT harfbuzzConfig install(EXPORT harfbuzzConfig
NAMESPACE harfbuzz:: NAMESPACE harfbuzz::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/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} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
FRAMEWORK DESTINATION Library/Frameworks FRAMEWORK DESTINATION Library/Frameworks
) )
make_pkgconfig_pc_file("harfbuzz-icu")
endif () endif ()
if (HB_BUILD_SUBSET) if (HB_BUILD_SUBSET)
install(TARGETS harfbuzz-subset install(TARGETS harfbuzz-subset
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
) )
make_pkgconfig_pc_file("harfbuzz-subset")
endif () endif ()
if (HB_BUILD_UTILS) if (HB_BUILD_UTILS)
if (WIN32 AND BUILD_SHARED_LIBS) 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} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
) )
make_pkgconfig_pc_file("harfbuzz-gobject")
if (HB_HAVE_INTROSPECTION) if (HB_HAVE_INTROSPECTION)
if ("${CMAKE_GENERATOR}" MATCHES "Visual Studio*") if ("${CMAKE_GENERATOR}" MATCHES "Visual Studio*")
set (hb_libpath "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>") set (hb_libpath "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIGURATION>")

Loading…
Cancel
Save