cmake: Link libnvim-test with luajit in place of lua, disable ASAN

Reasoning: luajit is not being compiled with sanitizers, lua is. Given that 
linking with sanitized libraries requires sanitizers enabled, it is needed to 
either compile libnvim-test with sanitizers or link it with lua compiled without 
sanitizers. Most easy way to do the latter is just use luajit which is compiled 
without sanitizers (as they do not work well with luajit).
This commit is contained in:
ZyX 2017-01-27 02:55:34 +03:00
parent d5228787ce
commit d60302d517
2 changed files with 21 additions and 16 deletions

View File

@ -310,14 +310,12 @@ include_directories(SYSTEM ${LIBUV_INCLUDE_DIRS})
find_package(Msgpack 1.0.0 REQUIRED)
include_directories(SYSTEM ${MSGPACK_INCLUDE_DIRS})
option(PREFER_LUAJIT "Prefer LuaJIT over Lua." ON)
option(PREFER_LUAJIT "Prefer LuaJIT over Lua when compiling executable. Test library always uses luajit." ON)
if(PREFER_LUAJIT)
find_package(LuaJit REQUIRED)
include_directories(SYSTEM ${LUAJIT_INCLUDE_DIRS})
else()
find_package(LuaJit REQUIRED)
if(NOT PREFER_LUAJIT)
find_package(Lua REQUIRED)
include_directories(SYSTEM ${LUA_INCLUDE_DIR})
endif()
if(UNIX)

View File

@ -292,11 +292,6 @@ list(APPEND NVIM_LINK_LIBRARIES
${UNIBILIUM_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)
if(PREFER_LUAJIT)
list(APPEND NVIM_LINK_LIBRARIES ${LUAJIT_LIBRARIES})
else()
list(APPEND NVIM_LINK_LIBRARIES ${LUA_LIBRARIES})
endif()
if(UNIX)
list(APPEND NVIM_LINK_LIBRARIES
@ -306,6 +301,14 @@ if(UNIX)
endif()
set(NVIM_EXEC_LINK_LIBRARIES ${NVIM_LINK_LIBRARIES})
set(NVIM_TEST_LINK_LIBRARIES ${NVIM_LINK_LIBRARIES})
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.
if(JEMALLOC_FOUND)
@ -317,6 +320,12 @@ add_executable(nvim ${NEOVIM_GENERATED_SOURCES} ${NEOVIM_SOURCES}
target_link_libraries(nvim ${NVIM_EXEC_LINK_LIBRARIES})
install_helper(TARGETS nvim)
if(PREFER_LUAJIT)
target_include_directories(nvim SYSTEM PRIVATE ${LUAJIT_INCLUDE_DIRS})
else()
target_include_directories(nvim SYSTEM PRIVATE ${LUA_INCLUDE_DIRS})
endif()
if(WIN32)
# Copy DLLs and third-party tools to bin/ and install them along with nvim
add_custom_target(nvim_runtime_deps ALL
@ -365,7 +374,7 @@ endif()
add_library(libnvim STATIC EXCLUDE_FROM_ALL ${NEOVIM_GENERATED_SOURCES}
${NEOVIM_SOURCES} ${NEOVIM_HEADERS})
target_link_libraries(libnvim ${NVIM_LINK_LIBRARIES})
target_link_libraries(libnvim ${NVIM_TEST_LINK_LIBRARIES})
set_target_properties(libnvim PROPERTIES
POSITION_INDEPENDENT_CODE ON
OUTPUT_NAME nvim)
@ -374,7 +383,8 @@ set_property(TARGET libnvim
add_library(nvim-test MODULE EXCLUDE_FROM_ALL ${NEOVIM_GENERATED_SOURCES}
${NEOVIM_SOURCES} ${UNIT_TEST_FIXTURES} ${NEOVIM_HEADERS})
target_link_libraries(nvim-test ${NVIM_LINK_LIBRARIES})
target_link_libraries(nvim-test ${NVIM_TEST_LINK_LIBRARIES})
target_include_directories(nvim-test SYSTEM PRIVATE ${LUAJIT_INCLUDE_DIRS})
set_target_properties(nvim-test PROPERTIES
POSITION_INDEPENDENT_CODE ON)
set_property(TARGET nvim-test
@ -391,9 +401,6 @@ if(CLANG_ASAN_UBSAN)
set_property(TARGET nvim APPEND_STRING PROPERTY COMPILE_FLAGS "-DEXITFREE ")
set_property(TARGET nvim APPEND_STRING PROPERTY COMPILE_FLAGS "${SANITIZE_RECOVER} -fno-omit-frame-pointer -fno-optimize-sibling-calls -fsanitize=address -fsanitize=undefined -fsanitize-blacklist=${PROJECT_SOURCE_DIR}/src/.asan-blacklist")
set_property(TARGET nvim APPEND_STRING PROPERTY LINK_FLAGS "-fsanitize=address -fsanitize=undefined ")
set_property(TARGET nvim-test APPEND_STRING PROPERTY COMPILE_FLAGS "${SANITIZE_RECOVER} -fno-omit-frame-pointer -fno-optimize-sibling-calls -fsanitize=address -fsanitize-blacklist=${PROJECT_SOURCE_DIR}/src/.asan-blacklist")
set_property(TARGET nvim-test APPEND_STRING PROPERTY LINK_FLAGS "-fsanitize=address ")
elseif(CLANG_MSAN)
message(STATUS "Enabling Clang memory sanitizer for nvim.")
set_property(TARGET nvim APPEND_STRING PROPERTY COMPILE_FLAGS "-DEXITFREE ")