From aa1068c3b245499dc730c4bc65691505bd27efcc Mon Sep 17 00:00:00 2001 From: Fernando Pelliccioni Date: Tue, 21 Nov 2023 16:09:43 +0100 Subject: [PATCH 1/3] adds boost-predef recipe --- recipes/boost-predef/all/conandata.yml | 6 + recipes/boost-predef/all/conanfile.py | 110 ++++++++++++++++++ .../all/test_package/CMakeLists.txt | 16 +++ .../all/test_package/conanfile.py | 42 +++++++ .../boost-predef/all/test_package/main.cpp | 7 ++ .../all/test_v1_package/CMakeLists.txt | 10 ++ .../all/test_v1_package/conanfile.py | 23 ++++ recipes/boost-predef/config.yml | 3 + 8 files changed, 217 insertions(+) create mode 100644 recipes/boost-predef/all/conandata.yml create mode 100644 recipes/boost-predef/all/conanfile.py create mode 100644 recipes/boost-predef/all/test_package/CMakeLists.txt create mode 100644 recipes/boost-predef/all/test_package/conanfile.py create mode 100644 recipes/boost-predef/all/test_package/main.cpp create mode 100644 recipes/boost-predef/all/test_v1_package/CMakeLists.txt create mode 100644 recipes/boost-predef/all/test_v1_package/conanfile.py create mode 100644 recipes/boost-predef/config.yml diff --git a/recipes/boost-predef/all/conandata.yml b/recipes/boost-predef/all/conandata.yml new file mode 100644 index 0000000000000..68e673dc2c78e --- /dev/null +++ b/recipes/boost-predef/all/conandata.yml @@ -0,0 +1,6 @@ +sources: + "1.83.0": + url: + - "https://github.com/boostorg/predef/archive/refs/tags/boost-1.83.0.tar.gz" + sha256: "c0d8a35f9258846f9daa511c0de052fcce0c88dbe1e697f3047118c31fa13854" + diff --git a/recipes/boost-predef/all/conanfile.py b/recipes/boost-predef/all/conanfile.py new file mode 100644 index 0000000000000..2d77948b1faef --- /dev/null +++ b/recipes/boost-predef/all/conanfile.py @@ -0,0 +1,110 @@ +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.build import check_min_cppstd +from conan.tools.files import ( + apply_conandata_patches, copy, export_conandata_patches, + get, mkdir, rename, rm, rmdir +) +from conan.tools.layout import basic_layout +from conan.tools.scm import Version + +import glob +import os + +required_conan_version = ">=1.53.0" + +class BoostPredefConan(ConanFile): + name = "boost-predef" + description = "This library defines a set of compiler, architecture, operating system, library, and other version numbers from the information it can gather of C, C++, Objective C, and Objective C++ predefined macros or those defined in generally available headers." + url = "https://github.com/boostorg/predef" + homepage = "https://www.boost.org" + license = "BSL-1.0" + topics = ("libraries", "cpp") + + settings = "os", "arch", "compiler", "build_type" + options = {} + default_options = {} + + short_paths = True + no_copy_source = True + + @property + def _min_cppstd(self): + return 11 + + def export_sources(self): + export_conandata_patches(self) + + def config_options(self): + pass + + def configure(self): + pass + + def layout(self): + basic_layout(self, src_folder="src") + + def validate(self): + if self.settings.compiler.get_safe("cppstd"): + check_min_cppstd(self, self._min_cppstd) + minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False) + if minimum_version and Version(self.settings.compiler.version) < minimum_version: + raise ConanInvalidConfiguration( + f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support." + ) + + def requirements(self): + pass + + def package_id(self): + self.info.clear() + + def build_requirements(self): + pass + + def source(self): + get(self, **self.conan_data["sources"][self.version], + destination=self.source_folder, strip_root=True) + apply_conandata_patches(self) + + def build(self): + apply_conandata_patches(self) + + def package(self): + copy( + self, + "*", + os.path.join(self.source_folder, "include"), + os.path.join(self.package_folder, "include"), + ) + + def package_info(self): + # Folders not used for header-only + self.cpp_info.bindirs = [] + self.cpp_info.libdirs = [] + + self.env_info.BOOST_ROOT = self.package_folder + + self.cpp_info.set_property("cmake_file_name", "Boost") + self.cpp_info.filenames["cmake_find_package"] = "Boost" + self.cpp_info.filenames["cmake_find_package_multi"] = "Boost" + self.cpp_info.names["cmake_find_package"] = "Boost" + self.cpp_info.names["cmake_find_package_multi"] = "Boost" + + # - Use 'predef' component for all includes + defines + + self.cpp_info.components["predef"].libs = [] + self.cpp_info.components["predef"].libdirs = [] + self.cpp_info.components["predef"].set_property("cmake_target_name", "Boost::predef") + self.cpp_info.components["predef"].names["cmake_find_package"] = "predef" + self.cpp_info.components["predef"].names["cmake_find_package_multi"] = "predef" + self.cpp_info.components["predef"].names["pkg_config"] = "boost" + + # # Boost::boost is an alias of Boost::predef + # self.cpp_info.components["_boost_cmake"].requires = ["predef"] + # self.cpp_info.components["_boost_cmake"].set_property("cmake_target_name", "Boost::boost") + # self.cpp_info.components["_boost_cmake"].names["cmake_find_package"] = "boost" + # self.cpp_info.components["_boost_cmake"].names["cmake_find_package_multi"] = "boost" + + # if self.options.header_only: + # self.cpp_info.components["_boost_cmake"].libdirs = [] diff --git a/recipes/boost-predef/all/test_package/CMakeLists.txt b/recipes/boost-predef/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..b94157f576e3c --- /dev/null +++ b/recipes/boost-predef/all/test_package/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.15) +project(test_package LANGUAGES CXX) + +if(UNIX AND NOT APPLE) + # use RPATH instead of RUNPATH so that + # transitive dependencies can be located + add_link_options("LINKER:--disable-new-dtags") +endif() + +include(CTest) +enable_testing() + +find_package(Boost REQUIRED) +add_executable(main_exe main.cpp) +target_link_libraries(main_exe PRIVATE Boost::predef) +add_test(NAME boost_boost COMMAND main_exe) diff --git a/recipes/boost-predef/all/test_package/conanfile.py b/recipes/boost-predef/all/test_package/conanfile.py new file mode 100644 index 0000000000000..807b51abfd71f --- /dev/null +++ b/recipes/boost-predef/all/test_package/conanfile.py @@ -0,0 +1,42 @@ +from conan import ConanFile +from conan.errors import ConanException +from conan.tools.build import can_run +from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout +from conan.tools.files import chdir + + +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeDeps", "VirtualBuildEnv", "VirtualRunEnv" + test_type = "explicit" + + def layout(self): + cmake_layout(self) + + def requirements(self): + self.requires(self.tested_reference_str) + + def generate(self): + tc = CMakeToolchain(self) + tc.generate() + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if not can_run(self): + return + with chdir(self, self.folders.build_folder): + # When boost and its dependencies are built as shared libraries, + # the test executables need to locate them. Typically the + # `conanrun` env should be enough, but this may cause problems on macOS + # where the CMake installation has dependencies on Apple-provided + # system libraries that are incompatible with Conan-provided ones. + # When `conanrun` is enabled, DYLD_LIBRARY_PATH will also apply + # to ctest itself. Given that CMake already embeds RPATHs by default, + # we can bypass this by using the `conanbuild` environment on + # non-Windows platforms, while still retaining the correct behaviour. + env = "conanrun" if self.settings.os == "Windows" else "conanbuild" + self.run(f"ctest --output-on-failure -C {self.settings.build_type}", env=env) diff --git a/recipes/boost-predef/all/test_package/main.cpp b/recipes/boost-predef/all/test_package/main.cpp new file mode 100644 index 0000000000000..03f4ff285dff5 --- /dev/null +++ b/recipes/boost-predef/all/test_package/main.cpp @@ -0,0 +1,7 @@ +#include +#include + +int main(int argc, const char * const argv[]) { + std::cout << "C++ Standard version: " << BOOST_LANG_STDCPP << "\n"; + return 0; +} diff --git a/recipes/boost-predef/all/test_v1_package/CMakeLists.txt b/recipes/boost-predef/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..c23ed5cfe6d98 --- /dev/null +++ b/recipes/boost-predef/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 3.1) +project(test_v1_package) + +enable_testing() + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package + ${CMAKE_CURRENT_BINARY_DIR}/test_package) diff --git a/recipes/boost-predef/all/test_v1_package/conanfile.py b/recipes/boost-predef/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..d6486f74bf37a --- /dev/null +++ b/recipes/boost-predef/all/test_v1_package/conanfile.py @@ -0,0 +1,23 @@ +from conans import ConanFile, CMake, tools +from conans.errors import ConanException +import os + + +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "cmake", "cmake_find_package" + + def build(self): + # FIXME: tools.vcvars added for clang-cl. Remove once conan supports clang-cl properly. (https://github.com/conan-io/conan-center-index/pull/1453) + with tools.vcvars(self.settings) if (self.settings.os == "Windows" and self.settings.compiler == "clang") else tools.no_op(): + cmake = CMake(self) + cmake.configure() + # Disable parallel builds because c3i (=conan-center's test/build infrastructure) seems to choke here + cmake.parallel = False + cmake.build() + + def test(self): + if tools.cross_building(self): + return + self.run(f"ctest --output-on-failure -C {self.settings.build_type}", run_environment=True) + diff --git a/recipes/boost-predef/config.yml b/recipes/boost-predef/config.yml new file mode 100644 index 0000000000000..b551933add987 --- /dev/null +++ b/recipes/boost-predef/config.yml @@ -0,0 +1,3 @@ +versions: + "1.83.0": + folder: all From 60cdc074b2a769ac6cae006ff122e26a96a6497e Mon Sep 17 00:00:00 2001 From: Fernando Pelliccioni Date: Tue, 21 Nov 2023 16:23:34 +0100 Subject: [PATCH 2/3] fix recipe --- recipes/boost-predef/all/conanfile.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/recipes/boost-predef/all/conanfile.py b/recipes/boost-predef/all/conanfile.py index 2d77948b1faef..f4b5aae67159e 100644 --- a/recipes/boost-predef/all/conanfile.py +++ b/recipes/boost-predef/all/conanfile.py @@ -47,11 +47,6 @@ def layout(self): def validate(self): if self.settings.compiler.get_safe("cppstd"): check_min_cppstd(self, self._min_cppstd) - minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False) - if minimum_version and Version(self.settings.compiler.version) < minimum_version: - raise ConanInvalidConfiguration( - f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support." - ) def requirements(self): pass From 26d0ad0ab44a18380bb09b1d0d861509f0b447d7 Mon Sep 17 00:00:00 2001 From: Fernando Pelliccioni Date: Tue, 21 Nov 2023 16:27:26 +0100 Subject: [PATCH 3/3] fix linting errors --- recipes/boost-predef/all/conandata.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/recipes/boost-predef/all/conandata.yml b/recipes/boost-predef/all/conandata.yml index 68e673dc2c78e..af5415f3b1d87 100644 --- a/recipes/boost-predef/all/conandata.yml +++ b/recipes/boost-predef/all/conandata.yml @@ -3,4 +3,3 @@ sources: url: - "https://github.com/boostorg/predef/archive/refs/tags/boost-1.83.0.tar.gz" sha256: "c0d8a35f9258846f9daa511c0de052fcce0c88dbe1e697f3047118c31fa13854" -