cea-hpc / wi4mpi

Wrapper interface for MPI
BSD 3-Clause "New" or "Revised" License
80 stars 15 forks source link

CMake Pthread erroneous error message #31

Closed spoutn1k closed 2 years ago

spoutn1k commented 2 years ago

Hey there,

I have been encountering an issue configuring the project, the following error preventing success:

$ cmake ..
-- The C compiler identification is GNU 12.1.1
-- The CXX compiler identification is GNU 12.1.1
[...]
-- Found Threads: TRUE  
CMake Error at CMakeLists.txt:129 (message):
  Be sure to have Pthread available on you system

-- Configuring incomplete, errors occurred!
See also "$HOME/Projects/wi4mpi/build/CMakeFiles/CMakeOutput.log".

I deleted the following check: https://github.com/cea-hpc/wi4mpi/blob/17e2911921541653a8d501966d185fecebdf1949/CMakeLists.txt#L127-L130

And configuration, compilation and execution worked. Looking at the CMake documentation, this value CMAKE_THREAD_LIBS_INIT underwent some change in the nearish past.

CMake 3.16.9:

The following variables are set

CMAKE_THREAD_LIBS_INIT     - the thread library

CMake 3.17.5:

CMAKE_THREAD_LIBS_INIT

    The thread library to use. This may be empty if the thread functions are provided by
the system libraries and no special flags are needed to use them.

Maybe I am missing something on my systems. This happened with CMake 3.23 and CMake 3.17 on a test machine and on a OLCF machine. I would tend to think that replacing CMAKE_THREAD_LIBS_INIT with Threads::Threads import target available on both versions would do the trick.

EDIT: It would appear Threads_FOUND can be true with Threads::Threads and CMAKE_THREAD_LIBS_INIT both empty. Backwards compatibility may be doable with a version check.

adrien-cotte commented 2 years ago

Hi @spoutn1k

Many thanks for your feedback. I am not able to reproduce (cmake 3.9.1, 3.20.3, 3.22.2), but I agree that Threads_FOUND does the job for cmake-3.17+.

Can you tell me if something like that works for you, please?

find_package(Threads)
if(${CMAKE_VERSION} VERSION_LESS "3.17.0")
    if(NOT CMAKE_THREAD_LIBS_INIT)
        message(FATAL_ERROR "Be sure to have Pthread available on you system")
    endif()
else()
    if(NOT Threads_FOUND)
        message(FATAL_ERROR "Be sure to have Pthread available on you system")
    endif()
endif()

Best, Adrien

spoutn1k commented 2 years ago

Interesting. I tested on some more machines in the lab using ubuntu containers, and some fail while some do not. It seemed like more recent versions of glib tended to fail.

The patch works ! Thanks for the quick response !

adrien-cotte commented 2 years ago

Great, I gonna add it to my current PR. You're welcome :smiley: :+1:!