From 51b7c6f91b2fa68b76f5a671a4cc9afeca7ff8ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abril=20Rinc=C3=B3n=20Blanco?= Date: Thu, 18 Sep 2025 13:03:55 +0200 Subject: [PATCH 1/4] conanfile.txt --- lesson21/conanfile.txt | 2 ++ lesson21/test.ps1 | 2 ++ lesson21/test.sh | 4 ++++ 3 files changed, 8 insertions(+) create mode 100644 lesson21/conanfile.txt create mode 100644 lesson21/test.ps1 create mode 100755 lesson21/test.sh diff --git a/lesson21/conanfile.txt b/lesson21/conanfile.txt new file mode 100644 index 0000000..d01e0cd --- /dev/null +++ b/lesson21/conanfile.txt @@ -0,0 +1,2 @@ +[requires] +fmt/[>=11.0 <11.2] diff --git a/lesson21/test.ps1 b/lesson21/test.ps1 new file mode 100644 index 0000000..674b0dc --- /dev/null +++ b/lesson21/test.ps1 @@ -0,0 +1,2 @@ +$ErrorActionPreference = 'Stop' + diff --git a/lesson21/test.sh b/lesson21/test.sh new file mode 100755 index 0000000..94ef7de --- /dev/null +++ b/lesson21/test.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +set -e + From 732aa12512e55b1c68f96963c473dc8faa2c6303 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abril=20Rinc=C3=B3n=20Blanco?= Date: Mon, 22 Sep 2025 13:50:07 +0200 Subject: [PATCH 2/4] Make it a real hello lib --- lesson21/CMakeLists.txt | 13 +++ lesson21/conanfile.py | 55 ++++++++++++ lesson21/conanfile.txt | 2 - lesson21/include/hello.h | 14 +++ lesson21/src/hello.cpp | 120 ++++++++++++++++++++++++++ lesson21/test_package/CMakeLists.txt | 7 ++ lesson21/test_package/conanfile.py | 26 ++++++ lesson21/test_package/src/example.cpp | 12 +++ 8 files changed, 247 insertions(+), 2 deletions(-) create mode 100644 lesson21/CMakeLists.txt create mode 100644 lesson21/conanfile.py delete mode 100644 lesson21/conanfile.txt create mode 100644 lesson21/include/hello.h create mode 100644 lesson21/src/hello.cpp create mode 100644 lesson21/test_package/CMakeLists.txt create mode 100644 lesson21/test_package/conanfile.py create mode 100644 lesson21/test_package/src/example.cpp diff --git a/lesson21/CMakeLists.txt b/lesson21/CMakeLists.txt new file mode 100644 index 0000000..963f0a3 --- /dev/null +++ b/lesson21/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.15) +project(hello CXX) + + + + +add_library(hello src/hello.cpp) +target_include_directories(hello PUBLIC include) + + + +set_target_properties(hello PROPERTIES PUBLIC_HEADER "include/hello.h") +install(TARGETS hello) diff --git a/lesson21/conanfile.py b/lesson21/conanfile.py new file mode 100644 index 0000000..02eaa20 --- /dev/null +++ b/lesson21/conanfile.py @@ -0,0 +1,55 @@ +from conan import ConanFile +from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps + + +class helloRecipe(ConanFile): + name = "hello" + version = "1.0" + package_type = "library" + + # Optional metadata + license = "" + author = " " + url = "" + description = "" + topics = ("", "", "") + + # Binary configuration + settings = "os", "compiler", "build_type", "arch" + options = {"shared": [True, False], "fPIC": [True, False]} + default_options = {"shared": False, "fPIC": True} + + # Sources are located in the same place as this recipe, copy them to the recipe + exports_sources = "CMakeLists.txt", "src/*", "include/*" + + def config_options(self): + if self.settings.os == "Windows": + self.options.rm_safe("fPIC") + + def configure(self): + if self.options.shared: + self.options.rm_safe("fPIC") + + def requirements(self): + self.requires("fmt/[>=11.0 <11.2]") + + def layout(self): + cmake_layout(self) + + def generate(self): + deps = CMakeDeps(self) + deps.generate() + tc = CMakeToolchain(self) + tc.generate() + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def package(self): + cmake = CMake(self) + cmake.install() + + def package_info(self): + self.cpp_info.libs = ["hello"] diff --git a/lesson21/conanfile.txt b/lesson21/conanfile.txt deleted file mode 100644 index d01e0cd..0000000 --- a/lesson21/conanfile.txt +++ /dev/null @@ -1,2 +0,0 @@ -[requires] -fmt/[>=11.0 <11.2] diff --git a/lesson21/include/hello.h b/lesson21/include/hello.h new file mode 100644 index 0000000..b9e261c --- /dev/null +++ b/lesson21/include/hello.h @@ -0,0 +1,14 @@ +#pragma once + +#include +#include + + +#ifdef _WIN32 + #define HELLO_EXPORT __declspec(dllexport) +#else + #define HELLO_EXPORT +#endif + +HELLO_EXPORT void hello(); +HELLO_EXPORT void hello_print_vector(const std::vector &strings); diff --git a/lesson21/src/hello.cpp b/lesson21/src/hello.cpp new file mode 100644 index 0000000..392974d --- /dev/null +++ b/lesson21/src/hello.cpp @@ -0,0 +1,120 @@ +#include +#include "hello.h" + + + +void hello(){ + + + #ifdef NDEBUG + std::cout << "hello/1.0: Hello World Release!\n"; + #else + std::cout << "hello/1.0: Hello World Debug!\n"; + #endif + + // ARCHITECTURES + #ifdef _M_X64 + std::cout << " hello/1.0: _M_X64 defined\n"; + #endif + + #ifdef _M_IX86 + std::cout << " hello/1.0: _M_IX86 defined\n"; + #endif + + #ifdef _M_ARM64 + std::cout << " hello/1.0: _M_ARM64 defined\n"; + #endif + + #if __i386__ + std::cout << " hello/1.0: __i386__ defined\n"; + #endif + + #if __x86_64__ + std::cout << " hello/1.0: __x86_64__ defined\n"; + #endif + + #if __aarch64__ + std::cout << " hello/1.0: __aarch64__ defined\n"; + #endif + + // Libstdc++ + #if defined _GLIBCXX_USE_CXX11_ABI + std::cout << " hello/1.0: _GLIBCXX_USE_CXX11_ABI "<< _GLIBCXX_USE_CXX11_ABI << "\n"; + #endif + + // MSVC runtime + #if defined(_DEBUG) + #if defined(_MT) && defined(_DLL) + std::cout << " hello/1.0: MSVC runtime: MultiThreadedDebugDLL\n"; + #elif defined(_MT) + std::cout << " hello/1.0: MSVC runtime: MultiThreadedDebug\n"; + #endif + #else + #if defined(_MT) && defined(_DLL) + std::cout << " hello/1.0: MSVC runtime: MultiThreadedDLL\n"; + #elif defined(_MT) + std::cout << " hello/1.0: MSVC runtime: MultiThreaded\n"; + #endif + #endif + + // COMPILER VERSIONS + #if _MSC_VER + std::cout << " hello/1.0: _MSC_VER" << _MSC_VER<< "\n"; + #endif + + #if _MSVC_LANG + std::cout << " hello/1.0: _MSVC_LANG" << _MSVC_LANG<< "\n"; + #endif + + #if __cplusplus + std::cout << " hello/1.0: __cplusplus" << __cplusplus<< "\n"; + #endif + + #if __INTEL_COMPILER + std::cout << " hello/1.0: __INTEL_COMPILER" << __INTEL_COMPILER<< "\n"; + #endif + + #if __GNUC__ + std::cout << " hello/1.0: __GNUC__" << __GNUC__<< "\n"; + #endif + + #if __GNUC_MINOR__ + std::cout << " hello/1.0: __GNUC_MINOR__" << __GNUC_MINOR__<< "\n"; + #endif + + #if __clang_major__ + std::cout << " hello/1.0: __clang_major__" << __clang_major__<< "\n"; + #endif + + #if __clang_minor__ + std::cout << " hello/1.0: __clang_minor__" << __clang_minor__<< "\n"; + #endif + + #if __apple_build_version__ + std::cout << " hello/1.0: __apple_build_version__" << __apple_build_version__<< "\n"; + #endif + + // SUBSYSTEMS + + #if __MSYS__ + std::cout << " hello/1.0: __MSYS__" << __MSYS__<< "\n"; + #endif + + #if __MINGW32__ + std::cout << " hello/1.0: __MINGW32__" << __MINGW32__<< "\n"; + #endif + + #if __MINGW64__ + std::cout << " hello/1.0: __MINGW64__" << __MINGW64__<< "\n"; + #endif + + #if __CYGWIN__ + std::cout << " hello/1.0: __CYGWIN__" << __CYGWIN__<< "\n"; + #endif +} + +void hello_print_vector(const std::vector &strings) { + for(std::vector::const_iterator it = strings.begin(); it != strings.end(); ++it) { + std::cout << "hello/1.0 " << *it << std::endl; + } +} diff --git a/lesson21/test_package/CMakeLists.txt b/lesson21/test_package/CMakeLists.txt new file mode 100644 index 0000000..c33c2a7 --- /dev/null +++ b/lesson21/test_package/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.15) +project(PackageTest CXX) + +find_package(hello CONFIG REQUIRED) + +add_executable(example src/example.cpp) +target_link_libraries(example hello::hello) diff --git a/lesson21/test_package/conanfile.py b/lesson21/test_package/conanfile.py new file mode 100644 index 0000000..e073113 --- /dev/null +++ b/lesson21/test_package/conanfile.py @@ -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") diff --git a/lesson21/test_package/src/example.cpp b/lesson21/test_package/src/example.cpp new file mode 100644 index 0000000..f6acdb3 --- /dev/null +++ b/lesson21/test_package/src/example.cpp @@ -0,0 +1,12 @@ +#include "hello.h" +#include +#include + +int main() { + hello(); + + std::vector vec; + vec.push_back("test_package"); + + hello_print_vector(vec); +} From dd013306fce2c403d26bc36840296dd96d9a9047 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abril=20Rinc=C3=B3n=20Blanco?= Date: Wed, 24 Sep 2025 16:18:56 +0200 Subject: [PATCH 3/4] Move library to hello folder --- lesson21/{ => hello}/CMakeLists.txt | 0 lesson21/{ => hello}/conanfile.py | 0 lesson21/{ => hello}/include/hello.h | 0 lesson21/{ => hello}/src/hello.cpp | 0 lesson21/{ => hello}/test_package/CMakeLists.txt | 0 lesson21/{ => hello}/test_package/conanfile.py | 0 lesson21/{ => hello}/test_package/src/example.cpp | 0 7 files changed, 0 insertions(+), 0 deletions(-) rename lesson21/{ => hello}/CMakeLists.txt (100%) rename lesson21/{ => hello}/conanfile.py (100%) rename lesson21/{ => hello}/include/hello.h (100%) rename lesson21/{ => hello}/src/hello.cpp (100%) rename lesson21/{ => hello}/test_package/CMakeLists.txt (100%) rename lesson21/{ => hello}/test_package/conanfile.py (100%) rename lesson21/{ => hello}/test_package/src/example.cpp (100%) diff --git a/lesson21/CMakeLists.txt b/lesson21/hello/CMakeLists.txt similarity index 100% rename from lesson21/CMakeLists.txt rename to lesson21/hello/CMakeLists.txt diff --git a/lesson21/conanfile.py b/lesson21/hello/conanfile.py similarity index 100% rename from lesson21/conanfile.py rename to lesson21/hello/conanfile.py diff --git a/lesson21/include/hello.h b/lesson21/hello/include/hello.h similarity index 100% rename from lesson21/include/hello.h rename to lesson21/hello/include/hello.h diff --git a/lesson21/src/hello.cpp b/lesson21/hello/src/hello.cpp similarity index 100% rename from lesson21/src/hello.cpp rename to lesson21/hello/src/hello.cpp diff --git a/lesson21/test_package/CMakeLists.txt b/lesson21/hello/test_package/CMakeLists.txt similarity index 100% rename from lesson21/test_package/CMakeLists.txt rename to lesson21/hello/test_package/CMakeLists.txt diff --git a/lesson21/test_package/conanfile.py b/lesson21/hello/test_package/conanfile.py similarity index 100% rename from lesson21/test_package/conanfile.py rename to lesson21/hello/test_package/conanfile.py diff --git a/lesson21/test_package/src/example.cpp b/lesson21/hello/test_package/src/example.cpp similarity index 100% rename from lesson21/test_package/src/example.cpp rename to lesson21/hello/test_package/src/example.cpp From 4b77f87a2fdbf432415e1fb16d8a70bcb5802c91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abril=20Rinc=C3=B3n=20Blanco?= Date: Fri, 26 Sep 2025 13:47:25 +0200 Subject: [PATCH 4/4] New range --- lesson21/hello/conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lesson21/hello/conanfile.py b/lesson21/hello/conanfile.py index 02eaa20..e3c1b88 100644 --- a/lesson21/hello/conanfile.py +++ b/lesson21/hello/conanfile.py @@ -31,7 +31,7 @@ def configure(self): self.options.rm_safe("fPIC") def requirements(self): - self.requires("fmt/[>=11.0 <11.2]") + self.requires("fmt/[>=11.0 <12]") def layout(self): cmake_layout(self)