Skip to content

Commit

Permalink
Tried to imporve the conan config a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
jgaa committed Mar 17, 2024
1 parent c35547c commit 7895669
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
11 changes: 10 additions & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout
from conan.tools.build import check_max_cppstd, check_min_cppstd
from conan.tools.files import copy
from conan.tools.scm import Git


class LogfaultConan(ConanFile):
Expand All @@ -11,6 +12,12 @@ class LogfaultConan(ConanFile):
exports_sources = "include/*", "tests/*", "CMakeLists.txt"
no_copy_source = True
generators = "CMakeToolchain", "CMakeDeps"
options = {"with_tests": [True, False]}
default_options = {"with_tests": False}

# def source(self):
# git = Git(self)
# git.clone(url="https://github.com/conan-io/libhello.git", target=".")

def package(self):
# This will also copy the "include" folder
Expand All @@ -23,7 +30,8 @@ def package_info(self):
self.cpp_info.libdirs = []

def requirements(self):
self.test_requires("gtest/1.14.0")
if not self.conf.get("tools.build:skip_test", default=False):
self.test_requires("gtest/1.14.0")

def validate(self):
check_min_cppstd(self, 14)
Expand All @@ -40,6 +48,7 @@ def build(self):

def package(self):
# This will also copy the "include" folder
copy(self, "LICENSE", self.source_folder, self.package_folder)
copy(self, "*.h", self.source_folder, self.package_folder)

def package_info(self):
Expand Down
12 changes: 12 additions & 0 deletions test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
project (example)

find_package (Threads)
find_package (Logfault REQUIRED)

add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE
logfault::logfault
Threads::Threads
)

26 changes: 26 additions & 0 deletions test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os

from conan import ConanFile
from conan.tools.cmake import CMake, cmake_layout
from conan.tools.build import can_run


class helloTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeDeps", "CMakeToolchain"

def requirements(self):
self.requires(self.tested_reference_str)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def layout(self):
cmake_layout(self)

def test(self):
if can_run(self):
cmd = os.path.join(self.cpp.build.bindir, "example")
self.run(cmd, env="conanrun")
13 changes: 13 additions & 0 deletions test_package/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

// General tests for manual testing during development

#include <iostream>
#include "logfault/logfault.h"

using namespace std;

int main( int argc, char *argv[]) {

logfault::LogManager::Instance().AddHandler(std::make_unique<logfault::StreamHandler>(clog, logfault::LogLevel::DEBUGGING));
LFLOG_INFO << "Testing" << 1 << 2 << 3;
}

0 comments on commit 7895669

Please sign in to comment.