Skip to content
Open
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
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
options: --user 0:0
strategy:
matrix:
lesson: [1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 14, 15, 16]
lesson: [1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 14, 15, 16, 18]
env:
CONAN_HOME: ${{ github.workspace }}/.conan_home_${{ matrix.lesson }}

Expand All @@ -46,7 +46,7 @@ jobs:
runs-on: macos-latest
strategy:
matrix:
lesson: [1, 2, 3, 4, 6, 8, 9, 10, 12, 14, 15, 16]
lesson: [1, 2, 3, 4, 6, 8, 9, 10, 12, 14, 15, 16, 18]
env:
CONAN_HOME: ${{ github.workspace }}/.conan_home_${{ matrix.lesson }}

Expand All @@ -68,7 +68,7 @@ jobs:
runs-on: windows-latest
strategy:
matrix:
lesson: [1, 2, 3, 4, 6, 8, 9, 10, 12, 14, 15, 16]
lesson: [1, 2, 3, 4, 6, 8, 9, 10, 12, 14, 15, 16, 18]
env:
CONAN_HOME: ${{ github.workspace }}/.conan_home_${{ matrix.lesson }}

Expand Down
12 changes: 12 additions & 0 deletions lesson18/hello/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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")

find_package(fmt)
target_link_libraries(hello fmt::fmt)

install(TARGETS hello)
52 changes: 52 additions & 0 deletions lesson18/hello/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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"

# 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 layout(self):
cmake_layout(self)

def requirements(self):
self.requires("fmt/11.2.0")

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

#ifdef _WIN32
#define HELLO_EXPORT __declspec(dllexport)
#else
#define HELLO_EXPORT
#endif

HELLO_EXPORT void hello();
9 changes: 9 additions & 0 deletions lesson18/hello/src/hello.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <iostream>
#include "hello.h"

#include <fmt/color.h>

void hello() {
fmt::print(fg(fmt::color::crimson) | fmt::emphasis::bold,
"hello/1.0: Hello World! (with color!)\n");
}
7 changes: 7 additions & 0 deletions lesson18/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 lesson18/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")
6 changes: 6 additions & 0 deletions lesson18/hello/test_package/src/example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "hello.h"


int main() {
hello();
}
9 changes: 9 additions & 0 deletions lesson18/say/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.15)
project(say CXX)

add_executable(say src/say.cpp)

find_package(hello REQUIRED CONFIG)
target_link_libraries(say hello::hello)

install(TARGETS say)
39 changes: 39 additions & 0 deletions lesson18/say/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps


class sayRecipe(ConanFile):
name = "say"
version = "1.0"
package_type = "application"

# Binary configuration
settings = "os", "compiler", "build_type", "arch"

# Sources are located in the same place as this recipe, copy them to the recipe
exports_sources = "CMakeLists.txt", "src/*", "include/*"

def layout(self):
cmake_layout(self)

def requirements(self):
self.requires("hello/1.0")

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 = []
self.cpp_info.libdirs = []
8 changes: 8 additions & 0 deletions lesson18/say/src/say.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <iostream>

#include "hello.h"

int main() {
std::cout << "We say: ";
hello();
}
17 changes: 17 additions & 0 deletions lesson18/say/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.layout import basic_layout

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

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

def layout(self):
basic_layout(self)

def test(self):
if can_run(self):
extension = ".exe" if self.settings.os == "Windows" else ""
self.run(f"say{extension}", env="conanrun")
21 changes: 21 additions & 0 deletions lesson18/test.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
$ErrorActionPreference = 'Stop'

# Add hello package to editable mode
conan editable add hello

cd say

# Try to build src
conan build . --build=missing --build=editable

# It built successfully and we can run it
./build/Release/say.exe

cd ..

# And now ensure the usual workflow still works
conan editable remove hello

conan create hello --build=missing

conan create say
23 changes: 23 additions & 0 deletions lesson18/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

set -e

# Add hello package to editable mode
conan editable add hello

cd say

# Try to build src
conan build . --build=missing --build=editable

# It built successfully and we can run it
./build/Release/say

cd ..

# And now ensure the usual workflow still works
conan editable remove hello

conan create hello --build=missing

conan create say
Loading