Dependencies.cmake 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. include(FindPackageHandleStandardArgs)
  9. #! ly_add_dependencies: wrapper to add_dependencies, however, this wrapper collaborates with
  10. # LYWrappers.cmake to delay adding dependencies if the target is not declared yet.
  11. #
  12. # This wrapper will add the dependency to the indicated target immediately if the target was
  13. # already added. If the target was not added at the moment this function is called, the dependency
  14. # will be stored in a global variable which ly_add_target will access and create those dependencies
  15. # after the target is added.
  16. #
  17. # \arg:TARGET name of the target
  18. # \arg:DEPENDENCIES dependencies to add to TARGET
  19. #
  20. function(ly_add_dependencies TARGET)
  21. if(NOT TARGET)
  22. message(FATAL_ERROR "You must provide a target")
  23. endif()
  24. set (extra_function_args ${ARGN})
  25. if(num_extra_args)
  26. message(FATAL_ERROR "You must provide at least a dependency")
  27. endif()
  28. if(${TARGET} IN_LIST extra_function_args)
  29. message(FATAL_ERROR "Cyclic dependency detected ${TARGET} depends on ${extra_function_args}")
  30. endif()
  31. if(TARGET ${TARGET})
  32. # Target already created, add it
  33. ly_parse_third_party_dependencies("${extra_function_args}")
  34. # Dependencies can only be added on non-alias target
  35. ly_de_alias_target(${TARGET} de_aliased_target)
  36. add_dependencies(${de_aliased_target} ${extra_function_args})
  37. else()
  38. set_property(GLOBAL APPEND PROPERTY LY_DELAYED_DEPENDENCIES_${TARGET} ${extra_function_args})
  39. endif()
  40. endfunction()