Skip to content

Commit

Permalink
cmake: determine when to use port.h
Browse files Browse the repository at this point in the history
Allow building using MSYS2 (without MinGW).
  • Loading branch information
sergiud committed Jan 5, 2024
1 parent fe46778 commit da3b8e7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
12 changes: 10 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -363,12 +363,14 @@ set (GLOG_SRCS
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
src/windows/port.cc
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
${_glog_BINARY_CMake_MODULES}
Expand Down Expand Up @@ -399,6 +401,12 @@ set (glog_libraries_options_for_static_linking)
# CMake always uses the generated export header
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)
# Do not define min and max as macros
target_compile_definitions (glog PRIVATE NOMINMAX)
Expand Down
1 change: 1 addition & 0 deletions bazel/glog.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def glog_library(with_gflags = 1, **kwargs):
"-DGLOG_EXPORT=__declspec(dllexport)",
"-DGLOG_NO_EXPORT=",
"-DGLOG_NO_ABBREVIATED_SEVERITIES",
"-DGLOG_USE_WINDOWS_PORT",
"-DHAVE__CHSIZE_S",
"-I" + src_windows,
]
Expand Down
4 changes: 3 additions & 1 deletion src/stacktrace_windows-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
#include <dbghelp.h>

#include "config.h"
#include "port.h"
#if defined(GLOG_USE_WINDOWS_PORT)
# include "port.h"
#endif
#include "stacktrace.h"

namespace google {
Expand Down
2 changes: 1 addition & 1 deletion src/utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

#include "glog/logging.h"

#if defined(GLOG_OS_WINDOWS)
#if defined(GLOG_USE_WINDOWS_PORT)
# include "port.h"
#endif

Expand Down

0 comments on commit da3b8e7

Please sign in to comment.