TestCXXAcceptsFlag.cmake 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #.rst:
  2. # TestCXXAcceptsFlag
  3. # ------------------
  4. #
  5. # Deprecated. See :module:`CheckCXXCompilerFlag`.
  6. #
  7. # Check if the CXX compiler accepts a flag.
  8. #
  9. # .. code-block:: cmake
  10. #
  11. # CHECK_CXX_ACCEPTS_FLAG(<flags> <variable>)
  12. #
  13. # ``<flags>``
  14. # the flags to try
  15. # ``<variable>``
  16. # variable to store the result
  17. #=============================================================================
  18. # Copyright 2002-2009 Kitware, Inc.
  19. #
  20. # Distributed under the OSI-approved BSD License (the "License");
  21. # see accompanying file Copyright.txt for details.
  22. #
  23. # This software is distributed WITHOUT ANY WARRANTY; without even the
  24. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  25. # See the License for more information.
  26. #=============================================================================
  27. # (To distribute this file outside of CMake, substitute the full
  28. # License text for the above reference.)
  29. macro(CHECK_CXX_ACCEPTS_FLAG FLAGS VARIABLE)
  30. if(NOT DEFINED ${VARIABLE})
  31. message(STATUS "Checking to see if CXX compiler accepts flag ${FLAGS}")
  32. try_compile(${VARIABLE}
  33. ${CMAKE_BINARY_DIR}
  34. ${CMAKE_ROOT}/Modules/DummyCXXFile.cxx
  35. CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${FLAGS}
  36. OUTPUT_VARIABLE OUTPUT)
  37. if(${VARIABLE})
  38. message(STATUS "Checking to see if CXX compiler accepts flag ${FLAGS} - yes")
  39. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  40. "Determining if the CXX compiler accepts the flag ${FLAGS} passed with "
  41. "the following output:\n${OUTPUT}\n\n")
  42. else()
  43. message(STATUS "Checking to see if CXX compiler accepts flag ${FLAGS} - no")
  44. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  45. "Determining if the CXX compiler accepts the flag ${FLAGS} failed with "
  46. "the following output:\n${OUTPUT}\n\n")
  47. endif()
  48. endif()
  49. endmacro()