Compare commits

2 Commits

Author SHA1 Message Date
e2ac5fde12 Fix conan build and make build 2025-07-16 18:34:33 +02:00
332324a6c2 Remove CMakeUserPresets 2025-07-16 17:52:57 +02:00
3 changed files with 31 additions and 52 deletions

3
.gitignore vendored
View File

@@ -37,4 +37,5 @@ build_*/**
cmake-build*/**
.idea
puml/**
.vscode/settings.json
.vscode/settings.json
CMakeUserPresets.json

View File

@@ -1,9 +0,0 @@
{
"version": 4,
"vendor": {
"conan": {}
},
"include": [
"build_debug/build/Debug/generators/CMakePresets.json"
]
}

View File

@@ -14,7 +14,14 @@ class ArffFilesConan(ConanFile):
homepage = "https://github.com/rmontanana/ArffFiles"
topics = ("arff", "data-processing", "file-parsing", "header-only", "cpp17")
no_copy_source = True
exports_sources = ("ArffFiles.hpp", "LICENSE", "README.md", "CMakeLists.txt", "config/*")
exports_sources = (
"ArffFiles.hpp",
"LICENSE",
"README.md",
"CMakeLists.txt",
"config/*",
"cmake/*",
)
package_type = "header-library"
settings = "build_type", "compiler", "arch", "os"
@@ -34,58 +41,38 @@ class ArffFilesConan(ConanFile):
self.test_requires("catch2/3.8.1")
def layout(self):
# Use cmake_layout for proper build folder structure
from conan.tools.cmake import cmake_layout
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()
# Create a minimal CMakeLists.txt for conan build that only generates config
import os
minimal_cmake = """cmake_minimum_required(VERSION 3.20)
project(ArffFiles
VERSION 1.2.1
DESCRIPTION "Library to read Arff Files and return STL vectors with the data read."
HOMEPAGE_URL "https://github.com/rmontanana/ArffFiles"
LANGUAGES CXX
)
# Subdirectories
add_subdirectory(config)
"""
with open(os.path.join(self.source_folder, "CMakeLists_conan.txt"), "w") as f:
f.write(minimal_cmake)
def build(self):
# Use CMake to generate the config file through existing config system
from conan.tools.cmake import CMake
import os
# Temporarily rename the files to use minimal CMakeLists.txt
original_cmake = os.path.join(self.source_folder, "CMakeLists.txt")
minimal_cmake = os.path.join(self.source_folder, "CMakeLists_conan.txt")
backup_cmake = os.path.join(self.source_folder, "CMakeLists_backup.txt")
# Backup and replace
os.rename(original_cmake, backup_cmake)
os.rename(minimal_cmake, original_cmake)
try:
cmake = CMake(self)
cmake.configure()
# No need to build anything, just configure to generate the config file
finally:
# Restore original files
os.rename(original_cmake, minimal_cmake)
os.rename(backup_cmake, original_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", "-DCODE_COVERAGE=OFF"],
)
# No need to build anything, just configure to generate the config file
def package(self):
# Copy header file