FindMPI: doesn't work with nvcc (CUDA) because of the -pthread flag
The following
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
project(sandox LANGUAGES CXX CUDA)
find_package(MPI REQUIRED)
add_executable(mytest mytest.cu)
target_link_libraries(mytest PRIVATE MPI::MPI_CXX)
fails with
make VERBOSE=1 mytest
/usr/bin/cmake -H/home/teonnik/downloads/sandbox -B/home/teonnik/downloads/sandbox/build --check-build-system CMakeFiles/Makefile.cmake 0
make -f CMakeFiles/Makefile2 mytest
make[1]: Entering directory '/home/teonnik/downloads/sandbox/build'
/usr/bin/cmake -H/home/teonnik/downloads/sandbox -B/home/teonnik/downloads/sandbox/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/teonnik/downloads/sandbox/build/CMakeFiles 3
make -f CMakeFiles/Makefile2 CMakeFiles/mytest.dir/all
make[2]: Entering directory '/home/teonnik/downloads/sandbox/build'
make -f CMakeFiles/mytest.dir/build.make CMakeFiles/mytest.dir/depend
make[3]: Entering directory '/home/teonnik/downloads/sandbox/build'
cd /home/teonnik/downloads/sandbox/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/teonnik/downloads/sandbox /home/teonnik/downloads/sandbox /home/teonnik/downloads/sandbox/build /home/teonnik/downloads/sandbox/build /home/teonnik/downloads/sandbox/build/CMakeFiles/mytest.dir/DependInfo.cmake --color=
make[3]: Leaving directory '/home/teonnik/downloads/sandbox/build'
make -f CMakeFiles/mytest.dir/build.make CMakeFiles/mytest.dir/build
make[3]: Entering directory '/home/teonnik/downloads/sandbox/build'
[ 33%] Building CUDA object CMakeFiles/mytest.dir/mytest.cu.o
/opt/cuda/bin/nvcc -pthread -x cu -c /home/teonnik/downloads/sandbox/mytest.cu -o CMakeFiles/mytest.dir/mytest.cu.o
nvcc fatal : Unknown option 'pthread'
make[3]: *** [CMakeFiles/mytest.dir/build.make:63: CMakeFiles/mytest.dir/mytest.cu.o] Error 1
make[3]: Leaving directory '/home/teonnik/downloads/sandbox/build'
make[2]: *** [CMakeFiles/Makefile2:68: CMakeFiles/mytest.dir/all] Error 2
make[2]: Leaving directory '/home/teonnik/downloads/sandbox/build'
make[1]: *** [CMakeFiles/Makefile2:80: CMakeFiles/mytest.dir/rule] Error 2
make[1]: Leaving directory '/home/teonnik/downloads/sandbox/build'
make: *** [Makefile:118: mytest] Error 2
where the problem seems to be that -pthread
is passed to nvcc
via MPI::MPI_CXX
.
There were no problems in CMake 3.9
. What can I do to fix the issue?
My system:
Linux teonnik 4.15.15-1-ARCH #1 SMP PREEMPT Sat Mar 31 23:59:25 UTC 2018 x86_64 GNU/Linux
CMake version: 3.10.3
MPI: Open MPI v3.0.1