diff --git a/CMakeLists.txt b/CMakeLists.txt
index 114048b813c853eec236aca5154f15e97624569a..dcca8cada76741ea78fe9eb0a62c66e37cf3da09 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -49,15 +49,9 @@ if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
       STRING "Choose the type of build." FORCE)
 else (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
   # Ignore capitalization when build type is selected manually and check for valid setting
-  string(TOLOWER ${CMAKE_BUILD_TYPE} selected_lower)
-  foreach(build ${allowed_build_types})
-    string(TOLOWER ${build} build_lower)
-    if (build_lower STREQUAL selected_lower)
-      set (CMAKE_BUILD_TYPE ${build})
-      set (build_type_found True)
-    endif()
-  endforeach()
-  if (NOT build_type_found)
+  string (TOLOWER ${CMAKE_BUILD_TYPE} selected_lower)
+  string (TOLOWER "${allowed_build_types}" build_types_lower)
+  if (NOT selected_lower IN_LIST build_types_lower)
     message (FATAL_ERROR "Unknown build type: ${CMAKE_BUILD_TYPE} [allowed: ${allowed_build_types}]")
   endif ()
   message (STATUS "Build type is: ${CMAKE_BUILD_TYPE}")