Re: [CMake] CMake specify using either NVCC or host compilers with add_executable

2018-08-27 Thread Petr Kmoch
Hi Quang,

I believe this should be doable with setting the source file's LANGUAGE
property ( https://cmake.org/cmake/help/latest/prop_sf/LANGUAGE.html ):

add_executable(foo_cuda foo.cpp)
set_property(SOURCE foo.cpp PROPERTY LANGUAGE CUDA)

Petr

On Mon, 27 Aug 2018 at 17:40, Quang Ha  wrote:

> Hi all,
>
> With the new way CMake is treating CUDA codes, now we can do:
>
> project(foo LANGUAGES CXX CUDA)
>
> and can do:
>
> add_executable(foo_cuda foo.cu) # will use NVCC
> add_executable(foo_cpp foo.cpp) # will use host compilers
>
> Now since CUDA can take *.cpp files as extension (see
> https://stackoverflow.com/questions/26208784/cuda-cpp-files), is there a
> away to flip the compiler using one single source files? Something along
> the line of:
>
> if(CUDA_FOUND)
>   add_executable_with_nvcc(foo_cuda foo.cpp) # of course this doesn't exist
> else(CUDA_FOUND)
>   add_executable_with_cpp(foo_cpp foo.cpp) # neither does this
> endif(CUDA_FOUND)
>
> 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.
>
> Thanks,
> Quang
>
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> https://cmake.org/mailman/listinfo/cmake
>
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake


[CMake] CMake specify using either NVCC or host compilers with add_executable

2018-08-27 Thread Quang Ha
Hi all,

With the new way CMake is treating CUDA codes, now we can do:

project(foo LANGUAGES CXX CUDA)

and can do:

add_executable(foo_cuda foo.cu) # will use NVCC
add_executable(foo_cpp foo.cpp) # will use host compilers

Now since CUDA can take *.cpp files as extension (see
https://stackoverflow.com/questions/26208784/cuda-cpp-files), is there a
away to flip the compiler using one single source files? Something along
the line of:

if(CUDA_FOUND)
  add_executable_with_nvcc(foo_cuda foo.cpp) # of course this doesn't exist
else(CUDA_FOUND)
  add_executable_with_cpp(foo_cpp foo.cpp) # neither does this
endif(CUDA_FOUND)

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.

Thanks,
Quang
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake