All new build system

This is based on GavinNL/cpp_library_template, which seems to be a
bit closer to meeting my needs.
This commit is contained in:
James P. Howard, II
2020-09-24 13:14:18 -04:00
parent 870e7b8cfc
commit 7d5482c082
86 changed files with 2124 additions and 871 deletions

View File

@@ -1,158 +0,0 @@
# 2012-01-31, Lars Bilke
# - Enable Code Coverage
#
# 2013-09-17, Joakim Söderberg
# - Added support for Clang.
# - Some additional usage instructions.
#
# 2018-03-31, Bendik Samseth
# - Relax debug output.
# - Keep a copy of the coverage output for later use.
# - Updated coverage exclude patterns.
#
# 2018-01-03, HenryRLee
# - Allow for *Clang compiler names, not just Clang.
#
# 2018-01-03, Bendik Samseth
# - Only check compiler compatibility if in a coverage build.
#
#
# USAGE:
# 0. (Mac only) If you use Xcode 5.1 make sure to patch geninfo as described here:
# http://stackoverflow.com/a/22404544/80480
#
# 1. Copy this file into your cmake modules path.
#
# 2. Add the following line to your CMakeLists.txt:
# INCLUDE(CodeCoverage)
#
# 3. Set compiler flags to turn off optimization and enable coverage:
# SET(CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
# SET(CMAKE_C_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
#
# 3. Use the function SETUP_TARGET_FOR_COVERAGE to create a custom make target
# which runs your test executable and produces a lcov code coverage report:
# Example:
# SETUP_TARGET_FOR_COVERAGE(
# my_coverage_target # Name for custom target.
# test_driver # Name of the test driver executable that runs the tests.
# # NOTE! This should always have a ZERO as exit code
# # otherwise the coverage generation will not complete.
# coverage # Name of output directory.
# )
#
# 4. Build a Debug build:
# cmake -DCMAKE_BUILD_TYPE=Debug ..
# make
# make my_coverage_target
#
#
# Param _targetname The name of new the custom make target
# Param _testrunner The name of the target which runs the tests.
# MUST return ZERO always, even on errors.
# If not, no coverage report will be created!
# Param _outputname lcov output is generated as _outputname.info
# HTML report is generated in _outputname/index.html
# Optional fourth parameter is passed as arguments to _testrunner
# Pass them in list form, e.g.: "-j;2" for -j 2
FUNCTION(SETUP_TARGET_FOR_COVERAGE _targetname _testrunner _outputname)
IF(NOT LCOV_PATH)
MESSAGE(FATAL_ERROR "lcov not found! Aborting...")
ENDIF() # NOT LCOV_PATH
IF(NOT GENHTML_PATH)
MESSAGE(FATAL_ERROR "genhtml not found! Aborting...")
ENDIF() # NOT GENHTML_PATH
# Setup target
ADD_CUSTOM_TARGET(${_targetname}
# Cleanup lcov
${LCOV_PATH} --directory . --zerocounters
# Run tests
COMMAND ${_testrunner} ${ARGV3}
# Capturing lcov counters and generating report
COMMAND ${LCOV_PATH} --directory . --capture --output-file ${_outputname}.info
COMMAND ${LCOV_PATH} --remove ${_outputname}.info '*/tests/*' '/usr/*' '*/external/*' '/Applications/*' --output-file ${_outputname}.info.cleaned
COMMAND ${GENHTML_PATH} -o ${_outputname} ${_outputname}.info.cleaned
COMMAND ${LCOV_PATH} --list ${_outputname}.info.cleaned
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report."
)
# Show info where to find the report
ADD_CUSTOM_COMMAND(TARGET ${_targetname} POST_BUILD
COMMAND ;
COMMENT "${BoldMagenta}Open ./${_outputname}/index.html in your browser to view the coverage report.${ColourReset}"
)
ENDFUNCTION() # SETUP_TARGET_FOR_COVERAGE
string(TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_tolower)
if (cmake_build_type_tolower STREQUAL "coverage")
# Check prereqs
FIND_PROGRAM( GCOV_PATH gcov )
FIND_PROGRAM( LCOV_PATH lcov )
FIND_PROGRAM( GENHTML_PATH genhtml )
FIND_PROGRAM( GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/tests)
IF(NOT GCOV_PATH)
MESSAGE(FATAL_ERROR "gcov not found! Aborting...")
ENDIF() # NOT GCOV_PATH
IF(NOT CMAKE_COMPILER_IS_GNUCXX)
IF(NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES ".*Clang")
MESSAGE(FATAL_ERROR "Compiler is not GNU gcc or Clang! Aborting...")
ENDIF()
ENDIF() # NOT CMAKE_COMPILER_IS_GNUCXX
SET(CMAKE_CXX_FLAGS_COVERAGE
"-g -O0 -fprofile-arcs -ftest-coverage"
CACHE STRING "Flags used by the C++ compiler during coverage builds."
FORCE )
SET(CMAKE_C_FLAGS_COVERAGE
"-g -O0 -fprofile-arcs -ftest-coverage"
CACHE STRING "Flags used by the C compiler during coverage builds."
FORCE )
SET(CMAKE_EXE_LINKER_FLAGS_COVERAGE
""
CACHE STRING "Flags used for linking binaries during coverage builds."
FORCE )
SET(CMAKE_SHARED_LINKER_FLAGS_COVERAGE
""
CACHE STRING "Flags used by the shared libraries linker during coverage builds."
FORCE )
MARK_AS_ADVANCED(
CMAKE_CXX_FLAGS_COVERAGE
CMAKE_C_FLAGS_COVERAGE
CMAKE_EXE_LINKER_FLAGS_COVERAGE
CMAKE_SHARED_LINKER_FLAGS_COVERAGE )
# If unwanted files are included in the coverage reports, you can
# adjust the exclude patterns on line 83.
SETUP_TARGET_FOR_COVERAGE(
coverage # Name for custom target.
${TEST_MAIN} # Name of the test driver executable that runs the tests.
# NOTE! This should always have a ZERO as exit code
# otherwise the coverage generation will not complete.
coverage_out # Name of output directory.
)
else()
add_custom_target(coverage
COMMAND echo "${Red}Code coverage only available in coverage builds."
COMMAND echo "${Green}Make a new build directory and rerun cmake with -DCMAKE_BUILD_TYPE=Coverage to enable this target.${ColorReset}"
)
endif()

View File

