Building VTK and PThreads vs Win32 Threads
Problem
I am trying to build VTK with CUDA support using CMake. I have run into an error I'm not sure how to resolve:
CMake Error at Common/Core/CMakeLists.txt:306 (message):
Failed to determine the thread implementation in use by the compiler.
The CMakeLists.txt
in this folder at this section is attempting to determine whether to use Win32 Threads or PThreads:
Common/Core/CMakeLists.txt, Lines 288-325
vtk_module_find_package(
PACKAGE Threads)
set(VTK_MAX_THREADS "64" CACHE STRING
"Max number of threads vtkMultiThreader will allocate.")
mark_as_advanced(VTK_MAX_THREADS)
if (CMAKE_USE_PTHREADS_INIT AND CMAKE_USE_WIN32_THREADS_INIT)
if (DEFINED _vtk_thread_impl_output)
set(thread_impl_output "${_vtk_thread_impl_output}")
else ()
execute_process(
COMMAND "${CMAKE_C_COMPILER}" -v
OUTPUT_VARIABLE thread_impl_output
ERROR_VARIABLE thread_impl_output
RESULT_VARIABLE result
TIMEOUT 10)
if (result)
message(FATAL_ERROR
"Failed to determine the thread implementation in use by the "
"compiler.")
endif ()
string (REGEX REPLACE ".*Thread model: \((posix|win32)\).*" "\\1" thread_impl_output "${thread_impl_output}")
endif ()
set(_vtk_thread_impl_output "${thread_impl_output}"
CACHE INTERNAL "thread model detection")
if (thread_impl_output MATCHES "posix")
set(VTK_USE_PTHREADS 1)
elseif (thread_impl_output MATCHES "win32")
set(VTK_USE_WIN32_THREADS 1)
else ()
set(VTK_USE_PTHREADS 1)
endif ()
elseif (CMAKE_USE_PTHREADS_INIT)
set(VTK_USE_PTHREADS 1)
elseif (CMAKE_USE_WIN32_THREADS_INIT)
set(VTK_USE_WIN32_THREADS 1)
endif ()
I use vcpkg
and installed pthread
and pthreads
, which is probably why it's getting confused, but is there a way to specify in CMake-GUI to use Windows threads?
Currently, my solution is to add the lines
set(CMAKE_USE_PTHREADS_INIT 0)
set(CMAKE_USE_WIN32_THREADS_INIT 1)
after
vtk_module_find_package(
PACKAGE Threads)
in the CMakeLists.txt
file.