From 5a12e40e581c677ebc29059700048ab790f4cd31 Mon Sep 17 00:00:00 2001
From: Lars Bilke <lars.bilke@ufz.de>
Date: Mon, 24 Apr 2017 14:34:59 +0200
Subject: [PATCH] [CMake] Added option OGS_USE_PCH.

Disabled PCH on Visual Studio 2015.
---
 Applications/ApplicationsLib/CMakeLists.txt                | 4 +++-
 Applications/CLI/CMakeLists.txt                            | 4 +++-
 Applications/DataExplorer/Base/CMakeLists.txt              | 4 +++-
 Applications/DataExplorer/DataExplorer.cmake               | 4 +++-
 Applications/DataExplorer/DataView/CMakeLists.txt          | 4 +++-
 .../DataExplorer/DataView/DiagramView/CMakeLists.txt       | 4 +++-
 .../DataExplorer/DataView/StratView/CMakeLists.txt         | 4 +++-
 Applications/DataExplorer/VtkAct/CMakeLists.txt            | 4 +++-
 Applications/DataExplorer/VtkVis/CMakeLists.txt            | 4 +++-
 Applications/DataHolderLib/CMakeLists.txt                  | 4 +++-
 Applications/FileIO/CMakeLists.txt                         | 4 +++-
 Applications/InSituLib/CMakeLists.txt                      | 4 +++-
 Applications/Utils/OGSFileConverter/CMakeLists.txt         | 4 +++-
 BaseLib/CMakeLists.txt                                     | 4 +++-
 CMakeLists.txt                                             | 1 +
 GeoLib/CMakeLists.txt                                      | 4 +++-
 MaterialLib/CMakeLists.txt                                 | 4 +++-
 MathLib/CMakeLists.txt                                     | 4 +++-
 MeshGeoToolsLib/CMakeLists.txt                             | 4 +++-
 MeshLib/CMakeLists.txt                                     | 4 +++-
 NumLib/CMakeLists.txt                                      | 4 +++-
 ProcessLib/CMakeLists.txt                                  | 4 +++-
 Tests/CMakeLists.txt                                       | 4 +++-
 scripts/cmake/CompilerSetup.cmake                          | 7 ++++++-
 24 files changed, 73 insertions(+), 23 deletions(-)

diff --git a/Applications/ApplicationsLib/CMakeLists.txt b/Applications/ApplicationsLib/CMakeLists.txt
index ed08c4a7c77..2df4fb662f5 100644
--- a/Applications/ApplicationsLib/CMakeLists.txt
+++ b/Applications/ApplicationsLib/CMakeLists.txt
@@ -20,4 +20,6 @@ if(TARGET Boost)
     add_dependencies(ApplicationsLib Boost)
 endif()
 
-cotire(ApplicationsLib)
+if(OGS_USE_PCH)
+    cotire(ApplicationsLib)
+endif()
diff --git a/Applications/CLI/CMakeLists.txt b/Applications/CLI/CMakeLists.txt
index 63b79824790..442531766f0 100644
--- a/Applications/CLI/CMakeLists.txt
+++ b/Applications/CLI/CMakeLists.txt
@@ -18,7 +18,9 @@ if(OGS_INSITU)
     target_link_libraries(ogs InSituLib)
 endif()
 
-cotire(ogs)
+if(OGS_USE_PCH)
+    cotire(ogs)
+endif()
 
 ####################
 ### Tests ##########
