Skip to content

Commit 55e8323

Browse files
committed
Check if CMAKE_BUILD_TYPE is correctly set
Signed-off-by: Lukasz Dorau <lukasz.dorau@intel.com>
1 parent 87a2d94 commit 55e8323

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
@@ -26,6 +26,23 @@ option(USE_TSAN "Enable ThreadSanitizer checks" OFF)
2626
option(USE_MSAN "Enable MemorySanitizer checks" OFF)
2727
option(USE_VALGRIND "Enable Valgrind instrumentation" OFF)
2828

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

0 commit comments

Comments
 (0)