Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix building with mingw-w64-gcc #389

Merged
merged 7 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ src/test/cpp/Testing/
src/test/resources/org/
src/test/resources/output/
target/
build/

*.user
54 changes: 26 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is pkg-config available on Windows? I don't think we want to always install the .pc file.

Adding a new option to force the .pc installation feels better to me, I'm not sure if anybody else has any thoughts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, It's available.
Does it hurt to install pc file?

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 $<TARGET_PROPERTY:log4cxx,INTERFACE_INCLUDE_DIRECTORIES>)
Expand Down
6 changes: 6 additions & 0 deletions src/cmake/FindAPR.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/examples/cpp/com/foo/config3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <log4cxx/helpers/loglog.h>
#include <log4cxx/helpers/transcoder.h>

#ifdef WIN32
#ifdef _WIN32
#include <Windows.h>
#elif __APPLE__
#include <mach-o/dyld.h>
Expand All @@ -48,7 +48,7 @@ auto DefaultConfigurationFileNames(std::string& altPrefix) -> std::vector<std::s
static const int bufSize = 4096;
char buf[bufSize+1] = {0}, pathSepar = '/';
uint32_t bufCount = 0;
#if defined(WIN32)
#if defined(_WIN32)
GetModuleFileName(NULL, buf, bufSize);
pathSepar = '\\';
#elif defined(__APPLE__)
Expand Down
22 changes: 11 additions & 11 deletions src/main/cpp/loggingevent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,12 @@ LoggingEvent::KeySet LoggingEvent::getPropertyKeySet() const

const LogString& LoggingEvent::getCurrentThreadName()
{
#if defined(_WIN32)
using ThreadIdType = DWORD;
ThreadIdType threadId = GetCurrentThreadId();
#elif LOG4CXX_HAS_PTHREAD_SELF
#if LOG4CXX_HAS_PTHREAD_SELF && !(defined(_WIN32) && defined(_LIBCPP_VERSION))
using ThreadIdType = pthread_t;
ThreadIdType threadId = pthread_self();
#elif defined(_WIN32)
using ThreadIdType = DWORD;
ThreadIdType threadId = GetCurrentThreadId();
#else
using ThreadIdType = int;
ThreadIdType threadId = 0;
Expand All @@ -362,16 +362,16 @@ const LogString& LoggingEvent::getCurrentThreadName()
return thread_id_string;
}

#if defined(_WIN32)
char result[20];
apr_snprintf(result, sizeof(result), LOG4CXX_WIN32_THREAD_FMTSPEC, threadId);
thread_id_string = Transcoder::decode(result);
#elif LOG4CXX_HAS_PTHREAD_SELF
#if LOG4CXX_HAS_PTHREAD_SELF && !(defined(_WIN32) && defined(_LIBCPP_VERSION))
// pthread_t encoded in HEX takes needs as many characters
// as two times the size of the type, plus an additional null byte.
char result[sizeof(pthread_t) * 3 + 10];
apr_snprintf(result, sizeof(result), LOG4CXX_APR_THREAD_FMTSPEC, (void*) &threadId);
thread_id_string = Transcoder::decode(result);
#elif defined(_WIN32)
char result[20];
apr_snprintf(result, sizeof(result), LOG4CXX_WIN32_THREAD_FMTSPEC, threadId);
thread_id_string = Transcoder::decode(result);
#else
thread_id_string = LOG4CXX_STR("0x00000000");
#endif
Expand All @@ -389,14 +389,14 @@ const LogString& LoggingEvent::getCurrentThreadUserName()
return thread_name;
}

#if LOG4CXX_HAS_PTHREAD_GETNAME
#if LOG4CXX_HAS_PTHREAD_GETNAME && !(defined(_WIN32) && defined(_LIBCPP_VERSION))
char result[16];
pthread_t current_thread = pthread_self();
if (pthread_getname_np(current_thread, result, sizeof(result)) < 0 || 0 == result[0])
thread_name = getCurrentThreadName();
else
thread_name = Transcoder::decode(result);
#elif WIN32
#elif defined(_WIN32)
typedef HRESULT (WINAPI *TGetThreadDescription)(HANDLE, PWSTR*);
static struct initialiser
{
Expand Down
2 changes: 1 addition & 1 deletion src/main/cpp/multiprocessrollingfileappender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ bool MultiprocessRollingFileAppender::rolloverInternal(Pool& p)

if (stat == APR_SUCCESS)
{
#ifdef WIN32
#ifdef _WIN32
snprintf(szUid, MAX_FILE_LEN, "%p", uid);
#else
snprintf(szUid, MAX_FILE_LEN, "%u", (unsigned int)uid);
Expand Down
6 changes: 3 additions & 3 deletions src/main/cpp/threadutility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <signal.h>
#include <mutex>

#if WIN32
#ifdef _WIN32
#include <windows.h>
#include <processthreadsapi.h>
#endif
Expand Down Expand Up @@ -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<pthread_t>(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
{
Expand Down
2 changes: 1 addition & 1 deletion src/main/cpp/timebasedrollingpolicy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 6 additions & 3 deletions src/main/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/test/cpp/abts.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <vector>
#include <string>

#ifdef WIN32
#ifdef _WIN32
#include <io.h>
#else
#include <unistd.h>
Expand Down
2 changes: 1 addition & 1 deletion src/test/cpp/helpers/threadutilitytestcase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions src/test/cpp/pattern/patternparsertestcase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
#define LOG4CXX_TEST 1
#include <log4cxx/private/log4cxx_private.h>
#include <thread>
#if WIN32
#ifdef _WIN32
#include <Windows.h>
#endif

Expand Down Expand Up @@ -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)){
Expand Down
Loading