From d283b39cf0634f2be73238e15d3357c0cf921b93 Mon Sep 17 00:00:00 2001
From: Maximilian Reininghaus <maximilian.reininghaus@kit.edu>
Date: Wed, 1 Feb 2023 15:12:53 +0100
Subject: [PATCH] CMake

---
 CMakeLists.txt               |  1 +
 modules/fluka/CMakeLists.txt | 16 ++++++++
 modules/fluka/FLUKA.hpp      | 76 ++++++++++++++++++++++++++++++++++++
 tests/modules/CMakeLists.txt |  6 ++-
 4 files changed, 98 insertions(+), 1 deletion(-)
 create mode 100644 modules/fluka/CMakeLists.txt
 create mode 100644 modules/fluka/FLUKA.hpp

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 344257e5b..5432ca03c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -258,6 +258,7 @@ add_subdirectory (modules/qgsjetII)
 add_subdirectory (modules/urqmd)
 add_subdirectory (modules/conex)
 add_subdirectory (modules/epos)
+add_subdirectory (modules/fluka)
 
 #+++++++++++++++++++++++++++++++
 # unit testing
diff --git a/modules/fluka/CMakeLists.txt b/modules/fluka/CMakeLists.txt
new file mode 100644
index 000000000..626901998
--- /dev/null
+++ b/modules/fluka/CMakeLists.txt
@@ -0,0 +1,16 @@
+set(C8_FLUKALIB CACHE STRING "path to libflukahp.a")
+
+if (DEFINED C8_FLUKALIB)
+    add_library(flukahp STATIC IMPORTED)
+    set_property(TARGET flukahp PROPERTY IMPORTED_LOCATION ${C8_FLUKALIB})
+    find_library(MATH_LIBRARY m)
+    target_link_libraries(flukahp INTERFACE gfortran ${MATH_LIBRARY})
+    target_include_directories (flukahp INTERFACE
+        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
+        $<INSTALL_INTERFACE:include/corsika_modules/fluka>
+    )
+    
+    # add fluka to corsika8 build
+    add_dependencies (CORSIKA8 flukahp)
+    target_link_libraries (CORSIKA8 INTERFACE flukahp)
+endif()
diff --git a/modules/fluka/FLUKA.hpp b/modules/fluka/FLUKA.hpp
new file mode 100644
index 000000000..40457737a
--- /dev/null
+++ b/modules/fluka/FLUKA.hpp
@@ -0,0 +1,76 @@
+/*
+ * (c) Copyright 2022 CORSIKA Project, corsika-project@lists.kit.edu
+ *
+ * This software is distributed under the terms of the GNU General Public
+ * Licence version 3 (GPL Version 3). See file LICENSE for a full version of
+ * the license.
+ */
+
+#pragma once
+
+namespace fluka {
+extern "C" {
+/*----------------------------------------------------------------------*
+*                                                                      *
+*     Copyright (C) 2022-2022      by    Alfredo Ferrari & Paola Sala  *
+*     All Rights Reserved.                                             *
+*                                                                      *
+*                                                                      *
+*     SeTuP for X/Y/Z interaction types:                               *
+*                                                                      *
+*     Authors:                           Alfredo Ferrari & Paola Sala  *
+*                                                                      *
+*                                                                      *
+*     Created on  24 October 2022  by    Alfredo Ferrari & Paola Sala  *
+*                                            Private        Private    *
+*                                                                      *
+*     Last change on  01-Nov-22    by             Alfredo Ferrari      *
+*                                                     Private          *
+*                                                                      *
+*     Input variables:                                                 *
+*                                                                      *
+*           Nmatfl    = Number of requested Fluka materials            *
+*           Nelmfl(m) = Number of elements in the m_th requested Fluka *
+*                       material, Nelmfl(m)=1 means simple element, no *
+*                       compound                                       *
+*           Izelfl(n) = Cumulative array of the Z of the elements con- *
+*                       stituting the requested Fluka materials        *
+*                      (the Z for the elements of the m_th materials   *
+*                       start at n = Sum_i=1^m-1 [Nelmfl(i)] + 1)      *
+*           Wfelml(n) = Cumulative array of the weight fractions of the*
+*                       elements constituting the requested Fluka      *
+*                       materials (the weight fractions for the elem-  *
+*                       ents of the m_th materials start at            *
+*                        n = Sum_i=1^m-1 [Nelmfl(i)] + 1)              *
+*           Mxelfl    = Dimension of the Iz/Wfelml arrays, it must be  *
+*                       Mxelfl >= Sum_i=1^nmatfl [Nelmfl(i)]           *
+*           Pptmax    = Maximum momentum (GeV/c) to be used in initia- *
+*                       lization (optional)                            *
+*           Ef2dp3    = Transition energy (GeV) from Fluka (Peanut) to *
+*                       Dpmjet3 for hA interactions (optional)         *
+*           Df2dp3    = Smearing (+/-Df2dp3) (GeV) of the transition   *
+*                       energy from Fluka (Peanut) to Dpmjet3 for hA   *
+*                       interactions (optional)                        *
+*           Lprint    = Material printout flag                         *
+*                                                                      *
+*     Output variables:                                                *
+*                                                                      *
+*           Mtflka(m) = Fluka material number corresponding to the m_th*
+*                       requested material                             *
+*                                                                      *
+*----------------------------------------------------------------------*
+*/
+void stpxyz_(int const* NMATFL,
+    int const NELMFL[],
+    int const IZELFL[],
+    double const WFELFL[],
+    int const* MXELFL,
+    double const* PPTMAX,
+    double const* EF2DP3,
+    double const* DF2DP3,
+    int const* IFLXYZ,
+    bool const* LPRINT,
+    int* MTFLKA,
+    char CRVRCK[8]);
+}
+}
diff --git a/tests/modules/CMakeLists.txt b/tests/modules/CMakeLists.txt
index 015093588..a677ff581 100644
--- a/tests/modules/CMakeLists.txt
+++ b/tests/modules/CMakeLists.txt
@@ -15,7 +15,11 @@ set (test_modules_sources
   testRadio.cpp
   testEMThinning.cpp
   testSophia.cpp
-  )
+)
+  
+if (DEFINED C8_FLUKALIB)
+    list(APPEND test_modules_sources "testFluka.cpp")
+endif()
 
 CORSIKA_ADD_TEST (testModules SOURCES ${test_modules_sources})
 
-- 
GitLab