From 4db6450fe8a9f8682f1a2e645e57abea8ed04f2f Mon Sep 17 00:00:00 2001 From: Andrey Semashev Date: Mon, 25 Sep 2023 20:06:26 +0300 Subject: [PATCH] Conditionally link with Boost.Regex library, if it's in C++03 mode. Boost.Log supports compilers that do not qualify as C++11 compilers for Boost.Regex, even if they are compiling in C++11 mode. In that case, we still need to link with Boost.Regex v4 prebuilt library. For more recent compilers, Boost.Regex v5 is used, and that is a header-only library. This commit removes linking with Boost.Regex when this is detected at configure time. Note that only Boost.Build is updated. CMake doesn't need to be updated since even header-only libraries need to be listed as dependencies. Closes https://github.com/boostorg/log/pull/219. --- build/Jamfile.v2 | 147 ++---------------- build/log-arch-config.jam | 18 +++ build/log-build-config.jam | 135 ++++++++++++++++ config/regex-header-only/Jamfile.jam | 19 +++ .../regex-header-only/regex_header_only.cpp | 17 ++ doc/changelog.qbk | 1 + test/Jamfile.v2 | 3 +- 7 files changed, 206 insertions(+), 134 deletions(-) create mode 100644 build/log-build-config.jam create mode 100644 config/regex-header-only/Jamfile.jam create mode 100644 config/regex-header-only/regex_header_only.cpp diff --git a/build/Jamfile.v2 b/build/Jamfile.v2 index 46dd04596..f3fcb58fa 100644 --- a/build/Jamfile.v2 +++ b/build/Jamfile.v2 @@ -14,16 +14,14 @@ import feature ; import configure ; import log-arch-config ; import log-platform-config ; +import log-build-config ; + using mc ; local here = [ modules.binding $(__name__) ] ; project.push-current [ project.current ] ; -project.load [ path.join [ path.make $(here:D) ] ../config/message-compiler ] ; project.load [ path.join [ path.make $(here:D) ] ../config/x86-ext ] ; -project.load [ path.join [ path.make $(here:D) ] ../config/pthread-mutex-robust ] ; -project.load [ path.join [ path.make $(here:D) ] ../config/native-syslog ] ; -project.load [ path.join [ path.make $(here:D) ] ../config/atomic-int32 ] ; project.pop-current ; # Windows libs @@ -41,132 +39,15 @@ lib nsl ; lib ipv6 ; explicit rt socket nsl ipv6 ; -rule has-config-flag ( flag : properties * ) -{ - if ( "$(flag)" in $(properties) || "$(flag)=1" in $(properties) ) - { - return 1 ; - } - else - { - return ; - } -} - -rule check-instruction-set ( properties * ) -{ - local result ; - local instruction_set = [ log-arch-config.deduce-instruction-set $(properties) ] ; - - if $(instruction_set) = i386 || $(instruction_set) = i486 - { - if ! $(.annouced-failure) - { - ECHO Boost.Log is not supported on the specified target CPU and will not be built. At least i586 class CPU is required. ; - .annouced-failure = 1 ; - } - result = no ; - } - - return $(result) ; -} - -rule select-regex-backend ( properties * ) -{ - local result ; - - # Use Boost.Regex backend by default. It produces smaller executables and also has the best performance for small string matching. - if ! ( - [ has-config-flag BOOST_LOG_WITHOUT_SETTINGS_PARSERS : $(properties) ] || - [ has-config-flag BOOST_LOG_WITHOUT_DEFAULT_FACTORIES : $(properties) ] || - [ has-config-flag BOOST_LOG_USE_STD_REGEX : $(properties) ] || - [ has-config-flag BOOST_LOG_USE_BOOST_XPRESSIVE : $(properties) ] ) - { - result = /boost/regex//boost_regex ; - } - - return $(result) ; -} - -rule check-pthread-mutex-robust ( properties * ) -{ - local result ; - - local has_pthread_mutex_robust = [ configure.builds /boost/log/pthread-mutex-robust//pthread_mutex_robust : $(properties) : "pthread supports robust mutexes" ] ; - if $(has_pthread_mutex_robust) - { - result = BOOST_LOG_HAS_PTHREAD_MUTEX_ROBUST ; - } - - return $(result) ; -} - -rule check-atomic-int32 ( properties * ) -{ - local result ; - - local has_atomic_int32 = [ configure.builds /boost/log/atomic-int32//atomic_int32 : $(properties) : "native atomic int32 supported" ] ; - if ! $(has_atomic_int32) - { - result = BOOST_LOG_WITHOUT_IPC ; - } - - return $(result) ; -} - -rule check-native-syslog ( properties * ) -{ - local result ; - - if ! [ has-config-flag BOOST_LOG_WITHOUT_SYSLOG : $(properties) ] - { - local has_native_syslog = [ configure.builds /boost/log/native-syslog//native_syslog : $(properties) : "native syslog supported" ] ; - if $(has_native_syslog) - { - result = BOOST_LOG_USE_NATIVE_SYSLOG ; - } - } - - return $(result) ; -} - -rule check-message-compiler ( properties * ) -{ - local result ; - - if windows in $(properties) - { - if ! [ has-config-flag BOOST_LOG_WITHOUT_EVENT_LOG : $(properties) ] - { - local has_mc = [ configure.builds /boost/log/message-compiler//test-availability : $(properties) : "has message compiler" ] ; - if ! $(has_mc) - { - result = BOOST_LOG_WITHOUT_EVENT_LOG ; - } - } - else - { - # This branch is needed to fix building with MinGW - result = BOOST_LOG_WITHOUT_EVENT_LOG ; - } - } - else - { - result = BOOST_LOG_WITHOUT_EVENT_LOG ; - } - - return $(result) ; -} - project boost/log : source-location ../src : requirements - @check-instruction-set - @check-atomic-int32 - @select-regex-backend - @check-pthread-mutex-robust - @check-native-syslog - @check-message-compiler + @log-arch-config.check-instruction-set + @log-build-config.check-atomic-int32 + @log-build-config.select-regex-backend + @log-build-config.check-pthread-mutex-robust + @log-build-config.check-native-syslog + @log-build-config.check-message-compiler @log-platform-config.set-platform-defines ../src @@ -346,7 +227,7 @@ rule select-platform-specific-sources ( properties * ) result += windows/light_rw_mutex.cpp ; result += windows/is_debugger_present.cpp ; - if ! [ has-config-flag BOOST_LOG_WITHOUT_IPC : $(properties) ] + if ! [ log-build-config.has-config-flag BOOST_LOG_WITHOUT_IPC : $(properties) ] { result += windows/object_name.cpp ; result += windows/mapped_shared_memory.cpp ; @@ -355,12 +236,12 @@ rule select-platform-specific-sources ( properties * ) result += secur32 ; } - if ! [ has-config-flag BOOST_LOG_WITHOUT_DEBUG_OUTPUT : $(properties) ] + if ! [ log-build-config.has-config-flag BOOST_LOG_WITHOUT_DEBUG_OUTPUT : $(properties) ] { result += windows/debug_output_backend.cpp ; } - if ! [ has-config-flag BOOST_LOG_WITHOUT_EVENT_LOG : $(properties) ] + if ! [ log-build-config.has-config-flag BOOST_LOG_WITHOUT_EVENT_LOG : $(properties) ] { result += windows/simple_event_log.mc ; result += windows/event_log_backend.cpp ; @@ -374,14 +255,14 @@ rule select-platform-specific-sources ( properties * ) result += BOOST_LOG_WITHOUT_EVENT_LOG ; result += BOOST_LOG_WITHOUT_DEBUG_OUTPUT ; - if ! [ has-config-flag BOOST_LOG_WITHOUT_IPC : $(properties) ] + if ! [ log-build-config.has-config-flag BOOST_LOG_WITHOUT_IPC : $(properties) ] { result += posix/object_name.cpp ; result += posix/ipc_reliable_message_queue.cpp ; } } - if ! [ has-config-flag BOOST_LOG_WITHOUT_SYSLOG : $(properties) ] + if ! [ log-build-config.has-config-flag BOOST_LOG_WITHOUT_SYSLOG : $(properties) ] { result += syslog_backend.cpp ; } @@ -422,7 +303,7 @@ rule check-boost_log_setup-enabled ( properties * ) { local result ; - if [ has-config-flag BOOST_LOG_WITHOUT_SETTINGS_PARSERS : $(properties) ] + if [ log-build-config.has-config-flag BOOST_LOG_WITHOUT_SETTINGS_PARSERS : $(properties) ] { result = no ; } diff --git a/build/log-arch-config.jam b/build/log-arch-config.jam index 89ecee405..ee410ce1e 100644 --- a/build/log-arch-config.jam +++ b/build/log-arch-config.jam @@ -154,3 +154,21 @@ rule avx2-flags ( properties * ) return $(result) ; } + +rule check-instruction-set ( properties * ) +{ + local result ; + local instruction_set = [ log-arch-config.deduce-instruction-set $(properties) ] ; + + if $(instruction_set) = i386 || $(instruction_set) = i486 + { + if ! $(.annouced-failure) + { + ECHO Boost.Log is not supported on the specified target CPU and will not be built. At least i586 class CPU is required. ; + .annouced-failure = 1 ; + } + result = no ; + } + + return $(result) ; +} diff --git a/build/log-build-config.jam b/build/log-build-config.jam new file mode 100644 index 000000000..51cc31279 --- /dev/null +++ b/build/log-build-config.jam @@ -0,0 +1,135 @@ +# log-build-config.jam +# +# Copyright 2023 Andrey Semashev +# +# Distributed under the Boost Software License Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +import configure ; +import project ; +import path ; +import property ; +import feature ; + +local here = [ modules.binding $(__name__) ] ; + +project.push-current [ project.current ] ; +project.load [ path.join [ path.make $(here:D) ] ../config/message-compiler ] ; +project.load [ path.join [ path.make $(here:D) ] ../config/pthread-mutex-robust ] ; +project.load [ path.join [ path.make $(here:D) ] ../config/native-syslog ] ; +project.load [ path.join [ path.make $(here:D) ] ../config/atomic-int32 ] ; +project.load [ path.join [ path.make $(here:D) ] ../config/regex-header-only ] ; +project.pop-current ; + +rule has-config-flag ( flag : properties * ) +{ + if ( "$(flag)" in $(properties) || "$(flag)=1" in $(properties) ) + { + return 1 ; + } + else + { + return ; + } +} + +rule check-regex-header-only ( properties * ) +{ + local result ; + + local has_regex_header_only = [ configure.builds /boost/log/regex-header-only//regex_header_only : $(properties) : "Boost.Regex is header-only" ] ; + if ! $(has_regex_header_only) + { + result = /boost/regex//boost_regex ; + } + + return $(result) ; +} + +rule check-atomic-int32 ( properties * ) +{ + local result ; + + local has_atomic_int32 = [ configure.builds /boost/log/atomic-int32//atomic_int32 : $(properties) : "native atomic int32 supported" ] ; + if ! $(has_atomic_int32) + { + result = BOOST_LOG_WITHOUT_IPC ; + } + + return $(result) ; +} + +rule check-pthread-mutex-robust ( properties * ) +{ + local result ; + + local has_pthread_mutex_robust = [ configure.builds /boost/log/pthread-mutex-robust//pthread_mutex_robust : $(properties) : "pthread supports robust mutexes" ] ; + if $(has_pthread_mutex_robust) + { + result = BOOST_LOG_HAS_PTHREAD_MUTEX_ROBUST ; + } + + return $(result) ; +} + +rule check-native-syslog ( properties * ) +{ + local result ; + + if ! [ has-config-flag BOOST_LOG_WITHOUT_SYSLOG : $(properties) ] + { + local has_native_syslog = [ configure.builds /boost/log/native-syslog//native_syslog : $(properties) : "native syslog supported" ] ; + if $(has_native_syslog) + { + result = BOOST_LOG_USE_NATIVE_SYSLOG ; + } + } + + return $(result) ; +} + +rule check-message-compiler ( properties * ) +{ + local result ; + + if windows in $(properties) + { + if ! [ has-config-flag BOOST_LOG_WITHOUT_EVENT_LOG : $(properties) ] + { + local has_mc = [ configure.builds /boost/log/message-compiler//test-availability : $(properties) : "has message compiler" ] ; + if ! $(has_mc) + { + result = BOOST_LOG_WITHOUT_EVENT_LOG ; + } + } + else + { + # This branch is needed to fix building with MinGW + result = BOOST_LOG_WITHOUT_EVENT_LOG ; + } + } + else + { + result = BOOST_LOG_WITHOUT_EVENT_LOG ; + } + + return $(result) ; +} + +rule select-regex-backend ( properties * ) +{ + local result ; + + # Use Boost.Regex backend by default. It produces smaller executables and also has the best performance for small string matching. + if ! ( + [ log-build-config.has-config-flag BOOST_LOG_WITHOUT_SETTINGS_PARSERS : $(properties) ] || + [ log-build-config.has-config-flag BOOST_LOG_WITHOUT_DEFAULT_FACTORIES : $(properties) ] || + [ log-build-config.has-config-flag BOOST_LOG_USE_STD_REGEX : $(properties) ] || + [ log-build-config.has-config-flag BOOST_LOG_USE_BOOST_XPRESSIVE : $(properties) ] ) + { + result = @log-build-config.check-regex-header-only ; + } + + return $(result) ; +} diff --git a/config/regex-header-only/Jamfile.jam b/config/regex-header-only/Jamfile.jam new file mode 100644 index 000000000..90d28e94f --- /dev/null +++ b/config/regex-header-only/Jamfile.jam @@ -0,0 +1,19 @@ +# +# Copyright Andrey Semashev 2023. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) +# + +import project ; +import log-platform-config ; + +project /boost/log/regex-header-only + : source-location . + : requirements + @log-platform-config.set-platform-defines + off + ; + +obj regex_header_only : regex_header_only.cpp ; +explicit regex_header_only ; diff --git a/config/regex-header-only/regex_header_only.cpp b/config/regex-header-only/regex_header_only.cpp new file mode 100644 index 000000000..d58422770 --- /dev/null +++ b/config/regex-header-only/regex_header_only.cpp @@ -0,0 +1,17 @@ +/* + * Copyright Andrey Semashev 2023. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * http://www.boost.org/LICENSE_1_0.txt) + */ + +#include + +#if defined(BOOST_REGEX_CXX03) +#error Boost.Log: Boost.Regex is in C++03 mode and is not header-only +#endif + +int main(int, char*[]) +{ + return 0; +} diff --git a/doc/changelog.qbk b/doc/changelog.qbk index e46cc2bfb..5d526c8b2 100644 --- a/doc/changelog.qbk +++ b/doc/changelog.qbk @@ -12,6 +12,7 @@ [heading 2.28, Boost 1.84] * C++03 is no longer supported. A C++11 or later compiler is required. +* When built with C++11 compilers that are conforming enough for Boost.Regex v5 to be used, Boost.Log no longer links with Boost.Regex prebuilt library, since Boost.Regex v5 is header-only. [heading 2.27, Boost 1.83] diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 73107a27f..34a8324fb 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -11,10 +11,12 @@ import path ; import regex ; import os ; import ../build/log-platform-config ; +import ../build/log-build-config ; project : requirements @log-platform-config.set-platform-defines + @log-build-config.check-regex-header-only common @@ -50,7 +52,6 @@ project /boost/log//boost_log /boost/log//boost_log_setup - /boost/regex//boost_regex /boost/filesystem//boost_filesystem /boost/test//boost_unit_test_framework single:BOOST_LOG_NO_THREADS