From cb505f44f5084549983a151a8216e30280ec4f93 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Thu, 22 Jun 2023 17:19:03 +0200 Subject: [PATCH] ENH: Restore ELASTIX_BUILD_EXECUTABLE CMake option 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 https://github.com/SuperElastix/elastix/pull/232 commit a0c161ad9891905b388a163d1306a824de998f84 "STYLE: Remove ELASTIX_BUILD_EXECUTABLE option -- always build lib + exe" The ability to suppress building the executables appears necessary for WebAssembly support, as requested by Matt McCormick at https://github.com/SuperElastix/elastix/pull/920 --- CMakeLists.txt | 4 +++ Core/CMakeLists.txt | 65 +++++++++++++++++++++++------------------- ElastixConfig.cmake.in | 1 + Testing/CMakeLists.txt | 10 ++++--- 4 files changed, 46 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e71921fe3..dac479907 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/Core/CMakeLists.txt b/Core/CMakeLists.txt index 0778c20a9..73e6bf6e1 100644 --- a/Core/CMakeLists.txt +++ b/Core/CMakeLists.txt @@ -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. @@ -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. @@ -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} diff --git a/ElastixConfig.cmake.in b/ElastixConfig.cmake.in index 1fd0957e1..3b084d4cd 100644 --- a/ElastixConfig.cmake.in +++ b/ElastixConfig.cmake.in @@ -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@ ) diff --git a/Testing/CMakeLists.txt b/Testing/CMakeLists.txt index 2922ca2be..60eef98c1 100644 --- a/Testing/CMakeLists.txt +++ b/Testing/CMakeLists.txt @@ -990,10 +990,12 @@ elx_add_run_test(3DCT_lung.NC.bspline.ASGD.001d # manual estimation and no adapt -t0 ${TestDataDir}/transformparameters.3DCT_lung.affine.txt -p ${TestDataDir}/parameters.3D.NC.bspline.ASGD.001d.txt) -# Test transformix to check memory problem -trx_add_test(TransformixMemoryTest - -in ${TestDataDir}/3DCT_lung_baseline_small.mha - -tp ${TestDataDir}/transformparameters.3DCT_lung.affine.txt) +if(${ELASTIX_BUILD_EXECUTABLE}) + # Test transformix to check memory problem + trx_add_test(TransformixMemoryTest + -in ${TestDataDir}/3DCT_lung_baseline_small.mha + -tp ${TestDataDir}/transformparameters.3DCT_lung.affine.txt) +endif() elx_add_test(TransformixFilterTest "" "Transformix" ${TestDataDir}/3DCT_lung_baseline_small.mha