@@ -1,19 +0,0 @@
IF(NOT WIN32)
string(ASCII 27 Esc)
set(ColorReset "${Esc}[m")
set(ColorBold "${Esc}[1m")
set(Red "${Esc}[31m")
set(Green "${Esc}[32m")
set(Yellow "${Esc}[33m")
set(Blue "${Esc}[34m")
set(Magenta "${Esc}[35m")
set(Cyan "${Esc}[36m")
set(White "${Esc}[37m")
set(BoldRed "${Esc}[1;31m")
set(BoldGreen "${Esc}[1;32m")
set(BoldYellow "${Esc}[1;33m")
set(BoldBlue "${Esc}[1;34m")
set(BoldMagenta "${Esc}[1;35m")
set(BoldCyan "${Esc}[1;36m")
set(BoldWhite "${Esc}[1;37m")
ENDIF()

4
cmake/Config.cmake.in Normal file
View File

@@ -0,0 +1,4 @@
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake")
check_required_components("@PROJECT_NAME@")

View File

@@ -1,20 +0,0 @@
# guard against in-source builds
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there.")
endif()
# guard against bad build-type strings
if (NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected, default to Debug")
set(CMAKE_BUILD_TYPE "Debug")
endif()
string(TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_tolower)
string(TOUPPER "${CMAKE_BUILD_TYPE}" cmake_build_type_toupper)
if( NOT cmake_build_type_tolower STREQUAL "debug"
AND NOT cmake_build_type_tolower STREQUAL "release"
AND NOT cmake_build_type_tolower STREQUAL "profile"
AND NOT cmake_build_type_tolower STREQUAL "relwithdebinfo"
AND NOT cmake_build_type_tolower STREQUAL "coverage")
message(FATAL_ERROR "Unknown build type \"${CMAKE_BUILD_TYPE}\". Allowed values are Debug, Coverage, Release, Profile, RelWithDebInfo (case-insensitive).")
endif()

View File

@@ -1,6 +0,0 @@
if(ENABLE_DOCTESTS)
add_definitions(-DENABLE_DOCTEST_IN_LIBRARY)
endif()
add_library(doctest INTERFACE)
target_include_directories(doctest INTERFACE ${PROJECT_SOURCE_DIR}/external/doctest/doctest)

View File

@@ -1,15 +0,0 @@
# --------------------------------------------------------------------------------
# Documentation (no change needed).
# --------------------------------------------------------------------------------
# Add a make target 'doc' to generate API documentation with Doxygen.
# You should set options to your liking in the file 'Doxyfile.in'.
find_package(Doxygen)
if(DOXYGEN_FOUND)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
add_custom_target(doc
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile &> doxygen.log
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "${BoldMagenta}Generating API documentation with Doxygen (open ./html/index.html to view).${ColourReset}" VERBATIM
)
endif(DOXYGEN_FOUND)

View File

@@ -1,249 +0,0 @@
# Usage :
#
# Variable : ENABLE_LTO | Enable or disable LTO support for this build
#
# find_lto(lang)
# - lang is C or CXX (the language to test LTO for)
# - call it after project() so that the compiler is already detected
#
# This will check for LTO support and create a target_enable_lto(target [debug,optimized,general]) macro.
# The 2nd parameter has the same meaning as in target_link_libraries, and is used to enable LTO only for those build configurations
# 'debug' is by default the Debug configuration, and 'optimized' all the other configurations
#
# if ENABLE_LTO is set to false, an empty macro will be generated
#
# Then to enable LTO for your target use
#
# target_enable_lto(mytarget general)
#
# It is however recommended to use it only for non debug builds the following way :
#
# target_enable_lto(mytarget optimized)
#
# Note : For CMake versions < 3.9, target_link_library is used in it's non plain version.
# You will need to specify PUBLIC/PRIVATE/INTERFACE to all your other target_link_library calls for the target
#
# WARNING for cmake versions older than 3.9 :
# This module will override CMAKE_AR CMAKE_RANLIB and CMAKE_NM by the gcc versions if found when building with gcc
# License:
#
# Copyright (C) 2016 Lectem <lectem@gmail.com>
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation files
# (the 'Software') deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
macro(find_lto lang)
if(ENABLE_LTO AND NOT LTO_${lang}_CHECKED)
#LTO support was added for clang/gcc in 3.9
if(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} VERSION_LESS 3.9)
cmake_policy(SET CMP0054 NEW)
message(STATUS "Checking for LTO Compatibility")
# Since GCC 4.9 we need to use gcc-ar / gcc-ranlib / gcc-nm
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_GCC_AR OR NOT CMAKE_GCC_RANLIB OR NOT CMAKE_GCC_NM)
find_program(CMAKE_GCC_AR NAMES
"${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar"
"${_CMAKE_TOOLCHAIN_PREFIX}gcc-ar-${_version}"
DOC "gcc provided wrapper for ar which adds the --plugin option"
)
find_program(CMAKE_GCC_RANLIB NAMES
"${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib"
"${_CMAKE_TOOLCHAIN_PREFIX}gcc-ranlib-${_version}"
DOC "gcc provided wrapper for ranlib which adds the --plugin option"
)
# Not needed, but at least stay coherent
find_program(CMAKE_GCC_NM NAMES
"${_CMAKE_TOOLCHAIN_PREFIX}gcc-nm"
"${_CMAKE_TOOLCHAIN_PREFIX}gcc-nm-${_version}"
DOC "gcc provided wrapper for nm which adds the --plugin option"
)
mark_as_advanced(CMAKE_GCC_AR CMAKE_GCC_RANLIB CMAKE_GCC_NM)
set(CMAKE_LTO_AR ${CMAKE_GCC_AR})
set(CMAKE_LTO_RANLIB ${CMAKE_GCC_RANLIB})
set(CMAKE_LTO_NM ${CMAKE_GCC_NM})
endif()
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(CMAKE_LTO_AR ${CMAKE_AR})
set(CMAKE_LTO_RANLIB ${CMAKE_RANLIB})
set(CMAKE_LTO_NM ${CMAKE_NM})
endif()
if(CMAKE_LTO_AR AND CMAKE_LTO_RANLIB)
set(__lto_flags -flto)
if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 4.7)
list(APPEND __lto_flags -fno-fat-lto-objects)
endif()
if(NOT DEFINED CMAKE_${lang}_PASSED_LTO_TEST)
set(__output_dir "${CMAKE_PLATFORM_INFO_DIR}/LtoTest1${lang}")
file(MAKE_DIRECTORY "${__output_dir}")
set(__output_base "${__output_dir}/lto-test-${lang}")
execute_process(
COMMAND ${CMAKE_COMMAND} -E echo "void foo() {}"
COMMAND ${CMAKE_${lang}_COMPILER} ${__lto_flags} -c -xc -
-o "${__output_base}.o"
RESULT_VARIABLE __result
ERROR_QUIET
OUTPUT_QUIET
)
if("${__result}" STREQUAL "0")
execute_process(
COMMAND ${CMAKE_LTO_AR} cr "${__output_base}.a" "${__output_base}.o"
RESULT_VARIABLE __result
ERROR_QUIET
OUTPUT_QUIET
)
endif()
if("${__result}" STREQUAL "0")
execute_process(
COMMAND ${CMAKE_LTO_RANLIB} "${__output_base}.a"
RESULT_VARIABLE __result
ERROR_QUIET
OUTPUT_QUIET
)
endif()
if("${__result}" STREQUAL "0")
execute_process(
COMMAND ${CMAKE_COMMAND} -E echo "void foo(); int main() {foo();}"
COMMAND ${CMAKE_${lang}_COMPILER} ${__lto_flags} -xc -
-x none "${__output_base}.a" -o "${__output_base}"
RESULT_VARIABLE __result
ERROR_QUIET
OUTPUT_QUIET
)
endif()
if("${__result}" STREQUAL "0")
set(__lto_found TRUE)
endif()
set(CMAKE_${lang}_PASSED_LTO_TEST
${__lto_found} CACHE INTERNAL
"If the compiler passed a simple LTO test compile")
endif()
if(CMAKE_${lang}_PASSED_LTO_TEST)
message(STATUS "Checking for LTO Compatibility - works")
set(LTO_${lang}_SUPPORT TRUE CACHE BOOL "Do we have LTO support ?")
set(LTO_COMPILE_FLAGS -flto CACHE STRING "Link Time Optimization compile flags")
set(LTO_LINK_FLAGS -flto CACHE STRING "Link Time Optimization link flags")
else()
message(STATUS "Checking for LTO Compatibility - not working")
endif()
endif()
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
message(STATUS "Checking for LTO Compatibility - works (assumed for clang)")
set(LTO_${lang}_SUPPORT TRUE CACHE BOOL "Do we have LTO support ?")
set(LTO_COMPILE_FLAGS -flto CACHE STRING "Link Time Optimization compile flags")
set(LTO_LINK_FLAGS -flto CACHE STRING "Link Time Optimization link flags")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
message(STATUS "Checking for LTO Compatibility - works")
set(LTO_${lang}_SUPPORT TRUE CACHE BOOL "Do we have LTO support ?")
set(LTO_COMPILE_FLAGS /GL CACHE STRING "Link Time Optimization compile flags")
set(LTO_LINK_FLAGS -LTCG:INCREMENTAL CACHE STRING "Link Time Optimization link flags")
else()
message(STATUS "Checking for LTO Compatibility - compiler not handled by module")
endif()
mark_as_advanced(LTO_${lang}_SUPPORT LTO_COMPILE_FLAGS LTO_LINK_FLAGS)
set(LTO_${lang}_CHECKED TRUE CACHE INTERNAL "" )
if(CMAKE_GCC_AR AND CMAKE_GCC_RANLIB AND CMAKE_GCC_NM)
# THIS IS HACKY BUT THERE IS NO OTHER SOLUTION ATM
set(CMAKE_AR ${CMAKE_GCC_AR} CACHE FILEPATH "Forcing gcc-ar instead of ar" FORCE)
set(CMAKE_NM ${CMAKE_GCC_NM} CACHE FILEPATH "Forcing gcc-nm instead of nm" FORCE)
set(CMAKE_RANLIB ${CMAKE_GCC_RANLIB} CACHE FILEPATH "Forcing gcc-ranlib instead of ranlib" FORCE)
endif()
endif(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} VERSION_LESS 3.9)
endif(ENABLE_LTO AND NOT LTO_${lang}_CHECKED)
if(ENABLE_LTO)
#Special case for cmake older than 3.9, using a library for gcc/clang, but could setup the flags directly.
#Taking advantage of the [debug,optimized] parameter of target_link_libraries
if(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} VERSION_LESS 3.9)
if(LTO_${lang}_SUPPORT)
if(NOT TARGET __enable_lto_tgt)
add_library(__enable_lto_tgt INTERFACE)
endif()
target_compile_options(__enable_lto_tgt INTERFACE ${LTO_COMPILE_FLAGS})
#this might not work for all platforms... in which case we'll have to set the link flags on the target directly
target_link_libraries(__enable_lto_tgt INTERFACE ${LTO_LINK_FLAGS} )
macro(target_enable_lto _target _build_configuration)
if(${_build_configuration} STREQUAL "optimized" OR ${_build_configuration} STREQUAL "debug" )
target_link_libraries(${_target} PRIVATE ${_build_configuration} __enable_lto_tgt)
else()
target_link_libraries(${_target} PRIVATE __enable_lto_tgt)
endif()
endmacro()
else()
#In old cmake versions, we can set INTERPROCEDURAL_OPTIMIZATION even if not supported by the compiler
#So if we didn't detect it, let cmake give it a try
set(__IPO_SUPPORTED TRUE)
endif()
else()
cmake_policy(SET CMP0069 NEW)
include(CheckIPOSupported)
# Optional IPO. Do not use IPO if it's not supported by compiler.
check_ipo_supported(RESULT __IPO_SUPPORTED OUTPUT output)
if(NOT __IPO_SUPPORTED)
message(STATUS "IPO is not supported or broken.")
else()
message(STATUS "IPO is supported")
endif()
endif()
if(__IPO_SUPPORTED)
macro(target_enable_lto _target _build_configuration)
if(NOT ${_build_configuration} STREQUAL "debug" )
#enable for all configurations
set_target_properties(${_target} PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
if(${_build_configuration} STREQUAL "optimized" )
#blacklist debug configurations
set(__enable_debug_lto FALSE)
else()
#enable only for debug configurations
set(__enable_debug_lto TRUE)
endif()
get_property(DEBUG_CONFIGURATIONS GLOBAL PROPERTY DEBUG_CONFIGURATIONS)
if(NOT DEBUG_CONFIGURATIONS)
set(DEBUG_CONFIGURATIONS DEBUG) # This is what is done by CMAKE internally... since DEBUG_CONFIGURATIONS is empty by default
endif()
foreach(config IN LISTS DEBUG_CONFIGURATIONS)
set_target_properties(${_target} PROPERTIES INTERPROCEDURAL_OPTIMIZATION_${config} ${__enable_debug_lto})
endforeach()
endmacro()
endif()
endif()
if(NOT COMMAND target_enable_lto)
macro(target_enable_lto _target _build_configuration)
endmacro()
endif()
endmacro()

View File

@@ -1,16 +0,0 @@
# --------------------------------------------------------------------------------
# Misc (no change needed).
# --------------------------------------------------------------------------------
# Have CMake parse the config file, generating the config header, with
# correct definitions. Here only used to make version number available to
# the source code. Include "exampleConfig.h" (no .in suffix) in the source.
configure_file (
"${PROJECT_SOURCE_DIR}/include/kami/config.hpp.in"
"${PROJECT_BINARY_DIR}/include/kami/config.hpp"
)
# add the binary tree to the search path for include files
# so that we will find exampleConfig.h
include_directories("${PROJECT_BINARY_DIR}")
# Ask CMake to output a compile_commands.json file for use with things like Vim YCM.
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)

