TestCXXAcceptsFlag.cmake 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # - Test CXX compiler for a flag
  2. # Check if the CXX compiler accepts a flag
  3. #
  4. # Macro CHECK_CXX_ACCEPTS_FLAG(FLAGS VARIABLE) -
  5. # checks if the function exists
  6. # FLAGS - the flags to try
  7. # VARIABLE - variable to store the result
  8. #
  9. #=============================================================================
  10. # Copyright 2002-2009 Kitware, Inc.
  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. macro(CHECK_CXX_ACCEPTS_FLAG FLAGS VARIABLE)
  22. if(NOT DEFINED ${VARIABLE})
  23. message(STATUS "Checking to see if CXX compiler accepts flag ${FLAGS}")
  24. try_compile(${VARIABLE}
  25. ${CMAKE_BINARY_DIR}
  26. ${CMAKE_ROOT}/Modules/DummyCXXFile.cxx
  27. CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${FLAGS}
  28. OUTPUT_VARIABLE OUTPUT)
  29. if(${VARIABLE})
  30. message(STATUS "Checking to see if CXX compiler accepts flag ${FLAGS} - yes")
  31. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  32. "Determining if the CXX compiler accepts the flag ${FLAGS} passed with "
  33. "the following output:\n${OUTPUT}\n\n")
  34. else()
  35. message(STATUS "Checking to see if CXX compiler accepts flag ${FLAGS} - no")
  36. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  37. "Determining if the CXX compiler accepts the flag ${FLAGS} failed with "
  38. "the following output:\n${OUTPUT}\n\n")
  39. endif()
  40. endif()
  41. endmacro()