diff --git a/.gitignore b/.gitignore index 0e14676b900cb1418593019be70cc4d20aba2883..9877699f938bdbf94d0383b5b9db6f5f4cf1023e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ # C++ Build build*/ install*/ +include/aidge/backend/cpu_version.h # VSCode .vscode diff --git a/CMakeLists.txt b/CMakeLists.txt index e9e191c36d5ad57a9a9dbed378154db6676ec796..4329d993cf91b5b45d1f5e56c6d4401d277366b8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,15 +3,18 @@ set(CXX_STANDARD 14) file(STRINGS "${CMAKE_SOURCE_DIR}/version.txt" version) +# Parse version.txt to retrieve Major, Minor and Path +string(REGEX MATCH "([0-9]+\\.[0-9]+\\.[0-9]+)" _ MATCHES ${version}) +set(PROJECT_VERSION_MAJOR ${CMAKE_MATCH_1}) +set(PROJECT_VERSION_MINOR ${CMAKE_MATCH_2}) +set(PROJECT_VERSION_PATCH ${CMAKE_MATCH_3}) + project(aidge_backend_cpu VERSION ${version} DESCRIPTION "CPU implementations of the operators of aidge framework." LANGUAGES CXX) -message(STATUS "Project name: ${CMAKE_PROJECT_NAME}") -message(STATUS "Project version: ${version}") -add_definitions(-DPROJECT_VERSION="${version}") - +# Retrieve latest git commit execute_process( COMMAND git rev-parse --short HEAD WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} @@ -19,8 +22,10 @@ execute_process( OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET ) + +message(STATUS "Project name: ${CMAKE_PROJECT_NAME}") +message(STATUS "Project version: ${version}") message(STATUS "Latest git commit: ${GIT_COMMIT_HASH}") -add_definitions(-DGIT_COMMIT_HASH="${GIT_COMMIT_HASH}") # helper for LSP users set(CMAKE_EXPORT_COMPILE_COMMANDS ON) @@ -115,6 +120,13 @@ if(CMAKE_COMPILER_IS_GNUCXX AND COVERAGE) append_coverage_compiler_flags() endif() +message(STATUS "Creating ${CMAKE_CURRENT_SOURCE_DIR}/include/aidge/backend/cpu_version.h") +# Generate version.h file from config file version.h.in +configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/include/aidge/backend/version.h.in" + "${CMAKE_CURRENT_SOURCE_DIR}/include/aidge/backend/cpu_version.h" +) + ############################################## # Installation instructions include(GNUInstallDirs) diff --git a/aidge_backend_cpu/__init__.py b/aidge_backend_cpu/__init__.py index a7fe1ea3abdea25b18af6e7e0a1958f01f928433..bb320b2fe436a3be81dde8d643728bd5a30942e7 100644 --- a/aidge_backend_cpu/__init__.py +++ b/aidge_backend_cpu/__init__.py @@ -1,3 +1,2 @@ import aidge_core from aidge_backend_cpu.aidge_backend_cpu import * # import so generated by PyBind -from ._version import * diff --git a/include/aidge/backend/cpu.hpp b/include/aidge/backend/cpu.hpp index caa75328e58f6c9581f81368a3981bb79a069d49..2223acef71116f761e47cc9ff15e1033a220b0fb 100644 --- a/include/aidge/backend/cpu.hpp +++ b/include/aidge/backend/cpu.hpp @@ -12,6 +12,8 @@ #ifndef AIDGE_CPU_IMPORTS_H_ #define AIDGE_CPU_IMPORTS_H_ +#include "aidge/backend/cpu_version.h" + #include "aidge/backend/cpu/operator/AbsImpl.hpp" #include "aidge/backend/cpu/operator/AddImpl.hpp" #include "aidge/backend/cpu/operator/AndImpl.hpp" diff --git a/include/aidge/backend/version.h.in b/include/aidge/backend/version.h.in new file mode 100644 index 0000000000000000000000000000000000000000..4b876f63002972c1f8f1340b70cdecdace911012 --- /dev/null +++ b/include/aidge/backend/version.h.in @@ -0,0 +1,11 @@ +#ifndef VERSION_H +#define VERSION_H + +namespace Aidge { +static constexpr const int PROJECT_VERSION_MAJOR = @PROJECT_VERSION_MAJOR@; +static constexpr const int PROJECT_VERSION_MINOR = @PROJECT_VERSION_MINOR@; +static constexpr const int PROJECT_VERSION_PATCH = @PROJECT_VERSION_PATCH@; +static constexpr const char * PROJECT_VERSION = "@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@"; +static constexpr const char * PROJECT_GIT_HASH = "@GIT_COMMIT_HASH@"; +} +#endif // VERSION_H diff --git a/include/aidge/utils/sys_info/CpuVersionInfo.hpp b/include/aidge/utils/sys_info/CpuVersionInfo.hpp index 887ce839e079349d9d64505f7184831ffc4cf1c2..3df70d139bd4ad26e0c88d2ee5192e508bc3f71a 100644 --- a/include/aidge/utils/sys_info/CpuVersionInfo.hpp +++ b/include/aidge/utils/sys_info/CpuVersionInfo.hpp @@ -2,17 +2,20 @@ #define AIDGE_UTILS_SYS_INFO_CPU_VERSION_INFO_H #include "aidge/utils/Log.hpp" +#include "aidge/backend/cpu_version.h" namespace Aidge { -#ifndef PROJECT_VERSION // Normally defined in CMakeLists.txt -#define PROJECT_VERSION "Unknown version" -#endif -#ifndef GIT_COMMIT_HASH -#define GIT_COMMIT_HASH "" -#endif -void showCpuVersion() { - Log::info("Aidge backend CPU: {} ({}), {} {}", PROJECT_VERSION, GIT_COMMIT_HASH, __DATE__, __TIME__); +constexpr inline const char * getBackendCPUProjectVersion(){ + return PROJECT_VERSION; +} + +constexpr inline const char * getBackendCPUGitHash(){ + return PROJECT_GIT_HASH; +} + +void showBackendCpuVersion() { + Log::info("Aidge backend CPU: {} ({}), {} {}", getBackendCPUProjectVersion(), getBackendCPUGitHash(), __DATE__, __TIME__); // Compiler version #if defined(__clang__) /* Clang/LLVM. ---------------------------------------------- */ diff --git a/project_name.txt b/project_name.txt new file mode 100644 index 0000000000000000000000000000000000000000..25caafdd8ab794dbcb8c8cdef5097e2143accc6a --- /dev/null +++ b/project_name.txt @@ -0,0 +1 @@ +aidge_backend_cpu diff --git a/pyproject.toml b/pyproject.toml index 3c08302d0fcd4e77943d165fab802a22f4dc39cc..baa61de57375aa97f803efb19bf59973d39ef36f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,17 +7,25 @@ dependencies = [ requires-python = ">= 3.7" readme = "README.md" license = { file = "LICENSE" } -classifiers = [ +classifiers = [ "Development Status :: 2 - Pre-Alpha", "Programming Language :: Python :: 3" ] -dynamic = ["version"] # defined in tool.setuptools_scm +dynamic = ["version"] # defined by pbr + + +[project.urls] +Homepage = "https://www.deepgreen.ai/en/platform" +Documentation = "https://eclipse-aidge.readthedocs.io/en/latest/" +Repository = "https://gitlab.eclipse.org/eclipse/aidge/aidge_backend_cpu" +Issues = "https://gitlab.eclipse.org/eclipse/aidge/aidge_backend_cpu/-/issues" +Changelog = "https://gitlab.eclipse.org/eclipse/aidge/aidge_backend_cpu/-/releases" [build-system] requires = [ "setuptools>=64", - "setuptools_scm[toml]==7.1.0", - "cmake>=3.18.4.post1" + "cmake>=3.18.4.post1", + "pbr" ] build-backend = "setuptools.build_meta" @@ -29,9 +37,6 @@ where = ["."] # list of folders that contain the packages (["."] by default) include = ["aidge_backend_cpu*"] # package names should match these glob patterns (["*"] by default) exclude = ["aidge_backend_cpu.unit_tests*"] # exclude packages matching these glob patterns (empty by default) namespaces = false # to disable scanning PEP 420 namespaces (true by default) -# SETUPTOOLS_SCM -[tool.setuptools_scm] -write_to = "aidge_backend_cpu/_version.py" ##################################################### # CIBUILDWHEEL diff --git a/python_binding/pybind_cpu.cpp b/python_binding/pybind_cpu.cpp index d5022e1d469ae4171e796baed6c1aa061dd95765..e576de0849ec6e0739b7cad32e8e8b003c092b7b 100644 --- a/python_binding/pybind_cpu.cpp +++ b/python_binding/pybind_cpu.cpp @@ -6,10 +6,10 @@ namespace py = pybind11; namespace Aidge { -void init_cpu_sys_info(py::module& m); +void init_CpuVersionInfo(py::module& m); void init_Aidge(py::module& m){ - init_cpu_sys_info(m); + init_CpuVersionInfo(m); } diff --git a/python_binding/utils/sys_info/pybind_CpuVersionInfo.cpp b/python_binding/utils/sys_info/pybind_CpuVersionInfo.cpp index 573bee3659c65f90935e03c06eff5a2998bb9f5b..7461dd955e8b3e64b086a51664b3d73b6bfaed93 100644 --- a/python_binding/utils/sys_info/pybind_CpuVersionInfo.cpp +++ b/python_binding/utils/sys_info/pybind_CpuVersionInfo.cpp @@ -3,7 +3,9 @@ namespace py = pybind11; namespace Aidge { -void init_cpu_sys_info(py::module& m){ - m.def("show_cpu_version", &showCpuVersion); +void init_CpuVersionInfo(py::module& m){ + m.def("show_version", &showBackendCpuVersion); + m.def("get_project_version", &getBackendCPUProjectVersion); + m.def("get_git_hash", &getBackendCPUGitHash); } } diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000000000000000000000000000000000000..aa0f227f6688468a5ab93384f7b1670086000035 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,3 @@ +# pbr file +[metadata] +version = file: version.txt diff --git a/setup.py b/setup.py index 22cbd9732c8b9e1099c3e322032e8377f6d4506b..82edd09c90413f4c81ab3356d57e0380d4eab5ab 100644 --- a/setup.py +++ b/setup.py @@ -11,8 +11,10 @@ from math import ceil from setuptools import setup, Extension from setuptools.command.build_ext import build_ext +def get_project_name() -> str: + return open(pathlib.Path().absolute() / "project_name.txt", "r").read().strip() -PROJECT_NAME = "aidge_backend_cpu" +PROJECT_NAME = get_project_name() SETUP_DIR = pathlib.Path(__file__).parent @@ -66,7 +68,7 @@ class AidgePkgBuild(build_ext): else [] ) test_onoff = os.environ.get("AIDGE_BUILD_TEST", "OFF") - + self.spawn( [ "cmake",