diff --git a/CMakeLists.txt b/CMakeLists.txt index 927e534..a480b58 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,15 +51,27 @@ else() add_compile_options(-g) endif() -option(BUILD_SHARED_LIBS "Build a shared library" OFF) +macro(xoption OPTION_NAME OPTION_TEXT OPTION_DEFAULT) + option(${OPTION_NAME} ${OPTION_TEXT} ${OPTION_DEFAULT}) + if(DEFINED ENV{${OPTION_NAME}}) + # Allow setting the option through an environment variable. + set(${OPTION_NAME} $ENV{${OPTION_NAME}}) + endif() + if(${OPTION_NAME}) + add_definitions(-D${OPTION_NAME}) + endif() + message(STATUS " ${OPTION_NAME}: ${${OPTION_NAME}}") +endmacro() + +xoption(BUILD_SHARED_LIBS "Build a shared library" OFF) if(BUILD_SHARED_LIBS) message(STATUS "Building a shared library") endif() -option(BUILD_EXAMPLES "Build examples" OFF) -option(CONFIG_ASAN "Enable AddressSanitizer (ASan)" OFF) -option(CONFIG_MSAN "Enable MemorySanitizer (MSan)" OFF) -option(CONFIG_UBSAN "Enable UndefinedBehaviorSanitizer (UBSan)" OFF) +xoption(BUILD_EXAMPLES "Build examples" OFF) +xoption(CONFIG_ASAN "Enable AddressSanitizer (ASan)" OFF) +xoption(CONFIG_MSAN "Enable MemorySanitizer (MSan)" OFF) +xoption(CONFIG_UBSAN "Enable UndefinedBehaviorSanitizer (UBSan)" OFF) if(CONFIG_ASAN) message(STATUS "Building with ASan")