Skip to content

Commit

Permalink
ENH: Restore ELASTIX_BUILD_EXECUTABLE CMake option
Browse files Browse the repository at this point in the history
Added support for `ELASTIX_BUILD_EXECUTABLE`, allowing to switch off building the elastix and transformix executables, while still building the libraries.

Basically reverts pull request #232 commit a0c161a "STYLE: Remove ELASTIX_BUILD_EXECUTABLE option -- always build lib + exe" (August 25, 2020).

The ability to suppress building the executables appears necessary for WebAssembly support, as requested by Matt McCormick at pull request #920
  • Loading branch information
N-Dekker committed Jun 23, 2023
1 parent c47889a commit 9d76b86
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 165 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ cmake_policy(SET CMP0042 NEW) # "MACOSX_RPATH is enabled by default."
#---------------------------------------------------------------------
include(CTest)

#---------------------------------------------------------------------
# Allow specifying whether or not the executables are built.
option( ELASTIX_BUILD_EXECUTABLE "Build elastix and transformix as executable? (The libraries are always built as well anyway.)" ON )

# The following may make smaller and quicker loading libraries,
# that hides unnecessary symbols. Available from CMake 3.0.0.
#set(CMAKE_C_VISIBILITY_PRESET hidden)
Expand Down
65 changes: 35 additions & 30 deletions Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,20 +179,23 @@ endif()

#---------------------------------------------------------------------
# Create the elastix executable and library.
add_executable(elastix_exe
Main/elastix.cxx
Main/elastix.h
Main/elxMainExeUtilities.cxx
Main/elxMainExeUtilities.h
Kernel/elxMainBase.cxx
Kernel/elxMainBase.h
Kernel/elxElastixMain.cxx
Kernel/elxElastixMain.h
${InstallFilesForExecutables}
)
set_target_properties(elastix_exe PROPERTIES OUTPUT_NAME elastix)
target_compile_definitions(elastix_exe PRIVATE ELX_CMAKE_VERSION="${CMAKE_VERSION}")
target_link_libraries(elastix_exe ${ELASTIX_TARGET_LINK_LIBRARIES})

if(ELASTIX_BUILD_EXECUTABLE)
add_executable(elastix_exe
Main/elastix.cxx
Main/elastix.h
Main/elxMainExeUtilities.cxx
Main/elxMainExeUtilities.h
Kernel/elxMainBase.cxx
Kernel/elxMainBase.h
Kernel/elxElastixMain.cxx
Kernel/elxElastixMain.h
${InstallFilesForExecutables}
)
set_target_properties(elastix_exe PROPERTIES OUTPUT_NAME elastix)
target_compile_definitions(elastix_exe PRIVATE ELX_CMAKE_VERSION="${CMAKE_VERSION}")
target_link_libraries(elastix_exe ${ELASTIX_TARGET_LINK_LIBRARIES})
endif()

# The library type (STATIC or SHARED) is determined by the parameter
# BUILD_SHARED_LIBS.
Expand All @@ -216,20 +219,22 @@ target_link_libraries(elastix_lib ${ELASTIX_TARGET_LINK_LIBRARIES})
#---------------------------------------------------------------------
# Create the transformix executable.

add_executable(transformix_exe
Main/transformix.cxx
Main/elastix.h
Main/elxMainExeUtilities.cxx
Main/elxMainExeUtilities.h
Kernel/elxMainBase.cxx
Kernel/elxMainBase.h
Kernel/elxTransformixMain.cxx
Kernel/elxTransformixMain.h
${InstallFilesForExecutables}
)
set_target_properties(transformix_exe PROPERTIES OUTPUT_NAME transformix)
target_compile_definitions(transformix_exe PRIVATE ELX_CMAKE_VERSION="${CMAKE_VERSION}")
target_link_libraries(transformix_exe ${ELASTIX_TARGET_LINK_LIBRARIES})
if(ELASTIX_BUILD_EXECUTABLE)
add_executable(transformix_exe
Main/transformix.cxx
Main/elastix.h
Main/elxMainExeUtilities.cxx
Main/elxMainExeUtilities.h
Kernel/elxMainBase.cxx
Kernel/elxMainBase.h
Kernel/elxTransformixMain.cxx
Kernel/elxTransformixMain.h
${InstallFilesForExecutables}
)
set_target_properties(transformix_exe PROPERTIES OUTPUT_NAME transformix)
target_compile_definitions(transformix_exe PRIVATE ELX_CMAKE_VERSION="${CMAKE_VERSION}")
target_link_libraries(transformix_exe ${ELASTIX_TARGET_LINK_LIBRARIES})
endif()

# The library type (STATIC or SHARED) is determined by the parameter
# BUILD_SHARED_LIBS.
Expand All @@ -254,13 +259,13 @@ set(ELASTIX_LIBRARIES elastix_lib transformix_lib PARENT_SCOPE)
#---------------------------------------------------------------------
# Define the install directory for elastix and transformix.

if(NOT WIN32)
if(ELASTIX_BUILD_EXECUTABLE AND NOT WIN32)
# Tell the executables where to find the required .so files.
set_target_properties(elastix_exe transformix_exe
PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib:${ITK_DIR}")
endif()

if(NOT ELASTIX_NO_INSTALL_EXECUTABLES)
if(ELASTIX_BUILD_EXECUTABLE AND NOT ELASTIX_NO_INSTALL_EXECUTABLES)
install(TARGETS elastix_exe transformix_exe
ARCHIVE DESTINATION ${ELASTIX_ARCHIVE_DIR}
LIBRARY DESTINATION ${ELASTIX_LIBRARY_DIR}
Expand Down
1 change: 1 addition & 0 deletions ElastixConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ endif()


# Set some variables that the user might want to use
set( ELASTIX_BUILD_EXECUTABLE @ELASTIX_BUILD_EXECUTABLE@ )
set( ELASTIX_USE_OPENMP @ELASTIX_USE_OPENMP@ )
set( ELASTIX_USE_OPENCL @ELASTIX_USE_OPENCL@ )
set( ELASTIX_USE_MEVISDICOMTIFF @ELASTIX_USE_MEVISDICOMTIFF@ )
Expand Down
Loading

0 comments on commit 9d76b86

Please sign in to comment.