You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by sw...@apache.org on 2023/01/23 00:13:34 UTC

[logging-log4cxx] branch check_unichar_support created (now f1946edd)

This is an automated email from the ASF dual-hosted git repository.

swebb2066 pushed a change to branch check_unichar_support
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git


      at f1946edd Check 'std::basic_ostringstream<UniChar>' is supported by the standard library.

This branch includes the following new commits:

     new f1946edd Check 'std::basic_ostringstream<UniChar>' is supported by the standard library.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[logging-log4cxx] 01/01: Check 'std::basic_ostringstream' is supported by the standard library.

Posted by sw...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

swebb2066 pushed a commit to branch check_unichar_support
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git

commit f1946edd23eec4bebd8d1969ae5217853448c444
Author: Stephen Webb <st...@sabreautonomous.com.au>
AuthorDate: Mon Jan 23 11:12:01 2023 +1100

    Check 'std::basic_ostringstream<UniChar>' is supported by the standard library.
    
    * Show 'std::string<UniChar>' support in cmake status report.
    
    * Restructure cmake code towards a better separation of concerns.
---
 CMakeLists.txt                                     | 22 ++++---
 src/cmake/boost-fallback/boost-fallback.cmake      | 56 ++++++++++++++++-
 .../compiler-features/check-compiler-support.cmake | 26 ++++++++
 .../makeunique.h.cmake                             |  0
 .../test-make-unique.cpp                           |  0
 .../{ => compiler-features}/test-thread-local.cpp  |  0
 src/cmake/compiler-features/test-unicode.cpp       | 17 +++++
 src/main/include/CMakeLists.txt                    | 73 +---------------------
 8 files changed, 112 insertions(+), 82 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5503c3a4..2e9bb5af 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -194,13 +194,14 @@ endif(LOG4CXX_QT_SUPPORT)
 get_directory_property( HAS_LIBESMTP DIRECTORY src/main/include DEFINITION HAS_LIBESMTP )
 get_directory_property( HAS_ODBC DIRECTORY src/main/include DEFINITION HAS_ODBC )
 get_directory_property( HAS_SYSLOG DIRECTORY src/main/include DEFINITION HAS_SYSLOG )
-get_directory_property( THREAD_IMPL DIRECTORY src/main/include DEFINITION THREAD_IMPL )
-get_directory_property( SMART_PTR_IMPL DIRECTORY src/main/include DEFINITION SMART_PTR_IMPL )
-get_directory_property( MUTEX_IMPL DIRECTORY src/main/include DEFINITION MUTEX_IMPL )
-get_directory_property( SHARED_MUTEX_IMPL DIRECTORY src/main/include DEFINITION SHARED_MUTEX_IMPL )
-get_directory_property( ATOMIC_IMPL DIRECTORY src/main/include DEFINITION ATOMIC_IMPL )
-get_directory_property( FILESYSTEM_IMPL DIRECTORY src/main/include DEFINITION FILESYSTEM_IMPL )
-get_directory_property( STD_MAKE_UNIQUE_IMPL DIRECTORY src/main/include DEFINITION STD_MAKE_UNIQUE_IMPL )
+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 )
 
 foreach(varName HAS_STD_LOCALE  HAS_ODBC  HAS_MBSRTOWCS  HAS_WCSTOMBS  HAS_FWIDE  HAS_LIBESMTP  HAS_SYSLOG HAS_FMT)
   if(${varName} EQUAL 0)
@@ -259,9 +260,13 @@ message(STATUS "  Build tests ..................... : ${BUILD_TESTING}")
 message(STATUS "  Build site ...................... : ${BUILD_SITE}")
 message(STATUS "  Install prefix .................. : ${CMAKE_INSTALL_PREFIX}")
 message(STATUS "  C++ compiler .................... : ${CMAKE_CXX_COMPILER}")
-message(STATUS "  log4cxx char API ................ : ${LOG4CXX_CHAR}")
+message(STATUS "  std::make_unique found? ......... : ${STD_MAKE_UNIQUE_IMPL}")
+message(STATUS "  std::basic_string<UniChar> ok? .. : ${STD_LIB_HAS_UNICODE_STRING}")
+message(STATUS "  log4cxx char API ................ : ON")
 message(STATUS "  log4cxx wchar API ............... : ${LOG4CXX_WCHAR_T}")
+if(STD_LIB_HAS_UNICODE_STRING)
 message(STATUS "  log4cxx unichar API ............. : ${LOG4CXX_UNICHAR}")
+endif()
 if(APPLE)
 message(STATUS "  log4cxx cfstring API ............ : ${LOG4CXX_CFSTRING}")
 endif()
