Skip to content

Commit

Permalink
#545: Store configured Python and NumPy versions in built code
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilMiller committed Jul 3, 2023
1 parent 2880ea9 commit df4e611
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
22 changes: 22 additions & 0 deletions include/realizations/catchment/Bmi_Py_Build_Versions.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef NGEN_BMI_PY_BUILD_VERSIONS_HPP
#define NGEN_BMI_PY_BUILD_VERSIONS_HPP

#ifdef ACTIVATE_PYTHON

#include <string>

namespace models {
namespace bmi {
extern const int python_major;
extern const int python_minor;
// Store the patch version as a string because it may have a non-numeric suffix
extern const std::string python_patch;

// NumPy version is not broken down by CMake
extern const std::string numpy_version;
}
}

#endif // ACTIVATE_PYTHON

#endif // NGEN_BMI_PY_BUILD_VERSIONS_HPP
16 changes: 16 additions & 0 deletions src/realizations/catchment/Bmi_Py_Build_Versions.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifdef ACTIVATE_PYTHON

#include "Bmi_Py_Build_Versions.hpp"

namespace models {
namespace bmi {

const int python_major = ${Python_VERSION_MAJOR};
const int python_minor = ${Python_VERSION_MINOR};
const std::string python_patch = "${Python_VERSION_PATCH}";

const std::string numpy_version = "${Python_NumPy_VERSION}";
}
}

#endif
2 changes: 2 additions & 0 deletions src/realizations/catchment/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ target_link_libraries(realizations_catchment PUBLIC
if(NGEN_ACTIVATE_PYTHON)
target_include_directories(realizations_catchment PUBLIC ${PROJECT_SOURCE_DIR}/extern/pybind11/include)
target_link_libraries(realizations_catchment PUBLIC pybind11::embed)
configure_file(Bmi_Py_Build_Versions.in Bmi_Py_Build_Versions.cpp)
target_sources(realizations_catchment PRIVATE Bmi_Py_Build_Versions.cpp)
endif()

##### Logic for Fortran integration
Expand Down

0 comments on commit df4e611

Please sign in to comment.