Skip to content

Commit

Permalink
(conan-io#13037) [Catch2] adapt recipe for Conan v2
Browse files Browse the repository at this point in the history
* [Catch2] adapt recipe for Conan v2

* fixes

* fixes

* fixes

* fixes

* fixes 4

* fixes 5

* fixes 6

* Update recipes/catch2/3.x.x/conanfile.py

Co-authored-by: Uilian Ries <uilianries@gmail.com>

* Update recipes/catch2/3.x.x/conanfile.py

Co-authored-by: Uilian Ries <uilianries@gmail.com>

* Update recipes/catch2/3.x.x/conanfile.py

Co-authored-by: Uilian Ries <uilianries@gmail.com>

* Update recipes/catch2/3.x.x/conanfile.py

* fix patches

* fix

* fix

* remove comments

* Update recipes/catch2/3.x.x/conanfile.py

Co-authored-by: Chris Mc <prince.chrismc@gmail.com>

* Update recipes/catch2/3.x.x/conanfile.py

Co-authored-by: Chris Mc <prince.chrismc@gmail.com>

* test package changes

* Move test package files (#2)

* move gtest

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* Delete test_all.sh

* Use cmake targets

* Do not use settings

Signed-off-by: Uilian Ries <uilianries@gmail.com>

Signed-off-by: Uilian Ries <uilianries@gmail.com>
Co-authored-by: Uilian Ries <uilianries@gmail.com>
Co-authored-by: Chris Mc <prince.chrismc@gmail.com>
  • Loading branch information
3 people authored and marc-mw committed Oct 7, 2022
1 parent cd233fc commit 7fb6df0
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 65 deletions.
32 changes: 32 additions & 0 deletions recipes/catch2/2.x.x/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
cmake_minimum_required(VERSION 3.5)
project(test_package)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

find_package(Catch2 REQUIRED)

if(NOT WITH_PREFIX)
add_executable(test_package ../test_package/000-CatchMain.cpp ../test_package/100-Fix-Section.cpp)
target_link_libraries(test_package PRIVATE Catch2::Catch2)

if(WITH_MAIN)
add_executable(standalone ../test_package/200-standalone.cpp)
target_link_libraries(standalone PRIVATE Catch2::Catch2WithMain)
if(WITH_BENCHMARK)
add_executable(benchmark ../test_package/300-benchmark.cpp)
target_link_libraries(benchmark PRIVATE Catch2::Catch2WithMain)
endif()
endif()
else()
add_executable(test_package ../test_package/000-CatchMain.cpp ../test_package/400-with-prefix.cpp)
target_link_libraries(test_package PRIVATE Catch2::Catch2)

if(WITH_MAIN)
add_executable(standalone ../test_package/400-with-prefix.cpp)
target_link_libraries(standalone PRIVATE Catch2::Catch2WithMain)
endif()
endif()
24 changes: 24 additions & 0 deletions recipes/catch2/2.x.x/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from conans import ConanFile, CMake, tools
from conans.tools import Version
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package"

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):
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)
10 changes: 0 additions & 10 deletions recipes/catch2/3.x.x/CMakeLists.txt

This file was deleted.

2 changes: 0 additions & 2 deletions recipes/catch2/3.x.x/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@ sources:
patches:
"3.1.0":
- patch_file: "patches/3.0.1-0001-force-not_usbproject-off.patch"
base_path: "source_subfolder"
"3.0.1":
- patch_file: "patches/3.0.1-0001-force-not_usbproject-off.patch"
base_path: "source_subfolder"
75 changes: 34 additions & 41 deletions recipes/catch2/3.x.x/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import os
import functools
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.build import check_min_cppstd
from conan.tools.scm import Version
from conan.tools.files import apply_conandata_patches, copy, get, rmdir

required_conan_version = ">=1.43.0"
required_conan_version = ">=1.52.0"

class Catch2Conan(ConanFile):
name = "catch2"
Expand All @@ -23,24 +26,14 @@ class Catch2Conan(ConanFile):
"with_prefix": False,
"default_reporter": None,
}
generators = "cmake"

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _build_subfolder(self):
return "build_subfolder"

@property
def _default_reporter_str(self):
return '"{}"'.format(str(self.options.default_reporter).strip('"'))

def export_sources(self):
self.copy("CMakeLists.txt")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])
for p in self.conan_data.get("patches", {}).get(self.version, []):
copy(self, p["patch_file"], self.recipe_folder, self.export_sources_folder)

def config_options(self):
if self.settings.os == "Windows":
Expand All @@ -55,52 +48,52 @@ def _compilers_minimum_version(self):
"apple-clang": "10",
}

