Browse Source

Provide an imported target for libs

experiment/meta_header
Martchus 6 years ago
parent
commit
b903adccdb
  1. 28
      cmake/modules/3rdParty.cmake
  2. 26
      cmake/modules/AppTarget.cmake
  3. 9
      cmake/modules/BasicConfig.cmake
  4. 130
      cmake/modules/LibraryTarget.cmake
  5. 71
      cmake/templates/Config.cmake.in
  6. 11
      cmake/templates/template.pc.in

28
cmake/modules/3rdParty.cmake

@ -1,3 +1,5 @@
cmake_minimum_required(VERSION 3.3.0 FATAL_ERROR)
if(NOT DEFINED FIND_THIRD_PARTY_LIBRARIES_EXISTS)
set(FIND_THIRD_PARTY_LIBRARIES_EXISTS true)
@ -40,13 +42,26 @@ if(NOT DEFINED FIND_THIRD_PARTY_LIBRARIES_EXISTS)
endif()
# add library to list of libraries to link against when building dynamic libraries or applications
if(${NAME}_STATIC_LIB AND (("${LINKAGE}" STREQUAL "AUTO_LINKAGE" AND ((STATIC_LINKAGE AND "${META_PROJECT_TYPE}" STREQUAL "application") OR (STATIC_LIBRARY_LINKAGE AND ("${META_PROJECT_TYPE}" STREQUAL "" OR "${META_PROJECT_TYPE}" STREQUAL "library")))) OR ("${LINKAGE}" STREQUAL "STATIC")))
list(APPEND LIBRARIES ${${NAME}_STATIC_LIB})
if(${NAME}_STATIC_LIB AND (("${LINKAGE}" STREQUAL "AUTO_LINKAGE" AND ((NOT (${NAME}_DYNAMIC_LIB OR ${NAME}_SHARED_LIB)) OR (STATIC_LINKAGE AND "${META_PROJECT_TYPE}" STREQUAL "application") OR (STATIC_LIBRARY_LINKAGE AND ("${META_PROJECT_TYPE}" STREQUAL "" OR "${META_PROJECT_TYPE}" STREQUAL "library")))) OR ("${LINKAGE}" STREQUAL "STATIC")))
set(USE_STATIC_${NAME} ON)
list(APPEND LIBRARIES ${${NAME}_STATIC_LIB})
if(${${NAME}_STATIC_LIB} IN_LIST META_PUBLIC_STATIC_LIB_DEPENDS)
list(APPEND PUBLIC_LIBRARIES ${${NAME}_STATIC_LIB})
else()
list(APPEND PRIVATE_LIBRARIES ${${NAME}_STATIC_LIB})
endif()
message(STATUS "Linking ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} statically against external library ${NAME} (${${NAME}_STATIC_LIB}).")
elseif(${NAME}_DYNAMIC_LIB AND ("${LINKAGE}" STREQUAL "AUTO_LINKAGE" OR ("${LINKAGE}" STREQUAL "SHARED")))
list(APPEND LIBRARIES ${${NAME}_DYNAMIC_LIB})
elseif((${NAME}_DYNAMIC_LIB OR ${NAME}_SHARED_LIB) AND (("${LINKAGE}" STREQUAL "AUTO_LINKAGE") OR ("${LINKAGE}" STREQUAL "SHARED")))
set(USE_STATIC_${NAME} OFF)
if(NOT ${NAME}_DYNAMIC_LIB)
set(${NAME}_DYNAMIC_LIB ${${NAME}_SHARED_LIB})
endif()
list(APPEND LIBRARIES ${${NAME}_DYNAMIC_LIB})
if(${${NAME}_DYNAMIC_LIB} IN_LIST META_PUBLIC_SHARED_LIB_DEPENDS)
list(APPEND PUBLIC_LIBRARIES ${${NAME}_DYNAMIC_LIB})
else()
list(APPEND PRIVATE_LIBRARIES ${${NAME}_DYNAMIC_LIB})
endif()
message(STATUS "Linking ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} dynamically against external library ${NAME} (${${NAME}_DYNAMIC_LIB}).")
else()
if(${NAME}_REQUIRED)
@ -59,6 +74,11 @@ if(NOT DEFINED FIND_THIRD_PARTY_LIBRARIES_EXISTS)
# add library to list of libraries to be provided as transitive dependencies when building static libraries
if(${NAME}_STATIC_LIB)
list(APPEND STATIC_LIBRARIES ${${NAME}_STATIC_LIB})
if(${${NAME}_STATIC_LIB} IN_LIST META_PUBLIC_STATIC_LIB_DEPENDS)
list(APPEND PUBLIC_STATIC_LIBRARIES ${${NAME}_STATIC_LIB})
else()
list(APPEND PRIVATE_STATIC_LIBRARIES ${${NAME}_STATIC_LIB})
endif()
message(STATUS "Adding ${${NAME}_STATIC_LIB} to static library dependencies of ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}.")
endif()
endmacro()

