Skip to content

Commit

Permalink
Only download GTest in Superbuild
Browse files Browse the repository at this point in the history
Do not build GTest in the Superbuild allow GTest to be built as a
subdirectory of the SimpleITK main project.

Change-Id: I2f984b255a185e1b0404b4c142b839bccac3a34f
  • Loading branch information
blowekamp committed Feb 1, 2017
1 parent d2302c3 commit 7187ab5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 43 deletions.
46 changes: 5 additions & 41 deletions SuperBuild/External_GTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,56 +11,20 @@ set(GTEST_TARGET_VERSION 1.8.0)
set(GTEST_DOWNLOAD_SOURCE_HASH "16877098823401d1bf2ed7891d7dce36")

# follow the standard EP_PREFIX locations
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})

sitkSourceDownload(GTEST_URL "googletest-release-${GTEST_TARGET_VERSION}.tar.gz" ${GTEST_DOWNLOAD_SOURCE_HASH})

file(WRITE "${GTEST_binary_dir}/CMakeCacheInit.txt" "${ep_common_cache}" )

set(${proj}_ARCHIVE_OUTPUT_DIRECTORY "<BINARY_DIR>/lib")
if (CMAKE_GENERATOR MATCHES "Visual Studio")
set(${proj}_ARCHIVE_OUTPUT_DIRECTORY "<BINARY_DIR>/lib/$<CONFIG>")
endif()

set(ep_extra_args)
if(MSVC_VERSION EQUAL 1700)
# Tuples are limited by _VARIADIC_MAX in VS11. The variadic
# templates are not deep enough by default. We are not currently
# using the GTest features which require tuple, so just disable them
# and hope that upstream premanetly addresses the problem, with out
# required more CMake core for compiler issues.
set(ep_extra_args ${ep_extra_args} -D CMAKE_CXX_FLAGS=-DGTEST_HAS_TR1_TUPLE=0 ${CMAKE_CXX_FLAGS})
endif()

if(MSVC)
set(ep_extra_args ${ep_extra_args} -D gtest_force_shared_crt:BOOL=ON)
endif()


ExternalProject_Add(${proj}
URL "${GTEST_URL}"
URL_MD5 ${GTEST_DOWNLOAD_SOURCE_HASH}
INSTALL_DIR ${GTEST_install_dir}
CMAKE_GENERATOR ${gen}
CMAKE_ARGS
--no-warn-unused-cli
-C "${GTEST_binary_dir}/CMakeCacheInit.txt"
${ep_common_args}
${ep_extra_args}
-DBUILD_GMOCK:BOOL=OFF
-DBUILD_GTEST:BOOL=ON
-DBUILD_SHARED_LIBS:BOOL=OFF
-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY:PATH=<BINARY_DIR>/lib
-Dgtest_disable_pthreads:BOOL=ON
INSTALL_COMMAND
${CMAKE_COMMAND} -E copy_directory ${${proj}_ARCHIVE_OUTPUT_DIRECTORY} <INSTALL_DIR>/lib
COMMAND
${CMAKE_COMMAND} -E copy_directory <SOURCE_DIR>/googletest/include <INSTALL_DIR>/include
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
${External_Project_USES_TERMINAL}
)

sitkSourceDownloadDependency(${proj})

set(GTEST_ROOT ${GTEST_install_dir})
set(GTEST_ROOT ${GTEST_source_dir}/googletest)
7 changes: 5 additions & 2 deletions SuperBuild/SuperBuild.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,13 @@ mark_as_advanced(USE_SYSTEM_GTEST)
if ( BUILD_TESTING )
if (USE_SYSTEM_GTEST)
find_package( GTest REQUIRED )
list(APPEND SimpleITK_VARS GTEST_LIBRARIES GTEST_INCLUDE_DIRS GTEST_MAIN_LIBRARIES)
if (GTEST_FOUND AND TARGET "${GTEST_LIBRARIES}" AND DEFINED GTEST_ROOT)
list(APPEND SimpleITK_VARS GTEST_ROOT)
else()
list(APPEND SimpleITK_VARS GTEST_LIBRARIES GTEST_INCLUDE_DIRS GTEST_MAIN_LIBRARIES)
endif()
else()
include(External_GTest)
set( GTEST_ROOT ${GTEST_ROOT} )
list(APPEND SimpleITK_VARS GTEST_ROOT)
list(APPEND ${CMAKE_PROJECT_NAME}_DEPENDENCIES GTest)
endif()
Expand Down

0 comments on commit 7187ab5

Please sign in to comment.