From 0a70ba2c01b2e417bb8667f56a88dde044565c1a Mon Sep 17 00:00:00 2001
From: redfish <redfish@galactica.pw>
Date: Fri, 8 Sep 2017 18:14:55 -0400
Subject: [PATCH 1/2] cmake: fix setting of -Werror

Setting COMPILE_FLAGS (or COMPILE_OPTIONS) property directly does not
end up on the command line (even though it should because
add_compile_options does just that).

Also, set -Werror for tests as well, because no warnings now.

Not set for 'external' only because simply moving add_compile_options
above add_subdirectory(external) doesn't do it, and moving add_usbdirectory
down is too big of a change (it will pick up new flags).

-Werror set only for GCC on Linux, since warnings not yet
cleared for other compilers/systems.
---
 CMakeLists.txt | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 971c097ff..535f3ab25 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -699,25 +699,19 @@ if(NOT ZMQ_LIB)
   message(FATAL_ERROR "Could not find require libzmq")
 endif()
 
-function (treat_warnings_as_errors dirs)
-  foreach(dir ${ARGV})
-    set_property(DIRECTORY ${dir}
-      APPEND PROPERTY COMPILE_FLAGS "-Werror")
-  endforeach()
-endfunction()
-
-add_subdirectory(contrib)
-add_subdirectory(src)
-
-treat_warnings_as_errors(contrib src)
-
 option(BUILD_TESTS "Build tests." OFF)
 
 if(BUILD_TESTS)
   add_subdirectory(tests)
 endif()
 
+# warnings are cleared only for GCC on Linux
+if (NOT (MINGW OR APPLE OR FREEBSD OR OPENBSD OR DRAGONFLY))
+add_compile_options("${WARNINGS_AS_ERRORS_FLAG}") # applies only to targets that follow
+endif()
 
+add_subdirectory(contrib)
+add_subdirectory(src)
 
 if(BUILD_DOCUMENTATION)
   set(DOC_GRAPHS "YES" CACHE STRING "Create dependency graphs (needs graphviz)")

From 504311128d96a9be1cd1401920e99d939564dc60 Mon Sep 17 00:00:00 2001
From: redfish <redfish@galactica.pw>
Date: Fri, 8 Sep 2017 22:20:44 -0400
Subject: [PATCH 2/2] cmake: make warning about headers not fatal

Warning issued on older boost and/or OS:

In file included from /usr/include/boost/asio/detail/socket_types.hpp:61:0,
                 from /usr/include/boost/asio/detail/epoll_reactor.hpp:30,
                 from /usr/include/boost/asio/detail/reactor.hpp:21,
                 from /usr/include/boost/asio/detail/impl/task_io_service.ipp:24,
                 from /usr/include/boost/asio/detail/task_io_service.hpp:198,
                 from /usr/include/boost/asio/impl/io_service.hpp:71,
                 from /usr/include/boost/asio/io_service.hpp:767,
                 from /usr/include/boost/asio/basic_io_object.hpp:19,
                 from /usr/include/boost/asio/basic_socket.hpp:20,
                 from /usr/include/boost/asio/basic_datagram_socket.hpp:20,
                 from /usr/include/boost/asio.hpp:21,
                 from /home/vagrant/slave/monero-static-alpine-3_5-x86_64/build/src/common/download.cpp:32:
/usr/include/sys/poll.h:1:2: warning: #warning redirecting incorrect #include <sys/poll.h> to <poll.h> [-Wcpp]
 #warning redirecting incorrect #include <sys/poll.h> to <poll.h>
---
 CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 535f3ab25..486a80b4e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -407,7 +407,7 @@ else()
       set(WARNINGS "${WARNINGS} -Wno-error=inline-asm")
     endif()
   else()
-    set(WARNINGS "${WARNINGS} -Wlogical-op -Wno-error=maybe-uninitialized")
+    set(WARNINGS "${WARNINGS} -Wlogical-op -Wno-error=maybe-uninitialized -Wno-error=cpp")
   endif()
   if(MINGW)
     set(WARNINGS "${WARNINGS} -Wno-error=unused-value -Wno-error=unused-but-set-variable")