26
cmake/modules/AppTarget.cmake

@ -10,21 +10,33 @@ if(WIN32)
set(WINDOWS_EXT "exe")
endif(WIN32)
# use correct linker flags and compile definitions (depend on linkage)
# set compile definitions
if(NOT META_PUBLIC_SHARED_LIB_COMPILE_DEFINITIONS)
set(META_PUBLIC_SHARED_LIB_COMPILE_DEFINITIONS ${META_PUBLIC_COMPILE_DEFINITIONS} ${META_ADDITIONAL_PUBLIC_SHARED_COMPILE_DEFINITIONS})
endif()
if(NOT META_PRIVATE_SHARED_LIB_COMPILE_DEFINITIONS)
set(META_PRIVATE_SHARED_LIB_COMPILE_DEFINITIONS ${META_PRIVATE_COMPILE_DEFINITIONS} ${META_ADDITIONAL_PRIVATE_SHARED_COMPILE_DEFINITIONS})
endif()
# set linker flags
if(STATIC_LINKAGE)
set(ACTUAL_ADDITIONAL_LINK_FLAGS ${ADDITIONAL_STATIC_LINK_FLAGS})
set(ACTUAL_ADDITIONAL_COMPILE_DEFINITIONS ${ADDITIONAL_STATIC_COMPILE_DEFINITIONS})
set(ACTUAL_ADDITIONAL_LINK_FLAGS ${META_ADDITIONAL_STATIC_LINK_FLAGS})
else()
set(ACTUAL_ADDITIONAL_LINK_FLAGS ${ADDITIONAL_LINK_FLAGS})
set(ACTUAL_ADDITIONAL_COMPILE_DEFINITIONS ${ADDITIONAL_COMPILE_DEFINITIONS})
set(ACTUAL_ADDITIONAL_LINK_FLAGS ${META_ADDITIONAL_LINK_FLAGS})
endif()
# add target for building the application
add_executable(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} ${GUI_TYPE} ${HEADER_FILES} ${SRC_FILES} ${WIDGETS_FILES} ${QML_FILES} ${RES_FILES} ${QM_FILES} ${WINDOWS_ICON_PATH})
target_link_libraries(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} ${ACTUAL_ADDITIONAL_LINK_FLAGS} ${LIBRARIES})
target_link_libraries(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}
PUBLIC ${ACTUAL_ADDITIONAL_LINK_FLAGS} "${PUBLIC_LIBRARIES}"
PRIVATE "${PRIVATE_LIBRARIES}"
)
target_compile_definitions(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}
PUBLIC "${META_PUBLIC_SHARED_LIB_COMPILE_DEFINITIONS}"
PRIVATE "${META_PRIVATE_SHARED_LIB_COMPILE_DEFINITIONS}"
)
set_target_properties(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} PROPERTIES
CXX_STANDARD 11
COMPILE_DEFINITIONS "${ACTUAL_ADDITIONAL_COMPILE_DEFINITIONS}"
LINK_SEARCH_START_STATIC ${STATIC_LINKAGE}
LINK_SEARCH_END_STATIC ${STATIC_LINKAGE}
)

9
cmake/modules/BasicConfig.cmake

