Skip to content

Commit 3496fa2

Browse files
committed
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 #232 commit a0c161a "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 #920
1 parent c74c68b commit 3496fa2

File tree

4 files changed

+46
-34
lines changed

4 files changed

+46
-34
lines changed

CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ cmake_policy(SET CMP0042 NEW) # "MACOSX_RPATH is enabled by default."
1515
#---------------------------------------------------------------------
1616
include(CTest)
1717

18+
#---------------------------------------------------------------------
19+
# Allow specifying whether or not the executables are built.
20+
option( ELASTIX_BUILD_EXECUTABLE "Build elastix and transformix as executable? (The libraries are always built as well anyway.)" ON )
21+
1822
# The following may make smaller and quicker loading libraries,
1923
# that hides unnecessary symbols. Available from CMake 3.0.0.
2024
#set(CMAKE_C_VISIBILITY_PRESET hidden)

Core/CMakeLists.txt

+35-30
Original file line numberDiff line numberDiff line change
@@ -179,20 +179,23 @@ endif()
179179

180180
#---------------------------------------------------------------------
181181
# Create the elastix executable and library.
182-
add_executable(elastix_exe
183-
Main/elastix.cxx
184-
Main/elastix.h
185-
Main/elxMainExeUtilities.cxx
186-
Main/elxMainExeUtilities.h
187-
Kernel/elxMainBase.cxx
188-
Kernel/elxMainBase.h
189-
Kernel/elxElastixMain.cxx
190-
Kernel/elxElastixMain.h
191-
${InstallFilesForExecutables}
192-
)
193-
set_target_properties(elastix_exe PROPERTIES OUTPUT_NAME elastix)
194-
target_compile_definitions(elastix_exe PRIVATE ELX_CMAKE_VERSION="${CMAKE_VERSION}")
195-
target_link_libraries(elastix_exe ${ELASTIX_TARGET_LINK_LIBRARIES})
182+
183+
if(ELASTIX_BUILD_EXECUTABLE)
184+
add_executable(elastix_exe
185+
Main/elastix.cxx
186+
Main/elastix.h
187+
Main/elxMainExeUtilities.cxx
188+
Main/elxMainExeUtilities.h
189+
Kernel/elxMainBase.cxx
190+
Kernel/elxMainBase.h
191+
Kernel/elxElastixMain.cxx
192+
Kernel/elxElastixMain.h
193+
${InstallFilesForExecutables}
194+
)
195+
set_target_properties(elastix_exe PROPERTIES OUTPUT_NAME elastix)
196+
target_compile_definitions(elastix_exe PRIVATE ELX_CMAKE_VERSION="${CMAKE_VERSION}")
197+
target_link_libraries(elastix_exe ${ELASTIX_TARGET_LINK_LIBRARIES})
198+
endif()
196199

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

219-
add_executable(transformix_exe
220-
Main/transformix.cxx
221-
Main/elastix.h
222-
Main/elxMainExeUtilities.cxx
223-
Main/elxMainExeUtilities.h
224-
Kernel/elxMainBase.cxx
225-
Kernel/elxMainBase.h
226-
Kernel/elxTransformixMain.cxx
227-
Kernel/elxTransformixMain.h
228-
${InstallFilesForExecutables}
229-
)
230-
set_target_properties(transformix_exe PROPERTIES OUTPUT_NAME transformix)
231-
target_compile_definitions(transformix_exe PRIVATE ELX_CMAKE_VERSION="${CMAKE_VERSION}")
232-
target_link_libraries(transformix_exe ${ELASTIX_TARGET_LINK_LIBRARIES})
222+
if(ELASTIX_BUILD_EXECUTABLE)
223+
add_executable(transformix_exe
224+
Main/transformix.cxx
225+
Main/elastix.h
226+
Main/elxMainExeUtilities.cxx
227+
Main/elxMainExeUtilities.h
228+
Kernel/elxMainBase.cxx
229+
Kernel/elxMainBase.h
230+
Kernel/elxTransformixMain.cxx
231+
Kernel/elxTransformixMain.h
232+
${InstallFilesForExecutables}
233+
)
234+
set_target_properties(transformix_exe PROPERTIES OUTPUT_NAME transformix)
235+
target_compile_definitions(transformix_exe PRIVATE ELX_CMAKE_VERSION="${CMAKE_VERSION}")
236+
target_link_libraries(transformix_exe ${ELASTIX_TARGET_LINK_LIBRARIES})
237+
endif()
233238

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

257-
if(NOT WIN32)
262+
if(ELASTIX_BUILD_EXECUTABLE AND NOT WIN32)
258263
# Tell the executables where to find the required .so files.
259264
set_target_properties(elastix_exe transformix_exe
260265
PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib:${ITK_DIR}")
261266
endif()
262267

263-
if(NOT ELASTIX_NO_INSTALL_EXECUTABLES)
268+
if(ELASTIX_BUILD_EXECUTABLE AND NOT ELASTIX_NO_INSTALL_EXECUTABLES)
264269
install(TARGETS elastix_exe transformix_exe
265270
ARCHIVE DESTINATION ${ELASTIX_ARCHIVE_DIR}
266271
LIBRARY DESTINATION ${ELASTIX_LIBRARY_DIR}

ElastixConfig.cmake.in

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ endif()
3636

3737

3838
# Set some variables that the user might want to use
39+
set( ELASTIX_BUILD_EXECUTABLE @ELASTIX_BUILD_EXECUTABLE@ )
3940
set( ELASTIX_USE_OPENMP @ELASTIX_USE_OPENMP@ )
4041
set( ELASTIX_USE_OPENCL @ELASTIX_USE_OPENCL@ )
4142
set( ELASTIX_USE_MEVISDICOMTIFF @ELASTIX_USE_MEVISDICOMTIFF@ )

Testing/CMakeLists.txt

+6-4
Original file line numberDiff line numberDiff line change
@@ -990,10 +990,12 @@ elx_add_run_test(3DCT_lung.NC.bspline.ASGD.001d # manual estimation and no adapt
990990
-t0 ${TestDataDir}/transformparameters.3DCT_lung.affine.txt
991991
-p ${TestDataDir}/parameters.3D.NC.bspline.ASGD.001d.txt)
992992

993-
# Test transformix to check memory problem
994-
trx_add_test(TransformixMemoryTest
995-
-in ${TestDataDir}/3DCT_lung_baseline_small.mha
996-
-tp ${TestDataDir}/transformparameters.3DCT_lung.affine.txt)
993+
if(${ELASTIX_BUILD_EXECUTABLE})
994+
# Test transformix to check memory problem
995+
trx_add_test(TransformixMemoryTest
996+
-in ${TestDataDir}/3DCT_lung_baseline_small.mha
997+
-tp ${TestDataDir}/transformparameters.3DCT_lung.affine.txt)
998+
endif()
997999

9981000
elx_add_test(TransformixFilterTest "" "Transformix"
9991001
${TestDataDir}/3DCT_lung_baseline_small.mha

0 commit comments

Comments
 (0)