Add pkg-config file

experiment/meta_header
Martchus 6 years ago
parent b36572a4dd
commit 9f68a95920
  1. 21
      cmake/modules/BasicConfig.cmake
  2. 33
      cmake/modules/LibraryTarget.cmake
  3. 3
      cmake/templates/Config.cmake.in
  4. 13
      cmake/templates/template.pc.in

@ -39,6 +39,7 @@ set(TARGET_EXECUTABLE "${CMAKE_INSTALL_PREFIX}/bin/${TARGET_PREFIX}${META_PROJEC
option(FORCE_OLD_ABI "specifies whether usage of old ABI should be forced" OFF)
if(FORCE_OLD_ABI)
add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
set(META_REQUIRED_CFLAGS "${META_REQUIRED_CFLAGS} -D-D_GLIBCXX_USE_CXX11_ABI=0")
message(STATUS "Forcing usage of old CXX11 ABI.")
else()
message(STATUS "Using default CXX11 ABI (not forcing old CX11 ABI).")
@ -60,3 +61,23 @@ endif()
# options for forcing static linkage when building applications or dynamic libraries
option(STATIC_LINKAGE "forces static linkage when building applications" OFF)
option(STATIC_LIBRARY_LINKAGE "forces static linkage when building dynamic libraries" OFF)
# options for enabling/disabling Qt GUI (if available)
if(WIDGETS_HEADER_FILES OR WIDGETS_SRC_FILES OR WIDGETS_UI_FILES)
if(META_GUI_OPTIONAL)
option(WIDGETS_GUI "enables/disables building the Qt Widgets GUI: yes (default) or no" ON)
else()
set(WIDGETS_GUI ON)
endif()
else()
set(WIDGETS_GUI OFF)
endif()
if(QML_HEADER_FILES OR QML_SRC_FILES)
if(META_GUI_OPTIONAL)
option(QUICK_GUI "enables/disables building the Qt Quick GUI: yes (default) or no" ON)
else()
set(QUICK_GUI ON)
endif()
else()
set(QUICK_GUI OFF)
endif()

@ -12,9 +12,9 @@ set(LIB_SUFFIX "" CACHE STRING "specifies the general suffix for the library dir
set(SELECTED_LIB_SUFFIX "${LIB_SUFFIX}")
set(LIB_SUFFIX_32 "" CACHE STRING "specifies the suffix for the library directory to be used when building 32-bit library")
set(LIB_SUFFIX_64 "" CACHE STRING "specifies the suffix for the library directory to be used when building 64-bit library")
if(CMAKE_SIZEOF_VOID_P MATCHES "8" AND NOT ${LIB_SUFFIX_64} STREQUAL "")
if(LIB_SUFFIX_64 AND CMAKE_SIZEOF_VOID_P MATCHES "8")
set(SELECTED_LIB_SUFFIX "${LIB_SUFFIX_64}")
elseif(CMAKE_SIZEOF_VOID_P MATCHES "4" AND NOT ${LIB_SUFFIX_32} STREQUAL "")
elseif(LIB_SUFFIX_32 AND CMAKE_SIZEOF_VOID_P MATCHES "4")
set(SELECTED_LIB_SUFFIX "${LIB_SUFFIX_32}")
endif()
@ -63,10 +63,10 @@ if(BUILD_STATIC_LIBS)
OUTPUT_NAME ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}
CXX_STANDARD 11
)
set(META_LIB_DEPENDS ${${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_static_LIB_DEPENDS}) # used in config file
set(META_STATIC_LIB_DEPENDS ${${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_static_LIB_DEPENDS}) # used in config file
endif()
# create the CMake config file from the template
# create the CMake package config file from template
configure_package_config_file(
"${CONFIG_TEMPLATE_FILE}"
"${CMAKE_CURRENT_BINARY_DIR}/${META_PROJECT_NAME}Config.cmake"
@ -87,13 +87,23 @@ write_basic_package_version_file(
COMPATIBILITY SameMajorVersion
)
# create pkg-config file from template
# will (currently) not contain Libs.private if static libs haven't been built anyways
include(TemplateFinder)
find_template_file("template.pc" CPP_UTILITIES PKGCONFIG_TEMPLATE_FILE)
configure_file(
"${PKGCONFIG_TEMPLATE_FILE}"
"${CMAKE_CURRENT_BINARY_DIR}/${META_PROJECT_NAME}.pc"
@ONLY
)
# add install target for the CMake config files
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/${META_PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${META_PROJECT_NAME}ConfigVersion.cmake"
DESTINATION
"${CMAKE_CONFIG_INSTALL_DESTINATION}"
"share/${META_PROJECT_NAME}/cmake"
COMPONENT
cmake-config
)
@ -105,6 +115,19 @@ if(NOT TARGET install-cmake-config)
)
endif()
# add install target for pkg-config file
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/${META_PROJECT_NAME}.pc"
DESTINATION "lib${SELECTED_LIB_SUFFIX}/lib"
COMPONENT pkg-config
)
if(NOT TARGET install-pkg-config)
add_custom_target(install-pkg-config
DEPENDS ${META_PROJECT_NAME}
COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=pkg-config -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
)
endif()
# add install target for dynamic libs
if(BUILD_SHARED_LIBS)
install(

@ -4,12 +4,13 @@ set(@META_PROJECT_VARNAME@_HAS_SHARED_LIB "@BUILD_SHARED_LIBS@")
set(@META_PROJECT_VARNAME@_SHARED_LIB "@META_PROJECT_NAME@")
set(@META_PROJECT_VARNAME@_HAS_STATIC_LIB "@BUILD_STATIC_LIBS@")
set(@META_PROJECT_VARNAME@_STATIC_LIB "@META_PROJECT_NAME@.a")
set(@META_PROJECT_VARNAME@_STATIC_LIB_DEPENDS @META_LIB_DEPENDS@)
set(@META_PROJECT_VARNAME@_STATIC_LIB_DEPENDS @META_STATIC_LIB_DEPENDS@)
set(@META_PROJECT_VARNAME@_INCLUDE_DIRS "@PACKAGE_HEADER_INSTALL_DESTINATION@")
set(@META_PROJECT_VARNAME@_BIN_DIR "@PACKAGE_BIN_INSTALL_DESTINATION@")
set(@META_PROJECT_VARNAME@_LIB_DIR "@PACKAGE_LIB_INSTALL_DESTINATION@")
set(@META_PROJECT_VARNAME@_MODULE_DIRS "@PACKAGE_CMAKE_MODULE_INSTALL_DESTINATION@")
set(@META_PROJECT_VARNAME@_CONFIG_DIRS "@PACKAGE_CMAKE_CONFIG_INSTALL_DESTINATION@")
set(@META_PROJECT_VARNAME@_REQUIRED_CFLAGS "@META_REQUIRED_CFLAGS@")
macro(use_@META_PROJECT_VARNAME@)
include_directories(BEFORE SYSTEM ${@META_PROJECT_VARNAME@_INCLUDE_DIRS})

@ -0,0 +1,13 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=@LIB_INSTALL_DESTINATION@
includedir=@HEADER_INSTALL_DESTINATION@
Name: @META_PROJECT_NAME@
Description: @META_APP_DESCRIPTION@
Version: @META_APP_VERSION@
URL: @META_APP_URL@
Libs: -L${libdir} -l@TARGET_PREFIX@@META_PROJECT_NAME@@TARGET_SUFFIX@
Libs.private: @META_STATIC_LIB_DEPENDS@
Cflags: -I${includedir} @META_REQUIRED_CFLAGS@
Loading…
Cancel
Save