From 3f5848989c460f36445033306e0a24cedc3ce4bc Mon Sep 17 00:00:00 2001 From: fuzzard Date: Mon, 8 Jul 2024 20:30:58 +1000 Subject: [cmake] create function to add dependency to a target A target may not always use target_link_libraries to create dependency chains. export-files is an example, and we want to make sure it has a dependency on all libs to be acquired/built before trying to execute the export-files script --- CMakeLists.txt | 2 ++ cmake/scripts/common/Macros.cmake | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index f6ba1e9097..0ef3151592 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -509,6 +509,8 @@ add_custom_target(gen_skin_pack DEPENDS ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/${ add_custom_target(generate-packaging ALL DEPENDS TexturePacker::TexturePacker::Executable export-files gen_skin_pack gen_system_addons) +core_target_add_dependencies(export-files) + # Add to lib${APP_NAME_LC} solely for Win UWP. msix building doesnt seem to pick up the # generated buildtree if we do it later. Other platforms dont care when this happens. add_dependencies(lib${APP_NAME_LC} generate-packaging) diff --git a/cmake/scripts/common/Macros.cmake b/cmake/scripts/common/Macros.cmake index e3ae5ed9b1..987301cb22 100644 --- a/cmake/scripts/common/Macros.cmake +++ b/cmake/scripts/common/Macros.cmake @@ -797,3 +797,21 @@ function(core_target_link_libraries core_lib) endif() endforeach() endfunction() + +# Iterate over optional/required dep lists and create dependency +# to the target supplied as first argument +function(core_target_add_dependencies core_target) + foreach(_depspec ${required_deps}) + split_dependency_specification(${_depspec} dep version) + if(TARGET ${APP_NAME_LC}::${dep}) + add_dependencies(${core_target} ${APP_NAME_LC}::${dep}) + endif() + endforeach() + + foreach(_depspec ${optional_deps}) + split_dependency_specification(${_depspec} dep version) + if(TARGET ${APP_NAME_LC}::${dep}) + add_dependencies(${core_target} ${APP_NAME_LC}::${dep}) + endif() + endforeach() +endfunction() -- cgit v1.2.3