Skip to content
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

Add ability to specify library directories for target rpaths #295

Merged
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
502f7b3
Initial version of rpath setting with new lib dirs.
vyasr Oct 25, 2022
f4882a9
Add new function to default includes.
vyasr Oct 25, 2022
ddd52ce
Move file to match function name.
vyasr Oct 25, 2022
95a24f5
Remove init check.
vyasr Oct 25, 2022
f91c4df
Properly propagate value up to parent scope.
vyasr Oct 25, 2022
ea5d8c4
Various bug fixes.
vyasr Oct 25, 2022
157eb7a
make sure paths are relative to origin and fix separator.
vyasr Oct 25, 2022
2fa5569
Remove message.
vyasr Oct 25, 2022
71836fc
Add docs file.
vyasr Oct 25, 2022
1433cdc
Fix typos in error messages.
vyasr Oct 25, 2022
24f403e
Add a test.
vyasr Oct 25, 2022
a44285b
Fix test and add comments.
vyasr Oct 25, 2022
cd76481
Update api.rst.
vyasr Oct 25, 2022
ba8ee68
Update format file.
vyasr Oct 25, 2022
ee033b9
Apply formatting.
vyasr Oct 25, 2022
a10879c
Add new approach add_rpath_entries with tests.
vyasr Oct 26, 2022
ba6ecd1
Update docs and format files.
vyasr Oct 26, 2022
81c4de6
Remove set_lib_dirs.
vyasr Oct 26, 2022
ba59734
Fix style.
vyasr Oct 26, 2022
5495b0b
Update docs a bit.
vyasr Oct 26, 2022
fe7d474
Remove set_lib_dirs from api.rst.
vyasr Oct 26, 2022
420fbb1
Fix path to file in docs.
vyasr Oct 26, 2022
2f3d976
Append to global property rather than overwriting.
vyasr Oct 26, 2022
b1ad4a8
Fix bugs that arise when the target is not created in the same direct…
vyasr Oct 26, 2022
5e9cca8
Fix style.
vyasr Oct 26, 2022
fd3f66f
Use set_property(TARGET) to enable appending.
vyasr Oct 27, 2022
f455f09
Fix path handling.
vyasr Nov 1, 2022
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
5 changes: 5 additions & 0 deletions cmake-format-rapids-cmake.json
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@
"LINKED_LIBRARIES": "*",
"INSTALL_DIR": "1"
}
},
"rapids_cython_set_lib_dirs": {
"pargs": {
"nargs": "*"
}
}

}
Expand Down
1 change: 1 addition & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ The `rapids_cython` functions allow projects to easily build cython modules usin

/command/rapids_cython_init
/command/rapids_cython_create_modules
/command/rapids_cython_set_lib_dirs


Find
Expand Down
1 change: 1 addition & 0 deletions docs/command/rapids_cython_set_lib_dirs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. cmake-module:: ../../rapids-cmake/cython/set_lib_dirs.cmake
11 changes: 9 additions & 2 deletions rapids-cmake/cython/create_modules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,15 @@ function(rapids_cython_create_modules)
endif()
install(TARGETS ${cython_module} DESTINATION ${_RAPIDS_CYTHON_INSTALL_DIR})

# Default the INSTALL_RPATH for all modules to $ORIGIN.
set_target_properties(${cython_module} PROPERTIES INSTALL_RPATH "\$ORIGIN")
# Default the INSTALL_RPATH for all modules to $ORIGIN. We also append any lib dirs specified in
vyasr marked this conversation as resolved.
Show resolved Hide resolved
# the current project.
set(_rpath_dirs)
foreach(_lib_dir IN LISTS RAPIDS_CYTHON_${PROJECT_NAME}_LIB_DIRS)
cmake_path(RELATIVE_PATH _lib_dir)
list(APPEND _rpath_dirs "\$ORIGIN/${_lib_dir}")
endforeach()
list(JOIN _rpath_dirs ";" _rpath_dirs)
set_target_properties(${cython_module} PROPERTIES INSTALL_RPATH "\$ORIGIN;${_rpath_dirs}")

list(APPEND CREATED_TARGETS "${cython_module}")
endforeach()
Expand Down
53 changes: 53 additions & 0 deletions rapids-cmake/cython/set_lib_dirs.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# =============================================================================
# Copyright (c) 2022, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
# in compliance with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied. See the License for the specific language governing permissions and limitations under
# the License.
# =============================================================================

