link to rt if it provides clock_gettime

As noted in #128, if clock_gettime is provided by librt then it does not
end up being linked into the static libuv.a binary. This might be
considered a bug in libuv but we can address it here.

Detect if librt provides the clock_gettime symbol and, if so, append it
to the list of libraries linked into nvim. On non-librt systems the
behaviour should be as before.
This commit is contained in:
Rich Wareham 2014-02-26 10:06:59 +00:00 committed by Thiago de Arruda
parent c3ff8cbb7c
commit de4fbf92d0
2 changed files with 19 additions and 3 deletions

View File

@ -18,6 +18,9 @@ else()
set(DEBUG 0)
endif()
# Modules used by platform auto-detection
include(CheckLibraryExists)
# Determine platform's threading library. Set CMAKE_THREAD_PREFER_PTHREAD
# explicitly to indicate a strong preference for pthread. It is an error to not
# have pthread installed even if, for example, the Win32 threading API is found.
@ -27,11 +30,15 @@ if(NOT CMAKE_USE_PTHREADS_INIT)
message(SEND_ERROR "The pthread library must be installed on your system.")
endif(NOT CMAKE_USE_PTHREADS_INIT)
# Detect if clock_gettime exists in -lrt. If so we need to link with it because
# the static libuv doesn't but uses clock_gettime.
check_library_exists(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME)
# Require libuv
find_package(LibUV REQUIRED)
include_directories(${LibUV_INCLUDE_DIRS})
include_directories ("${PROJECT_BINARY_DIR}/config")
include_directories ("${PROJECT_BINARY_DIR}/config")
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

View File

@ -14,7 +14,16 @@ file( GLOB OS_SOURCES os/*.c )
add_executable (nvim ${NEOVIM_SOURCES} ${OS_SOURCES})
target_link_libraries (vim m ${LibUV_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
# The libraries we link against for nvim
set(NVIM_LINK_LIBRARIES m ${LibUV_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
# Add any libraries needed for a specific platform
if(HAVE_CLOCK_GETTIME)
# Work around libuv.a not linking in rt.
list(APPEND NVIM_LINK_LIBRARIES rt)
endif(HAVE_CLOCK_GETTIME)
target_link_libraries (nvim ${NVIM_LINK_LIBRARIES})
include(CheckLibraryExists)
check_library_exists(termcap tgetent "" HAVE_LIBTERMCAP)
@ -30,6 +39,6 @@ else()
endif()
endif()
include_directories ("${PROJECT_SOURCE_DIR}/src/proto")
include_directories ("${PROJECT_SOURCE_DIR}/src/proto")
install(TARGETS nvim RUNTIME DESTINATION bin)