Debian Codegraph @

cmake/autocmake_safeguards.cmake

raw
1 # Downloaded from
2 # https://github.com/coderefinery/autocmake/blob/master/modules/safeguards.cmake
3 # * changed text of in-source message
4
5 #.rst:
6 #
7 # Provides safeguards against in-source builds and bad build types.
8 #
9 # Variables used::
10 #
11 # PROJECT_SOURCE_DIR
12 # PROJECT_BINARY_DIR
13 # CMAKE_BUILD_TYPE
14
15 if(${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR})
16 message(FATAL_ERROR "In-source builds not allowed. Please run CMake from top directory and specify a build directory (e.g., cmake -H. -Bbuild).")
17 endif()
18
19 string(TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_tolower)
20 string(TOUPPER "${CMAKE_BUILD_TYPE}" cmake_build_type_toupper)
21
22 if(NOT cmake_build_type_tolower STREQUAL "debug" AND
23 NOT cmake_build_type_tolower STREQUAL "release" AND
24 NOT cmake_build_type_tolower STREQUAL "relwithdebinfo")
25 message(FATAL_ERROR "Unknown build type \"${CMAKE_BUILD_TYPE}\". Allowed values are Debug, Release, RelWithDebInfo (case-insensitive).")
26 endif()