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

[glog] fix not work on c++03 #25155

Merged
merged 6 commits into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
19 changes: 19 additions & 0 deletions ports/glog/cmakelists_atomicdetect.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 13c474b..34ffc06 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -398,6 +398,14 @@ if (HAVE_EXECINFO_H)
set (HAVE_STACKTRACE 1)
endif (HAVE_EXECINFO_H)

+if (HAVE_CXX11_ATOMIC)
+ message(STATUS "have atomic")
+ set (ac_cv_cxx11_atomic 1)
+else ()
+ message(STATUS "not have atomic")
+ set (ac_cv_cxx11_atomic 0)
+endif ()
+
if (WITH_SYMBOLIZE)
if (WIN32 OR CYGWIN)
if(CMAKE_CROSSCOMPILING)
17 changes: 0 additions & 17 deletions ports/glog/fix-windows-CXX11_ATOMIC.patch

This file was deleted.

60 changes: 60 additions & 0 deletions ports/glog/noerror-nominmax.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
diff --git a/src/glog/logging.h.in b/src/glog/logging.h.in
index 3ecacfb..033230d 100644
--- a/src/glog/logging.h.in
+++ b/src/glog/logging.h.in
@@ -100,10 +100,18 @@
#include <gflags/gflags.h>
#endif

-#ifdef HAVE_CXX11_ATOMIC
+#if @ac_cv_cxx11_atomic@
#include <atomic>
#elif defined(GLOG_OS_WINDOWS)
+// To avoid macro definition of ERROR.
+// To avoid macro definition of min/max.
+# ifndef NOMINMAX
+# define NOMINMAX
+# endif
Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed that you have removed NOGDI, is NOMINMAX necessary here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I remember some ports will build fail if not define NOMINMAX. Maybe I can delete it and see if CI report error. The old error log #22135 (comment) I can't download.

Copy link
Contributor

Choose a reason for hiding this comment

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

As far as I know, just removing the definition of NOGDI can fix the build error of colmap, I want to confirm if your patch has any other effect?

Removing the definition of NOGDI can fix the build error of colmap, but CI of vcpkg will fail because of the macro ERROR defined in windows.h. It means that the macro ERROR defined in windows.h will get conflicts with other libs like rocksdb.

Including windows.h in glog is only to support C++03 on windows, and vcpkg only support C++14(C++11?) or above on windows. glog version less than 0.5 does not contain windows.h, and there are no errors when building colmap via vcpkg.

Beside, including windows.h in glog means many macros like MIN, MAX will be exported, and macros like NOMINMAX should be defined when using functions std::min/max.

Copy link
Contributor

Choose a reason for hiding this comment

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

@jiayuehua @Adela0814

Removing the definition of NOGDI can fix the build error of colmap, but CI of vcpkg will fail because of the macro ERROR defined in windows.h. It means that the macro ERROR defined in windows.h will get conflicts with other libs like rocksdb.

Including windows.h in glog is only to support C++03 on windows, and vcpkg only support C++14(C++11?) or above on windows. glog version less than 0.5 does not contain windows.h, and there are no errors when building colmap via vcpkg.

Beside, including windows.h in glog means many macros like MIN, MAX will be exported, and macros like NOMINMAX should be defined when using functions std::min/max.

#include <Windows.h>
+# ifdef ERROR
+# undef ERROR
+# endif
#endif

@ac_google_start_namespace@
@@ -1061,7 +1069,7 @@ namespace google {
#elif defined(GLOG_OS_WINDOWS)

#define SOME_KIND_OF_LOG_EVERY_N(severity, n, what_to_do) \
- static int LOG_OCCURRENCES = 0, LOG_OCCURRENCES_MOD_N = 0; \
+ static volatile unsigned LOG_OCCURRENCES = 0, LOG_OCCURRENCES_MOD_N = 0; \
InterlockedIncrement(&LOG_OCCURRENCES); \
if (InterlockedIncrement(&LOG_OCCURRENCES_MOD_N) > n) \
InterlockedExchangeSubtract(&LOG_OCCURRENCES_MOD_N, n); \
@@ -1071,7 +1079,7 @@ namespace google {
&what_to_do).stream()

#define SOME_KIND_OF_LOG_IF_EVERY_N(severity, condition, n, what_to_do) \
- static int LOG_OCCURRENCES = 0, LOG_OCCURRENCES_MOD_N = 0; \
+ static volatile unsigned LOG_OCCURRENCES = 0, LOG_OCCURRENCES_MOD_N = 0; \
InterlockedIncrement(&LOG_OCCURRENCES); \
if (condition && \
(InterlockedIncrement(&LOG_OCCURRENCES_MOD_N) || true) && \
@@ -1082,7 +1090,7 @@ namespace google {
&what_to_do).stream()

#define SOME_KIND_OF_PLOG_EVERY_N(severity, n, what_to_do) \
- static int LOG_OCCURRENCES = 0, LOG_OCCURRENCES_MOD_N = 0; \
+ static volatile unsigned LOG_OCCURRENCES = 0, LOG_OCCURRENCES_MOD_N = 0; \
InterlockedIncrement(&LOG_OCCURRENCES); \
if (InterlockedIncrement(&LOG_OCCURRENCES_MOD_N) > n) \
InterlockedExchangeSubtract(&LOG_OCCURRENCES_MOD_N, n); \
@@ -1092,7 +1100,7 @@ namespace google {
&what_to_do).stream()

#define SOME_KIND_OF_LOG_FIRST_N(severity, n, what_to_do) \
- static int LOG_OCCURRENCES = 0; \
+ static volatile unsigned LOG_OCCURRENCES = 0; \
if (LOG_OCCURRENCES <= n) \
jiayuehua marked this conversation as resolved.
Show resolved Hide resolved
InterlockedIncrement(&LOG_OCCURRENCES); \
if (LOG_OCCURRENCES <= n) \
4 changes: 2 additions & 2 deletions ports/glog/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ vcpkg_from_github(
glog_disable_debug_postfix.patch
fix_glog_CMAKE_MODULE_PATH.patch
fix_log_every_n.patch
fix-windows-CXX11_ATOMIC.patch
noerror-nominmax.patch
fix_crosscompile_symbolize.patch

cmakelists_atomicdetect.patch
)

vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
Expand Down
2 changes: 1 addition & 1 deletion ports/glog/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "glog",
"version": "0.5.0",
"port-version": 4,
"port-version": 5,
"description": "C++ implementation of the Google logging module",
"homepage": "https://github.com/google/glog",
"license": "BSD-3-Clause",
Expand Down
2 changes: 1 addition & 1 deletion versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -2574,7 +2574,7 @@
},
"glog": {
"baseline": "0.5.0",
"port-version": 4
"port-version": 5
},
"gloo": {
"baseline": "20201203",
Expand Down
5 changes: 5 additions & 0 deletions versions/g-/glog.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "23a5cebc8eddfba3c2da76d3a6f46a404aa458d9",
"version": "0.5.0",
"port-version": 5
},
{
"git-tree": "bb5f54eba990cc0f03c64e1d09f343dd6cd7b22b",
"version": "0.5.0",
Expand Down