cmocka: Allow include of cmocka_platform.h
authorAndreas Schneider <asn@cryptomilk.org>
Tue, 10 Feb 2015 07:23:25 +0000 (08:23 +0100)
committerAndreas Schneider <asn@cryptomilk.org>
Tue, 10 Feb 2015 14:49:30 +0000 (15:49 +0100)
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
doc/mainpage.dox
src/CMakeLists.txt
src/cmocka.c

index 5d658e0..925bfd2 100644 (file)
@@ -83,6 +83,18 @@ the mock object to return. CMocka provides and API to easily mock code.
 
 <a href="https://lwn.net/Articles/558106/">Learn more ...</a>
 
+@section main-embedded Embedded platforms
+
+It is possible that some embedded platforms do not provide definitions for
+required types or that the guards to protect them are not defined. To address
+this issue you can create a header file name 'cmocka_platform.h' with the
+required types and definitions. After that point cmake to the include directory
+using:
+
+<pre>
+    cmake -DCMOCKA_PLATFORM_INCLUDE=/home/compiler/my/include_directory ..
+</pre>
+
 @section main-threads Threading
 
 cmocka is not fully thread safe and it is not the goal of it to be it. We have
index 2b3c486..4ab084e 100644 (file)
@@ -1,7 +1,10 @@
 project(cmocka-library C)
 
+set(CMOCKA_PLATFORM_INCLUDE CACHE PATH "Path to include directory for cmocka_platform.h")
+
 set(CMOCKA_PUBLIC_INCLUDE_DIRS
     ${CMAKE_SOURCE_DIR}/include
+    ${CMOCKA_PLATFORM_INCLUDE}
     CACHE INTERNAL "cmocka public include directories"
 )
 
@@ -43,6 +46,9 @@ include_directories(
 )
 
 add_definitions(-DHAVE_CONFIG_H=1)
+if (CMOCKA_PLATFORM_INCLUDE)
+    add_definitions(-DCMOCKA_PLATFORM_INCLUDE=1)
+endif()
 
 add_library(${CMOCKA_SHARED_LIBRARY} SHARED ${cmocka_SRCS})
 
index 068bbcb..5b37688 100644 (file)
@@ -67,6 +67,20 @@ WINBASEAPI BOOL WINAPI IsDebuggerPresent(VOID);
 #include <signal.h>
 #endif /* _WIN32 */
 
+/*
+ * This allows to add a platform specific header file. Some embedded platforms
+ * sometimes miss certain types and definitions.
+ *
+ * Example:
+ *
+ * typedef unsigned long int uintptr_t
+ * #define _UINTPTR_T 1
+ * #define _UINTPTR_T_DEFINED 1
+ */
+#ifdef CMOCKA_PLATFORM_INCLUDE
+# include "cmocka_platform.h"
+#endif /* CMOCKA_PLATFORM_INCLUDE */
+
 #include <cmocka_private.h>
 #include <cmocka.h>