Skip to content

Instantly share code, notes, and snippets.

@jcfr
Last active September 21, 2023 16:56
Show Gist options
  • Save jcfr/e1974337c71d94730ae084985b887ca5 to your computer and use it in GitHub Desktop.
Save jcfr/e1974337c71d94730ae084985b887ca5 to your computer and use it in GitHub Desktop.
Example of external project for bundling "scikit-image" into a Slicer custom application
set(proj python-scikit-image)
# Set dependency list
set(${proj}_DEPENDENCIES
python
python-pip
python-setuptools
)
if(NOT DEFINED Slicer_USE_SYSTEM_${proj})
set(Slicer_USE_SYSTEM_${proj} ${Slicer_USE_SYSTEM_python})
endif()
# Include dependent projects if any
ExternalProject_Include_Dependencies(${proj} PROJECT_VAR proj DEPENDS_VAR ${proj}_DEPENDENCIES)
if(Slicer_USE_SYSTEM_${proj})
foreach(module_name IN ITEMS
skimage
)
ExternalProject_FindPythonPackage(
MODULE_NAME "${module_name}"
REQUIRED
)
endforeach()
endif()
if(NOT Slicer_USE_SYSTEM_${proj})
set(requirements_file ${CMAKE_BINARY_DIR}/${proj}-requirements.txt)
file(WRITE ${requirements_file} [===[
# [scikit-image]
# [/scikit-image]
# [imageio]
# [/imageio]
# [lazy_loader]
# [/lazy_loader]
# [networkx]
# [/networkx]
# [PyWavelets]
# [/PyWavelets]
# [tifffile]
# [/tifffile]
]===])
ExternalProject_Add(${proj}
${${proj}_EP_ARGS}
DOWNLOAD_COMMAND ""
SOURCE_DIR ${CMAKE_BINARY_DIR}/${proj}
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND
COMMAND ${PYTHON_EXECUTABLE} -m pip install --require-hashes -r ${requirements_file}
LOG_INSTALL 1
DEPENDS
${${proj}_DEPENDENCIES}
)
ExternalProject_GenerateProjectDescription_Step(${proj})
#-----------------------------------------------------------------------------
# Launcher setting specific to build tree
# NA
#-----------------------------------------------------------------------------
# Launcher setting specific to install tree
# NA
else()
ExternalProject_Add_Empty(${proj} DEPENDS ${${proj}_DEPENDENCIES})
endif()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment