Skip to content

Commit

Permalink
ENH: Add CMake options to not install artifacts
Browse files Browse the repository at this point in the history
Add CMake advanced options:

- ELASTIX_NO_INSTALL_EXECUTABLES
- ELASTIX_NO_INSTALL_DEVELOPMENT
- ELASTIX_NO_INSTALL_RUNTIME_LIBRARIES

To prevent installation of executables, headers and static libraries,
and runtime libraries, respectively.

This helps address:

- InsightSoftwareConsortium/ITKElastix#182
- InsightSoftwareConsortium/ITKElastix#183

Also update the install COMPONENT to be consistent.

Also remove duplicate `install`'s for some targets that were
installed via elastix_export_target.
  • Loading branch information
thewtex committed Dec 7, 2022
1 parent 353a095 commit 83f17a9
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 78 deletions.
49 changes: 42 additions & 7 deletions CMake/elastixExportTarget.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,51 @@ function(elastix_export_target tgt)
set_property(TARGET ${tgt} PROPERTY
OUTPUT_NAME ${tgt}-${ELASTIX_VERSION_MAJOR}.${ELASTIX_VERSION_MINOR})
endif()

if(type STREQUAL "STATIC_LIBRARY")
if(NOT ELASTIX_NO_INSTALL_DEVELOPMENT)
install(TARGETS ${tgt}
EXPORT ElastixTargets
RUNTIME DESTINATION ${ELASTIX_INSTALL_RUNTIME_DIR}
LIBRARY DESTINATION ${ELASTIX_INSTALL_LIBRARY_DIR}
ARCHIVE DESTINATION ${ELASTIX_INSTALL_ARCHIVE_DIR}
COMPONENT Development
)
endif()
else()
if(NOT ELASTIX_NO_INSTALL_RUNTIME_LIBRARIES)
install(TARGETS ${tgt}
EXPORT ElastixTargets
RUNTIME DESTINATION ${ELASTIX_INSTALL_RUNTIME_DIR}
LIBRARY DESTINATION ${ELASTIX_INSTALL_LIBRARY_DIR}
ARCHIVE DESTINATION ${ELASTIX_INSTALL_ARCHIVE_DIR}
COMPONENT RuntimeLibraries
)
endif()
endif()
elseif(type STREQUAL "EXECUTABLE")
if(NOT ELASTIX_NO_INSTALL_RUNTIME_LIBRARIES)
install(TARGETS ${tgt}
EXPORT ElastixTargets
RUNTIME DESTINATION ${ELASTIX_INSTALL_RUNTIME_DIR}
LIBRARY DESTINATION ${ELASTIX_INSTALL_LIBRARY_DIR}
ARCHIVE DESTINATION ${ELASTIX_INSTALL_ARCHIVE_DIR}
COMPONENT Executables
)
endif()
else()
if(NOT ELASTIX_NO_INSTALL_DEVELOPMENT)
install(TARGETS ${tgt}
EXPORT ElastixTargets
RUNTIME DESTINATION ${ELASTIX_INSTALL_RUNTIME_DIR}
LIBRARY DESTINATION ${ELASTIX_INSTALL_LIBRARY_DIR}
ARCHIVE DESTINATION ${ELASTIX_INSTALL_ARCHIVE_DIR}
COMPONENT Development
)
endif()
endif()

export(TARGETS ${tgt}
APPEND FILE "${elastix_BINARY_DIR}/ElastixTargets.cmake"
)

install(TARGETS ${tgt}
EXPORT ElastixTargets
RUNTIME DESTINATION ${ELASTIX_INSTALL_RUNTIME_DIR}
LIBRARY DESTINATION ${ELASTIX_INSTALL_LIBRARY_DIR}
ARCHIVE DESTINATION ${ELASTIX_INSTALL_ARCHIVE_DIR}
)
endfunction()
33 changes: 21 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@ if(NOT ELASTIX_INSTALL_PACKAGE_DIR)
set(ELASTIX_INSTALL_PACKAGE_DIR "${ELASTIX_LIBRARY_DIR}/cmake/elastix")
endif()

#---------------------------------------------------------------------
# Provide options to avoid installing runtime or development components
option(ELASTIX_NO_INSTALL_RUNTIME_LIBRARIES "Do not install runtime libraries" OFF)
option(ELASTIX_NO_INSTALL_EXECUTABLES "Do not install executables" OFF)
option(ELASTIX_NO_INSTALL_DEVELOPMENT "Do not install development headers and static libraries" OFF)
mark_as_advanced(ELASTIX_NO_INSTALL_EXECUTABLES ELASTIX_NO_INSTALL_RUNTIME_LIBRARIES ELASTIX_NO_INSTALL_DEVELOPMENT)

#---------------------------------------------------------------------
# Check if Mevis DicomTiff support is desired
mark_as_advanced(ELASTIX_USE_MEVISDICOMTIFF)
Expand Down Expand Up @@ -637,15 +644,17 @@ configure_file(ElastixConfig.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECT
configure_file(ElastixConfigVersion.cmake.in ElastixConfigVersion.cmake @ONLY)
configure_file(UseElastix.cmake.in UseElastix.cmake @ONLY)

install(FILES
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/ElastixConfig.cmake"
"${PROJECT_BINARY_DIR}/ElastixConfigVersion.cmake"
"${PROJECT_BINARY_DIR}/UseElastix.cmake"
DESTINATION ${ELASTIX_INSTALL_PACKAGE_DIR}
COMPONENT Development
)

install(EXPORT ElastixTargets
DESTINATION ${ELASTIX_INSTALL_PACKAGE_DIR}
COMPONENT Development
)
if(NOT ELASTIX_NO_INSTALL_DEVELOPMENT)
install(FILES
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/ElastixConfig.cmake"
"${PROJECT_BINARY_DIR}/ElastixConfigVersion.cmake"
"${PROJECT_BINARY_DIR}/UseElastix.cmake"
DESTINATION ${ELASTIX_INSTALL_PACKAGE_DIR}
COMPONENT Development
)

install(EXPORT ElastixTargets
DESTINATION ${ELASTIX_INSTALL_PACKAGE_DIR}
COMPONENT Development
)
endif()
12 changes: 8 additions & 4 deletions Common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,14 @@ add_library(elxCommon STATIC
${LineSearchOptimizersFiles}
${ImageSamplersFiles}
)
install(TARGETS elxCommon
ARCHIVE DESTINATION ${ELASTIX_ARCHIVE_DIR}
LIBRARY DESTINATION ${ELASTIX_LIBRARY_DIR}
RUNTIME DESTINATION ${ELASTIX_RUNTIME_DIR})
if(NOT ELASTIX_NO_INSTALL_DEVELOPMENT)
install(TARGETS elxCommon
ARCHIVE DESTINATION ${ELASTIX_ARCHIVE_DIR}
LIBRARY DESTINATION ${ELASTIX_LIBRARY_DIR}
RUNTIME DESTINATION ${ELASTIX_RUNTIME_DIR}
COMPONENT Development
)
endif()

#---------------------------------------------------------------------
# Link against other libraries.
Expand Down
11 changes: 7 additions & 4 deletions Common/MevisDicomTiff/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ else()
)
endif()

install(TARGETS mevisdcmtiff
ARCHIVE DESTINATION ${ELASTIX_ARCHIVE_DIR}
LIBRARY DESTINATION ${ELASTIX_LIBRARY_DIR}
RUNTIME DESTINATION ${ELASTIX_RUNTIME_DIR})
if(NOT ELASTIX_NO_INSTALL_DEVELOPMENT)
install(TARGETS mevisdcmtiff
ARCHIVE DESTINATION ${ELASTIX_ARCHIVE_DIR}
LIBRARY DESTINATION ${ELASTIX_LIBRARY_DIR}
RUNTIME DESTINATION ${ELASTIX_RUNTIME_DIR}
COMPONENT Development)
endif()

target_link_libraries(mevisdcmtiff ${ITK_LIBRARIES})

