diff --git a/CMake/elxCompilerFlags.cmake b/CMake/elxCompilerFlags.cmake new file mode 100644 index 0000000000000000000000000000000000000000..171a36b1bdafb1f2d1b939e3708e1203f8642dcf --- /dev/null +++ b/CMake/elxCompilerFlags.cmake @@ -0,0 +1,12 @@ +set( CompilerFlags + CMAKE_CXX_FLAGS + CMAKE_CXX_FLAGS_DEBUG + CMAKE_CXX_FLAGS_MINSIZEREL + CMAKE_CXX_FLAGS_RELEASE + CMAKE_CXX_FLAGS_RELWITHDEBINFO + CMAKE_C_FLAGS + CMAKE_C_FLAGS_DEBUG + CMAKE_C_FLAGS_MINSIZEREL + CMAKE_C_FLAGS_RELEASE + CMAKE_C_FLAGS_RELWITHDEBINFO +) diff --git a/CMake/elxGoogleTestWinConfig.cmake b/CMake/elxGoogleTestWinConfig.cmake new file mode 100644 index 0000000000000000000000000000000000000000..e72a8726f26a278eca4fcdee0471de494b67035d --- /dev/null +++ b/CMake/elxGoogleTestWinConfig.cmake @@ -0,0 +1,6 @@ +include( ${CMAKE_SOURCE_DIR}/CMake/elxCompilerFlags.cmake ) + +foreach( CompilerFlag ${CompilerFlags} ) + # GoogleTest needs static linking + string( REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}" ) +endforeach() diff --git a/CMake/elxRequiredITKModules.cmake b/CMake/elxRequiredITKModules.cmake index 284dddb8d676633360c83749f49e2a900aec621d..c9cce4a03c670dab607b646114c1f44a241e44d8 100644 --- a/CMake/elxRequiredITKModules.cmake +++ b/CMake/elxRequiredITKModules.cmake @@ -6,4 +6,4 @@ 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 +endforeach() diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d4f8b6546ce08c312a6ef006929505166961abb..c825fcac558f545969ba1a06204f7676d2a5503c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,20 +13,20 @@ 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() +# Do not build tests by default since this requires GoogleTest submodule +# to be initialized. This saves users that just clone and build from +# seeing FATAL_ERRORs out of the box. +option( ELASTIX_BUILD_TESTING "Enable building tests." OFF ) +if( ELASTIX_BUILD_TESTING ) enable_testing() - - mark_as_advanced( BUILD_CTESTS ) - option( BUILD_CTESTS "Enable CTests." ON ) - if( BUILD_CTESTS ) + add_subdirectory( Testing ) + + mark_as_advanced( ELASTIX_BUILD_CTESTS ) + option( ELASTIX_BUILD_CTESTS "Enable CTests." ON ) + if( ELASTIX_BUILD_CTESTS ) include( CTest ) endif() - - add_subdirectory( Testing ) endif() #--------------------------------------------------------------------- @@ -35,9 +35,9 @@ endif() #--------------------------------------------------------------------- # Build Documentation -mark_as_advanced( BUILD_DOXYGEN ) +mark_as_advanced( ELASTIX_BUILD_DOXYGEN ) option( BUILD_DOXYGEN "Enable building Doxygen documentation." OFF ) -mark_as_advanced( BUILD_READTHEDOCS OFF ) +mark_as_advanced( ELASTIX_BUILD_READTHEDOCS ) option( BUILD_READTHEDOCS "Enable building readthedocs.org documentation." OFF ) diff --git a/SuperBuild/CMakeLists.txt b/SuperBuild/CMakeLists.txt index dc7142e3243f54f794725489d28dcb0e803e717e..c719db98292235a93751280bf619b34d4e95b56a 100644 --- a/SuperBuild/CMakeLists.txt +++ b/SuperBuild/CMakeLists.txt @@ -1,15 +1,12 @@ cmake_minimum_required( VERSION 2.8 ) #--------------------------------------------------------------------- -# Prerequisites +project( elastixSuperBuild ) 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 @@ -28,7 +25,9 @@ endif() # 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 +# Do not build tests by default since this requires GoogleTest submodule +# to be initialized. This saves users that just clone and build from +# seeing FATAL_ERRORs out of the box. option( ELASTIX_BUILD_TESTING "Enable building tests." OFF ) if( ELASTIX_BUILD_TESTING ) diff --git a/SuperBuild/Elastix.cmake b/SuperBuild/Elastix.cmake index 5cc4b57baf66fdf465b0d7f9495b115e9142818b..130f5595e11ee400642750827c814c3604e48761 100644 --- a/SuperBuild/Elastix.cmake +++ b/SuperBuild/Elastix.cmake @@ -7,8 +7,8 @@ ExternalProject_Add( ${proj} INSTALL_DIR ${CMAKE_INSTALL_PREFIX} CMAKE_ARGS --no-warn-unused-cli - -DBUILD_TESTING:BOOL=${ELASTIX_BUILD_TESTING} - -DBUILD_CTESTS:BOOL=${ELASTIX_BUILD_CTESTS} + -DELASTIX_BUILD_TESTING:BOOL=${ELASTIX_BUILD_TESTING} + -DELASTIX_BUILD_CTESTS:BOOL=${ELASTIX_BUILD_CTESTS} -DITK_DIR:PATH=${ITK_DIR} DEPENDS ${ELASTIX_DEPENDENCIES} INSTALL_COMMAND "" diff --git a/Testing/CMakeLists.txt b/Testing/CMakeLists.txt index 626c54d7f6649c77a8252e397a734f21344fc7b2..83be7813cb1bd92515e49e9eeaffaf637b13dc4e 100644 --- a/Testing/CMakeLists.txt +++ b/Testing/CMakeLists.txt @@ -1,6 +1,15 @@ #--------------------------------------------------------------------- # Setup GoogleTest +if( NOT EXISTS "${CMAKE_SOURCE_DIR}/Testing/GoogleTest/.git" ) + message( FATAL_ERROR "Could not find GoogleTest submodule. Please run +git submodule update --init in the source directory to compile tests." ) +endif() + +if( ${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC") + include( ${CMAKE_SOURCE_DIR}/CMake/elxGoogleTestWinConfig.cmake ) +endif() + add_subdirectory( GoogleTest ) include_directories( @@ -25,6 +34,6 @@ set( ElastixUnitTestSource foreach( ElastixUnitTestFilename ${ElastixUnitTestSource} ) string( REPLACE ".cxx" "" ElastixUnitTestExe ${ElastixUnitTestFilename} ) add_executable( ${ElastixUnitTestExe} ${ElastixUnitTestFilename} ) - target_link_libraries( ${ElastixUnitTestExe} ${TEST_LIBRARIES} ) + target_link_libraries( ${ElastixUnitTestExe} ${ELASTIX_LIBRARIES} ${TEST_LIBRARIES} ) add_test( ElastixUnitTests ${ElastixUnitTestExe} ) endforeach() \ No newline at end of file