Skip to content

Commit

Permalink
Extend users presets example (#74)
Browse files Browse the repository at this point in the history
* extend users presets example

* wip

* simplify

* fix

* fix
  • Loading branch information
czoido authored Feb 17, 2023
1 parent 3bb6ec5 commit 6424771
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 0 deletions.
2 changes: 2 additions & 0 deletions examples/tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- CMakeToolchain: [Building your project using CMakePresets](cmake/cmake_toolchain/local_flow_cmake_presets/). [Docs](https://docs.conan.io/en/2.0/examples/tools/cmake/cmake_toolchain/build_project_cmake_presets.html)

- CMakeToolchain: [Extending your CMakePresets with Conan generated ones](cmake/cmake_toolchain/extend_own_cmake_presets/). [Docs](https://docs.conan.io/en/2.0/examples/tools/cmake/cmake_toolchain/extend_own_cmake_presets.html)

### [tools.files](files)

- Learn how [patch sources](files/patches/). [Docs](https://docs.conan.io/en/2.0/examples/tools/files/patches/patch_sources.html)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.15)
project(foo CXX)



add_executable(foo src/foo.cpp src/main.cpp)



install(TARGETS foo DESTINATION "."
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"version": 4,
"include": ["./ConanPresets.json"],
"configurePresets": [
{
"name": "default",
"displayName": "multi config",
"inherits": "conan-default"
},
{
"name": "release",
"displayName": "release single config",
"inherits": "conan-release"
},
{
"name": "debug",
"displayName": "debug single config",
"inherits": "conan-debug"
}
],
"buildPresets": [
{
"name": "multi-release",
"configurePreset": "default",
"configuration": "Release",
"inherits": "conan-release"
},
{
"name": "multi-debug",
"configurePreset": "default",
"configuration": "Debug",
"inherits": "conan-debug"
},
{
"name": "release",
"configurePreset": "release",
"configuration": "Release",
"inherits": "conan-release"
},
{
"name": "debug",
"configurePreset": "debug",
"configuration": "Debug",
"inherits": "conan-debug"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps


class fooRecipe(ConanFile):
name = "foo"
version = "1.0"
package_type = "application"

# 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 foo package here>"
topics = ("<Put some tag here>", "<here>", "<and here>")

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

def generate(self):
deps = CMakeDeps(self)
deps.generate()
tc = CMakeToolchain(self)
tc.user_presets_path = 'ConanPresets.json'
tc.generate()

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

def package(self):
cmake = CMake(self)
cmake.install()


Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import os
import platform
import textwrap

from test.examples_tools import run, replace

from conan import conan_version

print("- CMakeToolchain: Extending your CMakePresets with Conan generated ones -")

run("conan install .")
run("conan install . -s build_type=Debug")

if platform.system() == "Windows":
run(f"cmake --preset default")
run(f"cmake --build --preset multi-release")
run(f"cmake --build --preset multi-debug")
else:
run(f"cmake --preset release")
run(f"cmake --build --preset release")
run(f"cmake --preset debug")
run(f"cmake --build --preset debug")

if platform.system() == "Windows":
output = run("build\\Release\\foo.exe")
assert "Hello World Release!" in output
output = run("build\\Debug\\foo.exe")
assert "Hello World Debug!" in output
else:
output = run(str(os.path.join("build", "Release", "foo")))
assert "Hello World Release!" in output
output = run(str(os.path.join("build", "Debug", "foo")))
assert "Hello World Debug!" in output
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <iostream>
#include "foo.h"



void foo(){
#ifdef NDEBUG
std::cout << "foo/1.0: Hello World Release!\n";
#else
std::cout << "foo/1.0: Hello World Debug!\n";
#endif
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once


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

FOO_EXPORT void foo();
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "foo.h"

int main() {
foo();
}
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 can_run


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

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

def test(self):
if can_run(self):
self.run("foo", env="conanrun")

0 comments on commit 6424771

Please sign in to comment.