2017-06-23 15:34:56 +02:00
|
|
|
#!/usr/bin/env python
|
2024-02-17 16:42:44 +01:00
|
|
|
from conan import ConanFile, tools, __version__ as conan_version
|
|
|
|
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps, cmake_layout
|
|
|
|
from conan.tools import files, scm
|
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import re
|
|
|
|
|
2024-02-17 22:30:26 +01:00
|
|
|
required_conan_version = ">=1.53.0"
|
2017-06-23 15:34:56 +02:00
|
|
|
|
|
|
|
class CatchConan(ConanFile):
|
2020-01-25 18:48:59 +01:00
|
|
|
name = "catch2"
|
|
|
|
description = "A modern, C++-native, framework for unit-tests, TDD and BDD"
|
2020-01-20 20:20:59 +01:00
|
|
|
topics = ("conan", "catch2", "unit-test", "tdd", "bdd")
|
2018-06-11 10:48:10 +02:00
|
|
|
url = "https://github.com/catchorg/Catch2"
|
2018-11-16 12:45:07 +01:00
|
|
|
homepage = url
|
|
|
|
license = "BSL-1.0"
|
2024-02-17 16:42:44 +01:00
|
|
|
version = "latest"
|
2020-01-25 18:48:59 +01:00
|
|
|
|
2018-11-16 12:45:07 +01:00
|
|
|
exports = "LICENSE.txt"
|
2020-01-14 19:36:36 +01:00
|
|
|
exports_sources = ("src/*", "CMakeLists.txt", "CMake/*", "extras/*")
|
2020-01-25 18:48:59 +01:00
|
|
|
|
2020-01-14 19:36:36 +01:00
|
|
|
settings = "os", "compiler", "build_type", "arch"
|
2020-01-25 18:48:59 +01:00
|
|
|
|
2024-02-17 16:42:44 +01:00
|
|
|
def set_version(self):
|
|
|
|
pattern = re.compile(r"\w*VERSION (\d+\.\d+\.\d+) # CML version placeholder, don't delete")
|
|
|
|
with open("CMakeLists.txt") as file:
|
|
|
|
for line in file:
|
|
|
|
result = pattern.search(line)
|
|
|
|
if result:
|
|
|
|
self.version = result.group(1)
|
|
|
|
|
|
|
|
self.output.info(f'Using version: {self.version}')
|
|
|
|
|
|
|
|
def layout(self):
|
|
|
|
cmake_layout(self)
|
|
|
|
|
|
|
|
def generate(self):
|
|
|
|
tc = CMakeToolchain(self)
|
|
|
|
tc.generate()
|
|
|
|
|
|
|
|
deps = CMakeDeps(self)
|
|
|
|
deps.generate()
|
2020-10-31 18:58:57 +01:00
|
|
|
|
2020-01-14 19:36:36 +01:00
|
|
|
def _configure_cmake(self):
|
2018-06-19 07:14:46 +02:00
|
|
|
cmake = CMake(self)
|
2024-02-17 16:42:44 +01:00
|
|
|
|
|
|
|
# These are option variables. The toolchain in conan 2 doesn't appear to
|
|
|
|
# set these correctly so you have to do it in the configure variables.
|
|
|
|
cmake.configure(variables= {
|
|
|
|
"BUILD_TESTING": "OFF",
|
|
|
|
"CATCH_INSTALL_DOCS": "OFF",
|
|
|
|
"CATCH_INSTALL_EXTRAS": "ON",
|
|
|
|
}
|
|
|
|
)
|
2020-01-14 19:36:36 +01:00
|
|
|
return cmake
|
|
|
|
|
|
|
|
def build(self):
|
|
|
|
cmake = self._configure_cmake()
|
|
|
|
cmake.build()
|
2018-06-19 07:14:46 +02:00
|
|
|
|
2020-01-14 19:36:36 +01:00
|
|
|
def package(self):
|
|
|
|
cmake = self._configure_cmake()
|
|
|
|
cmake.install()
|
2017-10-31 15:17:21 +01:00
|
|
|
|
2024-02-17 16:42:44 +01:00
|
|
|
os.mkdir(f'{self.package_folder}/licenses/')
|
|
|
|
shutil.copy2(f'{self.recipe_folder}/LICENSE.txt', f'{self.package_folder}/licenses/')
|
|
|
|
|
2020-01-14 19:36:36 +01:00
|
|
|
def package_info(self):
|
2022-02-05 19:32:06 +01:00
|
|
|
lib_suffix = "d" if self.settings.build_type == "Debug" else ""
|
|
|
|
|
2024-02-17 22:30:26 +01:00
|
|
|
self.cpp_info.set_property("cmake_file_name", "Catch2")
|
|
|
|
self.cpp_info.set_property("cmake_target_name", "Catch2::Catch2WithMain")
|
|
|
|
self.cpp_info.set_property("pkg_config_name", "catch2-with-main")
|
|
|
|
|
|
|
|
# Catch2
|
|
|
|
self.cpp_info.components["catch2base"].set_property("cmake_file_name", "Catch2::Catch2")
|
|
|
|
self.cpp_info.components["catch2base"].set_property("pkg_config_name", "catch2")
|
|
|
|
self.cpp_info.components["catch2base"].libs = ["Catch2" + lib_suffix]
|
|
|
|
self.cpp_info.components["catch2base"].builddirs.append("lib/cmake/Catch2")
|
|
|
|
|
|
|
|
# Catch2WithMain
|
|
|
|
self.cpp_info.components["catch2main"].set_property("cmake_file_name", "Catch2::Catch2WithMain")
|
|
|
|
self.cpp_info.components["catch2main"].set_property("cmake_target_name", "Catch2::Catch2WithMain")
|
|
|
|
self.cpp_info.components["catch2main"].set_property("pkg_config_name", "catch2-with-main")
|
|
|
|
self.cpp_info.components["catch2main"].libs = ["Catch2Main" + lib_suffix]
|
|
|
|
self.cpp_info.components["catch2main"].requires = ["catch2base"]
|