From d1fba71f42153bf4b3e7b54c06fb840cf32dd9fc Mon Sep 17 00:00:00 2001
From: Lars Bilke <lars.bilke@ufz.de>
Date: Tue, 23 Jun 2020 09:23:15 +0200
Subject: [PATCH] [CMake] Do not build vtkdiff or gtest when BUILD_TESTING=OFF

---
 CMakeLists.txt                     | 2 +-
 ThirdParty/CMakeLists.txt          | 8 +++++---
 scripts/cmake/SubmoduleSetup.cmake | 4 +++-
 scripts/cmake/test/OgsTest.cmake   | 2 +-
 4 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 70a16867236..9e1ce04bc37 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -272,7 +272,7 @@ include_directories(
     ${CMAKE_CURRENT_SOURCE_DIR}/ThirdParty/spdlog/include)
 
 # vtkdiff
-if(EXISTS ${PROJECT_SOURCE_DIR}/ThirdParty/vtkdiff/CMakeLists.txt)
+if(EXISTS ${PROJECT_SOURCE_DIR}/ThirdParty/vtkdiff/CMakeLists.txt AND BUILD_TESTING)
     add_subdirectory(ThirdParty/vtkdiff)
     install(PROGRAMS $<TARGET_FILE:vtkdiff> DESTINATION bin COMPONENT ogs_extras)
 endif()
diff --git a/ThirdParty/CMakeLists.txt b/ThirdParty/CMakeLists.txt
index 65f1dba86e9..9760f5c9d71 100644
--- a/ThirdParty/CMakeLists.txt
+++ b/ThirdParty/CMakeLists.txt
@@ -1,9 +1,11 @@
 add_subdirectory(spdlog)
 set(DISABLE_WARNINGS_TARGETS spdlog)
 
-set(gtest_force_shared_crt ON CACHE INTERNAL "") # Use dynamic MSVC runtime
-set(INSTALL_GTEST OFF CACHE INTERNAL "")
-add_subdirectory(googletest)
+if(BUILD_TESTING)
+    set(gtest_force_shared_crt ON CACHE INTERNAL "") # Use dynamic MSVC runtime
+    set(INSTALL_GTEST OFF CACHE INTERNAL "")
+    add_subdirectory(googletest)
+endif()
 
 # This is a workaround for Travis builds.
 option(OGS_USE_OPTIONAL_SUBMODULES "Option for enabling optional submodules" OFF)
diff --git a/scripts/cmake/SubmoduleSetup.cmake b/scripts/cmake/SubmoduleSetup.cmake
index 6100c8c3905..7fa03a91e16 100644
--- a/scripts/cmake/SubmoduleSetup.cmake
+++ b/scripts/cmake/SubmoduleSetup.cmake
@@ -18,9 +18,11 @@ set(REQUIRED_SUBMODULES
     ThirdParty/spdlog
     ThirdParty/tclap
     ThirdParty/tetgen
-    ThirdParty/vtkdiff
     ${OGS_ADDITIONAL_SUBMODULES_TO_CHECKOUT}
 )
+if(BUILD_TESTING)
+    list(APPEND REQUIRED_SUBMODULES ThirdParty/vtkdiff)
+endif()
 if(OGS_BUILD_UTILS)
     # Required by the partmesh tool, which is build with utils only.
     list(APPEND REQUIRED_SUBMODULES ThirdParty/metis)
diff --git a/scripts/cmake/test/OgsTest.cmake b/scripts/cmake/test/OgsTest.cmake
index f4e166ca3bf..b05609b5d9b 100644
--- a/scripts/cmake/test/OgsTest.cmake
+++ b/scripts/cmake/test/OgsTest.cmake
@@ -1,5 +1,5 @@
 function (OgsTest)
-    if(NOT OGS_BUILD_CLI)
+    if(NOT OGS_BUILD_CLI OR NOT BUILD_TESTING)
         return()
     endif()
     set(options LARGE)
-- 
GitLab