Skip to content

Commit e97eba6

Browse files
committed
cmake: refactor searching libraries and executable
There are three ways to set Lua libraries, headers and executable: 1. Setting CMake option ENABLE_LUAJIT will trigger searching LuaJIT library, headers and executable. 2. Setting CMake options LUA_LIBRARIES, LUA_INCLUDE_DIR and optional LUA_EXECUTABLE with a path Lua library, directory with headers and to a path to Lua executable explicitly. 3. Searching PUC Rio Lua library, headers and executable automatically. LUA_EXECUTABLE is required for regression testing only, so if this CMake variable was not specified explicitly or was not found automatically the testing will not be enabled. The patch simplify a code for searching Lua library and makes the behavior the same for all three cases described above: - Move a code for searching `luajit` binary executable to CMake module. - Remove fatal message for a case when PUC Rio Lua executable was not found. - Remove excess `unset()` for ENABLE_TESTING. Needed for #59
1 parent c4f00e1 commit e97eba6

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

CMakeLists.txt

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,24 @@ if(LUA_INCLUDE_DIR AND LUA_LIBRARIES)
2424
set_target_properties(liblua PROPERTIES
2525
IMPORTED_LOCATION ${LUA_LIBRARIES})
2626
set(LUA_LIBRARIES liblua)
27+
set(LUA_FOUND TRUE)
2728
elseif(ENABLE_LUAJIT)
28-
include(FindLuaJIT)
29-
set(LUA_NAME "luajit")
30-
find_program(LUA_EXECUTABLE "${LUA_NAME}")
31-
if(NOT EXISTS ${LUA_EXECUTABLE})
32-
message(FATAL_ERROR "`${LUA_NAME}` is required")
33-
endif()
29+
find_package(LuaJIT)
3430
set(LUA_HAS_JIT ON CACHE INTERNAL "Use LuaJIT library")
3531
message(STATUS "Found LuaJIT ${LUA_VERSION_STRING}")
3632
message(STATUS "Found LuaJIT interpreter ${LUA_EXECUTABLE}")
3733
else()
3834
find_package(Lua 5.1 REQUIRED)
3935
set(LUA_NAME "lua${LUA_VERSION_MAJOR}.${LUA_VERSION_MINOR}")
4036
find_program(LUA_EXECUTABLE "${LUA_NAME}")
41-
if(NOT EXISTS ${LUA_EXECUTABLE})
42-
message(FATAL_ERROR "${LUA_NAME} is required")
43-
endif()
4437
message(STATUS "Found Lua ${LUA_VERSION_STRING}")
4538
message(STATUS "Found Lua interpreter ${LUA_EXECUTABLE}")
4639
endif()
4740

41+
if(NOT LUA_FOUND)
42+
message(FATAL_ERROR "Lua library is not found")
43+
endif()
44+
4845
if(LUAJIT_FRIENDLY_MODE AND NOT LUA_HAS_JIT)
4946
message(FATAL_ERROR "LuaJIT-friendly mode requires option ENABLE_LUAJIT")
5047
endif()
@@ -66,7 +63,6 @@ endif()
6663

6764
if(ENABLE_TESTING AND NOT EXISTS ${LUA_EXECUTABLE})
6865
message(WARNING "Lua executable is not found, testing is not available.")
69-
unset(ENABLE_TESTING)
7066
else()
7167
enable_testing()
7268
endif()

cmake/FindLuaJIT.cmake

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
# Locate a LuaJIT library.
1+
# Locate a LuaJIT library and binary executable.
22
#
33
# This module defines:
44
# LUA_FOUND, if false, do not try to link to LuaJIT,
55
# LUA_LIBRARIES, where to find libluajit,
66
# LUA_INCLUDE_DIR, where to find luajit.h,
7+
# LUA_EXECUTABLE, where to find luajit binary executable,
78
# LUA_VERSION_STRING, the version of LuaJIT found,
89
# LUA_VERSION_MAJOR, the major version of LuaJIT,
910
# LUA_VERSION_MINOR, the minor version of LuaJIT,
@@ -41,13 +42,21 @@ find_package_handle_standard_args(LuaJIT
4142
VERSION_VAR LUA_VERSION_STRING
4243
FAIL_MESSAGE "${ERROR_MESSAGE}"
4344
)
44-
# Set LUA_FOUND, LUA_INCLUDE_DIR and LUA_LIBRARIES for
45-
# compatibility with FindLua.cmake.
45+
46+
find_program(LUAJIT_EXECUTABLE luajit)
47+
if(NOT EXISTS ${LUAJIT_EXECUTABLE})
48+
message(WARNING "`luajit` is not found")
49+
endif()
50+
51+
# Set LUA_FOUND, LUA_INCLUDE_DIR, LUA_LIBRARIES and LUA_EXECUTABLE
52+
# for compatibility with FindLua.cmake.
4653
set(LUA_FOUND ${LUAJIT_FOUND})
4754
set(LUA_LIBRARIES ${LUAJIT_LIBRARIES})
4855
set(LUA_INCLUDE_DIR ${LUAJIT_INCLUDE_DIR})
56+
set(LUA_EXECUTABLE ${LUAJIT_EXECUTABLE})
4957
unset(LUAJIT_FOUND)
5058
unset(LUAJIT_LIBRARIES)
5159
unset(LUAJIT_INCLUDE_DIR)
60+
unset(LUAJIT_EXECUTABLE)
5261

5362
mark_as_advanced(LUA_INCLUDE_DIR LUA_LIBRARIES)

0 commit comments

Comments
 (0)