From 7187ab57c77856dbf263a309f432bbd571c10b39 Mon Sep 17 00:00:00 2001 From: Bradley Lowekamp Date: Wed, 1 Feb 2017 11:32:57 -0500 Subject: [PATCH] Only download GTest in Superbuild Do not build GTest in the Superbuild allow GTest to be built as a subdirectory of the SimpleITK main project. Change-Id: I2f984b255a185e1b0404b4c142b839bccac3a34f --- SuperBuild/External_GTest.cmake | 46 ++++----------------------------- SuperBuild/SuperBuild.cmake | 7 +++-- 2 files changed, 10 insertions(+), 43 deletions(-) diff --git a/SuperBuild/External_GTest.cmake b/SuperBuild/External_GTest.cmake index c708f2709..5fd363cc3 100644 --- a/SuperBuild/External_GTest.cmake +++ b/SuperBuild/External_GTest.cmake @@ -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 "/lib") -if (CMAKE_GENERATOR MATCHES "Visual Studio") - set(${proj}_ARCHIVE_OUTPUT_DIRECTORY "/lib/$") -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=/lib - -Dgtest_disable_pthreads:BOOL=ON - INSTALL_COMMAND - ${CMAKE_COMMAND} -E copy_directory ${${proj}_ARCHIVE_OUTPUT_DIRECTORY} /lib - COMMAND - ${CMAKE_COMMAND} -E copy_directory /googletest/include /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) diff --git a/SuperBuild/SuperBuild.cmake b/SuperBuild/SuperBuild.cmake index 8fb0cfa90..3866ebdac 100644 --- a/SuperBuild/SuperBuild.cmake +++ b/SuperBuild/SuperBuild.cmake @@ -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()