[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: CMake build files for Lua 5.1.x
- From: "Robert G. Jakabosky" <bobby@...>
- Date: Thu, 1 Oct 2009 20:06:53 -0700
Attached is a patch to add CMake build files to Lua 5.1. I have only tested
them on Linux, but they should work for atleast Macs & Windows systems. Also
some of the LUA_USE_* CMake options don't do anything right now, but they can
still be changed in src/luaconf.h
The patch doesn't change any of the existing files in Lua, it only adds about
3 files. The old Makefiles will still be there.
If you use CMake in the same folder as the source, then it will overwrite some
of the old Makefiles.
I would recommend this usage (for Linux type systems):
cd lua-5.1.4/
patch -p1 </tmp/lua_CMake.patch
mkdir build
cd build
cmake ..
make
make install
--
Robert G. Jakabosky
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..abdbf72
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,108 @@
+#
+# Lua 5.1.x
+#
+cmake_minimum_required(VERSION 2.4 FATAL_ERROR)
+
+project(lua C)
+
+set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
+
+include(CustomMacros)
+
+enable_testing()
+
+option(BUILD_STATIC "build static library" ON)
+
+option(LUA_USE_DLOPEN "Enable dlopen support.")
+option(LUA_USE_ISATTY "Enable isatty support.")
+option(LUA_USE_READLINE "Enable readline support.")
+option(LUA_USE_POPEN "Enable lua_popen support.")
+option(LUA_USE_ULONGJMP "Try using _longjmp/_setjmp (more efficient)")
+option(LUA_USE_APICHECK "Enable API checks.")
+option(LUA_USE_MKSTEMP "Use mkstemp.")
+option(LUA_ANSI "Disable non-ansi features." OFF)
+
+#
+# Lua version
+#
+set(LUA_VERSION_MAJOR 5)
+set(LUA_VERSION_MINOR 1)
+set(LUA_VERSION_PATCH 4)
+set(LUA_VERSION
+ "${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}.${LUA_VERSION_PATCH}")
+set(LUA_SOVERSION
+ "${LUA_VERSION_MAJOR}")
+#
+# Lua package info.
+#
+set(CPACK_PACKAGE_VERSION_MAJOR ${LUA_VERSION_MAJOR})
+set(CPACK_PACKAGE_VERSION_MINOR ${LUA_VERSION_MINOR})
+set(CPACK_PACKAGE_VERSION_PATCH ${LUA_VERSION_PATCH})
+set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYRIGHT")
+set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README")
+set(CPACK_PACKAGE_VENDOR "Lua.org, PUC-Rio.")
+set(CPACK_SOURCE_GENERATOR "TGZ")
+set(CPACK_SOURCE_IGNORE_FILES
+"/\\\\.;/\\\\.git.*/;~$;build/;CMakeFiles/;CMakeCache;Testing/;cmake_install;CPack;Dart;Makefile$")
+set(CPACK_SOURCE_PACKAGE_FILE_NAME
+ "${CMAKE_PROJECT_NAME}-${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}.${LUA_VERSION_PATCH}")
+# MUST be after CPACK_* variables.
+include(CPack)
+
+set(COMMON_CFLAGS)
+set(COMMON_LDFLAGS " -lm ")
+
+#
+# Detect system type
+#
+if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+ set(LUA_USE_LINUX TRUE)
+ set(COMMON_CFLAGS "${COMMON_CFLAGS} -DLUA_USE_LINUX")
+ set(COMMON_LDFLAGS "${COMMON_LDFLAGS} -Wl,-E -ldl -lreadline -lhistory -lncurses")
+else(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+ if(APPLE)
+ set(LUA_USE_MACOSX TRUE)
+ set(COMMON_CFLAGS "${COMMON_CFLAGS} -DLUA_USE_LINUX")
+ set(COMMON_LDFLAGS "${COMMON_LDFLAGS} -lreadline ")
+ # use this on Mac OS X 10.3-
+ #set(COMMON_CFLAGS "${COMMON_CFLAGS} -DLUA_USE_MACOSX")
+ elseif(WIN32)
+ set(LUA_WIN TRUE)
+ set(COMMON_CFLAGS "${COMMON_CFLAGS} -DLUA_BUILD_AS_DLL")
+ elseif(UNIX)
+ set(LUA_USE_POSIX TRUE)
+ set(COMMON_CFLAGS "${COMMON_CFLAGS} -DLUA_USE_POSIX")
+ else(APPLE)
+ set(LUA_ANSI TRUE)
+ set(COMMON_CFLAGS "${COMMON_CFLAGS} -DLUA_ANSI")
+ endif(APPLE)
+endif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+
+#
+# standard flags to use for each build type.
+#
+if(CMAKE_COMPILER_IS_GNUCC)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pipe -Wall -Wextra -Wshadow -W -pedantic -std=gnu99 -fgnu89-inline")
+ set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2")
+ set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -g")
+ set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_PROFILE} -O1 -g")
+ set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_WITHDEBINFO} -O2 -g")
+endif(CMAKE_COMPILER_IS_GNUCC)
+
+#
+# Install extra header files & manpages
+#
+install(FILES
+ etc/lua.hpp
+ DESTINATION include)
+install(FILES
+ doc/lua.1
+ doc/luac.1
+ DESTINATION man/man1)
+
+#
+# sub-folders
+#
+ADD_SUBDIRECTORY(src build)
+ADD_SUBDIRECTORY(test)
+
diff --git a/cmake/CustomMacros.cmake b/cmake/CustomMacros.cmake
new file mode 100644
index 0000000..9318ea4
--- /dev/null
+++ b/cmake/CustomMacros.cmake
@@ -0,0 +1,14 @@
+
+macro(add_target_properties _target _name)
+ set(_properties)
+ foreach(_prop ${ARGN})
+ set(_properties "${_properties} ${_prop}")
+ endforeach(_prop)
+ get_target_property(_old_properties ${_target} ${_name})
+ if(NOT _old_properties)
+ # in case it's NOTFOUND
+ set(_old_properties)
+ endif(NOT _old_properties)
+ set_target_properties(${_target} PROPERTIES ${_name} "${_old_properties} ${_properties}")
+endmacro(add_target_properties)
+
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644
index 0000000..19249bb
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -0,0 +1,100 @@
+
+# Lua core source files.
+set(LUA_CORE_SRC
+ lapi.c
+ lauxlib.c
+ lbaselib.c
+ lcode.c
+ ldblib.c
+ ldebug.c
+ ldo.c
+ ldump.c
+ lfunc.c
+ lgc.c
+ linit.c
+ liolib.c
+ llex.c
+ lmathlib.c
+ lmem.c
+ loadlib.c
+ lobject.c
+ lopcodes.c
+ loslib.c
+ lparser.c
+ lstate.c
+ lstring.c
+ lstrlib.c
+ ltable.c
+ ltablib.c
+ ltm.c
+ lundump.c
+ lvm.c
+ lzio.c
+)
+set(LUA_LIB_HEADERS
+ lua.h
+ lualib.h
+ lauxlib.h
+ luaconf.h
+)
+
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_CURRENT_BINARY_DIR})
+
+#
+# Lua library.
+#
+if(BUILD_STATIC)
+ add_library(lua STATIC ${LUA_CORE_SRC})
+ add_target_properties(lua COMPILE_FLAGS "${COMMON_CFLAGS}")
+ add_target_properties(lua LINK_FLAGS "${LD_FLAGS} ${COMMON_LDFLAGS}")
+ set(LUA_STATIC_LIB lua)
+ set(LUA_LIBS lua)
+else(BUILD_STATIC)
+ add_library(lua_static STATIC ${LUA_CORE_SRC})
+ add_target_properties(lua_static COMPILE_FLAGS "${COMMON_CFLAGS}")
+ add_target_properties(lua_static LINK_FLAGS "${LD_FLAGS} ${COMMON_LDFLAGS}")
+ set(LUA_STATIC_LIB lua_static)
+
+ add_library(lua SHARED ${LUA_CORE_SRC})
+ add_target_properties(lua COMPILE_FLAGS "${COMMON_CFLAGS}")
+ add_target_properties(lua LINK_FLAGS "${LD_FLAGS} ${COMMON_LDFLAGS}")
+
+ set(LUA_LIBS lua_static lua)
+endif(BUILD_STATIC)
+set_target_properties(${LUA_LIBS} PROPERTIES
+ VERSION ${LUA_VERSION}
+ SOVERSION ${LUA_SOVERSION}
+ CLEAN_DIRECT_OUTPUT 1
+)
+
+#
+# Lua compiler
+#
+add_executable(luac luac.c print.c)
+add_target_properties(luac COMPILE_FLAGS "${COMMON_CFLAGS}")
+add_target_properties(luac LINK_FLAGS "${LD_FLAGS} ${COMMON_LDFLAGS}")
+target_link_libraries(luac ${LUA_STATIC_LIB})
+
+#
+# Lua stand-alone interpreter
+#
+add_executable(lua.bin lua.c)
+add_target_properties(lua.bin COMPILE_FLAGS "${COMMON_CFLAGS}")
+add_target_properties(lua.bin LINK_FLAGS "${LD_FLAGS} ${COMMON_LDFLAGS}")
+target_link_libraries(lua.bin lua)
+# rename lub.bin to lua
+set_target_properties(lua.bin PROPERTIES OUTPUT_NAME lua)
+
+#
+# install lua/luac & library.
+#
+install(TARGETS luac lua.bin ${LUA_LIBS}
+ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION lib
+ ARCHIVE DESTINATION lib)
+
+install(FILES
+ ${LUA_LIB_HEADERS}
+ DESTINATION include)
+