Skip to content

Commit

Permalink
Merge branch 'master' into change_default_charset
Browse files Browse the repository at this point in the history
  • Loading branch information
stephen-webb committed Aug 14, 2023
2 parents cf0dc77 + 2569c6b commit e459052
Show file tree
Hide file tree
Showing 17 changed files with 344 additions and 344 deletions.
10 changes: 0 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,6 @@ endif(LOG4CXX_QT_SUPPORT)
#
get_directory_property( HAS_LIBESMTP DIRECTORY src/main/include DEFINITION HAS_LIBESMTP )
get_directory_property( HAS_SYSLOG DIRECTORY src/main/include DEFINITION HAS_SYSLOG )
get_directory_property( THREAD_IMPL DIRECTORY src DEFINITION THREAD_IMPL )
get_directory_property( SMART_PTR_IMPL DIRECTORY src DEFINITION SMART_PTR_IMPL )
get_directory_property( MUTEX_IMPL DIRECTORY src DEFINITION MUTEX_IMPL )
get_directory_property( SHARED_MUTEX_IMPL DIRECTORY src DEFINITION SHARED_MUTEX_IMPL )
get_directory_property( ATOMIC_IMPL DIRECTORY src DEFINITION ATOMIC_IMPL )
get_directory_property( FILESYSTEM_IMPL DIRECTORY src DEFINITION FILESYSTEM_IMPL )
get_directory_property( STD_MAKE_UNIQUE_IMPL DIRECTORY src DEFINITION STD_MAKE_UNIQUE_IMPL )
get_directory_property( STD_LIB_HAS_UNICODE_STRING DIRECTORY src DEFINITION STD_LIB_HAS_UNICODE_STRING )
Expand Down Expand Up @@ -310,12 +305,7 @@ message(STATUS " Qt support ...................... : ${LOG4CXX_QT_SUPPORT}")
message(STATUS "C++ version and Boost settings:")
message(STATUS " Prefer boost: ................... : ${PREFER_BOOST}")
message(STATUS " make_unique implementation :..... : ${STD_MAKE_UNIQUE_IMPL}")
message(STATUS " thread implementation ........... : ${THREAD_IMPL}")
message(STATUS " thread_local support? ........... : ${HAS_THREAD_LOCAL}")
message(STATUS " mutex implementation ............ : ${MUTEX_IMPL}")
message(STATUS " shared_ptr implementation ....... : ${SMART_PTR_IMPL}")
message(STATUS " shared_mutex implementation ..... : ${SHARED_MUTEX_IMPL}")
message(STATUS " atomic implementation ........... : ${ATOMIC_IMPL}")
message(STATUS " filesystem implementation ....... : ${FILESYSTEM_IMPL}")

if(BUILD_TESTING)
Expand Down
136 changes: 6 additions & 130 deletions src/cmake/boost-fallback/boost-fallback.cmake
Original file line number Diff line number Diff line change
@@ -1,150 +1,26 @@
#include(${CMAKE_MODULE_PATH}/FindPackageHandleStandardArgs.cmake)

# Checks for classes in std::, falling back to boost if the requested
# classes are not available
#
# Available classes to check for:
# thread
# mutex
# shared_mutex
# filesystem
#
# Variables set:
# ${prefix}_

#function(_boost_fallback_thread)
# try_compile(HAS_STD_THREAD "${CMAKE_BINARY_DIR}/boost-fallback-compile-tests"
# "${CMAKE_CURRENT_LIST_DIR}/test-stdthread.cpp")


# find_package(boost_thread COMPONENTS thread)
#endfunction()

## check for boost fallback instead of std:: classes
## arg1: prefix for variables to set
## arg2: list of classes to check for
#function(boost_fallback prefix classes)
#endfunction()

#
# This module checks for C++ standard classes and their boost counterparts
#
# Thread variables set:
# STD_THREAD_FOUND - if std::thread is found
# Boost_THREAD_FOUND - if boost::thread is found
#
# Mutex variables set:
# STD_MUTEX_FOUND - if std::mutex is found
# STD_SHARED_MUTEX_FOUND - if std::shared_mutex is found
# Boost_MUTEX_FOUND - if boost::mutex is found
# Boost_SHARED_MUTEX_FOUND - if boost::shared_mutex is found
#
# Smart pointer variables set:
# STD_SHARED_PTR_FOUND - if std::shared_ptr is found
# Boost_SHARED_PTR_FOUND - if boost::shared_ptr is found
#
# Filesystem variables set:
# STD_FILESYSTEM_FOUND - if std::filesystem is found
# STD_EXPERIMENTAL_FILESYSTEM_FOUND - if std::experimental::filesystem is found
# Boost_FILESYSTEM_FOUND - if boost::filesystem is found

