Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devops/ci tutorial #153

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions ci/game/.conanrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
conan_home=./.conan2
6 changes: 6 additions & 0 deletions ci/game/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.json
game.lock
conan.lock
.conan2
build
__pycache__
11 changes: 11 additions & 0 deletions ci/game/ai/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.15)
project(ai CXX)

find_package(mathlib CONFIG REQUIRED)

add_library(ai src/ai.cpp)
target_include_directories(ai PUBLIC include)
target_link_libraries(ai mathlib::mathlib)

set_target_properties(ai PROPERTIES PUBLIC_HEADER "include/ai.h")
install(TARGETS ai)
42 changes: 42 additions & 0 deletions ci/game/ai/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMakeDeps, CMake, cmake_layout


class aiRecipe(ConanFile):
name = "ai"
version = "1.0"
requires = "mathlib/[>=1.0 <2]"

# 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":
del self.options.fPIC

def generate(self):
tc = CMakeToolchain(self)
tc.preprocessor_definitions["PKG_VERSION"] = f'"{self.version}"'
tc.generate()
deps = CMakeDeps(self)
deps.generate()

def layout(self):
cmake_layout(self)

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 = ["ai"]
10 changes: 10 additions & 0 deletions ci/game/ai/include/ai.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once


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

AI_EXPORT void ai(int intelligence=0);
14 changes: 14 additions & 0 deletions ci/game/ai/src/ai.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <iostream>
#include "ai.h"
#include "mathlib.h"

void ai(int intelligence){
mathlib();
#ifdef NDEBUG
std::cout << "ai/" << PKG_VERSION << ": Some Artificial Intelligence for aliens (Release)!\n";
#else
std::cout << "ai/" << PKG_VERSION << ": Some Artificial Intelligence for aliens (Debug)!\n";
#endif

std::cout << "ai/" << PKG_VERSION << ": Intelligence level="<< intelligence << "\n";
}
7 changes: 7 additions & 0 deletions ci/game/ai/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(ai CONFIG REQUIRED)

add_executable(example src/example.cpp)
target_link_libraries(example ai::ai)
26 changes: 26 additions & 0 deletions ci/game/ai/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 cross_building


class aiTestConan(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 not cross_building(self):
cmd = os.path.join(self.cpp.build.bindirs[0], "example")
self.run(cmd, env="conanrun")
5 changes: 5 additions & 0 deletions ci/game/ai/test_package/src/example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "ai.h"

int main() {
ai();
}
12 changes: 12 additions & 0 deletions ci/game/engine/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.15)
project(engine CXX)

find_package(ai CONFIG REQUIRED)
find_package(graphics CONFIG REQUIRED)

add_library(engine src/engine.cpp)
target_include_directories(engine PUBLIC include)
target_link_libraries(engine graphics::graphics ai::ai)

set_target_properties(engine PROPERTIES PUBLIC_HEADER "include/engine.h")
install(TARGETS engine)
43 changes: 43 additions & 0 deletions ci/game/engine/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMakeDeps, CMake, cmake_layout


class engineRecipe(ConanFile):
name = "engine"
version = "1.0"

requires = "ai/[>=1.0 <2]", "graphics/[>=1.0 <2]"

# 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":
del self.options.fPIC

def generate(self):
tc = CMakeToolchain(self)
tc.preprocessor_definitions["PKG_VERSION"] = f'"{self.version}"'
tc.generate()
deps = CMakeDeps(self)
deps.generate()

def layout(self):
cmake_layout(self)

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 = ["engine"]
10 changes: 10 additions & 0 deletions ci/game/engine/include/engine.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once


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

ENGINE_EXPORT void engine();
14 changes: 14 additions & 0 deletions ci/game/engine/src/engine.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <iostream>
#include "engine.h"
#include "ai.h"
#include "graphics.h"

void engine(){
ai();
graphics();
#ifdef NDEBUG
std::cout << "engine/" << PKG_VERSION << ": Computing some game things (Release)!\n";
#else
std::cout << "engine/" << PKG_VERSION << ": Computing some game things (Debug)!\n";
#endif
}
12 changes: 12 additions & 0 deletions ci/game/game/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.15)
project(game CXX)

find_package(engine CONFIG REQUIRED)
add_executable(game src/game.cpp src/main.cpp)
target_link_libraries(game engine::engine)

install(TARGETS game DESTINATION "."
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
)
35 changes: 35 additions & 0 deletions ci/game/game/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMakeDeps, CMake, cmake_layout


class gameRecipe(ConanFile):
name = "game"
version = "1.0"
package_type = "application"

requires = "engine/[>=1.0 <2]"

# 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/*"

def generate(self):
tc = CMakeToolchain(self)
tc.preprocessor_definitions["PKG_VERSION"] = f'"{self.version}"'
tc.generate()
deps = CMakeDeps(self)
deps.generate()

def layout(self):
cmake_layout(self)

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

def package(self):
cmake = CMake(self)
cmake.install()
12 changes: 12 additions & 0 deletions ci/game/game/src/game.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <iostream>
#include "game.h"
#include "engine.h"

void game(){
engine();
#ifdef NDEBUG
std::cout << "game/" << PKG_VERSION << ":fun game (Release)!\n";
#else
std::cout << "game/" << PKG_VERSION << ":fun game (Debug)!\n";
#endif
}
10 changes: 10 additions & 0 deletions ci/game/game/src/game.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once


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

GAME_EXPORT void game();
5 changes: 5 additions & 0 deletions ci/game/game/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "game.h"

int main() {
game();
}
14 changes: 14 additions & 0 deletions ci/game/game/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import os
from conan import ConanFile
from conan.tools.build import cross_building


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

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

def test(self):
if not cross_building(self):
self.run("game", env="conanrun")
11 changes: 11 additions & 0 deletions ci/game/graphics/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.15)
project(graphics CXX)

find_package(mathlib CONFIG REQUIRED)

add_library(graphics src/graphics.cpp)
target_include_directories(graphics PUBLIC include)
target_link_libraries(graphics mathlib::mathlib)

set_target_properties(graphics PROPERTIES PUBLIC_HEADER "include/graphics.h")
install(TARGETS graphics)
43 changes: 43 additions & 0 deletions ci/game/graphics/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMakeDeps, CMake, cmake_layout


class graphicsRecipe(ConanFile):
name = "graphics"
version = "1.0"

requires = "mathlib/[>=1.0 <2]"

# 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":
del self.options.fPIC

def generate(self):
tc = CMakeToolchain(self)
tc.preprocessor_definitions["PKG_VERSION"] = f'"{self.version}"'
tc.generate()
deps = CMakeDeps(self)
deps.generate()

def layout(self):
cmake_layout(self)

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 = ["graphics"]
10 changes: 10 additions & 0 deletions ci/game/graphics/include/graphics.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once


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

graphics_EXPORT void graphics();
10 changes: 10 additions & 0 deletions ci/game/graphics/src/graphics.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <iostream>
#include "graphics.h"

void graphics(){
#ifdef NDEBUG
std::cout << "graphics/" << PKG_VERSION << ": Checking if things collide (Release)!\n";
#else
std::cout << "graphics/" << PKG_VERSION << ": Checking if things collide (Debug)!\n";
#endif
}
Loading