diff --git a/CMakeLists.txt b/CMakeLists.txt index a9aa16b5..24d6a8ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -141,7 +141,16 @@ option(DEBUG_ARC_COMPAT option(ENABLE_OBJCXX "Enable support for Objective-C++" ON) option(TESTS "Enable building the tests") option(EMBEDDED_BLOCKS_RUNTIME "Include an embedded blocks runtime, rather than relying on libBlocksRuntime to supply it" ON) -option(STRICT_APPLE_COMPATIBILITY "Use strict Apple compatibility, always defining BOOL as signed char" OFF) +option(STRICT_APPLE_COMPATIBILITY "Use strict Apple compatibility, defining non-C99-bool BOOL as signed char" OFF) +set(OBJC_BOOL_IS_BOOL_MODE auto CACHE STRING "Control whether BOOL should be defined as C99 bool. One of 'auto', 'always', 'never'.") + +if ("${OBJC_BOOL_IS_BOOL_MODE}" STREQUAL "always") + set(OBJC_BOOL_IS_BOOL_MODE_CONFIG OBJC_BOOL_IS_BOOL_MODE_ALWAYS) +elseif ("${OBJC_BOOL_IS_BOOL_MODE}" STREQUAL "never") + set(OBJC_BOOL_IS_BOOL_MODE_CONFIG OBJC_BOOL_IS_BOOL_MODE_NEVER) +else() + set(OBJC_BOOL_IS_BOOL_MODE_CONFIG OBJC_BOOL_IS_BOOL_MODE_AUTO) +endif() # For release builds, we disable spamming the terminal with warnings about # selector type mismatches @@ -149,7 +158,6 @@ add_compile_definitions($<$:NO_SELECTOR_MISMATCH_WARNINGS>) add_compile_definitions($<$:TYPE_DEPENDENT_DISPATCH>) add_compile_definitions($<$:WITH_TRACING=1>) add_compile_definitions($<$:DEBUG_ARC_COMPAT>) -add_compile_definitions($<$:STRICT_APPLE_COMPATIBILITY>) configure_file(objc/objc-config.h.in objc/objc-config.h @ONLY) include_directories("${PROJECT_BINARY_DIR}/objc/") diff --git a/objc/objc-config.h.in b/objc/objc-config.h.in index 907563c4..2a65a86a 100644 --- a/objc/objc-config.h.in +++ b/objc/objc-config.h.in @@ -1 +1,18 @@ #cmakedefine STRICT_APPLE_COMPATIBILITY @STRICT_APPLE_COMPATIBILITY@ + +#define OBJC_BOOL_IS_BOOL_MODE_AUTO 1 +#define OBJC_BOOL_IS_BOOL_MODE_ALWAYS 2 +#define OBJC_BOOL_IS_BOOL_MODE_NEVER 3 +#cmakedefine OBJC_BOOL_IS_BOOL_MODE @OBJC_BOOL_IS_BOOL_MODE_CONFIG@ + +#define OBJC_BOOL_TYPE_STDBOOL 1 +#define OBJC_BOOL_TYPE_TRADITIONAL 2 +#define OBJC_BOOL_TYPE_APPLE 3 + +#if OBJC_BOOL_IS_BOOL_MODE == OBJC_BOOL_IS_BOOL_MODE_ALWAYS || (defined(__OBJC_BOOL_IS_BOOL) && OBJC_BOOL_IS_BOOL_MODE == OBJC_BOOL_IS_BOOL_MODE_AUTO) +#define OBJC_BOOL_TYPE OBJC_BOOL_TYPE_STDBOOL +#elif STRICT_APPLE_COMPATIBILITY +#define OBJC_BOOL_TYPE OBJC_BOOL_TYPE_APPLE +#else +#define OBJC_BOOL_TYPE OBJC_BOOL_TYPE_TRADITIONAL +#endif \ No newline at end of file diff --git a/objc/runtime.h b/objc/runtime.h index 14cb2748..dfd3fbf4 100644 --- a/objc/runtime.h +++ b/objc/runtime.h @@ -44,6 +44,10 @@ extern "C" { #include #include "Availability.h" +#if OBJC_BOOL_TYPE == OBJC_BOOL_TYPE_STDBOOL +#include +#endif + // Undo GNUstep substitutions #ifdef class_setVersion # undef class_setVersion @@ -129,7 +133,9 @@ typedef struct objc_method *Method; /** * Objective-C boolean type. */ -# ifdef STRICT_APPLE_COMPATIBILITY +# if OBJC_BOOL_TYPE == OBJC_BOOL_TYPE_STDBOOL +typedef bool BOOL; +# elif OBJC_BOOL_TYPE == OBJC_BOOL_TYPE_APPLE typedef signed char BOOL; # else # if defined(__vxworks) || defined(_WIN32)