View File

@@ -1,101 +1,19 @@
# MIT License
#
# This Cmake file creates targets for better warnings
#
# Link to the following targets:
# warning::all - displays all warnings
# warning::error - treats warnings as errors
#
# Copyright (c) 2017 Lectem
add_library(warnings_all_ INTERFACE)
add_library(warning::all ALIAS warnings_all_)
target_compile_options(warnings_all_ INTERFACE -Wall -Wextra -Wpedantic)
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
set(WARNING_INSTALL_TARGET warnings_all_)
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
add_library(warnings_error_ INTERFACE)
add_library(warning::error ALIAS warnings_error_)
target_compile_options(warnings_error_ INTERFACE -Werror)
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
function(target_set_warnings)
if(NOT ENABLE_WARNINGS_SETTINGS)
return()
endif()
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(WMSVC TRUE)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(WGCC TRUE)
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(WCLANG TRUE)
endif()
set(multiValueArgs ENABLE DISABLE AS_ERROR)
cmake_parse_arguments(this "" "" "${multiValueArgs}" ${ARGN})
list(FIND this_ENABLE "ALL" enable_all)
list(FIND this_DISABLE "ALL" disable_all)
list(FIND this_AS_ERROR "ALL" as_error_all)
if(NOT ${enable_all} EQUAL -1)
if(WMSVC)
# Not all the warnings, but WAll is unusable when using libraries
# Unless you'd like to support MSVC in the code with pragmas, this is probably the best option
list(APPEND WarningFlags "/W4")
elseif(WGCC)
list(APPEND WarningFlags "-Wall" "-Wextra" "-Wpedantic")
elseif(WCLANG)
list(APPEND WarningFlags "-Wall" "-Weverything" "-Wpedantic")
endif()
elseif(NOT ${disable_all} EQUAL -1)
set(SystemIncludes TRUE) # Treat includes as if coming from system
if(WMSVC)
list(APPEND WarningFlags "/w" "/W0")
elseif(WGCC OR WCLANG)
list(APPEND WarningFlags "-w")
endif()
endif()
list(FIND this_DISABLE "Annoying" disable_annoying)
if(NOT ${disable_annoying} EQUAL -1)
if(WMSVC)
# bounds-checked functions require to set __STDC_WANT_LIB_EXT1__ which we usually don't need/want
list(APPEND WarningDefinitions -D_CRT_SECURE_NO_WARNINGS)
# disable C4514 C4710 C4711... Those are useless to add most of the time
#list(APPEND WarningFlags "/wd4514" "/wd4710" "/wd4711")
#list(APPEND WarningFlags "/wd4365") #signed/unsigned mismatch
#list(APPEND WarningFlags "/wd4668") # is not defined as a preprocessor macro, replacing with '0' for
elseif(WGCC OR WCLANG)
list(APPEND WarningFlags -Wno-switch-enum)
if(WCLANG)
list(APPEND WarningFlags -Wno-unknown-warning-option -Wno-padded -Wno-undef -Wno-reserved-id-macro -fcomment-block-commands=test,retval)
if(NOT CMAKE_CXX_STANDARD EQUAL 98)
list(APPEND WarningFlags -Wno-c++98-compat -Wno-c++98-compat-pedantic)
endif()
if ("${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC") # clang-cl has some VCC flags by default that it will not recognize...
list(APPEND WarningFlags -Wno-unused-command-line-argument)
endif()
endif(WCLANG)
endif()
endif()
if(NOT ${as_error_all} EQUAL -1)
if(WMSVC)
list(APPEND WarningFlags "/WX")
elseif(WGCC OR WCLANG)
list(APPEND WarningFlags "-Werror")
endif()
endif()
foreach(target IN LISTS this_UNPARSED_ARGUMENTS)
if(WarningFlags)
target_compile_options(${target} PRIVATE ${WarningFlags})
endif()
if(WarningDefinitions)
target_compile_definitions(${target} PRIVATE ${WarningDefinitions})
endif()
if(SystemIncludes)
set_target_properties(${target} PROPERTIES
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:${target},INTERFACE_INCLUDE_DIRECTORIES>)
endif()
endforeach()
endfunction(target_set_warnings)
set(WARNING_INSTALL_TARGET ${WARNING_INSTALL_TARGET} warnings_error_)

