ctkFunctionCheckCompilerFlags.cmake 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #
  2. # Helper macro allowing to check if the given flags are supported
  3. # by the underlying build tool
  4. #
  5. # If the flag(s) is/are supported, they will be appended to the string identified by RESULT_VAR
  6. #
  7. # Usage:
  8. # ctkFunctionCheckCompilerFlags(FLAGS_TO_CHECK VALID_FLAGS_VAR)
  9. #
  10. # Example:
  11. #
  12. # set(myflags)
  13. # ctkFunctionCheckCompilerFlags("-fprofile-arcs" myflags)
  14. # message(1-myflags:${myflags})
  15. # ctkFunctionCheckCompilerFlags("-fauto-bugfix" myflags)
  16. # message(2-myflags:${myflags})
  17. # ctkFunctionCheckCompilerFlags("-Wall" myflags)
  18. # message(1-myflags:${myflags})
  19. #
  20. # The output will be:
  21. # 1-myflags: -fprofile-arcs
  22. # 2-myflags: -fprofile-arcs
  23. # 3-myflags: -fprofile-arcs -Wall
  24. INCLUDE(TestCXXAcceptsFlag)
  25. FUNCTION(ctkFunctionCheckCompilerFlags CXX_FLAG_TO_TEST RESULT_VAR)
  26. IF(CXX_FLAG_TO_TEST STREQUAL "")
  27. MESSAGE(FATAL_ERROR "CXX_FLAG_TO_TEST shouldn't be empty")
  28. ENDIF()
  29. CHECK_CXX_ACCEPTS_FLAG(${CXX_FLAG_TO_TEST} HAS_FLAG)
  30. IF(HAS_FLAG)
  31. SET(${RESULT_VAR} "${${RESULT_VAR}} ${CXX_FLAG_TO_TEST}" PARENT_SCOPE)
  32. ENDIF()
  33. ENDFUNCTION()