Expand Down
11 changes: 7 additions & 4 deletions Common/OpenCL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,12 @@ target_link_libraries(elxOpenCL
# Group in IDE's like Visual Studio
set_property(TARGET elxOpenCL PROPERTY FOLDER "libraries")

install(TARGETS elxOpenCL
ARCHIVE DESTINATION ${ELASTIX_ARCHIVE_DIR}
LIBRARY DESTINATION ${ELASTIX_LIBRARY_DIR}
RUNTIME DESTINATION ${ELASTIX_RUNTIME_DIR})
if(NOT ELASTIX_NO_INSTALL_DEVELOPMENT)
install(TARGETS elxOpenCL
ARCHIVE DESTINATION ${ELASTIX_ARCHIVE_DIR}
LIBRARY DESTINATION ${ELASTIX_LIBRARY_DIR}
RUNTIME DESTINATION ${ELASTIX_RUNTIME_DIR}
COMPONENT Development)
endif()

elastix_export_target(elxOpenCL)
11 changes: 7 additions & 4 deletions Common/ParameterFileParser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ set(param_SRCS
source_group("Parser" FILES ${param_SRCS})

add_library(param STATIC ${param_SRCS})
install(TARGETS param
ARCHIVE DESTINATION ${ELASTIX_ARCHIVE_DIR}
LIBRARY DESTINATION ${ELASTIX_LIBRARY_DIR}
RUNTIME DESTINATION ${ELASTIX_RUNTIME_DIR})
if(NOT ELASTIX_NO_INSTALL_DEVELOPMENT)
install(TARGETS param
ARCHIVE DESTINATION ${ELASTIX_ARCHIVE_DIR}
LIBRARY DESTINATION ${ELASTIX_LIBRARY_DIR}
RUNTIME DESTINATION ${ELASTIX_RUNTIME_DIR}
COMPONENT Development)
endif()

target_link_libraries(param ${ITK_LIBRARIES})

Expand Down
11 changes: 7 additions & 4 deletions Common/xout/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ set(xouthfiles

# a lib defining the global variable xout.
add_library(xoutlib STATIC ${xoutcxxfiles} ${xouthfiles})
install(TARGETS xoutlib
ARCHIVE DESTINATION ${ELASTIX_ARCHIVE_DIR}
LIBRARY DESTINATION ${ELASTIX_LIBRARY_DIR}
RUNTIME DESTINATION ${ELASTIX_RUNTIME_DIR})
if(NOT ELASTIX_NO_INSTALL_DEVELOPMENT)
install(TARGETS xoutlib
ARCHIVE DESTINATION ${ELASTIX_ARCHIVE_DIR}
LIBRARY DESTINATION ${ELASTIX_LIBRARY_DIR}
RUNTIME DESTINATION ${ELASTIX_RUNTIME_DIR}
COMPONENT Development)
endif()

# Group in IDE's like Visual Studio
set_property(TARGET xoutlib PROPERTY FOLDER "libraries")
11 changes: 7 additions & 4 deletions Components/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,13 @@ macro(ADD_ELXCOMPONENT name)
project(${name})
add_library(${name} STATIC ${filelist})
target_link_libraries(${name} ${elxLinkLibs})
install(TARGETS ${name}
ARCHIVE DESTINATION ${ELASTIX_ARCHIVE_DIR}
LIBRARY DESTINATION ${ELASTIX_LIBRARY_DIR}
RUNTIME DESTINATION ${ELASTIX_RUNTIME_DIR})
if(NOT ELASTIX_NO_INSTALL_DEVELOPMENT)
install(TARGETS ${name}
ARCHIVE DESTINATION ${ELASTIX_ARCHIVE_DIR}
LIBRARY DESTINATION ${ELASTIX_LIBRARY_DIR}
RUNTIME DESTINATION ${ELASTIX_RUNTIME_DIR}
COMPONENT Development)
endif()

# Group in IDE's like Visual Studio
string(REGEX MATCH "[a-zA-Z]+" comp_group ${relative_path_to_comp})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ ADD_ELXCOMPONENT( KNNGraphAlphaMutualInformationMetric
)

if(USE_KNNGraphAlphaMutualInformationMetric)
if(ELASTIX_NO_INSTALL_RUNTIME_LIBRARIES AND NOT ELASTIX_NO_INSTALL_DEVELOPMENT)
message(SEND_ERROR "USE_KNNGraphAlphaMutualInformationMetric with ELASTIX_NO_INSTALL_RUNTIME_LIBRARIES enabled requires ELASTIX_NO_INSTALL_DEVELOPMENT enabled")
endif()
add_subdirectory(KNN)
target_include_directories(KNNGraphAlphaMutualInformationMetric
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/KNN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,3 @@ target_link_libraries(KNNlib ANNlib ${ITK_LIBRARIES})

# Group in IDE's like Visual Studio
set_property(TARGET KNNlib PROPERTY FOLDER "libraries")

install(TARGETS KNNlib
ARCHIVE DESTINATION ${ELASTIX_ARCHIVE_DIR}
LIBRARY DESTINATION ${ELASTIX_LIBRARY_DIR}
RUNTIME DESTINATION ${ELASTIX_RUNTIME_DIR}
COMPONENT RuntimeLibraries)
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,3 @@ generate_export_header(ANNlib

# Group in IDE's like Visual Studio
set_property(TARGET ANNlib PROPERTY FOLDER "libraries")

# Install
install(TARGETS ANNlib
ARCHIVE DESTINATION ${ELASTIX_ARCHIVE_DIR}
LIBRARY DESTINATION ${ELASTIX_LIBRARY_DIR}
RUNTIME DESTINATION ${ELASTIX_RUNTIME_DIR}
COMPONENT RuntimeLibraries)
54 changes: 32 additions & 22 deletions Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,14 @@ source_group("ProgressCommand" FILES ${ProgressCommandFiles})
configure_file(
elxVersionMacros.h.in
elxVersionMacros.h)

install(FILES
${CMAKE_CURRENT_BINARY_DIR}/elxVersionMacros.h
DESTINATION ${CMAKE_INSTALL_PREFIX}/include/Core)

if(NOT ELASTIX_NO_INSTALL_DEVELOPMENT)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/elxVersionMacros.h
DESTINATION ${CMAKE_INSTALL_PREFIX}/include/Core
COMPONENT Development
)
endif()
#---------------------------------------------------------------------

# Originally based on the answer by Naszta at
Expand Down Expand Up @@ -244,26 +248,32 @@ if(NOT WIN32)
PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib:${ITK_DIR}")
endif()

install(TARGETS elastix_exe transformix_exe elastix_lib transformix_lib elxCore
ARCHIVE DESTINATION ${ELASTIX_ARCHIVE_DIR}
LIBRARY DESTINATION ${ELASTIX_LIBRARY_DIR}
RUNTIME DESTINATION ${ELASTIX_RUNTIME_DIR}
COMPONENT RuntimeLibraries)
if(NOT ELASTIX_NO_INSTALL_EXECUTABLES)
install(TARGETS elastix_exe transformix_exe
ARCHIVE DESTINATION ${ELASTIX_ARCHIVE_DIR}
LIBRARY DESTINATION ${ELASTIX_LIBRARY_DIR}
RUNTIME DESTINATION ${ELASTIX_RUNTIME_DIR}
COMPONENT Executables)
endif()

# Install all header files.
install(DIRECTORY
${elastix_SOURCE_DIR}/Common
${elastix_SOURCE_DIR}/Core
${elastix_SOURCE_DIR}/Components
DESTINATION ${ELASTIX_INCLUDE_DIR}
FILES_MATCHING PATTERN "*.h" PATTERN "*.hxx")
install(FILES
${elastix_BINARY_DIR}/elxInstallComponentFunctionCalls.h
${elastix_BINARY_DIR}/elxInstallComponentFunctionDeclarations.h
${elastix_BINARY_DIR}/elxSupportedImageTypes.h
${elastix_BINARY_DIR}/ITKFactoryRegistration/itkImageIOFactoryRegisterManager.h
${elastix_BINARY_DIR}/ITKFactoryRegistration/itkTransformIOFactoryRegisterManager.h
DESTINATION ${ELASTIX_INCLUDE_DIR})
if(NOT ELASTIX_NO_INSTALL_DEVELOPMENT)
install(DIRECTORY
${elastix_SOURCE_DIR}/Common
${elastix_SOURCE_DIR}/Core
${elastix_SOURCE_DIR}/Components
DESTINATION ${ELASTIX_INCLUDE_DIR}
COMPONENT Development
FILES_MATCHING PATTERN "*.h" PATTERN "*.hxx")
install(FILES
${elastix_BINARY_DIR}/elxInstallComponentFunctionCalls.h
${elastix_BINARY_DIR}/elxInstallComponentFunctionDeclarations.h
${elastix_BINARY_DIR}/elxSupportedImageTypes.h
${elastix_BINARY_DIR}/ITKFactoryRegistration/itkImageIOFactoryRegisterManager.h
${elastix_BINARY_DIR}/ITKFactoryRegistration/itkTransformIOFactoryRegisterManager.h
DESTINATION ${ELASTIX_INCLUDE_DIR}
COMPONENT Development)
endif()

#---------------------------------------------------------------------
# The Core/Install directory contains a CMakeLists file for
Expand Down

0 comments on commit 83f17a9

Please sign in to comment.