Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lesson21/hello/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
55 changes: 55 additions & 0 deletions lesson21/hello/conanfile.py
Original file line number Diff line number Diff line change
@@ -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 = "<Put the package license here>"
author = "<Put your name here> <And your email here>"
url = "<Package recipe repository url here, for issues about the package>"
description = "<Description of hello package here>"
topics = ("<Put some tag here>", "<here>", "<and here>")

# 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"]
14 changes: 14 additions & 0 deletions lesson21/hello/include/hello.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#include <vector>
#include <string>


#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<std::string> &strings);
120 changes: 120 additions & 0 deletions lesson21/hello/src/hello.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#include <iostream>
#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<std::string> &strings) {
for(std::vector<std::string>::const_iterator it = strings.begin(); it != strings.end(); ++it) {
std::cout << "hello/1.0 " << *it << std::endl;
}
}
7 changes: 7 additions & 0 deletions lesson21/hello/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
26 changes: 26 additions & 0 deletions lesson21/hello/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")
12 changes: 12 additions & 0 deletions lesson21/hello/test_package/src/example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "hello.h"
#include <vector>
#include <string>

int main() {
hello();

std::vector<std::string> vec;
vec.push_back("test_package");

hello_print_vector(vec);
}
2 changes: 2 additions & 0 deletions lesson21/test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
$ErrorActionPreference = 'Stop'

4 changes: 4 additions & 0 deletions lesson21/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

set -e

Loading