diff options
author | Alan W. Irwin <airwin@users.sourceforge.net> | 2019-09-23 14:42:30 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2019-09-23 14:43:27 (GMT) |
commit | de5f123d3afd2dc4b82c66f760615e4034675418 (patch) | |
tree | 7b4f2b0e7dbeeb9c2f2f8988f322afaadf45a250 /Modules | |
parent | 3d1fb997e5322d6b6e7c4b0b467792995428ebb7 (diff) | |
download | CMake-de5f123d3afd2dc4b82c66f760615e4034675418.zip CMake-de5f123d3afd2dc4b82c66f760615e4034675418.tar.gz CMake-de5f123d3afd2dc4b82c66f760615e4034675418.tar.bz2 |
FindThreads: Do not hard-code '-l' flag on library name
When not using the `-pthread` flag we instead return a library to link
by name. Previously we hard-coded the `-l` flag before the library
name. When used with `target_link_libraries`, the hard-coded `-l` flag
is preserved rather than transformed into the link option preferred by
the toolchain in use. Drop the explicit `-l` part to let CMake's
generators produce the proper way to link the threads library for the
current toolchain.
Fixes: #19747
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/FindThreads.cmake | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/Modules/FindThreads.cmake b/Modules/FindThreads.cmake index b0c91b2..d39fe33 100644 --- a/Modules/FindThreads.cmake +++ b/Modules/FindThreads.cmake @@ -77,7 +77,7 @@ macro(_check_threads_lib LIBNAME FUNCNAME VARNAME) if(NOT Threads_FOUND) CHECK_LIBRARY_EXISTS(${LIBNAME} ${FUNCNAME} "" ${VARNAME}) if(${VARNAME}) - set(CMAKE_THREAD_LIBS_INIT "-l${LIBNAME}") + set(CMAKE_THREAD_LIBS_INIT "${LIBNAME}") set(CMAKE_HAVE_THREADS_LIBRARY 1) set(Threads_FOUND TRUE) endif() @@ -88,7 +88,7 @@ endmacro() # Do NOT even think about using it outside of this file! macro(_check_pthreads_flag) if(NOT Threads_FOUND) - # If we did not found -lpthread, -lpthread, or -lthread, look for -pthread + # If we did not find a thread library look for -pthread compiler option. if(NOT DEFINED THREADS_HAVE_PTHREAD_ARG) message(STATUS "Check if compiler accepts -pthread") if(CMAKE_C_COMPILER_LOADED) @@ -164,7 +164,7 @@ if(CMAKE_HAVE_PTHREAD_H) _check_threads_lib(pthreads pthread_create CMAKE_HAVE_PTHREADS_CREATE) _check_threads_lib(pthread pthread_create CMAKE_HAVE_PTHREAD_CREATE) if(CMAKE_SYSTEM_NAME MATCHES "SunOS") - # On sun also check for -lthread + # On sun also check for thread library with thr_create _check_threads_lib(thread thr_create CMAKE_HAVE_THR_CREATE) endif() endif() @@ -195,7 +195,7 @@ if(CMAKE_USE_PTHREADS_INIT) # are available. CHECK_LIBRARY_EXISTS(cma pthread_attr_create "" CMAKE_HAVE_HP_CMA) if(CMAKE_HAVE_HP_CMA) - set(CMAKE_THREAD_LIBS_INIT "-lcma") + set(CMAKE_THREAD_LIBS_INIT "cma") set(CMAKE_HP_PTHREADS_INIT 1) set(Threads_FOUND TRUE) endif() |