3 Commits

3 changed files with 31 additions and 52 deletions

3
.gitignore vendored
View File

@@ -37,4 +37,5 @@ build_*/**
cmake-build*/** cmake-build*/**
.idea .idea
puml/** 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" homepage = "https://github.com/rmontanana/ArffFiles"
topics = ("arff", "data-processing", "file-parsing", "header-only", "cpp17") topics = ("arff", "data-processing", "file-parsing", "header-only", "cpp17")
no_copy_source = True 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" package_type = "header-library"
settings = "build_type", "compiler", "arch", "os" settings = "build_type", "compiler", "arch", "os"
@@ -34,58 +41,38 @@ class ArffFilesConan(ConanFile):
self.test_requires("catch2/3.8.1") self.test_requires("catch2/3.8.1")
def layout(self): def layout(self):
# Use cmake_layout for proper build folder structure # Only use cmake_layout for conan packaging, not for development builds
from conan.tools.cmake import cmake_layout # This can be detected by checking if we're in a conan cache folder
cmake_layout(self) 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): def generate(self):
# Generate CMake toolchain file # Generate CMake toolchain file
tc = CMakeToolchain(self) tc = CMakeToolchain(self)
tc.generate() tc.generate()
# Generate CMake dependencies file (needed for test requirements like catch2) # Generate CMake dependencies file (needed for test requirements like catch2)
deps = CMakeDeps(self) deps = CMakeDeps(self)
deps.generate() 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): def build(self):
# Use CMake to generate the config file through existing config system # Use CMake to generate the config file through existing config system
from conan.tools.cmake import CMake from conan.tools.cmake import CMake
import os
cmake = CMake(self)
# Temporarily rename the files to use minimal CMakeLists.txt # Configure with minimal options - just enough to generate the config file
original_cmake = os.path.join(self.source_folder, "CMakeLists.txt") cmake.configure(
minimal_cmake = os.path.join(self.source_folder, "CMakeLists_conan.txt") build_script_folder=None,
backup_cmake = os.path.join(self.source_folder, "CMakeLists_backup.txt") cli_args=["-DENABLE_TESTING=OFF", "-DCODE_COVERAGE=OFF"],
)
# Backup and replace # No need to build anything, just configure to generate the config file
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)
def package(self): def package(self):
# Copy header file # Copy header file