Fix conan build and remove vcpkg

This commit is contained in:
2025-07-01 13:56:28 +02:00
parent 3178bcbda9
commit 3cb454d4aa
20 changed files with 101 additions and 320 deletions

View File

@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- *ld_proposed_cuts*: number of cut points to return.
- *mdlp_min_length*: minimum length of a partition in MDLP algorithm to be evaluated for partition.
- *mdlp_max_depth*: maximum level of recursion in MDLP algorithm.
- Remove vcpkg as a dependency manager, now the library is built with Conan package manager and CMake.
## [1.1.1] - 2025-05-20

View File

@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.27)
project(bayesnet
VERSION 1.1.2
VERSION 1.2.0
DESCRIPTION "Bayesian Network and basic classifiers Library."
HOMEPAGE_URL "https://github.com/rmontanana/bayesnet"
LANGUAGES CXX
@@ -28,18 +28,11 @@ endif()
# -------
option(ENABLE_TESTING "Unit testing build" OFF)
option(CODE_COVERAGE "Collect coverage from test library" OFF)
option(USING_CONAN "Use Conan package manager" OFF)
if(USING_CONAN)
message(STATUS "Using Conan package manager")
else(USING_CONAN)
message(STATUS "Using vcpkg package manager")
endif(USING_CONAN)
find_package(Torch CONFIG REQUIRED)
if(NOT TARGET torch::torch)
add_library(torch::torch INTERFACE IMPORTED GLOBAL)
# expose include paths and libraries that the find-module discovered
set_target_properties(torch::torch PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${TORCH_INCLUDE_DIRS}"
@@ -81,17 +74,7 @@ endif (CMAKE_BUILD_TYPE STREQUAL "Debug")
if (ENABLE_TESTING)
MESSAGE(STATUS "Testing enabled")
find_package(Catch2 CONFIG REQUIRED)
# Handle arff-files conditionally for different package managers
if(NOT USING_CONAN)
find_package(arff-files CONFIG REQUIRED)
else()
find_package(arff-files CONFIG QUIET)
if(NOT arff-files_FOUND)
message(WARNING "arff-files not found - you may need to create a custom Conan recipe")
endif()
endif()
enable_testing()
include(CTest)
add_subdirectory(tests)

View File

@@ -5,8 +5,8 @@
},
"include": [
"build/Release/generators/CMakePresets.json",
"build_Release/build/Release/generators/CMakePresets.json",
"build_Debug/build/Debug/generators/CMakePresets.json",
"build_Debug/build/Release/generators/CMakePresets.json"
"build_Debug/build/Release/generators/CMakePresets.json",
"build_Release/build/Release/generators/CMakePresets.json"
]
}

View File

@@ -6,6 +6,8 @@ This document explains how to use Conan as an alternative package manager for Ba
```bash
pip install conan
conan remote add Cimmeria https://conan.rmontanana.es/artifactory/api/conan/Cimmeria
conan profile new default --detect
```
## Quick Start
@@ -13,25 +15,26 @@ pip install conan
### As a Consumer
1. Create a `conanfile.txt` in your project:
```ini
[requires]
bayesnet/1.1.2@user/channel
libtorch/2.7.0
bayesnet/1.2.0
[generators]
CMakeDeps
CMakeToolchain
[options]
[imports]
```
2. Install dependencies:
```bash
conan install . --build=missing
```
3. In your CMakeLists.txt:
```cmake
find_package(bayesnet REQUIRED)
target_link_libraries(your_target bayesnet::bayesnet)
@@ -44,11 +47,11 @@ target_link_libraries(your_target bayesnet::bayesnet)
make conan-init
# Build debug version
make conan-debug
make debug
make buildd
# Build release version
make conan-release
make release
make buildr
# Create package
@@ -80,5 +83,5 @@ Once custom dependencies are resolved:
make conan-create
# Upload to your remote
conan upload bayesnet/1.1.2@user/channel -r myremote
conan upload bayesnet/1.2.0 -r myremote
```

View File

