diff --git a/CMake/elxComponent.cmake b/CMake/elxComponent.cmake deleted file mode 100644 index 4fd04dfb6e043411fce6ac20509b97a215444347..0000000000000000000000000000000000000000 --- a/CMake/elxComponent.cmake +++ /dev/null @@ -1,10 +0,0 @@ -macro( ElastixComponent COMPONENT ) - ElastixModuleCheckName( ${COMPONENT} ) - set( ELASTIX_COMPONENT_{$COMPONENT}_DEFINED TRUE ) -endmacro() - -macro( ElastixComponentCheckName COMPONENT ) - if( NOT "${_name}" MATCHES "^[a-zA-Z][a-zA-Z0-9]*$" ) - message( FATAL_ERROR "Invalid component name: ${COMPONENT}" ) - endif() -endmacro() \ No newline at end of file diff --git a/CMake/elxWinConfig.cmake b/CMake/elxWinConfig.cmake index 6f83da4f2ce11f43a2e5a2e9e965a94b91743e76..e0b1b38c129f9632c7c919475551c72a54c8bdf7 100644 --- a/CMake/elxWinConfig.cmake +++ b/CMake/elxWinConfig.cmake @@ -1,25 +1,18 @@ # Visual Studio complains if paths are too long +string( LENGTH "${CMAKE_CURRENT_SOURCE_DIR}" n ) +if( n GREATER 50 ) +message( + FATAL_ERROR + "Source code directory path length is too long for MSVC (${n} > 50)." + "Please move the source code directory to a directory with a shorter path." + ) +endif() -if( MSVC ) - string( LENGTH "${CMAKE_CURRENT_SOURCE_DIR}" n ) - if( n GREATER 50 ) - message( - FATAL_ERROR - "Source code directory path length is too long for MSVC (${n} > 50)." - "Please move the source code directory to a directory with a shorter path." - ) - endif() - - string( LENGTH "${CMAKE_CURRENT_BINARY_DIR}" n ) - if( n GREATER 50 ) - message( - FATAL_ERROR - "Build directory path length is too long for MSVC (${n} > 50)." - "Please move the build directory to a directory with a shorter path." - ) - endif() - - 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" ) +string( LENGTH "${CMAKE_CURRENT_BINARY_DIR}" n ) +if( n GREATER 50 ) +message( + FATAL_ERROR + "Build directory path length is too long for MSVC (${n} > 50)." + "Please move the build directory to a directory with a shorter path." + ) endif() \ No newline at end of file diff --git a/CMake/elxWinConfigGoogleTest.cmake b/CMake/elxWinConfigGoogleTest.cmake deleted file mode 100644 index 75a5ac06f7db5c2020b3c4e11e85b572e07abf3f..0000000000000000000000000000000000000000 --- a/CMake/elxWinConfigGoogleTest.cmake +++ /dev/null @@ -1,6 +0,0 @@ -# GoogleTest needs static linking - -include( elxCompilerFlags.cmake ) -foreach( CompilerFlag ${CompilerFlags} ) - string( REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}" ) -endforeach() diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d48eb59510e0d5cd86f11ad52e142e37a9b9612..81e9fb94c800d4b0debfb979b96eb16563deefc9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required( VERSION 2.8 ) # Explicitly add INCREMENTAL linking option to command lines. # http://www.cmake.org/pipermail/cmake/2010-February/035174.html -set( MSVC_INCREMENTAL_DEFAULT ON ) +#set( MSVC_INCREMENTAL_DEFAULT ON ) # --------------------------------------------------------------------- project( Elastix ) @@ -13,13 +13,10 @@ set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ) # Include SuperElastix CMake scripts -set( CMAKE_MODULE_PATH - "${CMAKE_CURRENT_SOURCE_DIR}/CMake" - ${CMAKE_MODULE_PATH} -) +list( APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake" ) -if( ${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC" ) - include( elxWinConfig.cmake ) +if( ${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC ) + include( elxWinConfig ) endif() # --------------------------------------------------------------------- @@ -31,13 +28,13 @@ include( "${CMAKE_CURRENT_SOURCE_DIR}/CMake/elxITKRequiredModules.cmake" ) # --------------------------------------------------------------------- # Boost Graph Library -find_package( Boost REQUIRED graph ) +find_package( Boost ) include_directories( ${Boost_INCLUDE_DIRS} ) # --------------------------------------------------------------------- # Build Elastix # For now we just enable all modules -include( "${CMAKE_CURRENT_SOURCE_DIR}/CMake/elxModules.cmake" ) +include( elxModules ) elxmodule_enable( elxModuleCore ) # --------------------------------------------------------------------- diff --git a/SuperBuild/CMakeLists.txt b/SuperBuild/CMakeLists.txt index b9f5378324b24ff57e6383863baebb262c30ae98..0043bd71878face198e56011cd1e03055e645785 100644 --- a/SuperBuild/CMakeLists.txt +++ b/SuperBuild/CMakeLists.txt @@ -23,6 +23,8 @@ if( NOT DEFINED CMAKE_BUILD_TYPE ) set( CMAKE_BUILD_TYPE "Release" ) endif() +option( BUILD_SHARED_LIBS OFF ) + # 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 ) diff --git a/SuperBuild/ExternalBoost.cmake b/SuperBuild/ExternalBoost.cmake index 4f27a44f0d312edb6258ff33ebd677e466c19a41..1047e94c5ae73d1dd77b115bf81ecfddc858ffec 100644 --- a/SuperBuild/ExternalBoost.cmake +++ b/SuperBuild/ExternalBoost.cmake @@ -27,11 +27,10 @@ ExternalProject_Add( BOOST URL_MD5 ${BOOST_MD5} UPDATE_COMMAND "" CONFIGURE_COMMAND ${BOOST_CONFIGURE_COMMAND} - --prefix=${BOOST_BUILD_DIR}/lib BUILD_COMMAND "" INSTALL_COMMAND "" ) -set( BOOST_ROOT ${BOOST_BUILD_DIR} ) +set( BOOST_ROOT "${CMAKE_INSTALL_PREFIX}/${proj}-prefix/src/BOOST" ) list( APPEND ELASTIX_DEPENDENCIES ${proj} ) diff --git a/Testing/CMakeLists.txt b/Testing/CMakeLists.txt index 925c9375c67da019bf48303e058074f4a111f2b6..3aea1e205da105094a716632448d2ce8d9070a34 100644 --- a/Testing/CMakeLists.txt +++ b/Testing/CMakeLists.txt @@ -48,10 +48,6 @@ if( NOT EXISTS ${CMAKE_SOURCE_DIR}/Testing/GoogleTest/.git ) ) endif() -if( ${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC" ) - include( elxWinConfigGoogleTest.cmake ) -endif() - add_subdirectory( GoogleTest ) include_directories( diff --git a/Testing/Unit/CMakeLists.txt b/Testing/Unit/CMakeLists.txt index 1ed2189daf32f2fab2f429e3bdb080dd276c3e77..720b58c5a88b14488c3e9017f0a1fa09ad10a9ee 100644 --- a/Testing/Unit/CMakeLists.txt +++ b/Testing/Unit/CMakeLists.txt @@ -3,11 +3,26 @@ # Any GoogleTests in these files are automatically added to CTest and # the elastix dashboard. -set( ElastixUnitTestFilenames - elxExampleUnitTest.cxx - elxBluePrintTest.cxx - itkRegistration.cxx -) +# Not compiling elastix tests while we debug windows build. See minimum viable examples below +# set( ElastixUnitTestFilenames +# elxExampleUnitTest.cxx +# elxBlueprintTest.cxx +# ) + +# Pass +add_executable( HelloWorld HelloWorld.cxx) + +# Pass +add_executable( HelloWorldBlueprint HelloWorldBlueprint.cxx ) +target_link_libraries( HelloWorldBlueprint ${ELASTIX_LIBRARIES} ${ITK_LIBRARIES} ) + +# Fail. It seems GoogleTest is compiled statically (like it should), while the executable is compiled dynamically (it should also be static) Why? BUILD_SHARED_LIBS is set to OFF! + +# And why is the static linker option not recongnized (VS2013)? +set(CMAKE_EXE_LINKER_FLAGS /MTd ) + +add_executable( HelloWorldGoogleTest HelloWorldGoogleTest.cxx ) +target_link_libraries( HelloWorldGoogleTest ${TEST_LIBRARIES} ) # --------------------------------------------------------------------- # Set data directories diff --git a/Testing/Unit/HelloWorld.cxx b/Testing/Unit/HelloWorld.cxx new file mode 100644 index 0000000000000000000000000000000000000000..9d9089828565d92cda9a58cad587a6d75c3b5179 --- /dev/null +++ b/Testing/Unit/HelloWorld.cxx @@ -0,0 +1,7 @@ +#include <iostream> + +int main() +{ + std::cout << "Hello World!" << std::endl; + return 0; +} \ No newline at end of file diff --git a/Testing/Unit/HelloWorldBlueprint.cxx b/Testing/Unit/HelloWorldBlueprint.cxx new file mode 100644 index 0000000000000000000000000000000000000000..1644eb241bd87e021567c941d1fce80cb8c5f298 --- /dev/null +++ b/Testing/Unit/HelloWorldBlueprint.cxx @@ -0,0 +1,12 @@ +#include <iostream> +#include "elxBlueprint.h" + +int main() +{ + elx::Blueprint::Pointer blueprint = elx::Blueprint::New(); + elx::Blueprint::ComponentIndexType index0 = blueprint->AddComponent(); + + std::cout << "Hello World!" << std::endl; + std::cout << "Loaded blueprint!" << std::endl; + return 0; +} diff --git a/Testing/Unit/HelloWorldGoogleTest.cxx b/Testing/Unit/HelloWorldGoogleTest.cxx new file mode 100644 index 0000000000000000000000000000000000000000..7dcd6d3fd19ec0e250df10d2f066e2a80c23b225 --- /dev/null +++ b/Testing/Unit/HelloWorldGoogleTest.cxx @@ -0,0 +1,7 @@ +#include <iostream> +#include "gtest/gtest.h" + +TEST( HelloWorld, GoogleTest ) +{ + int a = 1; +} diff --git a/Testing/Unit/itkRegistration.cxx b/Testing/Unit/itkRegistration.cxx deleted file mode 100644 index 3988f3089daaff475b4d1a4b359286d75eb6995d..0000000000000000000000000000000000000000 --- a/Testing/Unit/itkRegistration.cxx +++ /dev/null @@ -1,86 +0,0 @@ -#include "itkImage.h" -#include "itkImageFileReader.h" -#include "elxDataManager.h" -#include "gtest/gtest.h" - -#include "itkImageRegistrationMethod.h" -#include "itkTranslationTransform.h" -#include "itkMeanSquaresImageToImageMetric.h" -#include "itkLinearInterpolateImageFunction.h" -#include "itkRegularStepGradientDescentOptimizer.h" -#include "itkImage.h" -#include "itkImageFileReader.h" -#include "itkResampleImageFilter.h" -#include "itkCastImageFilter.h" - -class itkRegistration : public ::testing::Test { -public: - virtual void SetUp() - { - // TODO: Loading images here result in segfault - } - - typedef itk::Image< unsigned short, 2 > ImageType; - - typedef itk::ImageFileReader< ImageType > FixedImageReaderType; - typedef itk::ImageFileReader< ImageType > MovingImageReaderType; - - FixedImageReaderType::Pointer fixedImageReader; - MovingImageReaderType::Pointer movingImageReader; - -}; - -TEST_F( itkRegistration, ImageRegistration3 ) -{ - - typedef itk::TranslationTransform< double, ImageType::ImageDimension > TransformType; - typedef itk::RegularStepGradientDescentOptimizer OptimizerType; - typedef itk::LinearInterpolateImageFunction< ImageType, double > InterpolatorType; - typedef itk::ImageRegistrationMethod< ImageType, ImageType > RegistrationType; - - - typedef itk::MeanSquaresImageToImageMetric< ImageType, ImageType > MetricType; - - TransformType::Pointer transform = TransformType::New(); - OptimizerType::Pointer optimizer = OptimizerType::New(); - InterpolatorType::Pointer interpolator = InterpolatorType::New(); - RegistrationType::Pointer registration = RegistrationType::New(); - - MetricType::Pointer metric = MetricType::New(); - registration->SetMetric( metric ); - registration->SetOptimizer( optimizer ); - registration->SetTransform( transform ); - registration->SetInterpolator( interpolator ); - - FixedImageReaderType::Pointer fixedImageReader = FixedImageReaderType::New(); - MovingImageReaderType::Pointer movingImageReader = MovingImageReaderType::New(); - - DataManager::Pointer dataManager = DataManager::New(); - - fixedImageReader->SetFileName( dataManager->GetInputFullPath( "BrainProtonDensitySlice.png" ) ); - movingImageReader->SetFileName( dataManager->GetInputFullPath( "BrainProtonDensitySliceR10X13Y17.png" ) ); - - registration->SetFixedImage( fixedImageReader->GetOutput() ); - registration->SetMovingImage( movingImageReader->GetOutput() ); - - fixedImageReader->Update(); // This is needed to make the BufferedRegion valid. - registration->SetFixedImageRegion( fixedImageReader->GetOutput()->GetBufferedRegion() ); - - typedef RegistrationType::ParametersType ParametersType; - ParametersType initialParameters( transform->GetNumberOfParameters() ); - - initialParameters[0] = 0.0; // Initial offset in mm along X - initialParameters[1] = 0.0; // Initial offset in mm along Y - - registration->SetInitialTransformParameters( initialParameters ); - - optimizer->SetMaximumStepLength( 4.00 ); - optimizer->SetMinimumStepLength( 0.01 ); - optimizer->SetNumberOfIterations( 200 ); - - optimizer->MaximizeOff(); - - EXPECT_NO_THROW( registration->Update() ); - RecordProperty( "MetricValue", optimizer->GetValue() ); -} -