Skip to content

Commit

Permalink
Set install location and rpath for wheels
Browse files Browse the repository at this point in the history
This gets things put in the proper place when built with "pip install"
instead of with cmake directly. This also sets up rpaths for the wheels.

Signed-off-by: Patrick Avery <patrick.avery@kitware.com>
  • Loading branch information
psavery committed Feb 19, 2021
1 parent 9da8f15 commit ca0b6c6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
24 changes: 20 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ include_directories(SYSTEM
${PYBIND11_INCLUDE_DIR}
)

find_package(HDF5 REQUIRED)
include_directories(${HDF5_INCLUDE_DIRS})
find_package(HDF5 REQUIRED COMPONENTS C)

option(BUILD_SHARED_LIBS "Build shared libraries" ON)

Expand All @@ -55,7 +54,7 @@ set(_src
h5cpp/h5readwrite.cpp)

set(_libs Threads::Threads)
list(APPEND _libs "${HDF5_LIBRARIES}")
list(APPEND _libs hdf5::hdf5)

option(stempy_ENABLE_VTKm "Build with VTK-m" OFF)
cmake_dependent_option(stempy_ENABLE_CUDA "Enable VTK-m CUDA backend" OFF "stempy_ENABLE_VTKm" ON)
Expand Down Expand Up @@ -91,7 +90,24 @@ set_target_properties(stem
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/stempy"
)

install(TARGETS stem LIBRARY DESTINATION "${INSTALL_LIBRARY_DIR}/stempy/")
# Set the RPATH so the dependent libraries can be found in the wheel.
if(APPLE)
set(_rpath_value "@loader_path")
elseif(UNIX)
set(_rpath_value "$ORIGIN")
endif()

if (NOT WIN32)
set_target_properties(stem PROPERTIES
INSTALL_RPATH ${_rpath_value})
endif()

set(_python_module_install_dir "stempy")
# SKBUILD is set for binary wheel
if (NOT SKBUILD)
set(_python_module_install_dir "${INSTALL_LIBRARY_DIR}/stempy")
endif()
install(TARGETS stem LIBRARY DESTINATION "${_python_module_install_dir}")

set(VTKm ${VTKm_FOUND})
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.h.in"
Expand Down
23 changes: 10 additions & 13 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,22 @@ target_link_libraries(_image
stem
)

install(TARGETS _io LIBRARY COMPONENT python DESTINATION "${_python_module_install_dir}")
install(TARGETS _image LIBRARY COMPONENT python DESTINATION "${_python_module_install_dir}")

install(TARGETS _io LIBRARY COMPONENT python DESTINATION "${INSTALL_LIBRARY_DIR}/stempy/")
install(TARGETS _image LIBRARY COMPONENT python DESTINATION "${INSTALL_LIBRARY_DIR}/stempy/")

set_target_properties(_io
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/stempy"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/stempy"
BUILD_RPATH "$ORIGIN"
)
set_target_properties(_image
set_target_properties(_io _image
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/stempy"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/stempy"
BUILD_RPATH "$ORIGIN"
)

install(FILES stempy/io/__init__.py COMPONENT python DESTINATION "${INSTALL_LIBRARY_DIR}/stempy/io/")
install(FILES stempy/image/__init__.py COMPONENT python DESTINATION "${INSTALL_LIBRARY_DIR}/stempy/image/")
if (NOT WIN32)
set_target_properties(_io _image PROPERTIES
INSTALL_RPATH ${_rpath_value})
endif()

install(FILES stempy/io/__init__.py COMPONENT python DESTINATION "${_python_module_install_dir}/io")
install(FILES stempy/image/__init__.py COMPONENT python DESTINATION "${_python_module_install_dir}/image")

file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/lib/stempy/")
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${CMAKE_CURRENT_SOURCE_DIR}/stempy/io" "${CMAKE_BINARY_DIR}/lib/stempy/io")
Expand Down

0 comments on commit ca0b6c6

Please sign in to comment.