FindThreads in CMake 3.24 mistakenly interprets MSVC as supporting -pthread
With CMake 3.24 the FindThreads.cmake finder has been updated, leading to issues on Windows:
- In CMake up to 3.23, the following checks failed and as a fallback Windows was assumed:
CHECK_INCLUDE_FILE("pthread.h" CMAKE_HAVE_PTHREAD_H)
[...]
if(CMAKE_THREAD_LIBS_INIT OR CMAKE_HAVE_LIBC_PTHREAD)
- In CMake 3.24 new macro functions are used, with the following NOT failing, so support for
-pthread
is assumed:
try_compile(THREADS_HAVE_PTHREAD_ARG C:/Work/VisualStudio/Projects/obs-studio/build2 C:/Tools/CMake/share/cmake-3.24/Modules/CheckForPthreads.c CMAKE_FLAGS -DLINK_LIBRARIES:STRING=-pthread OUTPUT_VARIABLE _cmake_check_pthreads_output )
Root cause seems to be that MSVC only emits a warning but not an error on an unsupported linker flag (output was generated on a German-language system):
LINK : warning LNK4044: Nicht erkannte Option /pthread; wird ignoriert. [C:\Work\VisualStudio\Projects\obs-studio\build2\CMakeFiles\CMakeTmp\cmTC_cc1ce.vcxproj
.
The check probably would fail if /WX
is also passed to the linker, alas it's "ignored" and compilation (and with it the entire check) succeeds, but the generated project will obviously fail to compile because pthreads
are not available.