From b2bae6fefa13b363ad40e08e35116596dd058608 Mon Sep 17 00:00:00 2001
From: Roman Tsisyk <roman@tsisyk.com>
Date: Fri, 24 Apr 2015 15:54:16 +0300
Subject: [PATCH] Fix tarantool.h generation from config.h for out-of-source
 builds

---
 cmake/utils.cmake         |  8 ++++++--
 src/trivia/CMakeLists.txt |  6 +++++-
 test/app/module_api.c     | 17 +++++++++++++++++
 3 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/cmake/utils.cmake b/cmake/utils.cmake
index ed1c9e0236..c03c0878a1 100644
--- a/cmake/utils.cmake
+++ b/cmake/utils.cmake
@@ -87,7 +87,11 @@ function(apigen)
     set (headers)
     # Get absolute path for header files (required of out-of-source build)
     foreach (header ${ARGN})
-        list(APPEND headers ${CMAKE_CURRENT_SOURCE_DIR}/${header})
+        if (IS_ABSOLUTE ${header})
+            list(APPEND headers ${header})
+        else()
+            list(APPEND headers ${CMAKE_CURRENT_SOURCE_DIR}/${header})
+        endif()
     endforeach()
 
     add_custom_command(OUTPUT ${dstfile}
@@ -101,6 +105,6 @@ function(apigen)
                 ${CMAKE_CURRENT_SOURCE_DIR}/tarantool_footer.h
         )
 
-    add_custom_target(generate_module_api ALL DEPENDS ${dstfile})
+    add_custom_target(generate_module_api ALL DEPENDS ${srcfiles} ${dstfile})
     install(FILES ${dstfile} DESTINATION ${MODULE_INCLUDEDIR})
 endfunction()
diff --git a/src/trivia/CMakeLists.txt b/src/trivia/CMakeLists.txt
index 4e028a3cb1..4a50400da6 100644
--- a/src/trivia/CMakeLists.txt
+++ b/src/trivia/CMakeLists.txt
@@ -1,2 +1,6 @@
-set(api_headers config.h ../say.h ../coeio.h ../lua/utils.h)
+set(api_headers
+    ${CMAKE_CURRENT_BINARY_DIR}/config.h
+    ../say.h
+    ../coeio.h
+    ../lua/utils.h)
 apigen(${api_headers})
diff --git a/test/app/module_api.c b/test/app/module_api.c
index bf6907bc0d..e1938676b3 100644
--- a/test/app/module_api.c
+++ b/test/app/module_api.c
@@ -8,6 +8,22 @@
 #include <lua.h>
 #include <lauxlib.h>
 
+#define STR2(x) #x
+#define STR(x) STR2(x)
+
+/* Test for constants */
+static const char *consts[] = {
+	PACKAGE_VERSION,
+	STR(PACKAGE_VERSION_MINOR),
+	STR(PACKAGE_VERSION_MAJOR),
+	STR(PACKAGE_VERSION_PATCH),
+	TARANTOOL_C_FLAGS,
+	TARANTOOL_CXX_FLAGS,
+	MODULE_LIBDIR,
+	MODULE_LUADIR,
+	MODULE_INCLUDEDIR
+};
+
 static int
 test_say(lua_State *L)
 {
@@ -88,6 +104,7 @@ test_pushint64(lua_State *L)
 LUA_API int
 luaopen_module_api(lua_State *L)
 {
+	(void) consts;
 	static const struct luaL_reg lib[] = {
 		{"test_say", test_say },
 		{"test_coio_call", test_coio_call },
-- 
GitLab