From d3d08bbb7a493490f4e15f6238833efe095b4351 Mon Sep 17 00:00:00 2001
From: Lars Bilke <lars.bilke@ufz.de>
Date: Tue, 23 Feb 2021 08:50:06 +0100
Subject: [PATCH] Replaced Conan CVode module with CPM.

---
 MathLib/CMakeLists.txt           | 10 +++-------
 scripts/cmake/ConanSetup.cmake   |  4 ----
 scripts/cmake/Dependencies.cmake | 21 +++++++++++++++++++++
 scripts/cmake/Find.cmake         |  5 -----
 4 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/MathLib/CMakeLists.txt b/MathLib/CMakeLists.txt
index 46588c75ecd..2882065524b 100644
--- a/MathLib/CMakeLists.txt
+++ b/MathLib/CMakeLists.txt
@@ -5,7 +5,7 @@ append_source_files(SOURCES Curve)
 append_source_files(SOURCES InterpolationAlgorithms)
 append_source_files(SOURCES Integration)
 append_source_files(SOURCES LinAlg)
-if(CVODE_FOUND)
+if(OGS_USE_CVODE)
     append_source_files(SOURCES ODE)
 endif()
 append_source_files(SOURCES Nonlinear)
@@ -26,8 +26,6 @@ target_include_directories(MathLib
     PUBLIC
         ${CMAKE_CURRENT_BINARY_DIR}
         $<$<BOOL:${OGS_USE_PETSC}>:${PETSC_INCLUDE_DIRS}>
-    PRIVATE
-        $<$<BOOL:${OGS_USE_CVODE}>:${CVODE_INCLUDE_DIRS}>
 )
 
 set_target_properties(MathLib PROPERTIES LINKER_LANGUAGE CXX)
@@ -38,6 +36,7 @@ target_link_libraries(MathLib
         ${OpenMP_CXX_LIBRARIES}
         $<$<TARGET_EXISTS:LAPACK::LAPACK>:LAPACK::LAPACK>
         $<$<BOOL:${OGS_USE_LIS}>:${LIS_LIBRARIES}>
+        $<$<BOOL:${OGS_USE_CVODE}>:CVODE::CVODE>
         Eigen3::Eigen
     PRIVATE
         spdlog::spdlog
@@ -46,9 +45,6 @@ target_link_libraries(MathLib
 if(OGS_USE_PETSC)
     target_link_libraries(MathLib PUBLIC ${PETSC_LIBRARIES})
 endif()
-if(OGS_USE_CVODE)
-    target_link_libraries(MathLib PUBLIC ${CVODE_LIBRARIES})
-endif()
 if(OGS_USE_MKL)
     target_link_libraries(MathLib PUBLIC ${MKL_LIBRARIES})
 endif()
@@ -57,7 +53,7 @@ target_compile_definitions(MathLib
     PUBLIC
     $<$<BOOL:${USE_LIS}>:USE_LIS>
     $<$<BOOL:${OGS_USE_PETSC}>:USE_PETSC>
-    $<$<BOOL:${CVODE_FOUND}>:CVODE_FOUND>
+    $<$<BOOL:${OGS_USE_CVODE}>:CVODE_FOUND>
     PRIVATE
     $<$<BOOL:${OGS_USE_MKL}>:USE_MKL>
 )
diff --git a/scripts/cmake/ConanSetup.cmake b/scripts/cmake/ConanSetup.cmake
index e367a5e5476..9b97ed7b29c 100644
--- a/scripts/cmake/ConanSetup.cmake
+++ b/scripts/cmake/ConanSetup.cmake
@@ -62,10 +62,6 @@ if(OGS_USE_LIS)
     set(CONAN_REQUIRES ${CONAN_REQUIRES} lis/1.7.9@bilke/stable)
 endif()
 
-if(OGS_USE_CVODE)
-    set(CONAN_REQUIRES ${CONAN_REQUIRES} cvode/2.8.2@bilke/stable)
-endif()
-
 if(OGS_USE_MFRONT)
     set(CONAN_REQUIRES ${CONAN_REQUIRES} tfel/3.3.0@bilke/testing)
 endif()
diff --git a/scripts/cmake/Dependencies.cmake b/scripts/cmake/Dependencies.cmake
index d4bc04adf3c..ebb814b215a 100644
--- a/scripts/cmake/Dependencies.cmake
+++ b/scripts/cmake/Dependencies.cmake
@@ -257,6 +257,27 @@ if(OGS_BUILD_GUI)
     endif()
 endif()
 
+if(OGS_USE_CVODE)
+    CPMAddPackage(
+        NAME CVODE
+        GITHUB_REPOSITORY ufz/cvode
+        VERSION 2.8.2
+        GIT_TAG 42d786bff4f950045d2de941677ecd4432cec855
+        OPTIONS "EXAMPLES_ENABLE OFF"
+    )
+    if(CVODE_ADDED)
+        add_library(CVODE::CVODE INTERFACE IMPORTED)
+        target_include_directories(CVODE::CVODE INTERFACE
+            ${CVODE_SOURCE_DIR}/include
+            ${CVODE_BINARY_DIR}/include
+        )
+        target_link_libraries(CVODE::CVODE INTERFACE
+            sundials_cvode_static
+            sundials_nvecserial_static
+        )
+    endif()
+endif()
+
 # Disable warnings
 foreach(TARGET ${DISABLE_WARNINGS_TARGETS})
     target_compile_options(${TARGET} PRIVATE
diff --git a/scripts/cmake/Find.cmake b/scripts/cmake/Find.cmake
index a48c56a9d97..1a2e1f2ba0a 100644
--- a/scripts/cmake/Find.cmake
+++ b/scripts/cmake/Find.cmake
@@ -159,11 +159,6 @@ if(OGS_USE_MPI)
     find_package(MPI REQUIRED)
 endif()
 
-## Sundials cvode ode-solver library
-if(OGS_USE_CVODE)
-    find_package(CVODE REQUIRED)
-endif()
-
 find_package(Filesystem REQUIRED COMPONENTS Final Experimental)
 configure_file(${PROJECT_SOURCE_DIR}/BaseLib/filesystem.h.in
                ${PROJECT_BINARY_DIR}/BaseLib/filesystem.h)
-- 
GitLab