Skip to content

Commit 9e33c23

Browse files
committed
initial commit
0 parents  commit 9e33c23

File tree

8 files changed

+241
-0
lines changed

8 files changed

+241
-0
lines changed

.gitignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
CMakeLists.txt.user
2+
CMakeCache.txt
3+
CMakeFiles
4+
CMakeScripts
5+
Testing
6+
Makefile
7+
cmake_install.cmake
8+
install_manifest.txt
9+
compile_commands.json
10+
CTestTestfile.cmake
11+
_deps
12+
13+
build/
14+
install/
15+
lua-*/
16+
luarocks-*/
17+
*.gz
18+
*.zip

Build-Lua.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
$ErrorActionPreference = 'Stop'
2+
3+
if (Test-Path -Path build -PathType Container)
4+
{
5+
Remove-Item -Recurse -Force -Path build
6+
}
7+
cmake -B build -G Ninja -D CMAKE_BUILD_TYPE=RelWithDebInfo
8+
cmake --build build --target package

CMakeLists.txt

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
cmake_minimum_required(VERSION 3.26)
2+
set(LUA_VERSION 5.4.4)
3+
project(Lua VERSION ${LUA_VERSION} LANGUAGES C)
4+
5+
set(LUA_TARBALL lua-${CMAKE_PROJECT_VERSION}.tar.gz)
6+
set(LUA_TARBALL_SHA1 03c27684b9d5d9783fb79a7c836ba1cdc5f309cd)
7+
8+
if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/${LUA_TARBALL})
9+
file(DOWNLOAD https://www.lua.org/ftp/${LUA_TARBALL}
10+
${CMAKE_CURRENT_LIST_DIR}/${LUA_TARBALL}
11+
EXPECTED_HASH SHA1=${LUA_TARBALL_SHA1}
12+
)
13+
file(ARCHIVE_EXTRACT INPUT ${CMAKE_CURRENT_LIST_DIR}/${LUA_TARBALL}
14+
DESTINATION ${CMAKE_CURRENT_LIST_DIR}
15+
)
16+
endif()
17+
18+
if(WIN32)
19+
set(LUAROCKS_VERSION 3.9.2)
20+
set(LUAROCKS_TARBALL luarocks-${LUAROCKS_VERSION}-windows-64.zip)
21+
22+
if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/${LUAROCKS_TARBALL})
23+
file(DOWNLOAD http://luarocks.github.io/luarocks/releases/${LUAROCKS_TARBALL}
24+
${CMAKE_CURRENT_LIST_DIR}/${LUAROCKS_TARBALL}
25+
)
26+
file(ARCHIVE_EXTRACT INPUT ${CMAKE_CURRENT_LIST_DIR}/${LUAROCKS_TARBALL}
27+
DESTINATION ${CMAKE_CURRENT_LIST_DIR}
28+
)
29+
endif()
30+
endif()
31+
32+
set(LUA_SRC lua-${CMAKE_PROJECT_VERSION}/src)
33+
set(LUA_DOC lua-${CMAKE_PROJECT_VERSION}/doc)
34+
35+
set(LIB
36+
${LUA_SRC}/lapi.c
37+
${LUA_SRC}/lcode.c
38+
${LUA_SRC}/lctype.c
39+
${LUA_SRC}/ldebug.c
40+
${LUA_SRC}/ldo.c
41+
${LUA_SRC}/ldump.c
42+
${LUA_SRC}/lfunc.c
43+
${LUA_SRC}/lgc.c
44+
${LUA_SRC}/llex.c
45+
${LUA_SRC}/lmem.c
46+
${LUA_SRC}/lobject.c
47+
${LUA_SRC}/lopcodes.c
48+
${LUA_SRC}/lparser.c
49+
${LUA_SRC}/lstate.c
50+
${LUA_SRC}/lstring.c
51+
${LUA_SRC}/ltable.c
52+
${LUA_SRC}/ltm.c
53+
${LUA_SRC}/lundump.c
54+
${LUA_SRC}/lvm.c
55+
${LUA_SRC}/lzio.c
56+
${LUA_SRC}/lauxlib.c
57+
${LUA_SRC}/lbaselib.c
58+
${LUA_SRC}/lcorolib.c
59+
${LUA_SRC}/ldblib.c
60+
${LUA_SRC}/liolib.c
61+
${LUA_SRC}/lmathlib.c
62+
${LUA_SRC}/loadlib.c
63+
${LUA_SRC}/loslib.c
64+
${LUA_SRC}/lstrlib.c
65+
${LUA_SRC}/ltablib.c
66+
${LUA_SRC}/lutf8lib.c
67+
${LUA_SRC}/linit.c
68+
)
69+
70+
set(LUA
71+
${LUA_SRC}/lua.c
72+
)
73+
74+
set (LUAC
75+
${LUA_SRC}/luac.c
76+
)
77+
78+
include(CheckLibraryExists)
79+
check_library_exists(m pow "" LIBEXISTS)
80+
if(LIBEXISTS)
81+
set(LIBM "m")
82+
endif()
83+
84+
add_executable(lua ${LUA} ${LIB})
85+
target_link_libraries(lua PUBLIC ${LIBM})
86+
87+
add_executable(luac ${LUAC} ${LIB})
88+
target_link_libraries(luac PUBLIC ${LIBM})
89+
90+
add_library(lualib SHARED ${LIB})
91+
target_sources(lualib
92+
PUBLIC
93+
FILE_SET include TYPE HEADERS BASE_DIRS ${LUA_SRC}
94+
FILES ${LUA_SRC}/lauxlib.h ${LUA_SRC}/lua.h ${LUA_SRC}/lua.hpp ${LUA_SRC}/luaconf.h ${LUA_SRC}/lualib.h
95+
)
96+
97+
if(WIN32)
98+
target_compile_definitions(lualib PUBLIC LUA_BUILD_AS_DLL)
99+
set_property(TARGET lualib PROPERTY OUTPUT_NAME lua${CMAKE_PROJECT_VERSION_MAJOR}${CMAKE_PROJECT_VERSION_MINOR})
100+
101+
install(PROGRAMS
102+
${CMAKE_CURRENT_LIST_DIR}/luarocks-${LUAROCKS_VERSION}-windows-64/luarocks.exe
103+
${CMAKE_CURRENT_LIST_DIR}/luarocks-${LUAROCKS_VERSION}-windows-64/luarocks-admin.exe
104+
TYPE BIN)
105+
else()
106+
set_property(TARGET lualib PROPERTY OUTPUT_NAME lua)
107+
endif()
108+
109+
install(TARGETS lua luac)
110+
install(TARGETS lualib FILE_SET include)
111+
112+
if(WIN32)
113+
set(CPACK_GENERATOR ZIP WIX)
114+
set(CPACK_WIX_UPGRADE_GUID "3e5a792d-9d31-41d5-a93f-629ab7c7683d")
115+
set(CPACK_WIX_PRODUCT_ICON ${CMAKE_CURRENT_LIST_DIR}/lua.ico)
116+
list(APPEND CPACK_WIX_EXTENSIONS WixUtilExtension)
117+
list(APPEND CPACK_WIX_PATCH_FILE ${CMAKE_CURRENT_LIST_DIR}/WixPatch.xml)
118+
else()
119+
install(FILES ${LUA_DOC}/lua.1 ${LUA_DOC}/luac.1
120+
DESTINATION man/man1
121+
)
122+
endif()
123+
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_LIST_DIR}/LICENSE.txt")
124+
set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CMAKE_PROJECT_NAME})
125+
include(CPack)

