mirror of
https://github.com/neovim/neovim.git
synced 2025-10-10 11:56:30 +00:00
cmake: Support building without LuaJIT. #6736
Compile `nvim` executable against Lua if PREFER_LUA=ON. As the testing library `nvim-test` requires LuaJIT, it is still compiled against LuaJIT. If LuaJIT is not available, `nvim-test` is not built.
This commit is contained in:

committed by
Justin M. Keyes

parent
244a1f97db
commit
7383274f66
@@ -68,7 +68,7 @@ matrix:
|
|||||||
compiler: clang-3.9
|
compiler: clang-3.9
|
||||||
env: >
|
env: >
|
||||||
CLANG_SANITIZER=ASAN_UBSAN
|
CLANG_SANITIZER=ASAN_UBSAN
|
||||||
CMAKE_FLAGS="$CMAKE_FLAGS -DPREFER_LUAJIT=false"
|
CMAKE_FLAGS="$CMAKE_FLAGS -DPREFER_LUA=ON"
|
||||||
- os: linux
|
- os: linux
|
||||||
compiler: clang-3.9
|
compiler: clang-3.9
|
||||||
env: CLANG_SANITIZER=TSAN
|
env: CLANG_SANITIZER=TSAN
|
||||||
|
@@ -314,12 +314,18 @@ include_directories(SYSTEM ${LIBUV_INCLUDE_DIRS})
|
|||||||
find_package(Msgpack 1.0.0 REQUIRED)
|
find_package(Msgpack 1.0.0 REQUIRED)
|
||||||
include_directories(SYSTEM ${MSGPACK_INCLUDE_DIRS})
|
include_directories(SYSTEM ${MSGPACK_INCLUDE_DIRS})
|
||||||
|
|
||||||
option(PREFER_LUAJIT "Prefer LuaJIT over Lua when compiling executable. Test library always uses luajit." ON)
|
# Note: The test lib requires LuaJIT; it will be skipped if LuaJIT is missing.
|
||||||
|
option(PREFER_LUA "Prefer Lua over LuaJIT in the nvim executable." OFF)
|
||||||
|
|
||||||
find_package(LuaJit REQUIRED)
|
if(PREFER_LUA)
|
||||||
|
|
||||||
if(NOT PREFER_LUAJIT)
|
|
||||||
find_package(Lua REQUIRED)
|
find_package(Lua REQUIRED)
|
||||||
|
set(LUA_PREFERRED_INCLUDE_DIRS ${LUA_INCLUDE_DIR})
|
||||||
|
set(LUA_PREFERRED_LIBRARIES ${LUA_LIBRARIES})
|
||||||
|
find_package(LuaJit)
|
||||||
|
else()
|
||||||
|
find_package(LuaJit REQUIRED)
|
||||||
|
set(LUA_PREFERRED_INCLUDE_DIRS ${LUAJIT_INCLUDE_DIRS})
|
||||||
|
set(LUA_PREFERRED_LIBRARIES ${LUAJIT_LIBRARIES})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
list(APPEND CMAKE_REQUIRED_INCLUDES "${MSGPACK_INCLUDE_DIRS}")
|
list(APPEND CMAKE_REQUIRED_INCLUDES "${MSGPACK_INCLUDE_DIRS}")
|
||||||
|
@@ -171,7 +171,7 @@ if(CLANG_ASAN_UBSAN OR CLANG_MSAN OR CLANG_TSAN)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
get_directory_property(gen_includes INCLUDE_DIRECTORIES)
|
get_directory_property(gen_includes INCLUDE_DIRECTORIES)
|
||||||
foreach(gen_include ${gen_includes} ${LUAJIT_INCLUDE_DIRS})
|
foreach(gen_include ${gen_includes} ${LUA_PREFERRED_INCLUDE_DIRS})
|
||||||
list(APPEND gen_cflags "-I${gen_include}")
|
list(APPEND gen_cflags "-I${gen_include}")
|
||||||
endforeach()
|
endforeach()
|
||||||
string(TOUPPER "${CMAKE_BUILD_TYPE}" build_type)
|
string(TOUPPER "${CMAKE_BUILD_TYPE}" build_type)
|
||||||
@@ -367,25 +367,14 @@ if(UNIX)
|
|||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(NVIM_EXEC_LINK_LIBRARIES ${NVIM_LINK_LIBRARIES})
|
set(NVIM_EXEC_LINK_LIBRARIES ${NVIM_LINK_LIBRARIES} ${LUA_PREFERRED_LIBRARIES})
|
||||||
set(NVIM_TEST_LINK_LIBRARIES ${NVIM_LINK_LIBRARIES})
|
|
||||||
|
|
||||||
if(CMAKE_VERSION VERSION_LESS "2.8.8")
|
if(CMAKE_VERSION VERSION_LESS "2.8.8")
|
||||||
if(PREFER_LUAJIT)
|
# Use include_directories() because INCLUDE_DIRECTORIES target property
|
||||||
include_directories(${LUAJIT_INCLUDE_DIRS})
|
# is not supported
|
||||||
else()
|
include_directories(${LUA_PREFERRED_INCLUDE_DIRS})
|
||||||
message(FATAL_ERROR
|
|
||||||
"Must support INCLUDE_DIRECTORIES target property to build")
|
|
||||||
endif()
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(PREFER_LUAJIT)
|
|
||||||
list(APPEND NVIM_EXEC_LINK_LIBRARIES ${LUAJIT_LIBRARIES})
|
|
||||||
else()
|
|
||||||
list(APPEND NVIM_EXEC_LINK_LIBRARIES ${LUA_LIBRARIES})
|
|
||||||
endif()
|
|
||||||
list(APPEND NVIM_TEST_LINK_LIBRARIES ${LUAJIT_LIBRARIES})
|
|
||||||
|
|
||||||
# Don't use jemalloc in the unit test library.
|
# Don't use jemalloc in the unit test library.
|
||||||
if(JEMALLOC_FOUND)
|
if(JEMALLOC_FOUND)
|
||||||
list(APPEND NVIM_EXEC_LINK_LIBRARIES ${JEMALLOC_LIBRARIES})
|
list(APPEND NVIM_EXEC_LINK_LIBRARIES ${JEMALLOC_LIBRARIES})
|
||||||
@@ -396,11 +385,6 @@ add_executable(nvim ${NVIM_GENERATED_FOR_SOURCES} ${NVIM_GENERATED_FOR_HEADERS}
|
|||||||
target_link_libraries(nvim ${NVIM_EXEC_LINK_LIBRARIES})
|
target_link_libraries(nvim ${NVIM_EXEC_LINK_LIBRARIES})
|
||||||
install_helper(TARGETS nvim)
|
install_helper(TARGETS nvim)
|
||||||
|
|
||||||
if(PREFER_LUAJIT)
|
|
||||||
set(LUA_PREFERRED_INCLUDE_DIRS ${LUAJIT_INCLUDE_DIRS})
|
|
||||||
else()
|
|
||||||
set(LUA_PREFERRED_INCLUDE_DIRS ${LUA_INCLUDE_DIRS})
|
|
||||||
endif()
|
|
||||||
set_property(TARGET nvim APPEND PROPERTY
|
set_property(TARGET nvim APPEND PROPERTY
|
||||||
INCLUDE_DIRECTORIES ${LUA_PREFERRED_INCLUDE_DIRS})
|
INCLUDE_DIRECTORIES ${LUA_PREFERRED_INCLUDE_DIRS})
|
||||||
|
|
||||||
@@ -458,8 +442,7 @@ add_library(
|
|||||||
${NVIM_HEADERS} ${NVIM_GENERATED_FOR_SOURCES} ${NVIM_GENERATED_FOR_HEADERS}
|
${NVIM_HEADERS} ${NVIM_GENERATED_FOR_SOURCES} ${NVIM_GENERATED_FOR_HEADERS}
|
||||||
)
|
)
|
||||||
set_property(TARGET libnvim APPEND PROPERTY
|
set_property(TARGET libnvim APPEND PROPERTY
|
||||||
INCLUDE_DIRECTORIES ${LUAJIT_INCLUDE_DIRS})
|
INCLUDE_DIRECTORIES ${LUA_PREFERRED_INCLUDE_DIRS})
|
||||||
target_link_libraries(libnvim ${NVIM_TEST_LINK_LIBRARIES})
|
|
||||||
set_target_properties(
|
set_target_properties(
|
||||||
libnvim
|
libnvim
|
||||||
PROPERTIES
|
PROPERTIES
|
||||||
@@ -471,28 +454,32 @@ set_property(
|
|||||||
APPEND_STRING PROPERTY COMPILE_FLAGS " -DMAKE_LIB "
|
APPEND_STRING PROPERTY COMPILE_FLAGS " -DMAKE_LIB "
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(
|
if(LUAJIT_FOUND)
|
||||||
nvim-test
|
set(NVIM_TEST_LINK_LIBRARIES ${NVIM_LINK_LIBRARIES} ${LUAJIT_LIBRARIES})
|
||||||
MODULE
|
add_library(
|
||||||
EXCLUDE_FROM_ALL
|
nvim-test
|
||||||
${NVIM_SOURCES} ${NVIM_GENERATED_SOURCES}
|
MODULE
|
||||||
${NVIM_HEADERS} ${NVIM_GENERATED_FOR_SOURCES} ${NVIM_GENERATED_FOR_HEADERS}
|
EXCLUDE_FROM_ALL
|
||||||
${UNIT_TEST_FIXTURES}
|
${NVIM_SOURCES} ${NVIM_GENERATED_SOURCES}
|
||||||
)
|
${NVIM_HEADERS} ${NVIM_GENERATED_FOR_SOURCES} ${NVIM_GENERATED_FOR_HEADERS}
|
||||||
target_link_libraries(nvim-test ${NVIM_TEST_LINK_LIBRARIES})
|
${UNIT_TEST_FIXTURES}
|
||||||
set_property(
|
)
|
||||||
TARGET nvim-test
|
target_link_libraries(nvim-test ${NVIM_TEST_LINK_LIBRARIES})
|
||||||
APPEND PROPERTY INCLUDE_DIRECTORIES ${LUAJIT_INCLUDE_DIRS}
|
target_link_libraries(libnvim ${NVIM_TEST_LINK_LIBRARIES})
|
||||||
)
|
set_property(
|
||||||
set_target_properties(
|
TARGET nvim-test
|
||||||
nvim-test
|
APPEND PROPERTY INCLUDE_DIRECTORIES ${LUAJIT_INCLUDE_DIRS}
|
||||||
PROPERTIES
|
)
|
||||||
POSITION_INDEPENDENT_CODE ON
|
set_target_properties(
|
||||||
)
|
nvim-test
|
||||||
set_property(
|
PROPERTIES
|
||||||
TARGET nvim-test
|
POSITION_INDEPENDENT_CODE ON
|
||||||
APPEND_STRING PROPERTY COMPILE_FLAGS " -DUNIT_TESTING "
|
)
|
||||||
)
|
set_property(
|
||||||
|
TARGET nvim-test
|
||||||
|
APPEND_STRING PROPERTY COMPILE_FLAGS " -DUNIT_TESTING "
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(CLANG_ASAN_UBSAN)
|
if(CLANG_ASAN_UBSAN)
|
||||||
message(STATUS "Enabling Clang address sanitizer and undefined behavior sanitizer for nvim.")
|
message(STATUS "Enabling Clang address sanitizer and undefined behavior sanitizer for nvim.")
|
||||||
|
Reference in New Issue
Block a user