CheckCXXCompilerFlag.cmake 1.1 KB

123456789101112131415161718192021222324252627
  1. # - Check whether the CXX compiler supports a given flag.
  2. # CHECK_CXX_COMPILER_FLAG(<flag> <var>)
  3. # <flag> - the compiler flag
  4. # <var> - variable to store the result
  5. # This internally calls the check_cxx_source_compiles macro. See help
  6. # for CheckCXXSourceCompiles for a listing of variables that can
  7. # modify the build.
  8. # Copyright (c) 2006, Alexander Neundorf, <[email protected]>
  9. #
  10. # Redistribution and use is allowed according to the terms of the BSD license.
  11. # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
  12. INCLUDE(CheckCXXSourceCompiles)
  13. MACRO (CHECK_CXX_COMPILER_FLAG _FLAG _RESULT)
  14. SET(SAFE_CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}")
  15. SET(CMAKE_REQUIRED_DEFINITIONS "${_FLAG}")
  16. CHECK_CXX_SOURCE_COMPILES("int main() { return 0;}" ${_RESULT}
  17. # Some compilers do not fail with a bad flag
  18. FAIL_REGEX "unrecognized option" # GNU
  19. FAIL_REGEX "ignoring unknown option" # MSVC
  20. )
  21. SET (CMAKE_REQUIRED_DEFINITIONS "${SAFE_CMAKE_REQUIRED_DEFINITIONS}")
  22. ENDMACRO (CHECK_CXX_COMPILER_FLAG)