<div dir="ltr"><div>Hi Quang,</div><div><br></div><div>I believe this should be doable with setting the source file's LANGUAGE property ( <a href="https://cmake.org/cmake/help/latest/prop_sf/LANGUAGE.html">https://cmake.org/cmake/help/latest/prop_sf/LANGUAGE.html</a> ):</div><div><br></div><div>add_executable(foo_cuda foo.cpp)</div><div>set_property(SOURCE foo.cpp PROPERTY LANGUAGE CUDA)</div><div><br></div><div>Petr<br></div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, 27 Aug 2018 at 17:40, Quang Ha <<a href="mailto:quang.t.ha.20@gmail.com">quang.t.ha.20@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hi all,</div><div><br></div><div>With the new way CMake is treating CUDA codes, now we can do:</div><div><br></div><div>project(foo LANGUAGES CXX CUDA)<br></div><div><br></div><div>and can do:</div><div><br></div><div>add_executable(foo_cuda <a href="http://foo.cu" target="_blank">foo.cu</a>) # will use NVCC</div><div>add_executable(foo_cpp foo.cpp) # will use host compilers</div><div><br></div><div>Now since CUDA can take *.cpp files as extension (see <a href="https://stackoverflow.com/questions/26208784/cuda-cpp-files" target="_blank">https://stackoverflow.com/questions/26208784/cuda-cpp-files</a>), is there a away to flip the compiler using one single source files? Something along the line of:</div><div><br></div><div>if(CUDA_FOUND)</div><div> add_executable_with_nvcc(foo_cuda foo.cpp) # of course this doesn't exist<br></div><div>else(CUDA_FOUND)</div><div> add_executable_with_cpp(foo_cpp foo.cpp) # neither does this<br></div><div>endif(CUDA_FOUND)</div><div><br></div><div>Or would anyone suggest a work-around? With the help of add_definitions, I can manually compile a host and device executable - just need to integrate this final step into the project.</div><div><br></div><div>Thanks,</div><div>Quang<br></div><div><br></div></div>
-- <br>
<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" 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" rel="noreferrer" 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" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" 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" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="https://cmake.org/mailman/listinfo/cmake" rel="noreferrer" target="_blank">https://cmake.org/mailman/listinfo/cmake</a><br>
</blockquote></div>