Skip to content

Commit 8ac6d3d

Browse files
authored
Merge pull request #352 from ldorau/Check_if_CMAKE_BUILD_TYPE_is_correctly_set
Check if CMAKE_BUILD_TYPE is correctly set
2 parents 7533691 + 55e8323 commit 8ac6d3d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,23 @@ option(USE_TSAN "Enable ThreadSanitizer checks" OFF)
2525
option(USE_MSAN "Enable MemorySanitizer checks" OFF)
2626
option(USE_VALGRIND "Enable Valgrind instrumentation" OFF)
2727

28+
set(KNOWN_BUILD_TYPES Release Debug RelWithDebInfo MinSizeRel)
29+
string(REPLACE ";" " " KNOWN_BUILD_TYPES_STR "${KNOWN_BUILD_TYPES}")
30+
31+
if(NOT CMAKE_BUILD_TYPE)
32+
message(STATUS "No build type selected (CMAKE_BUILD_TYPE), defaulting to Release")
33+
set(CMAKE_BUILD_TYPE "Release")
34+
else()
35+
message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
36+
if(NOT CMAKE_BUILD_TYPE IN_LIST KNOWN_BUILD_TYPES)
37+
message(WARNING "Unusual build type was set (${CMAKE_BUILD_TYPE}), please make sure it is a correct one. "
38+
"The following ones are supported by default: ${KNOWN_BUILD_TYPES_STR}.")
39+
endif()
40+
endif()
41+
42+
set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING "Choose the type of build, options are: ${KNOWN_BUILD_TYPES_STR} ..." FORCE)
43+
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${KNOWN_BUILD_TYPES})
44+
2845
# For using the options listed in the OPTIONS_REQUIRING_CXX variable
2946
# a C++17 compiler is required. Moreover, if these options are not set,
3047
# CMake will set up a strict C build, without C++ support.

0 commit comments

Comments
 (0)