Browse Source

Apply cmake-format

sendfile
Martchus 3 years ago
parent
commit
a17f322f3c
  1. 1
      CMakeLists.txt
  2. 70
      cmake/modules/3rdParty.cmake
  3. 44
      cmake/modules/AppTarget.cmake
  4. 18
      cmake/modules/BasicConfig.cmake
  5. 9
      cmake/modules/ConfigHeader.cmake
  6. 18
      cmake/modules/Doxygen.cmake
  7. 118
      cmake/modules/LibraryTarget.cmake
  8. 51
      cmake/modules/TestTarget.cmake

1
CMakeLists.txt

@ -130,7 +130,6 @@ if (USE_NATIVE_FILE_BUFFER)
${CMAKE_CURRENT_SOURCE_DIR}/feature_detection/stdio_filebuf.cpp
OUTPUT_VARIABLE GNU_CXX_STDIO_FILEBUF_CHECK_LOG)
# use __gnu_cxx::stdio_filebuf if available or fallback to boost::iostreams::stream_buffer
if (GNU_CXX_STDIO_FILEBUF_AVAILABLE AND NOT FORCE_BOOST_IOSTREAMS_FOR_NATIVE_FILE_BUFFER)
message(STATUS "Using __gnu_cxx::stdio_filebuf for NativeFileStream")

70
cmake/modules/3rdParty.cmake

