From 6b6a3fa49ff9734cbab9806b5dfae6ccb4c65321 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Montan=CC=83ana?= Date: Wed, 16 Jul 2025 18:48:49 +0200 Subject: [PATCH 1/4] Update cmake and make build and conan --- .gitignore | 1 + CMakeLists.txt | 57 +++++++++++++++++++++ cmake/FoldingConfig.cmake.in | 5 ++ conanfile.py | 97 +++++++++++++++++++++++++++++++++--- config/CMakeLists.txt | 4 ++ config/config.h.in | 12 +++++ 6 files changed, 168 insertions(+), 8 deletions(-) create mode 100644 cmake/FoldingConfig.cmake.in create mode 100644 config/CMakeLists.txt create mode 100644 config/config.h.in diff --git a/.gitignore b/.gitignore index 67a6076..b701197 100644 --- a/.gitignore +++ b/.gitignore @@ -63,3 +63,4 @@ conandeps*.cmake Find*.cmake module-*.cmake CMakeUserPresets.json +.claude diff --git a/CMakeLists.txt b/CMakeLists.txt index 7fc7415..66e96bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,7 @@ cmake_minimum_required(VERSION 3.20) project(Folding + VERSION 1.1.1 DESCRIPTION "Folding utility for BayesNet library" HOMEPAGE_URL "https://github.com/rmontanana/folding" LANGUAGES CXX @@ -25,6 +26,10 @@ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") # ------- option(ENABLE_TESTING "Unit testing build" OFF) +# Subdirectories +# -------------- +add_subdirectory(config) + # Testing # ------- if (ENABLE_TESTING) @@ -39,3 +44,55 @@ endif (ENABLE_TESTING) # Library # -------- add_library(folding INTERFACE folding.hpp) + +target_include_directories(folding INTERFACE + $ + $ + $ +) + +# Install +# ------- +install(TARGETS folding EXPORT FoldingTargets + INCLUDES DESTINATION include +) +install(EXPORT FoldingTargets + FILE FoldingTargets.cmake + NAMESPACE Folding:: + DESTINATION lib/cmake/Folding +) + +# Install the main header file +install(FILES folding.hpp + DESTINATION include +) + +# Install the generated configuration header +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/configured_files/include/folding_config.h" + DESTINATION include +) + +# Install documentation files +install(FILES LICENSE README.md + DESTINATION share/doc/Folding +) + +# Create and install package configuration files +include(CMakePackageConfigHelpers) +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/FoldingConfigVersion.cmake" + VERSION ${PROJECT_VERSION} + COMPATIBILITY AnyNewerVersion +) + +configure_package_config_file( + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/FoldingConfig.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/FoldingConfig.cmake" + INSTALL_DESTINATION lib/cmake/Folding +) + +install(FILES + "${CMAKE_CURRENT_BINARY_DIR}/FoldingConfig.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/FoldingConfigVersion.cmake" + DESTINATION lib/cmake/Folding +) diff --git a/cmake/FoldingConfig.cmake.in b/cmake/FoldingConfig.cmake.in new file mode 100644 index 0000000..3979a56 --- /dev/null +++ b/cmake/FoldingConfig.cmake.in @@ -0,0 +1,5 @@ +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/FoldingTargets.cmake") + +check_required_components(Folding) \ No newline at end of file diff --git a/conanfile.py b/conanfile.py index 00271ee..90161b9 100644 --- a/conanfile.py +++ b/conanfile.py @@ -1,22 +1,39 @@ import re from conan import ConanFile from conan.tools.files import copy -from conan.tools.cmake import cmake_layout +from conan.tools.cmake import CMakeToolchain, CMakeDeps class FoldingConan(ConanFile): name = "folding" - version = "1.1.1" + version = "X.X.X" description = "K-Fold and stratified K-Fold header-only library" url = "https://github.com/rmontanana/folding" license = "MIT" homepage = "https://github.com/rmontanana/folding" topics = ("kfold", "stratified folding", "mdlp") no_copy_source = True - exports_sources = "folding.hpp" + exports_sources = ( + "folding.hpp", + "LICENSE", + "README.md", + "CMakeLists.txt", + "config/*", + "cmake/*", + ) package_type = "header-library" - settings = "os", "compiler", "build_type", "arch" - generators = "CMakeDeps", "CMakeToolchain" + settings = "build_type", "compiler", "arch", "os" + + def init(self): + # Read the CMakeLists.txt file to get the version + with open("CMakeLists.txt", "r") as f: + lines = f.readlines() + for line in lines: + if "VERSION" in line: + # Extract the version number using regex + match = re.search(r"VERSION\s+(\d+\.\d+\.\d+)", line) + if match: + self.version = match.group(1) def requirements(self): self.requires("libtorch/2.7.1") @@ -25,15 +42,79 @@ class FoldingConan(ConanFile): self.tool_requires("cmake/[>=3.15]") # Test dependencies self.test_requires("catch2/3.8.1") - self.test_requires("arff-files/1.2.0") + self.test_requires("arff-files/1.2.1") self.test_requires("fimdlp/2.1.0") def layout(self): - cmake_layout(self) + # Only use cmake_layout for conan packaging, not for development builds + # This can be detected by checking if we're in a conan cache folder + if ( + hasattr(self, "folders") + and hasattr(self.folders, "base_build") + and self.folders.base_build + and ".conan2" in self.folders.base_build + ): + from conan.tools.cmake import cmake_layout + + cmake_layout(self) + + def generate(self): + # Generate CMake toolchain file + tc = CMakeToolchain(self) + tc.generate() + + # Generate CMake dependencies file (needed for test requirements like catch2) + deps = CMakeDeps(self) + deps.generate() + + def build(self): + # Use CMake to generate the config file through existing config system + from conan.tools.cmake import CMake + + cmake = CMake(self) + # Configure with minimal options - just enough to generate the config file + cmake.configure( + build_script_folder=None, + cli_args=["-DENABLE_TESTING=OFF"], + ) + # No need to build anything, just configure to generate the config file def package(self): - copy(self, "*.hpp", src=self.source_folder, dst=self.package_folder) + # Copy header file + copy( + self, + "folding.hpp", + src=self.source_folder, + dst=self.package_folder, + keep_path=False, + ) + # Copy the generated config file from CMake build folder + copy( + self, + "folding_config.h", + src=f"{self.build_folder}/configured_files/include", + dst=self.package_folder, + keep_path=False, + ) + # Copy license and readme for package documentation + copy( + self, + "LICENSE", + src=self.source_folder, + dst=self.package_folder, + keep_path=False, + ) + copy( + self, + "README.md", + src=self.source_folder, + dst=self.package_folder, + keep_path=False, + ) def package_info(self): + # Header-only library configuration self.cpp_info.bindirs = [] self.cpp_info.libdirs = [] + # Set include directory (header will be in package root) + self.cpp_info.includedirs = ["."] diff --git a/config/CMakeLists.txt b/config/CMakeLists.txt new file mode 100644 index 0000000..551a076 --- /dev/null +++ b/config/CMakeLists.txt @@ -0,0 +1,4 @@ +configure_file( + "config.h.in" + "${CMAKE_BINARY_DIR}/configured_files/include/folding_config.h" ESCAPE_QUOTES +) \ No newline at end of file diff --git a/config/config.h.in b/config/config.h.in new file mode 100644 index 0000000..7f6fe40 --- /dev/null +++ b/config/config.h.in @@ -0,0 +1,12 @@ +#pragma once + +#define FOLDING_VERSION_MAJOR @PROJECT_VERSION_MAJOR@ +#define FOLDING_VERSION_MINOR @PROJECT_VERSION_MINOR@ +#define FOLDING_VERSION_PATCH @PROJECT_VERSION_PATCH@ + +#define FOLDING_VERSION "@PROJECT_VERSION@" + +static constexpr std::string_view folding_project_name = "@PROJECT_NAME@"; +static constexpr std::string_view folding_project_version = "@PROJECT_VERSION@"; +static constexpr std::string_view folding_project_description = "@PROJECT_DESCRIPTION@"; +static constexpr std::string_view folding_data_path = "@Folding_SOURCE_DIR@/tests/data/"; \ No newline at end of file From 8b2547aa0209f3eb001d237607c2b760f0e6d9ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Montan=CC=83ana?= Date: Wed, 16 Jul 2025 22:30:05 +0200 Subject: [PATCH 2/4] Complete configuration --- Makefile | 2 +- conanfile.py | 2 +- folding.hpp | 2 +- tests/TestFolding.cc | 3 ++- tests/TestUtils.h | 8 +++++--- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 29dd0f3..f107db6 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,7 @@ build: ## Build a debug version of the project @if [ -d $(f_debug) ]; then rm -rf $(f_debug); fi @mkdir $(f_debug); conan install . -of $(f_debug) -s build_type=Debug -b missing - cmake -B $(f_debug) -S . -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=$(f_debug)/build/Debug/generators/conan_toolchain.cmake -DENABLE_TESTING=ON + cmake -B $(f_debug) -S . -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=$(f_debug)/conan_toolchain.cmake -DENABLE_TESTING=ON cmake --build $(f_debug) -t $(test_targets) $(n_procs) @echo ">>> Done"; diff --git a/conanfile.py b/conanfile.py index 90161b9..d096a62 100644 --- a/conanfile.py +++ b/conanfile.py @@ -43,7 +43,7 @@ class FoldingConan(ConanFile): # Test dependencies self.test_requires("catch2/3.8.1") self.test_requires("arff-files/1.2.1") - self.test_requires("fimdlp/2.1.0") + self.test_requires("fimdlp/2.1.1") def layout(self): # Only use cmake_layout for conan packaging, not for development builds diff --git a/folding.hpp b/folding.hpp index 91a381b..a6f6cc4 100644 --- a/folding.hpp +++ b/folding.hpp @@ -10,8 +10,8 @@ #include #include #include +#include namespace folding { - const std::string FOLDING_VERSION = "1.1.1"; class Fold { public: inline Fold(int k, int n, int seed = -1) : k(k), n(n), seed(seed) diff --git a/tests/TestFolding.cc b/tests/TestFolding.cc index 6ab8159..bbc2469 100644 --- a/tests/TestFolding.cc +++ b/tests/TestFolding.cc @@ -9,10 +9,11 @@ #include #include "TestUtils.h" #include "folding.hpp" +#include TEST_CASE("Version Test", "[Folding]") { - std::string actual_version = "1.1.1"; + std::string actual_version = FOLDING_VERSION; auto data = std::vector(100); folding::StratifiedKFold stratified_kfold(5, data, 17); REQUIRE(stratified_kfold.version() == actual_version); diff --git a/tests/TestUtils.h b/tests/TestUtils.h index 693c695..5b2600c 100644 --- a/tests/TestUtils.h +++ b/tests/TestUtils.h @@ -8,6 +8,7 @@ #include #include "ArffFiles.hpp" #include "fimdlp/CPPFImdlp.h" +#include "folding_config.h" bool file_exists(const std::string& name); std::pair, map> discretize(std::vector& X, mdlp::labels_t& y, std::vector features); @@ -44,11 +45,12 @@ class Paths { public: static std::string datasets() { - return "data/"; + std::string result = { folding_data_path.begin(), folding_data_path.end() }; + return result + "/"; } static std::string csv() { - return "../../tests/csv/"; + return datasets() + "../csv/"; } }; class CSVFiles { @@ -73,4 +75,4 @@ public: return indices; } }; -#endif //TEST_UTILS_H \ No newline at end of file +#endif //TEST_UTILS_H From 0e95aa28fc8546d1180a4268e06ca86bbd44a28d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Montan=CC=83ana?= Date: Sat, 19 Jul 2025 19:37:45 +0200 Subject: [PATCH 3/4] Update version to 1.1.2 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 66e96bd..7a743da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.20) project(Folding - VERSION 1.1.1 + VERSION 1.1.2 DESCRIPTION "Folding utility for BayesNet library" HOMEPAGE_URL "https://github.com/rmontanana/folding" LANGUAGES CXX From a07a215780bbcfb5bdea7f267f9e9c42f949e798 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Montan=CC=83ana?= Date: Sat, 19 Jul 2025 19:44:35 +0200 Subject: [PATCH 4/4] Update changelog --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7df00ba..e8ffe0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.1.2] 2025-07-19 + +### Changed + +- Update cmake and make build and conan integration +- Remove CMakeUserPresets +- Add libtorch 2.7.1 dependency +- Fix conan package version +- Add conan integration for dependency management +- Remove git submodules + ## [1.1.1] 2024-12-13 - Added a new parameter `quiet` to enable/disable the warning messages in the Stratified K-Fold partitioning. Default value `true`.