From 84cc7f43af9682b081de51d14264b2bc45f2595b Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Sun, 8 Sep 2024 11:32:33 +0200 Subject: [PATCH] Prevent In-source builds --- CMakeLists.txt | 32 ++++++++++++++++++- .../ex03_external_cmake_module/CMakeLists.txt | 3 +- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 22c395f..c465ad1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,19 @@ project( "The 'build-all' instructions for all examples for the book CMake Best Practices" LANGUAGES CXX ) -include(CTest) + +# TODO(CK) only needed if working as "Dashboard Client" include(CTest) +enable_testing() + +# cmake-format: off +# see the CMAKE_SOURCE_DIR like readonly! +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) + message( + FATAL_ERROR + "In-source builds are not supported! " + "You may need to delete 'CMakeCache.txt' and 'CMakeFiles/' first." + ) +endif() # Add additional targets to your CMake project: if(EXISTS Format.cmake/CMakeLists.txt) @@ -25,6 +37,24 @@ if(EXISTS Format.cmake/CMakeLists.txt) # cmake-format fix-clang-format fix-cmake-format fix-format format endif() +if(PROJECT_IS_TOP_LEVEL) + option(BUILD_SHARED_LIBS "Build shared libs." OFF) + option(BUILD_TESTING "Build SelfTest project" ON) +endif() + +# This property setting also needs to be consistent between the installed shared +# library and its consumer, otherwise most toolchains will once again reject the +# consumer's generated BMI. +if(NOT DEFINED CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 20) + set(CMAKE_CXX_EXTENSIONS FALSE) + set(CMAKE_CXX_STANDARD_REQUIRED TRUE) + + set(CMAKE_CXX_VISIBILITY_PRESET hidden) + set(CMAKE_VISIBILITY_INLINES_HIDDEN TRUE) +endif() +# cmake-format: on + # Set the default build type for single-config generators. The build type # variable is still overridable from outside. set(CMAKE_BUILD_TYPE diff --git a/chapter13/ex03_external_cmake_module/CMakeLists.txt b/chapter13/ex03_external_cmake_module/CMakeLists.txt index c468213..3b7cc6d 100644 --- a/chapter13/ex03_external_cmake_module/CMakeLists.txt +++ b/chapter13/ex03_external_cmake_module/CMakeLists.txt @@ -22,6 +22,7 @@ fetchcontent_declare( GIT_TAG 7d0447fcadf8e93d25f242b9bb251ecbcf67f8cb SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/.hadouken" ) +# FIXME(CK): see the CMAKE_SOURCE_DIR like readonly! # Fetch hadouken fetchcontent_makeavailable(hadouken) @@ -30,7 +31,7 @@ fetchcontent_makeavailable(hadouken) list( APPEND CMAKE_MODULE_PATH - ${CMAKE_CURRENT_LIST_DIR}/.hadouken/cmake/modules + ${hadouken_SOURCE_DIR}/cmake/modules ) # Include some CMake modules provided by the Hadouken