From fd346a95fa619ef3dd8440bf541332ea2c97e399 Mon Sep 17 00:00:00 2001 From: Rich Wareham Date: Mon, 24 Feb 2014 18:52:12 +0000 Subject: [PATCH] use CMake's built in pthread detection CMake ships with a standard FindThreads module which can be used to a) test for a threading library and b) confirm that it is pthread. It also allows the hard-coding of the threading library name to be removed from ``src/CMakeLists.txt``. Make it an error not to have a pthread library installed and indicate to CMake that we strongly prefer pthread to any other platform threading library. --- CMakeLists.txt | 9 +++++++++ src/CMakeLists.txt | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 340bbad979..f0a04efe23 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,15 @@ else() set(DEBUG 0) endif() +# 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. +set(CMAKE_THREAD_PREFER_PTHREAD ON) +find_package(Threads REQUIRED) +if(NOT CMAKE_USE_PTHREADS_INIT) + message(SEND_ERROR "The pthread library must be installed on your system.") +endif(NOT CMAKE_USE_PTHREADS_INIT) + # add dependencies to include/lib directories link_directories ("${PROJECT_SOURCE_DIR}/.deps/usr/lib") include_directories ("${PROJECT_SOURCE_DIR}/.deps/usr/include") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1c7829e7d6..5ae5662a88 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -14,7 +14,7 @@ file( GLOB IO_SOURCES io/*.c ) add_executable (vim ${NEOVIM_SOURCES} ${IO_SOURCES}) -target_link_libraries (vim m uv pthread) +target_link_libraries (vim m uv ${CMAKE_THREAD_LIBS_INIT}) include(CheckLibraryExists) check_library_exists(termcap tgetent "" HAVE_LIBTERMCAP)