TestCXXAcceptsFlag.cmake 1.2 KB

123456789101112131415161718192021222324252627282930
  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. MACRO(CHECK_CXX_ACCEPTS_FLAG FLAGS VARIABLE)
  10. IF(NOT DEFINED ${VARIABLE})
  11. MESSAGE(STATUS "Checking to see if CXX compiler accepts flag ${FLAGS}")
  12. TRY_COMPILE(${VARIABLE}
  13. ${CMAKE_BINARY_DIR}
  14. ${CMAKE_ROOT}/Modules/DummyCXXFile.cxx
  15. CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${FLAGS}
  16. OUTPUT_VARIABLE OUTPUT)
  17. IF(${VARIABLE})
  18. MESSAGE(STATUS "Checking to see if CXX compiler accepts flag ${FLAGS} - yes")
  19. FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeOutput.log
  20. "Determining if the CXX compiler accepts the flag ${FLAGS} passed with "
  21. "the following output:\n${OUTPUT}\n\n")
  22. ELSE(${VARIABLE})
  23. MESSAGE(STATUS "Checking to see if CXX compiler accepts flag ${FLAGS} - no")
  24. FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeFiles/CMakeError.log
  25. "Determining if the CXX compiler accepts the flag ${FLAGS} failed with "
  26. "the following output:\n${OUTPUT}\n\n")
  27. ENDIF(${VARIABLE})
  28. ENDIF(NOT DEFINED ${VARIABLE})
  29. ENDMACRO(CHECK_CXX_ACCEPTS_FLAG)