include_guard(GLOBAL)

#[=======================================================================[.rst:
rapids_cython_set_lib_dirs
--------------------------

.. versionadded:: v22.12.00

Set the directories where any dependent libraries will be placed.
vyasr marked this conversation as resolved.
Show resolved Hide resolved

.. code-block:: cmake

rapids_cython_set_lib_dirs(<dir1> <dir2> ...)

The relative path to the provided directories is appended to the rpath of any
vyasr marked this conversation as resolved.
Show resolved Hide resolved
library built using rapids_cython_create_modules within the current project.

.. note::
Requires :cmake:command:`rapids_cython_init` to be called before usage.

Result Variables
^^^^^^^^^^^^^^^^
:cmake:variable:`RAPIDS_CYTHON_<ProjectName>_LIB_DIRS` will be set to the list of
directories provided to this function, where ProjectName is the name given to the
most recent :cmake:command:`project <cmake:command:project>` call.

#]=======================================================================]
function(rapids_cython_set_lib_dirs)
# Note that this function may be called safely before rapids-cython is initialized.
list(APPEND CMAKE_MESSAGE_CONTEXT "rapids.cython.set_lib_dirs")

# Need to convert all paths to absolute so that the later relative path conversions work.
set(_abs_lib_dirs)
foreach(_lib_dir IN LISTS ARGV)
cmake_path(ABSOLUTE_PATH _lib_dir)
list(APPEND _abs_lib_dirs ${_lib_dir})
endforeach()
set(RAPIDS_CYTHON_${PROJECT_NAME}_LIB_DIRS "${_abs_lib_dirs}" PARENT_SCOPE)
endfunction()
1 change: 1 addition & 0 deletions rapids-cmake/rapids-cython.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ include_guard(GLOBAL)

include(${CMAKE_CURRENT_LIST_DIR}/cython/init.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/cython/create_modules.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/cython/set_lib_dirs.cmake)
2 changes: 2 additions & 0 deletions testing/cython/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ add_cmake_config_test(create_modules_errors.cmake SHOULD_FAIL "You must call rap
add_cmake_config_test(create_modules)
add_cmake_config_test(create_modules_with_library)
add_cmake_config_test(create_modules_with_prefix)

add_cmake_config_test(set_lib_dirs)
2 changes: 1 addition & 1 deletion testing/cython/create_modules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ rapids_cython_create_modules(
)

if(NOT TARGET test)
message(FATAL_ERROR "rapids_cython_init didn't create the target `test`")
message(FATAL_ERROR "rapids_cython_create_modules didn't create the target `test`")
endif()
2 changes: 1 addition & 1 deletion testing/cython/create_modules_with_prefix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ rapids_cython_create_modules(
)

if(NOT TARGET test_test)
message(FATAL_ERROR "rapids_cython_init didn't create the prefixed library target `test_test`")
message(FATAL_ERROR "rapids_cython_create_modules didn't create the prefixed library target `test_test`")
endif()
46 changes: 46 additions & 0 deletions testing/cython/set_lib_dirs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#=============================================================================
# Copyright (c) 2022, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================

cmake_minimum_required(VERSION 3.20)

include(${rapids-cmake-dir}/cython/create_modules.cmake)
include(${rapids-cmake-dir}/cython/init.cmake)
include(${rapids-cmake-dir}/cython/set_lib_dirs.cmake)

project(rapids_cython-set_lib_dirs LANGUAGES C CXX)

# Silence warning about running without scikit-build.
set(SKBUILD ON)

# Ensure that scikit-build's CMake files are discoverable. The glob is to
# capture the current git commit hash.
file(GLOB skbuild_resource_dir LIST_DIRECTORIES ON "${CPM_SOURCE_CACHE}/skbuild/*/skbuild/resources/cmake")
LIST(APPEND CMAKE_MODULE_PATH "${skbuild_resource_dir}")

# Make sure set_lib_dirs can run before rapids_cython_init.
rapids_cython_set_lib_dirs(../libraries)

rapids_cython_init()

# Test that the RPATH of the resulting target is properly set.
rapids_cython_create_modules(
SOURCE_FILES test.pyx
)

get_target_property(rpath test INSTALL_RPATH)
if (NOT rpath STREQUAL "$ORIGIN;$ORIGIN/../libraries")
message(FATAL_ERROR "rapids_cython_set_lib_dirs failed to set the RPATH correctly.")
endif()
Empty file.