cmake: determine when to use port.h (#1037)

Allow building using MSYS2 (without MinGW).
This commit is contained in:
Sergiu Deitsch 2024-01-05 19:57:34 +01:00 committed by GitHub
parent fe46778bd3
commit 89f5977468
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 4 deletions

View File

@ -363,12 +363,14 @@ set (GLOG_SRCS
src/vlog_is_on.cc src/vlog_is_on.cc
) )
if (CYGWIN OR WIN32) # NOTE MSYS2 defines both WIN32 and UNIX. Do not use windows port in this case.
if ((CYGWIN OR WIN32) AND NOT UNIX)
list (APPEND GLOG_SRCS list (APPEND GLOG_SRCS
src/windows/port.cc src/windows/port.cc
src/windows/port.h src/windows/port.h
) )
endif (CYGWIN OR WIN32) set (_glog_USE_WINDOWS_PORT TRUE)
endif ((CYGWIN OR WIN32) AND NOT UNIX)
add_library (glog_internal OBJECT add_library (glog_internal OBJECT
${_glog_BINARY_CMake_MODULES} ${_glog_BINARY_CMake_MODULES}
@ -399,6 +401,12 @@ set (glog_libraries_options_for_static_linking)
# CMake always uses the generated export header # CMake always uses the generated export header
target_compile_definitions (glog PUBLIC GLOG_USE_GLOG_EXPORT) target_compile_definitions (glog PUBLIC GLOG_USE_GLOG_EXPORT)
if (_glog_USE_WINDOWS_PORT)
target_compile_definitions (glog PRIVATE GLOG_USE_WINDOWS_PORT)
endif (_glog_USE_WINDOWS_PORT)
unset (_glog_USE_WINDOWS_PORT)
if (WIN32) if (WIN32)
# Do not define min and max as macros # Do not define min and max as macros
target_compile_definitions (glog PRIVATE NOMINMAX) target_compile_definitions (glog PRIVATE NOMINMAX)

View File

@ -104,6 +104,7 @@ def glog_library(with_gflags = 1, **kwargs):
"-DGLOG_EXPORT=__declspec(dllexport)", "-DGLOG_EXPORT=__declspec(dllexport)",
"-DGLOG_NO_EXPORT=", "-DGLOG_NO_EXPORT=",
"-DGLOG_NO_ABBREVIATED_SEVERITIES", "-DGLOG_NO_ABBREVIATED_SEVERITIES",
"-DGLOG_USE_WINDOWS_PORT",
"-DHAVE__CHSIZE_S", "-DHAVE__CHSIZE_S",
"-I" + src_windows, "-I" + src_windows,
] ]

View File

@ -34,7 +34,9 @@
#include <dbghelp.h> #include <dbghelp.h>
#include "config.h" #include "config.h"
#include "port.h" #if defined(GLOG_USE_WINDOWS_PORT)
# include "port.h"
#endif
#include "stacktrace.h" #include "stacktrace.h"
namespace google { namespace google {

View File

@ -57,7 +57,7 @@
#include "glog/logging.h" #include "glog/logging.h"
#if defined(GLOG_OS_WINDOWS) #if defined(GLOG_USE_WINDOWS_PORT)
# include "port.h" # include "port.h"
#endif #endif