@@ -281,7 +286,6 @@ 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}")
-message(STATUS "  std::make_unique found? ......... : ${STD_MAKE_UNIQUE_IMPL}")
 
 if(BUILD_TESTING)
 message(STATUS "Applications required for tests:")
diff --git a/src/cmake/boost-fallback/boost-fallback.cmake b/src/cmake/boost-fallback/boost-fallback.cmake
index 8473721f..1a0a8493 100644
--- a/src/cmake/boost-fallback/boost-fallback.cmake
+++ b/src/cmake/boost-fallback/boost-fallback.cmake
@@ -64,8 +64,6 @@ try_compile(STD_FILESYSTEM_FOUND "${CMAKE_BINARY_DIR}/boost-fallback-compile-tes
     "${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")
-try_compile(STD_MAKE_UNIQUE_FOUND "${CMAKE_BINARY_DIR}/boost-fallback-compile-tests"
-    "${CMAKE_CURRENT_LIST_DIR}/test-make-unique.cpp")
 
 # We need to have all three boost components in order to run our tests
 # Boost thread requires chrono and atomic to work
@@ -105,4 +103,58 @@ function(boostfallback_link target)
     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" )
+endif()
+
+if( ${STD_FILESYSTEM_FOUND} AND NOT ${PREFER_BOOST} )
+	set( FILESYSTEM_IMPL "std::filesystem" )
+elseif( ${STD_EXPERIMENTAL_FILESYSTEM_FOUND} AND NOT ${PREFER_BOOST} )
+	set( FILESYSTEM_IMPL "std::experimental::filesystem" )
+elseif( ${Boost_FILESYSTEM_FOUND} )
+	set( FILESYSTEM_IMPL "boost::filesystem" )
+else()
+	set( FILESYSTEM_IMPL "NONE" )
+endif()
+
 
diff --git a/src/cmake/compiler-features/check-compiler-support.cmake b/src/cmake/compiler-features/check-compiler-support.cmake
new file mode 100644
index 00000000..7f5f9a3a
--- /dev/null
+++ b/src/cmake/compiler-features/check-compiler-support.cmake
@@ -0,0 +1,26 @@
+# This module checks compiler and standard library support
+#
+
+# Does the compiler support thread_local?
+try_compile(HAS_THREAD_LOCAL "${CMAKE_BINARY_DIR}/Testing/thread-local-test"
+    "${CMAKE_CURRENT_LIST_DIR}/test-thread-local.cpp"
+    CXX_STANDARD 11
+    )
+
+# Does the standard library support std::make_unique<T>>?
+try_compile(STD_MAKE_UNIQUE_FOUND "${CMAKE_BINARY_DIR}/boost-fallback-compile-tests"
+    "${CMAKE_CURRENT_LIST_DIR}/test-make-unique.cpp")
+if( ${STD_MAKE_UNIQUE_FOUND} )
+    set(STD_MAKE_UNIQUE_IMPL "std::make_unique")
+    set(STD_MAKE_UNIQUE_FOUND 1)
+else()
+    set(STD_MAKE_UNIQUE_IMPL "log4cxx std::make_unique")
+    set(STD_MAKE_UNIQUE_FOUND 0)
+endif()
+
+
+# Does the standard library support std::basic_string<UniChar> and std::basic_ostream<UniChar>?
+try_compile(STD_LIB_HAS_UNICODE_STRING "${CMAKE_BINARY_DIR}/Testing/unicode-test"
+    "${CMAKE_CURRENT_LIST_DIR}/test-unicode.cpp"
+    )
+
diff --git a/src/cmake/boost-fallback/makeunique.h.cmake b/src/cmake/compiler-features/makeunique.h.cmake
similarity index 100%
rename from src/cmake/boost-fallback/makeunique.h.cmake
rename to src/cmake/compiler-features/makeunique.h.cmake
diff --git a/src/cmake/boost-fallback/test-make-unique.cpp b/src/cmake/compiler-features/test-make-unique.cpp
similarity index 100%
rename from src/cmake/boost-fallback/test-make-unique.cpp
rename to src/cmake/compiler-features/test-make-unique.cpp
diff --git a/src/cmake/test-thread-local.cpp b/src/cmake/compiler-features/test-thread-local.cpp
similarity index 100%
rename from src/cmake/test-thread-local.cpp
rename to src/cmake/compiler-features/test-thread-local.cpp
diff --git a/src/cmake/compiler-features/test-unicode.cpp b/src/cmake/compiler-features/test-unicode.cpp
new file mode 100644
index 00000000..8abb2c88
--- /dev/null
+++ b/src/cmake/compiler-features/test-unicode.cpp
@@ -0,0 +1,17 @@
+/* Prevent error C2491: 'std::numpunct<_Elem>::id': definition of dllimport static data member not allowed */
+#if defined(_MSC_VER)
+#define __FORCE_INSTANCE
+#endif
+#include <string>
+#include <sstream>
+
+using UniChar = unsigned short;
+using StringType = std::basic_string<UniChar>;
+using StreamType = std::basic_ostringstream<UniChar>;
+int main()
+{
+	StringType str;
+	StreamType ss;
+    ss << str;
+    return 0;
+}
diff --git a/src/main/include/CMakeLists.txt b/src/main/include/CMakeLists.txt
index 62f61bd4..205041da 100644
--- a/src/main/include/CMakeLists.txt
+++ b/src/main/include/CMakeLists.txt
@@ -16,7 +16,6 @@
 #
 
 # Configure
