<div dir="ltr"><div>Hi all,</div><div><br></div><div>The situation I am currently in is as followed. This is the directory for my project:</div><div><br></div><div>project<br></div><div>|----------CMakeLists.txt<br></div><div>|----------app</div><div>|            |--------CMakeLists.txt</div><div>|            |--------test_cuda</div><div>|                          |--------CMakeLists.txt</div><div>|                          |--------<a href="http://test_cuda.cu">test_cuda.cu</a></div><div>|----------src</div><div>|----------test</div><div>|----------doc</div><div><br></div><div>Inside project/app/CMakeLists.txt, it looks like this:</div><div>##<br></div><div>add_subdirectory(test_cuda)</div><div>##<br></div><div>and then inside project/app/test_cuda/CMakeLists.txt, it is:</div><div>##</div><div>find_package(CUDA REQUIRED)<br><br>if (CUDA_FOUND)<br>    # CUDA falgs<br>    include_directories(${CUDA_INCLUDE_DIRS})<br>    set(ALL_CUDA_LIBS ${CUDA_LIBRARIES} ${CUDA_cusparse_LIBRARY} ${CUDA_cublas_LIBRARY})<br>    set(LIBS ${LIBS} ${ALL_CUDA_LIBS})<br>    set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};--maxrregcount 32)<br>    # set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};-gencode arch=compute_70,code=sm_70)<br><br>    # Link to executable<br>    cuda_add_executable(test_cuda <a href="http://test_cuda.cu">test_cuda.cu</a>)<br>    # set_target_properties(test_cuda PROPERTIES COMPILE_FLAGS "-DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_CUDA")<br>    set_target_properties(test_cuda PROPERTIES CUDA_SEPARABLE_COMPILATION ON)<br>    set_target_properties(test_cuda PROPERTIES CUDA_PROPAGATE_HOST_FLAGS OFF)<br>    target_link_libraries(test_cuda ${LIBS} ${EXTRA_LIBS})<br>endif()<br></div><div>##</div><div><br></div><div>There is nothing special inside <a href="http://test_cuda.cu">test_cuda.cu</a> - since I just want to test cmake integration:</div><div>##</div><div>#include <stdio.h><br>#include <fstream><br><br>__global__<br>void kernel (void){<br>}<br><br>int main(void ) {<br>  kernel<<<1,1>>>();<br>  return 0;<br>}<br></div><div>##</div><div><br></div><div>I got an error when running cmake with this:</div><div><br></div><div>###<br></div><div>[ 75%] Building NVCC (Device) object app/test_cuda/CMakeFiles/test_cuda.dir/test_cuda_generated_test_cuda.cu.o<br>/projects/opt/centos7/gcc/6.4.0/include/c++/6.4.0/bits/stl_algobase.h(200): error: statement may not appear in a constexpr function<br><br>/projects/opt/centos7/gcc/6.4.0/include/c++/6.4.0/bits/stl_algobase.h(202): error: a constexpr function must contain exactly one return statement<br><br>/projects/opt/centos7/gcc/6.4.0/include/c++/6.4.0/bits/stl_algobase.h(224): error: statement may not appear in a constexpr function<br><br>/projects/opt/centos7/gcc/6.4.0/include/c++/6.4.0/bits/stl_algobase.h(226): error: a constexpr function must contain exactly one return statement<br><br>/projects/opt/centos7/gcc/6.4.0/include/c++/6.4.0/bits/stl_algobase.h(246): error: statement may not appear in a constexpr function<br><br>/projects/opt/centos7/gcc/6.4.0/include/c++/6.4.0/bits/stl_algobase.h(248): error: a constexpr function must contain exactly one return statement<br><br>/projects/opt/centos7/gcc/6.4.0/include/c++/6.4.0/bits/stl_algobase.h(268): error: statement may not appear in a constexpr function<br><br>/projects/opt/centos7/gcc/6.4.0/include/c++/6.4.0/bits/stl_algobase.h(270): error: a constexpr function must contain exactly one return statement<br><br>8 errors detected in the compilation of "/tmp/tmpxft_00003241_00000000-4_test_cuda.cpp4.ii".<br>CMake Error at test_cuda_generated_test_cuda.cu.o.Release.cmake:279 (message):<br>  Error generating file<br>  /home/qth20/develop/project/build/app/test_cuda/CMakeFiles/test_cuda.dir//./test_cuda_generated_test_cuda.cu.o<br>###</div><div><br></div><div>Checking with make VERBOSE=1:</div><div><br></div><div>##</div><div>[ 75%] Building NVCC (Device) object app/test_cuda/CMakeFiles/test_cuda.dir/test_cuda_generated_test_cuda.cu.o<br>cd /home/qth20/develop/project/build/app/test_cuda/CMakeFiles/test_cuda.dir && /projects/opt/centos7/cmake/3.11.1/bin/cmake -E make_directory /home/qth20/develop/project/build/app/test_cuda/CMakeFiles/test_cuda.dir//.<br>cd /home/qth20/develop/project/build/app/test_cuda/CMakeFiles/test_cuda.dir && /projects/opt/centos7/cmake/3.11.1/bin/cmake -D verbose:BOOL=1 -D build_configuration:STRING=Release -D generated_file:STRING=/home/qth20/develop/project/build/app/test_cuda/CMakeFiles/test_cuda.dir//./test_cuda_generated_test_cuda.cu.o -D generated_cubin_file:STRING=/home/qth20/develop/project/build/app/test_cuda/CMakeFiles/test_cuda.dir//./test_cuda_generated_test_cuda.cu.o.cubin.txt -P /home/qth20/develop/project/build/app/test_cuda/CMakeFiles/test_cuda.dir//test_cuda_generated_test_cuda.cu.o.Release.cmake<br>-- Removing /home/qth20/develop/project/build/app/test_cuda/CMakeFiles/test_cuda.dir//./test_cuda_generated_test_cuda.cu.o<br>/projects/opt/centos7/cmake/3.11.1/bin/cmake -E remove /home/qth20/develop/project/build/app/test_cuda/CMakeFiles/test_cuda.dir//./test_cuda_generated_test_cuda.cu.o<br>-- Generating dependency file: /home/qth20/develop/project/build/app/test_cuda/CMakeFiles/test_cuda.dir//test_cuda_generated_test_cuda.cu.o.NVCC-depend<br>/projects/opt/centos7/cuda/9.1/bin/nvcc -M -D__CUDACC__ /home/qth20/develop/project/app/test_cuda/<a href="http://test_cuda.cu">test_cuda.cu</a> -o /home/qth20/develop/project/build/app/test_cuda/CMakeFiles/test_cuda.dir//test_cuda_generated_test_cuda.cu.o.NVCC-depend -ccbin /projects/opt/centos7/gcc/6.4.0/bin/gcc -m64 -DTHRUST -DTHRUST_HOST_SYSTEM=THRUST_HOST_SYSTEM_CPP -DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_CUDA "-DCUDA_CALLABLE=\"__host__ __device__\"" -Xcompiler ,\"-std=c++14\",\"-O3\",\"-DNDEBUG\" --std=c++11 --expt-relaxed-constexpr -Xcompiler -fPIC --maxrregcount 32 -DNVCC -I/projects/opt/centos7/cuda/9.1/include -I/home/qth20/develop/project -I/home/qth20/develop/project/build -I/home/qth20/develop/project/cinch/logging       -I/projects/opt/centos7/openmpi/3.1.0-gcc_8.1.0/include    /UnitTest++<br>-- Generating temporary cmake readable file: /home/qth20/develop/project/build/app/test_cuda/CMakeFiles/test_cuda.dir//test_cuda_generated_test_cuda.cu.o.depend.tmp<br>/projects/opt/centos7/cmake/3.11.1/bin/cmake -D input_file:FILEPATH=/home/qth20/develop/project/build/app/test_cuda/CMakeFiles/test_cuda.dir//test_cuda_generated_test_cuda.cu.o.NVCC-depend -D output_file:FILEPATH=/home/qth20/develop/project/build/app/test_cuda/CMakeFiles/test_cuda.dir//test_cuda_generated_test_cuda.cu.o.depend.tmp -D verbose=1 -P /projects/opt/centos7/cmake/3.11.1/share/cmake-3.11/Modules/FindCUDA/make2cmake.cmake<br>-- Copy if different /home/qth20/develop/project/build/app/test_cuda/CMakeFiles/test_cuda.dir//test_cuda_generated_test_cuda.cu.o.depend.tmp to /home/qth20/develop/project/build/app/test_cuda/CMakeFiles/test_cuda.dir//test_cuda_generated_test_cuda.cu.o.depend<br>/projects/opt/centos7/cmake/3.11.1/bin/cmake -E copy_if_different /home/qth20/develop/project/build/app/test_cuda/CMakeFiles/test_cuda.dir//test_cuda_generated_test_cuda.cu.o.depend.tmp /home/qth20/develop/project/build/app/test_cuda/CMakeFiles/test_cuda.dir//test_cuda_generated_test_cuda.cu.o.depend<br>-- Removing /home/qth20/develop/project/build/app/test_cuda/CMakeFiles/test_cuda.dir//test_cuda_generated_test_cuda.cu.o.depend.tmp and /home/qth20/develop/project/build/app/test_cuda/CMakeFiles/test_cuda.dir//test_cuda_generated_test_cuda.cu.o.NVCC-depend<br>/projects/opt/centos7/cmake/3.11.1/bin/cmake -E remove /home/qth20/develop/project/build/app/test_cuda/CMakeFiles/test_cuda.dir//test_cuda_generated_test_cuda.cu.o.depend.tmp /home/qth20/develop/project/build/app/test_cuda/CMakeFiles/test_cuda.dir//test_cuda_generated_test_cuda.cu.o.NVCC-depend<br>-- Generating /home/qth20/develop/project/build/app/test_cuda/CMakeFiles/test_cuda.dir//./test_cuda_generated_test_cuda.cu.o<br>/projects/opt/centos7/cuda/9.1/bin/nvcc /home/qth20/develop/project/app/test_cuda/<a href="http://test_cuda.cu">test_cuda.cu</a> -c -o /home/qth20/develop/project/build/app/test_cuda/CMakeFiles/test_cuda.dir//./test_cuda_generated_test_cuda.cu.o -ccbin /projects/opt/centos7/gcc/6.4.0/bin/gcc -m64 -DTHRUST -DTHRUST_HOST_SYSTEM=THRUST_HOST_SYSTEM_CPP -DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_CUDA "-DCUDA_CALLABLE=\"__host__ __device__\"" -Xcompiler ,\"-std=c++14\",\"-O3\",\"-DNDEBUG\" --std=c++11 --expt-relaxed-constexpr -Xcompiler -fPIC --maxrregcount 32 -DNVCC -I/projects/opt/centos7/cuda/9.1/include -I/home/qth20/develop/project -I/home/qth20/develop/project/build -I/home/qth20/develop/project/cinch/logging       -I/projects/opt/centos7/openmpi/3.1.0-gcc_8.1.0/include    /UnitTest++ <br></div><div>[Error]<br></div>##<br><div><br></div><div>It looks like all the flags used in gcc is passed directly into nvcc. Is there a way to turn this off? <br></div><div><br></div><div>Thanks,</div><div>Quang<br></div></div>