diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4505aae..b1b560c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,6 +1,14 @@
cmake_minimum_required(VERSION 3.24)
-project(Topologic CXX)
+if (BUILD_VERSION)
+ set(BUILD_VERSION ${BUILD_VERSION})
+ unset(BUILD_VERSION CACHE)
+else()
+ set(BUILD_VERSION 5.0.0) # Default version if not set in BUILD_VERSION.
+endif()
+
+project(Topologic VERSION ${BUILD_VERSION} LANGUAGES CXX)
+message("CMAKE_PROJECT_VERSION=${CMAKE_PROJECT_VERSION}")
# Sub-projects
add_subdirectory(TopologicCore)
diff --git a/TopologicCore/CMakeLists.txt b/TopologicCore/CMakeLists.txt
index ff22e84..afc0304 100644
--- a/TopologicCore/CMakeLists.txt
+++ b/TopologicCore/CMakeLists.txt
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.24)
-project(TopologicCore CXX)
+project(TopologicCore VERSION ${CMAKE_PROJECT_VERSION} LANGUAGES CXX)
set(PROJECT_NAMESPACE Topologic)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
@@ -160,7 +160,11 @@ target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_14)
# Include dir
target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/include)
# Set version: for now sync manually with: TopologicCore/src/About.cpp
-set_target_properties(${PROJECT_NAME} PROPERTIES VERSION "5.0.0" SOVERSION "5")
+string(REGEX MATCH "^([0-9]+)\\." CMAKE_PROJECT_VERSION_MATCH ${CMAKE_PROJECT_VERSION})
+set(BUILD_SOVERSION ${CMAKE_MATCH_1}) # Set "5" if project version is "5.0.0".
+set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${CMAKE_PROJECT_VERSION} SOVERSION ${BUILD_SOVERSION})
+include_directories(${CMAKE_BINARY_DIR})
+configure_file("TopologicConfig.h.in" "${CMAKE_BINARY_DIR}/TopologicConfig.h")
# Dependency: OpenCASCADE
find_package(OpenCASCADE REQUIRED)
diff --git a/TopologicCore/TopologicConfig.h.in b/TopologicCore/TopologicConfig.h.in
new file mode 100644
index 0000000..cae9b67
--- /dev/null
+++ b/TopologicCore/TopologicConfig.h.in
@@ -0,0 +1,16 @@
+#pragma once
+
+#define PROJECT_NAME "@PROJECT_NAME@"
+#define PROJECT_VERSION "@PROJECT_VERSION@"
+#define MAJOR_VERSION @PROJECT_VERSION_MAJOR@
+#define MINOR_VERSION @PROJECT_VERSION_MINOR@
+#define BUGFIX_VERSION @PROJECT_VERSION_PATCH@
+#define INTERNAL_BUILD_VERSION_ @PROJECT_VERSION_TWEAK@
+
+#if ~(~INTERNAL_BUILD_VERSION_ + 0) == 0 && ~(~INTERNAL_BUILD_VERSION_ + 1) == 1
+ // INTERNAL_BUILD_VERSION_ is defined, but its value is "empty".
+# define INTERNAL_BUILD_VERSION 0
+#else
+# define INTERNAL_BUILD_VERSION INTERNAL_BUILD_VERSION_
+#endif
+#undef INTERNAL_BUILD_VERSION_
diff --git a/TopologicCore/src/About.cpp b/TopologicCore/src/About.cpp
index 037f7d9..35bea89 100644
--- a/TopologicCore/src/About.cpp
+++ b/TopologicCore/src/About.cpp
@@ -15,11 +15,7 @@
// along with this program. If not, see .
#include "About.h"
-
-#define MAJOR_VERSION 5
-#define MINOR_VERSION 0
-#define BUGFIX_VERSION 0
-#define INTERNAL_BUILD_VERSION 1
+#include "TopologicConfig.h"
namespace TopologicCore
{
diff --git a/TopologicPythonBindings/setup.py b/TopologicPythonBindings/setup.py
index 404bfca..f1b8998 100644
--- a/TopologicPythonBindings/setup.py
+++ b/TopologicPythonBindings/setup.py
@@ -6,7 +6,7 @@
from setuptools import Extension, setup
from setuptools.command.build_ext import build_ext
-
+from setuptools.dist import Distribution
# taken from: https://github.com/pybind/cmake_example/blob/master/setup.py
# A CMakeExtension needs a sourcedir instead of a file list.
@@ -55,6 +55,7 @@ def build_extension(self, ext: CMakeExtension) -> None:
"--source-dir", source_dir,
"--build-dir", build_dir, "--install-to", install_to,
"--build-target", build_target, "--install-component", install_component,
+ "--build-version", self.distribution.get_version(),
"--extra-cmake-args", extra_cmake_args],
check=True
)
@@ -79,9 +80,33 @@ def build_options():
}
return {};
-setup(
+def try_read_actual_version(default_version):
+ if "TOPOLOGIC_VERSION" in os.environ:
+ return os.environ["TOPOLOGIC_VERSION"]
+ return default_version
+
+def print_wheel_name_to_output(**kwargs):
+ if "TOPOLOGIC_OUTPUT_ID" not in os.environ:
+ return
+ output_name = os.environ["TOPOLOGIC_OUTPUT_ID"];
+ if not output_name.isalnum():
+ return
+ output_name += '.log'
+
+ dist = Distribution(attrs=kwargs)
+ command_obj = dist.get_command_obj('bdist_wheel')
+ command_obj.ensure_finalized()
+ dist_name = command_obj.wheel_dist_name
+ tag = '-'.join(command_obj.get_tag())
+ f = open(output_name, "w")
+ wheel_name = f"{dist_name}-{tag}.whl"
+ print(f"Expected wheel name is {wheel_name} (WHEEL_NAME={wheel_name})");
+ f.write(f'WHEEL_NAME={wheel_name}\n');
+ f.close()
+
+setup_kwargs = dict(
name="topologic",
- version="5.0.0", # for now sync manually with: TopologicCore/CMakeLists.txt and TopologicCore/src/About.cpp
+ version=try_read_actual_version(default_version="5.0.0"), # Syncs with: TopologicCore/CMakeLists.txt and TopologicCore/src/About.cpp
author="Topologic Authors",
author_email="None",
description="TopologicPythonBindings wrapper package",
@@ -94,4 +119,7 @@ def build_options():
extras_require={},
python_requires=">=3.8",
options=build_options()
-)
+);
+
+print_wheel_name_to_output(**setup_kwargs)
+setup(**setup_kwargs)
diff --git a/build.py b/build.py
index bfa47c0..5f30c23 100644
--- a/build.py
+++ b/build.py
@@ -61,7 +61,7 @@ def _cmd_install(args):
def build_win32(args):
# letting cmake decide the generator on windows
- cmd = f"cmake -S '{args.source_dir}' -B '{args.build_dir}' -DCMAKE_BUILD_TYPE='{args.build_type}' -DCMAKE_CONFIGURATION_TYPES='{args.build_type}'"
+ cmd = f"cmake -S '{args.source_dir}' -B '{args.build_dir}' -DCMAKE_BUILD_TYPE='{args.build_type}' -DCMAKE_CONFIGURATION_TYPES='{args.build_type}' -DBUILD_VERSION='{args.build_version}'"
cmd = _cmd_gen_add_extra_args(cmd, args)
syscmd(cmd)
cmd = f"cmake --build '{args.build_dir}' --config '{args.build_type}'"
@@ -73,7 +73,7 @@ def build_win32(args):
def build_linux(args):
# use ninja on linux
- cmd = f"cmake -S '{args.source_dir}' -G Ninja -B '{args.build_dir}' -DCMAKE_BUILD_TYPE='{args.build_type}'"
+ cmd = f"cmake -S '{args.source_dir}' -G Ninja -B '{args.build_dir}' -DCMAKE_BUILD_TYPE='{args.build_type}' -DBUILD_VERSION='{args.build_version}'"
cmd = _cmd_gen_add_extra_args(cmd, args)
syscmd(cmd)
cmd = f"cmake --build '{args.build_dir}'"
@@ -85,7 +85,7 @@ def build_linux(args):
def build_darwin(args):
# use ninja on moacos
- cmd = f"cmake -S '{args.source_dir}' -G Ninja -B '{args.build_dir}' -DCMAKE_BUILD_TYPE='{args.build_type}'"
+ cmd = f"cmake -S '{args.source_dir}' -G Ninja -B '{args.build_dir}' -DCMAKE_BUILD_TYPE='{args.build_type}' -DBUILD_VERSION='{args.build_version}'"
cmd = _cmd_gen_add_extra_args(cmd, args)
syscmd(cmd)
cmd = f"cmake --build '{args.build_dir}'"
@@ -138,6 +138,7 @@ def script():
p.add_argument("--install-component", required=False, metavar="")
p.add_argument("--dry-run", action='store_true')
p.add_argument("--verbose", action='store_true')
+ p.add_argument("--build-version", required=False, metavar="")
p.add_argument('--extra-cmake-args', nargs=argparse.REMAINDER, metavar="")
args = p.parse_args()