Skip to content

Add install capabilities to top-level CMake config #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ ExternalProject_Add(
scylla-rust-cpp-driver
DOWNLOAD_COMMAND ""
CONFIGURE_COMMAND ""
BUILD_COMMAND cargo build $<IF:$<CONFIG:Debug>,,--release>
BUILD_COMMAND ./build-cmake-compat.sh $<IF:$<CONFIG:Debug>,DEBUG,RELEASE> $<IF:$<BOOL:${CASS_BUILD_STATIC}>,STATIC,NO_STATIC>
BINARY_DIR "${CMAKE_SOURCE_DIR}/scylla-rust-wrapper"
INSTALL_COMMAND ""
LOG_BUILD ON
Expand All @@ -250,11 +250,11 @@ add_library(scylla-cpp-driver SHARED IMPORTED)
set_target_properties(scylla-cpp-driver PROPERTIES IMPORTED_NO_SONAME TRUE)
set_property(TARGET scylla-cpp-driver APPEND PROPERTY IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(scylla-cpp-driver PROPERTIES
IMPORTED_LOCATION_DEBUG "${CMAKE_SOURCE_DIR}/scylla-rust-wrapper/target/debug/libscylla_cpp_driver.so"
IMPORTED_LOCATION_DEBUG "${CMAKE_SOURCE_DIR}/scylla-rust-wrapper/target/debug/cmake-compat/libscylla-cpp-driver.so"
)
set_property(TARGET scylla-cpp-driver APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(scylla-cpp-driver PROPERTIES
IMPORTED_LOCATION_RELEASE "${CMAKE_SOURCE_DIR}/scylla-rust-wrapper/target/release/libscylla_cpp_driver.so"
IMPORTED_LOCATION_RELEASE "${CMAKE_SOURCE_DIR}/scylla-rust-wrapper/target/release/cmake-compat/libscylla-cpp-driver.so"
)
set_target_properties(scylla-cpp-driver PROPERTIES
MAP_IMPORTED_CONFIG_MINSIZEREL Release
Expand All @@ -271,4 +271,34 @@ endif()

if(CASS_BUILD_INTEGRATION_TESTS OR CASS_BUILD_TESTS)
add_subdirectory(tests)
endif()
endif()

#-------------------------------------
# Installation
#-------------------------------------

# Determine if the library directory needs to be determined
if(NOT DEFINED CMAKE_INSTALL_LIBDIR)
if ("${CMAKE_SYSTEM_NAME}" MATCHES "Linux" AND ("${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr" OR
"${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr/local"))
if(EXISTS "/etc/debian_version")
set (CMAKE_INSTALL_LIBDIR "lib/${CMAKE_LIBRARY_ARCHITECTURE}")
elseif(EXISTS "/etc/redhat-release" OR EXISTS "/etc/fedora-release" OR
EXISTS "/etc/slackware-version" OR EXISTS "/etc/gentoo-release")
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set (CMAKE_INSTALL_LIBDIR "lib64")
else()
set (CMAKE_INSTALL_LIBDIR "lib")
endif()
else()
set (CMAKE_INSTALL_LIBDIR "lib")
endif()
else()
set (CMAKE_INSTALL_LIBDIR "lib")
endif()
endif()

file(GLOB CASS_API_HEADER_FILES ${CASS_INCLUDE_DIR}/*.h)
install(FILES ${CASS_API_HEADER_FILES} DESTINATION "include")

install(DIRECTORY ${CMAKE_SOURCE_DIR}/scylla-rust-wrapper/target/$<IF:$<CONFIG:Debug>,debug,release>/cmake-compat/ DESTINATION ${CMAKE_INSTALL_LIBDIR})
60 changes: 60 additions & 0 deletions scylla-rust-wrapper/build-cmake-compat.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash
set -e

# The version number should be in the third line
# of Cargo.toml file (e.g. version = "0.0.1")
VERSION_NUMBER=$(sed -n '3p' < Cargo.toml)
Comment on lines +4 to +6
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this an assumption that is prone to change?

REGEX="version = \"([0-9]+)\.([0-9]+)\.([0-9]+)\""
if [[ $VERSION_NUMBER =~ $REGEX ]]
then
MAJOR=${BASH_REMATCH[1]}
MINOR=${BASH_REMATCH[2]}
PATCH=${BASH_REMATCH[3]}
else
echo "Could not parse the version number in Cargo.toml"
echo "Tried to parse a third line of Cargo.toml: $VERSION_NUMBER"
echo 'but it did not contain a valid version number (e.g. version = "0.0.1").'
exit 1
fi

COPY_STATIC=false

if [[ $2 == "STATIC" ]]
then
COPY_STATIC=true
elif [[ $2 == "NO_STATIC" ]]
then
COPY_STATIC=false
else
echo 'Invalid static build configuration: $2 (only STATIC or NO_STATIC permitted)'
exit 1
fi


create_symlinks() {
rm -rf target/$1/cmake-compat/
mkdir target/$1/cmake-compat/

cp target/$1/libscylla_cpp_driver.so target/$1/cmake-compat/libscylla-cpp-driver.so.$MAJOR.$MINOR.$PATCH

if [[ "$COPY_STATIC" == true ]]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is comparison to true necessary in Bash??

then
cp target/$1/libscylla_cpp_driver.a target/$1/cmake-compat/libscylla-cpp-driver_static.a
fi

ln -s libscylla-cpp-driver.so.$MAJOR.$MINOR.$PATCH target/$1/cmake-compat/libscylla-cpp-driver.so.$MAJOR
ln -s libscylla-cpp-driver.so.$MAJOR target/$1/cmake-compat/libscylla-cpp-driver.so
}

if [[ $1 == "DEBUG" ]]
then
cargo build
create_symlinks "debug"
elif [[ $1 == "RELEASE" ]]
then
cargo build --release
create_symlinks "release"
else
echo 'Invalid build mode: $1 (only DEBUG or RELEASE permitted)'
exit 1
fi