I'm newbie with CMake. I tested it on Linux for a program I am making. This program uses (POSIX Threads lib), so in my CMakeList, I added :
find_package(Threads)
It works on Linux distribs (Arch, Mint, Ubuntu, ...), but now, I'm trying it in Windows32 (Visual Studio 9 2008), and I get this message during generation :
-- Looking for include file pthread.h - not found
(and when I compile output project file, pthread.h is indeed not found).
On Windows, considering "C:\pthread" as my pthread directory, I defined in path :
- "C:\pthread\include" (where resides the famous "pthread.h")
- "C:\pthread\" (in the case where CMake looks for an "include" somewhere)
But I still get the same error (even after deleted cache). I know I could "manually" add Pthread in my Project, or define some constants in CMakeList.txt, but I thinks it's not the principle of CMake : I could use the SAME "CMakeList.txt" on all systems, right ? So how can I tell to CMake "Hey ! Looks here ! Pthread is in this directory !". Maybe Cmake doesn't look in PATH, but in another environment variable, but I didn't find this information.
Thank you for reading.
EDIT : I don't know if it makes a difference, but my project is a C++ project (not C)
What I did, I edited the cmake file:
and
(I am using google test)
As far as i know, Pthreads is not natively supported on windows platform. Unless you use some thing like
win services for unix
Windows only has win32 threads.
However, this is a project which provides pthreads on windows
pthreads on win32
Apparently the CMAKE_USE_WIN32_THREADS_INIT is useful in context of all platforms. This variable is generated or initialised on invocation of findPackage(Threads), ideally it handles linking issues on all platforms in case thread library is required to be linked with executable. Basically it generates appropriate thread library name on platform unix like platforms and is empty on platform such as windows where explicit threading library is not required for linking. Reference: CMake findThreads https://cmake.org/cmake/help/v3.0/module/FindThreads.html?highlight=threads