Skip to content

Commit 1e3536a

Browse files
committed
Skip redundant DLL copy on Windows
Since the library is now named 'scylladb', Cargo's output (scylladb.dll, scylladb.lib) already matches the desired install name. Use the Cargo output directly on Windows instead of copying to an identical filename. This also eliminates the class of problems where the import library (.lib) internally references the original Cargo output name, causing 'dll not found' errors if the file were renamed (as was the case with the old scylla_cpp_driver -> scylla-cpp-driver rename).
1 parent 0251577 commit 1e3536a

1 file changed

Lines changed: 20 additions & 11 deletions

File tree

scylla-rust-wrapper/CMakeLists.txt

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,26 @@ else()
6464
endif()
6565
if(CASS_BUILD_SHARED)
6666
cargo_build(NAME scylladb CRATE_TYPE cdylib)
67-
create_copy($<TARGET_FILE:scylladb_cdylib> ${INSTALL_NAME_SHARED})
68-
add_library(scylladb SHARED IMPORTED GLOBAL)
69-
add_dependencies(scylladb ${INSTALL_NAME_SHARED}_copy)
70-
set_target_properties(scylladb PROPERTIES IMPORTED_LOCATION ${CMAKE_BINARY_DIR}/${INSTALL_NAME_SHARED})
7167
if(WIN32)
68+
# On Windows, Cargo's output name (scylladb.dll/.lib) already matches
69+
# the desired install name, so no copy/rename is needed. We use the
70+
# Cargo output paths directly. This avoids the problem where the import
71+
# library internally references the original Cargo output name, causing
72+
# "dll not found" errors if the file is renamed (#452).
73+
add_library(scylladb SHARED IMPORTED GLOBAL)
74+
add_dependencies(scylladb scylladb_cdylib_target)
75+
set_target_properties(scylladb PROPERTIES IMPORTED_LOCATION $<TARGET_FILE:scylladb_cdylib>)
7276
get_target_property(SCYLLADB_IMPLIB scylladb_cdylib IMPORTED_IMPLIB)
7377
if(SCYLLADB_IMPLIB)
74-
create_copy(${SCYLLADB_IMPLIB} ${INSTALL_NAME_SHARED_IMPLIB})
75-
set_target_properties(scylladb PROPERTIES IMPORTED_IMPLIB ${CMAKE_BINARY_DIR}/${INSTALL_NAME_SHARED_IMPLIB})
78+
set_target_properties(scylladb PROPERTIES IMPORTED_IMPLIB ${SCYLLADB_IMPLIB})
7679
endif()
77-
endif()
78-
if(NOT WIN32)
80+
else()
81+
# On Unix, we need to copy to add the version suffix
82+
# (e.g. libscylladb.so -> libscylladb.so.X.Y.Z).
83+
create_copy($<TARGET_FILE:scylladb_cdylib> ${INSTALL_NAME_SHARED})
84+
add_library(scylladb SHARED IMPORTED GLOBAL)
85+
add_dependencies(scylladb ${INSTALL_NAME_SHARED}_copy)
86+
set_target_properties(scylladb PROPERTIES IMPORTED_LOCATION ${CMAKE_BINARY_DIR}/${INSTALL_NAME_SHARED})
7987
create_symlink(${INSTALL_NAME_SHARED} ${INSTALL_NAME_SHARED_SYMLINK_VERSION})
8088
create_symlink(${INSTALL_NAME_SHARED} ${INSTALL_NAME_SHARED_SYMLINK_NO_VERSION})
8189
if(CASS_INSTALL_CASSANDRA_COMPAT)
@@ -158,12 +166,13 @@ endif()
158166
if(CASS_BUILD_SHARED)
159167
# Versioned shared library goes to runtime package
160168
if(WIN32)
161-
install(FILES ${CMAKE_BINARY_DIR}/${INSTALL_NAME_SHARED}
169+
install(FILES $<TARGET_FILE:scylladb>
162170
DESTINATION ${INSTALL_DLL_EXE_DIR}
163171
COMPONENT ${SCYLLA_DRIVER_RUNTIME_COMPONENT_NAME}
164172
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ)
165-
if(INSTALL_NAME_SHARED_IMPLIB)
166-
install(FILES ${CMAKE_BINARY_DIR}/${INSTALL_NAME_SHARED_IMPLIB}
173+
get_target_property(_scylladb_implib scylladb IMPORTED_IMPLIB)
174+
if(_scylladb_implib)
175+
install(FILES ${_scylladb_implib}
167176
DESTINATION ${CMAKE_INSTALL_LIBDIR}
168177
COMPONENT ${SCYLLA_DRIVER_DEV_COMPONENT_NAME})
169178
endif()

0 commit comments

Comments
 (0)