Skip to content
Snippets Groups Projects
Commit 78236915 authored by Kasper Marstal's avatar Kasper Marstal
Browse files

COMP: Add minimum viable linking error example in Testing/Unit/CMakeLists.txt

parent f9949fc3
No related branches found
No related tags found
No related merge requests found
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
# 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
# GoogleTest needs static linking
include( elxCompilerFlags.cmake )
foreach( CompilerFlag ${CompilerFlags} )
string( REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}" )
endforeach()
......@@ -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 )
# ---------------------------------------------------------------------
......
......@@ -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 )
......
......@@ -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} )
......@@ -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(
......
......@@ -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
......
#include <iostream>
int main()
{
std::cout << "Hello World!" << std::endl;
return 0;
}
\ No newline at end of file
#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;
}
#include <iostream>
#include "gtest/gtest.h"
TEST( HelloWorld, GoogleTest )
{
int a = 1;
}
#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() );
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment