From efc341d768650bd0b24aa0b7de660aca279e6267 Mon Sep 17 00:00:00 2001 From: Sergiu Deitsch Date: Thu, 8 Apr 2021 01:23:17 +0200 Subject: [PATCH] fixed windows builds --- CMakeLists.txt | 26 ++++---- README.rst | 4 +- bazel/glog.bzl | 8 +-- cmake/GetCacheVariables.cmake | 6 +- cmake/TestInitPackageConfig.cmake | 1 - cmake/TestPackageConfig.cmake | 25 ++++--- src/config_for_unittests.h | 66 ------------------- src/logging_unittest.cc | 2 +- .../working_config/CMakeLists.txt | 4 +- src/windows/config.h | 21 ------ src/windows/port.h | 2 + 11 files changed, 45 insertions(+), 120 deletions(-) delete mode 100644 src/config_for_unittests.h delete mode 100755 src/windows/config.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 64e575e..f56891f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -574,11 +574,6 @@ if (HAVE_PTHREAD) target_link_libraries (glog PUBLIC ${CMAKE_THREAD_LIBS_INIT}) endif (HAVE_PTHREAD) -if (WIN32 AND HAVE_SNPRINTF) - set_property (SOURCE src/windows/port.cc APPEND PROPERTY COMPILE_DEFINITIONS - HAVE_SNPRINTF) -endif (WIN32 AND HAVE_SNPRINTF) - if (gflags_FOUND) target_link_libraries (glog PUBLIC gflags) @@ -614,12 +609,12 @@ if (WIN32) PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/windows) endif (WIN32) +set_target_properties (glog PROPERTIES DEFINE_SYMBOL GOOGLE_GLOG_IS_A_DLL) + generate_export_header (glog EXPORT_MACRO_NAME GOOGLE_GLOG_DLL_DECL EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/glog/export.h) -set_target_properties (glog PROPERTIES DEFINE_SYMBOL GOOGLE_GLOG_IS_A_DLL) - # Unit testing if (BUILD_TESTING) @@ -737,12 +732,14 @@ if (BUILD_TESTING) ) add_test (NAME cmake_package_config_generate COMMAND ${CMAKE_COMMAND} - -DPATH=$ENV{PATH} - -DINITIAL_CACHE=${_INITIAL_CACHE} - -DTEST_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}/test_package_config/working_config - -DSOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}/src/package_config_unittest/working_config - -DPACKAGE_DIR=${CMAKE_CURRENT_BINARY_DIR} -DGENERATOR=${CMAKE_GENERATOR} + -DGENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} + -DGENERATOR_TOOLSET=${CMAKE_GENERATOR_TOOLSET} + -DINITIAL_CACHE=${_INITIAL_CACHE} + -DPACKAGE_DIR=${CMAKE_CURRENT_BINARY_DIR} + -DPATH=$ENV{PATH} + -DSOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}/src/package_config_unittest/working_config + -DTEST_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}/test_package_config/working_config -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/TestPackageConfig.cmake ) @@ -806,8 +803,9 @@ configure_package_config_file (glog-config.cmake.in INSTALL_DESTINATION ${_glog_CMake_INSTALLDIR} NO_CHECK_REQUIRED_COMPONENTS_MACRO) -write_basic_package_version_file (glog-config-version.cmake VERSION - ${PROJECT_VERSION} COMPATIBILITY SameMajorVersion) +write_basic_package_version_file ( + ${CMAKE_CURRENT_BINARY_DIR}/glog-config-version.cmake + COMPATIBILITY SameMajorVersion) export (TARGETS glog NAMESPACE glog:: FILE glog-targets.cmake) export (PACKAGE glog) diff --git a/README.rst b/README.rst index 3a4a0b1..a983f21 100644 --- a/README.rst +++ b/README.rst @@ -1,7 +1,7 @@ Google Logging Library ====================== -|Build Status| |Grunt status| +|Build Status| |Grunt status| |Github actions| Google Logging (glog) is a C++98 library that implements application-level logging. The library provides logging APIs based on C++-style streams and @@ -811,3 +811,5 @@ Submitting a Patch :target: https://travis-ci.org/google/glog/builds .. |Grunt status| image:: https://img.shields.io/appveyor/ci/google-admin/glog/master.svg?label=Appveyor :target: https://ci.appveyor.com/project/google-admin/glog/history +.. |Github actions| image:: https://github.com/google/glog/actions/workflows/windows-builds.yml/badge.svg + :target: https://github.com/google/glog/actions diff --git a/bazel/glog.bzl b/bazel/glog.bzl index 73b54bb..7429576 100644 --- a/bazel/glog.bzl +++ b/bazel/glog.bzl @@ -48,9 +48,12 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs): common_copts = [ "-DGLOG_BAZEL_BUILD", + # Inject a C++ namespace. + "-DGOOGLE_NAMESPACE='%s'" % namespace, "-DHAVE_STDINT_H", "-DHAVE_STRING_H", "-DHAVE_UNWIND_H", + "-I%s/glog_internal" % gendir, ] + (["-DHAVE_LIB_GFLAGS"] if with_gflags else []) wasm_copts = [ @@ -59,8 +62,6 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs): "-Wno-unused-function", "-Wno-unused-local-typedefs", "-Wno-unused-variable", - # Inject a C++ namespace. - "-DGOOGLE_NAMESPACE='%s'" % namespace, # Allows src/base/mutex.h to include pthread.h. "-DHAVE_PTHREAD", # Allows src/logging.cc to determine the host name. @@ -72,7 +73,6 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs): # For logging.cc. "-DHAVE_PREAD", "-DHAVE___ATTRIBUTE__", - "-I%s/glog_internal" % gendir, ] linux_or_darwin_copts = wasm_copts + [ @@ -93,13 +93,13 @@ def glog_library(namespace = "google", with_gflags = 1, **kwargs): ] windows_only_copts = [ + "-DGLOG_NO_ABBREVIATED_SEVERITIES", "-DHAVE_SNPRINTF", "-I" + src_windows, ] windows_only_srcs = [ "src/glog/log_severity.h", - "src/windows/config.h", "src/windows/dirent.h", "src/windows/port.cc", "src/windows/port.h", diff --git a/cmake/GetCacheVariables.cmake b/cmake/GetCacheVariables.cmake index 20485a8..5a9b993 100644 --- a/cmake/GetCacheVariables.cmake +++ b/cmake/GetCacheVariables.cmake @@ -45,8 +45,12 @@ function (get_cache_variables _CACHEVARS) string (REPLACE "\"" "\\\"" _CACHEVARDOC "${_CACHEVARDOC}") # Escape ; in values string (REPLACE ";" "\\\;" _CACHEVARVAL "${_CACHEVARVAL}") - # Escape backslash in values + # Escape backslashes in values except those that are followed by a + # quote. string (REGEX REPLACE "\\\\([^\"])" "\\\\\\1" _CACHEVARVAL "${_CACHEVARVAL}") + # Escape backslashes in values that are followed by a letter to avoid + # invalid escape sequence errors. + string (REGEX REPLACE "\\\\([a-zA-Z])" "\\\\\\\\1" _CACHEVARVAL "${_CACHEVARVAL}") if (NOT "${_CACHEVARTYPE}" STREQUAL BOOL) set (_CACHEVARVAL "\"${_CACHEVARVAL}\"") diff --git a/cmake/TestInitPackageConfig.cmake b/cmake/TestInitPackageConfig.cmake index 6cb11cc..01d3a40 100644 --- a/cmake/TestInitPackageConfig.cmake +++ b/cmake/TestInitPackageConfig.cmake @@ -9,4 +9,3 @@ if (NOT _DIRECTORY_CREATED_SUCCEEDED EQUAL 0) endif (NOT _DIRECTORY_CREATED_SUCCEEDED EQUAL 0) file (WRITE ${INITIAL_CACHE} "${CACHEVARS}") - diff --git a/cmake/TestPackageConfig.cmake b/cmake/TestPackageConfig.cmake index 191c3ca..e512a1d 100644 --- a/cmake/TestPackageConfig.cmake +++ b/cmake/TestPackageConfig.cmake @@ -8,21 +8,28 @@ if (NOT _DIRECTORY_CREATED_SUCCEEDED EQUAL 0) message (FATAL_ERROR "Failed to create build directory") endif (NOT _DIRECTORY_CREATED_SUCCEEDED EQUAL 0) -# Capture the PATH environment variable content set during project -# generation stage. This is required because later during the build stage -# the PATH is modified again (e.g., for MinGW AppVeyor CI builds) by adding -# back the directory containing git.exe. Incidently, the Git installation -# directory also contains sh.exe which causes MinGW Makefile generation to -# fail. -set (ENV{PATH} ${PATH}) +if (GENERATOR_TOOLSET) + list (APPEND _ADDITIONAL_ARGS -T ${GENERATOR_TOOLSET}) +endif (GENERATOR_TOOLSET) + +if (GENERATOR_PLATFORM) + list (APPEND _ADDITIONAL_ARGS -A ${GENERATOR_PLATFORM}) +endif (GENERATOR_PLATFORM) # Run CMake execute_process ( - COMMAND ${CMAKE_COMMAND} -C ${INITIAL_CACHE} + # Capture the PATH environment variable content set during project generation + # stage. This is required because later during the build stage the PATH is + # modified again (e.g., for MinGW AppVeyor CI builds) by adding back the + # directory containing git.exe. Incidently, the Git installation directory + # also contains sh.exe which causes MinGW Makefile generation to fail. + COMMAND ${CMAKE_COMMAND} env PATH=${PATH} + ${CMAKE_COMMAND} -C ${INITIAL_CACHE} -G ${GENERATOR} - -DCMAKE_PREFIX_PATH=${PACKAGE_DIR} + ${_ADDITIONAL_ARGS} -DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON -DCMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY=ON + -DCMAKE_PREFIX_PATH=${PACKAGE_DIR} ${SOURCE_DIR} WORKING_DIRECTORY ${TEST_BINARY_DIR} RESULT_VARIABLE _GENERATE_SUCCEEDED diff --git a/src/config_for_unittests.h b/src/config_for_unittests.h deleted file mode 100644 index 13ea8ea..0000000 --- a/src/config_for_unittests.h +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) 2008, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// --- -// All Rights Reserved. -// -// Author: Craig Silverstein -// Copied from google-perftools and modified by Shinichiro Hamaji -// -// This file is needed for windows -- unittests are not part of the -// glog dll, but still want to include config.h just like the -// dll does, so they can use internal tools and APIs for testing. -// -// The problem is that config.h declares GOOGLE_GLOG_DLL_DECL to be -// for exporting symbols, but the unittest needs to *import* symbols -// (since it's not the dll). -// -// The solution is to have this file, which is just like config.h but -// sets GOOGLE_GLOG_DLL_DECL to do a dllimport instead of a dllexport. -// -// The reason we need this extra GOOGLE_GLOG_DLL_DECL_FOR_UNITTESTS -// variable is in case people want to set GOOGLE_GLOG_DLL_DECL explicitly -// to something other than __declspec(dllexport). In that case, they -// may want to use something other than __declspec(dllimport) for the -// unittest case. For that, we allow folks to define both -// GOOGLE_GLOG_DLL_DECL and GOOGLE_GLOG_DLL_DECL_FOR_UNITTESTS explicitly. -// -// NOTE: This file is equivalent to config.h on non-windows systems, -// which never defined GOOGLE_GLOG_DLL_DECL_FOR_UNITTESTS and always -// define GOOGLE_GLOG_DLL_DECL to the empty string. - -#include "config.h" - -#undef GOOGLE_GLOG_DLL_DECL -#ifdef GOOGLE_GLOG_DLL_DECL_FOR_UNITTESTS -# define GOOGLE_GLOG_DLL_DECL GOOGLE_GLOG_DLL_DECL_FOR_UNITTESTS -#else -// if DLL_DECL_FOR_UNITTESTS isn't defined, use "" -# define GOOGLE_GLOG_DLL_DECL -#endif diff --git a/src/logging_unittest.cc b/src/logging_unittest.cc index 6a738be..edc7d35 100644 --- a/src/logging_unittest.cc +++ b/src/logging_unittest.cc @@ -29,7 +29,7 @@ // // Author: Ray Sidney -#include "config_for_unittests.h" +#include "config.h" #include "utilities.h" #include diff --git a/src/package_config_unittest/working_config/CMakeLists.txt b/src/package_config_unittest/working_config/CMakeLists.txt index d701aa7..c292c51 100644 --- a/src/package_config_unittest/working_config/CMakeLists.txt +++ b/src/package_config_unittest/working_config/CMakeLists.txt @@ -1,5 +1,5 @@ -cmake_minimum_required (VERSION 3.1) -project (glog_package_config) +cmake_minimum_required (VERSION 3.0) +project (glog_package_config LANGUAGES CXX) find_package (glog REQUIRED NO_MODULE) diff --git a/src/windows/config.h b/src/windows/config.h deleted file mode 100755 index 2d23fb0..0000000 --- a/src/windows/config.h +++ /dev/null @@ -1,21 +0,0 @@ -/* src/config.h.in. Generated from configure.ac by autoheader. */ - -/* Namespace for Google classes */ -#define GOOGLE_NAMESPACE google - -/* Stops putting the code inside the Google namespace */ -#define _END_GOOGLE_NAMESPACE_ } - -/* Puts following code inside the Google namespace */ -#define _START_GOOGLE_NAMESPACE_ namespace google { - -/* Always the empty-string on non-windows systems. On windows, should be - "__declspec(dllexport)". This way, when we compile the dll, we export our - functions/classes. It's safe to define this here because config.h is only - used internally, to compile the DLL, and every DLL source file #includes - "config.h" before anything else. */ -#ifndef GOOGLE_GLOG_DLL_DECL -# define GOOGLE_GLOG_IS_A_DLL 1 /* not set if you're statically linking */ -# define GOOGLE_GLOG_DLL_DECL __declspec(dllexport) -# define GOOGLE_GLOG_DLL_DECL_FOR_UNITTESTS __declspec(dllimport) -#endif diff --git a/src/windows/port.h b/src/windows/port.h index c3207e1..72068a1 100755 --- a/src/windows/port.h +++ b/src/windows/port.h @@ -62,6 +62,8 @@ * used by both C and C++ code, so we put all the C++ together. */ +#include "glog/logging.h" + #ifdef _MSC_VER /* 4244: otherwise we get problems when substracting two size_t's to an int