Fortran+CUDA+Make fails to build with too many source files
I've been adding CUDA support to a large project and discovered that the build process fails with Make (but not Ninja) if there are too many source files. This is a minimal example to replicate the large project behavior:
# CMakeLists.txt cmake_minimum_required(VERSION 3.0) project(cuda LANGUAGES Fortran CXX CUDA) add_executable(main main.f90 tmp.cu) add_subdirectory(src)
# main.f90 end
tmp.cu is an empty file. The subdirectory "src" contains a thousand source files created using the script
[ -d src ] || mkdir src echo "target_sources(main PRIVATE" > src/CMakeLists.txt for i in $(eval echo {1..1000}); do filename="long_file_name_____________________$i.f90" echo "src/$filename" >> src/CMakeLists.txt cat > "src/$filename" <<EOF subroutine sub$i end subroutine sub$i EOF done echo ")" >> src/CMakeLists.txt
The script should be run from ${PROJECT_SOURCE_DIR}. When I run
cmake -DCMAKE_CUDA_FLAGS="-arch=sm_52" .. && make -j
the build ends with
... [ 99%] Building Fortran object CMakeFiles/main.dir/src/long_file_name_____________________992.f90.o [ 99%] Building Fortran object CMakeFiles/main.dir/src/long_file_name_____________________993.f90.o [ 99%] Building Fortran object CMakeFiles/main.dir/src/long_file_name_____________________995.f90.o [ 99%] Building Fortran object CMakeFiles/main.dir/src/long_file_name_____________________994.f90.o [ 99%] Building Fortran object CMakeFiles/main.dir/src/long_file_name_____________________997.f90.o [ 99%] Building Fortran object CMakeFiles/main.dir/src/long_file_name_____________________996.f90.o [ 99%] Building Fortran object CMakeFiles/main.dir/src/long_file_name_____________________998.f90.o [ 99%] Building Fortran object CMakeFiles/main.dir/src/long_file_name_____________________999.f90.o [ 99%] Building Fortran object CMakeFiles/main.dir/src/long_file_name_____________________1000.f90.o [ 99%] Linking CUDA device code CMakeFiles/main.dir/cmake_device_link.o nvcc fatal : Don't know what to do with '@CMakeFiles/main.dir/objects1.rsp' make[2]: *** [CMakeFiles/main.dir/build.make:26122: CMakeFiles/main.dir/cmake_device_link.o] Error 1 make[1]: *** [CMakeFiles/Makefile2:69: CMakeFiles/main.dir/all] Error 2 make: *** [Makefile:84: all] Error 2
With a lesser number of source files, the configuration and build steps finish normally. On my machine specifically, the threshold seems to be 923 source files in the subdirectory "src". The file objects1.rsp that nvcc complains about is a list of object files, with a total size of 68953 bytes. My guess is that some internal array runs out of bounds somewhere.
Because the Ninja generator generates the build files differently, the problematic file does not exist and the build finishes normally.
See CMakeFiles/3.10.2.tar.gz for additional details.