summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorPeter Drahos <drahosp@gmail.com>2011-03-15 19:44:40 +0100
committerPeter Drahos <drahosp@gmail.com>2011-03-15 19:44:40 +0100
commite654d5428a2c5d978b0ba50ce8c512e2fc3c3cd4 (patch)
treee845224fafcbf94d7e84f2f3e4e09004ffcc38b9 /CMakeLists.txt
parent923d1e34568df985ff7613891a0231541a0b92c8 (diff)
downloadlua-e654d5428a2c5d978b0ba50ce8c512e2fc3c3cd4.tar.gz
Updated build, tested on OSX.
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt219
1 files changed, 155 insertions, 64 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d19f9f6..9abe112 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,68 +1,159 @@
-# Copyright (C) 2007-2009 LuaDist.
-# Created by Peter Drahoš and Peter Kapec
+# Copyright (C) 2007-2011 LuaDist.
+# Created by Peter Drahoš, Peter Kapec
# Redistribution and use of this file is allowed according to the terms of the MIT license.
# For details see the COPYRIGHT file distributed with LuaDist.
# Please note that the package source code is licensed under its own license.
-PROJECT ( lua C )
-CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-INCLUDE(dist.cmake )
-
-# Determine install host
-IF ( WIN32 AND NOT CYGWIN)
- ADD_DEFINITIONS ( -DLUA_BUILD_AS_DLL )
- IF(MSVC)
- ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE )
- SET(DEF_FILE src/lua.def)
- SET(DLL_RC_FILE src/lua_dll.rc)
- SET(LUA_RC_FILE src/lua.rc)
- SET(LUAC_RC_FILE src/lua_simple.rc)
- ENDIF()
-ELSE ( )
- ADD_DEFINITIONS ( -DLUA_USE_POSIX -DLUA_USE_DLOPEN )
- SET ( LIBS m dl )
-ENDIF ( )
-
-# Add Readline support when available
-FIND_PATH(READLINE_INCLUDE_DIR readline/readline.h)
-FIND_LIBRARY(READLINE_LIBRARY NAMES readline)
-IF ( READLINE_LIBRARY )
- INCLUDE_DIRECTORIES ( ${READLINE_INCLUDE_DIR} )
- ADD_DEFINITIONS ( -DLUA_USE_READLINE )
- SET ( LIBS ${LIBS} ${READLINE_LIBRARY} )
-ENDIF ( )
-
-# Add Curses support when available
-INCLUDE(FindCurses)
-IF ( CURSES_LIBRARY )
- INCLUDE_DIRECTORIES ( ${CURSES_INCLUDE_DIR} )
- SET ( LIBS ${LIBS} ${CURSES_LIBRARY} )
-ENDIF ( )
-
-# Build Libraries
-SET ( SRC_LIBLUA src/lapi.c src/lcode.c src/ldebug.c src/ldo.c src/ldump.c src/lfunc.c src/lgc.c src/llex.c src/lmem.c src/lobject.c src/lopcodes.c src/lparser.c src/lstate.c src/lstring.c src/ltable.c src/ltm.c src/lundump.c src/lvm.c src/lzio.c src/lauxlib.c src/lbaselib.c src/ldblib.c src/liolib.c src/lmathlib.c src/loslib.c src/ltablib.c src/lstrlib.c src/loadlib.c src/linit.c )
-
-ADD_LIBRARY ( liblua SHARED ${SRC_LIBLUA} ${DEF_FILE} ${DLL_RC_FILE})
-TARGET_LINK_LIBRARIES ( liblua ${LIBS})
-SET_TARGET_PROPERTIES ( liblua PROPERTIES OUTPUT_NAME lua51 CLEAN_DIRECT_OUTPUT 1 )
-
-ADD_LIBRARY ( liblua_static ${SRC_LIBLUA} )
-TARGET_LINK_LIBRARIES ( liblua_static ${LIBS})
-
-INCLUDE_DIRECTORIES ( src )
-
-# Build Executables
-SET ( SRC_LUA src/lua.c )
-SET ( SRC_LUAC src/luac.c src/print.c )
-
-ADD_EXECUTABLE ( lua ${SRC_LUA} ${LUA_RC_FILE})
-ADD_EXECUTABLE ( luac ${SRC_LUAC} ${LUAC_RC_FILE})
-TARGET_LINK_LIBRARIES ( lua liblua )
-TARGET_LINK_LIBRARIES ( luac liblua_static )
-
-# Install
-INSTALL ( TARGETS lua luac liblua RUNTIME DESTINATION ${INSTALL_BIN} LIBRARY DESTINATION ${INSTALL_LIB} ARCHIVE DESTINATION ${INSTALL_LIB})
-INSTALL ( FILES src/lua.h src/luaconf.h src/lualib.h src/lauxlib.h etc/lua.hpp DESTINATION ${INSTALL_INC} )
-INSTALL ( FILES etc/strict.lua DESTINATION ${INSTALL_LMOD} )
-INSTALL ( DIRECTORY doc etc test DESTINATION ${INSTALL_DATA} PATTERN ".git" EXCLUDE )
-INSTALL ( FILES README COPYRIGHT HISTORY DESTINATION ${INSTALL_DATA} )
+project ( lua C )
+cmake_minimum_required ( VERSION 2.6 )
+include ( dist.cmake )
+
+## CONFIGURATION
+# Default configuration (we assume POSIX by default)
+set ( LUA_PATH "LUA_PATH" CACHE STRING "Environment variable to use as package.path." )
+set ( LUA_CPATH "LUA_CPATH" CACHE STRING "Environment variable to use as package.cpath." )
+set ( LUA_INIT "LUA_INIT" CACHE STRING "Environment variable for initial script." )
+
+option ( LUA_ANSI "Use only ansi features." OFF )
+option ( LUA_USE_RELATIVE_LOADLIB "Use modified loadlib.c with support for relative paths on posix systems." ON)
+set ( LUA_IDSIZE 60 CACHE NUMBER "gives the maximum size for the description of the source." )
+set ( LUA_PROMPT "> " CACHE STRING "Is the default prompt used by stand-alone Lua." )
+set ( LUA_PROMPT2 ">> " CACHE STRING "Is the default continuation prompt used by stand-alone Lua." )
+set ( LUA_MAXINPUT 512 CACHE NUMBER "Is the maximum length for an input line in the stand-alone interpreter.")
+
+#2DO: LUAI_* and LUAL_* settings, for now defaults are used.
+
+if ( WIN32 AND NOT CYGWIN )
+ # Windows systems
+ option ( LUA_WIN "Windows specific build." ON )
+ option ( LUA_BUILD_AS_DLL "Build Lua library as Dll." ON )
+ # Paths
+ set ( LUA_DIRSEP "\\" )
+ set ( LUA_LDIR "!\\lua\\" CACHE STRING "Pure Lua module location." )
+ set ( LUA_CDIR "!\\" CACHE STRING "Binary Lua module location." )
+ set ( LUA_PATH_DEFAULT ".\\?.lua;${LUA_LDIR}?.lua;${LUA_LDIR}?\\init.lua;${LUA_CDIR}?.lua;${LUA_CDIR}?\\init.lua" )
+ set ( LUA_CPATH_DEFAULT ".\\?${CMAKE_SHARED_MODULE_SUFFIX};${LUA_CDIR}?${CMAKE_SHARED_MODULE_SUFFIX};${LUA_CDIR}loadall${CMAKE_SHARED_MODULE_SUFFIX}" )
+else ()
+ # Posix systems
+ option ( LUA_USE_POSIX "Use POSIX functionality." ON )
+ option ( LUA_USE_DLOPEN "Use dynamic linker to load modules." ON )
+ option ( LUA_USE_MKSTEMP "Use mkstep." ON )
+ option ( LUA_USE_ISATTY "Use tty." ON )
+ option ( LUA_USE_POPEN "Use popen." ON )
+ option ( LUA_USE_ULONGJMP "Use ulongjmp" ON)
+ # Paths
+ set ( LUA_DIRSEP "/" )
+ set ( LUA_LDIR "/usr/local/share/lua/5.1/" CACHE STRING "Pure Lua module location." )
+ set ( LUA_CDIR "/usr/local/lib/lua/5.1/" CACHE STRING "Binary Lua module location." )
+ set ( LUA_PATH_DEFAULT "./?.lua;${LUA_LDIR}?.lua;${LUA_LDIR}?/init.lua;${LUA_CDIR}?.lua;${LUA_CDIR}?/init.lua" )
+ set ( LUA_CPATH_DEFAULT "./?${CMAKE_SHARED_MODULE_SUFFIX};${LUA_CDIR}?${CMAKE_SHARED_MODULE_SUFFIX};${LUA_CDIR}loadall${CMAKE_SHARED_MODULE_SUFFIX}" )
+endif ()
+
+## SETUP
+# Optional libraries
+find_package ( Readline )
+if ( READLINE_FOUND )
+ option ( LUA_USE_READLINE "Use readline in the Lua CLI." ON )
+endif ()
+
+find_package ( Curses )
+if ( CURSES_FOUND )
+ option ( LUA_USE_CURSES "Use curses in the Lua CLI." ON )
+endif ()
+
+# Setup needed variables and libraries
+if ( LUA_USE_POSIX )
+ # On POSIX Lua links to standard math library "m"
+ list ( APPEND LIBS m )
+endif ()
+
+if ( LUA_USE_DLOPEN )
+ # Link to dynamic linker library "dl"
+ list ( APPEND LIBS dl )
+endif ()
+
+if ( LUA_WIN )
+ ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE )
+ # Add extra rc files to the windows build
+ if ( MSVC OR MINGW )
+ set ( LUA_DEF src/lua.def )
+ set ( LUA_DLL_RC src/lua_dll.rc )
+ set ( LUA_RC src/lua.rc )
+ set ( LUAC_RC src/lua_simple.rc )
+ endif ()
+endif ()
+
+if ( LUA_USE_READLINE )
+ # Add readline
+ include_directories ( ${READLINE_INCLUDE_DIR} )
+ list ( APPEND LIBS ${READLINE_LIBRARY} )
+endif ()
+
+if ( LUA_USE_CURSES )
+ # Add curses
+ include_directories ( ${CURSES_INCLUDE_DIR} )
+ list ( APPEND LIBS ${CURSES_LIBRARY} )
+endif ()
+
+## SOURCES
+# Generate luaconf.h
+configure_file ( src/luaconf.h.in ${CMAKE_CURRENT_BINARY_DIR}/luaconf.h )
+
+# Sources and headers
+include_directories ( src ${CMAKE_CURRENT_BINARY_DIR} )
+set ( SRC_LIB src/lapi.c src/lcode.c src/ldebug.c src/ldo.c src/ldump.c src/lfunc.c src/lgc.c src/llex.c src/lmem.c src/lobject.c src/lopcodes.c src/lparser.c src/lstate.c src/lstring.c src/ltable.c src/ltm.c src/lundump.c src/lvm.c src/lzio.c src/lauxlib.c src/lbaselib.c src/ldblib.c src/liolib.c src/lmathlib.c src/loslib.c src/ltablib.c src/lstrlib.c src/linit.c )
+set ( SRC_LUA src/lua.c )
+set ( SRC_LUAC src/luac.c src/print.c )
+
+if ( LUA_USE_RELATIVE_LOADLIB )
+ # Use modified loadlib
+ list ( APPEND SRC_LIB src/loadlib_rel.c )
+else ()
+ list ( APPEND SRC_LIB src/loadlib.c )
+endif ()
+
+## BUILD
+# Create dynamic library
+add_library ( liblua SHARED ${SRC_LIB} ${LUA_DLL_RC} ${LUA_DEF} )
+target_link_libraries ( liblua ${LIBS} )
+set_target_properties ( liblua PROPERTIES OUTPUT_NAME lua51 CLEAN_DIRECT_OUTPUT 1 )
+
+# Create static library, this is needed to compile luac in the 5.1.x Lua series
+add_library ( liblua_static STATIC ${SRC_LIB} )
+target_link_libraries ( liblua_static ${LIBS} )
+
+add_executable ( lua ${SRC_LUA} ${LUA_RC} )
+target_link_libraries ( lua liblua )
+
+add_executable ( luac ${SRC_LUAC} ${LUAC_RC} )
+target_link_libraries ( luac liblua_static )
+
+## INSTALL
+install ( TARGETS lua luac liblua RUNTIME DESTINATION ${INSTALL_BIN} LIBRARY DESTINATION ${INSTALL_LIB} ARCHIVE DESTINATION ${INSTALL_LIB} )
+install ( FILES src/lua.h src/lualib.h src/lauxlib.h etc/lua.hpp ${CMAKE_CURRENT_BINARY_DIR}/luaconf.h DESTINATION ${INSTALL_INC} )
+install ( FILES etc/strict.lua DESTINATION ${INSTALL_LMOD} )
+install ( DIRECTORY doc etc test DESTINATION ${INSTALL_DATA} )
+install ( FILES README COPYRIGHT HISTORY DESTINATION ${INSTALL_DATA} )
+
+## TESTS
+add_lua_test ( test/bisect.lua )
+add_lua_test ( test/cf.lua )
+add_lua_test ( test/echo.lua )
+add_lua_test ( test/env.lua )
+add_lua_test ( test/factorial.lua )
+add_lua_test ( test/fib.lua )
+add_lua_test ( test/fibfor.lua )
+#add_lua_test ( test/globals.lua ) # Requires input
+add_lua_test ( test/hello.lua )
+add_lua_test ( test/life.lua )
+#add_lua_test ( test/luac.lua ) # Requires input
+add_lua_test ( test/printf.lua )
+#add_lua_test ( test/readonly.lua ) # this is aimed to fail, modification is required
+add_lua_test ( test/sieve.lua )
+add_lua_test ( test/sort.lua )
+#add_lua_test ( test/table.lua ) # Requires input
+add_lua_test ( test/trace-calls.lua )
+add_lua_test ( test/trace-globals.lua )
+#add_lua_test ( test/xd.lua ) # Requires input
+
+