From 6ea66c045cddc503fdfec5513c68028ea125a241 Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Sat, 10 Jan 2015 01:15:25 +0300 Subject: [PATCH] libuavcan now compiles warning-free with -Wundef --- libuavcan/CMakeLists.txt | 2 +- libuavcan/include/uavcan/build_config.hpp | 17 ++++++++++++++--- libuavcan/include/uavcan/debug.hpp | 2 ++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/libuavcan/CMakeLists.txt b/libuavcan/CMakeLists.txt index ae1d920044..0648b8ca14 100644 --- a/libuavcan/CMakeLists.txt +++ b/libuavcan/CMakeLists.txt @@ -42,7 +42,7 @@ include_directories(${DSDLC_OUTPUT}) # Compiler flags # if (COMPILER_IS_GCC_COMPATIBLE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wundef") if (USE_CPP03) message(STATUS "Using C++03") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++03 -Wno-variadic-macros -Wno-long-long") diff --git a/libuavcan/include/uavcan/build_config.hpp b/libuavcan/include/uavcan/build_config.hpp index 028d19bd01..f9d6c65934 100644 --- a/libuavcan/include/uavcan/build_config.hpp +++ b/libuavcan/include/uavcan/build_config.hpp @@ -37,13 +37,21 @@ # endif #endif +/** + * This macro enables built-in runtime checks and debug output via printf(). + * Should be used only for library development. + */ +#ifndef UAVCAN_DEBUG +# define UAVCAN_DEBUG 0 +#endif + /** * UAVCAN can be explicitly told to ignore exceptions, or it can be detected automatically. * Autodetection is not expected to work with all compilers, so it's safer to define it explicitly. * If the autodetection fails, exceptions will be disabled by default. */ #ifndef UAVCAN_EXCEPTIONS -# if __EXCEPTIONS || _HAS_EXCEPTIONS +# if defined(__EXCEPTIONS) || defined(_HAS_EXCEPTIONS) # define UAVCAN_EXCEPTIONS 1 # else # define UAVCAN_EXCEPTIONS 0 @@ -89,7 +97,7 @@ */ #ifndef UAVCAN_TOSTRING // Objective is to make sure that we're NOT on a resource constrained platform -# if __linux__ || __linux || __APPLE__ || _WIN64 || _WIN32 +# if defined(__linux__) || defined(__linux) || defined(__APPLE__) || defined(_WIN64) || defined(_WIN32) # define UAVCAN_TOSTRING 1 # else # define UAVCAN_TOSTRING 0 @@ -116,6 +124,9 @@ * Disabled completely if UAVCAN_NO_ASSERTIONS is defined. */ #ifndef UAVCAN_ASSERT +# ifndef UAVCAN_NO_ASSERTIONS +# define UAVCAN_NO_ASSERTIONS 0 +# endif # if UAVCAN_NO_ASSERTIONS # define UAVCAN_ASSERT(x) # else @@ -139,7 +150,7 @@ namespace uavcan * Note that the pool block size shall be aligned at biggest alignment of the target platform (detected and * checked automatically at compile time). */ -#if UAVCAN_MEM_POOL_BLOCK_SIZE +#ifdef UAVCAN_MEM_POOL_BLOCK_SIZE /// Explicitly specified by the user. static const unsigned MemPoolBlockSize = UAVCAN_MEM_POOL_BLOCK_SIZE; #elif defined(__BIGGEST_ALIGNMENT__) && (__BIGGEST_ALIGNMENT__ <= 8) diff --git a/libuavcan/include/uavcan/debug.hpp b/libuavcan/include/uavcan/debug.hpp index 82896228fc..bee2dd0ad1 100644 --- a/libuavcan/include/uavcan/debug.hpp +++ b/libuavcan/include/uavcan/debug.hpp @@ -5,6 +5,8 @@ #pragma once +#include + #if UAVCAN_DEBUG # include