From f739af1e43e0005971641738f588f28c9abae08d Mon Sep 17 00:00:00 2001 From: Janne Blomqvist Date: Wed, 13 Sep 2017 17:43:12 +0300 Subject: [PATCH] Simplify pthreads library detection Use the cmake builtin Threads library detection, and bail out if it wasn't pthreads. This allows deleting the cmake/FindPTHREAD.cmake file which complains because pthreads doesn't provide a pkg-config file. In newer versions of cmake the FindThreads module has the THREADS_PREFER_PTHREAD_FLAG variable and creates a Threads::Threads import target. However, in order top remain compatible with older cmake version this is not used. --- CMakeLists.txt | 8 ++++++- cmake/FindPTHREAD.cmake | 38 ------------------------------ remmina-plugins/CMakeLists.txt | 2 +- remmina-plugins/rdp/CMakeLists.txt | 4 ++-- remmina/CMakeLists.txt | 7 ++---- 5 files changed, 12 insertions(+), 47 deletions(-) delete mode 100644 cmake/FindPTHREAD.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 4661256cf5..0e8d26bf29 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -191,7 +191,13 @@ add_custom_target(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake") find_required_package(GTK) -find_required_package(PTHREAD) + +set(CMAKE_THREAD_PREFER_PTHREAD TRUE) +find_package(Threads REQUIRED) +if(NOT CMAKE_USE_PTHREADS_INIT) + message(FATAL_ERROR "pthreads thread library not found") +endif() + find_suggested_package(GCRYPT) find_suggested_package(AVAHI) diff --git a/cmake/FindPTHREAD.cmake b/cmake/FindPTHREAD.cmake deleted file mode 100644 index cd22882cbf..0000000000 --- a/cmake/FindPTHREAD.cmake +++ /dev/null @@ -1,38 +0,0 @@ -# Remmina - The GTK+ Remote Desktop Client -# -# Copyright (C) 2011 Marc-Andre Moreau -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, -# Boston, MA 02110-1301, USA. - -find_package(PkgConfig) -pkg_check_modules(PC_PTHREAD pthread) -set(PTHREAD_DEFINITIONS ${PC_PTHREAD_CFLAGS_OTHER}) - -find_path(PTHREAD_INCLUDE_DIR NAMES pthread.h - HINTS ${PC_PTHREAD_INCLUDEDIR} ${PC_PTHREAD_INCLUDE_DIRS}) - -find_library(PTHREAD_LIBRARY NAMES pthread - HINTS ${PC_PTHREAD_LIBDIR} ${PC_PTHREAD_LIBRARY_DIRS}) - -include(FindPackageHandleStandardArgs) - -find_package_handle_standard_args(PTHREAD DEFAULT_MSG PTHREAD_LIBRARY PTHREAD_INCLUDE_DIR) - -set(PTHREAD_LIBRARIES ${PTHREAD_LIBRARY}) -set(PTHREAD_INCLUDE_DIRS ${PTHREAD_INCLUDE_DIR}) - -mark_as_advanced(PTHREAD_INCLUDE_DIR PTHREAD_LIBRARY) - diff --git a/remmina-plugins/CMakeLists.txt b/remmina-plugins/CMakeLists.txt index c5913c74d6..945755983d 100644 --- a/remmina-plugins/CMakeLists.txt +++ b/remmina-plugins/CMakeLists.txt @@ -44,7 +44,7 @@ set(APPICON16_EMBLEMS_DIR "${REMMINA_DATADIR}/icons/hicolor/16x16/emblems") set(APPICON22_EMBLEMS_DIR "${REMMINA_DATADIR}/icons/hicolor/22x22/emblems") set(REMMINA_COMMON_INCLUDE_DIRS ${GTK_INCLUDE_DIRS}) -set(REMMINA_COMMON_LIBRARIES ${GTK_LIBRARIES} ${PTHREAD_LIBRARY}) +set(REMMINA_COMMON_LIBRARIES ${GTK_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) find_suggested_package(LIBSSH) if(LIBSSH_FOUND) diff --git a/remmina-plugins/rdp/CMakeLists.txt b/remmina-plugins/rdp/CMakeLists.txt index c8a1885459..2a8a47a159 100644 --- a/remmina-plugins/rdp/CMakeLists.txt +++ b/remmina-plugins/rdp/CMakeLists.txt @@ -32,8 +32,8 @@ # files in the program, then also delete it here. -set(CMAKE_THREAD_PREFER_PTHREAD) -find_package(Threads) +set(CMAKE_THREAD_PREFER_PTHREAD TRUE) +find_package(Threads REQUIRED) find_package(X11) set(REMMINA_PLUGIN_RDP_SRCS diff --git a/remmina/CMakeLists.txt b/remmina/CMakeLists.txt index 3b6ed757b9..df6f580e74 100644 --- a/remmina/CMakeLists.txt +++ b/remmina/CMakeLists.txt @@ -123,6 +123,8 @@ find_package(X11) include_directories(${X11_INCLUDE_DIR}) target_link_libraries(remmina ${X11_LIBRARIES}) +target_link_libraries(remmina ${CMAKE_THREAD_LIBS_INIT}) + find_suggested_package(LIBSSH) if(LIBSSH_FOUND) add_definitions(-DHAVE_LIBSSH) @@ -130,11 +132,6 @@ if(LIBSSH_FOUND) target_link_libraries(remmina ${LIBSSH_LIBRARIES}) endif() -if(PTHREAD_FOUND) - include_directories(${PTHREAD_INCLUDE_DIRS}) - target_link_libraries(remmina ${PTHREAD_LIBRARIES}) -endif() - if(GCRYPT_FOUND) include_directories(${GCRYPT_INCLUDE_DIRS}) target_link_libraries(remmina ${GCRYPT_LIBRARIES})