From 00d22904e73f5061b3d24be5a08071ab641235f6 Mon Sep 17 00:00:00 2001 From: Kasper Marstal <kaspermarstal@gmail.com> Date: Tue, 28 Apr 2015 23:02:59 +0200 Subject: [PATCH] COMP: ELASTIX-1 Add SuperBuild --- .gitmodules | 1 + CMake/elxRequiredITKModules.cmake | 9 +++++ CMakeLists.txt | 43 +++++++++++++++++++++ SuperBuild/CMakeLists.txt | 64 +++++++++++++++++++++++++++++++ SuperBuild/Elastix.cmake | 15 ++++++++ SuperBuild/ExternalExamples.cmake | 0 SuperBuild/ExternalITK.cmake | 24 ++++++++++++ Testing/CMakeLists.txt | 30 +++++++++++++++ Testing/elxExampleTest.cxx | 5 +++ 9 files changed, 191 insertions(+) create mode 100644 CMake/elxRequiredITKModules.cmake create mode 100644 CMakeLists.txt create mode 100644 SuperBuild/CMakeLists.txt create mode 100644 SuperBuild/Elastix.cmake create mode 100644 SuperBuild/ExternalExamples.cmake create mode 100644 SuperBuild/ExternalITK.cmake create mode 100644 Testing/CMakeLists.txt create mode 100644 Testing/elxExampleTest.cxx diff --git a/.gitmodules b/.gitmodules index 5b670f3b..f5887d97 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,4 @@ [submodule "Testing/GoogleTest"] path = Testing/GoogleTest url = https://github.com/kaspermarstal/GoogleTest + tag = release-1.7.0 diff --git a/CMake/elxRequiredITKModules.cmake b/CMake/elxRequiredITKModules.cmake new file mode 100644 index 00000000..284dddb8 --- /dev/null +++ b/CMake/elxRequiredITKModules.cmake @@ -0,0 +1,9 @@ +list( APPEND ElastixRequiredITKModules + ITKReview +) + +foreach( ITKModule ${ElastixRequiredITKModules} ) + if( NOT ${ITKModule}_LOADED ) + message( FATAL_ERROR "Elastix requires that ITK is build with ${ITKModule}. Please rebuild ITK with Module_${ITKModule} set to ON." ) + endif() +endforeach() \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..9d4f8b65 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,43 @@ +cmake_minimum_required( VERSION 2.8 ) + +#--------------------------------------------------------------------- +project( elastix ) + +#--------------------------------------------------------------------- +# ITK + +find_package( ITK REQUIRED ) +include( ${ITK_USE_FILE} ) +include( "${CMAKE_CURRENT_SOURCE_DIR}/CMake/elxRequiredITKModules.cmake" ) + +#--------------------------------------------------------------------- +# Testing + +if( BUILD_TESTING ) + if( NOT EXISTS "${CMAKE_SOURCE_DIR}/Testing/GoogleTest/.git" ) + message( FATAL_ERROR "Could not find GoogleTest submodule. Please run git submodule init to compile tests." ) + endif() + + enable_testing() + + mark_as_advanced( BUILD_CTESTS ) + option( BUILD_CTESTS "Enable CTests." ON ) + if( BUILD_CTESTS ) + include( CTest ) + endif() + + add_subdirectory( Testing ) +endif() + +#--------------------------------------------------------------------- +# Build Elastix + +#--------------------------------------------------------------------- +# Build Documentation + +mark_as_advanced( BUILD_DOXYGEN ) +option( BUILD_DOXYGEN "Enable building Doxygen documentation." OFF ) + +mark_as_advanced( BUILD_READTHEDOCS OFF ) +option( BUILD_READTHEDOCS "Enable building readthedocs.org documentation." OFF ) + diff --git a/SuperBuild/CMakeLists.txt b/SuperBuild/CMakeLists.txt new file mode 100644 index 00000000..dc7142e3 --- /dev/null +++ b/SuperBuild/CMakeLists.txt @@ -0,0 +1,64 @@ +cmake_minimum_required( VERSION 2.8 ) + +#--------------------------------------------------------------------- +# Prerequisites + +find_package( Git REQUIRED ) + +include( ExternalProject ) + +enable_language(C) +enable_language(CXX) + +set( CMAKE_MODULE_PATH + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/../CMake + ${CMAKE_MODULE_PATH} +) + +#--------------------------------------------------------------------- +# Elastix SuperBuild configuration + +# Build release by default +if( NOT DEFINED CMAKE_BUILD_TYPE ) + set( CMAKE_BUILD_TYPE "Release" ) +endif() + +# Build examples by default +# Examples will be build as an external project to verify the installation of elastix +option( ELASTIX_BUILD_EXAMPLES "Enable building examples." ON ) + +# Do not build testing by default since this requires GoogleTest submodule to be initialized +option( ELASTIX_BUILD_TESTING "Enable building tests." OFF ) + +if( ELASTIX_BUILD_TESTING ) + mark_as_advanced( ELASTIX_BUILD_CTESTS ) + option( ELASTIX_BUILD_CTESTS "Enable CTests." OFF ) +endif() + +#--------------------------------------------------------------------- +# Build ITK as external project + +set( ITK_VERSION_MAJOR "4" ) +set( ITK_VERSION_MINOR "7" ) +set( ITK_VERSION_PATCH "1" ) +set( ITK_VERSION_STRING "${ITK_VERSION_MAJOR}.${ITK_VERSION_MINOR}.${ITK_VERSION_PATCH}" ) + +mark_as_advanced( USE_SYSTEM_ITK ) +option( USE_SYSTEM_ITK "Use an installed version of ITK" OFF ) + +if( USE_SYSTEM_ITK ) + find_package( ITK ${ITK_VERSION_MAJOR}.${ITK_VERSION_MINOR} REQUIRED ) + include( "${CMAKE_CURRENT_SOURCE_DIR}/../CMake/elxRequiredITKModules.cmake" ) +else() + include( ExternalITK ) + list( APPEND ELASTIX_DEPENDENCIES ITK ) +endif() + +#--------------------------------------------------------------------- +# Build Elastix as an external project + +include( Elastix ) + + + diff --git a/SuperBuild/Elastix.cmake b/SuperBuild/Elastix.cmake new file mode 100644 index 00000000..5cc4b57b --- /dev/null +++ b/SuperBuild/Elastix.cmake @@ -0,0 +1,15 @@ +set( proj Elastix ) + +ExternalProject_Add( ${proj} + DOWNLOAD_COMMAND "" + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/.. + BINARY_DIR ${proj}-build + INSTALL_DIR ${CMAKE_INSTALL_PREFIX} + CMAKE_ARGS + --no-warn-unused-cli + -DBUILD_TESTING:BOOL=${ELASTIX_BUILD_TESTING} + -DBUILD_CTESTS:BOOL=${ELASTIX_BUILD_CTESTS} + -DITK_DIR:PATH=${ITK_DIR} + DEPENDS ${ELASTIX_DEPENDENCIES} + INSTALL_COMMAND "" +) \ No newline at end of file diff --git a/SuperBuild/ExternalExamples.cmake b/SuperBuild/ExternalExamples.cmake new file mode 100644 index 00000000..e69de29b diff --git a/SuperBuild/ExternalITK.cmake b/SuperBuild/ExternalITK.cmake new file mode 100644 index 00000000..206e83a6 --- /dev/null +++ b/SuperBuild/ExternalITK.cmake @@ -0,0 +1,24 @@ +set( proj ITK ) +set( ITK_REPOSITORY https://github.com/InsightSoftwareConsortium/ITK.git ) +set( ITK_TAG "v${ITK_VERSION_STRING}") + +ExternalProject_Add( ${proj} + GIT_REPOSITORY ${ITK_REPOSITORY} + GIT_TAG ${ITK_TAG} + UPDATE_COMMAND "" + SOURCE_DIR ${proj} + BINARY_DIR ${proj}-build + CMAKE_ARGS + --no-warn-unused-cli + -DBUILD_EXAMPLES:BOOL=OFF + -DBUILD_TESTING:BOOL=OFF + -DITK_BUILD_DEFAULT_MODULES:BOOL=ON + -DModule_ITKReview:BOOL=ON + -DBUILD_SHARED_LIBS:BOOL=${BUILD_SHARED_LIBS} + -DCMAKE_SKIP_RPATH:BOOL=ON + -DITK_LEGACY_REMOVE:BOOL=ON + -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> +) + +ExternalProject_Get_Property( ITK install_dir ) +set( ITK_DIR "${install_dir}/lib/cmake/ITK-${ITK_VERSION_MAJOR}.${ITK_VERSION_MINOR}" ) \ No newline at end of file diff --git a/Testing/CMakeLists.txt b/Testing/CMakeLists.txt new file mode 100644 index 00000000..626c54d7 --- /dev/null +++ b/Testing/CMakeLists.txt @@ -0,0 +1,30 @@ +#--------------------------------------------------------------------- +# Setup GoogleTest + +add_subdirectory( GoogleTest ) + +include_directories( + ${gtest_SOURCE_DIR}/include +) + +set( TEST_LIBRARIES + gtest_main +) + +#--------------------------------------------------------------------- +# To add a test to the build system, append it to the list below. +# Any GoogleTests in these files are automatically added to CTest. + +set( ElastixUnitTestSource + elxExampleTest.cxx +) + +#--------------------------------------------------------------------- +# Build test executables + +foreach( ElastixUnitTestFilename ${ElastixUnitTestSource} ) + string( REPLACE ".cxx" "" ElastixUnitTestExe ${ElastixUnitTestFilename} ) + add_executable( ${ElastixUnitTestExe} ${ElastixUnitTestFilename} ) + target_link_libraries( ${ElastixUnitTestExe} ${TEST_LIBRARIES} ) + add_test( ElastixUnitTests ${ElastixUnitTestExe} ) +endforeach() \ No newline at end of file diff --git a/Testing/elxExampleTest.cxx b/Testing/elxExampleTest.cxx new file mode 100644 index 00000000..9c678ed9 --- /dev/null +++ b/Testing/elxExampleTest.cxx @@ -0,0 +1,5 @@ +#include "gtest/gtest.h" + +TEST( ExampleGoogleTest, Assert ) { + ASSERT_TRUE( true ); +} \ No newline at end of file -- GitLab