Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boost-ext-ut: Add Conan V2 support #12306

Merged
merged 8 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 52 additions & 50 deletions recipes/boost-ext-ut/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import os
from conans import CMake, ConanFile, tools
from conans.errors import ConanInvalidConfiguration

required_conan_version = ">=1.43.0"
from conan import ConanFile
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, cmake_layout, CMakeToolchain
from conan.tools.files import apply_conandata_patches, copy, get, rmdir
from conan.tools.microsoft import check_min_vs, is_msvc
from conan.tools.scm import Version
from conan.errors import ConanInvalidConfiguration

required_conan_version = ">=1.50.0"


class UTConan(ConanFile):
Expand All @@ -17,87 +23,83 @@ class UTConan(ConanFile):
no_copy_source = True
options = { "disable_module": [True, False], }
default_options = { "disable_module": False, }
_cmake = None

@property
def _minimum_cpp_standard(self):
return 17 if self.settings.compiler in ["clang", "gcc"] and tools.Version(self.version) <= "1.1.8" else 20
return 17 if self.settings.compiler in ["clang", "gcc"] and Version(self.version) <= "1.1.8" else 20

@property
def _minimum_compilers_version(self):
return {
"apple-clang": "11" if tools.Version(self.version) < "1.1.8" else "12",
"apple-clang": "11" if Version(self.version) < "1.1.8" else "12",
"clang": "9",
"gcc": "9",
"msvc": "19",
"Visual Studio": "16",
}

def layout(self):
cmake_layout(self)

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

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
tools.check_min_cppstd(self, self._minimum_cpp_standard)
if tools.Version(self.version) <= "1.1.8" and self.settings.compiler in ["msvc", "Visual Studio"]:
check_min_cppstd(self, self._minimum_cpp_standard)
if Version(self.version) <= "1.1.8" and is_msvc(self):
raise ConanInvalidConfiguration("{} version 1.1.8 may not be built with MSVC. "
"Please use at least version 1.1.9 with MSVC.")
min_version = self._minimum_compilers_version.get(
str(self.settings.compiler))
if not min_version:
self.output.warn("{} recipe lacks information about the {} "
"compiler support.".format(
self.name, self.settings.compiler))
else:
if tools.Version(self.settings.compiler.version) < min_version:
raise ConanInvalidConfiguration(
"{} requires C++{} support. "
"The current compiler {} {} does not support it.".format(
self.name, self._minimum_cpp_standard,
self.settings.compiler,
self.settings.compiler.version))

check_min_vs(self, "192")

if not is_msvc(self):
min_version = self._minimum_compilers_version.get(
str(self.settings.compiler))
if not min_version:
self.output.warn(f"{self.name} recipe lacks information about the {self.settings.compiler} "
"compiler support.")
else:
if Version(self.settings.compiler.version) < min_version:
raise ConanInvalidConfiguration(
f"{self.name} requires C++{self._minimum_cpp_standard} support. "
f"The current compiler {self.settings.compiler} {self.settings.compiler.version} does not support it.")

def config_options(self):
if tools.Version(self.version) <= "1.1.8":
if Version(self.version) <= "1.1.8":
del self.options.disable_module

def configure(self):
jwillikers marked this conversation as resolved.
Show resolved Hide resolved
if self.settings.compiler in ["msvc", "Visual Studio"]:
if "disable_module" in self.options.values:
self.options.disable_module = True
if is_msvc(self) and "disable_module" in self.options.values:
self.options.disable_module = True

def source(self):
tools.get(**self.conan_data["sources"][self.version], strip_root=True)
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["BOOST_UT_BUILD_BENCHMARKS"] = False
self._cmake.definitions["BOOST_UT_BUILD_EXAMPLES"] = False
self._cmake.definitions["BOOST_UT_BUILD_TESTS"] = False
self._cmake.definitions["PROJECT_DISABLE_VERSION_SUFFIX"] = True
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.cache_variables["BOOST_UT_BUILD_BENCHMARKS"] = False
tc.cache_variables["BOOST_UT_BUILD_EXAMPLES"] = False
tc.cache_variables["BOOST_UT_BUILD_TESTS"] = not self.conf.get("tools.build:skip_test", default=True, check_type=bool)
jwillikers marked this conversation as resolved.
Show resolved Hide resolved
tc.cache_variables["PROJECT_DISABLE_VERSION_SUFFIX"] = True
disable_module = self.options.get_safe("disable_module")
if disable_module:
self._cmake.definitions["BOOST_UT_DISABLE_MODULE"] = disable_module
self._cmake.configure()
return self._cmake
tc.cache_variables["BOOST_UT_DISABLE_MODULE"] = disable_module
tc.generate()

def build(self):
cmake = self._configure_cmake()
apply_conandata_patches(self)
cmake = CMake(self)
jwillikers marked this conversation as resolved.
Show resolved Hide resolved
cmake.configure()
cmake.build()

def package(self):
self.copy("LICENSE*", dst="licenses")
cmake = self._configure_cmake()
copy(self, "LICENSE*", self.source_folder, os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))

def package_id(self):
self.info.header_only()
self.info.clear()

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "ut")
Expand All @@ -110,7 +112,7 @@ def package_info(self):
self.cpp_info.components["ut"].names["cmake_find_package"] = "ut"
self.cpp_info.components["ut"].names["cmake_find_package_multi"] = "ut"

if tools.Version(self.version) > "1.1.8":
if Version(self.version) > "1.1.8":
self.cpp_info.components["ut"].includedirs = [os.path.join("include", "ut-" + self.version, "include")]

if self.options.get_safe("disable_module"):
Expand Down
7 changes: 2 additions & 5 deletions recipes/boost-ext-ut/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.16)
jwillikers marked this conversation as resolved.
Show resolved Hide resolved
project(test_package)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED yes)
set(CMAKE_CXX_EXTENSIONS no)

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

find_package(ut REQUIRED CONFIG)

add_executable(test_package test_package.cpp)
target_link_libraries(test_package boost::ut)
target_link_libraries(test_package PRIVATE boost::ut)
18 changes: 13 additions & 5 deletions recipes/boost-ext-ut/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import os
from conans import ConanFile, CMake, tools

from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout


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

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

def layout(self):
cmake_layout(self)

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

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
if can_run(self):
self.run(os.path.join(self.cpp.build.bindirs[0], "test_package"), env="conanrun")
14 changes: 14 additions & 0 deletions recipes/boost-ext-ut/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.15)
project(test_package)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED yes)
set(CMAKE_CXX_EXTENSIONS no)

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

find_package(ut REQUIRED CONFIG)

add_executable(test_package ../test_package/test_package.cpp)
target_link_libraries(test_package boost::ut)
19 changes: 19 additions & 0 deletions recipes/boost-ext-ut/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os

from conan.tools.build import cross_building
from conans import ConanFile, CMake


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

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

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