diff --git a/.gitignore b/.gitignore index fa67582cf..4b18b8b36 100644 --- a/.gitignore +++ b/.gitignore @@ -32,5 +32,6 @@ src/test/cpp/Testing/ src/test/resources/org/ src/test/resources/output/ target/ +build/ *.user diff --git a/CMakeLists.txt b/CMakeLists.txt index 21a018bbe..1bff64c94 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -170,35 +170,33 @@ IF(MSVC AND BUILD_SHARED_LIBS AND LOG4CXX_INSTALL_PDB) ) ENDIF() -if(UNIX) - # Support for pkg-config in consuming projects - set(prefix "${CMAKE_INSTALL_PREFIX}") - set(exec_prefix "${CMAKE_INSTALL_PREFIX}") - set(libdir "\${prefix}/${CMAKE_INSTALL_LIBDIR}") - set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") - set(VERSION "${log4cxx_VERSION_MAJOR}.${log4cxx_VERSION_MINOR}.${log4cxx_VERSION_PATCH}") - configure_file("${CMAKE_CURRENT_SOURCE_DIR}/liblog4cxx.pc.in" - "${CMAKE_CURRENT_BINARY_DIR}/lib${LOG4CXX_LIB_NAME}.pc" - ) +# Support for pkg-config in consuming projects +set(prefix "${CMAKE_INSTALL_PREFIX}") +set(exec_prefix "${CMAKE_INSTALL_PREFIX}") +set(libdir "\${prefix}/${CMAKE_INSTALL_LIBDIR}") +set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") +set(VERSION "${log4cxx_VERSION_MAJOR}.${log4cxx_VERSION_MINOR}.${log4cxx_VERSION_PATCH}") +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/liblog4cxx.pc.in" + "${CMAKE_CURRENT_BINARY_DIR}/lib${LOG4CXX_LIB_NAME}.pc" +) + +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/lib${LOG4CXX_LIB_NAME}.pc" + DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) + +if(LOG4CXX_QT_SUPPORT) + set(prefix "${CMAKE_INSTALL_PREFIX}") + set(exec_prefix "${CMAKE_INSTALL_PREFIX}") + set(libdir "\${prefix}/${CMAKE_INSTALL_LIBDIR}") + set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") + set(VERSION "${log4cxx_VERSION_MAJOR}.${log4cxx_VERSION_MINOR}.${log4cxx_VERSION_PATCH}") + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/liblog4cxx-qt.pc.in" + "${CMAKE_CURRENT_BINARY_DIR}/lib${LOG4CXX_LIB_NAME}-qt.pc" + ) - install(FILES "${CMAKE_CURRENT_BINARY_DIR}/lib${LOG4CXX_LIB_NAME}.pc" - DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) - - if(LOG4CXX_QT_SUPPORT) - set(prefix "${CMAKE_INSTALL_PREFIX}") - set(exec_prefix "${CMAKE_INSTALL_PREFIX}") - set(libdir "\${prefix}/${CMAKE_INSTALL_LIBDIR}") - set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") - set(VERSION "${log4cxx_VERSION_MAJOR}.${log4cxx_VERSION_MINOR}.${log4cxx_VERSION_PATCH}") - configure_file("${CMAKE_CURRENT_SOURCE_DIR}/liblog4cxx-qt.pc.in" - "${CMAKE_CURRENT_BINARY_DIR}/lib${LOG4CXX_LIB_NAME}-qt.pc" - ) - - install(FILES "${CMAKE_CURRENT_BINARY_DIR}/lib${LOG4CXX_LIB_NAME}-qt.pc" - DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig - ) - endif(LOG4CXX_QT_SUPPORT) -endif(UNIX) + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/lib${LOG4CXX_LIB_NAME}-qt.pc" + DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig + ) +endif(LOG4CXX_QT_SUPPORT) # Support for find_package(log4cxx) in consuming CMake projects using # target_include_directories(myApplication PRIVATE $) diff --git a/src/cmake/FindAPR.cmake b/src/cmake/FindAPR.cmake index e3f4c98f7..baf102779 100644 --- a/src/cmake/FindAPR.cmake +++ b/src/cmake/FindAPR.cmake @@ -46,6 +46,9 @@ if(APR_FOUND) else() set(APR_LIBRARIES ${APR_LINK_LIBRARIES}) endif() + if(WIN32) + list(APPEND APR_COMPILE_DEFINITIONS WIN32) + endif() else() find_program(APR_CONFIG_EXECUTABLE apr-1-config @@ -78,6 +81,9 @@ else() find_program(APR_DLL libapr-1.dll) endif() endif() + if(WIN32) + list(APPEND APR_COMPILE_DEFINITIONS WIN32) + endif() endif() find_package_handle_standard_args(APR diff --git a/src/examples/cpp/com/foo/config3.cpp b/src/examples/cpp/com/foo/config3.cpp index 8e686f681..33ee90d14 100644 --- a/src/examples/cpp/com/foo/config3.cpp +++ b/src/examples/cpp/com/foo/config3.cpp @@ -24,8 +24,8 @@ #include #include -#ifdef WIN32 -#include +#ifdef _WIN32 +#include #elif __APPLE__ #include #elif (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 500) || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L) @@ -48,7 +48,7 @@ auto DefaultConfigurationFileNames(std::string& altPrefix) -> std::vector +#include #include #include #include diff --git a/src/main/cpp/threadutility.cpp b/src/main/cpp/threadutility.cpp index 321c3ee66..d4211ce5a 100644 --- a/src/main/cpp/threadutility.cpp +++ b/src/main/cpp/threadutility.cpp @@ -26,7 +26,7 @@ #include #include -#if WIN32 +#ifdef _WIN32 #include #include #endif @@ -138,12 +138,12 @@ void ThreadUtility::threadStartedNameThread(LogString threadName, std::thread::id /*threadId*/, std::thread::native_handle_type nativeHandle) { -#if LOG4CXX_HAS_PTHREAD_SETNAME +#if LOG4CXX_HAS_PTHREAD_SETNAME && !(defined(_WIN32) && defined(_LIBCPP_VERSION)) LOG4CXX_ENCODE_CHAR(sthreadName, threadName); if (pthread_setname_np(static_cast(nativeHandle), sthreadName.c_str()) < 0) { LOGLOG_ERROR(LOG4CXX_STR("unable to set thread name")); } -#elif WIN32 +#elif defined(_WIN32) typedef HRESULT (WINAPI *TSetThreadDescription)(HANDLE, PCWSTR); static struct initialiser { diff --git a/src/main/cpp/timebasedrollingpolicy.cpp b/src/main/cpp/timebasedrollingpolicy.cpp index e9dd5a2e3..745cbbada 100644 --- a/src/main/cpp/timebasedrollingpolicy.cpp +++ b/src/main/cpp/timebasedrollingpolicy.cpp @@ -171,7 +171,7 @@ const std::string TimeBasedRollingPolicy::createFile(const std::string& fileName if (stat == APR_SUCCESS) { -#ifdef WIN32 +#ifdef _WIN32 snprintf(szUid, MAX_FILE_LEN, "%p", uid); #else snprintf(szUid, MAX_FILE_LEN, "%u", uid); diff --git a/src/main/include/CMakeLists.txt b/src/main/include/CMakeLists.txt index e078865a1..9eac03773 100644 --- a/src/main/include/CMakeLists.txt +++ b/src/main/include/CMakeLists.txt @@ -121,9 +121,12 @@ CHECK_SYMBOL_EXISTS(mbsrtowcs "cwchar" HAS_MBSRTOWCS) CHECK_SYMBOL_EXISTS(wcstombs "cstdlib" HAS_WCSTOMBS) CHECK_SYMBOL_EXISTS(fwide "cwchar" HAS_FWIDE ) CHECK_SYMBOL_EXISTS(syslog "syslog.h" HAS_SYSLOG) -if(UNIX) +if(NOT MSVC) set(CMAKE_REQUIRED_LIBRARIES "pthread") - CHECK_SYMBOL_EXISTS(pthread_sigmask "signal.h" HAS_PTHREAD_SIGMASK) + # pthread_sigmask exists on MINGW but with no function + if(NOT MINGW) + CHECK_SYMBOL_EXISTS(pthread_sigmask "signal.h" HAS_PTHREAD_SIGMASK) + endif() CHECK_SYMBOL_EXISTS(pthread_self "pthread.h" HAS_PTHREAD_SELF) # Check for the (linux) pthread_setname_np. @@ -138,7 +141,7 @@ if(UNIX) if(${PTHREAD_GETNAME_NP_FOUND}) set(HAS_PTHREAD_GETNAME 1) endif() -endif(UNIX) +endif() foreach(varName HAS_THREAD_LOCAL diff --git a/src/main/include/log4cxx/spi/location/locationinfo.h b/src/main/include/log4cxx/spi/location/locationinfo.h index 3b68d5310..c4af54e4c 100644 --- a/src/main/include/log4cxx/spi/location/locationinfo.h +++ b/src/main/include/log4cxx/spi/location/locationinfo.h @@ -22,7 +22,7 @@ #include #include -#if defined(_WIN32) +#if defined(_MSC_VER) #define LOG4CXX_SHORT_FILENAME_SPLIT_CHAR '\\' #else #define LOG4CXX_SHORT_FILENAME_SPLIT_CHAR '/' diff --git a/src/test/cpp/abts.h b/src/test/cpp/abts.h index 05e962d2e..73c8e17a6 100644 --- a/src/test/cpp/abts.h +++ b/src/test/cpp/abts.h @@ -20,7 +20,7 @@ #include #include -#ifdef WIN32 +#ifdef _WIN32 #include #else #include diff --git a/src/test/cpp/helpers/threadutilitytestcase.cpp b/src/test/cpp/helpers/threadutilitytestcase.cpp index 1304f896c..c62d665bf 100644 --- a/src/test/cpp/helpers/threadutilitytestcase.cpp +++ b/src/test/cpp/helpers/threadutilitytestcase.cpp @@ -33,7 +33,7 @@ LOGUNIT_CLASS(ThreadUtilityTest) LOGUNIT_TEST(testNullFunctions); LOGUNIT_TEST(testCustomFunctions); LOGUNIT_TEST(testDefaultFunctions); -#if LOG4CXX_HAS_PTHREAD_SETNAME || defined(WIN32) +#if LOG4CXX_HAS_PTHREAD_SETNAME || defined(_WIN32) LOGUNIT_TEST(testThreadNameLogging); #endif LOGUNIT_TEST_SUITE_END(); diff --git a/src/test/cpp/pattern/patternparsertestcase.cpp b/src/test/cpp/pattern/patternparsertestcase.cpp index bff9f830d..7a653cb41 100644 --- a/src/test/cpp/pattern/patternparsertestcase.cpp +++ b/src/test/cpp/pattern/patternparsertestcase.cpp @@ -56,8 +56,8 @@ #define LOG4CXX_TEST 1 #include #include -#if WIN32 -#include +#ifdef _WIN32 +#include #endif using namespace log4cxx; @@ -89,12 +89,12 @@ LOGUNIT_CLASS(PatternParserTestCase) { LogString threadName = LOG4CXX_STR("log4cxx-thr"); -#if LOG4CXX_HAS_PTHREAD_SETNAME +#if LOG4CXX_HAS_PTHREAD_SETNAME && !(defined(_WIN32) && defined(_LIBCPP_VERSION)) LOG4CXX_ENCODE_CHAR(sthreadName, threadName); if( pthread_setname_np( pthread_self(), sthreadName.c_str() ) < 0 ){ LOGLOG_ERROR( LOG4CXX_STR("unable to set thread name") ); } -#elif WIN32 +#elif defined(_WIN32) LOG4CXX_ENCODE_WCHAR(wthreadName, threadName); HRESULT hr = SetThreadDescription(GetCurrentThread(), wthreadName.c_str()); if(FAILED(hr)){