From 56bbd5ee6d40f8eec3bbfa87831bff47c42cfc1c Mon Sep 17 00:00:00 2001
From: Lars Bilke <lars.bilke@ufz.de>
Date: Wed, 6 Oct 2021 16:04:42 +0200
Subject: [PATCH] [cmake] Added option GENERATE_EXPORT_HEADER in
 ogs_add_library().

---
 BaseLib/CMakeLists.txt                    |  2 +-
 InfoLib/CMakeLists.txt                    |  2 +-
 MaterialLib/CMakeLists.txt                |  2 +-
 MaterialLib/FractureModels/CMakeLists.txt |  2 +-
 MathLib/CMakeLists.txt                    |  2 +-
 NumLib/CMakeLists.txt                     |  2 +-
 scripts/cmake/Functions.cmake             | 10 ++++++----
 7 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/BaseLib/CMakeLists.txt b/BaseLib/CMakeLists.txt
index be3eab56e93..d6b0f56d76a 100644
--- a/BaseLib/CMakeLists.txt
+++ b/BaseLib/CMakeLists.txt
@@ -6,7 +6,7 @@ if(OGS_BUILD_GUI)
 endif()
 
 # Create the library
-ogs_add_library(BaseLib ${SOURCES})
+ogs_add_library(BaseLib GENERATE_EXPORT_HEADER ${SOURCES})
 
 target_link_libraries(
     BaseLib
diff --git a/InfoLib/CMakeLists.txt b/InfoLib/CMakeLists.txt
index 4d1d1f6a86b..229641fbeee 100644
--- a/InfoLib/CMakeLists.txt
+++ b/InfoLib/CMakeLists.txt
@@ -5,6 +5,6 @@ foreach(lib Git CMake Test)
     )
 
     ogs_add_library(
-        ${lib}InfoLib ${CMAKE_CURRENT_BINARY_DIR}/${lib}Info.cpp ${lib}Info.h
+        ${lib}InfoLib GENERATE_EXPORT_HEADER ${CMAKE_CURRENT_BINARY_DIR}/${lib}Info.cpp ${lib}Info.h
     )
 endforeach(lib)
diff --git a/MaterialLib/CMakeLists.txt b/MaterialLib/CMakeLists.txt
index 9cd0317ce3c..35100bc7dc6 100644
--- a/MaterialLib/CMakeLists.txt
+++ b/MaterialLib/CMakeLists.txt
@@ -36,7 +36,7 @@ append_source_files(
 )
 append_source_files(SOURCES TwoPhaseModels)
 
-ogs_add_library(MaterialLib ${SOURCES})
+ogs_add_library(MaterialLib GENERATE_EXPORT_HEADER ${SOURCES})
 
 target_link_libraries(
     MaterialLib PUBLIC MaterialLib_SolidModels MaterialLib_FractureModels
diff --git a/MaterialLib/FractureModels/CMakeLists.txt b/MaterialLib/FractureModels/CMakeLists.txt
index 3891c7a17d1..ac8fecf84c1 100644
--- a/MaterialLib/FractureModels/CMakeLists.txt
+++ b/MaterialLib/FractureModels/CMakeLists.txt
@@ -1,7 +1,7 @@
 get_source_files(SOURCES)
 append_source_files(SOURCES Permeability)
 
-ogs_add_library(MaterialLib_FractureModels ${SOURCES})
+ogs_add_library(MaterialLib_FractureModels GENERATE_EXPORT_HEADER ${SOURCES})
 target_link_libraries(
     MaterialLib_FractureModels PUBLIC MathLib PRIVATE ParameterLib NumLib
 )
diff --git a/MathLib/CMakeLists.txt b/MathLib/CMakeLists.txt
index 45f7919c38e..204d6fa93a4 100644
--- a/MathLib/CMakeLists.txt
+++ b/MathLib/CMakeLists.txt
@@ -21,7 +21,7 @@ if(OGS_USE_PETSC)
 endif()
 
 # Create the library
-ogs_add_library(MathLib ${SOURCES})
+ogs_add_library(MathLib GENERATE_EXPORT_HEADER ${SOURCES})
 
 set_target_properties(MathLib PROPERTIES LINKER_LANGUAGE CXX)
 
diff --git a/NumLib/CMakeLists.txt b/NumLib/CMakeLists.txt
index d001882687d..d9f78959352 100644
--- a/NumLib/CMakeLists.txt
+++ b/NumLib/CMakeLists.txt
@@ -14,7 +14,7 @@ append_source_files(SOURCES ODESolver)
 append_source_files(SOURCES Extrapolation)
 
 # Create the library
-ogs_add_library(NumLib ${SOURCES})
+ogs_add_library(NumLib GENERATE_EXPORT_HEADER ${SOURCES})
 set_target_properties(NumLib PROPERTIES LINKER_LANGUAGE CXX)
 
 target_link_libraries(
diff --git a/scripts/cmake/Functions.cmake b/scripts/cmake/Functions.cmake
index 1f8213cdd0c..fa2c6d7db06 100644
--- a/scripts/cmake/Functions.cmake
+++ b/scripts/cmake/Functions.cmake
@@ -80,7 +80,7 @@ endfunction()
 
 # Replacement for add_library() for ogs libraries
 function(ogs_add_library targetName)
-    set(options STATIC SHARED)
+    set(options STATIC SHARED GENERATE_EXPORT_HEADER)
     cmake_parse_arguments(ogs_add_library "${options}" "" "" ${ARGN})
 
     foreach(file ${ogs_add_library_UNPARSED_ARGUMENTS})
@@ -117,9 +117,11 @@ function(ogs_add_library targetName)
         )
     endif()
 
-    include(GenerateExportHeader)
-    generate_export_header(${targetName})
-    target_include_directories(${targetName} PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
+    if(ogs_add_library_GENERATE_EXPORT_HEADER)
+        include(GenerateExportHeader)
+        generate_export_header(${targetName})
+        target_include_directories(${targetName} PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
+    endif()
 
     if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.16)
         set_target_properties(
-- 
GitLab