cmake: Simplify build type configuration.
authorMathias Preiner <mathias.preiner@gmail.com>
Wed, 12 Sep 2018 20:58:41 +0000 (13:58 -0700)
committerMathias Preiner <mathias.preiner@gmail.com>
Sat, 22 Sep 2018 23:30:59 +0000 (16:30 -0700)
CMakeLists.txt

index 4120e598474dd41f962b79b59700873392a3804a..a1d137232ee5455600203037a47b010636d9206d 100644 (file)
@@ -273,11 +273,14 @@ option(BUILD_BINDINGS_PYTHON "Build Python bindings")
 set(OPTIMIZATION_LEVEL 3)
 set(GPL_LIBS "")
 
-set(BUILD_TYPES Production Debug Testing Competition)
-
 #-----------------------------------------------------------------------------#
 # Build types
 
+
+# Note: Module CodeCoverage requires the name of the debug build to conform
+#       to cmake standards (first letter uppercase).
+set(BUILD_TYPES Production Debug Testing Competition)
+
 if(ENABLE_ASAN)
   set(CMAKE_BUILD_TYPE Debug)
 endif()
@@ -289,20 +292,17 @@ if(NOT CMAKE_BUILD_TYPE)
   # Provide drop down menu options in cmake-gui
   set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${BUILD_TYPES})
 endif()
-message(STATUS "Building ${CMAKE_BUILD_TYPE} build")
 
-# Note: Module CodeCoverage requires the name of the debug build to conform
-#       to cmake standards (first letter uppercase).
-if(CMAKE_BUILD_TYPE STREQUAL "Debug")
-  include(ConfigDebug)
-elseif(CMAKE_BUILD_TYPE STREQUAL "Production")
-  include(ConfigProduction)
-elseif(CMAKE_BUILD_TYPE STREQUAL "Testing")
-  include(ConfigTesting)
-elseif(CMAKE_BUILD_TYPE STREQUAL "Competition")
-  include(ConfigCompetition)
+list(FIND BUILD_TYPES ${CMAKE_BUILD_TYPE} FOUND_BUILD_TYPE)
+if(${FOUND_BUILD_TYPE} EQUAL -1)
+  message(FATAL_ERROR
+    "'${CMAKE_BUILD_TYPE}' is not a valid build type. "
+    "Available builds are: ${BUILD_TYPES}")
 endif()
 
+message(STATUS "Building ${CMAKE_BUILD_TYPE} build")
+include(Config${CMAKE_BUILD_TYPE})
+
 #-----------------------------------------------------------------------------#
 # Compiler flags