-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
213 lines (168 loc) · 8.38 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
203
204
205
206
207
208
209
210
211
212
# 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.
# Changed by Vinicius Jarina ([email protected])
cmake_minimum_required(VERSION 3.0)
PROJECT ( lua C )
IF (CMAKE_SIZEOF_VOID_P EQUAL 8)
SET (LIB_SUFFIX "64" CACHE STRING "Suffix of the directory name, e.g. 64 for lib64")
ELSE (CMAKE_SIZEOF_VOID_P EQUAL 8)
SET (LIB_SUFFIX "" CACHE STRING "Suffix of the directory name, e.g. 64 for lib64")
ENDIF (CMAKE_SIZEOF_VOID_P EQUAL 8)
SET (CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
# $ORIGIN support in rpath.
IF (UNIX AND NOT APPLE)
SET (USE_RPATH_ORIGIN TRUE)
SET (CMAKE_INSTALL_RPATH "\$ORIGIN/../lib${LIB_SUFFIX}")
ENDIF ()
IF (APPLE)
SET(SKIP_BUILD_RPATH, TRUE)
SET(CMAKE_MACOSX_RPATH 1)
ADD_DEFINITIONS (-DLUA_USE_MACOSX)
LIST ( APPEND LIBS readline )
ENDIF ()
SET(CMAKE_DEBUG_POSTFIX "d")
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib${LIB_SUFFIX}" CACHE STRING "Library build output directory")
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib${LIB_SUFFIX}")
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin${LIB_SUFFIX}")
SET(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin${LIB_SUFFIX}")
SET (LIB_LUA_VER "54" CACHE STRING "Suffix of version (for library name) e.g lua54")
#
# Include dir COPY
# If the source dir and the binary dir are not equals,
# copy the content of libzond/cinlude to $/include
#
IF(NOT ${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR})
SET(TEMP_INCLUDE_LUA_DIR_FROM "${PROJECT_SOURCE_DIR}/include")
SET(TEMP_INCLUDE_LUA_DIR_TO "${PROJECT_BINARY_DIR}")
MESSAGE(STATUS "Copying include dirs from ${TEMP_INCLUDE_LUA_DIR_FROM} to ${TEMP_INCLUDE_LUA_DIR_TO}")
FILE ( COPY ${TEMP_INCLUDE_LUA_DIR_FROM} DESTINATION ${TEMP_INCLUDE_LUA_DIR_TO})
ENDIF()
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 )
ELSE ()
# Posix systems (incl. Cygwin)
OPTION ( LUA_USE_POSIX "Use POSIX functionality." ON )
OPTION ( LUA_USE_DLOPEN "Use dynamic linker to load modules." ON )
ENDIF ()
IF ( LUA_USE_POSIX )
# On POSIX Lua links to standard math library "m"
LIST ( APPEND LIBS m )
ADD_DEFINITIONS (-DLUA_USE_POSIX)
ENDIF ()
IF ( LUA_USE_DLOPEN )
# Link to dynamic linker library "dl"
LIST ( APPEND LIBS dl )
ENDIF ()
IF ( LUA_WIN )
# Use static linked runtime for DLL to avoid issues with people without the vcredist installed
IF (MSVC)
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE} /MT")
SET(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_DEBUG} /MT")
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
SET(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE} /MT")
SET(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_DEBUG} /MT")
ENDIF()
# Add extra rc files to the windows build
IF ( MSVC OR MINGW )
SET ( LUA_DLL_RC src/lua_dll.rc )
SET ( LUA_RC src/lua.rc )
SET ( LUAC_RC src/luac.rc )
ENDIF ()
ENDIF ()
# Sources and headers
INCLUDE_DIRECTORIES ( include )
SET ( SRC_LIB
src/lapi.c
src/lauxlib.c
src/lbaselib.c
src/lcode.c
src/lcorolib.c
src/lctype.c
src/ldblib.c
src/ldebug.c
src/ldo.c
src/ldump.c
src/lfunc.c
src/lgc.c
src/linit.c
src/liolib.c
src/llex.c
src/lmathlib.c
src/lmem.c
src/loadlib.c
src/lobject.c
src/lopcodes.c
src/loslib.c
src/lparser.c
src/lstate.c
src/lstring.c
src/lstrlib.c
src/ltable.c
src/ltablib.c
src/ltm.c
src/lundump.c
src/lutf8lib.c
src/lvm.c
src/lzio.c
)
SET ( SRC_LUA src/lua.c )
SET ( SRC_LUAC src/luac.c )
## BUILD
# Create dynamic library (dll, so)
ADD_LIBRARY ( liblua SHARED ${SRC_LIB} ${LUA_DLL_RC})
TARGET_LINK_LIBRARIES ( liblua ${LIBS} )
SET_TARGET_PROPERTIES ( liblua PROPERTIES OUTPUT_NAME lua${LIB_LUA_VER} CLEAN_DIRECT_OUTPUT 1 )
if ( LUA_WIN )
SET_TARGET_PROPERTIES ( liblua PROPERTIES COMPILE_FLAGS -DLUA_BUILD_AS_DLL)
endif ( LUA_WIN )
SET_TARGET_PROPERTIES( liblua PROPERTIES ARCHIVE_OUTPUT_DIRECTORY_MINSIZEREL ${PROJECT_BINARY_DIR}/lib${LIB_SUFFIX} )
SET_TARGET_PROPERTIES( liblua PROPERTIES LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL ${PROJECT_BINARY_DIR}/lib${LIB_SUFFIX} )
SET_TARGET_PROPERTIES( liblua PROPERTIES RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${PROJECT_BINARY_DIR}/bin${LIB_SUFFIX} )
SET_TARGET_PROPERTIES( liblua PROPERTIES ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${PROJECT_BINARY_DIR}/lib${LIB_SUFFIX} )
SET_TARGET_PROPERTIES( liblua PROPERTIES LIBRARY_OUTPUT_DIRECTORY_RELEASE ${PROJECT_BINARY_DIR}/lib${LIB_SUFFIX} )
SET_TARGET_PROPERTIES( liblua PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PROJECT_BINARY_DIR}/bin${LIB_SUFFIX} )
SET_TARGET_PROPERTIES( liblua PROPERTIES ARCHIVE_OUTPUT_DIRECTORY_RELWITHDEBINFO ${PROJECT_BINARY_DIR}/lib${LIB_SUFFIX} )
SET_TARGET_PROPERTIES( liblua PROPERTIES LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO ${PROJECT_BINARY_DIR}/lib${LIB_SUFFIX} )
SET_TARGET_PROPERTIES( liblua PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${PROJECT_BINARY_DIR}/bin${LIB_SUFFIX} )
SET_TARGET_PROPERTIES( liblua PROPERTIES ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${PROJECT_BINARY_DIR}/lib${LIB_SUFFIX} )
SET_TARGET_PROPERTIES( liblua PROPERTIES LIBRARY_OUTPUT_DIRECTORY_DEBUG ${PROJECT_BINARY_DIR}/lib${LIB_SUFFIX} )
SET_TARGET_PROPERTIES( liblua PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PROJECT_BINARY_DIR}/bin${LIB_SUFFIX} )
# Create static library, this is needed to compile luac in the 5.1.x, 5.2 Lua series
ADD_LIBRARY ( liblua_static STATIC ${SRC_LIB} )
TARGET_LINK_LIBRARIES ( liblua_static ${LIBS} )
SET_TARGET_PROPERTIES ( liblua_static PROPERTIES OUTPUT_NAME lua${LIB_LUA_VER}_static CLEAN_DIRECT_OUTPUT 1 )
SET_TARGET_PROPERTIES( liblua_static PROPERTIES ARCHIVE_OUTPUT_DIRECTORY_MINSIZEREL ${PROJECT_BINARY_DIR}/lib${LIB_SUFFIX} )
SET_TARGET_PROPERTIES( liblua_static PROPERTIES LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL ${PROJECT_BINARY_DIR}/lib${LIB_SUFFIX} )
SET_TARGET_PROPERTIES( liblua_static PROPERTIES ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${PROJECT_BINARY_DIR}/lib${LIB_SUFFIX} )
SET_TARGET_PROPERTIES( liblua_static PROPERTIES LIBRARY_OUTPUT_DIRECTORY_RELEASE ${PROJECT_BINARY_DIR}/lib${LIB_SUFFIX} )
SET_TARGET_PROPERTIES( liblua_static PROPERTIES ARCHIVE_OUTPUT_DIRECTORY_RELWITHDEBINFO ${PROJECT_BINARY_DIR}/lib${LIB_SUFFIX} )
SET_TARGET_PROPERTIES( liblua_static PROPERTIES LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO ${PROJECT_BINARY_DIR}/lib${LIB_SUFFIX} )
SET_TARGET_PROPERTIES( liblua_static PROPERTIES ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${PROJECT_BINARY_DIR}/lib${LIB_SUFFIX} )
SET_TARGET_PROPERTIES( liblua_static PROPERTIES LIBRARY_OUTPUT_DIRECTORY_DEBUG ${PROJECT_BINARY_DIR}/lib${LIB_SUFFIX} )
ADD_EXECUTABLE ( lua ${SRC_LUA} ${LUA_RC})
TARGET_LINK_LIBRARIES ( lua liblua ${LIBS})
SET_TARGET_PROPERTIES ( lua PROPERTIES DEBUG_POSTFIX d)
SET_TARGET_PROPERTIES ( lua PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PROJECT_BINARY_DIR}/bin${LIB_SUFFIX} )
SET_TARGET_PROPERTIES ( lua PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${PROJECT_BINARY_DIR}/bin${LIB_SUFFIX} )
SET_TARGET_PROPERTIES ( lua PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PROJECT_BINARY_DIR}/bin${LIB_SUFFIX} )
SET_TARGET_PROPERTIES ( lua PROPERTIES RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${PROJECT_BINARY_DIR}/bin${LIB_SUFFIX} )
ADD_EXECUTABLE ( luac ${SRC_LUAC} ${LUAC_RC} )
TARGET_LINK_LIBRARIES ( luac liblua_static )
SET_TARGET_PROPERTIES ( luac PROPERTIES DEBUG_POSTFIX d)
SET_TARGET_PROPERTIES ( luac PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PROJECT_BINARY_DIR}/bin${LIB_SUFFIX} )
SET_TARGET_PROPERTIES ( luac PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${PROJECT_BINARY_DIR}/bin${LIB_SUFFIX} )
SET_TARGET_PROPERTIES ( luac PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PROJECT_BINARY_DIR}/bin${LIB_SUFFIX} )
SET_TARGET_PROPERTIES ( luac PROPERTIES RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${PROJECT_BINARY_DIR}/bin${LIB_SUFFIX} )
ENABLE_TESTING()
SET(TEST_PARAM -e _U=true)
ADD_TEST(NAME test_all
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/test
COMMAND lua ${TEST_PARAM} ${PROJECT_SOURCE_DIR}/test/all.lua)