@@ -1,6 +1,6 @@
SHELL := /bin/bash
.DEFAULT_GOAL := help
.PHONY: viewcoverage coverage setup help install uninstall diagrams buildr buildd test clean vcpkg-debug vcpkg-release vcpkg-sample updatebadge doc doc-install init clean-test conan-debug conan-release conan-create conan-upload conan-clean conan-sample
.PHONY: viewcoverage coverage setup help install uninstall diagrams buildr buildd test clean updatebadge doc doc-install init clean-test conan-debug conan-release conan-create conan-upload conan-clean conan-sample
f_release = build_Release
f_debug = build_Debug
@@ -189,14 +189,7 @@ doc-install: ## Install documentation
# Conan package manager targets
# =============================
# conan-debug: ## Build debug version using Conan
# @echo ">>> Building Debug BayesNet with Conan..."
# @if [ -d ./$(f_debug) ]; then rm -rf ./$(f_debug); fi
# @mkdir $(f_debug)
# @conan install . -s build_type=Debug --build=missing -of $(f_debug)
# @cmake -S . -B $(f_debug) -D CMAKE_BUILD_TYPE=Debug -D ENABLE_TESTING=ON -D CODE_COVERAGE=ON -D USING_CONAN=ON -DCMAKE_TOOLCHAIN_FILE=$(f_debug)/build/Debug/generators/conan_toolchain.cmake
# @echo ">>> Done"
conan-debug: ## Build debug version using Conan
debug: ## Build debug version using Conan
@echo ">>> Building *Debug* BayesNet with Conan..."
@rm -rf $(f_debug) # wipe previous tree
@conan install . \
@@ -208,11 +201,10 @@ conan-debug: ## Build debug version using Conan
-DCMAKE_BUILD_TYPE=Debug \
-DENABLE_TESTING=ON \
-DCODE_COVERAGE=ON \
-DUSING_CONAN=ON \
-DCMAKE_TOOLCHAIN_FILE=$(f_debug)/build/Debug/generators/conan_toolchain.cmake
@echo ">>> Done"
conan-release: ## Build release version using Conan
release: ## Build release version using Conan
@echo ">>> Building Release BayesNet with Conan..."
@conan install . \
-s build_type=Release \
@@ -222,18 +214,18 @@ conan-release: ## Build release version using Conan
@if [ -d ./$(f_release) ]; then rm -rf ./$(f_release); fi
@mkdir $(f_release)
@conan install . -s build_type=Release --build=missing -of $(f_release)
@cmake -S . -B $(f_release) -D CMAKE_BUILD_TYPE=Release -D USING_CONAN=ON -DCMAKE_TOOLCHAIN_FILE=$(f_release)/build/Release/generators/conan_toolchain.cmake
@cmake -S . -B $(f_release) -D CMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=$(f_release)/build/Release/generators/conan_toolchain.cmake
@echo ">>> Done"
conan-create: ## Create Conan package
@echo ">>> Creating Conan package..."
@conan create . --build=missing -tf "" --profile=release
@conan create . --build=missing -tf "" --profile=release -tf ""
@conan create . --build=missing -tf "" --profile=debug
@echo ">>> Done"
profile ?= default
profile ?= release
remote ?= Cimmeria
conan-upload: ## Upload package to Conan remote (profile=default remote=conancenter)
conan-upload: ## Upload package to Conan remote (profile=release remote=Cimmeria)
@echo ">>> Uploading to Conan remote $(remote) with profile $(profile)..."
@conan upload bayesnet/$(grep version conanfile.py | cut -d'"' -f2) -r $(remote) --confirm
@echo ">>> Done"
@@ -247,7 +239,7 @@ conan-clean: ## Clean Conan cache and build folders
fname = "tests/data/iris.arff"
model = "TANLd"
conan-sample: ## Build sample with Conan
sample: ## Build sample with Conan
@echo ">>> Building Sample with Conan...";
@if [ -d ./sample/build ]; then rm -rf ./sample/build; fi
@cd sample && conan install . --output-folder=build --build=missing
@@ -256,38 +248,6 @@ conan-sample: ## Build sample with Conan
sample/build/bayesnet_sample $(fname) $(model)
@echo ">>> Done";
# vcpkg package manager targets
# =============================
vcpkg-init: ## Initialize the project installing dependencies using vcpkg
@echo ">>> Installing dependencies with vcpkg"
@vcpkg install
@echo ">>> Done";
vcpkg-debug: ## Build a debug version of the project using vcpkg
@echo ">>> Building Debug BayesNet with vcpkg...";
@if [ -d ./$(f_debug) ]; then rm -rf ./$(f_debug); fi
@mkdir $(f_debug);
@cmake -S . -B $(f_debug) -D CMAKE_BUILD_TYPE=Debug -D ENABLE_TESTING=ON -D CODE_COVERAGE=ON -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake
@echo ">>> Done";
vcpkg-release: ## Build a Release version of the project using vcpkg
@echo ">>> Building Release BayesNet with vcpkg...";
@if [ -d ./$(f_release) ]; then rm -rf ./$(f_release); fi
@mkdir $(f_release);
@cmake -S . -B $(f_release) -D CMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake
@echo ">>> Done";
fname = "tests/data/iris.arff"
model = "TANLd"
vcpkg-sample: ## Build sample with vcpkg
@echo ">>> Building Sample with vcpkg...";
@if [ -d ./sample/build ]; then rm -rf ./sample/build; fi
@cd sample && cmake -B build -S . -D CMAKE_BUILD_TYPE=Release -DUSING_VCPKG=ON -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake && \
cmake --build build -t bayesnet_sample
sample/build/bayesnet_sample $(fname) $(model)
@echo ">>> Done";
# Help target
# ===========

