diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 19e67710..27f7f1b0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -67,15 +67,15 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") ) endif() -if(UNITS_DOWNCAST_MODE STREQUAL "AUTO") - message(STATUS "Configuring UNITS_DOWNCAST_MODE=AUTOMATIC") - target_compile_definitions(mp-units INTERFACE UNITS_DOWNCAST_MODE=2) -elseif(UNITS_DOWNCAST_MODE) - message(STATUS "Configuring UNITS_DOWNCAST_MODE=ON") - target_compile_definitions(mp-units INTERFACE UNITS_DOWNCAST_MODE=1) -else() - message(STATUS "Configuring UNITS_DOWNCAST_MODE=OFF") - target_compile_definitions(mp-units INTERFACE UNITS_DOWNCAST_MODE=0) +if(DEFINED UNITS_DOWNCAST_MODE) + set(downcast_mode_options OFF ON AUTO) + list(FIND downcast_mode_options "${UNITS_DOWNCAST_MODE}" downcast_mode) + if(downcast_mode EQUAL -1) + message(FATAL_ERROR "'${UNITS_DOWNCAST_MODE}' is an invalid UNITS_DOWNCAST_MODE value") + else() + message(STATUS "Configuring UNITS_DOWNCAST_MODE=${UNITS_DOWNCAST_MODE}") + target_compile_definitions(mp-units INTERFACE UNITS_DOWNCAST_MODE=${downcast_mode}) + endif() endif() add_library(mp::units ALIAS mp-units)