TestCXXAcceptsFlag.cmake 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #.rst:
  4. # TestCXXAcceptsFlag
  5. # ------------------
  6. #
  7. # Deprecated. See :module:`CheckCXXCompilerFlag`.
  8. #
  9. # Check if the CXX compiler accepts a flag.
  10. #
  11. # .. code-block:: cmake
  12. #
  13. # CHECK_CXX_ACCEPTS_FLAG(<flags> <variable>)
  14. #
  15. # ``<flags>``
  16. # the flags to try
  17. # ``<variable>``
  18. # variable to store the result
  19. macro(CHECK_CXX_ACCEPTS_FLAG FLAGS VARIABLE)
  20. if(NOT DEFINED ${VARIABLE})
  21. message(STATUS "Checking to see if CXX compiler accepts flag ${FLAGS}")
  22. try_compile(${VARIABLE}
  23. ${CMAKE_BINARY_DIR}
  24. ${CMAKE_ROOT}/Modules/DummyCXXFile.cxx
  25. CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${FLAGS}
  26. OUTPUT_VARIABLE OUTPUT)
  27. if(${VARIABLE})
  28. message(STATUS "Checking to see if CXX compiler accepts flag ${FLAGS} - yes")
  29. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  30. "Determining if the CXX compiler accepts the flag ${FLAGS} passed with "
  31. "the following output:\n${OUTPUT}\n\n")
  32. else()
  33. message(STATUS "Checking to see if CXX compiler accepts flag ${FLAGS} - no")
  34. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  35. "Determining if the CXX compiler accepts the flag ${FLAGS} failed with "
  36. "the following output:\n${OUTPUT}\n\n")
  37. endif()
  38. endif()
  39. endmacro()