diff --git a/CMakeLists.txt b/CMakeLists.txt index 586aaca..9028735 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,25 @@ -# +# # CMake options # # CMake version cmake_minimum_required(VERSION 3.15 FATAL_ERROR) + +# +# Detect type of CMake setup +# + +# Use PROJECT_IS_TOP_LEVEL once we bump the required CMake version up to 3.21 +get_directory_property(META_HAS_PARENT PARENT_DIRECTORY) +if(META_HAS_PARENT) + set(META_BUILD_AS_ROOT Off) +else() + set(META_BUILD_AS_ROOT On) +endif() + + # # Configure CMake environment # @@ -17,6 +31,7 @@ include(cmake/Custom.cmake) set_policy(CMP0054 NEW) # ENABLE CMP0054: Only interpret if() arguments as variables or keywords when unquoted. set_policy(CMP0042 NEW) # ENABLE CMP0042: MACOSX_RPATH is enabled by default. set_policy(CMP0063 NEW) # ENABLE CMP0063: Honor visibility properties for all target types. +set_policy(CMP0069 NEW) # ENABLE CMP0069: INTERPROCEDURAL_OPTIMIZATION is enforced when enabled. set_policy(CMP0077 NEW) # ENABLE CMP0077: option() honors normal variables. set_policy(CMP0120 OLD) # DISABLE CMP0120: The WriteCompilerDetectionHeader module is removed. @@ -34,16 +49,34 @@ include(cmake/HealthCheck.cmake) # -# Project description and (meta) information +# Project configuration options # +# Project options +option(BUILD_SHARED_LIBS "Build shared instead of static libraries." ON) +option(OPTION_SELF_CONTAINED "Create a self-contained install with all dependencies." OFF) +option(OPTION_BUILD_TESTS "Build tests." ON) +option(OPTION_BUILD_DOCS "Build documentation." OFF) +option(OPTION_BUILD_EXAMPLES "Build examples." OFF) +option(OPTION_ENABLE_COVERAGE "Add coverage information." OFF) + # Get git revision -get_git_head_revision(GIT_REFSPEC GIT_SHA1) -string(SUBSTRING "${GIT_SHA1}" 0 12 GIT_REV) -if(NOT GIT_SHA1) - set(GIT_REV "0") +if (OPTION_USE_GIT_INFORMATION AND META_BUILD_AS_ROOT) + get_git_head_revision(GIT_REFSPEC GIT_SHA1) + string(SUBSTRING "${GIT_SHA1}" 0 12 GIT_REV) + if(NOT GIT_SHA1) + set(GIT_REV "0") + endif() +else() + set(GIT_SHA1 "") + set(GIT_REV "0") endif() + +# +# Project description and (meta) information +# + # Meta information about the project set(META_PROJECT_NAME "template") set(META_PROJECT_DESCRIPTION "CMake Project Template") @@ -51,30 +84,18 @@ set(META_AUTHOR_ORGANIZATION "CG Internals GmbH") set(META_AUTHOR_DOMAIN "https://github.com/cginternals/cmake-init/") set(META_AUTHOR_MAINTAINER "opensource@cginternals.com") set(META_VERSION_MAJOR "2") -set(META_VERSION_MINOR "0") +set(META_VERSION_MINOR "1") set(META_VERSION_PATCH "0") set(META_VERSION_REVISION "${GIT_REV}") set(META_VERSION "${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH}") set(META_NAME_VERSION "${META_PROJECT_NAME} v${META_VERSION} (${META_VERSION_REVISION})") set(META_CMAKE_INIT_SHA "${GIT_REV}") +set(META_CMAKE_INIT_BRANCH "cmake-3.15") string(MAKE_C_IDENTIFIER ${META_PROJECT_NAME} META_PROJECT_ID) string(TOUPPER ${META_PROJECT_ID} META_PROJECT_ID) -# -# Project configuration options -# - -# Project options -option(BUILD_SHARED_LIBS "Build shared instead of static libraries." ON) -option(OPTION_SELF_CONTAINED "Create a self-contained install with all dependencies." OFF) -option(OPTION_BUILD_TESTS "Build tests." ON) -option(OPTION_BUILD_DOCS "Build documentation." OFF) -option(OPTION_BUILD_EXAMPLES "Build examples." OFF) -option(OPTION_ENABLE_COVERAGE "Add coverage information." OFF) - - # # Declare project # @@ -84,7 +105,13 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON) set(IDE_FOLDER "") # Declare project -project(${META_PROJECT_NAME} VERSION ${META_VERSION} DESCRIPTION ${META_PROJECT_DESCRIPTION} LANGUAGES C CXX) +project(${META_PROJECT_NAME} + VERSION ${META_VERSION} + DESCRIPTION ${META_PROJECT_DESCRIPTION} +) + +enable_language(C) +enable_language(CXX) # Set output directories set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) @@ -100,7 +127,7 @@ file(WRITE "${PROJECT_BINARY_DIR}/VERSION" "${META_NAME_VERSION}") # # Add cmake-init template check cmake targets -add_check_template_target(${META_CMAKE_INIT_SHA}) +add_check_template_target(${META_CMAKE_INIT_SHA} ${META_CMAKE_INIT_BRANCH}) # Configure health check tools enable_cppcheck(ON) diff --git a/README.md b/README.md index 408747a..5868616 100644 --- a/README.md +++ b/README.md @@ -210,7 +210,7 @@ This module is usable when the following is integrated into the `CMakeLists.txt` ```cmake # Add cmake-init template check cmake targets -add_check_template_target() +add_check_template_target( ) ``` Here, the `` contains the git hash of the used cmake-init template. @@ -221,9 +221,10 @@ The hash is usually configured using ```cmake # Meta information about the project set(META_CMAKE_INIT_SHA "") +set(META_CMAKE_INIT_BRANCH "") # Add cmake-init template check cmake targets -add_check_template_target() +add_check_template_target( ) ``` Correctly configures, this module adds a cmake build target named `check-template` that compares the passed `` with the current master commit hash of this repository and provides a link for a diff view. diff --git a/cmake/CheckTemplate.cmake b/cmake/CheckTemplate.cmake index 6f69590..e084374 100644 --- a/cmake/CheckTemplate.cmake +++ b/cmake/CheckTemplate.cmake @@ -3,8 +3,12 @@ # Get cmake-init latest commit SHA on master # +if(NOT APPLIED_CMAKE_INIT_BRANCH) + set(APPLIED_CMAKE_INIT_BRANCH "master") +endif () + file(DOWNLOAD - "https://api.github.com/repos/cginternals/cmake-init/commits/master" + "https://api.github.com/repos/cginternals/cmake-init/commits/${APPLIED_CMAKE_INIT_BRANCH}" "${PROJECT_BINARY_DIR}/cmake-init.github.data" ) file(READ @@ -45,5 +49,5 @@ endif() if(${APPLIED_CMAKE_INIT_SHA} STREQUAL ${CMAKE_INIT_SHA}) message(STATUS "cmake-init template is up-to-date (${CMAKE_INIT_SHA})") else() - message(STATUS "cmake-init template needs an update https://github.com/cginternals/cmake-init/compare/${APPLIED_CMAKE_INIT_SHA}...master") + message(STATUS "cmake-init template needs an update https://github.com/cginternals/cmake-init/compare/${APPLIED_CMAKE_INIT_SHA}...${APPLIED_CMAKE_INIT_BRANCH}") endif() diff --git a/cmake/CompileOptions.cmake b/cmake/CompileOptions.cmake index b08571f..d7a16b8 100644 --- a/cmake/CompileOptions.cmake +++ b/cmake/CompileOptions.cmake @@ -33,6 +33,10 @@ set(DEFAULT_PROJECT_OPTIONS set(DEFAULT_INCLUDE_DIRECTORIES) +if (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") + LIST(APPEND DEFAULT_INCLUDE_DIRECTORIES "/usr/local/include") +endif () + # # Libraries @@ -50,7 +54,8 @@ set(DEFAULT_COMPILE_DEFINITIONS ) # MSVC compiler options -if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC") +if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC" OR + "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" AND "x${CMAKE_CXX_SIMULATE_ID}" MATCHES "xMSVC") set(DEFAULT_COMPILE_DEFINITIONS ${DEFAULT_COMPILE_DEFINITIONS} _SCL_SECURE_NO_WARNINGS # Calling any one of the potentially unsafe methods in the Standard C++ Library _CRT_SECURE_NO_WARNINGS # Calling any one of the potentially unsafe methods in the CRT Library @@ -62,79 +67,89 @@ endif () # Compile options # -set(DEFAULT_COMPILE_OPTIONS) +set(DEFAULT_COMPILE_OPTIONS_PRIVATE) +set(DEFAULT_COMPILE_OPTIONS_PUBLIC) # MSVC compiler options if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC") - set(DEFAULT_COMPILE_OPTIONS ${DEFAULT_COMPILE_OPTIONS} - PRIVATE + set(DEFAULT_COMPILE_OPTIONS_PRIVATE ${DEFAULT_COMPILE_OPTIONS_PRIVATE} + $<$: /MP # -> build with multiple processes - /W4 # -> warning level 4 - # /WX # -> treat warnings as errors - - #$<$: - #/RTCc # -> value is assigned to a smaller data type and results in a data loss - #> - - $<$: - /Gw # -> whole program global optimization - /GS- # -> buffer security check: no - /GL # -> whole program optimization: enable link-time code generation (disables Zi) - /GF # -> enable string pooling - > - - # No manual c++11 enable for MSVC as all supported MSVC versions for cmake-init have C++11 implicitly enabled (MSVC >=2013) - - PUBLIC - /wd4251 # -> disable warning: 'identifier': class 'type' needs to have dll-interface to be used by clients of class 'type2' - /wd4592 # -> disable warning: 'identifier': symbol will be dynamically initialized (implementation limitation) - # /wd4201 # -> disable warning: nonstandard extension used: nameless struct/union (caused by GLM) - # /wd4127 # -> disable warning: conditional expression is constant (caused by Qt) + > + /W4 # -> warning level 4 + # /WX # -> treat warnings as errors + /wd4251 # -> disable warning: 'identifier': class 'type' needs to have dll-interface to be used by clients of class 'type2' + /wd4592 # -> disable warning: 'identifier': symbol will be dynamically initialized (implementation limitation) + # /wd4201 # -> disable warning: nonstandard extension used: nameless struct/union (caused by GLM) + /wd4127 # -> disable warning: conditional expression is constant (caused by Qt) + + # /Zm114 # -> Memory size for precompiled headers (insufficient for msvc 2013) + /Zm200 # -> Memory size for precompiled headers + + $<$: + -Wno-microsoft-cast + > + + #$<$: + #/RTCc # -> value is assigned to a smaller data type and results in a data loss + #> + + $<$: + /Gw # -> whole program global optimization + /GS- # -> buffer security check: no + /GL # -> whole program optimization: enable link-time code generation (disables Zi) + /GF # -> enable string pooling + > + + # No manual c++11 enable for MSVC as all supported MSVC versions for cmake-init have C++11 implicitly enabled (MSVC >=2013) ) endif () # GCC and Clang compiler options -if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") - set(DEFAULT_COMPILE_OPTIONS ${DEFAULT_COMPILE_OPTIONS} - PRIVATE - -Wall - -Wextra - -Wunused - - -Wreorder - -Wignored-qualifiers - -Wmissing-braces - -Wreturn-type - -Wswitch - -Wswitch-default - -Wuninitialized - -Wmissing-field-initializers - - $<$: - -Wmaybe-uninitialized - - $<$,4.8>: - -Wpedantic - - -Wreturn-local-addr - > - > +if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" AND NOT MSVC) + set(DEFAULT_COMPILE_OPTIONS_PRIVATE ${DEFAULT_COMPILE_OPTIONS_PRIVATE} + #-fno-exceptions # since we use stl and stl is intended to use exceptions, exceptions should not be disabled + + -Wall + -Wextra + -Wunused + + -Wreorder + -Wignored-qualifiers + -Wmissing-braces + -Wreturn-type + -Wswitch + -Wswitch-default + -Wuninitialized + -Wmissing-field-initializers + + $<$: + -Wmaybe-uninitialized + + -Wno-unknown-pragmas - $<$: + $<$,4.8>: -Wpedantic - # -Wreturn-stack-address # gives false positives + -Wreturn-local-addr > - - $<$: - -fprofile-arcs - -ftest-coverage - > - - PUBLIC - $<$: - -pthread + > + + $<$: + -Wpedantic + + $<$: + -Wno-language-extension-token + -Wno-microsoft-cast > + + # -Wreturn-stack-address # gives false positives + > + ) + set(DEFAULT_COMPILE_OPTIONS_PUBLIC ${DEFAULT_COMPILE_OPTIONS_PUBLIC} + $<$: + -pthread + > ) endif () @@ -147,16 +162,14 @@ set(DEFAULT_LINKER_OPTIONS) # Use pthreads on mingw and linux if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" OR "${CMAKE_SYSTEM_NAME}" MATCHES "Linux") - set(DEFAULT_LINKER_OPTIONS + set(DEFAULT_LINKER_OPTIONS ${DEFAULT_LINKER_OPTIONS} PUBLIC - ${DEFAULT_LINKER_OPTIONS} -pthread ) if (${OPTION_COVERAGE_ENABLED}) - set(DEFAULT_LINKER_OPTIONS + set(DEFAULT_LINKER_OPTIONS ${DEFAULT_LINKER_OPTIONS} PUBLIC - ${DEFAULT_LINKER_OPTIONS} -fprofile-arcs -ftest-coverage ) diff --git a/cmake/Custom.cmake b/cmake/Custom.cmake index e0e690f..18728b3 100644 --- a/cmake/Custom.cmake +++ b/cmake/Custom.cmake @@ -24,7 +24,7 @@ function(source_group_by_path PARENT_PATH REGEX GROUP) string(REPLACE "/" "\\" FILEPATH "${FILEPATH}") - source_group("${GROUP}\\${FILEPATH}" REGULAR_EXPRESSION "${REGEX}" FILES ${FILENAME}) + source_group("${GROUP}\\${FILEPATH}" REGULAR_EXPRESSION "${REGEX}" FILES ${FILENAME}) endforeach() diff --git a/cmake/FindGTK3.cmake b/cmake/FindGTK3.cmake new file mode 100644 index 0000000..3bd0163 --- /dev/null +++ b/cmake/FindGTK3.cmake @@ -0,0 +1,32 @@ + +# GTK3::GTK3 +# GTK3_FOUND +# GTK3_INCLUDE_DIRS +# GTK3_LIBRARIES + +include(FindPackageHandleStandardArgs) + +find_package(PkgConfig QUIET) +pkg_check_modules(GTK3 QUIET gtk+-3.0) + +if(GTK3_FOUND) + + add_library(GTK3::GTK3 INTERFACE IMPORTED) + + set_target_properties(GTK3::GTK3 PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${GTK3_INCLUDE_DIRS}" + ) + + set_target_properties(GTK3::GTK3 PROPERTIES + INTERFACE_LINK_LIBRARIES "${GTK3_LIBRARIES}" + ) + +endif() + +find_package_handle_standard_args(GTK3 + DEFAULT_MSG + REQUIRED_VARS + GTK3_FOUND +) + +mark_as_advanced(GTK3_FOUND GTK3_INCLUDE_DIRS GTK3_LIBRARIES) diff --git a/cmake/FindGTK4.cmake b/cmake/FindGTK4.cmake new file mode 100644 index 0000000..f09b13b --- /dev/null +++ b/cmake/FindGTK4.cmake @@ -0,0 +1,30 @@ + +# GTK4::GTK4 +# GTK4_FOUND +# GTK4_INCLUDE_DIRS +# GTK4_LIBRARIES + +include(FindPackageHandleStandardArgs) + +find_package(PkgConfig QUIET) +pkg_check_modules(GTK4 QUIET IMPORTED_TARGET gtk4) + +set(GTK4_FOUND OFF) + +if(TARGET PkgConfig::GTK4) + set(GTK4_FOUND ON) + + add_library(GTK4::GTK4 INTERFACE IMPORTED) + + set_target_properties(GTK4::GTK4 PROPERTIES + INTERFACE_LINK_LIBRARIES PkgConfig::GTK4 + ) + +endif() + +find_package_handle_standard_args(GTK4 + DEFAULT_MSG + REQUIRED_VARS + GTK4_FOUND +) +mark_as_advanced(GTK4_FOUND) diff --git a/cmake/FindSDL2.cmake b/cmake/FindSDL2.cmake new file mode 100644 index 0000000..3502df4 --- /dev/null +++ b/cmake/FindSDL2.cmake @@ -0,0 +1,33 @@ + +# SDL2::SDL2 +# SDL2_FOUND +# SDL2_INCLUDE_DIRS +# SDL2_LIBRARIES + +include(FindPackageHandleStandardArgs) + +find_package(PkgConfig QUIET) +pkg_check_modules(SDL2 QUIET sdl2) + +if(SDL2_FOUND) + + add_library(SDL2::SDL2 INTERFACE IMPORTED) + + set_target_properties(SDL2::SDL2 PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIRS}" + ) + + set_target_properties(SDL2::SDL2 PROPERTIES + INTERFACE_LINK_LIBRARIES "${SDL2_LIBRARIES}" + ) + +endif() + +find_package_handle_standard_args(SDL2 + DEFAULT_MSG + REQUIRED_VARS + SDL2_INCLUDE_DIRS + SDL2_LIBRARIES +) + +mark_as_advanced(SDL2_FOUND SDL2_INCLUDE_DIRS SDL2_LIBRARIES) diff --git a/cmake/GenerateTemplateExportHeader.cmake b/cmake/GenerateTemplateExportHeader.cmake index 5c36a9d..7f8ea88 100644 --- a/cmake/GenerateTemplateExportHeader.cmake +++ b/cmake/GenerateTemplateExportHeader.cmake @@ -5,8 +5,8 @@ # may get used to define public visibility for templates on GCC and Clang platforms. function(generate_template_export_header target target_id export_file) if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC") - configure_file(${PROJECT_SOURCE_DIR}/source/codegeneration/template_msvc_api.h.in ${CMAKE_CURRENT_BINARY_DIR}/${export_file} @ONLY) + configure_file(${PROJECT_SOURCE_DIR}/source/codegeneration/template_msvc_api.h.in ${CMAKE_CURRENT_BINARY_DIR}/${export_file}) else() - configure_file(${PROJECT_SOURCE_DIR}/source/codegeneration/template_api.h.in ${CMAKE_CURRENT_BINARY_DIR}/${export_file} @ONLY) + configure_file(${PROJECT_SOURCE_DIR}/source/codegeneration/template_api.h.in ${CMAKE_CURRENT_BINARY_DIR}/${export_file}) endif() endfunction() diff --git a/cmake/GetGitRevisionDescription.cmake b/cmake/GetGitRevisionDescription.cmake index 85eae15..9fd2efb 100644 --- a/cmake/GetGitRevisionDescription.cmake +++ b/cmake/GetGitRevisionDescription.cmake @@ -31,7 +31,7 @@ # http://www.boost.org/LICENSE_1_0.txt) if(__get_git_revision_description) - return() + return() endif() set(__get_git_revision_description YES) @@ -40,91 +40,91 @@ set(__get_git_revision_description YES) get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH) function(get_git_head_revision _refspecvar _hashvar) - set(GIT_PARENT_DIR "${CMAKE_CURRENT_SOURCE_DIR}") - set(GIT_DIR "${GIT_PARENT_DIR}/.git") - while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories - set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}") - get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH) - if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT) - # We have reached the root directory, we are not in git - set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE) - set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE) - return() - endif() - set(GIT_DIR "${GIT_PARENT_DIR}/.git") - endwhile() - # check if this is a submodule - if(NOT IS_DIRECTORY ${GIT_DIR}) - file(READ ${GIT_DIR} submodule) - string(REGEX REPLACE "gitdir: (.*)\n$" "\\1" GIT_DIR_RELATIVE ${submodule}) - get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH) - get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE} ABSOLUTE) - endif() - set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data") - if(NOT EXISTS "${GIT_DATA}") - file(MAKE_DIRECTORY "${GIT_DATA}") - endif() + set(GIT_PARENT_DIR "${CMAKE_CURRENT_SOURCE_DIR}") + set(GIT_DIR "${GIT_PARENT_DIR}/.git") + while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories + set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}") + get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH) + if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT) + # We have reached the root directory, we are not in git + set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE) + set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE) + return() + endif() + set(GIT_DIR "${GIT_PARENT_DIR}/.git") + endwhile() + # check if this is a submodule + if(NOT IS_DIRECTORY ${GIT_DIR}) + file(READ ${GIT_DIR} submodule) + string(REGEX REPLACE "gitdir: (.*)\n$" "\\1" GIT_DIR_RELATIVE ${submodule}) + get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH) + get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE} ABSOLUTE) + endif() + set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data") + if(NOT EXISTS "${GIT_DATA}") + file(MAKE_DIRECTORY "${GIT_DATA}") + endif() - if(NOT EXISTS "${GIT_DIR}/HEAD") - return() - endif() - set(HEAD_FILE "${GIT_DATA}/HEAD") - configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY) + if(NOT EXISTS "${GIT_DIR}/HEAD") + return() + endif() + set(HEAD_FILE "${GIT_DATA}/HEAD") + configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY) - configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in" - "${GIT_DATA}/grabRef.cmake" - @ONLY) - include("${GIT_DATA}/grabRef.cmake") + configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in" + "${GIT_DATA}/grabRef.cmake" + @ONLY) + include("${GIT_DATA}/grabRef.cmake") - set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE) - set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE) + set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE) + set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE) endfunction() function(git_describe _var) - if(NOT GIT_FOUND) - find_package(Git QUIET) - endif() - get_git_head_revision(refspec hash) - if(NOT GIT_FOUND) - set(${_var} "GIT-NOTFOUND" PARENT_SCOPE) - return() - endif() - if(NOT hash) - set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE) - return() - endif() + if(NOT GIT_FOUND) + find_package(Git QUIET) + endif() + get_git_head_revision(refspec hash) + if(NOT GIT_FOUND) + set(${_var} "GIT-NOTFOUND" PARENT_SCOPE) + return() + endif() + if(NOT hash) + set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE) + return() + endif() - # TODO sanitize - #if((${ARGN}" MATCHES "&&") OR - # (ARGN MATCHES "||") OR - # (ARGN MATCHES "\\;")) - # message("Please report the following error to the project!") - # message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}") - #endif() + # TODO sanitize + #if((${ARGN}" MATCHES "&&") OR + # (ARGN MATCHES "||") OR + # (ARGN MATCHES "\\;")) + # message("Please report the following error to the project!") + # message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}") + #endif() - #message(STATUS "Arguments to execute_process: ${ARGN}") + #message(STATUS "Arguments to execute_process: ${ARGN}") - execute_process(COMMAND - "${GIT_EXECUTABLE}" - describe - ${hash} - ${ARGN} - WORKING_DIRECTORY - "${CMAKE_CURRENT_SOURCE_DIR}" - RESULT_VARIABLE - res - OUTPUT_VARIABLE - out - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) - if(NOT res EQUAL 0) - set(out "${out}-${res}-NOTFOUND") - endif() + execute_process(COMMAND + "${GIT_EXECUTABLE}" + describe + ${hash} + ${ARGN} + WORKING_DIRECTORY + "${CMAKE_CURRENT_SOURCE_DIR}" + RESULT_VARIABLE + res + OUTPUT_VARIABLE + out + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + if(NOT res EQUAL 0) + set(out "${out}-${res}-NOTFOUND") + endif() - set(${_var} "${out}" PARENT_SCOPE) + set(${_var} "${out}" PARENT_SCOPE) endfunction() function(git_get_exact_tag _var) - git_describe(out --exact-match ${ARGN}) - set(${_var} "${out}" PARENT_SCOPE) + git_describe(out --exact-match ${ARGN}) + set(${_var} "${out}" PARENT_SCOPE) endfunction() diff --git a/cmake/HealthCheck.cmake b/cmake/HealthCheck.cmake index 8df8b9a..683908b 100644 --- a/cmake/HealthCheck.cmake +++ b/cmake/HealthCheck.cmake @@ -85,13 +85,14 @@ function(enable_clang_tidy status) endfunction() # Configure cmake target to check for cmake-init template -function(add_check_template_target current_template_sha) +function(add_check_template_target current_template_sha current_template_branch) add_custom_target( check-template COMMAND ${CMAKE_COMMAND} -DPROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR} -DPROJECT_BINARY_DIR=${PROJECT_BINARY_DIR} -DAPPLIED_CMAKE_INIT_SHA=${current_template_sha} + -DAPPLIED_CMAKE_INIT_BRANCH=${current_template_branch} -P ${PROJECT_SOURCE_DIR}/cmake/CheckTemplate.cmake WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} ) diff --git a/deploy/ubuntu-ppa/debian/copyright b/deploy/ubuntu-ppa/debian/copyright index 5d8e1ad..5966d32 100644 --- a/deploy/ubuntu-ppa/debian/copyright +++ b/deploy/ubuntu-ppa/debian/copyright @@ -11,7 +11,7 @@ Upstream Author: Copyright: - Copyright (c) 2015-2017 CG Internals GmbH and Computer Graphics Systems Group at the Hasso-Plattner-Institute, Germany. + Copyright (c) 2015-2025 CG Internals GmbH and Computer Graphics Systems Group at the Hasso-Plattner-Institute, Germany. License: diff --git a/deploy/ubuntu-ppa/debian/rules b/deploy/ubuntu-ppa/debian/rules index 64e5dee..5954259 100644 --- a/deploy/ubuntu-ppa/debian/rules +++ b/deploy/ubuntu-ppa/debian/rules @@ -24,28 +24,28 @@ binary: binary-arch binary-arch: libcmake-init libcmake-init-dev libcmake-init-docs libcmake-init-dbg libcmake-init-examples-data libcmake-init-examples libcmake-init-all -libcmake-init: +libcmake-init: build cd $(BUILDDIR); DESTDIR=../debian/tmp COMPONENT=runtime make component_install mkdir -p debian/tmp/DEBIAN dpkg-gencontrol -plibcmake-init dpkg --build debian/tmp .. rm -rf debian/tmp -libcmake-init-dev: +libcmake-init-dev: build cd $(BUILDDIR); DESTDIR=../debian/tmp COMPONENT=dev make component_install mkdir -p debian/tmp/DEBIAN dpkg-gencontrol -plibcmake-init-dev dpkg --build debian/tmp .. rm -rf debian/tmp -libcmake-init-docs: +libcmake-init-docs: build cd $(BUILDDIR); DESTDIR=../debian/tmp COMPONENT=docs make component_install mkdir -p debian/tmp/DEBIAN dpkg-gencontrol -plibcmake-init-docs dpkg --build debian/tmp .. rm -rf debian/tmp -libcmake-init-dbg: +libcmake-init-dbg: build cd $(BUILDDEBUGDIR); DESTDIR=../debian/tmp COMPONENT=runtime make component_install cd $(BUILDDEBUGDIR); DESTDIR=../debian/tmp COMPONENT=dev make component_install rm -rf debian/tmp/usr/include @@ -60,21 +60,21 @@ libcmake-init-dbg: dpkg --build debian/tmp .. rm -rf debian/tmp -libcmake-init-examples-data: +libcmake-init-examples-data: build cd $(BUILDDIR); DESTDIR=../debian/tmp COMPONENT=examples_data make component_install mkdir -p debian/tmp/DEBIAN dpkg-gencontrol -plibcmake-init-examples-data dpkg --build debian/tmp .. rm -rf debian/tmp -libcmake-init-examples: +libcmake-init-examples: build cd $(BUILDDIR); DESTDIR=../debian/tmp COMPONENT=examples_qt make component_install mkdir -p debian/tmp/DEBIAN dpkg-gencontrol -plibcmake-init-examples dpkg --build debian/tmp .. rm -rf debian/tmp -libcmake-init-all: +libcmake-init-all: build mkdir -p debian/tmp/DEBIAN dpkg-gencontrol -plibcmake-init-all dpkg --build debian/tmp .. diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index add2670..bbb8185 100644 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -4,7 +4,7 @@ # # Generate version-header -configure_file(version.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/${META_PROJECT_NAME}/${META_PROJECT_NAME}-version.h @ONLY) +configure_file(version.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/${META_PROJECT_NAME}/${META_PROJECT_NAME}-version.h) # diff --git a/source/baselib/CMakeLists.txt b/source/baselib/CMakeLists.txt index 50d91f9..ecefb75 100644 --- a/source/baselib/CMakeLists.txt +++ b/source/baselib/CMakeLists.txt @@ -157,9 +157,9 @@ target_compile_definitions(${target} target_compile_options(${target} PRIVATE - + ${DEFAULT_COMPILE_OPTIONS_PRIVATE} PUBLIC - ${DEFAULT_COMPILE_OPTIONS} + ${DEFAULT_COMPILE_OPTIONS_PUBLIC} INTERFACE ) diff --git a/source/examples/fibcmd/CMakeLists.txt b/source/examples/fibcmd/CMakeLists.txt index 3e83d28..8e4820f 100644 --- a/source/examples/fibcmd/CMakeLists.txt +++ b/source/examples/fibcmd/CMakeLists.txt @@ -91,7 +91,9 @@ target_compile_definitions(${target} target_compile_options(${target} PRIVATE - ${DEFAULT_COMPILE_OPTIONS} + ${DEFAULT_COMPILE_OPTIONS_PRIVATE} + PUBLIC + ${DEFAULT_COMPILE_OPTIONS_PUBLIC} ) diff --git a/source/examples/fibgui/CMakeLists.txt b/source/examples/fibgui/CMakeLists.txt index f794935..8644b4e 100644 --- a/source/examples/fibgui/CMakeLists.txt +++ b/source/examples/fibgui/CMakeLists.txt @@ -114,7 +114,9 @@ target_compile_definitions(${target} target_compile_options(${target} PRIVATE - ${DEFAULT_COMPILE_OPTIONS} + ${DEFAULT_COMPILE_OPTIONS_PRIVATE} + PUBLIC + ${DEFAULT_COMPILE_OPTIONS_PUBLIC} ) diff --git a/source/fiblib/CMakeLists.txt b/source/fiblib/CMakeLists.txt index 5eeb77e..76a0d13 100644 --- a/source/fiblib/CMakeLists.txt +++ b/source/fiblib/CMakeLists.txt @@ -159,9 +159,9 @@ target_compile_definitions(${target} target_compile_options(${target} PRIVATE - + ${DEFAULT_COMPILE_OPTIONS_PRIVATE} PUBLIC - ${DEFAULT_COMPILE_OPTIONS} + ${DEFAULT_COMPILE_OPTIONS_PUBLIC} INTERFACE ) diff --git a/source/tests/CMakeLists.txt b/source/tests/CMakeLists.txt index 632bff3..13959df 100644 --- a/source/tests/CMakeLists.txt +++ b/source/tests/CMakeLists.txt @@ -10,7 +10,10 @@ cmake_minimum_required(VERSION 3.15 FATAL_ERROR) set(META_PROJECT_NAME "template") # Declare project -project("${META_PROJECT_NAME}-tests" C CXX) +project("${META_PROJECT_NAME}-tests") + +enable_language(C) +enable_language(CXX) # Set policies set_policy(CMP0054 NEW) # ENABLE CMP0054: Only interpret if() arguments as variables or keywords when unquoted. diff --git a/source/tests/fiblib-test/CMakeLists.txt b/source/tests/fiblib-test/CMakeLists.txt index 1b70c9c..42b4659 100644 --- a/source/tests/fiblib-test/CMakeLists.txt +++ b/source/tests/fiblib-test/CMakeLists.txt @@ -87,7 +87,9 @@ target_compile_definitions(${target} target_compile_options(${target} PRIVATE - ${DEFAULT_COMPILE_OPTIONS} + ${DEFAULT_COMPILE_OPTIONS_PRIVATE} + PUBLIC + ${DEFAULT_COMPILE_OPTIONS_PUBLIC} ) diff --git a/source/version.h.in b/source/version.h.in index 0c23143..709bd19 100644 --- a/source/version.h.in +++ b/source/version.h.in @@ -1,15 +1,15 @@ -#define @META_PROJECT_ID@_PROJECT_NAME "@META_PROJECT_NAME@" -#define @META_PROJECT_ID@_PROJECT_DESCRIPTION "@META_PROJECT_DESCRIPTION@" +#define ${META_PROJECT_ID}_PROJECT_NAME "@META_PROJECT_NAME@" +#define ${META_PROJECT_ID}_PROJECT_DESCRIPTION "@META_PROJECT_DESCRIPTION@" -#define @META_PROJECT_ID@_AUTHOR_ORGANIZATION "@META_AUTHOR_ORGANIZATION@" -#define @META_PROJECT_ID@_AUTHOR_DOMAIN "@META_AUTHOR_DOMAIN@" -#define @META_PROJECT_ID@_AUTHOR_MAINTAINER "@META_AUTHOR_MAINTAINER@" +#define ${META_PROJECT_ID}_AUTHOR_ORGANIZATION "@META_AUTHOR_ORGANIZATION@" +#define ${META_PROJECT_ID}_AUTHOR_DOMAIN "@META_AUTHOR_DOMAIN@" +#define ${META_PROJECT_ID}_AUTHOR_MAINTAINER "@META_AUTHOR_MAINTAINER@" -#define @META_PROJECT_ID@_VERSION_MAJOR "@META_VERSION_MAJOR@" -#define @META_PROJECT_ID@_VERSION_MINOR "@META_VERSION_MINOR@" -#define @META_PROJECT_ID@_VERSION_PATCH "@META_VERSION_PATCH@" -#define @META_PROJECT_ID@_VERSION_REVISION "@META_VERSION_REVISION@" +#define ${META_PROJECT_ID}_VERSION_MAJOR "@META_VERSION_MAJOR@" +#define ${META_PROJECT_ID}_VERSION_MINOR "@META_VERSION_MINOR@" +#define ${META_PROJECT_ID}_VERSION_PATCH "@META_VERSION_PATCH@" +#define ${META_PROJECT_ID}_VERSION_REVISION "@META_VERSION_REVISION@" -#define @META_PROJECT_ID@_VERSION "@META_VERSION@" -#define @META_PROJECT_ID@_NAME_VERSION "@META_NAME_VERSION@" +#define ${META_PROJECT_ID}_VERSION "@META_VERSION@" +#define ${META_PROJECT_ID}_NAME_VERSION "@META_NAME_VERSION@" diff --git a/template-config.cmake b/template-config.cmake index 0667059..5dd73e3 100644 --- a/template-config.cmake +++ b/template-config.cmake @@ -4,7 +4,6 @@ # # Please adjust the list of submodules to search for. - # Find depencencies include(CMakeFindDependencyMacro) #find_dependency(glm)