From 18f705beed91b660e2226f500e73cd25dbc5b850 Mon Sep 17 00:00:00 2001 From: Lars Melchior Date: Thu, 16 Apr 2020 10:38:40 +0200 Subject: [PATCH] add tools.cmake --- CMakeLists.txt | 14 +++++++++----- cmake/tools.cmake | 33 +++++++++++++++++++++++++++++++++ test/CMakeLists.txt | 10 ---------- 3 files changed, 42 insertions(+), 15 deletions(-) create mode 100644 cmake/tools.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 2913c6b..4750542 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,12 +14,9 @@ if(PROJECT_SOURCE_DIR STREQUAL PROJECT_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() -# ---- Add source files ---- +# --- Import tools ---- -# Note: globbing sources is considered bad practice as CMake's generators may not detect new files automatically. -# Keep that in mind when changing files, or explicitly mention them here. -FILE(GLOB_RECURSE headers CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h") -FILE(GLOB_RECURSE sources CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp") +include(cmake/tools.cmake) # ---- Add dependencies via CPM ---- # see https://github.com/TheLartians/CPM.cmake for more info @@ -33,6 +30,13 @@ CPMAddPackage( VERSION 1.0 ) +# ---- Add source files ---- + +# Note: globbing sources is considered bad practice as CMake's generators may not detect new files automatically. +# Keep that in mind when changing files, or explicitly mention them here. +FILE(GLOB_RECURSE headers CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h") +FILE(GLOB_RECURSE sources CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp") + # ---- Create library ---- # Note: for header-only libraries change all PUBLIC flags to INTERFACE and create an interface target: diff --git a/cmake/tools.cmake b/cmake/tools.cmake new file mode 100644 index 0000000..31ec37c --- /dev/null +++ b/cmake/tools.cmake @@ -0,0 +1,33 @@ +# this file contains a list of tools that can be activated and downloaded on-demand +# each tool is enabled during configuration by passing an additional `-DUSE_=` argument to CMake + +# determine if a tool has already been enabled +foreach(TOOL USE_SANITIZER;USE_CCACHE) + get_property(${TOOL}_ENABLED GLOBAL "" PROPERTY ${TOOL}_ENABLED SET) +endforeach() + +# enables sanitizers support using the the `USE_SANITIZER` flag +# available values are: Address, Memory, MemoryWithOrigins, Undefined, Thread, Leak, 'Address;Undefined' +if (USE_SANITIZER AND NOT USE_SANITIZER_ENABLED) + set_property(GLOBAL PROPERTY USE_SANITIZER_ENABLED true) + + CPMAddPackage( + NAME StableCoder-cmake-scripts + GITHUB_REPOSITORY StableCoder/cmake-scripts + GIT_TAG 3a469d8251660a97dbf9e0afff0a242965d40277 + ) + + include(${StableCoder-cmake-scripts_SOURCE_DIR}/sanitizers.cmake) +endif() + +# enables CCACHE support through the USE_CCACHE flag +# possible values are: YES, NO or equivalent +if (USE_CCACHE AND NOT USE_CCACHE_ENABLED) + set_property(GLOBAL PROPERTY USE_CCACHE_ENABLED true) + + CPMAddPackage( + NAME Ccache.cmake + GITHUB_REPOSITORY TheLartians/Ccache.cmake + VERSION 1.1 + ) +endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b56e38d..1b0a5e5 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -34,16 +34,6 @@ CPMAddPackage( VERSION 1.0 ) -CPMAddPackage( - NAME StableCoder-cmake-scripts - GITHUB_REPOSITORY StableCoder/cmake-scripts - GIT_TAG 3a469d8251660a97dbf9e0afff0a242965d40277 -) - -# adds support the the `USE_SANITIZER` flag -# available options are: Address, Memory, MemoryWithOrigins, Undefined, Thread, Leak, 'Address;Undefined' -include(${StableCoder-cmake-scripts_SOURCE_DIR}/sanitizers.cmake) - # ---- Create binary ---- file(GLOB sources CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp)