Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support defining C99 bool as the BOOL type #322

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,23 @@ 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
add_compile_definitions($<$<CONFIG:Release>:NO_SELECTOR_MISMATCH_WARNINGS>)
add_compile_definitions($<$<BOOL:${TYPE_DEPENDENT_DISPATCH}>:TYPE_DEPENDENT_DISPATCH>)
add_compile_definitions($<$<BOOL:${ENABLE_TRACING}>:WITH_TRACING=1>)
add_compile_definitions($<$<BOOL:${DEBUG_ARC_COMPAT}>:DEBUG_ARC_COMPAT>)
add_compile_definitions($<$<BOOL:${STRICT_APPLE_COMPATIBILITY}>:STRICT_APPLE_COMPATIBILITY>)

configure_file(objc/objc-config.h.in objc/objc-config.h @ONLY)
include_directories("${PROJECT_BINARY_DIR}/objc/")
Expand Down
17 changes: 17 additions & 0 deletions objc/objc-config.h.in
Original file line number Diff line number Diff line change
@@ -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
8 changes: 7 additions & 1 deletion objc/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ extern "C" {
#include <sys/types.h>
#include "Availability.h"

#if OBJC_BOOL_TYPE == OBJC_BOOL_TYPE_STDBOOL
#include <stdbool.h>
#endif

// Undo GNUstep substitutions
#ifdef class_setVersion
# undef class_setVersion
Expand Down Expand Up @@ -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)
Expand Down
Loading