From 79ae60ed9737f6c0ec652eab5492b1359aaea9cf Mon Sep 17 00:00:00 2001 From: Loo Rong Jie Date: Tue, 28 Nov 2017 13:36:16 +0800 Subject: [PATCH 1/2] MSVC fixes --- CMake/README.md | 7 ++++++- CMakeLists.txt | 10 ++++++---- absl/copts.bzl | 2 ++ absl/time/clock.cc | 4 ++-- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/CMake/README.md b/CMake/README.md index 11160a9d6..9c2d6897f 100644 --- a/CMake/README.md +++ b/CMake/README.md @@ -43,6 +43,11 @@ set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++ ${CMAKE_CXX_FLAGS}") + if (MSVC) + add_compile_options(/wd4005 /wd4068 /wd4244 /wd4267 /wd4800) + add_definitions(/DNOMINMAX /DWIN32_LEAN_AND_MEAN=1 /D_CRT_SECURE_NO_WARNINGS) + endif() + add_subdirectory(googletest) add_subdirectory(cctz) add_subdirectory(abseil-cpp) @@ -51,7 +56,7 @@ target_link_libraries(my_exe absl::base absl::synchronization absl::strings) -You will need to create your own CMake files for cctz until https://github.com/google/cctz/pull/54 lands. As of this writing, that pull request requires -DBUILD_TESTING=OFF as it doesn't correctly export cctz's dependency on Google Benchmark. +As of this writing, that pull request requires -DBUILD_TESTING=OFF as it doesn't correctly export cctz's dependency on Google Benchmark. You will find here a non exhaustive list of absl public targets diff --git a/CMakeLists.txt b/CMakeLists.txt index e87f4a84a..a740088a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,7 +26,12 @@ include(AbseilHelpers) # config options -set(ABSL_STD_CXX_FLAG "-std=c++11" CACHE STRING "c++ std flag (default: c++11)") +if (MSVC) + add_definitions(/DNOMINMAX /DWIN32_LEAN_AND_MEAN=1 /D_CRT_SECURE_NO_WARNINGS) + add_compile_options(/W3 /WX /wd4005 /wd4068 /wd4244 /wd4267 /wd4800) +else() + set(ABSL_STD_CXX_FLAG "-std=c++11" CACHE STRING "c++ std flag (default: c++11)") +endif() @@ -66,9 +71,6 @@ check_target(gmock) # -fexceptions set(ABSL_EXCEPTIONS_FLAG "${CMAKE_CXX_EXCEPTIONS}") -# fix stuff -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FIX_MSVC} ${CMAKE_CXX_FLAGS}") - list(APPEND ABSL_TEST_COMMON_LIBRARIES gtest_main gtest diff --git a/absl/copts.bzl b/absl/copts.bzl index cc8db2f45..f687f58ff 100644 --- a/absl/copts.bzl +++ b/absl/copts.bzl @@ -103,7 +103,9 @@ MSVC_FLAGS = [ "/wd4244", # conversion from 'type1' to 'type2', possible loss of data "/wd4267", # conversion from 'size_t' to 'type', possible loss of data "/wd4800", # forcing value to bool 'true' or 'false' (performance warning) + "/DNOMINMAX", # Don't define min and max macros (windows.h) "/DWIN32_LEAN_AND_MEAN", # Don't bloat namespace with incompatible winsock versions. + "/D_CRT_SECURE_NO_WARNINGS", # Don't warn about usage of insecure C functions ] MSVC_TEST_FLAGS = [ diff --git a/absl/time/clock.cc b/absl/time/clock.cc index 6398170d0..9f2e07818 100644 --- a/absl/time/clock.cc +++ b/absl/time/clock.cc @@ -510,7 +510,7 @@ namespace { // Returns the maximum duration that SleepOnce() can sleep for. constexpr absl::Duration MaxSleep() { #ifdef _WIN32 - // Windows _sleep() takes unsigned long argument in milliseconds. + // Windows Sleep() takes unsigned long argument in milliseconds. return absl::Milliseconds( std::numeric_limits::max()); // NOLINT(runtime/int) #else @@ -522,7 +522,7 @@ constexpr absl::Duration MaxSleep() { // REQUIRES: to_sleep <= MaxSleep(). void SleepOnce(absl::Duration to_sleep) { #ifdef _WIN32 - _sleep(to_sleep / absl::Milliseconds(1)); + Sleep(to_sleep / absl::Milliseconds(1)); #else struct timespec sleep_time = absl::ToTimespec(to_sleep); while (nanosleep(&sleep_time, &sleep_time) != 0 && errno == EINTR) { From e98380282fdcd1573d478f380dafa08a15d2f9a5 Mon Sep 17 00:00:00 2001 From: Loo Rong Jie Date: Wed, 29 Nov 2017 08:37:53 +0800 Subject: [PATCH 2/2] Add comments about warning flags --- CMake/README.md | 5 +++++ CMakeLists.txt | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CMake/README.md b/CMake/README.md index 9c2d6897f..0ae9c2686 100644 --- a/CMake/README.md +++ b/CMake/README.md @@ -44,6 +44,11 @@ set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++ ${CMAKE_CXX_FLAGS}") if (MSVC) + # /wd4005 macro-redefinition + # /wd4068 unknown pragma + # /wd4244 conversion from 'type1' to 'type2' + # /wd4267 conversion from 'size_t' to 'type2' + # /wd4800 force value to bool 'true' or 'false' (performance warning) add_compile_options(/wd4005 /wd4068 /wd4244 /wd4267 /wd4800) add_definitions(/DNOMINMAX /DWIN32_LEAN_AND_MEAN=1 /D_CRT_SECURE_NO_WARNINGS) endif() diff --git a/CMakeLists.txt b/CMakeLists.txt index a740088a6..c65805ebd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,8 +27,13 @@ include(AbseilHelpers) # config options if (MSVC) - add_definitions(/DNOMINMAX /DWIN32_LEAN_AND_MEAN=1 /D_CRT_SECURE_NO_WARNINGS) + # /wd4005 macro-redefinition + # /wd4068 unknown pragma + # /wd4244 conversion from 'type1' to 'type2' + # /wd4267 conversion from 'size_t' to 'type2' + # /wd4800 force value to bool 'true' or 'false' (performance warning) add_compile_options(/W3 /WX /wd4005 /wd4068 /wd4244 /wd4267 /wd4800) + add_definitions(/DNOMINMAX /DWIN32_LEAN_AND_MEAN=1 /D_CRT_SECURE_NO_WARNINGS) else() set(ABSL_STD_CXX_FLAG "-std=c++11" CACHE STRING "c++ std flag (default: c++11)") endif()