diff --git a/cmake/utils.cmake b/cmake/utils.cmake
index ed1c9e0236ad7705eae330faf50d8e83ac430587..c03c0878a19d151263fbb864b2bf69b03bf3da2a 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 4e028a3cb11e4b80a79548b81d7efd8f4a45025b..4a50400da68c92377432a065dea36c91a16a523c 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 bf6907bc0ddc2370c79ba69241cbe9e586dba607..e1938676b38e709271b2bbe0899141634494b1a8 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 },