116
README.md
View File

@@ -13,114 +13,114 @@
Bayesian Network Classifiers library
## Setup
## Using the Library
### Using the vcpkg library
### Using Conan Package Manager
You can use the library with the vcpkg library manager. In your project you have to add the following files:
You can use the library with the [Conan](https://conan.io/) package manager. In your project you need to add the following files:
#### vcpkg.json
#### conanfile.txt
```json
{
"name": "sample-project",
"version-string": "0.1.0",
"dependencies": [
"bayesnet"
]
}
```
```txt
[requires]
bayesnet/1.1.2
#### vcpkg-configuration.json
```json
{
"registries": [
{
"kind": "git",
"repository": "https://github.com/rmontanana/vcpkg-stash",
"baseline": "393efa4e74e053b6f02c4ab03738c8fe796b28e5",
"packages": [
"folding",
"bayesnet",
"arff-files",
"fimdlp",
"libtorch-bin"
]
}
],
"default-registry": {
"kind": "git",
"repository": "https://github.com/microsoft/vcpkg",
"baseline": "760bfd0c8d7c89ec640aec4df89418b7c2745605"
}
}
[generators]
CMakeDeps
CMakeToolchain
```
#### CMakeLists.txt
You have to include the following lines in your `CMakeLists.txt` file:
Include the following lines in your `CMakeLists.txt` file:
```cmake
find_package(bayesnet CONFIG REQUIRED)
find_package(bayesnet REQUIRED)
add_executable(myapp main.cpp)
target_link_libraries(myapp PRIVATE bayesnet::bayesnet)
```
After that, you can use the `vcpkg` command to install the dependencies:
Then install the dependencies and build your project:
```bash
vcpkg install
conan install . --output-folder=build --build=missing
cmake -B build -S . -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake
cmake --build build
```
**Note: In the `sample` folder you can find a sample application that uses the library. You can use it as a reference to create your own application.**
## Playing with the library
## Building and Testing
The dependencies are managed with [vcpkg](https://vcpkg.io/) and supported by a private vcpkg repository in [https://github.com/rmontanana/vcpkg-stash](https://github.com/rmontanana/vcpkg-stash).
The project uses [Conan](https://conan.io/) for dependency management and provides convenient Makefile targets for common tasks.
### Prerequisites
- [Conan](https://conan.io/) package manager (`pip install conan`)
- CMake 3.27+
- C++17 compatible compiler
### Getting the code
```bash
git clone https://github.com/doctorado-ml/bayesnet
cd bayesnet
```
Once you have the code, you can use the `make` command to build the project. The `Makefile` is used to manage the build process and it will automatically download and install the dependencies.
### Build Commands
### Release
#### Release Build
```bash
make init # Install dependencies
make release # Build the release version
make buildr # compile and link the release version
make release # Configure release build with Conan
make buildr # Build the release version
```
### Debug & Tests
#### Debug Build & Tests
```bash
make init # Install dependencies
make debug # Build the debug version
make debug # Configure debug build with Conan
make buildd # Build the debug version
make test # Run the tests
```
### Coverage
#### Coverage Analysis
```bash
make coverage # Run the tests with coverage
make viewcoverage # View the coverage report in the browser
make coverage # Run tests with coverage analysis
make viewcoverage # View coverage report in browser
```
### Sample app
#### Sample Application
After building and installing the release version, you can run the sample app with the following commands:
Run the sample application with different datasets and models:
```bash
make sample
make sample fname=tests/data/glass.arff
make sample # Run with default settings
make sample fname=tests/data/glass.arff # Use glass dataset
make sample fname=tests/data/iris.arff model=AODE # Use specific model
```
### Available Makefile Targets
- `debug` - Configure debug build using Conan
- `release` - Configure release build using Conan
- `buildd` - Build debug targets
- `buildr` - Build release targets
- `test` - Run all tests (use `opt="-s"` for verbose output)
- `coverage` - Generate test coverage report
- `viewcoverage` - Open coverage report in browser
- `sample` - Build and run sample application
- `conan-create` - Create Conan package
- `conan-upload` - Upload package to Conan remote
- `conan-clean` - Clean Conan cache and build folders
- `clean` - Clean all build artifacts
- `doc` - Generate documentation
- `diagrams` - Generate UML diagrams
- `help` - Show all available targets
## Models
#### - TAN

View File

@@ -1,13 +1,10 @@
import os, re, pathlib
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps
from conan.tools.files import copy, save
import os
from conan.tools.files import copy
class BayesNetConan(ConanFile):
name = "bayesnet"
version = "1.2.0"
# Binary configuration
settings = "os", "compiler", "build_type", "arch"
options = {
"shared": [True, False],
@@ -25,6 +22,21 @@ class BayesNetConan(ConanFile):
# Sources are located in the same place as this recipe, copy them to the recipe
exports_sources = "CMakeLists.txt", "bayesnet/*", "config/*", "cmake/*", "docs/*", "tests/*", "bayesnetConfig.cmake.in"
def set_version(self) -> None:
cmake = pathlib.Path(self.recipe_folder) / "CMakeLists.txt"
text = cmake.read_text(encoding="utf-8")
# Accept either: project(foo VERSION 1.2.3) or set(foo_VERSION 1.2.3)
match = re.search(
r"""project\s*\([^\)]*VERSION\s+([0-9]+\.[0-9]+\.[0-9]+)""",
text, re.IGNORECASE | re.VERBOSE
)
if match:
self.version = match.group(1)
else:
raise Exception("Version not found in CMakeLists.txt")
self.version = match.group(1)
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

View File

@@ -11,25 +11,6 @@ find_package(arff-files CONFIG REQUIRED)
find_package(nlohmann_json REQUIRED)
find_package(bayesnet CONFIG REQUIRED)
# option(USING_VCPKG "Use vcpkg config for BayesNet" OFF)
# option(USING_CONAN "Use Conan config for BayesNet" OFF)
# if (USING_VCPKG OR USING_CONAN)
# message(STATUS "Using BayesNet vcpkg config")
# find_package(bayesnet CONFIG REQUIRED)
# set(BayesNet_LIBRARIES bayesnet::bayesnet)
# else(USING_VCPKG)
# message(STATUS "Using BayesNet local library config")
# find_library(bayesnet NAMES libbayesnet bayesnet libbayesnet.a PATHS ${Platform_SOURCE_DIR}/../lib/lib REQUIRED)
# find_path(Bayesnet_INCLUDE_DIRS REQUIRED NAMES bayesnet PATHS ${Platform_SOURCE_DIR}/../lib/include)
# add_library(bayesnet::bayesnet UNKNOWN IMPORTED)
# set_target_properties(bayesnet::bayesnet PROPERTIES
# IMPORTED_LOCATION ${bayesnet}
# INTERFACE_INCLUDE_DIRECTORIES ${Bayesnet_INCLUDE_DIRS}
# )
# endif(USING_VCPKG)
# message(STATUS "BayesNet: ${bayesnet}")
add_executable(bayesnet_sample sample.cc)
target_link_libraries(bayesnet_sample PRIVATE
fimdlp::fimdlp

View File

@@ -1,9 +0,0 @@
cmake_minimum_required(VERSION 3.27)
project(test_bayesnet)
set(CMAKE_CXX_STANDARD 17)
find_package(bayesnet REQUIRED)
add_executable(test_bayesnet test_bayesnet.cpp)
target_link_libraries(test_bayesnet bayesnet::bayesnet)

View File

@@ -1 +0,0 @@
. "/home/rmontanana/Code/BayesNet/test_package/build/gcc-14-x86_64-gnu17-release/generators/conanbuildenv-release-x86_64.sh"

View File

@@ -1,16 +0,0 @@
script_folder="/home/rmontanana/Code/BayesNet/test_package/build/gcc-14-x86_64-gnu17-release/generators"
echo "echo Restoring environment" > "$script_folder/deactivate_conanbuildenv-release-x86_64.sh"
for v in PATH
do
is_defined="true"
value=$(printenv $v) || is_defined="" || true
if [ -n "$value" ] || [ -n "$is_defined" ]
then
echo export "$v='$value'" >> "$script_folder/deactivate_conanbuildenv-release-x86_64.sh"
else
echo unset $v >> "$script_folder/deactivate_conanbuildenv-release-x86_64.sh"
fi
done
export PATH="/home/rmontanana/.conan2/p/cmakeab16c849c207b/p/bin:$PATH"

View File

@@ -1 +0,0 @@
. "/home/rmontanana/Code/BayesNet/test_package/build/gcc-14-x86_64-gnu17-release/generators/conanrunenv-release-x86_64.sh"

View File

@@ -1,17 +0,0 @@
script_folder="/home/rmontanana/Code/BayesNet/test_package/build/gcc-14-x86_64-gnu17-release/generators"
echo "echo Restoring environment" > "$script_folder/deactivate_conanrunenv-release-x86_64.sh"
for v in LD_LIBRARY_PATH DYLD_LIBRARY_PATH
do
is_defined="true"
value=$(printenv $v) || is_defined="" || true
if [ -n "$value" ] || [ -n "$is_defined" ]
then
echo export "$v='$value'" >> "$script_folder/deactivate_conanrunenv-release-x86_64.sh"
else
echo unset $v >> "$script_folder/deactivate_conanrunenv-release-x86_64.sh"
fi
done
export LD_LIBRARY_PATH="/home/rmontanana/.conan2/p/libto33fc3f5110c64/p/lib:$LD_LIBRARY_PATH"
export DYLD_LIBRARY_PATH="/home/rmontanana/.conan2/p/libto33fc3f5110c64/p/lib:$DYLD_LIBRARY_PATH"

View File

@@ -1 +0,0 @@
. "/home/rmontanana/Code/BayesNet/test_package/build/gcc-14-x86_64-gnu17-release/generators/deactivate_conanbuildenv-release-x86_64.sh"

View File

@@ -1 +0,0 @@
. "/home/rmontanana/Code/BayesNet/test_package/build/gcc-14-x86_64-gnu17-release/generators/deactivate_conanrunenv-release-x86_64.sh"

View File

@@ -1,26 +0,0 @@
from conan import ConanFile
from conan.tools.cmake import CMake, cmake_layout
from conan.tools.build import can_run
import os
class BayesNetTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
def requirements(self):
self.requires(self.tested_reference_str)
def build_requirements(self):
self.build_requires("cmake/[>=3.27]")
def layout(self):
cmake_layout(self)
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
def test(self):
if can_run(self):
cmd = os.path.join(self.cpp.build.bindirs[0], "test_bayesnet")
self.run(cmd, env="conanrun")

View File

@@ -1,26 +0,0 @@
#include <iostream>
#include <bayesnet/BaseClassifier.h>
#include <bayesnet/classifiers/TAN.h>
#include <bayesnet/network/Network.h>
int main() {
std::cout << "Testing BayesNet library integration..." << std::endl;
try {
// Test basic instantiation
bayesnet::Network network;
std::cout << "✓ Network class instantiated successfully" << std::endl;
// Test TAN classifier instantiation
bayesnet::TAN tan;
std::cout << "✓ TAN classifier instantiated successfully" << std::endl;
std::cout << "✓ All basic tests passed!" << std::endl;
std::cout << "BayesNet library is working correctly." << std::endl;
return 0;
} catch (const std::exception& e) {
std::cerr << "✗ Test failed: " << e.what() << std::endl;
return 1;
}
}

View File

@@ -20,7 +20,7 @@
#include "bayesnet/ensembles/AODELd.h"
#include "bayesnet/ensembles/BoostAODE.h"
const std::string ACTUAL_VERSION = "1.1.2";
const std::string ACTUAL_VERSION = "1.2.0";
TEST_CASE("Test Bayesian Classifiers score & version", "[Models]")
{

View File

@@ -1,21 +0,0 @@
{
"default-registry": {
"kind": "git",
"baseline": "760bfd0c8d7c89ec640aec4df89418b7c2745605",
"repository": "https://github.com/microsoft/vcpkg"
},
"registries": [
{
"kind": "git",
"repository": "https://github.com/rmontanana/vcpkg-stash",
"baseline": "1ea69243c0e8b0de77c9d1dd6e1d7593ae7f3627",
"packages": [
"arff-files",
"fimdlp",
"libtorch-bin",
"bayesnet",
"folding"
]
}
]
}

View File

@@ -1,40 +0,0 @@
{
"name": "bayesnet",
"version": "1.0.7",
"description": "Bayesian Network C++ Library",
"license": "MIT",
"dependencies": [
"arff-files",
"folding",
"fimdlp",
"libtorch-bin",
"nlohmann-json",
"catch2"
],
"overrides": [
{
"name": "arff-files",
"version": "1.1.0"
},
{
"name": "fimdlp",
"version": "2.0.1"
},
{
"name": "libtorch-bin",
"version": "2.7.0"
},
{
"name": "folding",
"version": "1.1.1"
},
{
"name": "nlohmann-json",
"version": "3.11.3"
},
{
"name": "catch2",
"version": "3.8.1"
}
]
}