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-predef] Add Modular Boost Predef recipe #21299

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions recipes/boost-predef/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
sources:
"1.83.0":
url:
- "https://github.com/boostorg/predef/archive/refs/tags/boost-1.83.0.tar.gz"
sha256: "c0d8a35f9258846f9daa511c0de052fcce0c88dbe1e697f3047118c31fa13854"
105 changes: 105 additions & 0 deletions recipes/boost-predef/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration

Check warning on line 2 in recipes/boost-predef/all/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Unused ConanInvalidConfiguration imported from conan.errors
from conan.tools.build import check_min_cppstd
from conan.tools.files import (

Check warning on line 4 in recipes/boost-predef/all/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Unused mkdir imported from conan.tools.files

Check warning on line 4 in recipes/boost-predef/all/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Unused rename imported from conan.tools.files

Check warning on line 4 in recipes/boost-predef/all/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Unused rm imported from conan.tools.files

Check warning on line 4 in recipes/boost-predef/all/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Unused rmdir imported from conan.tools.files
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

Check warning on line 9 in recipes/boost-predef/all/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Unused Version imported from conan.tools.scm

import glob

Check warning on line 11 in recipes/boost-predef/all/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Unused 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)

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 = []
16 changes: 16 additions & 0 deletions recipes/boost-predef/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
42 changes: 42 additions & 0 deletions recipes/boost-predef/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from conan import ConanFile
from conan.errors import ConanException

Check warning on line 2 in recipes/boost-predef/all/test_package/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed test_package/conanfile.py (v2 migration)

Unused ConanException imported from conan.errors
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)
7 changes: 7 additions & 0 deletions recipes/boost-predef/all/test_package/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <boost/predef.h>
#include <iostream>

int main(int argc, const char * const argv[]) {
std::cout << "C++ Standard version: " << BOOST_LANG_STDCPP << "\n";
return 0;
}
10 changes: 10 additions & 0 deletions recipes/boost-predef/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
23 changes: 23 additions & 0 deletions recipes/boost-predef/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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)

3 changes: 3 additions & 0 deletions recipes/boost-predef/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.83.0":
folder: all