CheckCCompilerFlag.cmake 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. #=============================================================================
  9. # Copyright 2006-2011 Kitware, Inc.
  10. # Copyright 2006 Alexander Neundorf <[email protected]>
  11. # Copyright 2011 Matthias Kretz <[email protected]>
  12. #
  13. # Distributed under the OSI-approved BSD License (the "License");
  14. # see accompanying file Copyright.txt for details.
  15. #
  16. # This software is distributed WITHOUT ANY WARRANTY; without even the
  17. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  18. # See the License for more information.
  19. #=============================================================================
  20. # (To distribute this file outside of CMake, substitute the full
  21. # License text for the above reference.)
  22. INCLUDE(CheckCSourceCompiles)
  23. MACRO (CHECK_C_COMPILER_FLAG _FLAG _RESULT)
  24. SET(SAFE_CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}")
  25. SET(CMAKE_REQUIRED_DEFINITIONS "${_FLAG}")
  26. CHECK_C_SOURCE_COMPILES("int main(void) { return 0; }" ${_RESULT}
  27. # Some compilers do not fail with a bad flag
  28. FAIL_REGEX "command line option .* is valid for .* but not for C" # GNU
  29. FAIL_REGEX "unrecognized .*option" # GNU
  30. FAIL_REGEX "unknown .*option" # Clang
  31. FAIL_REGEX "ignoring unknown option" # MSVC
  32. FAIL_REGEX "warning D9002" # MSVC, any lang
  33. FAIL_REGEX "option .*not supported" # Intel
  34. FAIL_REGEX "[Uu]nknown option" # HP
  35. FAIL_REGEX "[Ww]arning: [Oo]ption" # SunPro
  36. FAIL_REGEX "command option .* is not recognized" # XL
  37. FAIL_REGEX "WARNING: unknown flag:" # Open64
  38. )
  39. SET (CMAKE_REQUIRED_DEFINITIONS "${SAFE_CMAKE_REQUIRED_DEFINITIONS}")
  40. ENDMACRO (CHECK_C_COMPILER_FLAG)