diff --git a/Applications/DataExplorer/Base/CMakeLists.txt b/Applications/DataExplorer/Base/CMakeLists.txt
index f2f63bee060..2e251d09b10 100644
--- a/Applications/DataExplorer/Base/CMakeLists.txt
+++ b/Applications/DataExplorer/Base/CMakeLists.txt
@@ -42,4 +42,6 @@ target_link_libraries(QtBase
 
 set_property(TARGET QtBase PROPERTY FOLDER "DataExplorer")
 
-cotire(QtBase)
+if(OGS_USE_PCH)
+    cotire(QtBase)
+endif()
diff --git a/Applications/DataExplorer/DataExplorer.cmake b/Applications/DataExplorer/DataExplorer.cmake
index b5bdbe245af..0d12eb31d22 100644
--- a/Applications/DataExplorer/DataExplorer.cmake
+++ b/Applications/DataExplorer/DataExplorer.cmake
@@ -112,7 +112,9 @@ ADD_VTK_DEPENDENCY(DataExplorer)
 
 set_property(TARGET DataExplorer PROPERTY FOLDER "DataExplorer")
 
-cotire(DataExplorer)
+if(OGS_USE_PCH)
+    cotire(DataExplorer)
+endif()
 
 ####################
 ### Installation ###
diff --git a/Applications/DataExplorer/DataView/CMakeLists.txt b/Applications/DataExplorer/DataView/CMakeLists.txt
index 8846d291b77..66b214180b1 100644
--- a/Applications/DataExplorer/DataView/CMakeLists.txt
+++ b/Applications/DataExplorer/DataView/CMakeLists.txt
@@ -151,4 +151,6 @@ endif () # GEOTIFF_FOUND
 
 set_property(TARGET QtDataView PROPERTY FOLDER "DataExplorer")
 
-cotire(QtDataView)
+if(OGS_USE_PCH)
+    cotire(QtDataView)
+endif()
diff --git a/Applications/DataExplorer/DataView/DiagramView/CMakeLists.txt b/Applications/DataExplorer/DataView/DiagramView/CMakeLists.txt
index e133e60103b..9157b88ec85 100644
--- a/Applications/DataExplorer/DataView/DiagramView/CMakeLists.txt
+++ b/Applications/DataExplorer/DataView/DiagramView/CMakeLists.txt
@@ -48,4 +48,6 @@ target_link_libraries(QtDiagramView
 
 set_property(TARGET QtDiagramView PROPERTY FOLDER "DataExplorer")
 
-cotire(QtDiagramView)
+if(OGS_USE_PCH)
+    cotire(QtDiagramView)
+endif()
diff --git a/Applications/DataExplorer/DataView/StratView/CMakeLists.txt b/Applications/DataExplorer/DataView/StratView/CMakeLists.txt
index e5714cc497a..e93feced53f 100644
--- a/Applications/DataExplorer/DataView/StratView/CMakeLists.txt
+++ b/Applications/DataExplorer/DataView/StratView/CMakeLists.txt
@@ -36,4 +36,6 @@ target_link_libraries(QtStratView Qt5::Gui QtBase)
 
 set_property(TARGET QtStratView PROPERTY FOLDER "DataExplorer")
 
-cotire(QtStratView)
+if(OGS_USE_PCH)
+    cotire(QtStratView)
+endif()
diff --git a/Applications/DataExplorer/VtkAct/CMakeLists.txt b/Applications/DataExplorer/VtkAct/CMakeLists.txt
index 06f0186f5fd..8b7b655e4a2 100644
--- a/Applications/DataExplorer/VtkAct/CMakeLists.txt
+++ b/Applications/DataExplorer/VtkAct/CMakeLists.txt
@@ -32,4 +32,6 @@ target_link_libraries( VtkAct
 
 set_property(TARGET VtkAct PROPERTY FOLDER "DataExplorer")
 
-cotire(VtkAct)
+if(OGS_USE_PCH)
+    cotire(VtkAct)
+endif()
diff --git a/Applications/DataExplorer/VtkVis/CMakeLists.txt b/Applications/DataExplorer/VtkVis/CMakeLists.txt
index 218170bc45d..d870cfbb9b6 100644
--- a/Applications/DataExplorer/VtkVis/CMakeLists.txt
+++ b/Applications/DataExplorer/VtkVis/CMakeLists.txt
@@ -135,4 +135,6 @@ endif() # GEOTIFF_FOUND
 target_link_libraries(VtkVis Qt5::Gui QtDataView VtkAct)
 set_property(TARGET VtkVis PROPERTY FOLDER "DataExplorer")
 
-cotire(VtkVis)
+if(OGS_USE_PCH)
+    cotire(VtkVis)
+endif()
diff --git a/Applications/DataHolderLib/CMakeLists.txt b/Applications/DataHolderLib/CMakeLists.txt
index 2d42fd4aa7c..cfcd824d098 100644
--- a/Applications/DataHolderLib/CMakeLists.txt
+++ b/Applications/DataHolderLib/CMakeLists.txt
@@ -10,4 +10,6 @@ target_link_libraries(DataHolderLib
     logog
 )
 
-cotire(DataHolderLib)
+if(OGS_USE_PCH)
+    cotire(DataHolderLib)
+endif()
diff --git a/Applications/FileIO/CMakeLists.txt b/Applications/FileIO/CMakeLists.txt
index 826f2e7c80b..fffd2690063 100644
--- a/Applications/FileIO/CMakeLists.txt
+++ b/Applications/FileIO/CMakeLists.txt
@@ -35,7 +35,9 @@ if(TARGET Boost)
     add_dependencies(ApplicationsFileIO Boost)
 endif()
 
-cotire(ApplicationsFileIO)
+if(OGS_USE_PCH)
+    cotire(ApplicationsFileIO)
+endif()
 
 include(${PROJECT_SOURCE_DIR}/scripts/cmake/packaging/InstallXmlSchemaFiles.cmake)
 InstallXmlSchemaFiles("XmlIO/*.xsd")
diff --git a/Applications/InSituLib/CMakeLists.txt b/Applications/InSituLib/CMakeLists.txt
index a25329f9e15..38b9b025b7f 100644
--- a/Applications/InSituLib/CMakeLists.txt
+++ b/Applications/InSituLib/CMakeLists.txt
@@ -3,4 +3,6 @@ GET_SOURCE_FILES(SOURCES)
 
 # Library
 add_library(InSituLib ${SOURCES})
-cotire(InSituLib)
+if(OGS_USE_PCH)
+    cotire(InSituLib)
+endif()
diff --git a/Applications/Utils/OGSFileConverter/CMakeLists.txt b/Applications/Utils/OGSFileConverter/CMakeLists.txt
index 94bc5807452..0302190c9f1 100644
--- a/Applications/Utils/OGSFileConverter/CMakeLists.txt
+++ b/Applications/Utils/OGSFileConverter/CMakeLists.txt
@@ -58,7 +58,9 @@ set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
 
 set_property(TARGET OGSFileConverter PROPERTY FOLDER "Utilities")
 
-cotire(OGSFileConverter)
+if(OGS_USE_PCH)
+    cotire(OGSFileConverter)
+endif()
 
 ####################
 ### Installation ###
diff --git a/BaseLib/CMakeLists.txt b/BaseLib/CMakeLists.txt
index a5598bbd064..69e46a1af3c 100644
--- a/BaseLib/CMakeLists.txt
+++ b/BaseLib/CMakeLists.txt
@@ -36,4 +36,6 @@ if(TARGET Boost)
     add_dependencies(BaseLib Boost)
 endif()
 
-cotire(BaseLib)
+if(OGS_USE_PCH)
+    cotire(BaseLib)
+endif()
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5faa2f647ae..637877a60e8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -26,6 +26,7 @@ set(CMAKE_LIBRARY_SEARCH_PATH "" CACHE PATH
 set(OGS_CPU_ARCHITECTURE "native" CACHE STRING "Processor architecture, defaults to native (*nix) / blend (MSVC).")
 option(OGS_ENABLE_AVX2 "Enable the use of AVX2 instructions" OFF)
 option(OGS_BUILD_TESTS "Should the test executables be built?" ON)
+option(OGS_USE_PCH "Should pre-compiled headers be used?" ON)
 
 ### CMake includes ###
 include(scripts/cmake/ConanSetup.cmake)
diff --git a/GeoLib/CMakeLists.txt b/GeoLib/CMakeLists.txt
index e6b162512d0..747e074dca5 100644
--- a/GeoLib/CMakeLists.txt
+++ b/GeoLib/CMakeLists.txt
@@ -31,7 +31,9 @@ if(TARGET Boost)
     add_dependencies(GeoLib Boost)
 endif()
 
-cotire(GeoLib)
+if(OGS_USE_PCH)
+    cotire(GeoLib)
+endif()
 
 include(${PROJECT_SOURCE_DIR}/scripts/cmake/packaging/InstallXmlSchemaFiles.cmake)
 InstallXmlSchemaFiles("IO/XmlIO/*.xsd")
diff --git a/MaterialLib/CMakeLists.txt b/MaterialLib/CMakeLists.txt
index 6b4e1925115..d2488350c06 100644
--- a/MaterialLib/CMakeLists.txt
+++ b/MaterialLib/CMakeLists.txt
@@ -24,4 +24,6 @@ target_link_libraries(MaterialLib
     BaseLib
 )
 
-cotire(MaterialLib)
+if(OGS_USE_PCH)
+    cotire(MaterialLib)
+endif()
diff --git a/MathLib/CMakeLists.txt b/MathLib/CMakeLists.txt
index a90685fadf5..aeccec33ff7 100644
--- a/MathLib/CMakeLists.txt
+++ b/MathLib/CMakeLists.txt
@@ -59,4 +59,6 @@ if(TARGET Eigen)
     add_dependencies(MathLib Eigen)
 endif()
 
-cotire(MathLib)
+if(OGS_USE_PCH)
+    cotire(MathLib)
+endif()
diff --git a/MeshGeoToolsLib/CMakeLists.txt b/MeshGeoToolsLib/CMakeLists.txt
index ef43f083398..662f25ece84 100644
--- a/MeshGeoToolsLib/CMakeLists.txt
+++ b/MeshGeoToolsLib/CMakeLists.txt
@@ -15,4 +15,6 @@ if(TARGET Boost)
     add_dependencies(MeshGeoToolsLib Boost)
 endif()
 
-cotire(MeshGeoToolsLib)
+if(OGS_USE_PCH)
+    cotire(MeshGeoToolsLib)
+endif()
diff --git a/MeshLib/CMakeLists.txt b/MeshLib/CMakeLists.txt
index 2adfe7e6592..0746183e014 100644
--- a/MeshLib/CMakeLists.txt
+++ b/MeshLib/CMakeLists.txt
@@ -22,7 +22,9 @@ endif()
 
 # Create the library
 add_library(MeshLib ${SOURCES})
-cotire(MeshLib)
+if(OGS_USE_PCH)
+    cotire(MeshLib)
+endif()
 
 target_link_libraries(MeshLib
     BaseLib
diff --git a/NumLib/CMakeLists.txt b/NumLib/CMakeLists.txt
index 33e464a8866..ac83fc18073 100644
--- a/NumLib/CMakeLists.txt
+++ b/NumLib/CMakeLists.txt
@@ -35,4 +35,6 @@ if(TARGET Boost)
     add_dependencies(NumLib Boost)
 endif()
 
-cotire(NumLib)
+if(OGS_USE_PCH)
+    cotire(NumLib)
+endif()
diff --git a/ProcessLib/CMakeLists.txt b/ProcessLib/CMakeLists.txt
index 6c176911897..79cc2714663 100644
--- a/ProcessLib/CMakeLists.txt
+++ b/ProcessLib/CMakeLists.txt
@@ -74,4 +74,6 @@ if(OGS_INSITU)
     target_link_libraries(ProcessLib InSituLib)
 endif()
 
-cotire(ProcessLib)
+if(OGS_USE_PCH)
+    cotire(ProcessLib)
+endif()
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
index 69406a5520f..6485fd22a9c 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -76,7 +76,9 @@ endif()
 
 ADD_VTK_DEPENDENCY(testrunner)
 
-cotire(testrunner)
+if(OGS_USE_PCH)
+    cotire(testrunner)
+endif()
 
 # Add make-target tests which runs the testrunner
 if(DEFINED ENV{CI})
diff --git a/scripts/cmake/CompilerSetup.cmake b/scripts/cmake/CompilerSetup.cmake
index 9576399f1be..445216304f2 100644
--- a/scripts/cmake/CompilerSetup.cmake
+++ b/scripts/cmake/CompilerSetup.cmake
@@ -10,7 +10,12 @@ set(CMAKE_CXX_STANDARD 11)
 set(CMAKE_CXX_STANDARD_REQUIRED ON)
 set(CMAKE_CXX_EXTENSIONS OFF)
 
-include(cotire) # compile time reducer
+if(MSVC_VERSION LESS 1910) # < VS 15.0
+    set(OGS_USE_PCH OFF CACHE INTERNAL "")
+endif()
+if(OGS_USE_PCH)
+    include(cotire) # compile time reducer
+endif()
 
 # Set compiler helper variables
 
-- 
GitLab