From 035ccd87d91c50274985eecef769760e7471923b Mon Sep 17 00:00:00 2001
From: Nick Zavaritsky <mejedi@gmail.com>
Date: Thu, 3 Sep 2015 13:25:31 +0300
Subject: [PATCH] Fix tarantool.h generation on osx

Pass sysroot.
Abort build if preprocessing fails (a stage in tarantool.h generation).
---
 cmake/module.cmake | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/cmake/module.cmake b/cmake/module.cmake
index 8d6eafbcaf..25cb8f4934 100644
--- a/cmake/module.cmake
+++ b/cmake/module.cmake
@@ -2,6 +2,7 @@
 function(rebuild_module_api)
     set (dstfile "${CMAKE_CURRENT_BINARY_DIR}/tarantool.h")
     set (tmpfile "${dstfile}.new")
+    set (errcodefile "${CMAKE_CURRENT_BINARY_DIR}/errcode.i")
     set (headers)
     # Get absolute path for header files (required of out-of-source build)
     foreach (header ${ARGN})
@@ -12,16 +13,24 @@ function(rebuild_module_api)
         endif()
     endforeach()
 
+    set (cflags ${CMAKE_C_FLAGS})
+    separate_arguments(cflags)
+    # Pass sysroot settings on OSX
+    if (NOT "${CMAKE_OSX_SYSROOT}" STREQUAL "")
+        set (cflags ${cflags} ${CMAKE_C_SYSROOT_FLAG} ${CMAKE_OSX_SYSROOT})
+    endif()
     add_custom_command(OUTPUT ${dstfile}
         COMMAND cat ${CMAKE_CURRENT_SOURCE_DIR}/tarantool_header.h > ${tmpfile}
         COMMAND cat ${headers} | ${CMAKE_SOURCE_DIR}/extra/apigen >> ${tmpfile}
         COMMAND ${CMAKE_C_COMPILER}
+            ${cflags}
             -I ${CMAKE_SOURCE_DIR}/src -I ${CMAKE_BINARY_DIR}/src
-            -E ${CMAKE_SOURCE_DIR}/src/box/errcode.h |
-            grep "enum box_error_code" >> ${tmpfile}
+            -E ${CMAKE_SOURCE_DIR}/src/box/errcode.h > ${errcodefile}
+        COMMAND
+            grep "enum box_error_code" ${errcodefile} >> ${tmpfile}
         COMMAND cat ${CMAKE_CURRENT_SOURCE_DIR}/tarantool_footer.h >> ${tmpfile}
         COMMAND ${CMAKE_COMMAND} -E copy_if_different ${tmpfile} ${dstfile}
-        COMMAND ${CMAKE_COMMAND} -E remove ${tmpfile}
+        COMMAND ${CMAKE_COMMAND} -E remove ${errcodefile} ${tmpfile}
         DEPENDS ${srcfiles} ${CMAKE_SOURCE_DIR}/src/box/errcode.h
                 ${CMAKE_CURRENT_SOURCE_DIR}/tarantool_header.h
                 ${CMAKE_CURRENT_SOURCE_DIR}/tarantool_footer.h
-- 
GitLab