From 6981bf95232f6ef8bb8350cda3e862cbe61316f1 Mon Sep 17 00:00:00 2001
From: Lars Bilke <lars.bilke@ufz.de>
Date: Wed, 18 Mar 2020 10:05:26 +0100
Subject: [PATCH] [CMake] Fixed OGS_USE_NETCDF logic when OGS_BUILD_GUI=OFF.

---
 Applications/DataExplorer/DataExplorer.cmake | 1 -
 CMakeLists.txt                               | 2 +-
 scripts/cmake/Find.cmake                     | 2 +-
 3 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/Applications/DataExplorer/DataExplorer.cmake b/Applications/DataExplorer/DataExplorer.cmake
index 7e26c6f5aca..32c30d3cf0d 100644
--- a/Applications/DataExplorer/DataExplorer.cmake
+++ b/Applications/DataExplorer/DataExplorer.cmake
@@ -55,7 +55,6 @@ target_link_libraries(DataExplorer
 
 
 if(OGS_USE_NETCDF)
-    add_definitions(-DOGS_USE_NETCDF)
     add_subdirectory(NetCdfDialog)
     target_link_libraries(DataExplorer NetCdfDialogLib)
 endif()
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 81c012b7f62..9c85b5da193 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -96,7 +96,6 @@ endif() # GCC AND GPROF_PATH
 option(OGS_BUILD_GUI "Should the Data Explorer be built?" OFF)
 if(OGS_BUILD_GUI)
     add_definitions(-DOGS_BUILD_GUI)
-    option(OGS_USE_NETCDF "Add NetCDF support." OFF)
 endif()
 option(OGS_BUILD_UTILS "Should the utilities programms be built?" OFF)
 if(OGS_BUILD_UTILS AND OGS_USE_MPI)
@@ -116,6 +115,7 @@ option(OGS_NO_EXTERNAL_LIBS "Builds OGS without any external dependencies." OFF)
 option(OGS_INSITU "Builds OGS with insitu visualization capabilities." OFF)
 option(OGS_USE_LIS "Use Lis" OFF)
 option(OGS_USE_PETSC "Use PETSc routines" OFF)
+option(OGS_USE_NETCDF "Add NetCDF support." OFF)
 
 # Eigen
 option(OGS_USE_EIGEN "Use Eigen linear solver" ON)
diff --git a/scripts/cmake/Find.cmake b/scripts/cmake/Find.cmake
index 6be8db4d996..bb0270d2c7c 100644
--- a/scripts/cmake/Find.cmake
+++ b/scripts/cmake/Find.cmake
@@ -116,7 +116,7 @@ if(OGS_USE_NETCDF)
     else()
         find_package(HDF5 REQUIRED COMPONENTS C HL)
     endif()
-
+    add_compile_options(-DOGS_USE_NETCDF)
 endif()
 
 # lapack
-- 
GitLab