-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#13794) catch2 (2.x.x): support conan v2
* catch2 (2.x.x): support conan v2, based on work by SpaceIm that was done for 3.x.x * Some minor tweaks * Linter fixes * Update recipes/catch2/2.x.x/conanfile.py Co-authored-by: Uilian Ries <uilianries@gmail.com> * Fixed CATCH_CONFIG_PREFIX_ALL behaviour * Don't quote default_reporter - 3.x.x already changed * Fix for conan 1.52 * Fixup error message * Remove unused file * Removed lines - not needed as no package CMakeLists.txt supplied anymore * Update recipes/catch2/2.x.x/conanfile.py Co-authored-by: Uilian Ries <uilianries@gmail.com> * Fixes for linter * v2 fixes * Revert "v2 fixes" This reverts commit 332eb40. * Update recipes/catch2/2.x.x/conanfile.py Co-authored-by: Chris Mc <prince.chrismc@gmail.com> * v2 fixes * Fixup todos filename for test_package * Update recipes/catch2/2.x.x/conanfile.py Co-authored-by: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Co-authored-by: Uilian Ries <uilianries@gmail.com> Co-authored-by: Christopher McArthur <christopherm@jfrog.com> Co-authored-by: Chris Mc <prince.chrismc@gmail.com> Co-authored-by: SpaceIm <30052553+SpaceIm@users.noreply.github.com>
- Loading branch information
1 parent
002eaf2
commit 8c1c300
Showing
5 changed files
with
117 additions
and
107 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,32 +1,31 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
project(test_package) | ||
cmake_minimum_required(VERSION 3.8) | ||
project(test_package LANGUAGES CXX) | ||
|
||
set(CMAKE_CXX_STANDARD 11) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) | ||
conan_basic_setup() | ||
|
||
find_package(Catch2 REQUIRED) | ||
find_package(Catch2 REQUIRED CONFIG) | ||
|
||
if(NOT WITH_PREFIX) | ||
add_executable(test_package 000-CatchMain.cpp 100-Fix-Section.cpp) | ||
target_link_libraries(test_package PRIVATE Catch2::Catch2) | ||
target_compile_features(test_package PRIVATE cxx_std_11) | ||
|
||
if(WITH_MAIN) | ||
add_executable(standalone 200-standalone.cpp) | ||
target_link_libraries(standalone PRIVATE Catch2::Catch2WithMain) | ||
target_compile_features(standalone PRIVATE cxx_std_11) | ||
if(WITH_BENCHMARK) | ||
add_executable(benchmark 300-benchmark.cpp) | ||
target_link_libraries(benchmark PRIVATE Catch2::Catch2WithMain) | ||
target_compile_features(benchmark PRIVATE cxx_std_11) | ||
endif() | ||
endif() | ||
else() | ||
add_executable(test_package 000-CatchMain.cpp 400-with-prefix.cpp) | ||
target_link_libraries(test_package PRIVATE Catch2::Catch2) | ||
target_compile_features(test_package PRIVATE cxx_std_11) | ||
|
||
if(WITH_MAIN) | ||
add_executable(standalone 400-with-prefix.cpp) | ||
target_link_libraries(standalone PRIVATE Catch2::Catch2WithMain) | ||
target_compile_features(standalone PRIVATE cxx_std_11) | ||
endif() | ||
endif() |
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 |
---|---|---|
@@ -1,24 +1,53 @@ | ||
from conans import ConanFile, CMake, tools | ||
from conans.tools import Version | ||
from conan import ConanFile | ||
from conan.tools.cmake import CMake, CMakeToolchain | ||
from conan.tools.build import can_run | ||
from conan.tools.cmake import cmake_layout | ||
import os | ||
|
||
import yaml | ||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "compiler", "build_type", "arch" | ||
generators = "cmake", "cmake_find_package" | ||
generators = "CMakeDeps", "VirtualRunEnv" | ||
test_type = "explicit" | ||
|
||
_tests_todo = [] | ||
|
||
@property | ||
def _todos_filename(self): | ||
return os.path.join(self.recipe_folder, self.folders.generators, "catch2_test_to_do.yml") | ||
|
||
def requirements(self): | ||
self.requires(self.tested_reference_str) | ||
|
||
def generate(self): | ||
tc = CMakeToolchain(self) | ||
catch_opts = self.dependencies[self.tested_reference_str].options | ||
tc.variables["WITH_PREFIX"] = catch_opts.with_prefix | ||
tc.variables["WITH_MAIN"] = catch_opts.with_main | ||
tc.variables["WITH_BENCHMARK"] = not catch_opts.with_prefix and catch_opts.with_main and catch_opts.with_benchmark | ||
tc.generate() | ||
|
||
# note: this is required as self.dependencies is not available in test() | ||
self._tests_todo.append("test_package") | ||
if catch_opts.with_main: | ||
self._tests_todo.append("standalone") | ||
if not catch_opts.with_prefix and catch_opts.with_main and catch_opts.with_benchmark: | ||
self._tests_todo.append("benchmark") | ||
|
||
with open(self._todos_filename, "w", encoding="utf-8") as file: | ||
yaml.dump(self._tests_todo, file) | ||
|
||
def layout(self): | ||
cmake_layout(self) | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.definitions["WITH_MAIN"] = self.options["catch2"].with_main | ||
cmake.definitions["WITH_BENCHMARK"] = self.options["catch2"].with_main and self.options["catch2"].with_benchmark | ||
cmake.definitions["WITH_PREFIX"] = self.options["catch2"].with_prefix | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def test(self): | ||
if not tools.cross_building(self.settings): | ||
self.run(os.path.join("bin", "test_package"), run_environment=True) | ||
if self.options["catch2"].with_main: | ||
self.run(os.path.join("bin", "standalone"), run_environment=True) | ||
if self.options["catch2"].with_benchmark: | ||
self.run(os.path.join("bin", "benchmark"), run_environment=True) | ||
with open(self._todos_filename, "r", encoding="utf-8") as file: | ||
self._tests_todo = yaml.safe_load(file) | ||
if can_run(self): | ||
for test_name in self._tests_todo: | ||
self.run(os.path.join(self.cpp.build.bindirs[0], test_name), env="conanrun") |
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