TargetIncludeSystemDirectories_unsupported.cmake 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #
  2. # Copyright (c) Contributors to the Open 3D Engine Project.
  3. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. #
  5. # SPDX-License-Identifier: Apache-2.0 OR MIT
  6. #
  7. #
  8. #! ly_target_include_system_directories: adds a system include to the target. This is the same behavior as target_include_directories
  9. # passing the SYSTEM parameter. However, this supports doing it in generators that CMake still does not.
  10. #
  11. # To handle platforms that yet not support SYSTEM includes, we pass the includes as part of compilation options
  12. # Once all platforms support it, we can roll back to target_include_directories
  13. # We are using the same variable for the system include that CMake does, so this works in all platforms where cmake supports
  14. # it and by defining the variables, it will support it in platforms where the compiler supports it but CMake still didnt
  15. # add it to the generator (e.g. MSVC: https://gitlab.kitware.com/cmake/cmake/issues/17904)
  16. #
  17. # \arg:TARGET name of the target
  18. # \arg:INTERFACE includes to apply to INTERFACE
  19. # \arg:PUBLIC includes to apply to PUBLIC
  20. # \arg:PRIVATE includes to apply to PRIVATE
  21. #
  22. function(ly_target_include_system_directories)
  23. set(options)
  24. set(oneValueArgs TARGET)
  25. set(multiValueArgs INTERFACE PUBLIC PRIVATE)
  26. cmake_parse_arguments(ly_target_include_system_directories "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
  27. if(NOT ly_target_include_system_directories_TARGET)
  28. message(FATAL_ERROR "Target not provided")
  29. endif()
  30. if(LY_CXX_SYSTEM_INCLUDE_CONFIGURATION_FLAG)
  31. target_compile_options(${ly_target_include_system_directories_TARGET}
  32. INTERFACE
  33. ${LY_CXX_SYSTEM_INCLUDE_CONFIGURATION_FLAG}
  34. )
  35. endif()
  36. foreach(type ITEMS INTERFACE PUBLIC PRIVATE)
  37. foreach(include_dir ${ly_target_include_system_directories_${type}})
  38. string(GENEX_STRIP ${include_dir} include_genex_expr)
  39. # Skip over any include directory value which contains a generator expression
  40. # It's path cannot be validated at configure
  41. # The check validates that the string stripped from generation expressions is the same as the original string
  42. if(include_genex_expr STREQUAL include_dir AND NOT EXISTS ${include_dir})
  43. message(FATAL_ERROR "Cannot find 3rdParty library ${ly_add_external_target_NAME} include path ${include_dir}")
  44. endif()
  45. target_compile_options(${ly_target_include_system_directories_TARGET}
  46. ${type} ${CMAKE_INCLUDE_SYSTEM_FLAG_CXX}${include_dir}
  47. )
  48. # For windows add the includes to the INTERFACE_SYSTEM_INCLUDE_DIRECTORIES directly so that the property
  49. # is available in dependent targets
  50. set_property(TARGET ${ly_target_include_system_directories_TARGET} APPEND
  51. PROPERTY INTERFACE_SYSTEM_INCLUDE_DIRECTORIES ${include_dir})
  52. endforeach()
  53. endforeach()
  54. endfunction()