1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- include(CheckCCompilerFlag)
- include(CheckCXXCompilerFlag)
- function(check_and_add_flag var flag)
- set(genexp_config_test "1")
- if(ARGV2 STREQUAL "DEBUG_ONLY")
- set(genexp_config_test "$<CONFIG:Debug>")
- elseif(ARGV2 STREQUAL "NO_DEBINFO_ONLY")
- set(genexp_config_test "$<NOT:$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>>")
- elseif(ARGV2 STREQUAL "RELEASE_ONLY")
- set(genexp_config_test "$<NOT:$<CONFIG:Debug>>")
- elseif(ARGV2)
- message(FATAL_ERROR "check_and_add_flag called with incorrect arguments: ${ARGN}")
- endif()
- set(is_c "$<COMPILE_LANGUAGE:C>")
- set(is_cxx "$<COMPILE_LANGUAGE:CXX>")
- set(test_flags_c)
- set(test_flags_cxx)
-
-
- if(CMAKE_GENERATOR MATCHES "Visual Studio")
- set(is_c "0")
- set(is_cxx "1")
- else()
-
-
- set(test_flags_c "${test_flags_c}-Werror ")
- set(test_flags_cxx "${test_flags_cxx}-Werror ")
- endif()
- check_c_compiler_flag("${test_flags_c}${flag}" FLAG_C_${var})
- if(FLAG_C_${var})
- add_compile_options("$<$<AND:${is_c},${genexp_config_test}>:${flag}>")
- endif()
- check_cxx_compiler_flag("${test_flags_cxx}${flag}" FLAG_CXX_${var})
- if(FLAG_CXX_${var})
- add_compile_options("$<$<AND:${is_cxx},${genexp_config_test}>:${flag}>")
- endif()
- endfunction()
|