User Guide
config.h
Go to the documentation of this file.
1 /*
2  * Copyright 2023 Blue Brain Project, EPFL.
3  * See the top-level LICENSE file for details.
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #pragma once
9 
10 /**
11  * \dir
12  * \brief Global project configurations
13  *
14  * \file
15  * \brief Version information and units file path
16  */
17 
18 #include <cstdlib>
19 #include <fstream>
20 #include <sstream>
21 #include <string>
22 #include <vector>
23 
24 #include "utils/common_utils.hpp"
25 
26 namespace nmodl {
27 
28 /**
29  * \brief Project version information
30  */
31 struct Version {
32  /// git revision id
33  static const std::string GIT_REVISION;
34 
35  /// project tagged version in the cmake
36  static const std::string NMODL_VERSION;
37 
38  /// return version string (version + git id) as a string
39  static std::string to_string() {
40  return NMODL_VERSION + " " + GIT_REVISION;
41  }
42 };
43 
44 /**
45  * \brief Information of units database i.e. `nrnunits.lib`
46  */
47 struct NrnUnitsLib {
48  /// paths where nrnunits.lib can be found
49  static std::vector<std::string> NRNUNITSLIB_PATH;
50 
51  /**
52  * Return path of units database file
53  */
54  static std::string get_path() {
55  // first look for NMODLHOME env variable
56  if (const char* nmodl_home = std::getenv("NMODLHOME")) {
57  auto path = std::string(nmodl_home) + "/share/nmodl/nrnunits.lib";
58  NRNUNITSLIB_PATH.emplace(NRNUNITSLIB_PATH.begin(), path);
59  }
60 
61  // check paths in order and return if found
62  for (const auto& path: NRNUNITSLIB_PATH) {
63  std::ifstream f(path.c_str());
64  if (f.good()) {
65  return path;
66  }
67  }
68  std::ostringstream err_msg;
69  err_msg << "Could not find nrnunits.lib in any of:\n";
70  for (const auto& path: NRNUNITSLIB_PATH) {
71  err_msg << path << "\n";
72  }
73  throw std::runtime_error(err_msg.str());
74  }
75 };
76 
77 struct CMakeInfo {
78  static const std::string SHARED_LIBRARY_SUFFIX;
79 };
80 
81 } // namespace nmodl
nmodl
encapsulates code generation backend implementations
Definition: ast_common.hpp:26
nmodl::Version
Project version information.
Definition: config.h:31
nmodl::NrnUnitsLib::NRNUNITSLIB_PATH
static std::vector< std::string > NRNUNITSLIB_PATH
paths where nrnunits.lib can be found
Definition: config.h:49
nmodl::CMakeInfo
Definition: config.h:77
nmodl::Version::GIT_REVISION
static const std::string GIT_REVISION
git revision id
Definition: config.h:33
nmodl::CMakeInfo::SHARED_LIBRARY_SUFFIX
static const std::string SHARED_LIBRARY_SUFFIX
Definition: config.h:78
nmodl::NrnUnitsLib
Information of units database i.e.
Definition: config.h:47
nmodl::Version::to_string
static std::string to_string()
return version string (version + git id) as a string
Definition: config.h:39
nmodl::Version::NMODL_VERSION
static const std::string NMODL_VERSION
project tagged version in the cmake
Definition: config.h:36
nmodl::NrnUnitsLib::get_path
static std::string get_path()
Return path of units database file.
Definition: config.h:54
common_utils.hpp
Common utility functions for file/dir manipulation.