Update cmake and make build and conan
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -63,3 +63,4 @@ conandeps*.cmake
|
|||||||
Find*.cmake
|
Find*.cmake
|
||||||
module-*.cmake
|
module-*.cmake
|
||||||
CMakeUserPresets.json
|
CMakeUserPresets.json
|
||||||
|
.claude
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
cmake_minimum_required(VERSION 3.20)
|
cmake_minimum_required(VERSION 3.20)
|
||||||
|
|
||||||
project(Folding
|
project(Folding
|
||||||
|
VERSION 1.1.1
|
||||||
DESCRIPTION "Folding utility for BayesNet library"
|
DESCRIPTION "Folding utility for BayesNet library"
|
||||||
HOMEPAGE_URL "https://github.com/rmontanana/folding"
|
HOMEPAGE_URL "https://github.com/rmontanana/folding"
|
||||||
LANGUAGES CXX
|
LANGUAGES CXX
|
||||||
@@ -25,6 +26,10 @@ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
|
|||||||
# -------
|
# -------
|
||||||
option(ENABLE_TESTING "Unit testing build" OFF)
|
option(ENABLE_TESTING "Unit testing build" OFF)
|
||||||
|
|
||||||
|
# Subdirectories
|
||||||
|
# --------------
|
||||||
|
add_subdirectory(config)
|
||||||
|
|
||||||
# Testing
|
# Testing
|
||||||
# -------
|
# -------
|
||||||
if (ENABLE_TESTING)
|
if (ENABLE_TESTING)
|
||||||
@@ -39,3 +44,55 @@ endif (ENABLE_TESTING)
|
|||||||
# Library
|
# Library
|
||||||
# --------
|
# --------
|
||||||
add_library(folding INTERFACE folding.hpp)
|
add_library(folding INTERFACE folding.hpp)
|
||||||
|
|
||||||
|
target_include_directories(folding INTERFACE
|
||||||
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
||||||
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/configured_files/include>
|
||||||
|
$<INSTALL_INTERFACE:include>
|
||||||
|
)
|
||||||
|
|
||||||
|
# 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
|
||||||
|
)
|
||||||
|
5
cmake/FoldingConfig.cmake.in
Normal file
5
cmake/FoldingConfig.cmake.in
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
@PACKAGE_INIT@
|
||||||
|
|
||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/FoldingTargets.cmake")
|
||||||
|
|
||||||
|
check_required_components(Folding)
|
95
conanfile.py
95
conanfile.py
@@ -1,22 +1,39 @@
|
|||||||
import re
|
import re
|
||||||
from conan import ConanFile
|
from conan import ConanFile
|
||||||
from conan.tools.files import copy
|
from conan.tools.files import copy
|
||||||
from conan.tools.cmake import cmake_layout
|
from conan.tools.cmake import CMakeToolchain, CMakeDeps
|
||||||
|
|
||||||
|
|
||||||
class FoldingConan(ConanFile):
|
class FoldingConan(ConanFile):
|
||||||
name = "folding"
|
name = "folding"
|
||||||
version = "1.1.1"
|
version = "X.X.X"
|
||||||
description = "K-Fold and stratified K-Fold header-only library"
|
description = "K-Fold and stratified K-Fold header-only library"
|
||||||
url = "https://github.com/rmontanana/folding"
|
url = "https://github.com/rmontanana/folding"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
homepage = "https://github.com/rmontanana/folding"
|
homepage = "https://github.com/rmontanana/folding"
|
||||||
topics = ("kfold", "stratified folding", "mdlp")
|
topics = ("kfold", "stratified folding", "mdlp")
|
||||||
no_copy_source = True
|
no_copy_source = True
|
||||||
exports_sources = "folding.hpp"
|
exports_sources = (
|
||||||
|
"folding.hpp",
|
||||||
|
"LICENSE",
|
||||||
|
"README.md",
|
||||||
|
"CMakeLists.txt",
|
||||||
|
"config/*",
|
||||||
|
"cmake/*",
|
||||||
|
)
|
||||||
package_type = "header-library"
|
package_type = "header-library"
|
||||||
settings = "os", "compiler", "build_type", "arch"
|
settings = "build_type", "compiler", "arch", "os"
|
||||||
generators = "CMakeDeps", "CMakeToolchain"
|
|
||||||
|
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):
|
def requirements(self):
|
||||||
self.requires("libtorch/2.7.1")
|
self.requires("libtorch/2.7.1")
|
||||||
@@ -25,15 +42,79 @@ class FoldingConan(ConanFile):
|
|||||||
self.tool_requires("cmake/[>=3.15]")
|
self.tool_requires("cmake/[>=3.15]")
|
||||||
# Test dependencies
|
# Test dependencies
|
||||||
self.test_requires("catch2/3.8.1")
|
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")
|
self.test_requires("fimdlp/2.1.0")
|
||||||
|
|
||||||
def layout(self):
|
def 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)
|
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):
|
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):
|
def package_info(self):
|
||||||
|
# Header-only library configuration
|
||||||
self.cpp_info.bindirs = []
|
self.cpp_info.bindirs = []
|
||||||
self.cpp_info.libdirs = []
|
self.cpp_info.libdirs = []
|
||||||
|
# Set include directory (header will be in package root)
|
||||||
|
self.cpp_info.includedirs = ["."]
|
||||||
|
4
config/CMakeLists.txt
Normal file
4
config/CMakeLists.txt
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
configure_file(
|
||||||
|
"config.h.in"
|
||||||
|
"${CMAKE_BINARY_DIR}/configured_files/include/folding_config.h" ESCAPE_QUOTES
|
||||||
|
)
|
12
config/config.h.in
Normal file
12
config/config.h.in
Normal file
@@ -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/";
|
Reference in New Issue
Block a user