#--------------------------------------------------------------------- cmake_minimum_required( VERSION 2.8 ) cmake_policy( SET CMP0012 NEW ) #--------------------------------------------------------------------- project( elastix ) #--------------------------------------------------------------------- # 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 ) ADD_DEFINITIONS( -D_ELASTIX_BUILD_LIBRARY ) MARK_AS_ADVANCED( ELASTIX_BUILD_SHARED_LIBS ) OPTION( ELASTIX_BUILD_SHARED_LIBS "Build shared libraries?" ON ) IF( ELASTIX_BUILD_SHARED_LIBS ) ADD_DEFINITIONS( -D_ELASTIX_BUILD_SHARED_LIBRARY ) ENDIF() ENDIF() #--------------------------------------------------------------------- # Find ITK. find_package( ITK REQUIRED ) include( ${ITK_USE_FILE} ) #--------------------------------------------------------------------- # Add the elastix source dir as an additional module path, # so that CMake is able to find the FindPackage modules. list( APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR} ) #--------------------------------------------------------------------- # Find CUDA. mark_as_advanced( ELASTIX_USE_CUDA ) option( ELASTIX_USE_CUDA "Use CUDA enabled GPU" OFF ) if( ELASTIX_USE_CUDA ) find_package( CUDA REQUIRED ) mark_as_advanced( CUDA_BUILD_CUBIN ) mark_as_advanced( CUDA_BUILD_EMULATION ) mark_as_advanced( CUDA_VERBOSE_BUILD ) mark_as_advanced( CUDA_SDK_ROOT_DIR ) endif() #--------------------------------------------------------------------- # Find Eigen mark_as_advanced( ELASTIX_USE_EIGEN ) option( ELASTIX_USE_EIGEN "Use Eigen library" OFF ) if( ELASTIX_USE_EIGEN ) find_package( Eigen3 REQUIRED ) include_directories( ${EIGEN3_INCLUDE_DIR} ) add_definitions( -DELASTIX_USE_EIGEN ) endif() #--------------------------------------------------------------------- # Find OpenMP find_package( OpenMP ) if( OPENMP_FOUND ) set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}" ) set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}" ) # set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} # ${OpenMP_EXE_LINKER_FLAGS}") add_definitions( -DELASTIX_USE_OPENMP ) endif() #---------------------------------------------------------------------- # Check for the SuiteSparse package # We need to do that here, because the link_directories should be set # before declaring any targets. if( USE_PreconditionedGradientDescent ) set( SUITESPARSE_BINARY_DIR "" CACHE PATH "Path to SuiteSparse" ) set( SUITESPARSE_USE_FILE ${SUITESPARSE_BINARY_DIR}/UseSuiteSparse.cmake ) if( EXISTS ${SUITESPARSE_USE_FILE} ) include( ${SUITESPARSE_USE_FILE} ) endif() endif() #--------------------------------------------------------------------- # Set single output directories for all executables and libraries. # This makes it easier to create an elxUseFile.cmake, that users can # include in their programs to borrow elastix functionality. if( NOT LIBRARY_OUTPUT_PATH ) set( LIBRARY_OUTPUT_PATH ${elastix_BINARY_DIR}/bin CACHE INTERNAL "Single output directory for building all libraries." ) endif() if( NOT EXECUTABLE_OUTPUT_PATH ) set( EXECUTABLE_OUTPUT_PATH ${elastix_BINARY_DIR}/bin CACHE INTERNAL "Single output directory for building all executables." ) endif() # Mark these variables as advanced; their default value is usually fine mark_as_advanced( LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH ) #--------------------------------------------------------------------- # Check if Mevis DicomTiff support is desired mark_as_advanced( ELASTIX_USE_MEVISDICOMTIFF ) option( ELASTIX_USE_MEVISDICOMTIFF "Support MevisLab DicomTiff image format" OFF ) #--------------------------------------------------------------------- # Define cmake variable to define extra user component directories # These directories will be added to the list of include directories # and they will be searched for CMakeLists.txt files for further # processing. In these directories, users may put code for their own # components. mark_as_advanced( ELASTIX_USER_COMPONENT_DIRS ) set( ELASTIX_USER_COMPONENT_DIRS "" CACHE PATH "directories with user defined elastix components" ) #--------------------------------------------------------------------- # elastix depends on some ITK settings if( NOT ITKReview_LOADED ) message( SEND_ERROR "Module_ITKReview has not been set to ON when compiling ITK. This option is mandatory for elastix to build.\nPlease recompile your ITK installation." ) endif() #--------------------------------------------------------------------- # If IDE supports it, do use folder view. # gcc automatically ignores it. VC Express does not support and gives # annoying warnings when this option is turned on. # VC pro does support it. set( CMAKE_USE_FOLDERS ON CACHE INTERNAL "Use folder view in IDE" ) if( CMAKE_MAKE_PROGRAM MATCHES ".?VCExpress.?" ) set( CMAKE_USE_FOLDERS OFF CACHE INTERNAL "Use folder view in IDE" ) endif() set_property( GLOBAL PROPERTY USE_FOLDERS ${CMAKE_USE_FOLDERS} ) #--------------------------------------------------------------------- # Set default build type to Release, if none was specified # Taken from ITK CMake list if( NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES ) message( STATUS "Setting build type to 'Release' as none was specified." ) set( CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE ) # Set the possible values of build type for cmake-gui set_property( CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo" ) endif() #--------------------------------------------------------------------- # Include directories set( elxCommon_INCLUDE_DIRECTORIES ${elastix_SOURCE_DIR}/Common ${elastix_SOURCE_DIR}/Common/CostFunctions ${elastix_SOURCE_DIR}/Common/CUDA ${elastix_SOURCE_DIR}/Common/ImageSamplers ${elastix_SOURCE_DIR}/Common/KNN ${elastix_SOURCE_DIR}/Common/KNN/ann_1.1/include ${elastix_SOURCE_DIR}/Common/LineSearchOptimizers ${elastix_SOURCE_DIR}/Common/ParameterFileParser ${elastix_SOURCE_DIR}/Common/Transforms ${elastix_SOURCE_DIR}/Common/xout ${elastix_SOURCE_DIR}/Common/MevisDicomTiff ) set( elxCore_INCLUDE_DIRECTORIES ${elastix_SOURCE_DIR}/Core ${elastix_SOURCE_DIR}/Core/Install ${elastix_SOURCE_DIR}/Core/Kernel ${elastix_SOURCE_DIR}/Core/ComponentBaseClasses ${elastix_SOURCE_DIR}/Core/Configuration ${elastix_SOURCE_DIR}/Core/Main ) set( elxComponents_INCLUDE_DIRECTORIES ${elastix_SOURCE_DIR}/Components/FixedImagePyramids ${elastix_SOURCE_DIR}/Components/ImageSamplers ${elastix_SOURCE_DIR}/Components/Interpolators ${elastix_SOURCE_DIR}/Components/Metrics ${elastix_SOURCE_DIR}/Components/MovingImagePyramids ${elastix_SOURCE_DIR}/Components/Optimizers ${elastix_SOURCE_DIR}/Components/Registrations ${elastix_SOURCE_DIR}/Components/ResampleInterpolators ${elastix_SOURCE_DIR}/Components/Resamplers ${elastix_SOURCE_DIR}/Components/Transforms ) set( elxINCLUDE_DIRECTORIES ${elxCommon_INCLUDE_DIRECTORIES} ${elxCore_INCLUDE_DIRECTORIES} ${elxComponents_INCLUDE_DIRECTORIES} ${elastix_BINARY_DIR} ${ELASTIX_USER_COMPONENT_DIRS} ) include_directories( ${elxINCLUDE_DIRECTORIES} ) #--------------------------------------------------------------------- # Microsoft specific items if( MSVC ) # Kill the anoying MS VS warning about non-safe functions. # They hide real warnings. add_definitions( /D_SCL_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_DEPRECATE /D_CRT_TIME_FUNCTIONS_NO_DEPRECATE ) # Increases address capacity if ( WIN32 ) set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /bigobj" ) set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /bigobj" ) set( CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /bigobj" ) endif() endif() #--------------------------------------------------------------------- # Process the sub-directories # Common dir: code that is neither related to the core of elastix or # to specific components. add_subdirectory( Common ) # Components: the registration components such as metrics, transforms, # optimizers, etc. add_subdirectory( Components ) # Core dir: code that takes care of starting elastix, loading # components, definitions of macros etc. add_subdirectory( Core ) #--------------------------------------------------------------------- # Configure the examples set( ELASTIX_DOX_DIR ${elastix_SOURCE_DIR}/../dox ) set( ELASTIX_HELP_DIR ${elastix_SOURCE_DIR}/../help CACHE PATH "path to the doxygen generated help files and the examples" ) # Copy the examples to the help directory if( WIN32 ) configure_file( ${ELASTIX_DOX_DIR}/example.bat ${ELASTIX_HELP_DIR}/example.bat COPYONLY ) else() configure_file( ${ELASTIX_DOX_DIR}/example ${ELASTIX_HELP_DIR}/example COPYONLY ) endif() make_directory( ${ELASTIX_HELP_DIR}/exampleinput ) make_directory( ${ELASTIX_HELP_DIR}/exampleoutput ) set( ELX_EXAMPLEINPUTFILES fixed.mhd fixed.raw mask_fixed.mhd mask_fixed.raw mask_moving.mhd mask_moving.raw moving.mhd moving.raw parameters_Affine.txt parameters_BSpline.txt parameters_Rigid.txt parameters_Translation.txt solution_deformedmovingimage.mhd solution_deformedmovingimage.raw ) foreach( ELX_EXAMPLEINPUTFILE ${ELX_EXAMPLEINPUTFILES} ) configure_file( ${ELASTIX_DOX_DIR}/exampleinput/${ELX_EXAMPLEINPUTFILE} ${ELASTIX_HELP_DIR}/exampleinput/${ELX_EXAMPLEINPUTFILE} COPYONLY ) endforeach() #--------------------------------------------------------------------- # Get version information. # Get the version number of elastix file( STRINGS ${elastix_SOURCE_DIR}/Core/Install/elxBaseComponent.h ELASTIX_VERSION REGEX "\(#define\ __ELASTIX_VERSION\)" ) string( SUBSTRING ${ELASTIX_VERSION} 26 3 ELASTIX_VERSION ) # Split version in major minor. Assuming no patch number, just x.y string( REGEX MATCH "[0-9]+" ELASTIX_VERSION_MAJOR "${ELASTIX_VERSION}" ) string( REGEX REPLACE "([0-9]+)\\." "" ELASTIX_VERSION_MINOR "${ELASTIX_VERSION}" ) #--------------------------------------------------------------------- # Configure the doxygen-configuration find_package( Doxygen QUIET ) string( COMPARE NOTEQUAL ${DOXYGEN} "DOXYGEN-NOTFOUND" Doxygen_FOUND ) if( Doxygen_FOUND ) # Set the path to the doxygen configuration source set( ELASTIX_DOXYGEN_DIR ${ELASTIX_DOX_DIR}/doxygen ) # Get the version number of doxygen EXEC_PROGRAM( ${DOXYGEN} ARGS "--version" OUTPUT_VARIABLE ELASTIX_DOXYGEN_VERSION ) # Get date if( UNIX OR CYGWIN ) EXEC_PROGRAM( "date '+%d-%m-%Y'" OUTPUT_VARIABLE ELASTIX_DOXYGEN_DATE ) endif() if( WIN32 ) if( NOT CYGWIN ) EXECUTE_PROCESS( COMMAND "${ELASTIX_DOXYGEN_DIR}/doxdate.bat" OUTPUT_VARIABLE ELASTIX_DOXYGEN_DATETEMP ) string( REPLACE "/" "-" ELASTIX_DOXYGEN_DATE ${ELASTIX_DOXYGEN_DATETEMP} ) endif() endif() # Configure the doxygen configuration configure_file( ${ELASTIX_DOXYGEN_DIR}/doxyfile.in ${ELASTIX_HELP_DIR}/doxyfile.out @ONLY ) # Configure the footer of the help website. configure_file( ${ELASTIX_DOXYGEN_DIR}/DoxygenFooter.html.in ${ELASTIX_HELP_DIR}/DoxygenFooter.html @ONLY ) # Configure the MainPage.dox configure_file( ${ELASTIX_DOXYGEN_DIR}/MainPage.dox.in ${ELASTIX_HELP_DIR}/MainPage.dox @ONLY ) endif() #--------------------------------------------------------------------- # Testing set( ELASTIX_BUILD_TESTING OFF CACHE BOOL "Perform some tests on basic functionality of elastix." ) if( ELASTIX_BUILD_TESTING ) enable_testing() add_subdirectory( Testing ) include( CTest ) endif() #--------------------------------------------------------------------- # Packaging mark_as_advanced( ELASTIX_ENABLE_PACKAGER ) option( ELASTIX_ENABLE_PACKAGER "Enable elastix packager using CPack" OFF ) if( ELASTIX_ENABLE_PACKAGER ) # Version information # If the next line is uncommented the package name will be like # elastix-4.3-win64 instead of elastix-4.3.0-win64 #set( CPACK_PACKAGE_VERSION ${ELASTIX_VERSION} ) set( CPACK_PACKAGE_VERSION_MAJOR ${ELASTIX_VERSION_MAJOR} ) set( CPACK_PACKAGE_VERSION_MINOR ${ELASTIX_VERSION_MINOR} ) set( CPACK_PACKAGE_VERSION_PATCH "0" ) # Also install the copyright file, since when the user enables packaging # we assume that the package is meant to distribute. INSTALL( FILES "${elastix_SOURCE_DIR}/CopyrightElastix.txt" DESTINATION . ) # We have split the elastix package into two components: # - the core: elastix and transformix # - the libraries: ANNlib and cudart when ELASTIX_USE_CUDA ON # NOTE: Currently does not work for nsis. A bug related to this # seems to be fixed in the upcoming CMake 2.8.3 # Therefore, disable component support for now. #set( CPACK_COMPONENTS_ALL core libraries Unspecified ) # CPACK_ADD_COMPONENT( core # "Core files" # DESCRIPTION "Contains elastix and transformix" # REQUIRED # DEPENDS libraries ) # [GROUP group] # [DEPENDS comp1 comp2 ... ] # [INSTALL_TYPES type1 type2 ... ] # [DOWNLOADED] # [ARCHIVE_FILE filename]) #CPACK_ADD_COMPONENT( libraries # "Libraries" # DESCRIPTION "Contains the libraries" # REQUIRED ) #set( CPACK_COMPONENT_CORE_DISPLAY_NAME "Core files" ) #set( CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries" ) #set( CPACK_COMPONENT_CORE_DESCRIPTION "Contains elastix and transformix" ) #set( CPACK_COMPONENT_LIBRARIES_DESCRIPTION "Contains the libraries" ) #set( CPACK_COMPONENT_CORE_DEPENDS libraries ) #set( CPACK_COMPONENT_CORE_REQUIRED ON ) #set( CPACK_COMPONENT_LIBRARIES_REQUIRED ON ) # The default package filename is # ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME} # which is like elastix-4.3.0-win64, or elastix-4.3.0-linux-i686 # Currently however we use elastix_windows64_v4.3 # We can change our naming schedule or come close to it using: #set( CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}_${CPACK_SYSTEM_NAME}_v${CPACK_PACKAGE_VERSION}" ) # but it doesn't work since these variables are not defined yet # Moving include(CPack) to above introduces other errors. #set( CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}_${CMAKE_SYSTEM_NAME}_v${ELASTIX_VERSION}" ) # also does not work properly. Just use the default for now. # General information set( CPACK_PACKAGE_VENDOR "Stefan Klein and Marius Staring" ) set( CPACK_PACKAGE_DESCRIPTION_SUMMARY "elastix is an image registration toolkit" ) #set( CPACK_PACKAGE_DESCRIPTION_FILE # "${CMAKE_CURRENT_SOURCE_DIR}/ReadMe.txt" ) set( CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/CopyrightElastix.txt" ) # The default install directories: .../elastix_v4.3 set( CPACK_PACKAGE_INSTALL_DIRECTORY "elastix_v${ELASTIX_VERSION_MAJOR}.${ELASTIX_VERSION_MINOR}" ) set( CPACK_PACKAGE_INSTALL_REGISTRY_KEY "elastix_v${ELASTIX_VERSION_MAJOR}.${ELASTIX_VERSION_MINOR}" ) # Do not include a subdirectory in the zip set( CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0 ) set( CPACK_SET_DESTDIR "OFF") # Make sure the directory structure is kept in the source zip # and that also the dox directory is included. set( CPACK_SOURCE_INSTALLED_DIRECTORIES "${elastix_SOURCE_DIR};/src;${ELASTIX_DOX_DIR};/dox" ) # ?? #set(CPACK_PACKAGE_EXECUTABLES "MyExecutable" "My Executable") # For the windows nsis installer only (is this if-check necessary?) if( WIN32 AND NOT UNIX ) # NOTE: There is a bug in NSI that does not handle full unix paths properly. # Make sure there is at least one set of four (4) backlashes # (CMake escapes 2, and the other gets escaped too in some second step) # Set the generators. If left blank the user has all options. set( CPACK_GENERATOR "NSIS;ZIP") # Adding information set( CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY} elastix" ) set( CPACK_NSIS_HELP_LINK "http:\\\\\\\\elastix.isi.uu.nl" ) set( CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\elastix.isi.uu.nl" ) set( CPACK_NSIS_CONTACT "elastix@bigr.nl" ) set( CPACK_NSIS_PACKAGE_NAME "elastix" ) set( CPACK_NSIS_DISPLAY_NAME "elastix" ) # Adding icons and images to make it look nice: # 1 A branding image that will be displayed inside the installer # 2 The icon file (.ico) for the generated install program # 3 The icon file (.ico) for the generated uninstall program set( CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/../dox/art\\\\elastix_logo_full_small.bmp" ) set( CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}/../dox/art\\\\elastix_logo_64.ico" ) set( CPACK_NSIS_MUI_UNIICON "${CMAKE_CURRENT_SOURCE_DIR}/../dox/art\\\\elastix_logo_64.ico" ) # Create an option in the installer that asks if elastix # needs to be added to the system path set( CPACK_NSIS_MODIFY_PATH ON ) else() # set the generators set( CPACK_GENERATOR "TBZ2;ZIP" ) # set(CPACK_STRIP_FILES "bin/MyExecutable") #set(CPACK_SOURCE_STRIP_FILES "") endif() # Uncomment the following line if we want to include the system # dll's in the distribution! #include( InstallRequiredSystemLibraries ) # This include will do all the work. include( CPack ) endif() #--------------------------------------------------------------------- # Make it easier to include elastix functionality in other programs. # Save library dependencies. # The library dependencies file. set( elxLIBRARY_DEPENDS_FILE ${elastix_BINARY_DIR}/elxLibraryDepends.cmake ) export_library_dependencies( ${elxLIBRARY_DEPENDS_FILE} ) # The "use" file. set( elxUSE_FILE ${elastix_BINARY_DIR}/UseElastix.cmake ) # The build settings file. (necessary for elastix?) #set( ITK_BUILD_SETTINGS_FILE ${ITK_BINARY_DIR}/ITKBuildSettings.cmake ) # Create the use file. configure_file( ${elastix_SOURCE_DIR}/UseElastix.cmake.in ${elxUSE_FILE} @ONLY )