include(FindThreads)

try_compile(STD_THREAD_FOUND "${CMAKE_BINARY_DIR}/boost-fallback-compile-tests"
"${CMAKE_CURRENT_LIST_DIR}/test-stdthread.cpp")
try_compile(STD_MUTEX_FOUND "${CMAKE_BINARY_DIR}/boost-fallback-compile-tests"
"${CMAKE_CURRENT_LIST_DIR}/test-stdmutex.cpp")
try_compile(STD_SHARED_MUTEX_FOUND "${CMAKE_BINARY_DIR}/boost-fallback-compile-tests"
"${CMAKE_CURRENT_LIST_DIR}/test-stdsharedmutex.cpp")
try_compile(STD_SHARED_PTR_FOUND "${CMAKE_BINARY_DIR}/boost-fallback-compile-tests"
"${CMAKE_CURRENT_LIST_DIR}/test-stdsharedptr.cpp")
try_compile(STD_ATOMIC_FOUND "${CMAKE_BINARY_DIR}/boost-fallback-compile-tests"
"${CMAKE_CURRENT_LIST_DIR}/test-stdatomic.cpp")
try_compile(STD_FILESYSTEM_FOUND "${CMAKE_BINARY_DIR}/boost-fallback-compile-tests"
"${CMAKE_CURRENT_LIST_DIR}/test-stdfilesystem.cpp")
try_compile(STD_EXPERIMENTAL_FILESYSTEM_FOUND "${CMAKE_BINARY_DIR}/boost-fallback-compile-tests"
"${CMAKE_CURRENT_LIST_DIR}/test-stdexpfilesystem.cpp")

# We need to have all three boost components in order to run our tests
# Boost thread requires chrono and atomic to work
find_package(Boost COMPONENTS thread chrono atomic)
if( ${Boost_FOUND} )
try_compile(Boost_SHARED_PTR_FOUND "${CMAKE_BINARY_DIR}/boost-fallback-compile-tests"
"${CMAKE_CURRENT_LIST_DIR}/test-boostsharedptr.cpp")
try_compile(Boost_MUTEX_FOUND "${CMAKE_BINARY_DIR}/boost-fallback-compile-tests"
"${CMAKE_CURRENT_LIST_DIR}/test-boostmutex.cpp")
try_compile(Boost_SHARED_MUTEX_FOUND "${CMAKE_BINARY_DIR}/boost-fallback-compile-tests"
"${CMAKE_CURRENT_LIST_DIR}/test-boostsharedmutex.cpp"
LINK_LIBRARIES Threads::Threads Boost::thread)
try_compile(Boost_ATOMIC_FOUND "${CMAKE_BINARY_DIR}/boost-fallback-compile-tests"
"${CMAKE_CURRENT_LIST_DIR}/test-boostatomic.cpp")
endif( ${Boost_FOUND} )

find_package(Boost COMPONENTS filesystem)
if( ${Boost_FOUND} )
try_compile(Boost_FILESYSTEM_FOUND "${CMAKE_BINARY_DIR}/boost-fallback-compile-tests"
"${CMAKE_CURRENT_LIST_DIR}/test-boostfilesystem.cpp")
endif( ${Boost_FOUND} )


# Link the target with the appropriate boost libraries(if required)
function(boostfallback_link target)
if(NOT ${STD_THREAD_FOUND})
if(${Boost_THREAD_FOUND})
find_package(Boost COMPONENTS thread)
target_link_libraries( ${target} PUBLIC Boost::thread)
endif()
endif()
if(NOT ${STD_SHARED_MUTEX_FOUND})
if(${Boost_SHARED_MUTEX_FOUND})
find_package(Boost COMPONENTS thread)
target_link_libraries( ${target} PUBLIC Boost::thread)
endif()
endif()
endfunction()

# Check for standard headers that we need, fall back to boost if they're not found
set(NAMESPACE_ALIAS log4cxx)
option(PREFER_BOOST "Prefer Boost over std:: equivalents" OFF)

