]> granicus.if.org Git - icinga2/commitdiff
Detect whether __COUNTER__ is available
authorGunnar Beutner <gunnar.beutner@netways.de>
Sun, 31 Aug 2014 09:01:37 +0000 (11:01 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Sun, 31 Aug 2014 09:01:37 +0000 (11:01 +0200)
fixes #7040

CMakeLists.txt
config.h.cmake
lib/base/initialize.hpp
lib/base/type.hpp
lib/base/utility.hpp

index 5dfbd11c6587cce06389ff45d863ea3e07141496..7739c66835fa1ab669988d0250cf5cfaf1c562a5 100644 (file)
@@ -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)
index 8f0f3f3495eb908f209ec42c777d6df8804409dd..2c03a0ae9a6167f39974e51882b1530974550443 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef CONFIG_H
 #define CONFIG_H
 
+#cmakedefine HAVE_COUNTER_MACRO
 #cmakedefine HAVE_BACKTRACE_SYMBOLS
 #cmakedefine HAVE_PIPE2
 #cmakedefine HAVE_VFORK
index 5baf050e71226554c3a9d2142f107d71abbb7329..4e7319fdb6064e85ddfde5265977e7cb277d9a9c 100644 (file)
@@ -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)); \
        } }
 
index 4656796ac2f2a12243f789122410be19a84ee227..219b07bc6c39ca2d37ecc7ac19bd10eae2f45307 100644 (file)
@@ -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<type>(); \
index bd3dc8021981b1c231b360c660f2cef057903f72..361d17c4d2227af7387807541657794f58065be7 100644 (file)
@@ -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