Mac 上的 CMake:找不到线程(缺少:Threads_FOUND)

CMake on Mac: Could NOT find Threads (missing: Threads_FOUND)

我正在尝试编译 LibPD,但收到 CMake 错误消息。我在网上搜索了 Mac 上处理此问题的解决方案,但发现 none 是过去 10 年的解决方案。我在我的 MacBook Pro 和我的 Mac 塔式桌面上都收到了这个错误。 :

我输入:

cmake .. -GXcode

我得到:

CMake Error at /Applications/CMake.app/Contents/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
  Could NOT find Threads (missing: Threads_FOUND)
Call Stack (most recent call first):
  /Applications/CMake.app/Contents/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
  /Applications/CMake.app/Contents/share/cmake-3.13/Modules/FindThreads.cmake:205 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  CMakeLists.txt:317 (find_package)

感谢您的帮助。

虽然我在 mojave 上没有遇到这个错误,但在 mac 上处理线程的一种方法是告诉 cmake 线程是内置的。

# assume built-in pthreads on MacOS
IF(APPLE)
    set(CMAKE_THREAD_LIBS_INIT "-lpthread")
    set(CMAKE_HAVE_THREADS_LIBRARY 1)
    set(CMAKE_USE_WIN32_THREADS_INIT 0)
    set(CMAKE_USE_PTHREADS_INIT 1)
    set(THREADS_PREFER_PTHREAD_FLAG ON)
ENDIF()