Skip to content

Commit

Permalink
Prevent In-source builds
Browse files Browse the repository at this point in the history
  • Loading branch information
ClausKlein committed Sep 8, 2024
1 parent 04fd81c commit 84cc7f4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
32 changes: 31 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion chapter13/ex03_external_cmake_module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 84cc7f4

Please sign in to comment.