TestCXXAcceptsFlag.cmake 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. .. deprecated:: 3.0
  7. See :module:`CheckCXXCompilerFlag`.
  8. Check if the CXX compiler accepts a flag.
  9. .. code-block:: cmake
  10. CHECK_CXX_ACCEPTS_FLAG(<flags> <variable>)
  11. ``<flags>``
  12. the flags to try
  13. ``<variable>``
  14. variable to store the result
  15. #]=======================================================================]
  16. macro(CHECK_CXX_ACCEPTS_FLAG FLAGS VARIABLE)
  17. if(NOT DEFINED ${VARIABLE})
  18. message(STATUS "Checking to see if CXX compiler accepts flag ${FLAGS}")
  19. try_compile(${VARIABLE}
  20. ${CMAKE_BINARY_DIR}
  21. ${CMAKE_ROOT}/Modules/DummyCXXFile.cxx
  22. CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${FLAGS}
  23. OUTPUT_VARIABLE OUTPUT)
  24. if(${VARIABLE})
  25. message(STATUS "Checking to see if CXX compiler accepts flag ${FLAGS} - yes")
  26. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  27. "Determining if the CXX compiler accepts the flag ${FLAGS} passed with "
  28. "the following output:\n${OUTPUT}\n\n")
  29. else()
  30. message(STATUS "Checking to see if CXX compiler accepts flag ${FLAGS} - no")
  31. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  32. "Determining if the CXX compiler accepts the flag ${FLAGS} failed with "
  33. "the following output:\n${OUTPUT}\n\n")
  34. endif()
  35. endif()
  36. endmacro()