Skip to content

Commit

Permalink
ENH: Allow building the exe and the lib of elastix together
Browse files Browse the repository at this point in the history
  • Loading branch information
N-Dekker committed Mar 8, 2020
1 parent 633c684 commit f4676a6
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 56 deletions.
37 changes: 16 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,27 @@ include( CTest )
#---------------------------------------------------------------------
# Generate executable, static library or dynamic library.
mark_as_advanced( ELASTIX_BUILD_EXECUTABLE )
option( ELASTIX_BUILD_EXECUTABLE "Generate executable or library?" ON )

if( NOT ELASTIX_BUILD_EXECUTABLE )
option( ELASTIX_BUILD_EXECUTABLE "Generate executable? (The library is always generated 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 )
#set( CMAKE_CXX_VISIBILITY_PRESET hidden )

mark_as_advanced( BUILD_SHARED_LIBS )
option( BUILD_SHARED_LIBS "Build shared libraries?" OFF )
if( BUILD_SHARED_LIBS )
add_definitions( -D_ELASTIX_USE_SHARED_LIBRARY )
mark_as_advanced( BUILD_SHARED_LIBS )
option( BUILD_SHARED_LIBS "Build shared libraries?" OFF )
if( BUILD_SHARED_LIBS )
add_definitions( -D_ELASTIX_USE_SHARED_LIBRARY )

# We need to make sure that also the ITK is compiled with shared
# libraries on. Related to flag (ITK_)BUILD_SHARED_LIBS. todo
# We need to make sure that also the ITK is compiled with shared
# libraries on. Related to flag (ITK_)BUILD_SHARED_LIBS. todo

# In order to compile a shared library, all static sub-libraries
# need to build position independend code.
# Otherwise an error similar to the following is raised:
# relocation R_X86_64_32S against `.bss' can not be used when
# making a shared object; recompile with -fPIC
set( CMAKE_POSITION_INDEPENDENT_CODE ON )
endif()
# In order to compile a shared library, all static sub-libraries
# need to build position independend code.
# Otherwise an error similar to the following is raised:
# relocation R_X86_64_32S against `.bss' can not be used when
# making a shared object; recompile with -fPIC
set( CMAKE_POSITION_INDEPENDENT_CODE ON )
endif()

#---------------------------------------------------------------------
Expand Down Expand Up @@ -444,9 +441,7 @@ option( ELASTIX_USE_GTEST "Use GoogleTest to test Elastix implementation" OFF )
if( ELASTIX_USE_GTEST )
enable_testing()
add_subdirectory( Common/GTesting )
if( NOT ELASTIX_BUILD_EXECUTABLE )
add_subdirectory( Core/Main/GTesting )
endif()
add_subdirectory( Core/Main/GTesting )
endif()

#---------------------------------------------------------------------
Expand Down Expand Up @@ -597,8 +592,8 @@ export_library_dependencies( ${elxLIBRARY_DEPENDS_FILE} )
# The build settings file. (necessary for elastix?)
#set( ITK_BUILD_SETTINGS_FILE ${ITK_BINARY_DIR}/ITKBuildSettings.cmake )

elastix_export_target( elastix )
elastix_export_target( transformix )
elastix_export_target( elastix_lib )
elastix_export_target( transformix_lib )

foreach( LIB IN LISTS AllComponentLibs )
elastix_export_target( ${LIB} )
Expand Down
101 changes: 67 additions & 34 deletions Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,34 +120,50 @@ set( mevisdcmtifflib mevisdcmtiff )
#---------------------------------------------------------------------
# Create the elastix executable or library.
if( ELASTIX_BUILD_EXECUTABLE )
add_executable( elastix
add_executable( elastix_exe
Main/elastix.cxx
Main/elastix.h
Kernel/elxElastixMain.cxx
Kernel/elxElastixMain.h
${InstallFilesForExecutables}
)
else()
# The library type (STATIC or SHARED) is determined by the parameter
# BUILD_SHARED_LIBS.
add_library( elastix
Main/elxParameterObject.cxx
Main/elxParameterObject.h
Main/elastixlib.cxx
Main/elastixlib.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
param
xoutlib
elxCommon
elxCore
${mevisdcmtifflib}
${AllComponentLibs}
${ITK_LIBRARIES}
)
if( ELASTIX_USE_OPENCL )
target_link_libraries( elastix_lib elxOpenCL )
endif()
endif()

target_compile_definitions(elastix PRIVATE ELX_CMAKE_VERSION="${CMAKE_VERSION}")
# The library type (STATIC or SHARED) is determined by the parameter
# BUILD_SHARED_LIBS.
add_library( elastix_lib
Main/elxParameterObject.cxx
Main/elxParameterObject.h
Main/elastixlib.cxx
Main/elastixlib.h
Kernel/elxElastixMain.cxx
Kernel/elxElastixMain.h
${InstallFilesForExecutables}
)

target_compile_definitions(elastix_lib PRIVATE ELX_CMAKE_VERSION="${CMAKE_VERSION}")

#---------------------------------------------------------------------
# Create the transformix executable.

if( ELASTIX_BUILD_EXECUTABLE )
add_executable( transformix
add_executable( transformix_exe
Main/transformix.cxx
Main/elastix.h
Kernel/elxElastixMain.cxx
Expand All @@ -156,27 +172,44 @@ if( ELASTIX_BUILD_EXECUTABLE )
Kernel/elxTransformixMain.h
${InstallFilesForExecutables}
)
else()
# The library type (STATIC or SHARED) is determined by the parameter
# BUILD_SHARED_LIBS.
add_library( transformix
Main/elxParameterObject.cxx
Main/elxParameterObject.h
Main/transformixlib.cxx
Main/transformixlib.h
Kernel/elxElastixMain.cxx
Kernel/elxElastixMain.h
Kernel/elxTransformixMain.cxx
Kernel/elxTransformixMain.h
${InstallFilesForExecutables}
set_target_properties(transformix_exe PROPERTIES OUTPUT_NAME transformix)
#---------------------------------------------------------------------
# Link transformix against other libraries.

target_link_libraries( transformix_exe
param
xoutlib
elxCommon
elxCore
${mevisdcmtifflib}
${AllComponentLibs}
${ITK_LIBRARIES}
)
set( ELASTIX_LIBRARIES elastix transformix PARENT_SCOPE )

if( ELASTIX_USE_OPENCL )
target_link_libraries( transformix_exe elxOpenCL )
endif()
endif()

# The library type (STATIC or SHARED) is determined by the parameter
# BUILD_SHARED_LIBS.
add_library( transformix_lib
Main/elxParameterObject.cxx
Main/elxParameterObject.h
Main/transformixlib.cxx
Main/transformixlib.h
Kernel/elxElastixMain.cxx
Kernel/elxElastixMain.h
Kernel/elxTransformixMain.cxx
Kernel/elxTransformixMain.h
${InstallFilesForExecutables}
)
set( ELASTIX_LIBRARIES elastix transformix PARENT_SCOPE )

#---------------------------------------------------------------------
# Link elastix against other libraries.

target_link_libraries( elastix
target_link_libraries( elastix_lib
param
xoutlib
elxCommon
Expand All @@ -187,13 +220,13 @@ target_link_libraries( elastix
)

if( ELASTIX_USE_OPENCL )
target_link_libraries( elastix elxOpenCL )
target_link_libraries( elastix_lib elxOpenCL )
endif()

#---------------------------------------------------------------------
# Link transformix against other libraries.

target_link_libraries( transformix
target_link_libraries( transformix_lib
param
xoutlib
elxCommon
Expand All @@ -204,7 +237,7 @@ target_link_libraries( transformix
)

if( ELASTIX_USE_OPENCL )
target_link_libraries( transformix elxOpenCL )
target_link_libraries( transformix_lib elxOpenCL )
endif()

if( MSVC )
Expand All @@ -223,11 +256,11 @@ endif()

if( NOT WIN32 )
# Tell the executables where to find the required .so files.
set_target_properties( elastix transformix
set_target_properties( elastix_lib transformix_lib
PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib:${ITK_DIR}" )
endif()

install( TARGETS elastix transformix elxCore
install( TARGETS elastix_lib transformix_lib elxCore
ARCHIVE DESTINATION ${ELASTIX_ARCHIVE_DIR}
LIBRARY DESTINATION ${ELASTIX_LIBRARY_DIR}
RUNTIME DESTINATION ${ELASTIX_RUNTIME_DIR}
Expand Down
2 changes: 1 addition & 1 deletion Testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ macro( elx_add_run_test testbasename howtocompare )
CONFIGURATIONS Release
COMMAND ${python_executable} ${pythonlandmarks}
-b ${baselineTP} -d ${output_dir} -f ${TestDataDir}/3DCT_lung_baseline_landmarks.txt -t 1.0
-p $<TARGET_FILE:transformix> )
-p $<TARGET_FILE:transformix_exe> )
set_tests_properties( ${testname}_COMPARE_LANDMARKS
PROPERTIES DEPENDS ${testname}_OUTPUT )
endif()
Expand Down

0 comments on commit f4676a6

Please sign in to comment.