1
0

CheckCCompilerFlag.cmake 1.1 KB

123456789101112131415161718192021222324252627
  1. # - Check whether the C compiler supports a given flag.
  2. # CHECK_C_COMPILER_FLAG(<flag> <var>)
  3. # <flag> - the compiler flag
  4. # <var> - variable to store the result
  5. # This internally calls the check_c_source_compiles macro.
  6. # See help for CheckCSourceCompiles for a listing of variables
  7. # that can 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(CheckCSourceCompiles)
  13. MACRO (CHECK_C_COMPILER_FLAG _FLAG _RESULT)
  14. SET(SAFE_CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}")
  15. SET(CMAKE_REQUIRED_DEFINITIONS "${_FLAG}")
  16. CHECK_C_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_C_COMPILER_FLAG)