@ -44,8 +44,7 @@ set(TARGET_EXECUTABLE "${CMAKE_INSTALL_PREFIX}/bin/${TARGET_PREFIX}${META_PROJEC
# disable new ABI (can't catch ios_base::failure with new ABI)
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_BUILD_FLAGS "${META_REQUIRED_BUILD_CFLAGS} -D_GLIBCXX_USE_CXX11_ABI=0")
list(APPEND META_PRIVATE_COMPILE_DEFINITIONS _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).")
@ -53,14 +52,14 @@ endif()
# enable debug-only code when doing a debug build
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-DDEBUG_BUILD)
list(APPEND META_PRIVATE_COMPILE_DEFINITIONS DEBUG_BUILD)
message(STATUS "Debug build enabled.")
endif()
# enable logging when option is set
option(LOGGING_ENABLED "specifies whether logging is enabled" OFF)
if(LOGGING_ENABLED)
add_definitions(-DLOGGING_ENABLED)
list(APPEND META_PRIVATE_COMPILE_DEFINITIONS LOGGING_ENABLED)
message(STATUS "Logging is enabled.")
endif()
@ -88,7 +87,7 @@ elseif("${META_PROJECT_TYPE}" STREQUAL "application")
endif()
# additional linker flags used when static linkage is enables
set(ADDITIONAL_STATIC_LINK_FLAGS -static -static-libstdc++ -static-libgcc)
list(APPEND META_ADDITIONAL_STATIC_LINK_FLAGS -static -static-libstdc++ -static-libgcc)
# options for enabling/disabling Qt GUI (if available)
if(WIDGETS_HEADER_FILES OR WIDGETS_SRC_FILES OR WIDGETS_UI_FILES)

130
cmake/modules/LibraryTarget.cmake

