CMake: fixes to pthreads detection.

changes unnecessary check_c_source_runs to check_c_source_compiles,
removes the reduntant cross-compile check, and defines _GNU_SOURCE
for PTHREAD_MUTEX_RECURSIVE checks just like the autotools version.

Fixes: https://github.com/libsdl-org/SDL/issues/4262
Closes:  https://github.com/libsdl-org/SDL/pull/4282
This commit is contained in:
Ozkan Sezer 2021-04-23 01:56:10 +03:00 committed by Ozkan Sezer
parent ca969eb2be
commit 89a2980a6d

View File

@ -930,17 +930,13 @@ macro(CheckPTHREAD)
# Run some tests # Run some tests
set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") set(ORIG_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${PTHREAD_CFLAGS} ${PTHREAD_LDFLAGS}") set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${PTHREAD_CFLAGS} ${PTHREAD_LDFLAGS}")
if(CMAKE_CROSSCOMPILING) check_c_source_compiles("
set(HAVE_PTHREADS 1) #include <pthread.h>
else() int main(int argc, char** argv) {
check_c_source_runs(" pthread_attr_t type;
#include <pthread.h> pthread_attr_init(&type);
int main(int argc, char** argv) { return 0;
pthread_attr_t type; }" HAVE_PTHREADS)
pthread_attr_init(&type);
return 0;
}" HAVE_PTHREADS)
endif()
if(HAVE_PTHREADS) if(HAVE_PTHREADS)
set(SDL_THREAD_PTHREAD 1) set(SDL_THREAD_PTHREAD 1)
list(APPEND EXTRA_CFLAGS ${PTHREAD_CFLAGS}) list(APPEND EXTRA_CFLAGS ${PTHREAD_CFLAGS})
@ -949,6 +945,7 @@ macro(CheckPTHREAD)
list(APPEND SDL_LIBS ${PTHREAD_LDFLAGS}) list(APPEND SDL_LIBS ${PTHREAD_LDFLAGS})
check_c_source_compiles(" check_c_source_compiles("
#define _GNU_SOURCE 1
#include <pthread.h> #include <pthread.h>
int main(int argc, char **argv) { int main(int argc, char **argv) {
pthread_mutexattr_t attr; pthread_mutexattr_t attr;
@ -959,6 +956,7 @@ macro(CheckPTHREAD)
set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1) set(SDL_THREAD_PTHREAD_RECURSIVE_MUTEX 1)
else() else()
check_c_source_compiles(" check_c_source_compiles("
#define _GNU_SOURCE 1
#include <pthread.h> #include <pthread.h>
int main(int argc, char **argv) { int main(int argc, char **argv) {
pthread_mutexattr_t attr; pthread_mutexattr_t attr;