22
cmake/coverage.cmake Normal file
View File

@@ -0,0 +1,22 @@
if(CMAKE_COMPILER_IS_GNUCC)
add_library(coverage_ INTERFACE)
add_library(coverage::coverage ALIAS coverage_)
target_compile_options(coverage_ INTERFACE --coverage -g -O0 -fprofile-arcs -ftest-coverage)
target_link_libraries(coverage_ INTERFACE --coverage -g -O0 -fprofile-arcs -ftest-coverage)
set(COVERAGE_TARGET coverage::coverage)
set(COVERAGE_INSTALL_TARGET coverage_)
add_custom_target(coverage
COMMAND rm -rf coverage
COMMAND mkdir -p coverage
COMMAND ${CMAKE_MAKE_PROGRAM} test
COMMAND gcovr . -r ${CMAKE_SOURCE_DIR} --html-details --html -o coverage/index.html -e ${CMAKE_SOURCE_DIR}/test/third_party;
COMMAND gcovr . -r ${CMAKE_SOURCE_DIR} --xml -o coverage/report.xml -e ${CMAKE_SOURCE_DIR}/test/third_party;
COMMAND gcovr . -r ${CMAKE_SOURCE_DIR} -o coverage/report.txt -e ${CMAKE_SOURCE_DIR}/test/third_party;
COMMAND cat coverage/report.txt
WORKING_DIRECTORY ${CMAKE_BINARY_DIR} # Need separate command for this line
)
endif()

