TestCXXAcceptsFlag.cmake 1.2 KB

1234567891011121314151617181920212223242526272829
  1. #
  2. # Check if the CXX compiler accepts a flag
  3. #
  4. # CHECK_FUNCTION_EXISTS - macro which checks if the function exists
  5. # FLAG - the flags to try
  6. # VARIABLE - variable to store the result
  7. #
  8. MACRO(CHECK_CXX_ACCEPTS_FLAG FLAGS VARIABLE)
  9. IF(NOT DEFINED ${VARIABLE})
  10. MESSAGE(STATUS "Checking to see if CXX compiler accepts flag ${FLAGS}")
  11. TRY_COMPILE(${VARIABLE}
  12. ${CMAKE_BINARY_DIR}
  13. ${CMAKE_ROOT}/Modules/DummyCXXFile.cxx
  14. CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${FLAGS}
  15. OUTPUT_VARIABLE OUTPUT)
  16. IF(${VARIABLE})
  17. MESSAGE(STATUS "Checking to see if CXX compiler accepts flag ${FLAGS} - yes")
  18. FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeOutput.log
  19. "Determining if the CXX compiler accepts the flag ${FLAGS} passed with "
  20. "the following output:\n${OUTPUT}\n\n")
  21. ELSE(${VARIABLE})
  22. MESSAGE(STATUS "Checking to see if CXX compiler accepts flag ${FLAGS} - no")
  23. FILE(APPEND ${CMAKE_BINARY_DIR}/CMakeError.log
  24. "Determining if the CXX compiler accepts the flag ${FLAGS} failed with "
  25. "the following output:\n${OUTPUT}\n\n")
  26. ENDIF(${VARIABLE})
  27. ENDIF(NOT DEFINED ${VARIABLE})
  28. ENDMACRO(CHECK_CXX_ACCEPTS_FLAG)