diff --git a/lesson21/hello/CMakeLists.txt b/lesson21/hello/CMakeLists.txt new file mode 100644 index 0000000..963f0a3 --- /dev/null +++ b/lesson21/hello/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/hello/conanfile.py b/lesson21/hello/conanfile.py new file mode 100644 index 0000000..e3c1b88 --- /dev/null +++ b/lesson21/hello/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 <12]") + + 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/hello/include/hello.h b/lesson21/hello/include/hello.h new file mode 100644 index 0000000..b9e261c --- /dev/null +++ b/lesson21/hello/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/hello/src/hello.cpp b/lesson21/hello/src/hello.cpp new file mode 100644 index 0000000..392974d --- /dev/null +++ b/lesson21/hello/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/hello/test_package/CMakeLists.txt b/lesson21/hello/test_package/CMakeLists.txt new file mode 100644 index 0000000..c33c2a7 --- /dev/null +++ b/lesson21/hello/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/hello/test_package/conanfile.py b/lesson21/hello/test_package/conanfile.py new file mode 100644 index 0000000..e073113 --- /dev/null +++ b/lesson21/hello/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/hello/test_package/src/example.cpp b/lesson21/hello/test_package/src/example.cpp new file mode 100644 index 0000000..f6acdb3 --- /dev/null +++ b/lesson21/hello/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); +} 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 +