if( ${STD_THREAD_FOUND} AND NOT ${PREFER_BOOST} )
set( THREAD_IMPL "std::thread" )
elseif( ${Boost_THREAD_FOUND} )
set( THREAD_IMPL "boost::thread" )
else()
set( THREAD_IMPL "NONE" )
endif()

if( ${STD_MUTEX_FOUND} AND NOT ${PREFER_BOOST} )
set( MUTEX_IMPL "std::mutex" )
elseif( ${Boost_MUTEX_FOUND} )
set( MUTEX_IMPL "boost::mutex" )
else()
set( MUTEX_IMPL "NONE" )
endif()

if( ${STD_SHARED_PTR_FOUND} AND NOT ${PREFER_BOOST} )
set( SMART_PTR_IMPL "std::shared_ptr" )
elseif( ${Boost_SHARED_PTR_FOUND} )
set( SMART_PTR_IMPL "boost::shared_ptr" )
else()
set( SMART_PTR_IMPL "NONE" )
endif()

if( ${STD_SHARED_MUTEX_FOUND} AND NOT ${PREFER_BOOST} )
set( SHARED_MUTEX_IMPL "std::shared_mutex" )
elseif( ${Boost_SHARED_MUTEX_FOUND} )
set( SHARED_MUTEX_IMPL "boost::shared_mutex" )
else()
set( SHARED_MUTEX_IMPL "NONE" )
endif()

if( ${STD_ATOMIC_FOUND} AND NOT ${PREFER_BOOST} )
set( ATOMIC_IMPL "std::atomic" )
elseif( ${Boost_ATOMIC_FOUND} )
set( ATOMIC_IMPL "boost::atomic" )
else()
set( ATOMIC_IMPL "NONE" )
if( ${PREFER_BOOST} OR NOT ( ${STD_FILESYSTEM_FOUND} OR ${STD_EXPERIMENTAL_FILESYSTEM_FOUND} ) )
find_package(Boost COMPONENTS filesystem)
if( ${Boost_FOUND} )
try_compile(Boost_FILESYSTEM_FOUND "${CMAKE_BINARY_DIR}/boost-fallback-compile-tests"
"${CMAKE_CURRENT_LIST_DIR}/test-boostfilesystem.cpp")
endif( ${Boost_FOUND} )
endif()

if( ${STD_FILESYSTEM_FOUND} AND NOT ${PREFER_BOOST} )
Expand Down
18 changes: 0 additions & 18 deletions src/cmake/boost-fallback/boost-std-configuration.h.cmake
Original file line number Diff line number Diff line change
@@ -1,28 +1,10 @@
#ifndef BOOST_STD_CONFIGURATION_H
#define BOOST_STD_CONFIGURATION_H

#cmakedefine01 STD_SHARED_MUTEX_FOUND
#cmakedefine01 Boost_SHARED_MUTEX_FOUND
#cmakedefine01 STD_FILESYSTEM_FOUND
#cmakedefine01 Boost_FILESYSTEM_FOUND
#cmakedefine01 STD_EXPERIMENTAL_FILESYSTEM_FOUND

#if STD_SHARED_MUTEX_FOUND
#include <shared_mutex>
namespace ${NAMESPACE_ALIAS} {
typedef std::shared_mutex shared_mutex;
template <typename T>
using shared_lock = std::shared_lock<T>;
}
#elif Boost_SHARED_MUTEX_FOUND
#include <boost/thread/shared_mutex.hpp>
namespace ${NAMESPACE_ALIAS} {
typedef boost::shared_mutex shared_mutex;
template <typename T>
using shared_lock = boost::shared_lock<T>;
}
#endif

#if STD_FILESYSTEM_FOUND
#include <filesystem>
namespace ${NAMESPACE_ALIAS} {
Expand Down
1 change: 0 additions & 1 deletion src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ set_target_properties(log4cxx PROPERTIES
VERSION ${LIBLOG4CXX_LIB_VERSION}
SOVERSION ${LIBLOG4CXX_LIB_SOVERSION}
)
boostfallback_link(log4cxx)
get_directory_property( FILESYSTEM_IMPL DIRECTORY "${LOG4CXX_SOURCE_DIR}/src/main/include" DEFINITION FILESYSTEM_IMPL )
if("${FILESYSTEM_IMPL}" STREQUAL "std::filesystem" OR
"${FILESYSTEM_IMPL}" STREQUAL "std::experimental::filesystem" )
Expand Down
Loading

0 comments on commit e459052

Please sign in to comment.