Don't mix building static and shared libraries

sendfile
Martchus 4 years ago
parent 6d7a6ab735
commit e9cc26478b
  1. 6
      CMakeLists.txt
  2. 4
      application/argumentparser.h
  3. 439
      cmake/modules/3rdParty.cmake
  4. 43
      cmake/modules/AppTarget.cmake
  5. 40
      cmake/modules/BasicConfig.cmake
  6. 90
      cmake/modules/ConfigHeader.cmake
  7. 312
      cmake/modules/LibraryTarget.cmake
  8. 49
      cmake/modules/TestTarget.cmake
  9. 64
      cmake/templates/Config.cmake.in
  10. 9
      cmake/templates/SharedConfig.cmake.in
  11. 9
      cmake/templates/StaticConfig.cmake.in
  12. 1
      cmake/templates/config.h.in
  13. 45
      doc/buildvariables.md

@ -82,8 +82,6 @@ set(CMAKE_MODULE_FILES
set(CMAKE_TEMPLATE_FILES
cmake/templates/bash-completion.sh.in
cmake/templates/Config.cmake.in
cmake/templates/SharedConfig.cmake.in
cmake/templates/StaticConfig.cmake.in
cmake/templates/config.h.in
cmake/templates/desktop.in
cmake/templates/appdata.xml.in
@ -139,8 +137,8 @@ if (USE_NATIVE_FILE_BUFFER)
PROPERTY COMPILE_DEFINITIONS ${META_PROJECT_VARNAME}_USE_GNU_CXX_STDIO_FILEBUF)
else ()
message(STATUS "Using boost::iostreams::stream_buffer<boost::iostreams::file_descriptor_sink> for NativeFileStream")
set(boost_iostreams_DYNAMIC_COMPILE_DEFINITIONS BOOST_IOSTREAMS_DYN_LINK)
use_external_library(boost_iostreams AUTO_LINKAGE REQUIRED)
find_package(Boost REQUIRED COMPONENTS iostreams)
use_target(TARGET_NAME Boost::iostreams)
set_property(SOURCE io/nativefilestream.cpp
APPEND
PROPERTY COMPILE_DEFINITIONS ${META_PROJECT_VARNAME}_USE_BOOST_IOSTREAMS)

@ -30,11 +30,7 @@ CPP_UTILITIES_EXPORT extern std::vector<const char *> dependencyVersions2;
* used by ArgumentParser::printHelp().
* \remarks Reads those data from the config header so "config.h" must be included.
*/
#ifndef APP_STATICALLY_LINKED
#define SET_DEPENDENCY_INFO ::ApplicationUtilities::dependencyVersions2 = DEPENCENCY_VERSIONS
#else
#define SET_DEPENDENCY_INFO ::ApplicationUtilities::dependencyVersions2 = STATIC_DEPENCENCY_VERSIONS
#endif
/*!
* \def SET_APPLICATION_INFO

@ -35,311 +35,44 @@ macro (configure_dynamic_library_suffixes)
endif ()
endmacro ()
macro (link_against_library_varnames
NAME
LINKAGE
REQUIRED
PRIVATE_LIBRARIES_VARNAME
PUBLIC_LIBRARIES_VARNAME
PRIVATE_STATIC_LIBRARIES_VARNAME
PUBLIC_STATIC_LIBRARIES_VARNAME)
# determine whether the library is required or optional FIXME: improve passing required argument
if ("${REQUIRED}" STREQUAL "OPTIONAL")
set(${NAME}_REQUIRED "NO")
elseif ("${REQUIRED}" STREQUAL "REQUIRED")
set(${NAME}_REQUIRED "REQUIRED")
else ()
message(FATAL_ERROR "Invalid use of link_against_library; must specify either REQUIRED or OPTIONAL.")
endif ()
# add library to list of libraries to link against when building dynamic libraries or applications - prefer dynamic lib
# if linkage not explicitely specified
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_${NAME} ON)
set(USE_STATIC_${NAME} ON)
list(APPEND LIBRARIES ${${NAME}_STATIC_LIB})
message(
STATUS
"Linking ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} statically against external library ${NAME} (${${NAME}_STATIC_LIB})."
)
if (${NAME}_STATIC_INCLUDE_DIR)
list(APPEND ADDITIONAL_STATIC_INCLUDE_DIRS ${${NAME}_STATIC_INCLUDE_DIR})
message(
STATUS
"Adding include path for ${NAME} to ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}: ${${NAME}_STATIC_INCLUDE_DIR}"
)
endif ()
if (${NAME}_STATIC_COMPILE_DEFINITIONS)
list(APPEND META_PRIVATE_STATIC_LIB_COMPILE_DEFINITIONS ${${NAME}_STATIC_COMPILE_DEFINITIONS})
endif ()
if (${${NAME}_STATIC_LIB} IN_LIST META_PUBLIC_STATIC_LIB_DEPENDS OR ${NAME} IN_LIST META_PUBLIC_STATIC_LIB_DEPENDS)
list(APPEND ${PUBLIC_LIBRARIES_VARNAME} ${${NAME}_STATIC_LIB})
if (${NAME}_STATIC_INCLUDE_DIR)
list(APPEND PUBLIC_SHARED_INCLUDE_DIRS ${${NAME}_STATIC_INCLUDE_DIR})
endif ()
else ()
list(APPEND ${PRIVATE_LIBRARIES_VARNAME} ${${NAME}_STATIC_LIB})
if (${NAME}_STATIC_INCLUDE_DIR)
list(APPEND PRIVATE_SHARED_INCLUDE_DIRS ${${NAME}_STATIC_INCLUDE_DIR})
endif ()
endif ()
# add Qt resources of static library to be enabled
if (${NAME}_QT_RESOURCES)
message(STATUS "Adding ${${NAME}_QT_RESOURCES} to LIBRARIES_QT_RESOURCES for ${META_PROJECT_NAME}.")
list(APPEND LIBRARIES_QT_RESOURCES ${${NAME}_QT_RESOURCES})
endif ()
elseif ((${NAME}_DYNAMIC_LIB OR ${NAME}_SHARED_LIB)
AND (("${LINKAGE}" STREQUAL "AUTO_LINKAGE") OR ("${LINKAGE}" STREQUAL "SHARED")))
set(USE_${NAME} ON)
set(USE_SHARED_${NAME} ON)
if (NOT ${NAME}_DYNAMIC_LIB)
set(${NAME}_DYNAMIC_LIB ${${NAME}_SHARED_LIB})
endif ()
list(APPEND LIBRARIES ${${NAME}_DYNAMIC_LIB})
message(
STATUS
"Linking ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} dynamically against external library ${NAME} (${${NAME}_DYNAMIC_LIB})."
)
if (${NAME}_DYNAMIC_INCLUDE_DIR)
list(APPEND ADDITIONAL_SHARED_INCLUDE_DIRS ${${NAME}_DYNAMIC_INCLUDE_DIR})
message(
STATUS
"Adding include path for ${NAME} to ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}: ${${NAME}_DYNAMIC_INCLUDE_DIR}"
)
endif ()
if (${NAME}_DYNAMIC_COMPILE_DEFINITIONS)
list(APPEND META_PRIVATE_SHARED_LIB_COMPILE_DEFINITIONS ${${NAME}_DYNAMIC_COMPILE_DEFINITIONS})
endif ()
if (${${NAME}_DYNAMIC_LIB} IN_LIST META_PUBLIC_SHARED_LIB_DEPENDS OR ${NAME} IN_LIST META_PUBLIC_SHARED_LIB_DEPENDS)
list(APPEND ${PUBLIC_LIBRARIES_VARNAME} ${${NAME}_DYNAMIC_LIB})
if (${NAME}_DYNAMIC_INCLUDE_DIR)
list(APPEND PUBLIC_SHARED_INCLUDE_DIRS ${${NAME}_DYNAMIC_INCLUDE_DIR})
endif ()
else ()
list(APPEND ${PRIVATE_LIBRARIES_VARNAME} ${${NAME}_DYNAMIC_LIB})
if (${NAME}_DYNAMIC_INCLUDE_DIR)
list(APPEND PRIVATE_SHARED_INCLUDE_DIRS ${${NAME}_DYNAMIC_INCLUDE_DIR})
endif ()
endif ()
else ()
if (${NAME}_REQUIRED)
message(
FATAL_ERROR
"External library ${NAME} required by ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} is not available for the specified linkage ${LINKAGE}."
)
else ()
message(
WARNING
"External library ${NAME} required by ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} is not available for the specified linkage ${LINKAGE}."
)
endif ()
endif ()
# add library to list of libraries to be provided as transitive dependencies when building static libraries - prefer
# static lib if linkage not explicitely specified
if (${NAME}_STATIC_LIB AND ("${LINKAGE}" STREQUAL "AUTO_LINKAGE") OR ("${LINKAGE}" STREQUAL "STATIC"))
set(USE_${NAME} ON)
set(USE_STATIC_${NAME} ON)
list(APPEND STATIC_LIBRARIES ${${NAME}_STATIC_LIB})
message(
STATUS
"Adding static external library ${NAME} (${${NAME}_STATIC_LIB}) to dependencies of ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}."
)
if (${NAME}_STATIC_INCLUDE_DIR)
list(APPEND ADDITIONAL_STATIC_INCLUDE_DIRS ${${NAME}_STATIC_INCLUDE_DIR})
message(
STATUS
"Adding include path for ${NAME} to static ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}: ${${NAME}_STATIC_INCLUDE_DIR}"
)
endif ()
if (${${NAME}_STATIC_LIB} IN_LIST META_PUBLIC_STATIC_LIB_DEPENDS OR ${NAME} IN_LIST META_PUBLIC_STATIC_LIB_DEPENDS)
list(APPEND ${PUBLIC_STATIC_LIBRARIES_VARNAME} ${${NAME}_STATIC_LIB})
if (${NAME}_STATIC_INCLUDE_DIR)
list(APPEND PUBLIC_STATIC_INCLUDE_DIRS ${${NAME}_STATIC_INCLUDE_DIR})
endif ()
else ()
list(APPEND ${PRIVATE_STATIC_LIBRARIES_VARNAME} ${${NAME}_STATIC_LIB})
if (${NAME}_STATIC_INCLUDE_DIR)
list(APPEND PRIVATE_STATIC_INCLUDE_DIRS ${${NAME}_STATIC_INCLUDE_DIR})
endif ()
endif ()
# add Qt resources of static library for exporting it
if (${NAME}_QT_RESOURCES)
message(STATUS "Adding ${${NAME}_QT_RESOURCES} to STATIC_LIBRARIES_QT_RESOURCES for ${META_PROJECT_NAME}.")
list(APPEND STATIC_LIBRARIES_QT_RESOURCES ${${NAME}_QT_RESOURCES})
endif ()
elseif ((${NAME}_DYNAMIC_LIB OR ${NAME}_SHARED_LIB)
AND (("${LINKAGE}" STREQUAL "AUTO_LINKAGE"
AND (NOT ${NAME}_STATIC_LIB
OR (NOT STATIC_LINKAGE AND "${META_PROJECT_TYPE}" STREQUAL "application")
OR (NOT STATIC_LIBRARY_LINKAGE
AND ("${META_PROJECT_TYPE}" STREQUAL "" OR "${META_PROJECT_TYPE}" STREQUAL "library"))))
OR ("${LINKAGE}" STREQUAL "SHARED")))
set(USE_${NAME} ON)
set(USE_SHARED_${NAME} ON)
if (NOT ${NAME}_DYNAMIC_LIB)
set(${NAME}_DYNAMIC_LIB ${${NAME}_SHARED_LIB})
endif ()
list(APPEND STATIC_LIBRARIES ${${NAME}_DYNAMIC_LIB})
message(
STATUS
"Adding dynamic external library ${NAME} (${${NAME}_DYNAMIC_LIB}) to dependencies of static ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}."
)
if (${NAME}_DYNAMIC_INCLUDE_DIR)
list(APPEND ADDITIONAL_SHARED_INCLUDE_DIRS ${${NAME}_DYNAMIC_INCLUDE_DIR})
message(
STATUS
"Adding include path for ${NAME} to static ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}: ${${NAME}_DYNAMIC_INCLUDE_DIR}"
)
endif ()
if (${${NAME}_DYNAMIC_LIB} IN_LIST META_PUBLIC_SHARED_LIB_DEPENDS OR ${NAME} IN_LIST META_PUBLIC_SHARED_LIB_DEPENDS)
list(APPEND ${PUBLIC_STATIC_LIBRARIES_VARNAME} ${${NAME}_DYNAMIC_LIB})
if (${NAME}_DYNAMIC_INCLUDE_DIR)
list(APPEND PUBLIC_STATIC_INCLUDE_DIRS ${${NAME}_DYNAMIC_INCLUDE_DIR})
endif ()
else ()
list(APPEND ${PRIVATE_STATIC_LIBRARIES_VARNAME} ${${NAME}_DYNAMIC_LIB})
if (${NAME}_DYNAMIC_INCLUDE_DIR)
list(APPEND PRIVATE_STATIC_INCLUDE_DIRS ${${NAME}_DYNAMIC_INCLUDE_DIR})
endif ()
endif ()
else ()
if (${NAME}_REQUIRED)
message(
FATAL_ERROR
"External library ${NAME} required by ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} is not available for the specified linkage ${LINKAGE}."
)
else ()
message(
WARNING
"External library ${NAME} required by ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} is not available for the specified linkage ${LINKAGE}."
)
endif ()
endif ()
endmacro ()
macro (link_against_library NAME LINKAGE REQUIRED)
link_against_library_varnames("${NAME}"
"${LINKAGE}"
"${REQUIRED}"
PRIVATE_LIBRARIES
PUBLIC_LIBRARIES
PRIVATE_STATIC_LIBRARIES
PUBLIC_STATIC_LIBRARIES)
endmacro ()
macro (link_tests_against_library NAME LINKAGE REQUIRED)
link_against_library_varnames("${NAME}"
"${LINKAGE}"
"${REQUIRED}"
TEST_LIBRARIES
TEST_LIBRARIES
STATIC_TEST_LIBRARIES
STATIC_TEST_LIBRARIES)
endmacro ()
macro (find_external_library NAME LINKAGE REQUIRED)
set(${NAME}_DYNAMIC_INCLUDE_DIR NOTFOUND CACHE PATH "${NAME} include dir (dynamic)")
set(${NAME}_DYNAMIC_LIB NOTFOUND CACHE FILEPATH "${NAME} lib (dynamic)")
set(${NAME}_STATIC_INCLUDE_DIR NOTFOUND CACHE PATH "${NAME} include dir (static)")
set(${NAME}_STATIC_LIB NOTFOUND CACHE FILEPATH "${NAME} lib (static)")
save_default_library_suffixes()
if (NOT ${NAME}_DYNAMIC_LIB)
configure_dynamic_library_suffixes()
find_library(DETECTED_${NAME}_DYNAMIC_LIB ${NAME})
set(${NAME}_DYNAMIC_LIB ${DETECTED_${NAME}_DYNAMIC_LIB} CACHE FILEPATH "${NAME} lib (dynamic)" FORCE)
endif ()
if (NOT ${NAME}_STATIC_LIB)
configure_static_library_suffixes()
find_library(DETECTED_${NAME}_STATIC_LIB ${NAME})
set(${NAME}_STATIC_LIB ${DETECTED_${NAME}_STATIC_LIB} CACHE FILEPATH "${NAME} lib (static)" FORCE)
endif ()
restore_default_library_suffixes()
endmacro ()
macro (use_external_library NAME LINKAGE REQUIRED)
find_external_library("${NAME}" "${LINKAGE}" "${REQUIRED}")
link_against_library("${NAME}" "${LINKAGE}" "${REQUIRED}")
endmacro ()
function (use_external_library_from_package_dynamic NAME PKGNAME INCLUDE_VAR LIBRARY_VAR COMPAT_VERSION)
# internally used by find_external_library_from_package to find dynamic libraries
configure_dynamic_library_suffixes()
find_package(${PKGNAME} ${COMPAT_VERSION})
set(${NAME}_DYNAMIC_INCLUDE_DIR ${${INCLUDE_VAR}} CACHE PATH "${NAME} include dir (dynamic)" FORCE)
set(${NAME}_DYNAMIC_LIB ${${LIBRARY_VAR}} CACHE FILEPATH "${NAME} lib (dynamic)" FORCE)
endfunction ()
function (use_external_library_from_package_static NAME PKGNAME INCLUDE_VAR LIBRARY_VAR COMPAT_VERSION)
# internally used by find_external_library_from_package to find static libraries
configure_static_library_suffixes()
find_package(${PKGNAME} ${COMPAT_VERSION})
set(${NAME}_STATIC_INCLUDE_DIR ${${INCLUDE_VAR}} CACHE PATH "${NAME} include dir (static)" FORCE)
set(${NAME}_STATIC_LIB ${${LIBRARY_VAR}} CACHE FILEPATH "${NAME} lib (static)" FORCE)
endfunction ()
macro (find_external_library_from_package NAME PKGNAME VERSION INCLUDE_VAR LIBRARY_VAR LINKAGE REQUIRED)
# handle specified VERSION
if ("${VERSION}" STREQUAL "ANY_VERSION")
set(${NAME}_COMPATIBLE_VERSION "")
else ()
set(${NAME}_COMPATIBLE_VERSION ${VERSION})
endif ()
# use the find_library approach first because it is less buggy when trying to detect static libraries caveat: this way
# include dirs are not detected - however those are mostly the default anyways and can also be set manually by the user
# in case the auto-detection is not sufficient
find_external_library("${NAME}" "${LINKAGE}" OPTIONAL)
# fall back to actual use of find_package use separate functions to get a new scope
save_default_library_suffixes()
if (NOT ${NAME}_DYNAMIC_LIB)
use_external_library_from_package_dynamic(${NAME}
${PKGNAME}
${INCLUDE_VAR}
"${LIBRARY_VAR}"
"${${NAME}_COMPATIBLE_VERSION}")
endif ()
if (NOT ${NAME}_STATIC_LIB)
use_external_library_from_package_static(${NAME}
${PKGNAME}
${INCLUDE_VAR}
"${LIBRARY_VAR}"
"${${NAME}_COMPATIBLE_VERSION}")
endif ()
restore_default_library_suffixes()
endmacro ()
macro (use_external_library_from_package NAME PKGNAME VERSION INCLUDE_VAR LIBRARY_VAR LINKAGE REQUIRED)
find_external_library_from_package("${NAME}"
"${PKGNAME}"
"${VERSION}"
"${INCLUDE_VAR}"
"${LIBRARY_VAR}"
"${LINKAGE}"
"${REQUIRED}")
link_against_library("${NAME}" "${LINKAGE}" "${REQUIRED}")
endmacro ()
macro (use_iconv LINKAGE REQUIRED)
function(validate_visibility VISIBILITY)
if (NOT (VISIBILITY STREQUAL PUBLIC OR VISIBILITY STREQUAL PRIVATE))
message(FATAL_ERROR "Specified visibility ${VISIBILITY} is invalid (must be either PUBLIC or PRIVATE).")
endif()
endfunction()
function(parse_arguments_for_use_functions)
# parse arguments
set(OPTIONAL_ARGS OPTIONAL)
set(ONE_VALUE_ARGS VISIBILITY LIBRARIES_VARIABLE TARGET_NAME)
set(MULTI_VALUE_ARGS)
cmake_parse_arguments(ARGS "${OPTIONAL_ARGS}" "${ONE_VALUE_ARGS}" "${MULTI_VALUE_ARGS}" ${ARGN})
# validate values
if (ARGS_VISIBILITY)
validate_visibility(${ARGS_VISIBILITY})
else()
set (ARGS_VISIBILITY PRIVATE)
endif()
if (NOT ARGS_LIBRARIES_VARIABLE)
set (ARGS_LIBRARIES_VARIABLE "${ARGS_VISIBILITY}_LIBRARIES")
endif()
# export parsed values to parent scope
set(ARGS_VISIBILITY "${ARGS_VISIBILITY}" PARENT_SCOPE)
set(ARGS_LIBRARIES_VARIABLE "${ARGS_LIBRARIES_VARIABLE}" PARENT_SCOPE)
set(ARGS_TARGET_NAME "${ARGS_TARGET_NAME}" PARENT_SCOPE)
set(ARGS_OPTIONAL "${ARGS_OPTIONAL}" PARENT_SCOPE)
if (NOT ARGS_OPTIONAL)
set(ARGS_FIND_PACKAGE "REQUIRED" PARENT_SCOPE)
endif()
endfunction()
function (use_iconv)
parse_arguments_for_use_functions(${ARGN})
# check whether iconv from the standard library can be used
set(FORCE_EXTERNAL_ICONV OFF
CACHE PATH "whether to force usage of external iconv (rather than the using the one bundled with glibc)")
if (NOT FORCE_EXTERNAL_ICONV)
@ -348,9 +81,93 @@ macro (use_iconv LINKAGE REQUIRED)
check_function_exists(iconv HAS_ICONV)
endif ()
if (NOT FORCE_EXTERNAL_ICONV AND HAS_ICONV)
message(STATUS "Using iconv from the standard library for ${META_PROJECT_NAME}.")
else ()
# find external iconv library
use_external_library(iconv ${LINKAGE} ${REQUIRED})
endif ()
endmacro ()
message(STATUS "Using iconv from the standard library for target ${META_PROJECT_NAME}.")
return()
endif()
# find external iconv library
if (NOT TARGET ICONV::LIBICONV)
find_library(ICONV_LIBRARY_PATH iconv)
if (NOT EXISTS "${ICONV_LIBRARY_PATH}")
if (ARGS_OPTIONAL)
return()
endif()
message(FATAL_ERROR "Unable to find iconv library for project ${META_PROJECT_NAME}.")
endif()
add_library(ICONV::LIBICONV STATIC IMPORTED)
set_property(TARGET ICONV::LIBICONV PROPERTY IMPORTED_LOCATION "${ICONV_LIBRARY_PATH}")
endif()
set("${ARGS_LIBRARIES_VARIABLE}" "${${ARGS_LIBRARIES_VARIABLE}};ICONV::LIBICONV" PARENT_SCOPE)
endfunction()
function (use_openssl)
parse_arguments_for_use_functions(${ARGN})
find_package(OpenSSL ${ARGS_FIND_PACKAGE})
set("${ARGS_LIBRARIES_VARIABLE}" "${${ARGS_LIBRARIES_VARIABLE}};OpenSSL::SSL;OpenSSL::Crypto" PARENT_SCOPE)
set("PKG_CONFIG_OpenSSL_SSL" "libssl" PARENT_SCOPE)
set("PKG_CONFIG_OpenSSL_Crypto" "libcrypto" PARENT_SCOPE)
endfunction()
function (use_crypto)
parse_arguments_for_use_functions(${ARGN})
find_package(OpenSSL ${ARGS_FIND_PACKAGE})
set("${ARGS_LIBRARIES_VARIABLE}" "${${ARGS_LIBRARIES_VARIABLE}};OpenSSL::Crypto" PARENT_SCOPE)
set("PKG_CONFIG_OpenSSL_Crypto" "libcrypto" PARENT_SCOPE)
endfunction()
function (use_zlib)
parse_arguments_for_use_functions(${ARGN})
find_package(ZLIB ${ARGS_FIND_PACKAGE})
set("${ARGS_LIBRARIES_VARIABLE}" "${${ARGS_LIBRARIES_VARIABLE}};ZLIB::ZLIB" PARENT_SCOPE)
set("PKG_CONFIG_ZLIB_ZLIB" "zlib" PARENT_SCOPE)
endfunction()
function (use_target)
parse_arguments_for_use_functions(${ARGN})
if(NOT TARGET "${ARGS_TARGET_NAME}")
if (ARGS_OPTIONAL)
return()
endif()
message(FATAL_ERROR "Target \"${ARGS_TARGET_NAME}\" does not exist.")
endif()
set("${ARGS_LIBRARIES_VARIABLE}" "${${ARGS_LIBRARIES_VARIABLE}};${ARGS_TARGET_NAME}" PARENT_SCOPE)
endfunction()
if (META_NO_3RDPARTY_CONFIG)
return()
endif()
# option for deciding whether to build/use static or shared libraries
if (("${META_PROJECT_TYPE}" STREQUAL "library")
OR ("${META_PROJECT_TYPE}" STREQUAL "plugin")
OR ("${META_PROJECT_TYPE}" STREQUAL "qtplugin")
OR ("${META_PROJECT_TYPE}" STREQUAL ""))
set(META_PROJECT_IS_LIBRARY YES)
elseif ("${META_PROJECT_TYPE}" STREQUAL "application")
set(META_PROJECT_IS_APPLICATION YES)
endif ()
if (META_PROJECT_IS_LIBRARY)
option(BUILD_SHARED_LIBS ON "whether to build shared or static libraries")
option(STATIC_LIBRARY_LINKAGE "adds flags for static linkage when building dynamic libraries" OFF)
elseif (META_PROJECT_IS_APPLICATION)
option(STATIC_LINKAGE "adds flags for static linkage when building applications" OFF)
endif()
# configure "static linkage"
if ((STATIC_LINKAGE AND META_PROJECT_IS_APPLICATION) OR (STATIC_LIBRARY_LINKAGE AND META_PROJECT_IS_LIBRARY))
# add additional linker flags to achieve a fully statically linked build
if (META_PROJECT_IS_APPLICATION)
if (NOT APPLE)
list(APPEND META_ADDITIONAL_LINK_FLAGS -static)
endif ()
list(APPEND META_ADDITIONAL_LINK_FLAGS -static-libstdc++ -static-libgcc)
endif()
# prefer static libraries
configure_static_library_suffixes()
endif()

@ -18,26 +18,6 @@ if (WIN32)
set(WINDOWS_EXT "exe")
endif (WIN32)
# 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})
if (STATIC_LINKAGE)
list(APPEND META_PRIVATE_SHARED_LIB_COMPILE_DEFINITIONS APP_STATICALLY_LINKED)
endif ()
endif ()
# set linker flags
if (STATIC_LINKAGE)
set(ACTUAL_ADDITIONAL_LINK_FLAGS ${META_ADDITIONAL_STATIC_LINK_FLAGS})
else ()
set(ACTUAL_ADDITIONAL_LINK_FLAGS ${META_ADDITIONAL_LINK_FLAGS})
endif ()
# define relevant files
set(ALL_FILES
${HEADER_FILES}
@ -52,27 +32,30 @@ if (NOT BUILTIN_TRANSLATIONS)
endif ()
# add target for building the application
if (NOT ANDROID)
add_executable(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} ${GUI_TYPE} ${ALL_FILES})
else ()
# create a library which can be loaded from the Java-side
if (ANDROID)
# create a shared library which can be loaded from the Java-side
add_library(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} SHARED ${GUI_TYPE} ${ALL_FILES})
else ()
add_executable(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} ${GUI_TYPE} ${ALL_FILES})
endif ()
message(STATUS LINKING ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}
PUBLIC ${META_ADDITIONAL_LINK_FLAGS} "${PUBLIC_LIBRARIES}"
PRIVATE "${PRIVATE_LIBRARIES}")
target_link_libraries(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}
PUBLIC ${ACTUAL_ADDITIONAL_LINK_FLAGS} "${PUBLIC_LIBRARIES}"
PUBLIC ${META_ADDITIONAL_LINK_FLAGS} "${PUBLIC_LIBRARIES}"
PRIVATE "${PRIVATE_LIBRARIES}")
target_include_directories(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${HEADER_INSTALL_DESTINATION}> ${PUBLIC_SHARED_INCLUDE_DIRS}
PRIVATE "${PRIVATE_SHARED_INCLUDE_DIRS}")
PRIVATE "${PRIVATE_INCLUDE_DIRS}")
target_compile_definitions(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}
PUBLIC
"${META_PUBLIC_SHARED_LIB_COMPILE_DEFINITIONS}"
"${META_PUBLIC_COMPILE_DEFINITIONS}"
PRIVATE
"${META_PRIVATE_SHARED_LIB_COMPILE_DEFINITIONS}")
"${META_PRIVATE_COMPILE_DEFINITIONS}")
target_compile_options(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}
PUBLIC "${META_PUBLIC_SHARED_LIB_COMPILE_OPTIONS}"
PRIVATE "${META_PRIVATE_SHARED_LIB_COMPILE_OPTIONS}")
PUBLIC "${META_PUBLIC_COMPILE_OPTIONS}"
PRIVATE "${META_PRIVATE_COMPILE_OPTIONS}")
set_target_properties(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}
PROPERTIES CXX_STANDARD
"${META_CXX_STANDARD}"

@ -12,6 +12,8 @@ if (NOT META_APP_DESCRIPTION)
message(FATAL_ERROR "No project name (META_APP_DESCRIPTION) specified.")
endif ()
string(TOUPPER "${CMAKE_BUILD_TYPE}" META_CURRENT_CONFIGURATION)
# set project name (displayed in Qt Creator)
message(STATUS "Configuring project ${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}")
project(${META_PROJECT_NAME})
@ -165,41 +167,6 @@ if (LOGGING_ENABLED)
message(STATUS "Logging is enabled.")
endif ()
# options for deciding whether to build static and/or shared libraries
if (("${META_PROJECT_TYPE}" STREQUAL "library")
OR ("${META_PROJECT_TYPE}" STREQUAL "plugin")
OR ("${META_PROJECT_TYPE}" STREQUAL "qtplugin")
OR ("${META_PROJECT_TYPE}" STREQUAL ""))
option(ENABLE_STATIC_LIBS "whether building static libraries is enabled (disabled by default)" OFF)
option(DISABLE_SHARED_LIBS "whether building dynamic libraries is disabled (enabled by default)" OFF)
if (DISABLE_SHARED_LIBS)
set(BUILD_SHARED_LIBS OFF)
else ()
set(BUILD_SHARED_LIBS ON)
endif ()
if (ENABLE_STATIC_LIBS)
set(BUILD_STATIC_LIBS ON)
else ()
set(BUILD_STATIC_LIBS OFF)
endif ()
endif ()
# options for forcing static linkage when building applications or dynamic libraries
if (("${META_PROJECT_TYPE}" STREQUAL "library")
OR ("${META_PROJECT_TYPE}" STREQUAL "plugin")
OR ("${META_PROJECT_TYPE}" STREQUAL "qtplugin")
OR ("${META_PROJECT_TYPE}" STREQUAL ""))
option(STATIC_LIBRARY_LINKAGE "forces static linkage when building dynamic libraries" OFF)
elseif ("${META_PROJECT_TYPE}" STREQUAL "application")
option(STATIC_LINKAGE "forces static linkage when building applications" OFF)
endif ()
# additional linker flags used when static linkage is enabled
if (NOT APPLE)
list(APPEND META_ADDITIONAL_STATIC_LINK_FLAGS -static)
endif ()
list(APPEND META_ADDITIONAL_STATIC_LINK_FLAGS -static-libstdc++ -static-libgcc)
# determine whether the project is a header-only library
if (SRC_FILES OR GUI_SRC_FILES OR WIDGETS_SRC_FILES OR WIDGETS_UI_FILES OR QML_SRC_FILES OR RES_FILES)
set(META_HEADER_ONLY_LIB NO)
@ -211,6 +178,9 @@ else ()
message(STATUS "Project ${META_PROJECT_NAME} is header-only library.")
endif ()
# ensure 3rdParty has been included to configure BUILD_SHARED_LIBS and STATIC_LINKAGE/STATIC_LIBRARY_LINKAGE
include(3rdParty)
# options for enabling/disabling Qt GUI (if available)
if (WIDGETS_HEADER_FILES OR WIDGETS_SRC_FILES OR WIDGETS_UI_FILES OR META_HAS_WIDGETS_GUI)
if (META_GUI_OPTIONAL)

@ -1,3 +1,5 @@
cmake_minimum_required(VERSION 3.3.0 FATAL_ERROR)
# before including this module, all relevant variables must be set just include this module as last one since nothing should
# depend on it
@ -9,48 +11,61 @@ endif ()
include(TemplateFinder)
find_template_file("config.h" CPP_UTILITIES CONFIG_H_TEMPLATE_FILE)
# create list of dependency versions present at link time (one list for shared library and another for the static library
# since the lists might differ)
# create list of dependency versions present at link time
include(ListToString)
foreach (LINKAGE IN ITEMS "" "STATIC_")
unset(DEPENCENCY_VERSIONS)
unset(${LINKAGE}DEPENCENCY_VERSIONS_ARRAY)
# iterate through public and private libraries of shared/static library
foreach (DEPENDENCY IN LISTS PUBLIC_${LINKAGE}LIBRARIES PRIVATE_${LINKAGE}LIBRARIES)
if (TARGET ${DEPENDENCY})
unset(DEPENDENCY_DISPLAY_NAME)
unset(DEPENDENCY_VER)
# find version and display name for target
if (DEPENDENCY MATCHES "(Static)?Qt5::([A-Za-z0-9]+)")
# read meta-data of Qt module
set(DEPENDENCY_MODULE_NAME "${CMAKE_MATCH_2}")
set(DEPENDENCY_DISPLAY_NAME "Qt ${DEPENDENCY_MODULE_NAME}")
set(DEPENDENCY_VER "${Qt5${DEPENDENCY_MODULE_NAME}_VERSION_STRING}")
elseif (${DEPENDENCY}_varname)
# read meta-data of one of my own libraries
set(DEPENDENCY_VARNAME "${${DEPENDENCY}_varname}")
set(DEPENDENCY_DISPLAY_NAME "${DEPENDENCY}")
if (${DEPENDENCY_VARNAME}_DISPLAY_NAME)
set(DEPENDENCY_DISPLAY_NAME "${${DEPENDENCY_VARNAME}_DISPLAY_NAME}")
endif ()
set(DEPENDENCY_VER "${${DEPENDENCY_VARNAME}_VERSION}")
endif ()
# FIXME: provide meta-data for other libs, too
unset(DEPENCENCY_VERSIONS)
unset(DEPENCENCY_VERSIONS_ARRAY)
unset(LINK_LIBRARIES_LIST)
unset(INTERFACE_LINK_LIBRARIES_LIST)
unset(PROCESSED_DEPENDENCIES)
unset(HAVE_OPENSSL)
if (NOT META_HEADER_ONLY_LIB)
get_target_property(LINK_LIBRARIES_LIST "${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}" LINK_LIBRARIES)
endif()
get_target_property(INTERFACE_LINK_LIBRARIES_LIST "${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}" INTERFACE_LINK_LIBRARIES)
foreach (DEPENDENCY IN LISTS LINK_LIBRARIES_LIST INTERFACE_LINK_LIBRARIES_LIST)
if (NOT TARGET "${DEPENDENCY}" OR "${DEPENDENCY}" IN_LIST PROCESSED_DEPENDENCIES)
continue()
endif()
unset(DEPENDENCY_DISPLAY_NAME)
unset(DEPENDENCY_VER)
if (DEPENDENCY_VER
AND NOT
"${DEPENDENCY_VER}"
STREQUAL
"DEPENDENCY_VER-NOTFOUND")
list(APPEND DEPENCENCY_VERSIONS "${DEPENDENCY_DISPLAY_NAME}: ${DEPENDENCY_VER}")
endif ()
# find version and display name for target
if (DEPENDENCY MATCHES "((Static)?Qt5)::([A-Za-z0-9]+)")
# read meta-data of Qt module
set(DEPENDENCY_MODULE_PREFIX "${CMAKE_MATCH_1}")
set(DEPENDENCY_MODULE_NAME "${CMAKE_MATCH_3}")
set(DEPENDENCY_DISPLAY_NAME "Qt ${DEPENDENCY_MODULE_NAME}")
set(DEPENDENCY_VER "${${DEPENDENCY_MODULE_PREFIX}${DEPENDENCY_MODULE_NAME}_VERSION_STRING}")
elseif (DEPENDENCY STREQUAL ZLIB::ZLIB)
set(DEPENDENCY_DISPLAY_NAME "zlib")
set(DEPENDENCY_VER "${ZLIB_VERSION_STRING}")
elseif (NOT HAVE_OPENSSAL AND (DEPENDENCY STREQUAL OpenSSL::SSL OR DEPENDENCY STREQUAL OpenSSL::Crypto))
set(DEPENDENCY_DISPLAY_NAME "OpenSSL")
set(DEPENDENCY_VER "${OPENSSL_VERSION}")
elseif (${DEPENDENCY}_varname)
# read meta-data of one of my own libraries
set(DEPENDENCY_VARNAME "${${DEPENDENCY}_varname}")
set(DEPENDENCY_DISPLAY_NAME "${DEPENDENCY}")
if (${DEPENDENCY_VARNAME}_DISPLAY_NAME)
set(DEPENDENCY_DISPLAY_NAME "${${DEPENDENCY_VARNAME}_DISPLAY_NAME}")
endif ()
endforeach ()
if (DEPENCENCY_VERSIONS)
list_to_string("," " \\\n \"" "\"" "${DEPENCENCY_VERSIONS}" ${LINKAGE}DEPENCENCY_VERSIONS_ARRAY)
set(DEPENDENCY_VER "${${DEPENDENCY_VARNAME}_VERSION}")
endif ()
# FIXME: provide meta-data for other libs, too
if (DEPENDENCY_VER
AND NOT
"${DEPENDENCY_VER}"
STREQUAL
"DEPENDENCY_VER-NOTFOUND")
list(APPEND PROCESSED_DEPENDENCIES "${DEPENDENCY}")
list(APPEND DEPENCENCY_VERSIONS "${DEPENDENCY_DISPLAY_NAME}: ${DEPENDENCY_VER}")
endif ()
endforeach ()
if (DEPENCENCY_VERSIONS)
list_to_string("," " \\\n \"" "\"" "${DEPENCENCY_VERSIONS}" DEPENCENCY_VERSIONS_ARRAY)
endif ()
# add configuration header
configure_file("${CONFIG_H_TEMPLATE_FILE}" "${CMAKE_CURRENT_BINARY_DIR}/resources/config.h")
@ -59,7 +74,6 @@ configure_file("${CONFIG_H_TEMPLATE_FILE}" "${CMAKE_CURRENT_BINARY_DIR}/resource
if (NOT META_HEADER_ONLY_LIB)
foreach (TARGET_NAME
${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}
${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_static
${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_tests
${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_testlib)
if (TARGET ${TARGET_NAME})

@ -40,25 +40,10 @@ if (MINGW)
set(WINDOWS_EXT "dll")
endif (MINGW)
# 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_PRIVATE_STATIC_LIB_COMPILE_DEFINITIONS)
set(META_PRIVATE_STATIC_LIB_COMPILE_DEFINITIONS ${META_PRIVATE_COMPILE_DEFINITIONS}
${META_ADDITIONAL_PRIVATE_STATIC_COMPILE_DEFINITIONS})
endif ()
# set compile definitions for static build
if (NOT BUILD_SHARED_LIBS)
list(APPEND META_PUBLIC_COMPILE_DEFINITIONS ${META_PROJECT_VARNAME_UPPER}_STATIC)
endif()
# add global library-specific header
find_template_file("global.h" CPP_UTILITIES GLOBAL_H_TEMPLATE_FILE)
@ -81,7 +66,6 @@ if (NOT META_SOVERSION AND NOT META_IS_PLUGIN)
set(META_SOVERSION "${META_VERSION_MAJOR}")
endif ()
endif ()
message(STATUS "${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}: BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}")
# define relevant files
set(ALL_FILES
@ -107,118 +91,69 @@ endif ()
# add target for building the library
if (BUILD_SHARED_LIBS)
if (STATIC_LIBRARY_LINKAGE)
set(ACTUAL_ADDITIONAL_LINK_FLAGS ${META_ADDITIONAL_STATIC_LINK_FLAGS})
else ()
set(ACTUAL_ADDITIONAL_LINK_FLAGS ${META_ADDITIONAL_SHARED_LINK_FLAGS})
endif ()
if (META_IS_PLUGIN)
set(META_SHARED_OBJECT_TYPE MODULE)
else ()
set(META_SHARED_OBJECT_TYPE SHARED)
endif ()
# add library to be created, set libs to link against, set version and C++ standard
if (META_HEADER_ONLY_LIB)
add_library(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} INTERFACE)
target_link_libraries(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}
INTERFACE ${ACTUAL_ADDITIONAL_LINK_FLAGS} "${PUBLIC_LIBRARIES}" "${PRIVATE_LIBRARIES}")
target_include_directories(
${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}
INTERFACE $<BUILD_INTERFACE:${TARGET_INCLUDE_DIRECTORY_BUILD_INTERFACE}>
$<INSTALL_INTERFACE:${HEADER_INSTALL_DESTINATION}> ${PUBLIC_SHARED_INCLUDE_DIRS})
target_compile_definitions(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}
INTERFACE
"${META_PUBLIC_SHARED_LIB_COMPILE_DEFINITIONS}"
"${META_PRIVATE_SHARED_LIB_COMPILE_DEFINITIONS}")
target_compile_options(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}
INTERFACE "${META_PUBLIC_SHARED_LIB_COMPILE_OPTIONS}"
"${META_PRIVATE_SHARED_LIB_COMPILE_OPTIONS}")
set(META_LIBRARY_TYPE MODULE)
else ()
add_library(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} ${META_SHARED_OBJECT_TYPE} ${ALL_FILES})
target_link_libraries(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}
PUBLIC ${ACTUAL_ADDITIONAL_LINK_FLAGS} "${PUBLIC_LIBRARIES}"
PRIVATE "${PRIVATE_LIBRARIES}")
target_include_directories(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}
PUBLIC $<BUILD_INTERFACE:${TARGET_INCLUDE_DIRECTORY_BUILD_INTERFACE}>
$<INSTALL_INTERFACE:${HEADER_INSTALL_DESTINATION}> ${PUBLIC_SHARED_INCLUDE_DIRS}
PRIVATE "${PRIVATE_SHARED_INCLUDE_DIRS}")
target_compile_definitions(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}
PUBLIC
"${META_PUBLIC_SHARED_LIB_COMPILE_DEFINITIONS}"
PRIVATE
"${META_PRIVATE_SHARED_LIB_COMPILE_DEFINITIONS}")
target_compile_options(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}
PUBLIC "${META_PUBLIC_SHARED_LIB_COMPILE_OPTIONS}"
PRIVATE "${META_PRIVATE_SHARED_LIB_COMPILE_OPTIONS}")
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
"${META_CXX_STANDARD}"
LINK_SEARCH_START_STATIC
${STATIC_LINKAGE}
LINK_SEARCH_END_STATIC
${STATIC_LINKAGE}
AUTOGEN_TARGET_DEPENDS
"${AUTOGEN_DEPS}")
set(META_LIBRARY_TYPE SHARED)
endif ()
endif ()
else()
set(META_LIBRARY_TYPE STATIC)
endif()
# add target for building a static version of the library
if (BUILD_STATIC_LIBS)
# add library to be created, set required libs, set version and C++ standard
if (META_HEADER_ONLY_LIB)
add_library(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_static INTERFACE)
target_link_libraries(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_static
INTERFACE ${ACTUAL_ADDITIONAL_LINK_FLAGS} "${PUBLIC_STATIC_LIBRARIES}"
"${PRIVATE_STATIC_LIBRARIES}")
target_include_directories(
${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_static
INTERFACE $<BUILD_INTERFACE:${TARGET_INCLUDE_DIRECTORY_BUILD_INTERFACE}>
$<INSTALL_INTERFACE:${HEADER_INSTALL_DESTINATION}> ${PUBLIC_STATIC_INCLUDE_DIRS})
target_compile_definitions(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_static
INTERFACE
"${META_PUBLIC_STATIC_LIB_COMPILE_DEFINITIONS}"
"${META_PRIVATE_STATIC_LIB_COMPILE_DEFINITIONS}")
target_compile_options(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_static
INTERFACE "${META_PUBLIC_STATIC_LIB_COMPILE_OPTIONS}"
"${META_PRIVATE_STATIC_LIB_COMPILE_OPTIONS}")
else ()
add_library(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_static STATIC ${ALL_FILES})
target_link_libraries(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_static
PUBLIC "${PUBLIC_STATIC_LIBRARIES}" "${PRIVATE_STATIC_LIBRARIES}")
target_include_directories(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_static
PUBLIC $<BUILD_INTERFACE:${TARGET_INCLUDE_DIRECTORY_BUILD_INTERFACE}>
$<INSTALL_INTERFACE:${HEADER_INSTALL_DESTINATION}> ${PUBLIC_STATIC_INCLUDE_DIRS}
PRIVATE "${PRIVATE_STATIC_INCLUDE_DIRS}")
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}")
target_compile_options(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_static
PUBLIC "${META_PUBLIC_STATIC_LIB_COMPILE_OPTIONS}"
PRIVATE "${META_PRIVATE_STATIC_LIB_COMPILE_OPTIONS}")
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
"${META_CXX_STANDARD}"
AUTOGEN_TARGET_DEPENDS
"${AUTOGEN_DEPS}")
endif ()
foreach (DEPENDENCY ${PUBLIC_STATIC_LIBRARIES} ${PRIVATE_STATIC_LIBRARIES})
if (NOT ${DEPENDENCY} IN_LIST META_PUBLIC_STATIC_LIB_DEPENDS)
list(APPEND META_PRIVATE_STATIC_LIB_DEPENDS ${DEPENDENCY})
# add library to be created, set libs to link against, set version and C++ standard
if (META_HEADER_ONLY_LIB)
add_library(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} INTERFACE)
target_link_libraries(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}
INTERFACE ${META_ADDITIONAL_LINK_FLAGS} "${PUBLIC_LIBRARIES}" "${PRIVATE_LIBRARIES}")
target_include_directories(
${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}
INTERFACE $<BUILD_INTERFACE:${TARGET_INCLUDE_DIRECTORY_BUILD_INTERFACE}>
$<INSTALL_INTERFACE:${HEADER_INSTALL_DESTINATION}> ${PUBLIC_INCLUDE_DIRS})
target_compile_definitions(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}
INTERFACE
"${META_PUBLIC_COMPILE_DEFINITIONS}"
"${META_PRIVATE_COMPILE_DEFINITIONS}")
target_compile_options(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}
INTERFACE "${META_PUBLIC_COMPILE_OPTIONS}"
"${META_PRIVATE_COMPILE_OPTIONS}")
else ()
add_library(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX} ${META_LIBRARY_TYPE} ${ALL_FILES})
target_link_libraries(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}
PUBLIC ${META_ADDITIONAL_LINK_FLAGS} "${PUBLIC_LIBRARIES}"
PRIVATE "${PRIVATE_LIBRARIES}")
target_include_directories(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}
PUBLIC $<BUILD_INTERFACE:${TARGET_INCLUDE_DIRECTORY_BUILD_INTERFACE}>
$<INSTALL_INTERFACE:${HEADER_INSTALL_DESTINATION}> ${PUBLIC_INCLUDE_DIRS}
PRIVATE "${PRIVATE_INCLUDE_DIRS}")
target_compile_definitions(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}
PUBLIC
"${META_PUBLIC_COMPILE_DEFINITIONS}"
PRIVATE
"${META_PRIVATE_COMPILE_DEFINITIONS}")
target_compile_options(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}
PUBLIC "${META_PUBLIC_LIB_COMPILE_OPTIONS}"
PRIVATE "${META_PRIVATE_LIB_COMPILE_OPTIONS}")
set_target_properties(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}
PROPERTIES VERSION
"${META_VESION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH}"
SOVERSION
"${META_SOVERSION}"
CXX_STANDARD
"${META_CXX_STANDARD}"
LINK_SEARCH_START_STATIC
${STATIC_LINKAGE}
LINK_SEARCH_END_STATIC
${STATIC_LINKAGE}
AUTOGEN_TARGET_DEPENDS
"${AUTOGEN_DEPS}")
endif ()
if (NOT BUILD_SHARED_LIBS)
foreach (DEPENDENCY ${PUBLIC_LIBRARIES} ${PRIVATE_LIBRARIES})
if (NOT "${DEPENDENCY}" IN_LIST META_PUBLIC_LIB_DEPENDS)
list(APPEND META_PRIVATE_LIB_DEPENDS ${DEPENDENCY})
endif ()
endforeach ()
endif ()
endif()
# Qt Creator does not show INTERFACE_SOURCES in project tree, so create a custom target as workaround
if (META_HEADER_ONLY_LIB)
@ -230,14 +165,14 @@ if (META_HEADER_ONLY_LIB)
${HEADER_FILES})
target_include_directories(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_interface_sources_for_qtcreator
INTERFACE $<BUILD_INTERFACE:${TARGET_INCLUDE_DIRECTORY_BUILD_INTERFACE}>
$<INSTALL_INTERFACE:${HEADER_INSTALL_DESTINATION}> ${PUBLIC_SHARED_INCLUDE_DIRS})
$<INSTALL_INTERFACE:${HEADER_INSTALL_DESTINATION}> ${PUBLIC_INCLUDE_DIRS})
target_compile_definitions(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_interface_sources_for_qtcreator
INTERFACE
"${META_PUBLIC_SHARED_LIB_COMPILE_DEFINITIONS}"
"${META_PRIVATE_SHARED_LIB_COMPILE_DEFINITIONS}")
"${META_PUBLIC_LIB_COMPILE_DEFINITIONS}"
"${META_PRIVATE_LIB_COMPILE_DEFINITIONS}")
target_compile_options(
${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_interface_sources_for_qtcreator
INTERFACE "${META_PUBLIC_SHARED_LIB_COMPILE_OPTIONS}" "${META_PRIVATE_SHARED_LIB_COMPILE_OPTIONS}")
INTERFACE "${META_PUBLIC_LIB_COMPILE_OPTIONS}" "${META_PRIVATE_LIB_COMPILE_OPTIONS}")
set_target_properties(${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}_interface_sources_for_qtcreator
PROPERTIES VERSION
"${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH}"
@ -263,18 +198,6 @@ configure_package_config_file("${CONFIG_TEMPLATE_FILE}"
LIB_INSTALL_DESTINATION)
list(APPEND CMAKE_CONFIG_FILES "${CMAKE_CURRENT_BINARY_DIR}/${META_PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${META_PROJECT_NAME}ConfigVersion.cmake")
if (BUILD_SHARED_LIBS)
find_template_file("SharedConfig.cmake" CPP_UTILITIES SHARED_CONFIG_TEMPLATE_FILE)
configure_file("${SHARED_CONFIG_TEMPLATE_FILE}" "${CMAKE_CURRENT_BINARY_DIR}/${META_PROJECT_NAME}SharedConfig.cmake"
@ONLY)
list(APPEND CMAKE_CONFIG_FILES "${CMAKE_CURRENT_BINARY_DIR}/${META_PROJECT_NAME}SharedConfig.cmake")
endif ()
if (BUILD_STATIC_LIBS)
find_template_file("StaticConfig.cmake" CPP_UTILITIES STATIC_CONFIG_TEMPLATE_FILE)
configure_file("${STATIC_CONFIG_TEMPLATE_FILE}" "${CMAKE_CURRENT_BINARY_DIR}/${META_PROJECT_NAME}StaticConfig.cmake"
@ONLY)
list(APPEND CMAKE_CONFIG_FILES "${CMAKE_CURRENT_BINARY_DIR}/${META_PROJECT_NAME}StaticConfig.cmake")
endif ()