CheckCXXCompilerFlag.cmake 1.7 KB

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