Skip to content

Commit e955b54

Browse files
committed
Make rb_loader weakly linked to libruby.
1 parent 88f2e1c commit e955b54

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

source/loaders/rb_loader/CMakeLists.txt

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@ if(NOT Ruby_FOUND)
1414
return()
1515
endif()
1616

17+
# TODO: Search Ruby_LIBRARY_NAME_PATH like in Python?
18+
set(Ruby_LIBRARY_NAME_PATH "${Ruby_LIBRARY_NAME}")
19+
get_filename_component(Ruby_LIBRARY_NAME "${Ruby_LIBRARY_NAME_PATH}" NAME)
20+
1721
# Copy Ruby DLL into project output directory
1822
# TODO: https://cmake.org/cmake/help/latest/command/file.html#get-runtime-dependencies
1923
# TODO: https://gist.github.com/micahsnyder/5d98ac8548b429309ec5a35bca9366da
20-
if(WIN32 AND Ruby_LIBRARY_NAME)
24+
if(Ruby_LIBRARY_NAME_PATH AND WIN32)
2125
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_OUTPUT_DIR})
22-
file(COPY "${Ruby_LIBRARY_NAME}" DESTINATION ${PROJECT_OUTPUT_DIR})
26+
file(COPY "${Ruby_LIBRARY_NAME_PATH}" DESTINATION ${PROJECT_OUTPUT_DIR})
2327
endif()
2428

2529
#
@@ -142,7 +146,9 @@ target_link_libraries(${target}
142146
PRIVATE
143147
${META_PROJECT_NAME}::metacall # MetaCall library
144148

145-
${Ruby_LIBRARY} # Ruby library
149+
# Delay load for MSVC
150+
$<$<CXX_COMPILER_ID:MSVC>:${Ruby_LIBRARY}> # Ruby library
151+
$<$<CXX_COMPILER_ID:MSVC>:delayimp>
146152

147153
PUBLIC
148154
${DEFAULT_LIBRARIES}
@@ -191,6 +197,8 @@ endif()
191197

192198
target_link_options(${target}
193199
PRIVATE
200+
$<$<AND:$<BOOL:${APPLE}>,$<CXX_COMPILER_ID:AppleClang,Clang>>:-Wl,-undefined,dynamic_lookup>
201+
$<$<CXX_COMPILER_ID:MSVC>:/DELAYLOAD:${Ruby_LIBRARY_NAME_PATH}>
194202

195203
PUBLIC
196204
${DEFAULT_LINKER_OPTIONS}
@@ -213,10 +221,29 @@ install(TARGETS ${target}
213221
# Runtime (pack Ruby DLL in windows)
214222
# TODO: https://cmake.org/cmake/help/latest/command/file.html#get-runtime-dependencies
215223
# TODO: https://gist.github.com/micahsnyder/5d98ac8548b429309ec5a35bca9366da
216-
if(WIN32 AND Ruby_LIBRARY_NAME)
224+
set(Ruby_LIBRARY_DEVELOPMENT "${Ruby_LIBRARY_NAME_PATH}")
225+
226+
if(Ruby_LIBRARY_NAME_PATH AND WIN32)
217227
install(FILES
218-
"${Ruby_LIBRARY_NAME}"
228+
"${Ruby_LIBRARY_NAME_PATH}"
219229
DESTINATION ${INSTALL_LIB}
220230
COMPONENT runtime
221231
)
232+
set(Ruby_LIBRARY_INSTALL "${CMAKE_INSTALL_PREFIX}/${INSTALL_LIB}/${Ruby_LIBRARY_NAME}")
233+
else()
234+
set(Ruby_LIBRARY_INSTALL "${Ruby_LIBRARY_NAME_PATH}")
222235
endif()
236+
237+
#
238+
# Configuration
239+
#
240+
241+
# Development
242+
loader_configuration_begin(rb_loader)
243+
loader_configuration_deps(ruby "${Ruby_LIBRARY_DEVELOPMENT}")
244+
loader_configuartion_end_development()
245+
246+
# Install
247+
loader_configuration_begin(rb_loader)
248+
loader_configuration_deps(ruby "${Ruby_LIBRARY_INSTALL}")
249+
loader_configuartion_end_install()

0 commit comments

Comments
 (0)