18

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)

Neozaru
  • 1,109
  • 1
  • 10
  • 25
  • Since there is no standard paths for include and library files on windows CMake frequently needs to be helped a long when you run cmake-gui. A second option is that many finders look in environment variables. So for example to find ITK on my windows install I have ITK_DIR set in the cmd.exe session that I launched cmake-gui from. Same goes with lots of packages. Also there are options to find_package that you can use to help control where CMake looks to find your packages that can be a help. – drescherjm Nov 04 '12 at 13:59
  • Looking at the code for FindThreads in CMake 2.8.10 it looks like on windows it will default to use windows threads. – drescherjm Nov 06 '12 at 16:21
  • I have not tested that. See if CMAKE_USE_PTHREADS_INIT is set or just CMAKE_USE_WIN32_THREADS_INIT. – drescherjm Nov 06 '12 at 16:36

3 Answers3

5

What I did, I edited the cmake file:

option(CMAKE_USE_WIN32_THREADS_INIT "using WIN32 threads" ON)

and

option(gtest_disable_pthreads "Disable uses of pthreads in gtest." ON)

(I am using google test)

radato
  • 840
  • 9
  • 27
3

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

Saif Mulla
  • 47
  • 2
  • 5
1

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

fkl
  • 5,412
  • 4
  • 28
  • 68
  • err okay i thought you were talking about linux pthread package that you copied here. – fkl Nov 04 '12 at 13:10
  • 6
    No, I got pthreads for win32, with headers and pre-compiled packages. But CMake doesn't find it – Neozaru Nov 04 '12 at 13:16