lua: expose add_list change items as table values
[project/uci.git] / lua / CMakeLists.txt
index 69079c9..63c6a40 100644 (file)
@@ -4,30 +4,49 @@ PROJECT(uci C)
 
 SET(CMAKE_INSTALL_PREFIX /)
 
 
 SET(CMAKE_INSTALL_PREFIX /)
 
-ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -g3)
+IF(NOT LUA_CFLAGS)
+       FIND_PROGRAM(PKG_CONFIG pkg-config)
+       IF(PKG_CONFIG)
+               EXECUTE_PROCESS(
+                       COMMAND pkg-config --silence-errors --cflags lua5.1
+                       OUTPUT_VARIABLE LUA_CFLAGS
+                       OUTPUT_STRIP_TRAILING_WHITESPACE
+               )
+       ENDIF()
+ENDIF()
+
+ADD_DEFINITIONS(-Os -Wall -Werror --std=gnu99 -g3 -I.. ${LUA_CFLAGS})
+LINK_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/..)
 
 IF(APPLE)
        SET(CMAKE_SHARED_MODULE_CREATE_C_FLAGS "${CMAKE_SHARED_MODULE_CREATE_C_FLAGS} -undefined dynamic_lookup")
 ENDIF(APPLE)
 
 
 IF(APPLE)
        SET(CMAKE_SHARED_MODULE_CREATE_C_FLAGS "${CMAKE_SHARED_MODULE_CREATE_C_FLAGS} -undefined dynamic_lookup")
 ENDIF(APPLE)
 
-EXECUTE_PROCESS(
-       COMMAND  lua -e "for k in string.gmatch(package.cpath .. \";\", \"([^;]+)/..so;\") do if k:sub(1,1) == \"/\" then print(k) break end end"
-       OUTPUT_VARIABLE LUAPATH
-       RESULT_VARIABLE LUA_CHECK_RES
-       OUTPUT_STRIP_TRAILING_WHITESPACE
-)
-
-IF(NOT ${LUA_CHECK_RES} EQUAL 0 OR ${LUAPATH} EQUAL "")
-       MESSAGE(SEND_ERROR "Lua was not found on your system")
+IF(NOT LUAPATH)
+       EXECUTE_PROCESS(
+               COMMAND  lua -e "for k in string.gmatch(package.cpath .. \";\", \"([^;]+)/..so;\") do if k:sub(1,1) == \"/\" then print(k) break end end"
+               OUTPUT_VARIABLE LUAPATH
+               RESULT_VARIABLE LUA_CHECK_RES
+               OUTPUT_STRIP_TRAILING_WHITESPACE
+       )
+
+       IF(BUILD_LUA)
+               IF(NOT ${LUA_CHECK_RES} EQUAL 0 OR ${LUAPATH} EQUAL "")
+                       MESSAGE(SEND_ERROR "Lua was not found on your system")
+               ENDIF()
+       ENDIF()
 ENDIF()
 
 ENDIF()
 
-ADD_LIBRARY(uci_lua MODULE uci.c)
-SET_TARGET_PROPERTIES(uci_lua PROPERTIES
-       OUTPUT_NAME uci
-       PREFIX ""
-)
-TARGET_LINK_LIBRARIES(uci_lua uci)
+IF(BUILD_LUA)
+       ADD_LIBRARY(uci_lua MODULE uci.c)
+       SET_TARGET_PROPERTIES(uci_lua PROPERTIES
+               OUTPUT_NAME uci
+               PREFIX ""
+       )
+       TARGET_LINK_LIBRARIES(uci_lua uci dl)
+
+       INSTALL(TARGETS uci_lua
+               LIBRARY DESTINATION ${LUAPATH}
+       )
+ENDIF()
 
 
-INSTALL(TARGETS uci_lua
-       LIBRARY DESTINATION ${LUAPATH}
-)