diff --git a/CMakeLists.txt b/CMakeLists.txt index 0605a361b9a9c102946713db32d342b8750ca6a9..1cb48d5e73caba1ed6df27fa8a191facd5186287 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,10 +10,19 @@ cmake_minimum_required (VERSION 3.9) +#+++++++++++++++++++++++++++++ +# for pre-defined standard path +# +include (GNUInstallDirs) + #+++++++++++++++++++++++++++++ # project name +# version is: "8.major.minor.patch" +# major: API changes +# minor: no API changes +# patch: bug fix and small improvements # -set (c8_version 8.0.0) +set (c8_version 8.0.0.0) project ( corsika VERSION ${c8_version} @@ -255,72 +264,116 @@ install ( EXPORT CORSIKA8PublicTargets PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_PREFIX} ) - # -# header only part +# header only part, just copy entire directory tree # install (DIRECTORY corsika DESTINATION include) - +# +# generate cmake config package version (for find_package) +# write_basic_package_version_file ( ${PROJECT_BINARY_DIR}/corsikaConfigVersion.cmake VERSION ${c8_version} COMPATIBILITY SameMajorVersion ) - -# export targets in build tree +# +# export targets in build tree (for find_package) +# export ( EXPORT CORSIKA8PublicTargets FILE "${CMAKE_CURRENT_BINARY_DIR}/corsikaTargets.cmake" NAMESPACE CORSIKA8:: ) - -# export targets in install tree +# +# export targets in install tree (for find_package) +# install ( EXPORT CORSIKA8PublicTargets FILE corsikaTargets.cmake NAMESPACE CORSIKA8:: DESTINATION lib/cmake/corsika ) - -# config for build tree +# +# config for build tree (for find_package) +# configure_package_config_file ( cmake/corsikaConfig.cmake.in ${PROJECT_BINARY_DIR}/corsikaConfig.cmake INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX} ) - -# corsikaDefines for build tree +# +# corsikaDefines +# configure_package_config_file ( cmake/corsikaDefines.cmake ${PROJECT_BINARY_DIR}/corsikaDefines.cmake INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX} ) - -# config for install tree -# overwrite with install location (if it was build as part of corsika) +# +# config for install tree (for find_package) +# overwrite with install locations (if it was build as part of corsika) +# set (Pythia8_INCDIR ${Pythia8_INCDIR_INSTALL}) set (Pythia8_LIBDIR ${Pythia8_LIBDIR_INSTALL}) configure_package_config_file ( cmake/corsikaConfig.cmake.in - ${PROJECT_BINARY_DIR}/cmake/corsikaConfig.cmake - INSTALL_DESTINATION ${PROJECT_BINARY_DIR}/do_not_need_this + ${PROJECT_BINARY_DIR}/corsikaConfig.cmake-install + INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX} ) - +# +# generate "corsika/corsika.hpp" file with cmake-level details and paths +# first for build-tree +# +# the location of the "corsika-data" is of fundamental importance +set (CORSIKA_CMAKE_DATA_DIR ${CMAKE_SOURCE_DIR}/modules/data) +configure_file ( + src/corsika.hpp.in + ${PROJECT_BINARY_DIR}/corsika/corsika.hpp +) +# +# second also for install-tree +# +set (CORSIKA_CMAKE_DATA_DIR "${CMAKE_INSTALL_FULL_DATADIR}/corsika/data") +configure_file ( + src/corsika.hpp.in + ${PROJECT_BINARY_DIR}/corsika.hpp-install +) +# +# installation of cmake and config files +# install ( FILES ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake ${CMAKE_BINARY_DIR}/conaninfo.txt - ${CMAKE_BINARY_DIR}/corsikaConfig.cmake ${CMAKE_BINARY_DIR}/corsikaDefines.cmake ${CMAKE_BINARY_DIR}/corsikaConfigVersion.cmake DESTINATION lib/cmake/corsika ) - +# +# install and rename install-level corsikaConfig.cmake +# +install ( + FILES + ${CMAKE_BINARY_DIR}/corsikaConfig.cmake-install + RENAME corsikaConfig.cmake + DESTINATION lib/cmake/corsika + ) +# +# also install-level config.hpp +# +install (FILES + ${PROJECT_BINARY_DIR}/corsika.hpp-install + RENAME corsika.hpp + DESTINATION include/corsika + ) # # examples # -install (DIRECTORY examples DESTINATION share/corsika) - +install (DIRECTORY examples DESTINATION ${CMAKE_INSTALL_DATADIR}/corsika) +# +# data +# +install (DIRECTORY modules/data DESTINATION ${CMAKE_INSTALL_DATADIR}/corsika) # # tools # diff --git a/README.md b/README.md index 6d89368fb706076b66c5779b2819ffc4b97cc939..5f48b14497d6bc3aef2e564927a40efaf6988871 100644 --- a/README.md +++ b/README.md @@ -120,13 +120,6 @@ make install ## Runing Unit Tests -Note, before you run *any* executbale you must also define the -`CORSIKA_DATA` environment variable to point to the location where you -cloned corsika `modules/data`, thus typically -```shell -export CORSIKA_DATA=$PWD/../corsika/modules/data -``` - To run the Unit Tests, just type `ctest` in your build area. @@ -144,7 +137,7 @@ e.g. `corsika-install/share/corsika/examples/` to your working place Next, you need to define the environment variable `corsika_DIR` to point to, either, your build, or your install area. Thus, e.g. ```shell -export corsika_DIR=<dir where you installed CORSIKA 8 to, or where you buld it"> +export corsika_DIR=<dir where you installed CORSIKA 8 to, or where you build it> ``` Then compile your example/application with diff --git a/README.rst b/README.rst index 27eb3d1d8480b5821c46e22af7da9ab39ee1b748..2f4d28d212901f1f8b71ef97ffd563091d5bcdff 100644 --- a/README.rst +++ b/README.rst @@ -129,13 +129,6 @@ Follow these steps to download and install CORSIKA 8, master development version Runing Unit Tests ----------------- -Note, before you run *any* executbale you must also define the -:code:`CORSIKA_DATA` environment variable to point to the location where you -cloned corsika :code:`modules/data`, thus typically -:: - - export CORSIKA_DATA=$PWD/../corsika/modules/data - To run the Unit Tests, just type :code:`ctest` in your build area. @@ -155,7 +148,7 @@ Next, you need to define the environment variable :code:`corsika_DIR` to point t your build, or your install area. Thus, e.g. :: - export corsika_DIR=<dir where you installed CORSIKA 8 to, or where you buld it"> + export corsika_DIR=<dir where you installed CORSIKA 8 to, or where you build it> Then compile your example/application with :: diff --git a/corsika/corsika.hpp b/corsika/corsika.hpp deleted file mode 100644 index 36fa90b6315e83504a74d20ba6c66f657929e409..0000000000000000000000000000000000000000 --- a/corsika/corsika.hpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * (c) Copyright 2020 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 - -/** - @file corsika.hpp - - The CORSIKA 8 air shower simulation framework. - - @mainpage Technical documentation of the CORSIKA 8 software framework - - Software documentatin and reference guide for the CORSIKA 8 - software framework for air shower simulations. CORSIKA 8 is developed - at <a href="https://gitlab.ikp.kit.edu/AirShowerPhysics">https://gitlab.ikp.kit.edu</a>. - If you got the code from somewhere else, consider to switch to the official development - repository. If you want to report bugs, or want to suggest features or future - development, please submit an "issue" on this gitlab server. We only accept Issues and - discussion via our central development server https://gitlab.ikp.kit.edu. - - Write to corsika-devel@lists.kit.edu, or even register yourself at - https://www.lists.kit.edu/sympa/info/corsika-devel to get in contact - with other developers. - - For more information about the project, see @ref md_README. - **/ - -/*! Usage: - * to get the version X.YY.Z, - * set CORSIKA_VERSION X0YY0Z - */ -#define CORSIKA_VERSION 800000 - -/*! \def CORSIKA_MAJOR_VERSION - * \brief The preprocessor macro \p CORSIKA_MAJOR_VERSION encodes the - * major version number of CORSIKA. - */ -#define CORSIKA_MAJOR_VERSION (CORSIKA_VERSION / 100000) - -/*! \def CORSIKA_MINOR_VERSION - * \brief The preprocessor macro \p CORSIKA_MINOR_VERSION encodes the - * minor version number of CORSIKA. - */ -#define CORSIKA_MINOR_VERSION (CORSIKA_VERSION / 100 % 1000) - -/*! \def CORSIKA_PATCH_NUMBER - * \brief The preprocessor macro \p CORSIKA_PATCH_NUMBER encodes the - * patch number of the CORSIKA library. - */ -#define CORSIKA_PATCH_NUMBER 0 diff --git a/corsika/detail/framework/utility/CorsikaData.inl b/corsika/detail/framework/utility/CorsikaData.inl index c3a82ad11d59e6849617b521735d8b6a92212e1d..0bfc369393c473be94f0d9d740db3b7994a33873 100644 --- a/corsika/detail/framework/utility/CorsikaData.inl +++ b/corsika/detail/framework/utility/CorsikaData.inl @@ -7,16 +7,26 @@ */ #pragma once +#include <corsika/corsika.hpp> +#include <corsika/framework/core/Logging.hpp> + #include <boost/filesystem/path.hpp> #include <cstdlib> #include <stdexcept> #include <string> -inline boost::filesystem::path corsika::corsika_data(boost::filesystem::path const& key) { - if (auto const* p = std::getenv("CORSIKA_DATA"); p != nullptr) { - return boost::filesystem::path(p) / key; - } else { // LCOV_EXCL_START, this cannot be easily tested system-independently - throw std::runtime_error("CORSIKA_DATA not set"); - } // LCOV_EXCL_STOP -} +namespace corsika { + + inline boost::filesystem::path corsika_data(boost::filesystem::path const& key) { + boost::filesystem::path fname = + boost::filesystem::path(corsika::CORSIKA_DATA_DIR) / key; + // LCOV_EXCL_START, this cannot be easily tested system-independently + if (auto const* p = std::getenv("CORSIKA_DATA"); p != nullptr) { + fname = boost::filesystem::path(p) / key; + } + // LCOV_EXCL_STOP + CORSIKA_LOG_INFO("opening data file={}", fname); + return fname; + } +} // namespace corsika diff --git a/corsika/detail/modules/epos/Interaction.inl b/corsika/detail/modules/epos/Interaction.inl index dde502eb0b3284a83b1fd5af01708800d6e49573..1e69cff4eb6ec68037b9ae4fcb943cb4f45e5665 100644 --- a/corsika/detail/modules/epos/Interaction.inl +++ b/corsika/detail/modules/epos/Interaction.inl @@ -9,14 +9,16 @@ #pragma once #include <corsika/modules/epos/Interaction.hpp> +#include <corsika/modules/epos/EposStack.hpp> #include <corsika/media/Environment.hpp> #include <corsika/media/NuclearComposition.hpp> -#include <corsika/framework/geometry/FourVector.hpp> -#include <corsika/modules/epos/EposStack.hpp> + +#include <corsika/framework/utility/COMBoost.hpp> +#include <corsika/framework/utility/CorsikaData.hpp> + #include <corsika/setup/SetupStack.hpp> #include <corsika/setup/SetupTrajectory.hpp> -#include <corsika/framework/utility/COMBoost.hpp> #include <epos.hpp> @@ -33,13 +35,8 @@ namespace corsika::epos { : data_path_(dataPath) , epos_listing_(epos_printout_on) { if (dataPath == "") { - if (std::getenv("CORSIKA_DATA")) { - data_path_ = std::string(std::getenv("CORSIKA_DATA")) + "/EPOS/"; - CORSIKA_LOGGER_DEBUG(logger_, "Searching for EPOSLHC data tables in {}", - data_path_); - } + data_path_ = (std::string(corsika_data("EPOS").c_str()) + "/").c_str(); } - // initialize Eposlhc static bool initialized = false; if (!initialized) { diff --git a/corsika/detail/modules/proposal/ProposalProcessBase.inl b/corsika/detail/modules/proposal/ProposalProcessBase.inl index 6b869ad438ec2a97384b436f7cc25182efba5286..404e713b726a0a1ab6998721f1e3558daa08e053 100644 --- a/corsika/detail/modules/proposal/ProposalProcessBase.inl +++ b/corsika/detail/modules/proposal/ProposalProcessBase.inl @@ -11,6 +11,7 @@ #include <corsika/modules/proposal/ProposalProcessBase.hpp> #include <corsika/framework/core/PhysicalUnits.hpp> #include <corsika/framework/utility/COMBoost.hpp> +#include <corsika/framework/utility/CorsikaData.hpp> #include <cstdlib> #include <iostream> @@ -53,14 +54,7 @@ namespace corsika::proposal { //! If corsika data exist store interpolation tables to the corresponding //! path, otherwise interpolation tables would only stored in main memory if //! no explicit intrpolation def is specified. - if (auto data_path = std::getenv("CORSIKA_DATA")) { - PROPOSAL::InterpolationSettings::TABLES_PATH = std::string(data_path) + "/PROPOSAL"; - } else { - throw std::runtime_error( - "It is not recommended to run PROPOSAL without its tables in " - "$CORSIKA_DATA/PROPOSAL. This would be extremely slow. Please provide the " - "table directory. "); - } + PROPOSAL::InterpolationSettings::TABLES_PATH = corsika_data("PROPOSAL").c_str(); } inline size_t ProposalProcessBase::hash::operator()(const calc_key_t& p) const diff --git a/corsika/framework/core/Cascade.hpp b/corsika/framework/core/Cascade.hpp index 10f9eb9a2d4820643a7562ae76be890b68febfc7..1163950f3806050b9fdd04c93aa6905a9c8cc6f0 100644 --- a/corsika/framework/core/Cascade.hpp +++ b/corsika/framework/core/Cascade.hpp @@ -8,6 +8,8 @@ #pragma once +#include <corsika/corsika.hpp> + #include <corsika/framework/process/ProcessReturn.hpp> #include <corsika/framework/core/PhysicalUnits.hpp> #include <corsika/framework/random/ExponentialDistribution.hpp> @@ -82,6 +84,8 @@ namespace corsika { , output_(out) , stack_(stack) { CORSIKA_LOG_INFO(c8_ascii_); + CORSIKA_LOG_INFO("This is CORSIKA {}.{}.{}.{}", CORSIKA_RELEASE_NUMBER, + CORSIKA_MAJOR_NUMBER, CORSIKA_MINOR_NUMBER, CORSIKA_PATCH_NUMBER); CORSIKA_LOG_INFO("Tracking algorithm: {} (version {})", TTracking::getName(), TTracking::getVersion()); if constexpr (stack_view_type::has_event) { diff --git a/documentation/CMakeLists.txt b/documentation/CMakeLists.txt index 5e727190a8bb493e5b5a4f679226970303b084a1..026bc9b89a1993d031c744d15564ee41d1a32d2e 100644 --- a/documentation/CMakeLists.txt +++ b/documentation/CMakeLists.txt @@ -25,8 +25,8 @@ if (DOXYGEN_FOUND) COMMAND cd ${CMAKE_CURRENT_BINARY_DIR}/latex; pdflatex refman.tex ) - install (DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION share/doc OPTIONAL) - install (FILES ${CMAKE_CURRENT_BINARY_DIR}/latex/refman.pdf DESTINATION share/doc OPTIONAL) + install (DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION ${CMAKE_INSTALL_DATADIR}/corsika/doc OPTIONAL) + install (FILES ${CMAKE_CURRENT_BINARY_DIR}/latex/refman.pdf DESTINATION ${CMAKE_INSTALL_DATADIR}/corsika/doc OPTIONAL) if (SPHINX_FOUND) diff --git a/modules/pythia8/CMakeLists.txt b/modules/pythia8/CMakeLists.txt index 91433eb8ddcaec6a042eab83864a5763833ac046..84abac6f004310585d500f9842ec31a49f648e5d 100644 --- a/modules/pythia8/CMakeLists.txt +++ b/modules/pythia8/CMakeLists.txt @@ -92,15 +92,20 @@ else () install (DIRECTORY ${Pythia8_PREFIX}/ DESTINATION ${Pythia8_PREFIX_INSTALL}) set (Pythia8_INCLUDE_DIRS ${Pythia8_INCLUDE_DIR}) - + set_target_properties ( C8::ext::pythia8 PROPERTIES IMPORTED_LOCATION ${Pythia8_LIBDIR}/libpythia8.a IMPORTED_LINK_INTERFACE_LIBRARIES dl - INTERFACE_INCLUDE_DIRECTORIES "${Pythia8_INCLUDE_DIRS}" ) - + target_include_directories ( + C8::ext::pythia8 + INTERFACE + $<BUILD_INTERFACE:${Pythia8_INCLUDE_DIRS}> + $<INSTALL_INTERFACE:include/corsika/modules/pythia8/include> + ) + message (STATUS "Pythia8 build at: ${Pythia8_PREFIX}, final install to: ${Pythia8_PREFIX_INSTALL}") endif () diff --git a/src/corsika.hpp.in b/src/corsika.hpp.in new file mode 100644 index 0000000000000000000000000000000000000000..3f683d93607a2e7e9c0138f86290ff0964991be0 --- /dev/null +++ b/src/corsika.hpp.in @@ -0,0 +1,87 @@ +/* + * (c) Copyright 2020 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 + +#include <string> + +namespace corsika { + + /** + * @file corsika.hpp + * + * The CORSIKA 8 air shower simulation framework. + * + * @mainpage Technical documentation of the CORSIKA 8 software framework. + * + * Software documentatin and reference guide for the CORSIKA 8 + * software framework for air shower simulations. CORSIKA 8 is developed + * at <a + * href="https://gitlab.ikp.kit.edu/AirShowerPhysics">https://gitlab.ikp.kit.edu</a>. If + * you got the code from somewhere else, consider to switch to the official development + * repository. If you want to report bugs, or want to suggest features or future + * development, please submit an "issue" on this gitlab server. We only accept Issues + * and discussion via our central development server https://gitlab.ikp.kit.edu. + * + * Write to corsika-devel@lists.kit.edu, or even register yourself at + * https://www.lists.kit.edu/sympa/info/corsika-devel to get in contact + * with other developers. + * + * For more information about the project, see @ref md_README. + */ + + /*! Usage: + * to get the version R.X.Y.Z, + * x: major version + * y: minor version + * z: patch number + */ + static std::string const CORSIKA_VERSION = "@PROJECT_VERSION@"; + + /*! + * The value of \p CORSIKA_RELEASE_VERSION encodes the + * main release version number of CORSIKA. It is "8" right now. + */ + static unsigned int const CORSIKA_RELEASE_NUMBER = @PROJECT_VERSION_MAJOR@; + + /*! + * The value of \p CORSIKA_MAJOR_VERSION encodes the + * major release version number of CORSIKA. + */ + static unsigned int const CORSIKA_MAJOR_NUMBER = @PROJECT_VERSION_MINOR@; + + /*! + * The value of \p CORSIKA_MINOR_NUMBER encodes the + * minor release number of the CORSIKA library. + */ + static unsigned int const CORSIKA_MINOR_NUMBER = @PROJECT_VERSION_PATCH@; + + /*! + * The value of \p CORSIKA_PATCH_NUMBER encodes the + * patch number of the CORSIKA library. + */ + static unsigned int const CORSIKA_PATCH_NUMBER = @PROJECT_VERSION_TWEAK@; + + /** + * + * CORSIKA_DATA_DIR is a cmake-time marker for the location of corsika-data. + * + * the location of the "corsika-data" is of fundamental importance + * this should not be done in corsikaDefines.cmake since we may want + * to change behaviour at config/build/install time. + * + * There is a build-time default location of corsika-data at: "modules/data", + * but there is also an install-time default location of corsika-data at + * "share/corsika/data". + * The search for corsika-data can always be overwritten by the + * user with the `CORSIKA_DATA` envrionment variable. + */ + + static std::string const CORSIKA_DATA_DIR = "@CORSIKA_CMAKE_DATA_DIR@"; + +} // namespace corsika diff --git a/tests/modules/testQGSJetII.cpp b/tests/modules/testQGSJetII.cpp index eddf34acabe40f1ec40d1ed2a082c281a2245096..84f1b4ebe8fc7f6edcd9c2aac0c2ec1b0336f8da 100644 --- a/tests/modules/testQGSJetII.cpp +++ b/tests/modules/testQGSJetII.cpp @@ -46,25 +46,6 @@ auto sumMomentum(TStackView const& view, CoordinateSystemPtr const& vCS) { return sum; } -TEST_CASE("CORSIKA_DATA", "[processes]") { - - logging::set_level(logging::level::info); - - SECTION("check CORSIKA_DATA") { - - const char* CORSIKA_DATA = std::getenv("CORSIKA_DATA"); - // these CHECKS are needed: - CHECK(CORSIKA_DATA != 0); - CHECK(boost::filesystem::is_directory(boost::filesystem::path(CORSIKA_DATA) / - "QGSJetII")); - CORSIKA_LOG_INFO( - "data: {}" - " isDir: {}" - "/QGSJetII", - CORSIKA_DATA, boost::filesystem::is_directory(CORSIKA_DATA)); - } -} - TEST_CASE("QgsjetII", "[processes]") { logging::set_level(logging::level::info);