Collection of DPF-based plugins for packaging
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.9KB

  1. include(CheckCXXCompilerFlag)
  2. include(CheckCXXSourceCompiles)
  3. macro(enable_cflags_if_supported)
  4. foreach(flag ${ARGN})
  5. check_cxx_compiler_flag("${flag}" CXXFLAG_${flag}_SUPPORTED)
  6. if(CXXFLAG_${flag}_SUPPORTED)
  7. add_compile_options("${flag}")
  8. endif()
  9. endforeach()
  10. endmacro()
  11. macro(enable_linker_flags_if_supported)
  12. set(_old_CMAKE_REQUIRED_LINK_OPTIONS "${CMAKE_REQUIRED_LINK_OPTIONS}")
  13. foreach(flag ${ARGN})
  14. set(CMAKE_REQUIRED_LINK_OPTIONS "${flag}")
  15. check_cxx_source_compiles("int main(){return 0;}" LDCFLAG_${flag}_SUPPORTED)
  16. if(LDCFLAG_${flag}_SUPPORTED)
  17. add_link_options(${flag})
  18. else()
  19. set(CMAKE_REQUIRED_LINK_OPTIONS "LINKER:${flag}")
  20. check_cxx_source_compiles("int main(){return 0;}" LDCFLAG_LINKER_${flag}_SUPPORTED)
  21. if(LDFLAG_LINKER_${flag}_SUPPORTED)
  22. add_link_options(LINKER:${flag})
  23. endif()
  24. endif()
  25. endforeach()
  26. set(CMAKE_REQUIRED_LINK_OPTIONS "${_old_CMAKE_REQUIRED_LINK_OPTIONS}")
  27. endmacro()
  28. macro(enable_target_linker_flags_if_supported target access)
  29. set(_old_CMAKE_REQUIRED_LINK_OPTIONS "${CMAKE_REQUIRED_LINK_OPTIONS}")
  30. foreach(flag ${ARGN})
  31. set(CMAKE_REQUIRED_LINK_OPTIONS "${flag}")
  32. check_cxx_source_compiles("int main(){return 0;}" LDCFLAG_${flag}_SUPPORTED)
  33. if(LDCFLAG_${flag}_SUPPORTED)
  34. target_link_options(${target} ${access} ${flag})
  35. else()
  36. set(CMAKE_REQUIRED_LINK_OPTIONS "LINKER:${flag}")
  37. check_cxx_source_compiles("int main(){return 0;}" LDCFLAG_LINKER_${flag}_SUPPORTED)
  38. if(LDFLAG_LINKER_${flag}_SUPPORTED)
  39. target_link_options(${target} ${access} LINKER:${flag})
  40. endif()
  41. endif()
  42. endforeach()
  43. set(CMAKE_REQUIRED_LINK_OPTIONS "${_old_CMAKE_REQUIRED_LINK_OPTIONS}")
  44. endmacro()