Skip to content

Commit 685e023

Browse files
committed
Build lcurl and lzip in-tree, add INSTALL target including dependencies
1 parent 14cfc8c commit 685e023

7 files changed

Lines changed: 860 additions & 1 deletion

File tree

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "vcpkg"]
22
path = vcpkg
33
url = https://github.com/microsoft/vcpkg
4+
[submodule "libs/Lua-cURLv3"]
5+
path = libs/Lua-cURLv3
6+
url = https://github.com/Lua-cURL/Lua-cURLv3.git

CMakeLists.txt

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ target_include_directories(SimpleGraphic
8787
)
8888

8989
find_package(unofficial-angle CONFIG REQUIRED)
90+
find_package(CURL CONFIG REQUIRED)
9091
find_package(fmt CONFIG REQUIRED)
9192
find_package(glfw3 CONFIG REQUIRED)
9293
find_package(LuaJit REQUIRED)
@@ -135,4 +136,54 @@ target_link_libraries(SimpleGraphic
135136
re2::re2
136137
Threads::Threads
137138
ZLIB::ZLIB
138-
)
139+
)
140+
141+
install(FILES $<TARGET_RUNTIME_DLLS:SimpleGraphic> DESTINATION ".")
142+
install(TARGETS SimpleGraphic RUNTIME DESTINATION ".")
143+
144+
if (WIN32)
145+
find_file(LUAJIT_DLL NAMES "lua51.dll" PATHS "${CMAKE_BINARY_DIR}" REQUIRED)
146+
find_file(ZLIB_DLL NAMES "zlib1.dll" PATHS "${CMAKE_BINARY_DIR}" REQUIRED)
147+
install(FILES ${LUAJIT_DLL} ${ZLIB_DLL} DESTINATION ".")
148+
endif ()
149+
150+
151+
# lcurl module
152+
153+
set(LCURL_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libs/Lua-cURLv3)
154+
file(GLOB LCURL_SOURCES ${LCURL_SOURCE_DIR}/src/**.c)
155+
add_library(lcurl SHARED ${LCURL_SOURCES})
156+
157+
target_include_directories(lcurl
158+
PRIVATE
159+
${LCURL_SOURCE_DIR}/src
160+
${LUAJIT_INCLUDE_DIR}
161+
)
162+
163+
target_link_libraries(lcurl
164+
PRIVATE
165+
CURL::libcurl
166+
${LUAJIT_LIBRARIES}
167+
)
168+
169+
install(TARGETS lcurl RUNTIME DESTINATION ".")
170+
install(FILES $<TARGET_RUNTIME_DLLS:lcurl> DESTINATION ".")
171+
172+
173+
# lzip module
174+
175+
add_library(lzip SHARED libs/LZip/lzip.cpp)
176+
177+
target_include_directories(lzip
178+
PRIVATE
179+
${LUAJIT_INCLUDE_DIR}
180+
)
181+
182+
target_link_libraries(lzip
183+
PRIVATE
184+
${LUAJIT_LIBRARIES}
185+
ZLIB::ZLIB
186+
)
187+
188+
install(TARGETS lzip RUNTIME DESTINATION ".")
189+
install(FILES $<TARGET_RUNTIME_DLLS:lzip> DESTINATION ".")

libs/LZip/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
cmake_minimum_required(VERSION 3.18)
2+
project(lzip CXX)
3+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
4+
5+
find_package(ZLIB REQUIRED)
6+
7+
find_package(LuaJIT REQUIRED)
8+
9+
add_library(lzip SHARED lzip.cpp)
10+
target_include_directories(lzip PRIVATE ${LUA_INCLUDE_DIR})
11+
target_link_libraries(lzip PRIVATE ZLIB::ZLIB ${LUA_LIBRARY})

libs/LZip/cmake/FindLuaJIT.cmake

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Locate LuaJIT library
2+
# This module defines
3+
# LUAJIT_FOUND, if false, do not try to link to Lua
4+
# LUA_INCLUDE_DIR, where to find lua.h
5+
# LUA_VERSION_STRING, the version of Lua found (since CMake 2.8.8)
6+
#
7+
# This module is similar to FindLua51.cmake except that it finds LuaJit instead.
8+
9+
FIND_PATH(LUA_INCLUDE_DIR luajit.h
10+
HINTS
11+
$ENV{LUA_DIR}
12+
PATH_SUFFIXES include/luajit-2.1 include/luajit-2.0 include/luajit-5_1-2.1 include/luajit-5_1-2.0 include luajit
13+
PATHS
14+
~/Library/Frameworks
15+
/Library/Frameworks
16+
/sw # Fink
17+
/opt/local # DarwinPorts
18+
/opt/csw # Blastwave
19+
/opt
20+
)
21+
22+
# Test if running on vcpkg toolchain
23+
if(DEFINED VCPKG_TARGET_TRIPLET AND DEFINED VCPKG_APPLOCAL_DEPS)
24+
# On vcpkg luajit is 'lua51' and normal lua is 'lua'
25+
FIND_LIBRARY(LUA_LIBRARY
26+
NAMES lua51
27+
HINTS
28+
$ENV{LUA_DIR}
29+
PATH_SUFFIXES lib
30+
)
31+
else()
32+
FIND_LIBRARY(LUA_LIBRARY
33+
NAMES luajit-5.1
34+
HINTS
35+
$ENV{LUA_DIR}
36+
PATH_SUFFIXES lib64 lib
37+
PATHS
38+
~/Library/Frameworks
39+
/Library/Frameworks
40+
/sw
41+
/opt/local
42+
/opt/csw
43+
/opt
44+
)
45+
endif()
46+
47+
48+
IF(LUA_INCLUDE_DIR AND EXISTS "${LUA_INCLUDE_DIR}/luajit.h")
49+
FILE(STRINGS "${LUA_INCLUDE_DIR}/luajit.h" lua_version_str REGEX "^#define[ \t]+LUA_RELEASE[ \t]+\"LuaJIT .+\"")
50+
51+
STRING(REGEX REPLACE "^#define[ \t]+LUA_RELEASE[ \t]+\"LuaJIT ([^\"]+)\".*" "\\1" LUA_VERSION_STRING "${lua_version_str}")
52+
UNSET(lua_version_str)
53+
ENDIF()
54+
55+
INCLUDE(FindPackageHandleStandardArgs)
56+
# handle the QUIETLY and REQUIRED arguments and set LUAJIT_FOUND to TRUE if
57+
# all listed variables are TRUE
58+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LuaJit
59+
REQUIRED_VARS LUA_LIBRARY LUA_INCLUDE_DIR
60+
VERSION_VAR LUA_VERSION_STRING)
61+
62+
MARK_AS_ADVANCED(LUA_INCLUDE_DIR LUA_LIBRARY LUA_MATH_LIBRARY)

0 commit comments

Comments
 (0)