Last active
February 18, 2025 17:49
-
-
Save RafaelPalomar/8b082d9dc64d99cd7e9b60aa373578c1 to your computer and use it in GitHub Desktop.
Building 3D Slicer (superbuild) on GNU Guix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/CMakeLists.txt b/CMakeLists.txt | |
| index 49ebc51..824145a 100644 | |
| --- a/CMakeLists.txt | |
| +++ b/CMakeLists.txt | |
| @@ -91,6 +91,11 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) | |
| set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON) | |
| set(CMAKE_POSITION_INDEPENDENT_CODE ON) | |
| +# Ensure that RPATH is used when installing, but only for the libraries outside the build tree | |
| +set(CMAKE_SKIP_BUILD_RPATH FALSE) | |
| +set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) | |
| +set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) | |
| + | |
| #----------------------------------------------------------------------------- | |
| # Update CMake module path | |
| # | |
| @@ -274,6 +279,8 @@ else() | |
| include(${QT_USE_FILE}) | |
| endif() | |
| +list(APPEND CMAKE_INSTALL_RPATH "${Qt5Core_DIR}/../../../lib") | |
| + | |
| #----------------------------------------------------------------------------- | |
| # Build ctkAppLauncherBase and associated tests | |
| # |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env sh | |
| export CCACHE_DIR=/ccache-cache | |
| cd /tmp && \ | |
| git clone https://github.com/commontk/AppLauncher && \ | |
| cd AppLauncher && \ | |
| curl -L \ | |
| https://gist.githubusercontent.com/RafaelPalomar/8b082d9dc64d99cd7e9b60aa373578c1/raw/c8e23c0d89278fad4bc7f4a326f750ce7c092637/applauncher-add-qt5-library-rpath.patch \ | |
| -o applauncher-add-qt5-library-rpath.patch && \ | |
| patch -p1 < applauncher-add-qt5-library-rpath.patch && \ | |
| cmake -S . -B /tmp/CTKAppLauncher-build \ | |
| -DCMAKE_C_COMPILER_LAUNCHER=ccache \ | |
| -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ | |
| -DCTKAppLauncher_QT_VERSION:STRING=5 \ | |
| -DBUILD_TESTING:BOOL=OFF \ | |
| -DCMAKE_INSTALL_PREFIX:PATH=/tmp/CTKAppLauncher-install && \ | |
| cmake --build /tmp/CTKAppLauncher-build --target install -- -j$(nproc) && \ | |
| cd /tmp && \ | |
| git clone https://github.com/python-cmake-buildsystem/python-cmake-buildsystem.git && \ | |
| cd python-cmake-buildsystem && \ | |
| curl -L \ | |
| https://gist.githubusercontent.com/RafaelPalomar/8b082d9dc64d99cd7e9b60aa373578c1/raw/14a14df97122a027ccb64e9017eddb92c0a151a0/python-add-rpaths.patch \ | |
| -o python-add-rpaths.patch && \ | |
| patch -p1 < python-add-rpaths.patch && \ | |
| cmake -S . -B Release \ | |
| -DCMAKE_C_COMPILER_LAUNCHER=ccache \ | |
| -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ | |
| -DCMAKE_BUILD_TYPE:STRING=Release \ | |
| -DBUILD_LIBPYTHON_SHARED:BOOL=ON \ | |
| -DCMAKE_INSTALL_PREFIX:PATH=/tmp/SlicerPython-install && \ | |
| cmake --build Release -j$(nproc) --target install && \ | |
| cd /tmp && \ | |
| git clone --branch v5.8.0 --single-branch https://github.com/Slicer/Slicer.git && \ | |
| cd Slicer && \ | |
| curl -L \ | |
| https://gist.githubusercontent.com/RafaelPalomar/8b082d9dc64d99cd7e9b60aa373578c1/raw/d4ed6a31639ffd573bc145e91b720fb9543b8cfb/slicer-set-system-python-dir.patch \ | |
| -o slicer-set-system-python-dir.patch && \ | |
| patch -p1 < slicer-set-system-python-dir.patch && \ | |
| cmake -S . -B Release \ | |
| -DCMAKE_C_COMPILER_LAUNCHER=ccache \ | |
| -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ | |
| -DCTKAppLauncher_DIR=/tmp/CTKAppLauncher-install \ | |
| -DCMAKE_BUILD_TYPE:STRING=Release \ | |
| -DSlicer_USE_SYSTEM_OpenSSL:BOOL=ON \ | |
| -DPYTHON_EXECUTABLE=/tmp/SlicerPython-install/bin/python3 \ | |
| -DPYTHON_INCLUDE_DIR=/tmp/SlicerPython-install/include/python3.9 \ | |
| -DPYTHON_LIBRARY=/tmp/SlicerPython-install/lib/libpython3.9.so && \ | |
| cmake --build Release -- -j$(nproc) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env sh | |
| guix shell {qtbase,qttools,qtx11extras,qtxmlpatterns,qtmultimedia,qtsvg,qtwebengine,qtlocation}@5.15.15 libsm libice libxrender libxext libx11 zlib cmake git nss-certs binutils coreutils gcc-toolchain@11 make patch openssl bash perl sed grep gnulib gawk curl groff binutils findutils strace vim zlib ccache --container --network --share=$HOME/ccache-cache=/ccache-cache |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/cmake/Extensions.cmake b/cmake/Extensions.cmake | |
| index d9adc80..ff89aa7 100644 | |
| --- a/cmake/Extensions.cmake | |
| +++ b/cmake/Extensions.cmake | |
| @@ -169,9 +169,23 @@ function(add_python_extension name) | |
| add_library(${target_name} SHARED ${absolute_sources}) | |
| target_include_directories(${target_name} PUBLIC "${ADD_PYTHON_EXTENSION_INCLUDEDIRS}") | |
| - if(PY_VERSION VERSION_GREATER_EQUAL "3.8") | |
| - list(APPEND ADD_PYTHON_EXTENSION_DEFINITIONS Py_BUILD_CORE_MODULE) | |
| - endif() | |
| + # Add the rpath directories | |
| + set(rpath_dirs "") | |
| + foreach(lib ${ADD_PYTHON_EXTENSION_LIBRARIES}) | |
| + get_filename_component(lib_path ${lib} DIRECTORY) | |
| + list(APPEND rpath_dirs ${lib_path}) | |
| + endforeach() | |
| + list(REMOVE_DUPLICATES rpath_dirs) | |
| + | |
| + # Set the rpath properties | |
| + set_target_properties(${target_name} PROPERTIES | |
| + BUILD_RPATH "${rpath_dirs}" | |
| + INSTALL_RPATH "${rpath_dirs}" | |
| + ) | |
| + | |
| + if(PY_VERSION VERSION_GREATER_EQUAL "3.8") | |
| + list(APPEND ADD_PYTHON_EXTENSION_DEFINITIONS Py_BUILD_CORE_MODULE) | |
| + endif() | |
| if(WIN32) | |
| string(REGEX MATCH "Py_LIMITED_API" require_limited_api "${ADD_PYTHON_EXTENSION_DEFINITIONS}") | |
| diff --git a/cmake/python/CMakeLists.txt b/cmake/python/CMakeLists.txt | |
| index 7850be5..9a3452d 100644 | |
| --- a/cmake/python/CMakeLists.txt | |
| +++ b/cmake/python/CMakeLists.txt | |
| @@ -10,6 +10,7 @@ set_property( | |
| TARGET python | |
| PROPERTY RUNTIME_OUTPUT_DIRECTORY ${BIN_BUILD_DIR} | |
| ) | |
| + | |
| target_compile_definitions(python PRIVATE Py_BUILD_CORE) | |
| add_definitions(-DPy_BUILD_CORE) | |
| @@ -17,6 +18,12 @@ add_definitions(-DPy_BUILD_CORE) | |
| # version. | |
| if(BUILD_LIBPYTHON_SHARED) | |
| target_link_libraries(python libpython-shared) | |
| + | |
| + # Set the rpath properties | |
| + set_target_properties(python PROPERTIES | |
| + BUILD_RPATH "${Python_BINARY_DIR}" | |
| + INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib" | |
| + ) | |
| else() | |
| target_link_libraries(python libpython-static) | |
| set_target_properties(python PROPERTIES |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/SuperBuild/External_python.cmake b/SuperBuild/External_python.cmake | |
| index ea077841e0..a43745cfaa 100644 | |
| --- a/SuperBuild/External_python.cmake | |
| +++ b/SuperBuild/External_python.cmake | |
| @@ -434,6 +434,9 @@ else() | |
| message(FATAL_ERROR "Failed to execute '${python_cmd}' using PYTHON_EXECUTABLE [${PYTHON_EXECUTABLE}]. ${ev}") | |
| endif() | |
| + get_filename_component(PYTHON_DIRECTORY "${PYTHON_EXECUTABLE}" DIRECTORY) | |
| + set(python_DIR "${PYTHON_DIRECTORY}/../../") | |
| + | |
| #----------------------------------------------------------------------------- | |
| # Slicer Launcher setting specific to build tree | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment