Skip to content

Commit 3f75761

Browse files
committed
fix: dll not copy after update issue (which cause failed to attach debugger)
1 parent 33e4aad commit 3f75761

1 file changed

Lines changed: 31 additions & 13 deletions

File tree

CMake/Target.cmake

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ endif()
1515

1616
function(exp_gather_target_runtime_dependencies_recurse)
1717
set(options "")
18-
set(singleValueArgs NAME OUT_RUNTIME_DEP)
18+
set(singleValueArgs NAME OUT_RUNTIME_DEP OUT_DEP_TARGET)
1919
set(multiValueArgs "")
2020
cmake_parse_arguments(arg "${options}" "${singleValueArgs}" "${multiValueArgs}" ${ARGN})
2121

@@ -54,18 +54,21 @@ function(exp_gather_target_runtime_dependencies_recurse)
5454
list(APPEND result_runtime_dep $<TARGET_FILE:${l}>)
5555
endif ()
5656

57+
list(APPEND result_dep_target ${l})
5758
exp_gather_target_runtime_dependencies_recurse(
5859
NAME ${l}
5960
OUT_RUNTIME_DEP temp_runtime_dep
61+
OUT_DEP_TARGET temp_dep_target
6062
)
61-
foreach(t ${temp_runtime_dep})
62-
list(APPEND result_runtime_dep ${t})
63-
endforeach()
63+
list(APPEND result_runtime_dep ${temp_runtime_dep})
64+
list(APPEND result_dep_target ${temp_dep_target})
6465
endforeach()
6566
endif()
6667

6768
list(REMOVE_DUPLICATES result_runtime_dep)
69+
list(REMOVE_DUPLICATES result_dep_target)
6870
set(${arg_OUT_RUNTIME_DEP} ${result_runtime_dep} PARENT_SCOPE)
71+
set(${arg_OUT_DEP_TARGET} ${result_dep_target} PARENT_SCOPE)
6972
endfunction()
7073

7174
function(exp_process_runtime_dependencies)
@@ -77,26 +80,41 @@ function(exp_process_runtime_dependencies)
7780
exp_gather_target_runtime_dependencies_recurse(
7881
NAME ${arg_NAME}
7982
OUT_RUNTIME_DEP runtime_deps
83+
OUT_DEP_TARGET dep_targets
8084
)
8185
foreach (d ${arg_DEP_TARGET})
8286
list(APPEND runtime_deps $<TARGET_FILE:${d}>)
8387
exp_gather_target_runtime_dependencies_recurse(
8488
NAME ${d}
8589
OUT_RUNTIME_DEP dep_target_runtime_deps
90+
OUT_DEP_TARGET dep_dep_targets
8691
)
8792
list(APPEND runtime_deps ${dep_target_runtime_deps})
93+
list(APPEND dep_targets ${dep_dep_targets})
8894
endforeach ()
95+
8996
foreach(r ${runtime_deps})
90-
add_custom_command(
91-
TARGET ${arg_NAME} POST_BUILD
92-
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${r} $<TARGET_FILE_DIR:${arg_NAME}>
93-
)
94-
if (NOT ${arg_NOT_INSTALL})
95-
install(
96-
FILES ${r} DESTINATION ${CMAKE_INSTALL_PREFIX}/${SUB_PROJECT_NAME}/Binaries
97-
)
98-
endif ()
97+
list(APPEND copy_commands COMMAND ${CMAKE_COMMAND} -E copy_if_different ${r} $<TARGET_FILE_DIR:${arg_NAME}>)
9998
endforeach()
99+
if (NOT "${copy_commands}" STREQUAL "")
100+
set(custom_target_name ${arg_NAME}.CopyRuntimeDeps)
101+
add_custom_target(
102+
${custom_target_name}
103+
${copy_commands}
104+
)
105+
106+
add_dependencies(${arg_NAME} ${custom_target_name})
107+
foreach (t ${dep_targets})
108+
add_dependencies(${custom_target_name} ${t})
109+
endforeach ()
110+
111+
set_target_properties(${custom_target_name} PROPERTIES FOLDER ${AUX_TARGETS_FOLDER})
112+
endif ()
113+
if (NOT ${arg_NOT_INSTALL} AND NOT "${runtime_deps}" STREQUAL "")
114+
install(
115+
FILES ${runtime_deps} DESTINATION ${CMAKE_INSTALL_PREFIX}/${SUB_PROJECT_NAME}/Binaries
116+
)
117+
endif ()
100118
endfunction()
101119

102120
function(exp_expand_resource_path_expression)

0 commit comments

Comments
 (0)