forked from LuaDist/luajit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
202 lines (169 loc) · 7.12 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# Copyright (C) 2007-2012 LuaDist.
# Created by Peter Drahoš
# 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 ( luajit C ASM)
cmake_minimum_required ( VERSION 2.8 )
include ( cmake/dist.cmake )
include ( lua )
## 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.")
# LuaJIT specific
option ( LUAJIT_DISABLE_FFI "Disable FFI." OFF )
option ( LUAJIT_ENABLE_LUA52COMPAT "Enable Lua 5.2 compatibility." ON )
option ( LUAJIT_DISABLE_JIT "Disable JIT." OFF )
option ( LUAJIT_CPU_SSE2 "Disable SSE2." OFF )
option ( LUAJIT_CPU_NOCMOV "Disable NOCMOV." OFF )
#2DO: LUAI_* and LUAL_* settings, for now defaults are used.
set ( LUA_DIRSEP "/" )
set ( LUA_MODULE_SUFFIX ${CMAKE_SHARED_MODULE_SUFFIX} )
set ( LUA_LDIR ${INSTALL_LMOD} )
set ( LUA_CDIR ${INSTALL_CMOD} )
if ( LUA_USE_RELATIVE_LOADLIB )
# This will set up relative paths to lib
string ( REGEX REPLACE "[^!/]+" ".." LUA_DIR "!/${INSTALL_BIN}/" )
else ()
# Direct path to installation
set ( LUA_DIR ${CMAKE_INSTALL_PREFIX} CACHE STRING "Destination from which modules will be resolved. See INSTALL_LMOD and INSTALL_CMOD.")
endif ()
set ( LUA_PATH_DEFAULT "./?.lua;${LUA_DIR}${LUA_LDIR}/?.lua;${LUA_DIR}${LUA_LDIR}/?/init.lua;./?/init.lua" )
set ( LUA_CPATH_DEFAULT "./?${LUA_MODULE_SUFFIX};${LUA_DIR}${LUA_CDIR}/?${LUA_MODULE_SUFFIX};${LUA_DIR}${LUA_CDIR}/loadall${LUA_MODULE_SUFFIX}" )
if ( WIN32 AND NOT CYGWIN )
# Windows systems
add_definitions ( -DLUA_BUILD_AS_DLL -DLUAJIT_OS=LUAJIT_OS_WINDOWS)
option ( LUA_BUILD_WLUA "Build wluajit interpreter for no-console applications." ON )
set ( LJVM_MODE coffasm )
# Paths (Double escapes needed)
set ( LUA_DIRSEP "\\\\" )
string ( REPLACE "/" ${LUA_DIRSEP} LUA_DIR "${LUA_DIR}" )
string ( REPLACE "/" ${LUA_DIRSEP} LUA_LDIR "${LUA_LDIR}" )
string ( REPLACE "/" ${LUA_DIRSEP} LUA_CDIR "${LUA_CDIR}" )
string ( REPLACE "/" ${LUA_DIRSEP} LUA_PATH_DEFAULT "${LUA_PATH_DEFAULT}" )
string ( REPLACE "/" ${LUA_DIRSEP} LUA_CPATH_DEFAULT "${LUA_CPATH_DEFAULT}" )
elseif ( APPLE )
set ( CMAKE_EXE_LINKER_FLAGS "-pagezero_size 10000 -image_base 100000000" )
option ( LUA_USE_POSIX "Use POSIX functionality." ON )
option ( LUA_USE_DLOPEN "Use dynamic linker to load modules." ON )
set ( LJVM_MODE machasm )
else ()
option ( LUA_USE_POSIX "Use POSIX functionality." ON )
option ( LUA_USE_DLOPEN "Use dynamic linker to load modules." ON )
set ( LJVM_MODE elfasm )
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_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 )
file ( GLOB SRC_LIB src/lib_*.c )
if ( LUA_USE_RELATIVE_LOADLIB )
list ( REMOVE_ITEM SRC_LIB ${CMAKE_CURRENT_SOURCE_DIR}/src/lib_package.c )
else ()
list ( REMOVE_ITEM SRC_LIB ${CMAKE_CURRENT_SOURCE_DIR}/src/lib_package_rel.c )
endif ()
## GENERATE VM
# Build minilua
add_executable ( minilua src/host/minilua.c )
target_link_libraries ( minilua ${LIBS} )
# Dynasm
set ( DASM ${CMAKE_CURRENT_SOURCE_DIR}/dynasm/dynasm.lua )
set ( DASM_T ${CMAKE_CURRENT_SOURCE_DIR}/src/host/buildvm_arch.h )
set ( DASM_FLAGS "" )
set ( DASM_ARCH "x86" )
set ( DASM_DASC ${CMAKE_CURRENT_SOURCE_DIR}/src/vm_${DASM_ARCH}.dasc )
# Generate buildvm arch header
add_custom_command(OUTPUT ${DASM_T}
COMMAND minilua ${DASM} ${DASM_FLAGS} -o ${DASM_T} ${DASM_DASC}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dynasm
DEPENDS minilua
)
# Buildvm
file ( GLOB SRC_BUILDVM src/host/buildvm*.c )
add_executable ( buildvm ${SRC_BUILDVM} ${DASM_T} )
macro(add_buildvm_target _target _mode)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_target}
COMMAND buildvm ARGS -m ${_mode} -o ${CMAKE_CURRENT_BINARY_DIR}/${_target} ${ARGN}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS buildvm ${ARGN}
)
endmacro(add_buildvm_target)
if (MSVC)
add_buildvm_target ( lj_vm.obj peobj )
set (LJ_VM_SRC ${CMAKE_CURRENT_BINARY_DIR}/lj_vm.obj)
else ()
add_buildvm_target ( lj_vm.s ${LJVM_MODE} )
set (LJ_VM_SRC ${CMAKE_CURRENT_BINARY_DIR}/lj_vm.s)
endif ()
add_buildvm_target ( lj_ffdef.h ffdef ${SRC_LIB} )
add_buildvm_target ( lj_bcdef.h bcdef ${SRC_LIB} )
add_buildvm_target ( lj_folddef.h folddef src/lj_opt_fold.c )
add_buildvm_target ( lj_recdef.h recdef ${SRC_LIB} )
add_buildvm_target ( lj_libdef.h libdef ${SRC_LIB} )
add_buildvm_target ( jit/vmdef.lua libvm ${SRC_LIB} )
SET(DEPS
${LJ_VM_SRC}
${CMAKE_CURRENT_BINARY_DIR}/lj_ffdef.h
${CMAKE_CURRENT_BINARY_DIR}/lj_bcdef.h
${CMAKE_CURRENT_BINARY_DIR}/lj_libdef.h
${CMAKE_CURRENT_BINARY_DIR}/lj_recdef.h
${CMAKE_CURRENT_BINARY_DIR}/lj_folddef.h
)
## LuaJIT Library
include_directories ( ${CMAKE_CURRENT_BINARY_DIR} dynasm src src/host )
file ( GLOB SRC_JIT src/lj_*.c )
add_library ( liblua SHARED ${SRC_JIT} ${SRC_LIB} ${DEPS} )
target_link_libraries ( liblua ${LIBS} )
set_target_properties ( liblua PROPERTIES OUTPUT_NAME lua CLEAN_DIRECT_OUTPUT 1 )
## LuaJIT Executable
add_executable ( luajit src/luajit.c src/luajit.rc )
target_link_libraries ( luajit liblua )
# On Windows build a no-console variant also
if(LUA_BUILD_WLUA)
add_executable ( wluajit WIN32 src/wmain.c src/luajit.c src/luajit.rc )
target_link_libraries ( wluajit liblua )
install_executable ( wluajit )
endif()
## INSTALL
install_executable( luajit )
install_library( liblua )
install_header( src/lua.h src/luajit.h src/lua.hpp ${CMAKE_CURRENT_BINARY_DIR}/luaconf.h src/lualib.h src/lauxlib.h )
install_doc ( doc/ )
install_foo ( etc/ )
install_data ( COPYRIGHT README.md )