Detect whether __COUNTER__ is available

fixes #7040
This commit is contained in:
Gunnar Beutner 2014-08-31 11:01:37 +02:00
parent 1c92712146
commit 6ba0612644
5 changed files with 17 additions and 5 deletions

View 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)

View 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

View 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)); \
} }

View 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>(); \

View 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