Install-Lua.ps1

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
$ErrorActionPreference = 'Stop'
2+
3+
if (Test-Path -Path install -PathType Container)
4+
{
5+
Remove-Item -Recurse -Force -Path install
6+
}
7+
cmake --install build --prefix install

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Copyright © 1994–2023 Lua.org, PUC-Rio.
2+
Copyright © 2007-2011, Kepler Project.
3+
Copyright © 2011-2022, the LuaRocks project authors.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# CMake for Lua
2+
3+
This is a CMake-based project to build and package [Lua](https://lua.org/) and
4+
[LuaRocks](https://luarocks.org/). As the [official Lua binaries
5+
repository](https://luabinaries.sourceforge.net/) is not updated very
6+
frequently, and the [compilation
7+
process](https://www.lua.org/manual/5.4/readme.html) for Windows binaries is not
8+
easy for non-C developers, you can use this project to build an updated version
9+
of Lua.
10+
11+
## Prerequisites
12+
13+
- C compiler (Microsoft Visual C++ or Clang)
14+
- CMake
15+
- Ninja
16+
- WiX Toolset
17+
18+
You can install the first three components with the following
19+
[winget](https://learn.microsoft.com/windows/package-manager/winget/) commands:
20+
21+
```powershell
22+
winget install --id LLVM.LLVM
23+
winget install --id Kitware.CMake
24+
winget install --id Ninja-build.Ninja
25+
```
26+
WiX Toolset is available at <https://github.com/wixtoolset/wix3/releases/>.
27+
28+
## Build
29+
30+
Use the following commands to generate the installation package in both ZIP and
31+
MSI formats:
32+
33+
```powershell
34+
cmake -B build -G Ninja -D CMAKE_BUILD_TYPE=RelWithDebInfo
35+
cmake --build build --target package
36+
```
37+
You need Internet access to execute the build process to download the Lua source
38+
code and LuaRocks binaries.
39+
40+
For convenience, you can use the `Build-Lua.ps1` script to run these commands.
41+
42+
If successful, the ZIP and MSI files will be available in the `build` directory.

WixPatch.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<CPackWiXPatch>
2+
<!-- Fragment ID is from [build/_CPack_Packages/win64/WIX/features.wxs] -->
3+
<CPackWiXFragment Id="CM_CP_bin.lua.exe">
4+
<Environment
5+
Id='UpdatePath'
6+
Name='PATH'
7+
Action='set'
8+
Permanent='no'
9+
Part='last'
10+
Value='[INSTALL_ROOT]bin'
11+
/>
12+
</CPackWiXFragment>
13+
14+
<!-- Allow installation by non-administrative users -->
15+
<!-- https://learn.microsoft.com/windows/win32/msi/allusers -->
16+
<CPackWiXFragment Id="#PRODUCT">
17+
<Property Id="ALLUSERS" Value="2" />
18+
<Property Id="MSIINSTALLPERUSER" Value="1" />
19+
</CPackWiXFragment>
20+
</CPackWiXPatch>

lua.ico

200 KB
Binary file not shown.

0 commit comments

Comments
 (0)