Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/atlas4py/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,12 @@ endif()
nanobind_add_module(_atlas4py
_atlas4py.cpp
_atlas4py_Config.cpp
mpi/_mpi.cpp
)
target_link_libraries(_atlas4py PUBLIC atlas)
target_include_directories(_atlas4py PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_definitions(_atlas4py PRIVATE ATLAS4PY_VERSION_STRING=${PROJECT_VERSION_FULL})
target_compile_definitions(_atlas4py PRIVATE ATLAS4PY_ATLAS_VERSION_INT=${ATLAS4PY_ATLAS_VERSION_INT})

### Installation

Expand Down
2 changes: 2 additions & 0 deletions src/atlas4py/_atlas4py.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace pluto {
#include "eckit/config/Configuration.h"

#include "_atlas4py_Config.hpp"
#include "mpi/_mpi.hpp"

namespace nb = ::nanobind;

Expand Down Expand Up @@ -224,6 +225,7 @@ NB_MODULE( _atlas4py, m ) {
.def("_finalise", atlas::finalise);
m.attr("__version__") = STRINGIFY(ATLAS4PY_VERSION_STRING);

atlas4py::bind_submodule_mpi( m );
atlas4py::bind_Config( m );

nb::class_<PointLonLat>( m, "PointLonLat" )
Expand Down
4 changes: 4 additions & 0 deletions src/atlas4py/_atlas4py_common.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once

#define ATLAS4PY_ATLAS_VERSION_AT_LEAST(x, y, z) (ATLAS4PY_ATLAS_VERSION_INT >= x * 10000 + y * 100 + z)

4 changes: 4 additions & 0 deletions src/atlas4py/cmake/atlas4py_add_atlas.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,9 @@ macro(atlas4py_add_atlas)
set(ATLAS_ENABLE_ECKIT_CMD OFF)

FetchContent_MakeAvailable(eckit atlas)
find_package(atlas CONFIG REQUIRED)
endif()

include(cmake/atlas4py_parse_version.cmake)
atlas4py_parse_version(${atlas_VERSION_STR} PREFIX ATLAS4PY_ATLAS)
endmacro()
99 changes: 99 additions & 0 deletions src/atlas4py/cmake/atlas4py_parse_version.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# This file defines a function to parse version strings and export version components as CMake variables.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No strong objection, but until there is a user that needs this I would KISS and rather only support the latest atlas api in the bindings so that no compatibility logic is required.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you mean that we should bump the required atlas version instead? I'm OK with that of course!
Let's make that a new policy from now on then.


##############################################################################
#.rst:
#
# atlas4py_parse_version
# =====================
#
# Parse version string of the form "<major>[.<minor>[.<patch>[.<tweak>]]][<suffix>]" ::
#
# atlas4py_parse_version( <version_str> [ PREFIX <prefix> ] )
#
# Options
# -------
#
# PREFIX : optional
# string to be prefixed to all defined variables. If not given,
# the value "_" will be used.
#
# Notes
# -----
#
# Following variables if possible:
#
# <prefix>_VERSION_STR = <major>[.<minor>[.<patch>[.<tweak>]]][<suffix>]
# <prefix>_VERSION = <major>[.<minor>[.<patch>[.<tweak>]]]
# <prefix>_VERSION_MAJOR = <major>
# <prefix>_VERSION_MINOR = <minor>
# <prefix>_VERSION_PATCH = <patch>
# <prefix>_VERSION_TWEAK = <tweak>
# <prefix>_VERSION_SUFFIX = <suffix>
# <prefix>_VERSION_INT = <major> * 10000 + <minor> * 100 + <patch>
#
# Note, this is taken from ecbuild_parse_version.cmake, with addition of <prefix>_VERSION_INT

function( atlas4py_parse_version version_str )
set( options )
set( single_value_args PREFIX )
set( multi_value_args )

cmake_parse_arguments( _PAR "${options}" "${single_value_args}" "${multi_value_args}" ${ARGN} )

if( NOT _PAR_PREFIX )
set( prefix "_" )
else()
set( prefix ${_PAR_PREFIX} )
endif()

## Parse version_str
set( ${prefix}_VERSION_STR "${version_str}" )
string( REGEX REPLACE "^((([0-9]+)\\.)+([0-9]+)).*" "\\1" ${prefix}_VERSION "${version_str}" )
string( LENGTH "${${prefix}_VERSION}" ver_len )
string( SUBSTRING "${version_str}" ${ver_len} -1 ${prefix}_VERSION_SUFFIX )
string( REPLACE "." " " _version_list ${${prefix}_VERSION} ) # dots to spaces
separate_arguments( _version_list )
list (LENGTH _version_list _len)
if( ${_len} GREATER 0 )
list( GET _version_list 0 ${prefix}_VERSION_MAJOR )
endif()
if( ${_len} GREATER 1 )
list( GET _version_list 1 ${prefix}_VERSION_MINOR )
endif()
if( ${_len} GREATER 2 )
list( GET _version_list 2 ${prefix}_VERSION_PATCH )
endif()
if( ${_len} GREATER 3 )
list( GET _version_list 3 ${prefix}_VERSION_TWEAK )
endif()

if( NOT DEFINED ${prefix}_VERSION_MINOR )
set( ${prefix}_VERSION_MINOR 0 )
endif()
if( NOT DEFINED ${prefix}_VERSION_PATCH )
set( ${prefix}_VERSION_PATCH 0 )
endif()
if( NOT DEFINED ${prefix}_VERSION_TWEAK )
set( ${prefix}_VERSION_TWEAK 0 )
endif()

math(EXPR ${prefix}_VERSION_INT "${${prefix}_VERSION_MAJOR} * 10000 + ${${prefix}_VERSION_MINOR} * 100 + ${${prefix}_VERSION_PATCH}")

## Export variables to parent scope
list( APPEND export_variables_parent_scope
${prefix}_VERSION_STR
${prefix}_VERSION
${prefix}_VERSION_MAJOR
${prefix}_VERSION_MINOR
${prefix}_VERSION_PATCH
${prefix}_VERSION_TWEAK
${prefix}_VERSION_SUFFIX
${prefix}_VERSION_INT
)
foreach( _var ${export_variables_parent_scope} )
if( DEFINED ${_var} )
set( ${_var} ${${_var}} PARENT_SCOPE )
endif()
endforeach()

endfunction()
Loading
Loading