-
 if(WIN32)
     configure_file(${CMAKE_CURRENT_SOURCE_DIR}/log4cxx/version_info.h.in
 	           ${CMAKE_CURRENT_BINARY_DIR}/log4cxx/version_info.h
@@ -124,10 +123,6 @@ CHECK_FUNCTION_EXISTS(wcstombs HAS_WCSTOMBS)
 CHECK_FUNCTION_EXISTS(fwide HAS_FWIDE)
 CHECK_LIBRARY_EXISTS(esmtp smtp_create_session "" HAS_LIBESMTP)
 CHECK_FUNCTION_EXISTS(syslog HAS_SYSLOG)
-try_compile(HAS_THREAD_LOCAL "${CMAKE_BINARY_DIR}/thread-local-test"
-    "${LOG4CXX_SOURCE_DIR}/src/cmake/test-thread-local.cpp"
-    CXX_STANDARD 11
-    )
 if(UNIX)
     set(CMAKE_REQUIRED_LIBRARIES "pthread")
     CHECK_SYMBOL_EXISTS(pthread_sigmask "signal.h" HAS_PTHREAD_SIGMASK)
@@ -170,73 +165,10 @@ foreach(varName
   endif()
 endforeach()
 
-# Check for standard headers that we need, fall back to boost if they're not found
-include(${LOG4CXX_SOURCE_DIR}/src/cmake/boost-fallback/boost-fallback.cmake)
-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" )
-endif()
-
-if( ${STD_FILESYSTEM_FOUND} AND NOT ${PREFER_BOOST} )
-	set( FILESYSTEM_IMPL "std::filesystem" )
-elseif( ${STD_EXPERIMENTAL_FILESYSTEM_FOUND} AND NOT ${PREFER_BOOST} )
-	set( FILESYSTEM_IMPL "std::experimental::filesystem" )
-elseif( ${Boost_FILESYSTEM_FOUND} )
-	set( FILESYSTEM_IMPL "boost::filesystem" )
-else()
-	set( FILESYSTEM_IMPL "NONE" )
-endif()
-
-if( ${STD_MAKE_UNIQUE_FOUND} )
-    set(STD_MAKE_UNIQUE_IMPL "std::make_unique")
-    set(STD_MAKE_UNIQUE_FOUND 1)
-else()
-    set(STD_MAKE_UNIQUE_IMPL "log4cxx std::make_unique")
-    set(STD_MAKE_UNIQUE_FOUND 0)
-endif()
-configure_file(${LOG4CXX_SOURCE_DIR}/src/cmake/boost-fallback/makeunique.h.cmake
+# Configure both our private header and our public header
+configure_file(${LOG4CXX_SOURCE_DIR}/src/cmake/compiler-features/makeunique.h.cmake
                 ${CMAKE_CURRENT_BINARY_DIR}/log4cxx/helpers/makeunique.h
 )
-
-# Configure both our private header and our public header
 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/log4cxx/private/log4cxx_private.h.in
                ${CMAKE_CURRENT_BINARY_DIR}/log4cxx/private/log4cxx_private.h
                @ONLY
@@ -248,7 +180,6 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/log4cxx/log4cxx.h.in
 configure_file(${LOG4CXX_SOURCE_DIR}/src/cmake/boost-fallback/boost-std-configuration.h.cmake
                 ${CMAKE_CURRENT_BINARY_DIR}/log4cxx/private/boost-std-configuration.h
 )
-
 # Provide the dependencies
 add_custom_target(configure_log4cxx
   COMMAND "${CMAKE_COMMAND}" -E echo "Checking configuration"