From: Gunnar Beutner Date: Sun, 31 Aug 2014 09:01:37 +0000 (+0200) Subject: Detect whether __COUNTER__ is available X-Git-Tag: v2.1.1~50 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6ba06126445fd81ec5401d96dd98f5f3234c52ed;p=icinga2 Detect whether __COUNTER__ is available fixes #7040 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 5dfbd11c6..7739c6683 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -113,8 +113,17 @@ endif() set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/Bin/${CMAKE_BUILD_TYPE} CACHE PATH "Library output path") set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/Bin/${CMAKE_BUILD_TYPE} CACHE PATH "Executable output path") +include(CheckSymbolExists) include(CheckFunctionExists) include(CheckLibraryExists) + +check_symbol_exists(__COUNTER__ "" HAVE_COUNTER_MACRO) + +if(NOT HAVE_COUNTER_MACRO AND ICINGA2_UNITY_BUILD) + message(STATUS "Your C/C++ compiler does not support the __COUNTER__ macro. Disabling unity build.") + set(ICINGA2_UNITY_BUILD FALSE) +endif() + check_function_exists(vfork HAVE_VFORK) check_function_exists(backtrace_symbols HAVE_BACKTRACE_SYMBOLS) check_function_exists(pipe2 HAVE_PIPE2) diff --git a/config.h.cmake b/config.h.cmake index 8f0f3f349..2c03a0ae9 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -1,6 +1,7 @@ #ifndef CONFIG_H #define CONFIG_H +#cmakedefine HAVE_COUNTER_MACRO #cmakedefine HAVE_BACKTRACE_SYMBOLS #cmakedefine HAVE_PIPE2 #cmakedefine HAVE_VFORK diff --git a/lib/base/initialize.hpp b/lib/base/initialize.hpp index 5baf050e7..4e7319fdb 100644 --- a/lib/base/initialize.hpp +++ b/lib/base/initialize.hpp @@ -35,7 +35,7 @@ inline bool InitializeOnceHelper(InitializeFunc func) } #define INITIALIZE_ONCE(func) \ - namespace { namespace TOKENPASTE2(io, __COUNTER__) { \ + namespace { namespace UNIQUE_NAME(io) { \ I2_EXPORT bool l_InitializeOnce(icinga::InitializeOnceHelper(func)); \ } } diff --git a/lib/base/type.hpp b/lib/base/type.hpp index 4656796ac..219b07bc6 100644 --- a/lib/base/type.hpp +++ b/lib/base/type.hpp @@ -100,7 +100,7 @@ struct FactoryHelper }; #define REGISTER_TYPE(type) \ - namespace { namespace TOKENPASTE2(rt, __COUNTER__) { \ + namespace { namespace UNIQUE_NAME(rt) { \ void RegisterType(void) \ { \ icinga::Type *t = new TypeImpl(); \ diff --git a/lib/base/utility.hpp b/lib/base/utility.hpp index bd3dc8021..361d17c4d 100644 --- a/lib/base/utility.hpp +++ b/lib/base/utility.hpp @@ -33,9 +33,11 @@ namespace icinga #define TOKENPASTE(x, y) x ## y #define TOKENPASTE2(x, y) TOKENPASTE(x, y) -#if defined(ICINGA2_UNITY_BUILD) && !defined(__COUNTER__) -# error "Your compiler needs to support __COUNTER__ in order to do unity builds." -#endif /* ICINGA2_UNITY_BUILD && !defined(__COUNTER__) */ +#ifdef HAVE_COUNTER_MACRO +# define UNIQUE_NAME(prefix) TOKENPASTE2(prefix, __COUNTER__) +#else /* HAVE_COUNTER_MACRO */ +# define UNIQUE_NAME(prefix) prefix +#endif /* HAVE_COUNTER_MACRO */ #ifdef _WIN32 #define MS_VC_EXCEPTION 0x406D1388