13
cmake/cppcheck.cmake Normal file
View File

@@ -0,0 +1,13 @@
add_custom_target(cppcheck
#COMMAND mkdir -p coverage
#COMMAND ${CMAKE_MAKE_PROGRAM} test
#WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
add_custom_command(TARGET cppcheck
COMMAND echo "=================== CPPCHECK ===================="
COMMAND mkdir -p ${CMAKE_BINARY_DIR}/cppcheck
COMMAND cppcheck . -I include/ --enable=all --inconclusive --xml-version=2 --force --library=windows,posix,gnu . --output-file=${CMAKE_BINARY_DIR}/cppcheck/result.xml
COMMAND cppcheck-htmlreport --source-encoding="iso8859-1" --title="mmp2top" --source-dir . --report-dir=${CMAKE_BINARY_DIR}/cppcheck --file=${CMAKE_BINARY_DIR}/cppcheck/result.xml
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} # Need separate command for this line
)

663
cmake/functions.cmake Normal file
View File

@@ -0,0 +1,663 @@
include(GenerateExportHeader)
if(NOT WIN32)
string(ASCII 27 Esc)
set(ColourReset "${Esc}[m")
set(ColourBold "${Esc}[1m")
set(Red "${Esc}[31m")
set(Green "${Esc}[32m")
set(Yellow "${Esc}[33m")
set(Blue "${Esc}[34m")
set(Magenta "${Esc}[35m")
set(Cyan "${Esc}[36m")
set(White "${Esc}[37m")
set(BoldRed "${Esc}[1;31m")
set(BoldGreen "${Esc}[1;32m")
set(BoldYellow "${Esc}[1;33m")
set(BoldBlue "${Esc}[1;34m")
set(BoldMagenta "${Esc}[1;35m")
set(BoldCyan "${Esc}[1;36m")
set(BoldWhite "${Esc}[1;37m")
endif()
MACRO(directory_list result curdir)
FILE(GLOB children RELATIVE ${curdir} ${curdir}/*)
SET(dirlist "")
FOREACH(child ${children})
IF(IS_DIRECTORY ${curdir}/${child} )
LIST(APPEND dirlist ${child})
ENDIF()
ENDFOREACH()
SET(${result} ${dirlist})
ENDMACRO()
MACRO(print_list result)
foreach(arg IN LISTS ${result})
message(" - ${arg}")
endforeach()
ENDMACRO()
MACRO(print_list_label Label ListVar)
message("${Label}:")
print_list(${ListVar})
ENDMACRO()
# create_library( NAME myLibrary
# NAMESPACE myNamespace
# SOURCES
# myLib.cpp
# myLib_functions.cpp
# PUBLIC_DEFINITIONS
# USE_DOUBLE_PRECISION=1
# PRIVATE_DEFINITIONS
# DEBUG_VERBOSE
# PUBLIC_INCLUDE_PATHS
# ${CMAKE_SOURCE_DIR}/mylib/include
# PRIVATE_INCLUDE_PATHS
# ${CMAKE_SOURCE_DIR}/include
# PRIVATE_LINKED_TARGETS
# Threads::Threads
# PUBLIC_LINKED_TARGETS
# Threads::Threads
# LINKED_TARGETS
# Threads::Threads
# EXPORT_FILE_PATH
# ${CMAKE_BINARY_DIR}/MYLIBRARY_EXPORT.h
################################################################################
# Create a Library.
#
# Example usage:
#
# create_library( NAME myLibrary
# NAMESPACE myNamespace
# SOURCES
# myLib.cpp
# myLib_functions.cpp
# PUBLIC_DEFINITIONS
# USE_DOUBLE_PRECISION=1
# PRIVATE_DEFINITIONS
# DEBUG_VERBOSE
# PUBLIC_INCLUDE_PATHS
# ${CMAKE_SOURCE_DIR}/mylib/include
# PRIVATE_INCLUDE_PATHS
# ${CMAKE_SOURCE_DIR}/include
# PRIVATE_LINKED_TARGETS
# Threads::Threads
# PUBLIC_LINKED_TARGETS
# Threads::Threads
# LINKED_TARGETS
# Threads::Threads
# EXPORT_FILE_PATH
# ${CMAKE_BINARY_DIR}/MYLIBRARY_EXPORT.h
# )
#
# The above example creates an alias target, myNamespace::myLibrary which can be
# linked to by other tar gets.
# PUBLIC_DEFINITIONS - preprocessor defines which are inherated by targets which
# link to this library
#
# PRIVATE_DEFINITIONS - preprocessor defines which are private and only seen by
# myLibrary
#
# PUBLIC_INCLUDE_PATHS - include paths which are public, therefore inherted by
# targest which link to this library.
#
# PRIVATE_INCLUDE_PATHS - private include paths which are only visible by MyLibrary
#
# LINKED_TARGETS - targets to link to.
#
# EXPORT_FILE_PATH - the export file to generate for dll files.
################################################################################
function(create_library)
set(options)
set(args NAME
NAMESPACE
EXPORT_FILE_PATH
)
set(list_args
PUBLIC_LINKED_TARGETS
PRIVATE_LINKED_TARGETS
SOURCES
PUBLIC_DEFINITIONS
PRIVATE_DEFINITIONS
PUBLIC_INCLUDE_PATHS
PRIVATE_INCLUDE_PATHS
PUBLIC_COMPILE_FEATURES
PRIVATE_COMPILE_FEATURES
PUBLIC_COMPILE_OPTIONS
PRIVATE_COMPILE_OPTIONS
)
cmake_parse_arguments(
PARSE_ARGV 0
lib
"${options}"
"${args}"
"${list_args}"
)
message("--------------------------")
message("Creating Library")
if("${lib_NAME}" STREQUAL "")
get_filename_component(lib_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)
string(REPLACE " " "_" lib_NAME ${lib_NAME})
message(" Library, NAME argument not provided. Using folder name: ${lib_NAME}")
endif()
if("${lib_NAMESPACE}" STREQUAL "")
set(lib_NAMESPACE ${lib_NAME})
message(" Library, NAMESPACE argument not provided. Using target alias: ${lib_NAME}::${lib_NAME}")
endif()
message("-----------------------------------")
message("Building Library: ${lib_NAME}")
message("-----------------------------------")
print_list_label("Sources" lib_SOURCES)
print_list_label("Public Linked Targest" lib_PUBLIC_LINKED_TARGETS)
print_list_label("Private Linked Targest" lib_PRIVATE_LINKED_TARGETS)
print_list_label("Public Include Paths" lib_PUBLIC_INCLUDE_PATHS)
print_list_label("Private Include Paths" lib_PRIVATE_INCLUDE_PATHS)
print_list_label("Public Compile Features" lib_PUBLIC_COMPILE_FEATURES)
print_list_label("Private Compile Features" lib_PRIVATE_COMPILE_FEATURES)
print_list_label("Public Definitions" lib_PUBLIC_DEFINITIONS)
print_list_label("Private Definitions" lib_PRIVATE_DEFINITIONS)
message("Export File Name:")
message(" - ${lib_EXPORT_FILE_PATH}")
message("-----------------------------------")
add_library( ${lib_NAME} ${lib_SOURCES} )
add_library( ${lib_NAMESPACE}::${lib_NAME} ALIAS ${lib_NAME} )
target_compile_features(${lib_NAME} PUBLIC ${lib_PUBLIC_COMPILE_FEATURES} )
target_compile_features(${lib_NAME} PRIVATE ${lib_PRIVATE_COMPILE_FEATURES} )
target_compile_options(${lib_NAME} PUBLIC ${lib_PUBLIC_COMPILE_OPTIONS} )
target_compile_options(${lib_NAME} PRIVATE ${lib_PRIVATE_COMPILE_OPTIONS} )
target_link_libraries( ${lib_NAME} PUBLIC ${lib_PUBLIC_LINKED_TARGETS})
target_link_libraries( ${lib_NAME} PRIVATE ${lib_PRIVATE_LINKED_TARGETS})
target_include_directories( ${lib_NAME}
PUBLIC
${lib_INCLUDE_PATHS}
${lib_PUBLIC_INCLUDE_PATHS}
PRIVATE
${lib_PRIVATE_INCLUDE_PATHS}
)
target_compile_definitions( ${lib_NAME}
PUBLIC
${lib_PUBLIC_DEFINITIONS}
PRIVATE
${lib_PRIVATE_DEFINITIONS}
)
if( NOT "${lib_EXPORT_FILE_PATH}" STREQUAL "" )
generate_export_header( ${lib_NAME}
EXPORT_FILE_NAME
${lib_EXPORT_FILE_PATH}
)
endif()
################################################################################
# Debug Information Format:
# * https://docs.microsoft.com/en-us/cpp/build/reference/z7-zi-zi-debug-information-format
#
# Notes:
#
# * /Z7 still produce PDB file for DLL and without the PDB file installed
# you can't debug DLL
#
# * /Z7 for static library doesn't produce PDB. It's the best option if you
# want debug library without changing internal CMake code.
# Toolchain example: https://github.com/ruslo/polly/blob/master/vs-15-2017-win64-z7.cmake
#
# * /Zi option is default (produce separate PDB files)
#
# * TARGET_PDB_FILE generator expression doesn't support static libraries.
# See https://gitlab.kitware.com/cmake/cmake/issues/16932
# (that's why it's not used here)
#
# * This code can be implemented as a 'PDB DESTINATION' feature.
# See https://gitlab.kitware.com/cmake/cmake/issues/16935#note_275180
#
# * By default only Debug/RelWithDebInfo produce debug information,
# Release/MinSizeRel do not.
#
# * Generated PDB for static libraries doesn't respect CMAKE_<CONFIG>_POSTFIX
# variable. It means if you specify Debug and RelWithDebInfo then generated
# PDB files for both will be "md5.pdb". When PDB files installed one will
# overwrite another making it unusable. Release + Debug configurations will
# work fine because Release doesn't produce PDB files.
#
# * All PDB files will be installed, including PDB for targets that will not
# be installed themselves.
################################################################################
if(MSVC)
set(pdb_output_dir "${CMAKE_CURRENT_BINARY_DIR}/pdb-files")
set(CMAKE_PDB_OUTPUT_DIRECTORY "${pdb_output_dir}")
set(CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY "${pdb_output_dir}")
get_cmake_property(is_multi GENERATOR_IS_MULTI_CONFIG)
if(is_multi)
set(config_suffix "$<CONFIG>")
else()
set(config_suffix "")
endif()
# Introduce variables:
# * CMAKE_INSTALL_LIBDIR
# * CMAKE_INSTALL_BINDIR
include(GNUInstallDirs)
if(BUILD_SHARED_LIBS)
set(pdb_dst ${CMAKE_INSTALL_BINDIR})
else()
set(pdb_dst ${CMAKE_INSTALL_LIBDIR})
endif()
install(
DIRECTORY "${pdb_output_dir}/${config_suffix}/"
DESTINATION ${pdb_dst}
)
endif()
################################################################################
foreach(arg IN LISTS lib_UNPARSED_ARGUMENTS)
message(WARNING "Unparsed argument: ${arg}")
endforeach()
endfunction()
################################################################################
# Create an executable.
#
# Example usage:
#
# create_executable( NAME myExe
# SOURCES
# main.cpp
# PUBLIC_DEFINITIONS
# USE_DOUBLE_PRECISION=1
# PRIVATE_DEFINITIONS
# DEBUG_VERBOSE
# PUBLIC_INCLUDE_PATHS
# ${CMAKE_SOURCE_DIR}/mylib/include
# PRIVATE_INCLUDE_PATHS
# ${CMAKE_SOURCE_DIR}/include
# PRIVATE_LINKED_TARGETS
# Threads::Threads
# PUBLIC_LINKED_TARGETS
# Threads::Threads
# LINKED_TARGETS
# Threads::Threads
# myNamespace::myLib
# )
#
# The above example creates an alias target, myNamespace::myLibrary which can be
# linked to by other tar gets.
# PUBLIC_DEFINITIONS - preprocessor defines which are inherated by targets which
# link to this library
#
# PRIVATE_DEFINITIONS - preprocessor defines which are private and only seen by
# myLibrary
#
# PUBLIC_INCLUDE_PATHS - include paths which are public, therefore inherted by
# targest which link to this library.
#
# PRIVATE_INCLUDE_PATHS - private include paths which are only visible by MyExe
#
# LINKED_TARGETS - targets to link to.
################################################################################
function(create_executable)
set(options)
set(args NAME
)
set(list_args
PUBLIC_LINKED_TARGETS
PRIVATE_LINKED_TARGETS
SOURCES
PUBLIC_DEFINITIONS
PRIVATE_DEFINITIONS
PUBLIC_INCLUDE_PATHS
PRIVATE_INCLUDE_PATHS
PUBLIC_COMPILE_FEATURES
PRIVATE_COMPILE_FEATURES
PUBLIC_COMPILE_OPTIONS
PRIVATE_COMPILE_OPTIONS
)
cmake_parse_arguments(
PARSE_ARGV 0
lib
"${options}"
"${args}"
"${list_args}"
)
message("-----------------------------------")
message("Building Executable: ${Green}${lib_NAME}${ColourReset}")
message("-----------------------------------")
print_list_label("Sources" lib_SOURCES)
print_list_label("Public Linked Targest" lib_PUBLIC_LINKED_TARGETS)
print_list_label("Private Linked Targest" lib_PRIVATE_LINKED_TARGETS)
print_list_label("Public Include Paths" lib_PUBLIC_INCLUDE_PATHS)
print_list_label("Private Include Paths" lib_PRIVATE_INCLUDE_PATHS)
print_list_label("Public Compile Features" lib_PUBLIC_COMPILE_FEATURES)
print_list_label("Private Compile Features" lib_PRIVATE_COMPILE_FEATURES)
print_list_label("Public Definitions" lib_PUBLIC_DEFINITIONS)
print_list_label("Private Definitions" lib_PRIVATE_DEFINITIONS)
message("Export File Name:")
message(" - ${lib_EXPORT_FILE_PATH}")
message("-----------------------------------")
add_executable( ${lib_NAME} ${lib_SOURCES} )
target_link_libraries( ${lib_NAME} PUBLIC ${lib_PUBLIC_LINKED_TARGETS} )
target_include_directories( ${lib_NAME}
PUBLIC
${lib_PUBLIC_INCLUDE_PATHS}
PRIVATE
${lib_PRIVATE_INCLUDE_PATHS}
)
target_compile_definitions( ${lib_NAME}
PUBLIC
${lib_PUBLIC_DEFINITIONS}
PRIVATE
${lib_PRIVATE_DEFINITIONS}
)
target_compile_features(${lib_NAME} PUBLIC ${lib_PUBLIC_COMPILE_FEATURES} )
target_compile_features(${lib_NAME} PRIVATE ${lib_PRIVATE_COMPILE_FEATURES} )
target_compile_options(${lib_NAME} PUBLIC ${lib_PUBLIC_COMPILE_OPTIONS} )
target_compile_options(${lib_NAME} PRIVATE ${lib_PRIVATE_COMPILE_OPTIONS} )
################################################################################
foreach(arg IN LISTS lib_UNPARSED_ARGUMENTS)
message(WARNING "Unparsed argument: ${arg}")
endforeach()
endfunction(create_executable)
function(create_module)
set(options)
set(args NAME
)
set(list_args
LINKED_TARGETS
SOURCES
PUBLIC_DEFINITIONS
PRIVATE_DEFINITIONS
INCLUDE_PATHS)
cmake_parse_arguments(
PARSE_ARGV 0
lib
"${options}"
"${args}"
"${list_args}"
)
message("Building Module: ${lib_NAME}")
add_library( ${lib_NAME} MODULE ${lib_SOURCES} )
target_link_libraries( ${lib_NAME} PUBLIC ${lib_LINKED_TARGETS} )
set_target_properties( ${lib_NAME} PROPERTIES SUFFIX ".so")
set_target_properties( ${lib_NAME} PROPERTIES PREFIX "")
target_include_directories( ${lib_NAME}
PUBLIC
${lib_INCLUDE_PATHS}
${lib_PUBLIC_INCLUDE_PATHS}
PRIVATE
${lib_PRIVATE_INCLUDE_PATHS}
)
target_compile_definitions( ${lib_NAME}
PUBLIC
${lib_PUBLIC_DEFINITIONS}
PRIVATE
${lib_PRIVATE_DEFINITIONS}
)
################################################################################
foreach(arg IN LISTS lib_UNPARSED_ARGUMENTS)
message(WARNING "Unparsed argument: ${arg}")
endforeach()
endfunction()
################################################################################
# Create a Header Only Library.
#
# Example usage:
#
# create_library( NAME myLibrary
# NAMESPACE myNamespace
# SOURCES
# myLib.cpp
# myLib_functions.cpp
# PUBLIC_DEFINITIONS
# USE_DOUBLE_PRECISION=1
# PRIVATE_DEFINITIONS
# DEBUG_VERBOSE
# PUBLIC_INCLUDE_PATHS
# ${CMAKE_SOURCE_DIR}/mylib/include
# PRIVATE_INCLUDE_PATHS
# ${CMAKE_SOURCE_DIR}/include
# PRIVATE_LINKED_TARGETS
# Threads::Threads
# PUBLIC_LINKED_TARGETS
# Threads::Threads
# LINKED_TARGETS
# Threads::Threads
# EXPORT_FILE_PATH
# ${CMAKE_BINARY_DIR}/MYLIBRARY_EXPORT.h
# )
#
# The above example creates an alias target, myNamespace::myLibrary which can be
# linked to by other tar gets.
# PUBLIC_DEFINITIONS - preprocessor defines which are inherated by targets which
# link to this library
#
# PRIVATE_DEFINITIONS - preprocessor defines which are private and only seen by
# myLibrary
#
# PUBLIC_INCLUDE_PATHS - include paths which are public, therefore inherted by
# targest which link to this library.
#
# PRIVATE_INCLUDE_PATHS - private include paths which are only visible by MyLibrary
#
# LINKED_TARGETS - targets to link to.
#
# EXPORT_FILE_PATH - the export file to generate for dll files.
################################################################################
function(create_header_only_library)
set(options)
set(args NAME
NAMESPACE
)
set(list_args
PUBLIC_LINKED_TARGETS
PRIVATE_LINKED_TARGETS
SOURCES
PUBLIC_DEFINITIONS
PRIVATE_DEFINITIONS
PUBLIC_INCLUDE_PATHS
PRIVATE_INCLUDE_PATHS
PUBLIC_COMPILE_FEATURES
PRIVATE_COMPILE_FEATURES
PUBLIC_COMPILE_OPTIONS
PRIVATE_COMPILE_OPTIONS
)
cmake_parse_arguments(
PARSE_ARGV 0
lib
"${options}"
"${args}"
"${list_args}"
)
message("--------------------------")
message("Creating Header-Only Library")
if("${lib_NAME}" STREQUAL "")
get_filename_component(lib_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)
string(REPLACE " " "_" lib_NAME ${lib_NAME})
message(" Library, NAME argument not provided. Using folder name: ${lib_NAME}")
endif()
if("${lib_NAMESPACE}" STREQUAL "")
set(lib_NAMESPACE ${lib_NAME})
message(" Library, NAMESPACE argument not provided. Using target alias: ${lib_NAME}::${lib_NAME}")
endif()
message("-----------------------------------")
message("Building Library: ${lib_NAME} Alias: ${lib_NAMESPACE}::${lib_NAME}")
message("-----------------------------------")
print_list_label("Sources" lib_SOURCES)
print_list_label("Public Linked Targest" lib_PUBLIC_LINKED_TARGETS)
print_list_label("Private Linked Targest" lib_PRIVATE_LINKED_TARGETS)
print_list_label("Public Include Paths" lib_PUBLIC_INCLUDE_PATHS)
print_list_label("Private Include Paths" lib_PRIVATE_INCLUDE_PATHS)
print_list_label("Public Compile Features" lib_PUBLIC_COMPILE_FEATURES)
print_list_label("Private Compile Features" lib_PRIVATE_COMPILE_FEATURES)
print_list_label("Public Definitions" lib_PUBLIC_DEFINITIONS)
print_list_label("Private Definitions" lib_PRIVATE_DEFINITIONS)
message("Export File Name:")
message(" - ${lib_EXPORT_FILE_PATH}")
message("-----------------------------------")
add_library( ${lib_NAME} INTERFACE ${lib_SOURCES} )
add_library( ${lib_NAMESPACE}::${lib_NAME} ALIAS ${lib_NAME} )
target_compile_features(${lib_NAME} INTERFACE ${lib_PUBLIC_COMPILE_FEATURES} )
target_compile_features(${lib_NAME} INTERFACE ${lib_PRIVATE_COMPILE_FEATURES} )
target_compile_features(${lib_NAME} INTERFACE ${lib_PUBLIC_COMPILE_OPTIONS} )
target_compile_features(${lib_NAME} INTERFACE ${lib_PRIVATE_COMPILE_OPTIONS} )
target_link_libraries( ${lib_NAME} PUBLIC ${PUBLIC_LINKED_TARGETS})
target_link_libraries( ${lib_NAME} PRIVATE ${PRIVATE_LINKED_TARGETS})
target_include_directories( ${lib_NAME}
INTERFACE
${lib_PUBLIC_INCLUDE_PATHS}
${lib_PRIVATE_INCLUDE_PATHS}
)
target_compile_definitions( ${lib_NAME}
INTERFACE
${lib_PUBLIC_DEFINITIONS}
${lib_PRIVATE_DEFINITIONS}
)
foreach(arg IN LISTS lib_UNPARSED_ARGUMENTS)
message(WARNING "Unparsed argument: ${arg}")
endforeach()
endfunction()
function(create_test)
set(options)
set(args NAME
WORKING_DIRECTORY
)
set(list_args
PUBLIC_LINKED_TARGETS
PRIVATE_LINKED_TARGETS
SOURCES
COMMAND
PUBLIC_DEFINITIONS
PRIVATE_DEFINITIONS
PUBLIC_INCLUDE_PATHS
PRIVATE_INCLUDE_PATHS
PUBLIC_COMPILE_FEATURES
PRIVATE_COMPILE_FEATURES
)
cmake_parse_arguments(
PARSE_ARGV 0
lib
"${options}"
"${args}"
"${list_args}"
)
message("-----------------------------------")
message("Building Test: ${lib_NAME} ")
message("-----------------------------------")
message("Command to Execute: ${lib_COMMAND}")
message("Working Directory : ${lib_WORKING_DIRECTORY}")
print_list_label("Sources" lib_SOURCES)
print_list_label("Public Linked Targest" lib_PUBLIC_LINKED_TARGETS)
print_list_label("Private Linked Targest" lib_PRIVATE_LINKED_TARGETS)
print_list_label("Public Include Paths" lib_PUBLIC_INCLUDE_PATHS)
print_list_label("Private Include Paths" lib_PRIVATE_INCLUDE_PATHS)
print_list_label("Public Compile Features" lib_PUBLIC_COMPILE_FEATURES)
print_list_label("Private Compile Features" lib_PRIVATE_COMPILE_FEATURES)
print_list_label("Public Definitions" lib_PUBLIC_DEFINITIONS)
print_list_label("Private Definitions" lib_PRIVATE_DEFINITIONS)
message("Export File Name:")
message(" - ${lib_EXPORT_FILE_PATH}")
message("-----------------------------------")
set(testcase ${lib_NAME} )
add_executable(${testcase} ${lib_SOURCES})
target_compile_definitions(${testcase} PRIVATE
#CATCH_CONFIG_FAST_COMPILE
$<$<CXX_COMPILER_ID:MSVC>:_SCL_SECURE_NO_WARNINGS>
${lib_PRIVATE_DEFINITIONS}
${lib_PUBLIC_DEFINITIONS}
)
target_compile_options(${testcase} PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/EHsc;$<$<CONFIG:Release>:/Od>>
# $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-deprecated;-Wno-float-equal>
$<$<CXX_COMPILER_ID:GNU>:-Wno-deprecated-declarations>
${lib_PUBLIC_COMPILE_FEATURES}
${lib_PRIVATE_COMPILE_FEATURES}
)
target_include_directories(${testcase} PRIVATE
${lib_PUBLIC_INCLUDE_PATHS}
${lib_PRIVATE_INCLUDE_PATHS}
)
target_link_libraries(${testcase} ${lib_PUBLIC_LINKED_TARGETS} ${lib_PRIVATE_LINKED_TARGETS} )
#target_link_libraries(${testcase} --coverage -g -O0 -fprofile-arcs -ftest-coverage)
#target_compile_options(${testcase} PRIVATE --coverage -g -O0 -fprofile-arcs -ftest-coverage)
#MESSAGE(" Adding link libraries for ${testcase}: ${GNL_LIBS} ${GNL_COVERAGE_FLAGS} ")
add_test( NAME ${testcase}
COMMAND ${lib_COMMAND}
WORKING_DIRECTORY ${lib_WORKING_DIRECTORY})
endfunction()