Skip to content

Commit 12f78af

Browse files
authored
fix: exclude common dlls and alpine dependencies installation (#129)
Signed-off-by: msclock <msclock@qq.com>
1 parent 63c2659 commit 12f78af

File tree

1 file changed

+43
-14
lines changed

1 file changed

+43
-14
lines changed

cmake/install/InstallDependency.cmake

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,26 @@ function(install_dependency)
106106
endif()
107107

108108
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
109-
# exclude windows API earlier
109+
# exclude common dll
110110
if(NOT arg_PRE_EXCLUDE_REGEXES)
111-
list(APPEND arg_PRE_EXCLUDE_REGEXES "api-ms-.*" "ext-ms-.*"
112-
"KERNEL32.dll")
111+
list(
112+
APPEND
113+
arg_PRE_EXCLUDE_REGEXES
114+
"api-ms-.*"
115+
"ext-ms-.*"
116+
"KERNEL32.*"
117+
"python.*"
118+
"msvcp.*"
119+
"vcruntime.*"
120+
"concrt.*")
113121
endif()
114122

115123
# exclude system dlls directories later
116124
if(NOT arg_POST_EXCLUDE_REGEXES)
117125
list(APPEND arg_POST_EXCLUDE_REGEXES "WINDOWS" "system32")
118126
endif()
119127
else()
120-
# exclude windows API earlier
128+
# exclude system libs earlier
121129
if(NOT arg_PRE_EXCLUDE_REGEXES)
122130
list(
123131
APPEND
@@ -154,6 +162,20 @@ function(install_dependency)
154162
endif()
155163
endif()
156164

165+
if(CMAKE_HOST_SYSTEM_NAME MATCHES [[Linux]] AND EXISTS "/etc/alpine-release")
166+
find_program(_ldconfig ldconfig)
167+
execute_process(COMMAND ldconfig -v -N -X RESULT_VARIABLE ldconfig_result)
168+
169+
if(NOT ldconfig_result EQUAL "0")
170+
message(STATUS "Patch ldconfig in alpine for GET_RUNTIME_DEPENDENCIES")
171+
file(READ "${_ldconfig}" _ldconfig_content)
172+
string(REPLACE [[[ $# -gt 0 ] && scan_dirs]]
173+
[[[ $# -eq 0 ] && exit 0 || [ $# -gt 0 ] && scan_dirs]]
174+
_ldconfig_content "${_ldconfig_content}")
175+
file(WRITE "${_ldconfig}" "${_ldconfig_content}")
176+
endif()
177+
endif()
178+
157179
install(CODE "set(arg_DIRECTORIES \"${arg_DIRECTORIES}\")")
158180
install(CODE "set(arg_PRE_EXCLUDE_REGEXES \"${arg_PRE_EXCLUDE_REGEXES}\")")
159181
install(CODE "set(arg_POST_EXCLUDE_REGEXES \"${arg_POST_EXCLUDE_REGEXES}\")")
@@ -209,10 +231,14 @@ function(install_dependency)
209231
if(_r_deps)
210232
message(STATUS "Resolved dependencies: ${_r_deps}")
211233
foreach(_file ${_r_deps})
212-
file(
213-
INSTALL
214-
DESTINATION "${arg_DEPENDS_DESTINATION}"
215-
TYPE SHARED_LIBRARY FOLLOW_SYMLINK_CHAIN FILES "${_file}")
234+
if(EXISTS "${_file}")
235+
file(
236+
INSTALL
237+
DESTINATION "${arg_DEPENDS_DESTINATION}"
238+
TYPE SHARED_LIBRARY FOLLOW_SYMLINK_CHAIN FILES "${_file}")
239+
else()
240+
message(WARNING "Found a non-existent dependency: ${_file}")
241+
endif()
216242
endforeach()
217243
endif()
218244

@@ -230,15 +256,18 @@ function(install_dependency)
230256
set(_c_file_list ${_c_deps_${_filename}})
231257
message(STATUS "conflict ${_filename} list ${_c_file_list}")
232258
foreach(_file ${_c_file_list})
233-
file(
234-
INSTALL
235-
DESTINATION "${arg_DEPENDS_DESTINATION}"
236-
TYPE SHARED_LIBRARY FOLLOW_SYMLINK_CHAIN FILES "${_file}")
259+
if(EXISTS "${_file}")
260+
file(
261+
INSTALL
262+
DESTINATION "${arg_DEPENDS_DESTINATION}"
263+
TYPE SHARED_LIBRARY FOLLOW_SYMLINK_CHAIN FILES "${_file}")
264+
else()
265+
message(WARNING "Found a non-existent conflict dependency: ${_file}")
266+
endif()
237267
endforeach()
238268
endforeach()
239269
endif()
240-
241-
]])
270+
]])
242271
endif()
243272
endforeach()
244273

0 commit comments

Comments
 (0)