@ -1,3 +1,5 @@
cmake_minimum_required(VERSION 3.3.0 FATAL_ERROR)
# before including this module, BasicConfig must be included
# check whether project type is set correctly
@ -40,12 +42,18 @@ if(MINGW)
set(WINDOWS_EXT "dll")
endif(MINGW)
# create global header and define build flags
if(NOT META_SHARED_LIB_COMPILE_DEFINITIONS)
set(META_SHARED_LIB_COMPILE_DEFINITIONS ${META_COMPILE_DEFINITIONS})
# set compile definitions
if(NOT META_PUBLIC_SHARED_LIB_COMPILE_DEFINITIONS)
set(META_PUBLIC_SHARED_LIB_COMPILE_DEFINITIONS ${META_PUBLIC_COMPILE_DEFINITIONS} ${META_ADDITIONAL_PUBLIC_SHARED_COMPILE_DEFINITIONS})
endif()
if(NOT META_PRIVATE_SHARED_LIB_COMPILE_DEFINITIONS)
set(META_PRIVATE_SHARED_LIB_COMPILE_DEFINITIONS ${META_PRIVATE_COMPILE_DEFINITIONS} ${META_ADDITIONAL_PRIVATE_SHARED_COMPILE_DEFINITIONS})
endif()
if(NOT META_PUBLIC_STATIC_LIB_COMPILE_DEFINITIONS)
set(META_PUBLIC_STATIC_LIB_COMPILE_DEFINITIONS ${META_PUBLIC_COMPILE_DEFINITIONS} ${META_PROJECT_VARNAME_UPPER}_STATIC ${META_ADDITIONAL_PUBLIC_STATIC_COMPILE_DEFINITIONS})
endif()
if(NOT META_STATIC_LIB_COMPILE_DEFINITIONS)
set(META_STATIC_LIB_COMPILE_DEFINITIONS ${META_COMPILE_DEFINITIONS} ${META_PROJECT_VARNAME_UPPER}_STATIC)
if(NOT META_PRIVATE_STATIC_LIB_COMPILE_DEFINITIONS)
set(META_PRIVATE_STATIC_LIB_COMPILE_DEFINITIONS ${META_PRIVATE_COMPILE_DEFINITIONS} ${META_ADDITIONAL_PRIVATE_STATIC_COMPILE_DEFINITIONS})
endif()
# add global library-specific header
@ -74,22 +82,25 @@ endif()
# add target for building the library
if(BUILD_SHARED_LIBS)
# use correct linker flags and compile definitions (depend on linkage)
if(STATIC_LIBRARY_LINKAGE)
set(ACTUAL_ADDITIONAL_LINK_FLAGS ${ADDITIONAL_STATIC_LINK_FLAGS})
set(ACTUAL_ADDITIONAL_COMPILE_DEFINITIONS ${ADDITIONAL_STATIC_COMPILE_DEFINITIONS})
set(ACTUAL_ADDITIONAL_LINK_FLAGS ${META_ADDITIONAL_STATIC_LINK_FLAGS})
else()
set(ACTUAL_ADDITIONAL_LINK_FLAGS ${ADDITIONAL_LINK_FLAGS})
set(ACTUAL_ADDITIONAL_COMPILE_DEFINITIONS ${ADDITIONAL_COMPILE_DEFINITIONS})
set(ACTUAL_ADDITIONAL_LINK_FLAGS ${META_ADDITIONAL_SHARED_LINK_FLAGS})
endif()
# add library to be created, set libs to link against, set version and C++ standard
add_library(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} SHARED ${HEADER_FILES} ${SRC_FILES} ${WIDGETS_FILES} ${QML_FILES} ${RES_FILES} ${QM_FILES} ${WINDOWS_ICON_PATH})
target_link_libraries(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} ${ACTUAL_ADDITIONAL_LINK_FLAGS} ${LIBRARIES})
target_link_libraries(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}
PUBLIC ${ACTUAL_ADDITIONAL_LINK_FLAGS} "${PUBLIC_LIBRARIES}"
PRIVATE "${PRIVATE_LIBRARIES}"
)
target_compile_definitions(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}
PUBLIC "${META_PUBLIC_SHARED_LIB_COMPILE_DEFINITIONS}"
PRIVATE "${META_PRIVATE_SHARED_LIB_COMPILE_DEFINITIONS}"
)
set_target_properties(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} PROPERTIES
VERSION "${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH}"
SOVERSION "${META_SOVERSION}"
CXX_STANDARD 11
COMPILE_DEFINITIONS "${ACTUAL_ADDITIONAL_COMPILE_DEFINITIONS}"
LINK_SEARCH_START_STATIC ${STATIC_LINKAGE}
LINK_SEARCH_END_STATIC ${STATIC_LINKAGE}
)
@ -97,19 +108,27 @@ endif()
# add target for building a static version of the library
if(BUILD_STATIC_LIBS)
set(ACTUAL_ADDITIONAL_COMPILE_DEFINITIONS ${ADDITIONAL_STATIC_COMPILE_DEFINITIONS})
list(APPEND ACTUAL_ADDITIONAL_COMPILE_DEFINITIONS ${META_STATIC_LIB_COMPILE_DEFINITIONS})
add_library(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_static STATIC ${HEADER_FILES} ${SRC_FILES} ${WIDGETS_FILES} ${QML_FILES} ${RES_FILES} ${QM_FILES} ${WINDOWS_ICON_PATH})
# add target link libraries for the static lib also because otherwise Qt header files can not be located
target_link_libraries(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_static ${STATIC_LIBRARIES})
target_link_libraries(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_static
PUBLIC "${PUBLIC_STATIC_LIBRARIES}"
PRIVATE "${PRIVATE_STATIC_LIBRARIES}"
)
target_compile_definitions(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_static
PUBLIC "${META_PUBLIC_STATIC_LIB_COMPILE_DEFINITIONS}"
PRIVATE "${META_PRIVATE_STATIC_LIB_COMPILE_DEFINITIONS}"
)
set_target_properties(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_static PROPERTIES
VERSION "${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH}"
SOVERSION "${META_SOVERSION}"
OUTPUT_NAME "${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}"
CXX_STANDARD 11
COMPILE_DEFINITIONS "${ACTUAL_ADDITIONAL_COMPILE_DEFINITIONS}"
)
set(META_STATIC_LIB_DEPENDS ${${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_static_LIB_DEPENDS}) # used in config file
foreach(DEPENDENCY ${${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_static_LIB_DEPENDS})
if(NOT ${DEPENDENCY} IN_LIST META_PUBLIC_STATIC_LIB_DEPENDS)
list(APPEND META_PRIVATE_STATIC_LIB_DEPENDS ${DEPENDENCY})
endif()
endforeach()
endif()
# create the CMake package config file from template
@ -134,13 +153,52 @@ write_basic_package_version_file(
)
# create pkg-config file from template
# will (currently) not contain Libs.private if static libs haven't been built anyways
find_template_file("template.pc" CPP_UTILITIES PKGCONFIG_TEMPLATE_FILE)
configure_file(
"${PKGCONFIG_TEMPLATE_FILE}"
"${CMAKE_CURRENT_BINARY_DIR}/${META_PROJECT_NAME}.pc"
@ONLY
)
macro(depends_for_pc LIB_TYPE DEPENDS OUTPUT_VAR_PKGS OUTPUT_VAR_LIBS)
unset(${OUTPUT_VAR_PKGS})
unset(${OUTPUT_VAR_LIBS})
foreach(DEPENDENCY ${${DEPENDS}})
if("${DEPENDENCY}" STREQUAL "general")
continue()
endif()
string(REPLACE "::" "_" DEPENDENCY_VARNAME "${DEPENDENCY}")
message(STATUS "PC_PKG_${LIB_TYPE}_${DEPENDENCY_VARNAME}: ${PC_PKG_${LIB_TYPE}_${DEPENDENCY_VARNAME}}")
if(PC_PKG_${LIB_TYPE}_${DEPENDENCY_VARNAME})
set(${OUTPUT_VAR_PKGS} "${${OUTPUT_VAR_PKGS}} ${PC_PKG_${LIB_TYPE}_${DEPENDENCY_VARNAME}}")
else()
set(${OUTPUT_VAR_LIBS} "${${OUTPUT_VAR_LIBS}} ${DEPENDENCY}")
endif()
endforeach()
endmacro()
macro(comple_defs_for_pc LIB_TYPE)
foreach(COMPILE_DEFINITION ${META_PUBLIC_${LIB_TYPE}_LIB_COMPILE_DEFINITIONS})
set(META_COMPILE_DEFINITIONS_FOR_PC "${META_COMPILE_DEFINITIONS_FOR_PC} -D${COMPILE_DEFINITION}")
endforeach()
endmacro()
unset(PC_FILES)
if(BUILD_SHARED_LIBS)
set(META_PROJECT_NAME_FOR_PC "${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}")
depends_for_pc(SHARED META_PUBLIC_SHARED_LIB_DEPENDS META_PUBLIC_PC_PKGS META_PUBLIC_LIB_DEPENDS_FOR_PC)
comple_defs_for_pc(SHARED)
configure_file(
"${PKGCONFIG_TEMPLATE_FILE}"
"${CMAKE_CURRENT_BINARY_DIR}/${META_PROJECT_NAME_FOR_PC}.pc"
@ONLY
)
list(APPEND PC_FILES ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}.pc)
endif()
if(BUILD_STATIC_LIBS)
set(META_PROJECT_NAME_FOR_PC "${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_static")
depends_for_pc(STATIC META_PUBLIC_STATIC_LIB_DEPENDS META_PUBLIC_PC_PKGS META_PUBLIC_LIB_DEPENDS_FOR_PC)
depends_for_pc(STATIC META_PRIVATE_STATIC_LIB_DEPENDS META_PRIVATE_PC_PKGS META_PRIVATE_LIB_DEPENDS_FOR_PC)
comple_defs_for_pc(STATIC)
configure_file(
"${PKGCONFIG_TEMPLATE_FILE}"
"${CMAKE_CURRENT_BINARY_DIR}/${META_PROJECT_NAME_FOR_PC}.pc"
@ONLY
)
list(APPEND PC_FILES ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_static.pc)
endif()
# add install target for the CMake config files
install(
@ -159,11 +217,13 @@ 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}/pkgconfig"
COMPONENT pkg-config
)
if(PC_FILES)
install(
FILES ${PC_FILES}
DESTINATION "lib${SELECTED_LIB_SUFFIX}/pkgconfig"
COMPONENT pkg-config
)
endif()
if(NOT TARGET install-pkg-config)
add_custom_target(install-pkg-config
COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=pkg-config -P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
@ -174,6 +234,7 @@ endif()
if(BUILD_SHARED_LIBS)
install(
TARGETS ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}
EXPORT ${META_PROJECT_NAME}SharedTargets
RUNTIME DESTINATION bin
COMPONENT binary
LIBRARY DESTINATION lib${SELECTED_LIB_SUFFIX}
@ -181,6 +242,11 @@ if(BUILD_SHARED_LIBS)
ARCHIVE DESTINATION lib${SELECTED_LIB_SUFFIX}
COMPONENT binary
)
install(EXPORT ${META_PROJECT_NAME}SharedTargets
DESTINATION "share/${META_PROJECT_NAME}/cmake"
EXPORT_LINK_INTERFACE_LIBRARIES
COMPONENT cmake-config
)
endif()
if(NOT TARGET install-binary)
add_custom_target(install-binary
@ -192,6 +258,7 @@ endif()
if(BUILD_STATIC_LIBS)
install(
TARGETS ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_static
EXPORT ${META_PROJECT_NAME}StaticTargets
RUNTIME DESTINATION bin
COMPONENT binary
LIBRARY DESTINATION lib${SELECTED_LIB_SUFFIX}
@ -199,8 +266,15 @@ if(BUILD_STATIC_LIBS)
ARCHIVE DESTINATION lib${SELECTED_LIB_SUFFIX}
COMPONENT binary
)
install(EXPORT ${META_PROJECT_NAME}StaticTargets
DESTINATION "share/${META_PROJECT_NAME}/cmake"
EXPORT_LINK_INTERFACE_LIBRARIES
COMPONENT cmake-config
)
endif()
#export(EXPORT ${META_PROJECT_NAME}Targets EXPORT_LINK_INTERFACE_LIBRARIES)
# add install target for stripped libs
if(NOT TARGET install-binary-strip)
add_custom_target(install-binary-strip

71
cmake/templates/Config.cmake.in

@ -1,50 +1,49 @@
@PACKAGE_INIT@
set(@META_PROJECT_VARNAME_UPPER@_HAS_SHARED_LIB "@BUILD_SHARED_LIBS@")
set(@META_PROJECT_VARNAME_UPPER@_SHARED_LIB "@TARGET_PREFIX@@META_PROJECT_NAME@@TARGET_SUFFIX@")
set(@META_PROJECT_VARNAME_UPPER@_SHARED_LIB_COMPILE_DEFINITIONS @META_SHARED_LIB_COMPILE_DEFINITIONS@)
set(@META_PROJECT_VARNAME_UPPER@_HAS_STATIC_LIB "@BUILD_STATIC_LIBS@")
set(@META_PROJECT_VARNAME_UPPER@_STATIC_LIB "@TARGET_PREFIX@@META_PROJECT_NAME@@TARGET_SUFFIX@.a")
set(@META_PROJECT_VARNAME_UPPER@_STATIC_LIB_DEPENDS @META_STATIC_LIB_DEPENDS@)
set(@META_PROJECT_VARNAME_UPPER@_STATIC_LIB_COMPILE_DEFINITIONS @META_STATIC_LIB_COMPILE_DEFINITIONS@)
set(@META_PROJECT_VARNAME_UPPER@_INCLUDE_DIRS "@PACKAGE_HEADER_INSTALL_DESTINATION@")
set(@META_PROJECT_VARNAME_UPPER@_BIN_DIR "@PACKAGE_BIN_INSTALL_DESTINATION@")
set(@META_PROJECT_VARNAME_UPPER@_LIB_DIR "@PACKAGE_LIB_INSTALL_DESTINATION@")
set(@META_PROJECT_VARNAME_UPPER@_MODULE_DIRS "@PACKAGE_CMAKE_MODULE_INSTALL_DESTINATION@")
set(@META_PROJECT_VARNAME_UPPER@_CONFIG_DIRS "@PACKAGE_CMAKE_CONFIG_INSTALL_DESTINATION@")
set(@META_PROJECT_VARNAME_UPPER@_QT_MODULES "@QT_MODULES@")
set(@META_PROJECT_VARNAME_UPPER@_KF_MODULES "@KF_MODULES@")
set(@META_PROJECT_VARNAME_UPPER@_HAS_SHARED_LIB @BUILD_SHARED_LIBS@)
if(@META_PROJECT_VARNAME_UPPER@_HAS_SHARED_LIB)
set(@META_PROJECT_VARNAME_UPPER@_SHARED_LIB "@TARGET_PREFIX@@META_PROJECT_NAME@@TARGET_SUFFIX@")
set(@META_PROJECT_VARNAME_UPPER@_SHARED_LIB_DEPENDS @META_PUBLIC_SHARED_LIB_DEPENDS@)
set(@META_PROJECT_VARNAME_UPPER@_SHARED_LIB_COMPILE_DEFINITIONS @META_PUBLIC_SHARED_LIB_COMPILE_DEFINITIONS@)
set(PC_PKG_SHARED_@TARGET_PREFIX@@META_PROJECT_NAME@@TARGET_SUFFIX@ "@TARGET_PREFIX@@META_PROJECT_NAME@@TARGET_SUFFIX@")
set(@META_PROJECT_VARNAME_UPPER@_LIB "${@META_PROJECT_VARNAME_UPPER@_SHARED_LIB}")
else()
set(@META_PROJECT_VARNAME_UPPER@_LIB "${@META_PROJECT_VARNAME_UPPER@_STATIC_LIB}")
endif()
set(@META_PROJECT_VARNAME_UPPER@_HAS_STATIC_LIB @BUILD_STATIC_LIBS@)
if(@META_PROJECT_VARNAME_UPPER@_HAS_STATIC_LIB)
set(@META_PROJECT_VARNAME_UPPER@_STATIC_LIB "@TARGET_PREFIX@@META_PROJECT_NAME@@TARGET_SUFFIX@_static")
set(@META_PROJECT_VARNAME_UPPER@_STATIC_LIB_DEPENDS @META_PUBLIC_STATIC_LIB_DEPENDS@ @META_PRIVATE_STATIC_LIB_DEPENDS@)
set(@META_PROJECT_VARNAME_UPPER@_STATIC_LIB_COMPILE_DEFINITIONS @META_PUBLIC_STATIC_LIB_COMPILE_DEFINITIONS@)
set(PC_PKG_STATIC_@TARGET_PREFIX@@META_PROJECT_NAME@@TARGET_SUFFIX@_static "@TARGET_PREFIX@@META_PROJECT_NAME@@TARGET_SUFFIX@_static")
endif()
set(@META_PROJECT_VARNAME_UPPER@_INCLUDE_DIRS "@PACKAGE_HEADER_INSTALL_DESTINATION@")
set(@META_PROJECT_VARNAME_UPPER@_BIN_DIR "@PACKAGE_BIN_INSTALL_DESTINATION@")
set(@META_PROJECT_VARNAME_UPPER@_LIB_DIR "@PACKAGE_LIB_INSTALL_DESTINATION@")
set(@META_PROJECT_VARNAME_UPPER@_MODULE_DIRS "@PACKAGE_CMAKE_MODULE_INSTALL_DESTINATION@")
set(@META_PROJECT_VARNAME_UPPER@_CONFIG_DIRS "@PACKAGE_CMAKE_CONFIG_INSTALL_DESTINATION@")
set(@META_PROJECT_VARNAME_UPPER@_PRIVATE_QT_MODULES "@QT_MODULES@")
set(@META_PROJECT_VARNAME_UPPER@_PRIVATE_KF_MODULES "@KF_MODULES@")
set(@META_PROJECT_VARNAME_UPPER@_PUBLIC_QT_MODULES "@META_PUBLIC_QT_MODULES@")
set(@META_PROJECT_VARNAME_UPPER@_PUBLIC_KF_MODULES "@META_PUBLIC_KF_MODULES@")
macro(use_@META_PROJECT_VARNAME@)
# make CMake modules of the project available
list(APPEND CMAKE_MODULE_PATH ${@META_PROJECT_VARNAME_UPPER@_MODULE_DIRS})
# add include and link directories
include_directories(BEFORE SYSTEM ${@META_PROJECT_VARNAME_UPPER@_INCLUDE_DIRS})
link_directories(${@META_PROJECT_VARNAME_UPPER@_LIB_DIR})
# add library to list of libraries to link against when building dynamic libraries or applications
if(@META_PROJECT_VARNAME_UPPER@_HAS_STATIC_LIB AND ((NOT ARGV0 AND ((STATIC_LINKAGE AND "${META_PROJECT_TYPE}" STREQUAL "application") OR (STATIC_LIBRARY_LINKAGE AND ("${META_PROJECT_TYPE}" STREQUAL "" OR "${META_PROJECT_TYPE}" STREQUAL "library")))) OR ("${ARGV0}" STREQUAL "STATIC") OR (NOT ARGV0 AND NOT @META_PROJECT_VARNAME_UPPER@_HAS_SHARED_LIB)))
list(APPEND LIBRARIES ${@META_PROJECT_VARNAME_UPPER@_STATIC_LIB} ${@META_PROJECT_VARNAME_UPPER@_STATIC_LIB_DEPENDS})
list(APPEND ADDITIONAL_QT_MODULES ${@META_PROJECT_VARNAME_UPPER@_QT_MODULES})
list(APPEND ADDITIONAL_KF_MODULES ${@META_PROJECT_VARNAME_UPPER@_KF_MODULES})
list(APPEND ADDITIONAL_STATIC_COMPILE_DEFINITIONS ${@META_PROJECT_VARNAME_UPPER@_STATIC_LIB_COMPILE_DEFINITIONS})
message(STATUS "Linking ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} statically against @TARGET_PREFIX@@META_PROJECT_NAME@@TARGET_SUFFIX@ (${@META_PROJECT_VARNAME_UPPER@_STATIC_LIB} ${@META_PROJECT_VARNAME_UPPER@_STATIC_LIB_DEPENDS}).")
elseif(@META_PROJECT_VARNAME_UPPER@_HAS_SHARED_LIB AND (NOT ARGV0 OR ("${ARGV0}" STREQUAL "SHARED")))
list(APPEND LIBRARIES ${@META_PROJECT_VARNAME_UPPER@_SHARED_LIB})
list(APPEND ADDITIONAL_SHARED_COMPILE_DEFINITIONS ${@META_PROJECT_VARNAME_UPPER@_SHARED_LIB_COMPILE_DEFINITIONS})
message(STATUS "Linking ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} dynamically against @TARGET_PREFIX@@META_PROJECT_NAME@@TARGET_SUFFIX@ (${@META_PROJECT_VARNAME_UPPER@_SHARED_LIB}).")
elseif(ARGV0)
message(FATAL_ERROR "Can not link ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} against @TARGET_PREFIX@@META_PROJECT_NAME@@TARGET_SUFFIX@ with the specified linkage ${ARGV0}.")
# link against library
include(3rdParty)
if(NOT ARGV0)
set(@META_PROJECT_VARNAME_UPPER@_LINKAGE AUTO_LINKAGE)
else()
message(FATAL_ERROR "Can not link ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} against @TARGET_PREFIX@@META_PROJECT_NAME@@TARGET_SUFFIX@.")
set(@META_PROJECT_VARNAME_UPPER@_LINKAGE "${ARG0}")
endif()
# add library (including dependencies) to list of libraries to be provided as transitive dependencies when building static libraries
list(APPEND STATIC_LIBRARIES ${@META_PROJECT_VARNAME_UPPER@_STATIC_LIB} ${@META_PROJECT_VARNAME_UPPER@_STATIC_LIB_DEPENDS})
message(STATUS "Adding ${@META_PROJECT_VARNAME_UPPER@_STATIC_LIB} ${@META_PROJECT_VARNAME_UPPER@_STATIC_LIB_DEPENDS} to static library dependencies of ${META_PROJECT_NAME}.")
# make CMake modules of the project available
list(APPEND CMAKE_MODULE_PATH ${@META_PROJECT_VARNAME_UPPER@_MODULE_DIRS})
link_against_library(@META_PROJECT_VARNAME_UPPER@ "${@META_PROJECT_VARNAME_UPPER@_LINKAGE}" REQUIRED)
# add required Qt and KF modules
list(APPEND IMPORTED_QT_MODULES ${@META_PROJECT_VARNAME_UPPER@_PUBLIC_QT_MODULES})
list(APPEND IMPORTED_KF_MODULES ${@META_PROJECT_VARNAME_UPPER@_PUBLIC_KF_MODULES})
endmacro()
# FIXME: provide an imported target

11
cmake/templates/template.pc.in

@ -3,11 +3,14 @@ exec_prefix=${prefix}
libdir=@LIB_INSTALL_DESTINATION@
includedir=@HEADER_INSTALL_DESTINATION@
Name: @META_PROJECT_NAME@
Name: @META_PROJECT_NAME_FOR_PC@
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}
Requires:@META_PUBLIC_PC_PKGS@
Requires.private:@META_PRIVATE_PC_PKGS@
Libs: -L${libdir} -l@TARGET_PREFIX@@META_PROJECT_NAME@@TARGET_SUFFIX@@META_PUBLIC_LIB_DEPENDS_FOR_PC@
Libs.private:@META_PRIVATE_LIB_DEPENDS_FOR_PC@
Cflags:@META_COMPILE_DEFINITIONS_FOR_PC@ -I${includedir}

Loading…
Cancel
Save