Skip to content

Commit

Permalink
(#22554) [boost] Add default support to C++11
Browse files Browse the repository at this point in the history
* Add support to C++11

Signed-off-by: Uilian Ries <[email protected]>

* update tests

Signed-off-by: Uilian Ries <[email protected]>

* update more tests with c++11

Signed-off-by: Uilian Ries <[email protected]>

* apple clang still does not suport c++11 by default

Signed-off-by: Uilian Ries <[email protected]>

* Use correct cxxstd flag with b2

Signed-off-by: Uilian Ries <[email protected]>

* format nothing in string

Signed-off-by: Uilian Ries <[email protected]>

---------

Signed-off-by: Uilian Ries <[email protected]>
Co-authored-by: Rubén Rincón Blanco <[email protected]>
  • Loading branch information
uilianries and AbrilRBS authored Feb 1, 2024
1 parent c77d764 commit 9eb51cf
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
40 changes: 26 additions & 14 deletions recipes/boost/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from conan import ConanFile
from conan.errors import ConanException, ConanInvalidConfiguration
from conan.tools.apple import is_apple_os, to_apple_arch, XCRun
from conan.tools.build import build_jobs, check_min_cppstd, cross_building, valid_min_cppstd
from conan.tools.build import build_jobs, check_min_cppstd, cross_building, valid_min_cppstd, supported_cppstd
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import (
apply_conandata_patches, chdir, collect_libs, copy, export_conandata_patches,
Expand Down Expand Up @@ -163,11 +163,12 @@ def export_sources(self):

@property
def _min_compiler_version_default_cxx11(self):
# Minimum compiler version having c++ standard >= 11
""" Minimum compiler version having c++ standard >= 11
"""
return {
"gcc": 6,
"clang": 6,
"apple-clang": 14,
"apple-clang": 99, # still uses C++98 by default. XCode does not reflect apple-clang
"Visual Studio": 14, # guess
"msvc": 190, # guess
}.get(str(self.settings.compiler))
Expand All @@ -177,12 +178,19 @@ def _min_compiler_version_default_cxx20(self):
return {
"gcc": 99,
"clang": 99,
# As of the end of 2023, only apple-clang >=14 use C++20 as their default C++ version.
"apple-clang": 14,
"apple-clang": 99,
"Visual Studio": 99,
"msvc": 999,
}.get(str(self.settings.compiler))

def _has_cppstd_11_supported(self):
cppstd = self.settings.compiler.get_safe("cppstd")
if cppstd:
return valid_min_cppstd(self, 11)
compiler_version = self._min_compiler_version_default_cxx11
if compiler_version:
return (Version(self.settings.compiler.version) >= compiler_version) or "11" in supported_cppstd(self)

@property
def _min_compiler_version_nowide(self):
# Nowide needs c++11 + swappable std::fstream
Expand Down Expand Up @@ -286,7 +294,7 @@ def config_options(self):
else:
version_cxx11_standard_json = self._min_compiler_version_default_cxx11
if version_cxx11_standard_json:
if Version(self.settings.compiler.version) < version_cxx11_standard_json:
if not self._has_cppstd_11_supported:
self.options.without_fiber = True
self.options.without_json = True
self.options.without_nowide = True
Expand Down Expand Up @@ -332,7 +340,7 @@ def disable_math():
min_compiler_version = self._min_compiler_version_default_cxx11
if min_compiler_version is None:
self.output.warning("Assuming the compiler supports c++11 by default")
elif Version(self.settings.compiler.version) < min_compiler_version:
elif not self._has_cppstd_11_supported:
disable_math()

if Version(self.version) >= "1.79.0":
Expand All @@ -354,7 +362,7 @@ def disable_wave():
min_compiler_version = self._min_compiler_version_default_cxx11
if min_compiler_version is None:
self.output.warning("Assuming the compiler supports c++11 by default")
elif Version(self.settings.compiler.version) < min_compiler_version:
elif not self._has_cppstd_11_supported:
disable_wave()

if Version(self.version) >= "1.81.0":
Expand All @@ -376,7 +384,7 @@ def disable_locale():
min_compiler_version = self._min_compiler_version_default_cxx11
if min_compiler_version is None:
self.output.warning("Assuming the compiler supports c++11 by default")
elif Version(self.settings.compiler.version) < min_compiler_version:
elif not self._has_cppstd_11_supported:
disable_locale()

if Version(self.version) >= "1.84.0":
Expand Down Expand Up @@ -532,8 +540,7 @@ def validate(self):
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, 11)
else:
version_cxx11_standard = self._min_compiler_version_default_cxx11
if version_cxx11_standard and Version(self.settings.compiler.version) < version_cxx11_standard:
if not self._has_cppstd_11_supported:
raise ConanInvalidConfiguration(
f"Boost.{{{','.join(self._cxx11_boost_libraries)}}} requires a c++11 compiler "
"(please set compiler.cppstd or use a newer compiler)"
Expand Down Expand Up @@ -1095,9 +1102,14 @@ def add_defines(library):

flags.append(f"toolset={self._toolset}")

if self.settings.get_safe("compiler.cppstd"):
cppstd_flag = AutotoolsToolchain(self).cppstd
flags.append(f"cxxflags={cppstd_flag}")
safe_cppstd = self.settings.get_safe("compiler.cppstd")
if safe_cppstd:
cppstd_version = safe_cppstd.replace("gnu", "")
flags.append(f"cxxstd={cppstd_version}")
if "gnu" in safe_cppstd:
flags.append("cxxstd-dialect=gnu")
elif self._has_cppstd_11_supported:
flags.append("cxxstd=11")

# LDFLAGS
link_flags = []
Expand Down
9 changes: 9 additions & 0 deletions recipes/boost/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ if(NOT HEADER_ONLY)
find_package(Boost COMPONENTS regex REQUIRED)
add_executable(regex_exe regex.cpp)
target_link_libraries(regex_exe PRIVATE Boost::regex)
set_property(TARGET regex_exe PROPERTY CXX_STANDARD 11)
add_test(NAME boost_regex COMMAND regex_exe)
endif()

Expand All @@ -47,6 +48,7 @@ if(NOT HEADER_ONLY)
find_package(Boost COMPONENTS chrono REQUIRED)
add_executable(chrono_exe chrono.cpp)
target_link_libraries(chrono_exe PRIVATE Boost::chrono)
set_property(TARGET chrono_exe PROPERTY CXX_STANDARD 11)
add_test(NAME chrono_test COMMAND chrono_exe)
endif()

Expand Down Expand Up @@ -78,6 +80,7 @@ if(NOT HEADER_ONLY)
find_package(Boost COMPONENTS locale REQUIRED)
add_executable(locale_exe locale.cpp)
target_link_libraries(locale_exe PRIVATE Boost::locale)
set_property(TARGET locale_exe PROPERTY CXX_STANDARD 11)
add_test(NAME boost_locale COMMAND locale_exe)
endif()

Expand All @@ -86,13 +89,15 @@ if(NOT HEADER_ONLY)
add_executable(stacktrace_addr2line_exe stacktrace.cpp)
target_compile_definitions(stacktrace_addr2line_exe PRIVATE TEST_STACKTRACE_IMPL=1)
target_link_libraries(stacktrace_addr2line_exe PRIVATE Boost::stacktrace_addr2line)
set_property(TARGET stacktrace_addr2line_exe PROPERTY CXX_STANDARD 11)
add_test(NAME boost_stacktrace_addr2line COMMAND stacktrace_addr2line_exe)
endif()

if(WITH_STACKTRACE_BACKTRACE)
add_executable(stacktrace_backtrace_exe stacktrace.cpp)
target_compile_definitions(stacktrace_backtrace_exe PRIVATE TEST_STACKTRACE_IMPL=2)
target_link_libraries(stacktrace_backtrace_exe PRIVATE Boost::stacktrace_backtrace)
set_property(TARGET stacktrace_backtrace_exe PROPERTY CXX_STANDARD 11)
add_test(NAME boost_stacktrace_backtrace COMMAND stacktrace_backtrace_exe)
endif()

Expand All @@ -102,22 +107,26 @@ if(NOT HEADER_ONLY)
add_executable(stacktrace_noop_exe stacktrace.cpp)
target_compile_definitions(stacktrace_noop_exe PRIVATE TEST_STACKTRACE_IMPL=4)
target_link_libraries(stacktrace_noop_exe PRIVATE Boost::stacktrace_noop)
set_property(TARGET stacktrace_noop_exe PROPERTY CXX_STANDARD 11)
add_test(NAME boost_stacktrace_noop COMMAND stacktrace_noop_exe)

if(WIN32)
add_executable(stacktrace_windbg_exe stacktrace.cpp)
target_compile_definitions(stacktrace_windbg_exe PRIVATE TEST_STACKTRACE_IMPL=5)
target_link_libraries(stacktrace_windbg_exe PRIVATE Boost::stacktrace_windbg)
set_property(TARGET stacktrace_windbg_exe PROPERTY CXX_STANDARD 11)
add_test(NAME boost_stacktrace_windbg COMMAND stacktrace_windbg_exe)

add_executable(stacktrace_windbg_cached_exe stacktrace.cpp)
target_compile_definitions(stacktrace_windbg_cached_exe PRIVATE TEST_STACKTRACE_IMPL=6)
target_link_libraries(stacktrace_windbg_cached_exe PRIVATE Boost::stacktrace_windbg_cached)
set_property(TARGET stacktrace_windbg_cached_exe PROPERTY CXX_STANDARD 11)
add_test(NAME boost_stacktrace_windbg_cached COMMAND stacktrace_windbg_cached_exe)
else()
add_executable(stacktrace_basic_exe stacktrace.cpp)
target_compile_definitions(stacktrace_basic_exe PRIVATE TEST_STACKTRACE_IMPL=3)
target_link_libraries(stacktrace_basic_exe PRIVATE Boost::stacktrace_basic)
set_property(TARGET stacktrace_basic_exe PROPERTY CXX_STANDARD 11)
add_test(NAME boost_stacktrace_basic COMMAND stacktrace_basic_exe)
endif()
endif()
Expand Down

0 comments on commit 9eb51cf

Please sign in to comment.