diff --git a/CMake/Target.cmake b/CMake/Target.cmake index 86123845..a53eaf97 100644 --- a/CMake/Target.cmake +++ b/CMake/Target.cmake @@ -15,7 +15,7 @@ endif() function(exp_gather_target_runtime_dependencies_recurse) set(options "") - set(singleValueArgs NAME OUT_RUNTIME_DEP) + set(singleValueArgs NAME OUT_RUNTIME_DEP OUT_DEP_TARGET) set(multiValueArgs "") cmake_parse_arguments(arg "${options}" "${singleValueArgs}" "${multiValueArgs}" ${ARGN}) @@ -54,18 +54,21 @@ function(exp_gather_target_runtime_dependencies_recurse) list(APPEND result_runtime_dep $) endif () + list(APPEND result_dep_target ${l}) exp_gather_target_runtime_dependencies_recurse( NAME ${l} OUT_RUNTIME_DEP temp_runtime_dep + OUT_DEP_TARGET temp_dep_target ) - foreach(t ${temp_runtime_dep}) - list(APPEND result_runtime_dep ${t}) - endforeach() + list(APPEND result_runtime_dep ${temp_runtime_dep}) + list(APPEND result_dep_target ${temp_dep_target}) endforeach() endif() list(REMOVE_DUPLICATES result_runtime_dep) + list(REMOVE_DUPLICATES result_dep_target) set(${arg_OUT_RUNTIME_DEP} ${result_runtime_dep} PARENT_SCOPE) + set(${arg_OUT_DEP_TARGET} ${result_dep_target} PARENT_SCOPE) endfunction() function(exp_process_runtime_dependencies) @@ -77,26 +80,41 @@ function(exp_process_runtime_dependencies) exp_gather_target_runtime_dependencies_recurse( NAME ${arg_NAME} OUT_RUNTIME_DEP runtime_deps + OUT_DEP_TARGET dep_targets ) foreach (d ${arg_DEP_TARGET}) list(APPEND runtime_deps $) exp_gather_target_runtime_dependencies_recurse( NAME ${d} OUT_RUNTIME_DEP dep_target_runtime_deps + OUT_DEP_TARGET dep_dep_targets ) list(APPEND runtime_deps ${dep_target_runtime_deps}) + list(APPEND dep_targets ${dep_dep_targets}) endforeach () + foreach(r ${runtime_deps}) - add_custom_command( - TARGET ${arg_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different ${r} $ - ) - if (NOT ${arg_NOT_INSTALL}) - install( - FILES ${r} DESTINATION ${CMAKE_INSTALL_PREFIX}/${SUB_PROJECT_NAME}/Binaries - ) - endif () + list(APPEND copy_commands COMMAND ${CMAKE_COMMAND} -E copy_if_different ${r} $) endforeach() + if (NOT "${copy_commands}" STREQUAL "") + set(custom_target_name ${arg_NAME}.CopyRuntimeDeps) + add_custom_target( + ${custom_target_name} + ${copy_commands} + ) + + add_dependencies(${arg_NAME} ${custom_target_name}) + foreach (t ${dep_targets}) + add_dependencies(${custom_target_name} ${t}) + endforeach () + + set_target_properties(${custom_target_name} PROPERTIES FOLDER ${AUX_TARGETS_FOLDER}) + endif () + if (NOT ${arg_NOT_INSTALL} AND NOT "${runtime_deps}" STREQUAL "") + install( + FILES ${runtime_deps} DESTINATION ${CMAKE_INSTALL_PREFIX}/${SUB_PROJECT_NAME}/Binaries + ) + endif () endfunction() function(exp_expand_resource_path_expression) @@ -487,7 +505,7 @@ function(exp_add_library) string(REPLACE ">" "]" runtime_dep_files "${runtime_dep_files}") set_target_properties( ${arg_NAME} PROPERTIES - EXPORT_PROPERTIES "runtime_dep" + EXPORT_PROPERTIES "RUNTIME_DEP" RUNTIME_DEP "${runtime_dep_files}" ) endif () diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ba03855..8ac7d687 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,3 +27,9 @@ add_subdirectory(Sample) if (${BUILD_EDITOR}) add_subdirectory(Editor) endif() + +file(GLOB engine_cmake_libs CMake/*.cmake) +install( + FILES ${engine_cmake_libs} + DESTINATION ${SUB_PROJECT_NAME}/CMake +) diff --git a/Editor/Resource/ProjectTemplates/Default/CMakeLists.txt b/Editor/Resource/ProjectTemplates/Default/CMakeLists.txt index 91ab9c5e..e048152f 100644 --- a/Editor/Resource/ProjectTemplates/Default/CMakeLists.txt +++ b/Editor/Resource/ProjectTemplates/Default/CMakeLists.txt @@ -1,5 +1,4 @@ -cmake_minimum_required(VERSION 3.25) +cmake_minimum_required(VERSION %{cmakeMinVersion}) project(%{projectName}%) -include(ExternalProject) -include(GenerateExportHeader) +%{commonCMakeScripts} diff --git a/Tool/MirrorTool/CMakeLists.txt b/Tool/MirrorTool/CMakeLists.txt index 75b78cfe..97e2009a 100644 --- a/Tool/MirrorTool/CMakeLists.txt +++ b/Tool/MirrorTool/CMakeLists.txt @@ -5,7 +5,6 @@ exp_add_library( PUBLIC_INC Include PUBLIC_LIB Mirror PUBLIC_MERGE_LIB libclang::libclang clipp::clipp - NOT_INSTALL ) file(GLOB exe_sources ExeSrc/*.cpp)