@ -16,8 +16,7 @@ macro (restore_default_library_suffixes)
endmacro ()
macro (configure_static_library_suffixes)
# allows to look for static libraries in particular
# NOTE: code duplicated in Config.cmake.in
# allows to look for static libraries in particular NOTE: code duplicated in Config.cmake.in
if (WIN32)
set(CMAKE_FIND_LIBRARY_SUFFIXES .a .lib)
else ()
@ -36,13 +35,13 @@ macro (configure_dynamic_library_suffixes)
endif ()
endmacro ()
function(validate_visibility VISIBILITY)
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()
endif ()
endfunction ()
function(parse_arguments_for_use_functions)
function (parse_arguments_for_use_functions)
# parse arguments
set(OPTIONAL_ARGS OPTIONAL)
set(ONE_VALUE_ARGS VISIBILITY LIBRARIES_VARIABLE PACKAGES_VARIABLE TARGET_NAME)
@ -52,17 +51,17 @@ function(parse_arguments_for_use_functions)
# validate values
if (ARGS_VISIBILITY)
validate_visibility(${ARGS_VISIBILITY})
else()
set (ARGS_VISIBILITY PRIVATE)
endif()
else ()
set(ARGS_VISIBILITY PRIVATE)
endif ()
if (NOT ARGS_LIBRARIES_VARIABLE)
set (ARGS_LIBRARIES_VARIABLE "${ARGS_VISIBILITY}_LIBRARIES")
endif()
set(ARGS_LIBRARIES_VARIABLE "${ARGS_VISIBILITY}_LIBRARIES")
endif ()
if (NOT ARGS_PACKAGES_VARIABLE AND (NOT BUILD_SHARED_LIBS OR VISIBILITY STREQUAL PUBLIC))
set (ARGS_PACKAGES_VARIABLE "INTERFACE_REQUIRED_PACKAGES")
set(ARGS_PACKAGES_VARIABLE "INTERFACE_REQUIRED_PACKAGES")
else ()
set (ARGS_PACKAGES_VARIABLE "REQUIRED_PACKAGES")
set(ARGS_PACKAGES_VARIABLE "REQUIRED_PACKAGES")
endif ()
# export parsed values to parent scope
@ -73,8 +72,8 @@ function(parse_arguments_for_use_functions)
set(ARGS_OPTIONAL "${ARGS_OPTIONAL}" PARENT_SCOPE)
if (NOT ARGS_OPTIONAL)
set(ARGS_FIND_PACKAGE "REQUIRED" PARENT_SCOPE)
endif()
endfunction()
endif ()
endfunction ()
function (use_iconv)
parse_arguments_for_use_functions(${ARGN})
@ -90,7 +89,7 @@ function (use_iconv)
if (NOT FORCE_EXTERNAL_ICONV AND HAS_ICONV)
message(STATUS "Using iconv from the standard library for target ${META_PROJECT_NAME}.")
return()
endif()
endif ()
# find external iconv library
if (NOT TARGET Iconv::Iconv)
@ -98,12 +97,12 @@ function (use_iconv)
find_package(Iconv ${ARGS_FIND_PACKAGE})
if (NOT Iconv_FOUND)
return()
endif()
endif()
endif ()
endif ()
set("${ARGS_LIBRARIES_VARIABLE}" "${${ARGS_LIBRARIES_VARIABLE}};Iconv::Iconv" PARENT_SCOPE)
set("${ARGS_PACKAGES_VARIABLE}" "${${ARGS_PACKAGES_VARIABLE}};Iconv" PARENT_SCOPE)
endfunction()
endfunction ()
function (use_openssl)
parse_arguments_for_use_functions(${ARGN})
@ -111,7 +110,7 @@ function (use_openssl)
find_package(OpenSSL ${ARGS_FIND_PACKAGE})
if (NOT OpenSSL_FOUND)
return()
endif()
endif ()
set("${ARGS_LIBRARIES_VARIABLE}" "${${ARGS_LIBRARIES_VARIABLE}};OpenSSL::SSL;OpenSSL::Crypto" PARENT_SCOPE)
set("${ARGS_PACKAGES_VARIABLE}" "${${ARGS_PACKAGES_VARIABLE}};OpenSSL" PARENT_SCOPE)
if (WIN32 AND OPENSSL_USE_STATIC_LIBS)
@ -119,7 +118,7 @@ function (use_openssl)
endif ()
set("PKG_CONFIG_OpenSSL_SSL" "libssl" PARENT_SCOPE)
set("PKG_CONFIG_OpenSSL_Crypto" "libcrypto" PARENT_SCOPE)
endfunction()
endfunction ()
function (use_crypto)
parse_arguments_for_use_functions(${ARGN})
@ -127,14 +126,15 @@ function (use_crypto)
find_package(OpenSSL ${ARGS_FIND_PACKAGE})
if (NOT OpenSSL_FOUND)
return()
endif()
endif ()
set("${ARGS_LIBRARIES_VARIABLE}" "${${ARGS_LIBRARIES_VARIABLE}};OpenSSL::Crypto" PARENT_SCOPE)
set("${ARGS_PACKAGES_VARIABLE}" "${${ARGS_PACKAGES_VARIABLE}};OpenSSL" PARENT_SCOPE)
if (WIN32 AND OPENSSL_USE_STATIC_LIBS)
set("${ARGS_LIBRARIES_VARIABLE}" "${${ARGS_LIBRARIES_VARIABLE}};OpenSSL::Crypto;-lws2_32;-lgdi32;-lcrypt32" PARENT_SCOPE)
set("${ARGS_LIBRARIES_VARIABLE}" "${${ARGS_LIBRARIES_VARIABLE}};OpenSSL::Crypto;-lws2_32;-lgdi32;-lcrypt32"
PARENT_SCOPE)
endif ()
set("PKG_CONFIG_OpenSSL_Crypto" "libcrypto" PARENT_SCOPE)
endfunction()
endfunction ()
function (use_zlib)
parse_arguments_for_use_functions(${ARGN})
@ -142,28 +142,28 @@ function (use_zlib)
find_package(ZLIB ${ARGS_FIND_PACKAGE})
if (NOT ZLIB_FOUND)
return()
endif()
endif ()
set("${ARGS_LIBRARIES_VARIABLE}" "${${ARGS_LIBRARIES_VARIABLE}};ZLIB::ZLIB" PARENT_SCOPE)
set("${ARGS_PACKAGES_VARIABLE}" "${${ARGS_PACKAGES_VARIABLE}};ZLIB" PARENT_SCOPE)
set("PKG_CONFIG_ZLIB_ZLIB" "zlib" PARENT_SCOPE)
endfunction()
endfunction ()
function (use_target)
parse_arguments_for_use_functions(${ARGN})
if(NOT TARGET "${ARGS_TARGET_NAME}")
if (NOT TARGET "${ARGS_TARGET_NAME}")
if (ARGS_OPTIONAL)
return()
endif()
endif ()
message(FATAL_ERROR "Target \"${ARGS_TARGET_NAME}\" does not exist.")
endif()
endif ()
set("${ARGS_LIBRARIES_VARIABLE}" "${${ARGS_LIBRARIES_VARIABLE}};${ARGS_TARGET_NAME}" PARENT_SCOPE)
endfunction()
endfunction ()
# skip subsequent configuration if only the function includes are wanted
if (META_NO_3RDPARTY_CONFIG)
return()
endif()
endif ()
# add options for deciding whether to build/use static or shared libraries
if (("${META_PROJECT_TYPE}" STREQUAL "library")
@ -179,7 +179,7 @@ if (META_PROJECT_IS_LIBRARY)
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()
endif ()
# configure "static linkage"
if ((STATIC_LINKAGE AND META_PROJECT_IS_APPLICATION) OR (STATIC_LIBRARY_LINKAGE AND META_PROJECT_IS_LIBRARY))
@ -194,7 +194,7 @@ if ((STATIC_LINKAGE AND META_PROJECT_IS_APPLICATION) OR (STATIC_LIBRARY_LINKAGE
if (META_PROJECT_IS_APPLICATION)
list(APPEND META_ADDITIONAL_LINK_FLAGS ${STATIC_LINKAGE_LINKER_FLAGS})
endif()
endif ()
list(APPEND META_ADDITIONAL_LINK_FLAGS_TEST_TARGET ${STATIC_LINKAGE_LINKER_FLAGS})
# prefer static libraries
@ -202,6 +202,6 @@ if ((STATIC_LINKAGE AND META_PROJECT_IS_APPLICATION) OR (STATIC_LIBRARY_LINKAGE
set(BOOST_USE_STATIC_LIBS ON)
configure_static_library_suffixes()
else()
else ()
set(STATIC_LINKAGE_CONFIGURED OFF)
endif()
endif ()

44
cmake/modules/AppTarget.cmake

@ -49,9 +49,7 @@ target_compile_definitions(${META_TARGET_NAME}
"${META_PUBLIC_COMPILE_DEFINITIONS}"
PRIVATE
"${META_PRIVATE_COMPILE_DEFINITIONS}")
target_compile_options(${META_TARGET_NAME}
PUBLIC "${META_PUBLIC_COMPILE_OPTIONS}"
PRIVATE "${META_PRIVATE_COMPILE_OPTIONS}")
target_compile_options(${META_TARGET_NAME} PUBLIC "${META_PUBLIC_COMPILE_OPTIONS}" PRIVATE "${META_PRIVATE_COMPILE_OPTIONS}")
set_target_properties(${META_TARGET_NAME}
PROPERTIES CXX_STANDARD
"${META_CXX_STANDARD}"
@ -160,7 +158,7 @@ find_template_file("appdata.xml" CPP_UTILITIES APP_APPSTREAM_TEMPLATE_FILE)
# define generic function to add *.desktop files
include(CMakeParseArguments)
function(add_custom_desktop_file)
function (add_custom_desktop_file)
# parse arguments
set(ONE_VALUE_ARGS
FILE_NAME
@ -169,13 +167,9 @@ function(add_custom_desktop_file)
DESKTOP_FILE_DESCRIPTION
DESKTOP_FILE_CATEGORIES
DESKTOP_FILE_CMD
DESKTOP_FILE_ICON
)
set(MULTI_VALUE_ARGS
)
set(OPTIONAL_ARGS
DESKTOP_FILE_ADDITIONAL_ENTRIES
)
DESKTOP_FILE_ICON)
set(MULTI_VALUE_ARGS)
set(OPTIONAL_ARGS DESKTOP_FILE_ADDITIONAL_ENTRIES)
cmake_parse_arguments(ARGS "${OPTIONAL_ARGS}" "${ONE_VALUE_ARGS}" "${MULTI_VALUE_ARGS}" ${ARGN})
# create desktop file from template
@ -187,7 +181,7 @@ function(add_custom_desktop_file)
endfunction ()
# define function to add *.desktop file and meta info from project meta data
function(add_desktop_file)
function (add_desktop_file)
# compose actions
set(DESKTOP_FILE_ADDITIONAL_ENTRIES "")
foreach (ACTION_VAR ${META_APP_ACTIONS})
@ -201,16 +195,22 @@ function(add_desktop_file)
endforeach ()
# create desktop file
add_custom_desktop_file(
FILE_NAME "${META_ID}"
DESKTOP_FILE_APP_NAME "${META_APP_NAME}"
DESKTOP_FILE_GENERIC_NAME "${META_GENERIC_NAME}"
DESKTOP_FILE_DESCRIPTION "${META_APP_DESCRIPTION}"
DESKTOP_FILE_CATEGORIES "${META_APP_CATEGORIES}"
DESKTOP_FILE_CMD "${META_TARGET_NAME}"
DESKTOP_FILE_ICON "${META_PROJECT_NAME}"
DESKTOP_FILE_ADDITIONAL_ENTRIES "${DESKTOP_FILE_ADDITIONAL_ENTRIES}"
)
add_custom_desktop_file(FILE_NAME
"${META_ID}"
DESKTOP_FILE_APP_NAME
"${META_APP_NAME}"
DESKTOP_FILE_GENERIC_NAME
"${META_GENERIC_NAME}"
DESKTOP_FILE_DESCRIPTION
"${META_APP_DESCRIPTION}"
DESKTOP_FILE_CATEGORIES
"${META_APP_CATEGORIES}"
DESKTOP_FILE_CMD
"${META_TARGET_NAME}"
DESKTOP_FILE_ICON
"${META_PROJECT_NAME}"
DESKTOP_FILE_ADDITIONAL_ENTRIES
"${DESKTOP_FILE_ADDITIONAL_ENTRIES}")
# read body for appstream desktop file from resources
set(META_APP_APPDATA_BODY_FILE "${CMAKE_CURRENT_SOURCE_DIR}/resources/body.appdata.xml")

18
cmake/modules/BasicConfig.cmake

@ -32,16 +32,15 @@ if (NOT META_PROJECT_VARNAME_LOWER)
string(TOLOWER "${META_PROJECT_VARNAME_LOWER}" META_PROJECT_VARNAME_LOWER)
endif ()
# allow setting a configuration name to allow installing multiple differently configured versions
# within the same prefix (intended to be used for installing Qt 5 and Qt 6 version or shared and
# static version within the same prefix)
# allow setting a configuration name to allow installing multiple differently configured versions within the same prefix
# (intended to be used for installing Qt 5 and Qt 6 version or shared and static version within the same prefix)
set(${META_PROJECT_VARNAME_UPPER}_CONFIGURATION_NAME "" CACHE STRING "sets the configuration name for ${META_PROJECT_NAME}")
set(CONFIGURATION_NAME "" CACHE STRING "sets the configuration name for all projects within the current build")
if (${META_PROJECT_VARNAME_UPPER}_CONFIGURATION_NAME STREQUAL "none")
set(META_CONFIG_NAME "")
elseif (${META_PROJECT_VARNAME_UPPER}_CONFIGURATION_NAME)
set(META_CONFIG_NAME "${${META_PROJECT_VARNAME_UPPER}_CONFIGURATION_NAME}")
else()
else ()
set(META_CONFIG_NAME "${CONFIGURATION_NAME}")
endif ()
if (META_CONFIG_NAME)
@ -49,10 +48,11 @@ if (META_CONFIG_NAME)
set(META_CONFIG_SUFFIX "-${META_CONFIG_NAME}")
endif ()
# allow setting a library/application target suffix - A different configuration name might not require
# a different target name since it might differ anyways (e.g. library extensions for static and shared
# configuration). Hence there's not simply the configuration name used to distinguish targets as well.
set(${META_PROJECT_VARNAME_UPPER}_CONFIGURATION_TARGET_SUFFIX "" CACHE STRING "sets a target suffix for ${META_PROJECT_NAME}")
# allow setting a library/application target suffix - A different configuration name might not require a different target
# name since it might differ anyways (e.g. library extensions for static and shared configuration). Hence there's not simply
# the configuration name used to distinguish targets as well.
set(${META_PROJECT_VARNAME_UPPER}_CONFIGURATION_TARGET_SUFFIX ""
CACHE STRING "sets a target suffix for ${META_PROJECT_NAME}")
set(CONFIGURATION_TARGET_SUFFIX "" CACHE STRING "sets the target suffix for all projects within the current build")
if (${META_PROJECT_VARNAME_UPPER}_CONFIGURATION_TARGET_SUFFIX STREQUAL "none")
set(TARGET_SUFFIX "")
@ -64,7 +64,7 @@ endif ()
# define a few variables
set(META_TARGET_NAME "${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}")
SET(META_DATA_DIR "share/${META_PROJECT_NAME}${META_CONFIG_SUFFIX}")
set(META_DATA_DIR "share/${META_PROJECT_NAME}${META_CONFIG_SUFFIX}")
string(TOUPPER "${CMAKE_BUILD_TYPE}" META_CURRENT_CONFIGURATION)
# set META_GENERIC_NAME to META_APP_NAME if not specified explicitely

9
cmake/modules/ConfigHeader.cmake

@ -22,7 +22,7 @@ unset(HAVE_OPENSSL)
# get list of dependencies the main target links to
if (NOT META_HEADER_ONLY_LIB)
get_target_property(LINK_LIBRARIES_LIST "${META_TARGET_NAME}" LINK_LIBRARIES)
endif()
endif ()
get_target_property(INTERFACE_LINK_LIBRARIES_LIST "${META_TARGET_NAME}" INTERFACE_LINK_LIBRARIES)
# make list with link-time dependency versions and display names
@ -30,7 +30,7 @@ foreach (DEPENDENCY IN LISTS LINK_LIBRARIES_LIST INTERFACE_LINK_LIBRARIES_LIST)
# skip non-targets and already processed dependencies
if (NOT TARGET "${DEPENDENCY}" OR "${DEPENDENCY}" IN_LIST PROCESSED_DEPENDENCIES)
continue()
endif()
endif ()
# find version and display name for target
unset(DEPENDENCY_VER)
@ -77,10 +77,7 @@ configure_file("${CONFIG_H_TEMPLATE_FILE}" "${CMAKE_CURRENT_BINARY_DIR}/resource
# ensure generated include files can be included via #include "resources/config.h"
if (NOT META_HEADER_ONLY_LIB)
foreach (TARGET_NAME
${META_TARGET_NAME}
${META_TARGET_NAME}_tests
${META_TARGET_NAME}_testlib)
foreach (TARGET_NAME ${META_TARGET_NAME} ${META_TARGET_NAME}_tests ${META_TARGET_NAME}_testlib)
if (TARGET ${TARGET_NAME})
target_include_directories(${TARGET_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
endif ()

18
cmake/modules/Doxygen.cmake

@ -27,10 +27,7 @@ else ()
set(HAVE_DOT "NO")
endif ()
if (NOT DOXYGEN_BIN)
message(
WARNING
"Doxygen not found, unable to add target for generating API documentation for ${META_TARGET_NAME}"
)
message(WARNING "Doxygen not found, unable to add target for generating API documentation for ${META_TARGET_NAME}")
return()
endif ()
@ -61,8 +58,7 @@ list_to_string(" " "\"${DOXY_PATH_PREFIX}" "\"" "${DOXY_INPUT_FILES}" DOXY_INPUT
configure_file("${DOXYGEN_TEMPLATE_FILE}" "${CMAKE_CURRENT_BINARY_DIR}/doxygen.config")
# add target for generating API documentation
add_custom_target("${META_TARGET_NAME}_apidoc"
COMMAND "${DOXYGEN_BIN}" "${CMAKE_CURRENT_BINARY_DIR}/doxygen.config")
add_custom_target("${META_TARGET_NAME}_apidoc" COMMAND "${DOXYGEN_BIN}" "${CMAKE_CURRENT_BINARY_DIR}/doxygen.config")
if (NOT TARGET apidoc)
add_custom_target(apidoc)
endif ()
@ -70,10 +66,7 @@ add_dependencies(apidoc "${META_TARGET_NAME}_apidoc")
# add install target for API documentation
if (NOT META_NO_INSTALL_TARGETS AND ENABLE_INSTALL_TARGETS)
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/api-doc"
DESTINATION "${META_DATA_DIR}"
COMPONENT api-doc
OPTIONAL)
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/api-doc" DESTINATION "${META_DATA_DIR}" COMPONENT api-doc OPTIONAL)
if (NOT TARGET install-api-doc)
add_custom_target(install-api-doc
COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=api-doc -P
@ -81,7 +74,4 @@ if (NOT META_NO_INSTALL_TARGETS AND ENABLE_INSTALL_TARGETS)
endif ()
endif ()
message(
STATUS
"Generating target for generating API documentation for ${META_TARGET_NAME} with Doxygen"
)
message(STATUS "Generating target for generating API documentation for ${META_TARGET_NAME} with Doxygen")

118
cmake/modules/LibraryTarget.cmake

@ -47,7 +47,7 @@ endif (MINGW)
# set compile definitions for static build
if (NOT BUILD_SHARED_LIBS)
list(APPEND META_PUBLIC_COMPILE_DEFINITIONS ${META_PROJECT_VARNAME_UPPER}_STATIC)
endif()
endif ()
# add global library-specific header
find_template_file("global.h" CPP_UTILITIES GLOBAL_H_TEMPLATE_FILE)
@ -100,26 +100,23 @@ if (BUILD_SHARED_LIBS)
else ()
set(META_LIBRARY_TYPE SHARED)
endif ()
else()
else ()
set(META_LIBRARY_TYPE STATIC)
endif()
endif ()
# add library to be created, set libs to link against, set version and C++ standard
if (META_HEADER_ONLY_LIB)
add_library(${META_TARGET_NAME} INTERFACE)
target_link_libraries(${META_TARGET_NAME}
INTERFACE ${META_ADDITIONAL_LINK_FLAGS} "${PUBLIC_LIBRARIES}" "${PRIVATE_LIBRARIES}")
target_include_directories(
${META_TARGET_NAME}
INTERFACE $<BUILD_INTERFACE:${TARGET_INCLUDE_DIRECTORY_BUILD_INTERFACE}>
$<INSTALL_INTERFACE:${HEADER_INSTALL_DESTINATION}> ${PUBLIC_INCLUDE_DIRS})
target_include_directories(${META_TARGET_NAME}
INTERFACE $<BUILD_INTERFACE:${TARGET_INCLUDE_DIRECTORY_BUILD_INTERFACE}>
$<INSTALL_INTERFACE:${HEADER_INSTALL_DESTINATION}> ${PUBLIC_INCLUDE_DIRS})
target_compile_definitions(${META_TARGET_NAME}
INTERFACE
"${META_PUBLIC_COMPILE_DEFINITIONS}"
"${META_PRIVATE_COMPILE_DEFINITIONS}")
target_compile_options(${META_TARGET_NAME}
INTERFACE "${META_PUBLIC_COMPILE_OPTIONS}"
"${META_PRIVATE_COMPILE_OPTIONS}")
target_compile_options(${META_TARGET_NAME} INTERFACE "${META_PUBLIC_COMPILE_OPTIONS}" "${META_PRIVATE_COMPILE_OPTIONS}")
else ()
add_library(${META_TARGET_NAME} ${META_LIBRARY_TYPE} ${ALL_FILES})
target_link_libraries(${META_TARGET_NAME}
@ -161,11 +158,18 @@ endforeach ()
# populate META_PRIVATE_LIB_DEPENDS (only required when building static libraries)
if (NOT BUILD_SHARED_LIBS)
foreach (DEPENDENCY ${PRIVATE_LIBRARIES})
if (NOT "${DEPENDENCY}" IN_LIST META_PUBLIC_LIB_DEPENDS AND NOT "${DEPENDENCY}" IN_LIST META_PRIVATE_LIB_DEPENDS)
if (NOT
"${DEPENDENCY}"
IN_LIST
META_PUBLIC_LIB_DEPENDS
AND NOT
"${DEPENDENCY}"
IN_LIST
META_PRIVATE_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)
@ -182,9 +186,8 @@ if (META_HEADER_ONLY_LIB)
INTERFACE
"${META_PUBLIC_LIB_COMPILE_DEFINITIONS}"
"${META_PRIVATE_LIB_COMPILE_DEFINITIONS}")
target_compile_options(
${META_TARGET_NAME}_interface_sources_for_qtcreator
INTERFACE "${META_PUBLIC_LIB_COMPILE_OPTIONS}" "${META_PRIVATE_LIB_COMPILE_OPTIONS}")
target_compile_options(${META_TARGET_NAME}_interface_sources_for_qtcreator
INTERFACE "${META_PUBLIC_LIB_COMPILE_OPTIONS}" "${META_PRIVATE_LIB_COMPILE_OPTIONS}")
set_target_properties(${META_TARGET_NAME}_interface_sources_for_qtcreator
PROPERTIES VERSION
"${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH}"
@ -206,15 +209,15 @@ endif ()
find_template_file("Config.cmake" CPP_UTILITIES CONFIG_TEMPLATE_FILE)
foreach (CONFIG_TARGET ${CONFIG_TARGETS})
configure_package_config_file("${CONFIG_TEMPLATE_FILE}"
"${CONFIG_TARGET}"
INSTALL_DESTINATION
"${CMAKE_CONFIG_INSTALL_DESTINATION}"
PATH_VARS
CMAKE_MODULE_INSTALL_DESTINATION
CMAKE_CONFIG_INSTALL_DESTINATION
HEADER_INSTALL_DESTINATION
BIN_INSTALL_DESTINATION
LIB_INSTALL_DESTINATION)
"${CONFIG_TARGET}"
INSTALL_DESTINATION
"${CMAKE_CONFIG_INSTALL_DESTINATION}"
PATH_VARS
CMAKE_MODULE_INSTALL_DESTINATION
CMAKE_CONFIG_INSTALL_DESTINATION
HEADER_INSTALL_DESTINATION
BIN_INSTALL_DESTINATION
LIB_INSTALL_DESTINATION)
endforeach ()
list(APPEND CMAKE_CONFIG_FILES "${CMAKE_CURRENT_BINARY_DIR}/${META_PROJECT_NAME}${META_CONFIG_SUFFIX}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${META_PROJECT_NAME}${META_CONFIG_SUFFIX}ConfigVersion.cmake")
@ -245,19 +248,21 @@ macro (compute_dependencies_for_package_config DEPENDS OUTPUT_VAR_PKGS OUTPUT_VA
if (EXISTS "${${DEPENDENCY_VARNAME}_INTERFACE_LINK_LIBRARIES}")
set(${OUTPUT_VAR_LIBS} "${${OUTPUT_VAR_LIBS}} ${${DEPENDENCY_VARNAME}_INTERFACE_LINK_LIBRARIES}")
continue()
endif()
endif ()
if (META_CURRENT_CONFIGURATION)
get_target_property("${DEPENDENCY_VARNAME}_IMPORTED_LOCATION_${META_CURRENT_CONFIGURATION}" "${DEPENDENCY}" "IMPORTED_LOCATION_${META_CURRENT_CONFIGURATION}")
get_target_property("${DEPENDENCY_VARNAME}_IMPORTED_LOCATION_${META_CURRENT_CONFIGURATION}" "${DEPENDENCY}"
"IMPORTED_LOCATION_${META_CURRENT_CONFIGURATION}")
if (EXISTS "${${DEPENDENCY_VARNAME}_IMPORTED_LOCATION_${META_CURRENT_CONFIGURATION}}")
set(${OUTPUT_VAR_LIBS} "${${OUTPUT_VAR_LIBS}} ${${DEPENDENCY_VARNAME}_IMPORTED_LOCATION_${META_CURRENT_CONFIGURATION}}")
set(${OUTPUT_VAR_LIBS}
"${${OUTPUT_VAR_LIBS}} ${${DEPENDENCY_VARNAME}_IMPORTED_LOCATION_${META_CURRENT_CONFIGURATION}}")
continue()
endif()
endif()
endif ()
endif ()
get_target_property("${DEPENDENCY_VARNAME}_IMPORTED_LOCATION" "${DEPENDENCY}" IMPORTED_LOCATION)
if (EXISTS "${${DEPENDENCY_VARNAME}_IMPORTED_LOCATION}")
set(${OUTPUT_VAR_LIBS} "${${OUTPUT_VAR_LIBS}} ${${DEPENDENCY_VARNAME}_IMPORTED_LOCATION}")
continue()
endif()
endif ()
else ()
# add raw dependency
set(${OUTPUT_VAR_LIBS} "${${OUTPUT_VAR_LIBS}} ${DEPENDENCY}")
@ -267,8 +272,7 @@ endmacro ()
compute_dependencies_for_package_config(META_PUBLIC_LIB_DEPENDS META_PUBLIC_PC_PKGS META_PUBLIC_LIB_DEPENDS_FOR_PC)
compute_dependencies_for_package_config(META_PRIVATE_LIB_DEPENDS META_PRIVATE_PC_PKGS META_PRIVATE_LIB_DEPENDS_FOR_PC)
if (NOT META_HEADER_ONLY_LIB)
set(META_PUBLIC_LIB_DEPENDS_FOR_PC
" -l${META_TARGET_NAME}${META_PUBLIC_LIB_DEPENDS_FOR_PC}")
set(META_PUBLIC_LIB_DEPENDS_FOR_PC " -l${META_TARGET_NAME}${META_PUBLIC_LIB_DEPENDS_FOR_PC}")
endif ()
if (META_PUBLIC_LIB_DEPENDS_FOR_PC)
set(META_PUBLIC_LIB_DEPENDS_FOR_PC " -L\${libdir}${META_PUBLIC_LIB_DEPENDS_FOR_PC}")
@ -326,13 +330,16 @@ if (NOT META_NO_INSTALL_TARGETS AND ENABLE_INSTALL_TARGETS)
else ()
if (COMMAND query_qmake_variable)
query_qmake_variable(QT_INSTALL_PLUGINS)
endif()
endif ()
if (QT_INSTALL_PLUGINS)
set(LIBRARY_DESTINATION ${QT_INSTALL_PLUGINS})
else()
else ()
set(LIBRARY_DESTINATION lib${SELECTED_LIB_SUFFIX}/qt/plugins)
message(WARNING "Unable to detect appropriate install directory for Qt plugins (assuming \"${LIBRARY_DESTINATION}\").")
endif()
message(
WARNING
"Unable to detect appropriate install directory for Qt plugins (assuming \"${LIBRARY_DESTINATION}\")."
)
endif ()
endif ()
if (META_PLUGIN_CATEGORY)
set(LIBRARY_DESTINATION ${LIBRARY_DESTINATION}/${META_PLUGIN_CATEGORY})
@ -358,7 +365,9 @@ if (NOT META_NO_INSTALL_TARGETS AND ENABLE_INSTALL_TARGETS)
if (NOT META_IS_PLUGIN)
foreach (HEADER_FILE ${HEADER_FILES} ${ADDITIONAL_HEADER_FILES})
get_filename_component(HEADER_DIR "${HEADER_FILE}" DIRECTORY)
install(FILES "${HEADER_FILE}" DESTINATION "${INCLUDE_SUBDIR}/${META_PROJECT_NAME}/${HEADER_DIR}" COMPONENT header)
install(FILES "${HEADER_FILE}"
DESTINATION "${INCLUDE_SUBDIR}/${META_PROJECT_NAME}/${HEADER_DIR}"
COMPONENT header)
endforeach ()
if (NOT TARGET install-header)
add_custom_target(install-header
@ -370,9 +379,7 @@ if (NOT META_NO_INSTALL_TARGETS AND ENABLE_INSTALL_TARGETS)
# add install target for CMake modules
foreach (CMAKE_MODULE_FILE ${CMAKE_MODULE_FILES})
get_filename_component(CMAKE_MODULE_DIR ${CMAKE_MODULE_FILE} DIRECTORY)
install(FILES ${CMAKE_MODULE_FILE}
DESTINATION ${META_DATA_DIR}/${CMAKE_MODULE_DIR}
COMPONENT cmake-modules)
install(FILES ${CMAKE_MODULE_FILE} DESTINATION ${META_DATA_DIR}/${CMAKE_MODULE_DIR} COMPONENT cmake-modules)
endforeach ()
if (NOT TARGET install-cmake-modules)
add_custom_target(install-cmake-modules
@ -383,9 +390,7 @@ if (NOT META_NO_INSTALL_TARGETS AND ENABLE_INSTALL_TARGETS)
# add install target for CMake templates
foreach (CMAKE_TEMPLATE_FILE ${CMAKE_TEMPLATE_FILES})
get_filename_component(CMAKE_TEMPLATE_DIR ${CMAKE_TEMPLATE_FILE} DIRECTORY)
install(FILES ${CMAKE_TEMPLATE_FILE}
DESTINATION ${META_DATA_DIR}/${CMAKE_TEMPLATE_DIR}
COMPONENT cmake-templates)
install(FILES ${CMAKE_TEMPLATE_FILE} DESTINATION ${META_DATA_DIR}/${CMAKE_TEMPLATE_DIR} COMPONENT cmake-templates)
endforeach ()
if (NOT TARGET install-cmake-templates)
add_custom_target(install-cmake-templates
@ -422,26 +427,17 @@ if (NOT META_NO_INSTALL_TARGETS AND ENABLE_INSTALL_TARGETS)
if (BUILD_SHARED_LIBS AND NOT META_HEADER_ONLY_LIB)
add_custom_target(
install-${META_TARGET_NAME}-mingw-w64-importlib-strip
COMMAND
"${STRIP_BINARY_PATH}" -g
"\$\{DESTDIR\}\$\{DESTDIR:+/\}${CMAKE_INSTALL_PREFIX}/lib/lib${META_TARGET_NAME}.dll.a"
)
add_dependencies(install-${META_TARGET_NAME}-mingw-w64-importlib-strip
install-binary-strip)
add_dependencies(install-mingw-w64-strip
install-${META_TARGET_NAME}-mingw-w64-importlib-strip)
COMMAND "${STRIP_BINARY_PATH}" -g
"\$\{DESTDIR\}\$\{DESTDIR:+/\}${CMAKE_INSTALL_PREFIX}/lib/lib${META_TARGET_NAME}.dll.a")
add_dependencies(install-${META_TARGET_NAME}-mingw-w64-importlib-strip install-binary-strip)
add_dependencies(install-mingw-w64-strip install-${META_TARGET_NAME}-mingw-w64-importlib-strip)
endif ()
if (BUILD_STATIC_LIBS AND NOT META_HEADER_ONLY_LIB)
add_custom_target(
install-${META_TARGET_NAME}-mingw-w64-staticlib-strip
COMMAND
"${STRIP_BINARY_PATH}" -g
"\$\{DESTDIR\}\$\{DESTDIR:+/\}${CMAKE_INSTALL_PREFIX}/lib/lib${META_TARGET_NAME}.a"
)
add_dependencies(install-${META_TARGET_NAME}-mingw-w64-staticlib-strip
install-binary-strip)
add_dependencies(install-mingw-w64-strip
install-${META_TARGET_NAME}-mingw-w64-staticlib-strip)
add_custom_target(install-${META_TARGET_NAME}-mingw-w64-staticlib-strip
COMMAND "${STRIP_BINARY_PATH}" -g
"\$\{DESTDIR\}\$\{DESTDIR:+/\}${CMAKE_INSTALL_PREFIX}/lib/lib${META_TARGET_NAME}.a")
add_dependencies(install-${META_TARGET_NAME}-mingw-w64-staticlib-strip install-binary-strip)
add_dependencies(install-mingw-w64-strip install-${META_TARGET_NAME}-mingw-w64-staticlib-strip)
endif ()
endif ()
endif ()

51
cmake/modules/TestTarget.cmake

@ -81,10 +81,7 @@ if (EXCLUDE_TESTS_FROM_ALL)
else ()
unset(TESTS_EXCLUSION)
endif ()
add_executable(${META_TARGET_NAME}_tests
${TESTS_EXCLUSION}
${TEST_HEADER_FILES}
${TEST_SRC_FILES})
add_executable(${META_TARGET_NAME}_tests ${TESTS_EXCLUSION} ${TEST_HEADER_FILES} ${TEST_SRC_FILES})
# add top-level target to build all test targets conveniently, also when excluded from "all" target
if (NOT TARGET tests)
@ -141,8 +138,7 @@ if (META_PROJECT_IS_APPLICATION)
# link tests against it
list(APPEND TEST_LIBRARIES ${META_TARGET_NAME}_testlib)
# ensure all symbols are visible (man gcc: "Despite the nomenclature, default always means public")
set_target_properties(${META_TARGET_NAME}_testlib
PROPERTIES CXX_VISIBILITY_PRESET default)
set_target_properties(${META_TARGET_NAME}_testlib PROPERTIES CXX_VISIBILITY_PRESET default)
endif ()
endif ()
@ -184,23 +180,16 @@ endif ()
# enable source code based coverage analysis using clang
if (CLANG_SOURCE_BASED_COVERAGE_AVAILABLE)
# define path of raw profile data
set(LLVM_PROFILE_RAW_FILE
"${CMAKE_CURRENT_BINARY_DIR}/${META_TARGET_NAME}_tests.profraw")
set(LLVM_PROFILE_RAW_FILE "${CMAKE_CURRENT_BINARY_DIR}/${META_TARGET_NAME}_tests.profraw")
# define path of list with additional raw profile data from fork processes spawned during tests
set(LLVM_PROFILE_RAW_LIST_FILE
"${CMAKE_CURRENT_BINARY_DIR}/${META_TARGET_NAME}_tests.profraw.list")
set(LLVM_PROFILE_RAW_LIST_FILE "${CMAKE_CURRENT_BINARY_DIR}/${META_TARGET_NAME}_tests.profraw.list")
# define path of merged profile data generated from raw profiling data
set(LLVM_PROFILE_DATA_FILE
"${CMAKE_CURRENT_BINARY_DIR}/${META_TARGET_NAME}_tests.profdata")
set(LLVM_PROFILE_DATA_FILE "${CMAKE_CURRENT_BINARY_DIR}/${META_TARGET_NAME}_tests.profdata")
# define paths of output files
set(COVERAGE_REPORT_FILE
"${CMAKE_CURRENT_BINARY_DIR}/${META_TARGET_NAME}_tests_coverage.txt")
set(COVERAGE_PER_FILE_REPORT_FILE
"${CMAKE_CURRENT_BINARY_DIR}/${META_TARGET_NAME}_tests_coverage_per_file.txt")
set(COVERAGE_OVERALL_REPORT_FILE
"${CMAKE_CURRENT_BINARY_DIR}/${META_TARGET_NAME}_tests_coverage_overall.txt")
set(COVERAGE_HTML_REPORT_FILE
"${CMAKE_CURRENT_BINARY_DIR}/${META_TARGET_NAME}_tests_coverage.html")
set(COVERAGE_REPORT_FILE "${CMAKE_CURRENT_BINARY_DIR}/${META_TARGET_NAME}_tests_coverage.txt")
set(COVERAGE_PER_FILE_REPORT_FILE "${CMAKE_CURRENT_BINARY_DIR}/${META_TARGET_NAME}_tests_coverage_per_file.txt")
set(COVERAGE_OVERALL_REPORT_FILE "${CMAKE_CURRENT_BINARY_DIR}/${META_TARGET_NAME}_tests_coverage_overall.txt")
set(COVERAGE_HTML_REPORT_FILE "${CMAKE_CURRENT_BINARY_DIR}/${META_TARGET_NAME}_tests_coverage.html")
set(COVERAGE_REPORT_FILES "${COVERAGE_REPORT_FILE}")
# specify where to store raw clang profiling data via environment variable
@ -215,12 +204,10 @@ if (CLANG_SOURCE_BASED_COVERAGE_AVAILABLE)
add_custom_command(
OUTPUT "${LLVM_PROFILE_RAW_FILE}" "${LLVM_PROFILE_RAW_LIST_FILE}"
COMMAND "${CMAKE_COMMAND}" -E env "LLVM_PROFILE_FILE=${LLVM_PROFILE_RAW_FILE}"
"LLVM_PROFILE_LIST_FILE=${LLVM_PROFILE_RAW_LIST_FILE}"
$<TARGET_FILE:${META_TARGET_NAME}_tests> -p
"LLVM_PROFILE_LIST_FILE=${LLVM_PROFILE_RAW_LIST_FILE}" $<TARGET_FILE:${META_TARGET_NAME}_tests> -p
"${CMAKE_CURRENT_SOURCE_DIR}/testfiles" -w "${CMAKE_CURRENT_BINARY_DIR}/testworkingdir"
${RUN_TESTS_APPLICATION_ARGS}
COMMENT
"Executing ${META_TARGET_NAME}_tests to generate raw profiling data for source-based coverage report"
COMMENT "Executing ${META_TARGET_NAME}_tests to generate raw profiling data for source-based coverage report"
DEPENDS "${META_TARGET_NAME}_tests")
# add commands for processing raw profiling data
@ -250,8 +237,7 @@ if (CLANG_SOURCE_BASED_COVERAGE_AVAILABLE)
# determine the target file for llvm-cov
if (NOT META_HEADER_ONLY_LIB)
set(LLVM_COV_TARGET_FILE $<TARGET_FILE:${META_TARGET_NAME}>
$<TARGET_FILE:${META_TARGET_NAME}_tests>)
set(LLVM_COV_TARGET_FILE $<TARGET_FILE:${META_TARGET_NAME}> $<TARGET_FILE:${META_TARGET_NAME}_tests>)
else ()
set(LLVM_COV_TARGET_FILE $<TARGET_FILE:${META_TARGET_NAME}_tests>)
endif ()
@ -286,11 +272,10 @@ if (CLANG_SOURCE_BASED_COVERAGE_AVAILABLE)
endif ()
# add target for the coverage reports
add_custom_target("${META_TARGET_NAME}_tests_coverage_summary"
DEPENDS ${COVERAGE_REPORT_FILES})
add_custom_target("${META_TARGET_NAME}_tests_coverage_summary" DEPENDS ${COVERAGE_REPORT_FILES})
# NOTE: Those commands have been added before the release of LLVM 5 where coverage reports
# with statistics per file could not be generated.
# NOTE: Those commands have been added before the release of LLVM 5 where coverage reports with statistics per file
# could not be generated.
# generate coverage overall report (total region/line coverage)
set(OVERALL_COVERAGE_AKW_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/tests/calculateoverallcoverage.awk")
@ -305,8 +290,7 @@ if (CLANG_SOURCE_BASED_COVERAGE_AVAILABLE)
"${COVERAGE_OVERALL_REPORT_FILE}"
COMMENT "Generating coverage report (overall figures)"
DEPENDS "${OVERALL_COVERAGE_AKW_SCRIPT}" "${COVERAGE_REPORT_FILE}")
add_custom_target("${META_TARGET_NAME}_tests_coverage_overall_summary"
DEPENDS "${COVERAGE_OVERALL_REPORT_FILE}")
add_custom_target("${META_TARGET_NAME}_tests_coverage_overall_summary" DEPENDS "${COVERAGE_OVERALL_REPORT_FILE}")
# generate HTML document showing covered/uncovered code
add_custom_command(OUTPUT "${COVERAGE_HTML_REPORT_FILE}"
@ -316,8 +300,7 @@ if (CLANG_SOURCE_BASED_COVERAGE_AVAILABLE)
COMMENT "Generating HTML document showing covered/uncovered code"
DEPENDS "${LLVM_PROFILE_DATA_FILE}"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
add_custom_target("${META_TARGET_NAME}_tests_coverage_html"
DEPENDS "${COVERAGE_HTML_REPORT_FILE}")
add_custom_target("${META_TARGET_NAME}_tests_coverage_html" DEPENDS "${COVERAGE_HTML_REPORT_FILE}")
# create target for all coverage docs
add_custom_target("${META_TARGET_NAME}_tests_coverage"

Loading…
Cancel
Save