def layout(self):
cmake_layout(self, src_folder="src")

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
tools.check_min_cppstd(self, "14")
check_min_cppstd(self, "14")
minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False)
if minimum_version:
if tools.Version(self.settings.compiler.version) < minimum_version:
if Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration("{}/{}: Unsupported compiler: {}-{} "
"(https://github.com/p-ranav/structopt#compiler-compatibility)."
.format(self.name, self.version, self.settings.compiler, self.settings.compiler.version))
else:
self.output.warn("{}/{} requires C++14. Your compiler is unknown. Assuming it supports C++14.".format(self.name, self.version))

def source(self):
tools.get(**self.conan_data["sources"][self.version], strip_root=True, destination=self._source_subfolder)

@functools.lru_cache(1)
def _configure_cmake(self):
cmake = CMake(self)
cmake.definitions["BUILD_TESTING"] = "OFF"
cmake.definitions["CATCH_INSTALL_DOCS"] = "OFF"
cmake.definitions["CATCH_INSTALL_HELPERS"] = "ON"
cmake.definitions["CATCH_CONFIG_PREFIX_ALL"] = self.options.with_prefix
get(self, **self.conan_data["sources"][self.version], destination=self.source_folder, strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["BUILD_TESTING"] = False
tc.variables["CATCH_INSTALL_DOCS"] = False
tc.variables["CATCH_INSTALL_HELPERS"] = True
tc.variables["CATCH_CONFIG_PREFIX_ALL"] = self.options.with_prefix
if self.options.default_reporter:
cmake.definitions["CATCH_CONFIG_DEFAULT_REPORTER"] = self._default_reporter_str
cmake.configure(build_folder=self._build_subfolder)
return cmake

def _patch_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
tc.variables["CATCH_CONFIG_DEFAULT_REPORTER"] = self._default_reporter_str
tc.generate()

def build(self):
self._patch_sources()
cmake = self._configure_cmake()
apply_conandata_patches(self)
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
self.copy(pattern="LICENSE.txt", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
copy(self, "LICENSE.txt", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))

cmake = CMake(self)
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
tools.rmdir(os.path.join(self.package_folder, "share"))

rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "share"))
for cmake_file in ["ParseAndAddCatchTests.cmake", "Catch.cmake", "CatchAddTests.cmake"]:
self.copy(
cmake_file,
src=os.path.join(self._source_subfolder, "extras"),
src=os.path.join(self.source_folder, "extras"),
dst=os.path.join("lib", "cmake", "Catch2"),
)

Expand Down
5 changes: 1 addition & 4 deletions recipes/catch2/3.x.x/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
cmake_minimum_required(VERSION 3.12)
cmake_minimum_required(VERSION 3.15)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

find_package(Catch2 REQUIRED CONFIG)

set(CMAKE_CXX_STANDARD 14)
Expand Down
29 changes: 21 additions & 8 deletions recipes/catch2/3.x.x/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
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

class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeDeps", "VirtualRunEnv"
test_type = "explicit"

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

def generate(self):
tc = CMakeToolchain(self)
tc.variables["WITH_PREFIX"] = self.dependencies[self.tested_reference_str].options.with_prefix
tc.generate()

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.definitions["WITH_PREFIX"] = self.options["catch2"].with_prefix
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
self.run(os.path.join("bin", "standalone"), run_environment=True)
self.run(os.path.join("bin", "benchmark"), run_environment=True)
if can_run(self):
self.run(os.path.join(self.cpp.build.bindirs[0], "standalone"), env="conanrun")
self.run(os.path.join(self.cpp.build.bindirs[0], "benchmark"), env="conanrun")
22 changes: 22 additions & 0 deletions recipes/catch2/3.x.x/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
cmake_minimum_required(VERSION 3.12)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

find_package(Catch2 REQUIRED CONFIG)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if(NOT WITH_PREFIX)
add_executable(standalone ../test_package/100-standalone.cpp)
target_link_libraries(standalone PRIVATE Catch2::Catch2WithMain)
add_executable(benchmark ../test_package/200-benchmark.cpp)
target_link_libraries(benchmark PRIVATE Catch2::Catch2WithMain)
else()
add_executable(standalone ../test_package/300-standalone-with-prefix.cpp)
target_link_libraries(standalone PRIVATE Catch2::Catch2WithMain)
add_executable(benchmark ../test_package/400-benchmark-with-prefix.cpp)
target_link_libraries(benchmark PRIVATE Catch2::Catch2WithMain)
endif()
18 changes: 18 additions & 0 deletions recipes/catch2/3.x.x/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from conans import ConanFile, CMake, tools
from conans.tools import Version
import os

class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"

def build(self):
cmake = CMake(self)
cmake.definitions["WITH_PREFIX"] = self.options["catch2"].with_prefix
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
self.run(os.path.join("bin", "standalone"), run_environment=True)
self.run(os.path.join("bin", "benchmark"), run_environment=True)

0 comments on commit 7fb6df0

Please sign in to comment.