<div dir="ltr">cuda_add_executable(mytarget foo.cc OPTIONS -x cu)<div><br></div><div>Unfortunately, FindCUDA is setup to ignore any files that aren't .cu files.</div><div><br></div><div>CUDA_WRAP_SRCS()</div><div>...</div><div><div>  foreach(file ${ARGN})</div><div>    # Ignore any file marked as a HEADER_FILE_ONLY</div><div>    get_source_file_property(_is_header ${file} HEADER_FILE_ONLY)</div><div>    if(${file} MATCHES ".*\\.cu$" AND NOT _is_header)</div></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Nov 14, 2014 at 10:26 AM, Joan Puigcerver <span dir="ltr"><<a href="mailto:joapuipe@gmail.com" target="_blank">joapuipe@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I'm trying to use CMake with FindCUDA to compile a C++/CUDA code, and<br>
I am having a small issue with cuda_add_executable.<br>
<br>
One of my files has the .cc extension, but it may import headers which<br>
contain CUDA kernels definitions (depending on wheather I want to use<br>
CUDA or not). So, I need to compile it as a CUDA file. You can tell<br>
nvcc to ignore the file extension and use a particular language with<br>
the -x option. For instance:<br>
<br>
nvcc -x cu foo.cc<br>
<br>
Will force to compile foo.cc as a CUDA file.<br>
<br>
However, I don't know how to pass that compilation option to nvcc<br>
through cuda_add_executable. I tried to set it in the CUDA_NVCC_FLAGS<br>
variable, but it never gets passed to nvcc, since CMake calls directly<br>
the C++ compiler.<br>
<br>
Can anyone suggest how to force the -x option?<br>
<br>
PS: One dirty fix is to create a symlink from foo.cc to <a href="http://foo.cu" target="_blank">foo.cu</a>, and<br>
compile <a href="http://foo.cu" target="_blank">foo.cu</a> if CUDA is enable, or foo.cc if it is not. CMake works<br>
fine with this workaround, but I'd rather pass the -x option and keep<br>
my code base clean.<br>
--<br>
<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" target="_blank">http://cmake.org/cmake/help/training.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/cmake" target="_blank">http://public.kitware.com/mailman/listinfo/cmake</a><br>
</blockquote></div><br></div>