Commit d40ea44c authored by Kasper Marstal's avatar Kasper Marstal
Browse files

COMP: Add GoogleTest to SuperBuild

Model the GoogleTest build after SimpleITK. This fixes previous build
errors.
parent 78236915
......@@ -23,8 +23,6 @@ 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 )
......@@ -69,6 +67,19 @@ else()
include( ExternalBoost )
endif()
# ---------------------------------------------------------------------
# Build GoogleTest
option( USE_SYSTEM_GOOGLETEST "Use a pre-compiled version of GoogleTest. " OFF )
mark_as_advanced(USE_SYSTEM_GOOGLETEST)
if ( ELASTIX_BUILD_TESTING )
if ( USE_SYSTEM_GOOGLETEST )
find_package( GTest REQUIRED )
else()
include(ExternalGoogleTest)
endif()
endif()
# ---------------------------------------------------------------------
# Build Elastix
......
......@@ -12,6 +12,7 @@ ExternalProject_Add( ${proj}
-DELASTIX_BUILD_DASHBOARD:BOOL=${ELASTIX_BUILD_DASHBOARD}
-DITK_DIR:PATH=${ITK_DIR}
-DBOOST_ROOT:PATH=${BOOST_ROOT}
-DGTEST_ROOT:PATH=${GTEST_ROOT}
DEPENDS ${ELASTIX_DEPENDENCIES}
INSTALL_COMMAND ""
)
set( proj GoogleTest )
set( GTEST_TARGET_VERSION 1.7.0 )
set( GTEST_DOWNLOAD_SOURCE_HASH "2d6ec8ccdf5c46b05ba54a9fd1d130d7" )
set( GTEST_binary_dir ${CMAKE_CURRENT_BINARY_DIR}/${proj}-prefix/src/${proj}-build )
set( GTEST_source_dir ${CMAKE_CURRENT_BINARY_DIR}/${proj}-prefix/src/${proj} )
set( GTEST_install_dir ${CMAKE_CURRENT_BINARY_DIR}/${proj} )
set( ${proj}_ARCHIVE_OUTPUT_DIRECTORY "<BINARY_DIR>/lib" )
if( MSVC )
set( ${proj}_ARCHIVE_OUTPUT_DIRECTORY "<BINARY_DIR>/lib/$<CONFIGURATION>" )
endif()
set( MSVS_ARGS )
if(MSVC_VERSION EQUAL 1700)
set(MSVS_ARGS ${MSVS_ARGS} -D CMAKE_CXX_FLAGS=-DGTEST_HAS_TR1_TUPLE=0 ${CMAKE_CXX_FLAGS})
endif()
if( MSVC)
set( MSVS_ARGS ${MSVS_ARGS} -D gtest_force_shared_crt:BOOL=ON )
endif()
ExternalProject_Add(${proj}
URL http://midas3.kitware.com/midas/api/rest?method=midas.bitstream.download&checksum=${GTEST_DOWNLOAD_SOURCE_HASH}&name=swig-${GTEST_TARGET_VERSION}.zip
URL_MD5 ${GTEST_DOWNLOAD_SOURCE_HASH}
INSTALL_DIR ${GTEST_install_dir}
CMAKE_GENERATOR ${gen}
CMAKE_ARGS
--no-warn-unused-cli
${MSVS_ARGS}
-D BUILD_SHARED_LIBS:BOOL=OFF
-D CMAKE_ARCHIVE_OUTPUT_DIRECTORY:PATH=<BINARY_DIR>/lib
INSTALL_COMMAND
${CMAKE_COMMAND} -E copy_directory ${${proj}_ARCHIVE_OUTPUT_DIRECTORY} <INSTALL_DIR>/lib
COMMAND
${CMAKE_COMMAND} -E copy_directory <SOURCE_DIR>/include <INSTALL_DIR>/include
)
set( GTEST_ROOT ${GTEST_install_dir} )
list( APPEND ELASTIX_DEPENDENCIES ${proj} )
......@@ -14,7 +14,6 @@ ExternalProject_Add( ${proj}
-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>
......
......@@ -30,37 +30,20 @@ endforeach()
ExternalData_Add_Target( ElastixData )
# ---------------------------------------------------------------------
# Add GoogleTest
# Find GoogleTest library
find_package( Git )
if( NOT EXISTS "${CMAKE_SOURCE_DIR}/Testing/GoogleTest/.git" AND GIT_EXECUTABLE )
execute_process(
COMMAND ${GIT_EXECUTABLE} submodule update --init
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_QUIET
)
endif()
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()
add_subdirectory( GoogleTest )
include_directories(
${gtest_SOURCE_DIR}/include
)
find_package( GTest REQUIRED )
include_directories( ${GTEST_INCLUDE_DIRS} )
set( TEST_LIBRARIES
gtest_main
${GTEST_BOTH_LIBRARIES}
)
# ---------------------------------------------------------------------
# Build test suite
set( CTEST_CONFIGURATION_TYPE Debug )
# Unit tests
add_subdirectory( Unit )
......
......@@ -3,26 +3,10 @@
# Any GoogleTests in these files are automatically added to CTest and
# the elastix dashboard.
# 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( ElastixUnitTestFilenames
elxExampleUnitTest.cxx
elxBlueprintTest.cxx
)
# ---------------------------------------------------------------------
# Set data directories
......@@ -60,11 +44,9 @@ list( APPEND TEST_LIBRARIES
foreach( ElastixUnitTestFilename ${ElastixUnitTestFilenames} )
# Build tests executables
string( REPLACE ".cxx" "" ElastixUnitTest ${ElastixUnitTestFilename} )
add_executable( "${ElastixUnitTest}" ${ElastixUnitTestFilename} )
add_executable( ${ElastixUnitTest} ${ElastixUnitTestFilename} )
target_link_libraries( "${ElastixUnitTest}" ${ELASTIX_LIBRARIES} ${ITK_LIBRARIES} ${TEST_LIBRARIES} )
ExternalData_Add_Test( ElastixData
NAME ${ElastixUnitTest}
COMMAND ${ElastixUnitTest} "--gtest_output=xml:${CMAKE_BINARY_DIR}/Testing/Unit/${ElastixUnitTest}.xml"
)
# Add GoogleTest to CTest
GTEST_ADD_TESTS( ${ElastixUnitTest} "--gtest_output=xml:${CMAKE_BINARY_DIR}/Testing/Unit/${ElastixUnitTest}.xml" ${ElastixUnitTestFilename} )
endforeach()
#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;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment