-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* extend users presets example * wip * simplify * fix * fix
- Loading branch information
Showing
9 changed files
with
179 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
examples/tools/cmake/cmake_toolchain/extend_own_cmake_presets/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
47 changes: 47 additions & 0 deletions
47
examples/tools/cmake/cmake_toolchain/extend_own_cmake_presets/CMakePresets.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
} |
42 changes: 42 additions & 0 deletions
42
examples/tools/cmake/cmake_toolchain/extend_own_cmake_presets/conanfile.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|
||
|
33 changes: 33 additions & 0 deletions
33
examples/tools/cmake/cmake_toolchain/extend_own_cmake_presets/run_example.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
12 changes: 12 additions & 0 deletions
12
examples/tools/cmake/cmake_toolchain/extend_own_cmake_presets/src/foo.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
10 changes: 10 additions & 0 deletions
10
examples/tools/cmake/cmake_toolchain/extend_own_cmake_presets/src/foo.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
5 changes: 5 additions & 0 deletions
5
examples/tools/cmake/cmake_toolchain/extend_own_cmake_presets/src/main.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#include "foo.h" | ||
|
||
int main() { | ||
foo(); | ||
} |
14 changes: 14 additions & 0 deletions
14
examples/tools/cmake/cmake_toolchain/extend_own_cmake_presets/test_package/conanfile.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |