Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2013-01-01 16:47:58 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-01-01 16:47:58 +0400
commit80ff313495ed739851dbd15d3e31506904503d5e (patch)
tree9a80a4983ccc829ac98bca931276b38c1acab961
parente4f65749f9c522476f646004c06556b0fc5c4b4d (diff)
patch [#33331] Time To Start Moving To Stdbool
by Lawrence D'Oliveiro (ldo) so BKE_utildefines.h allows use of C99's bool type and true/false. currently scons wont try to use stdbool.h, and works as if its never found.
-rw-r--r--CMakeLists.txt16
-rw-r--r--SConstruct3
-rw-r--r--build_files/cmake/macros.cmake9
-rw-r--r--source/blender/blenlib/BLI_utildefines.h30
4 files changed, 52 insertions, 6 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 674e532ff2c..a87c3e2d96d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -149,6 +149,9 @@ mark_as_advanced(WITH_HEADLESS)
option(WITH_AUDASPACE "Build with blenders audio library (only disable if you know what you're doing!)" ON)
mark_as_advanced(WITH_AUDASPACE)
+option(WITH_BOOL_COMPAT "Continue defining \"TRUE\" and \"FALSE\" until these can be replaced with \"true\" and \"false\" from stdbool.h" ON)
+mark_as_advanced(WITH_BOOL_COMPAT)
+
# (unix defaults to OpenMP On)
if((UNIX AND NOT APPLE) OR (MINGW))
@@ -264,7 +267,6 @@ mark_as_advanced(WITH_CXX_GUARDEDALLOC)
option(WITH_ASSERT_ABORT "Call abort() when raising an assertion through BLI_assert()" OFF)
mark_as_advanced(WITH_ASSERT_ABORT)
-
if(APPLE)
cmake_minimum_required(VERSION 2.8.8)
cmake_policy(VERSION 2.8.8)
@@ -423,6 +425,13 @@ endif()
TEST_SSE_SUPPORT(COMPILER_SSE_FLAG COMPILER_SSE2_FLAG)
+TEST_STDBOOL_SUPPORT()
+if(HAVE_STDBOOL_H)
+ add_definitions(-DHAVE_STDBOOL_H)
+endif()
+if(WITH_BOOL_COMPAT)
+ add_definitions(-DWITH_BOOL_COMPAT)
+endif()
#-----------------------------------------------------------------------------
# Check for valid directories
@@ -2137,3 +2146,8 @@ if(FIRST_RUN)
message("${_config_msg}")
endif()
+
+# debug
+message(
+ STATUS "HAVE_STDBOOL_H = ${HAVE_STDBOOL_H}"
+)
diff --git a/SConstruct b/SConstruct
index f73aabc6767..90c3c45b302 100644
--- a/SConstruct
+++ b/SConstruct
@@ -373,9 +373,10 @@ if btools.ENDIAN == "big":
else:
env['CPPFLAGS'].append('-D__LITTLE_ENDIAN__')
-# TODO, make optional
+# TODO, make optional (as with CMake)
env['CPPFLAGS'].append('-DWITH_AUDASPACE')
env['CPPFLAGS'].append('-DWITH_AVI')
+env['CPPFLAGS'].append('-DWITH_BOOL_COMPAT')
# lastly we check for root_build_dir ( we should not do before, otherwise we might do wrong builddir
B.root_build_dir = env['BF_BUILDDIR']
diff --git a/build_files/cmake/macros.cmake b/build_files/cmake/macros.cmake
index efa258aa9dc..4a4c0fe6d2d 100644
--- a/build_files/cmake/macros.cmake
+++ b/build_files/cmake/macros.cmake
@@ -441,6 +441,15 @@ macro(TEST_SSE_SUPPORT
unset(CMAKE_REQUIRED_FLAGS)
endmacro()
+macro(TEST_STDBOOL_SUPPORT)
+ # This program will compile correctly if and only if
+ # this C compiler supports C99 stdbool.
+ check_c_source_runs("
+ #include <stdbool.h>
+ int main(void) { return (int)false; }"
+ HAVE_STDBOOL_H)
+endmacro()
+
# when we have warnings as errors applied globally this
# needs to be removed for some external libs which we dont maintain.
diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h
index 7c3b70545d6..1774ef3d2b7 100644
--- a/source/blender/blenlib/BLI_utildefines.h
+++ b/source/blender/blenlib/BLI_utildefines.h
@@ -32,12 +32,34 @@
* \ingroup bli
*/
-#ifndef FALSE
-# define FALSE 0
+/* note: use of (int, TRUE / FALSE) is deprecated,
+ * use (bool, true / false) instead */
+#ifdef HAVE_STDBOOL_H
+# include <stdbool.h>
+#else
+# ifndef HAVE__BOOL
+# ifdef __cplusplus
+typedef bool _Bool;
+# else
+# define _Bool signed char
+# endif
+# endif
+# define bool _Bool
+# define false 0
+# define true 1
+# define __bool_true_false_are_defined 1
#endif
-#ifndef TRUE
-# define TRUE 1
+/* remove this when we're ready to remove TRUE/FALSE completely */
+#ifdef WITH_BOOL_COMPAT
+/* interim until all occurrences of these can be updated to stdbool */
+# ifndef FALSE
+# define FALSE 0
+# endif
+
+# ifndef TRUE
+# define TRUE 1
+# endif
#endif
/* useful for finding bad use of min/max */