1+ cmake_minimum_required (VERSION 3.22 )
12
2- set (AX_LUA_VERSION "5.4.6" )
3+ set (_LUA_VERSION "5.4.8" )
4+ set (lib_name plainlua)
35
46set (LUA_SRC_PATH ${CMAKE_CURRENT_LIST_DIR} )
57
6- set (lib_name plainlua)
7- set (target_name ${lib_name} )
8-
98project (${lib_name} )
109
1110aux_source_directory (${LUA_SRC_PATH} LUA_CORE )
1211list (REMOVE_ITEM LUA_CORE ${LUA_SRC_PATH} /lua.c ${LUA_SRC_PATH} /luac.c)
1312
1413set (LUA_BUILD_AS_DLL ${BUILD_SHARED_LIBS} )
1514
15+ # generate additional exports .def file
16+ set (_export_symbols "; Export additional symbols for build luac.exe" )
17+ string (APPEND _export_symbols "\n EXPORTS" )
18+ if (${_LUA_VERSION} VERSION_GREATER_EQUAL "5.4.0" )
19+ string (APPEND _export_symbols "\n luaG_getfuncline" )
20+ if (${_LUA_VERSION} VERSION_GREATER_EQUAL "5.5.0" )
21+ string (APPEND _export_symbols "\n luaH_getstr" )
22+ string (APPEND _export_symbols "\n luaH_set" )
23+ string (APPEND _export_symbols "\n luaH_new" )
24+ endif ()
25+ elseif (${_LUA_VERSION} VERSION_GREATER_EQUAL "5.3.0" )
26+ string (APPEND _export_symbols "\n " )
27+ elseif (${_LUA_VERSION} VERSION_GREATER_EQUAL "5.1.0" )
28+ string (APPEND _export_symbols "\n luaU_header" )
29+ if (${_LUA_VERSION} VERSION_LESS "5.2.0" )
30+ string (APPEND _export_symbols "\n luaM_realloc_" )
31+ string (APPEND _export_symbols "\n luaM_toobig" )
32+ string (APPEND _export_symbols "\n luaD_growstack" )
33+ string (APPEND _export_symbols "\n luaS_newlstr" )
34+ string (APPEND _export_symbols "\n luaU_print" )
35+ string (APPEND _export_symbols "\n luaF_newproto" )
36+ endif ()
37+ else ()
38+ message (FATAL_ERROR "Unsupported Lua version: ${_LUA_VERSION} . Please use Lua 5.1.0 or later." )
39+ endif ()
40+
41+ write_file ("${LUA_SRC_PATH} /plainlua.def" "${_export_symbols} " )
42+
1643if (WIN32 )
1744 set (LUA_BUILD_AS_DLL TRUE )
18- add_library (${target_name} SHARED ${LUA_CORE} ${LUA_SRC_PATH} /plainlua.def )
19- # if(WINRT)
20- # target_link_libraries(${target_name} PRIVATE runtimeobject)
21- # endif()
45+ add_library (${lib_name} SHARED ${LUA_CORE} ${LUA_SRC_PATH} /plainlua.def )
2246else ()
2347 if (BUILD_SHARED_LIBS AND NOT WINRT)
2448 set (LUA_BUILD_AS_DLL FALSE )
25- add_library (${target_name } SHARED ${LUA_CORE} ${LUA_SRC_PATH} /plainlua.def )
49+ add_library (${lib_name } SHARED ${LUA_CORE} ${LUA_SRC_PATH} /plainlua.def )
2650 else ()
27- add_library (${target_name } ${LUA_CORE} )
51+ add_library (${lib_name } ${LUA_CORE} )
2852 endif ()
2953endif ()
3054
31- target_compile_definitions (${target_name }
55+ target_compile_definitions (${lib_name }
3256 PRIVATE _CRT_SECURE_NO_WARNINGS
3357 PRIVATE _WINSOCK_DEPRECATED_NO_WARNINGS
34- )
58+ )
3559
3660if (IOS )
37- target_compile_definitions (${target_name } PUBLIC LUA_USE_IOS=1 )
61+ target_compile_definitions (${lib_name } PUBLIC LUA_USE_IOS=1 )
3862endif ()
3963
40- if (${AX_LUA_VERSION } VERSION_GREATER_EQUAL "5.4.0" ) # !important: traditional lua bindings solution tolua++ not support yet
41- target_compile_definitions (${target_name }
42- PUBLIC LUA_COMPAT_APIINTCASTS=1
43- PUBLIC LUA_COMPAT_MATHLIB=1
64+ if (${_LUA_VERSION } VERSION_GREATER_EQUAL "5.4.0" ) # !important: traditional lua bindings solution tolua++ not support yet
65+ target_compile_definitions (${lib_name }
66+ PUBLIC LUA_COMPAT_APIINTCASTS=1
67+ PUBLIC LUA_COMPAT_MATHLIB=1
4468 )
45- elseif (${AX_LUA_VERSION} VERSION_GREATER_EQUAL "5.3.0" )
46- target_compile_definitions (${target_name}
47- PUBLIC LUA_COMPAT_5_1=1
48- PUBLIC LUA_COMPAT_5_2=1
49- PUBLIC LUA_COMPAT_MODULE=1
69+ elseif (${_LUA_VERSION} VERSION_GREATER_EQUAL "5.3.0" )
70+ target_compile_definitions (${lib_name}
71+ PUBLIC LUA_COMPAT_5_1=1
72+ PUBLIC LUA_COMPAT_5_2=1
5073 )
51- elseif (${AX_LUA_VERSION} VERSION_GREATER_EQUAL "5.2.0" )
52- target_compile_definitions (${target_name}
53- PUBLIC LUA_COMPAT_ALL=1
54- PUBLIC LUA_COMPAT_MODULE=1
74+ elseif (${_LUA_VERSION} VERSION_GREATER_EQUAL "5.2.0" )
75+ target_compile_definitions (${lib_name}
76+ PUBLIC LUA_COMPAT_ALL=1
5577 )
5678endif ()
5779
5880if (LUA_BUILD_AS_DLL)
59- target_compile_definitions (${target_name } PUBLIC LUA_BUILD_AS_DLL=1 )
81+ target_compile_definitions (${lib_name } PUBLIC LUA_BUILD_AS_DLL=1 )
6082endif ()
6183
62- set_target_properties (${target_name } PROPERTIES
63- INTERFACE_INCLUDE_DIRECTORIES "${LUA_SRC_PATH} "
84+ set_target_properties (${lib_name } PROPERTIES
85+ INTERFACE_INCLUDE_DIRECTORIES "${LUA_SRC_PATH} "
6486)
6587
66- set_target_properties (${target_name }
88+ set_target_properties (${lib_name }
6789 PROPERTIES
6890 ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR} /lib"
6991 LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR} /lib"
@@ -72,36 +94,30 @@ set_target_properties(${target_name}
7294)
7395
7496if (WIN32 OR MACOSX)
75-
76- function (add_lua_bin target_name src_files )
77- add_executable (${target_name} ${src_files} )
78- if (${AX_LUA_VERSION} VERSION_GREATER_EQUAL "5.4.0" ) # !important: traditional lua bindings solution tolua++ not support yet
79- target_compile_definitions (${target_name} PUBLIC LUA_COMPAT_APIINTCASTS=1 )
80- elseif (${AX_LUA_VERSION} VERSION_GREATER_EQUAL "5.3.0" )
81- target_compile_definitions (${target_name}
82- PUBLIC LUA_COMPAT_5_1=1
83- PUBLIC LUA_COMPAT_5_2=1
84- )
85- elseif (${AX_LUA_VERSION} VERSION_GREATER_EQUAL "5.2.0" )
86- target_compile_definitions (${target_name} PUBLIC LUA_COMPAT_ALL=1 )
87- endif ()
88-
89- target_link_libraries (${target_name} plainlua )
97+ function (add_lua_bin target_name src_files )
98+ add_executable (${target_name} ${src_files} )
9099
91- set_target_properties (${target_name}
92- PROPERTIES
93- ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR} /lib"
94- LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR} /lib"
95- RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR} /bin"
96- FOLDER "Tools"
97- )
98- endfunction ()
100+ target_compile_definitions (${target_name}
101+ PRIVATE _CRT_SECURE_NO_WARNINGS
102+ PRIVATE _WINSOCK_DEPRECATED_NO_WARNINGS
103+ )
104+
105+ target_link_libraries (${target_name} ${lib_name} )
106+
107+ set_target_properties (${target_name}
108+ PROPERTIES
109+ ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR} /lib"
110+ LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR} /lib"
111+ RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR} /bin"
112+ FOLDER "Tools"
113+ )
114+ endfunction ()
99115
100- # tool:luac the lua bytecode compiler
101- add_lua_bin (luac "${LUA_SRC_PATH} /luac.c;${LUA_SRC_PATH} /ldump.c;${LUA_SRC_PATH} /lopcodes.c" )
116+ # tool:luac the lua bytecode compiler
117+ add_lua_bin (luac "${LUA_SRC_PATH} /luac.c;${LUA_SRC_PATH} /ldump.c;${LUA_SRC_PATH} /lopcodes.c" )
102118
103- # tool:lua the lua interpreter
104- add_lua_bin (lua "${LUA_SRC_PATH} /lua.c" )
119+ # tool:lua the lua interpreter
120+ add_lua_bin (lua "${LUA_SRC_PATH} /lua.c" )
105121elseif (LINUX )
106- target_compile_definitions (${target_name } PUBLIC LUA_USE_LINUX=1 )
122+ target_compile_definitions (${lib_name } PUBLIC LUA_USE_LINUX=1 )
107123endif ()
0 commit comments