fixes #976 Enable all warnings by default

While here we fix a few warnings we found, and enable coverage
building with CMake.  This is in anticipation of switching to
Circle CI.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1727a95..b0aa665 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -98,6 +98,7 @@
 
 option (NN_STATIC_LIB "Build static library instead of shared library." OFF)
 option (NN_ENABLE_DOC "Enable building documentation." ON)
+option (NN_ENABLE_COVERAGE "Enable coverage reporting." OFF)
 option (NN_ENABLE_GETADDRINFO_A "Enable/disable use of getaddrinfo_a in place of getaddrinfo." ON)
 option (NN_TESTS "Build and run nanomsg tests" ON)
 option (NN_TOOLS "Build nanomsg tools" ON)
@@ -106,6 +107,32 @@
 
 #  Platform checks.
 
+if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
+    set(NN_WARN_FLAGS "-Wall -Wextra")
+elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang")
+    set(NN_WARN_FLAGS "-Wall -Wextra")
+elseif (CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
+    set(NN_WARN_FLAGS "-Wall -Wextra")
+endif()
+
+if (NNG_ENABLE_COVERAGE)
+    # NB: This only works for GCC and Clang 3.0 and newer.  If your stuff
+    # is older than that, you will need to find something newer.  For
+    # correct reporting, we always turn off all optimizations.
+    if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
+        set(NN_COVERAGE_FLAGS "-g -O0 --coverage")
+    elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang")
+        set(NN_COVERAGE_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
+    elseif (CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
+        set(NN_COVERAGE_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage")
+    else()
+        message(FATAL_ERROR "Unable to enable coverage for your compiler.")
+    endif()
+endif()
+
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${NN_WARN_FLAGS} ${NN_COVERAGE_FLAGS}")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${NN_WARN_FLAGS} ${NN_COVERAGE_FLAGS}")
+
 find_package (Threads REQUIRED)
 
 message(STATUS "OS System is ${CMAKE_SYSTEM_NAME}")
diff --git a/src/utils/atomic.c b/src/utils/atomic.c
index 4018c7e..f82d0b9 100644
--- a/src/utils/atomic.c
+++ b/src/utils/atomic.c
@@ -22,6 +22,7 @@
 
 #include "atomic.h"
 #include "err.h"
+#include "attr.h"
 
 void nn_atomic_init (struct nn_atomic *self, uint32_t n)
 {
@@ -31,12 +32,16 @@
 #endif
 }
 
+#if defined NN_ATOMIC_MUTEX
 void nn_atomic_term (struct nn_atomic *self)
 {
-#if defined NN_ATOMIC_MUTEX
     nn_mutex_term (&self->sync);
-#endif
 }
+#else
+void nn_atomic_term (NN_UNUSED struct nn_atomic *self)
+{
+}
+#endif
 
 uint32_t nn_atomic_inc (struct nn_atomic *self, uint32_t n)
 {
diff --git a/tests/bug777.c b/tests/bug777.c
index 506ec73..7d5e01b 100644
--- a/tests/bug777.c
+++ b/tests/bug777.c
@@ -25,7 +25,7 @@
 
 #include "testutil.h"
 
-int main (int argc, const char *argv[])
+int main (NN_UNUSED int argc, const NN_UNUSED char *argv[])
 {
     int sb;
     int sc1;
diff --git a/tests/ipc_stress.c b/tests/ipc_stress.c
index a3bbf84..4ebd171 100644
--- a/tests/ipc_stress.c
+++ b/tests/ipc_stress.c
@@ -95,7 +95,7 @@
         bytes = nn_send (cli_sock, msg, sz_msg, 0);
         /*  This would better be handled via semaphore or condvar. */
         nn_sleep (100);
-        nn_assert (bytes == sz_msg);
+        nn_assert ((size_t)bytes == sz_msg);
         nn_close (cli_sock);
     }
 }