Discussion:
[CMake] how do you allow CMAKE_CUDA_COMPILER to be optional via project LANGUAGE?
Quang Ha
2018-08-28 17:06:58 UTC
Permalink
Hi all,

So this question is again about project(foo LANGUAGES CXX CUDA). Is it
possible to switch off CUDA if Cmake couldn't find CUDA compiler? I.e.
something along the line:

if (CUDA_FOUND)
set_language_to_CUDA_and_CXX
else(CUDA_FOUND)
set_language_to_CXX_only
endif(CUDA_FOUND)

The main reason is I don't want CMake to fail when CUDA compiler isn't
available. Rather, it should continue to compile the source files using CPP
compilers instead.

Thanks,
Quang
Eric Noulard
2018-08-28 17:28:38 UTC
Permalink
Post by Quang Ha
Hi all,
So this question is again about project(foo LANGUAGES CXX CUDA). Is it
possible to switch off CUDA if Cmake couldn't find CUDA compiler? I.e.
May be you can only:

project(foo LANGUAGES CXX)

then

include(CheckLanguage)
check_language(CUDA)
if(CMAKE_CUDA_COMPILER)
enable_language(CUDA)
else()
message(STATUS "No CUDA compiler found")
endif()

see doc:
https://cmake.org/cmake/help/latest/module/CheckLanguage.html


Eric
Post by Quang Ha
if (CUDA_FOUND)
set_language_to_CUDA_and_CXX
else(CUDA_FOUND)
set_language_to_CXX_only
endif(CUDA_FOUND)
The main reason is I don't want CMake to fail when CUDA compiler isn't
available. Rather, it should continue to compile the source files using CPP
compilers instead.
Thanks,
Quang
--
Powered by www.kitware.com
http://www.cmake.org/Wiki/CMake_FAQ
Kitware offers various services to support the CMake community. For more
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
https://cmake.org/mailman/listinfo/cmake
--
Eric
Robert Maynard
2018-08-28 18:36:39 UTC
Permalink
The way Eric suggest with check_language is what I use when I want to
conditionally support CUDA.
Post by Eric Noulard
Post by Quang Ha
Hi all,
So this question is again about project(foo LANGUAGES CXX CUDA). Is it
possible to switch off CUDA if Cmake couldn't find CUDA compiler? I.e.
project(foo LANGUAGES CXX)
then
include(CheckLanguage)
check_language(CUDA)
if(CMAKE_CUDA_COMPILER)
enable_language(CUDA)
else()
message(STATUS "No CUDA compiler found")
endif()
https://cmake.org/cmake/help/latest/module/CheckLanguage.html
Eric
Post by Quang Ha
if (CUDA_FOUND)
set_language_to_CUDA_and_CXX
else(CUDA_FOUND)
set_language_to_CXX_only
endif(CUDA_FOUND)
The main reason is I don't want CMake to fail when CUDA compiler isn't
available. Rather, it should continue to compile the source files using CPP
compilers instead.
Thanks,
Quang
--
Powered by www.kitware.com
http://www.cmake.org/Wiki/CMake_FAQ
Kitware offers various services to support the CMake community. For more
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
https://cmake.org/mailman/listinfo/cmake
--
Eric
--
Powered by www.kitware.com
http://www.cmake.org/Wiki/CMake_FAQ
Kitware offers various services to support the CMake community. For more
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
https://cmake.org/mailman/listinfo/cmake
Quang Ha
2018-08-28 18:52:44 UTC
Permalink
It works perfectly - thanks!

QT
Post by Robert Maynard
The way Eric suggest with check_language is what I use when I want to
conditionally support CUDA.
Post by Eric Noulard
Post by Quang Ha
Hi all,
So this question is again about project(foo LANGUAGES CXX CUDA). Is it
possible to switch off CUDA if Cmake couldn't find CUDA compiler? I.e.
project(foo LANGUAGES CXX)
then
include(CheckLanguage)
check_language(CUDA)
if(CMAKE_CUDA_COMPILER)
enable_language(CUDA)
else()
message(STATUS "No CUDA compiler found")
endif()
https://cmake.org/cmake/help/latest/module/CheckLanguage.html
Eric
Post by Quang Ha
if (CUDA_FOUND)
set_language_to_CUDA_and_CXX
else(CUDA_FOUND)
set_language_to_CXX_only
endif(CUDA_FOUND)
The main reason is I don't want CMake to fail when CUDA compiler isn't
available. Rather, it should continue to compile the source files using CPP
compilers instead.
Thanks,
Quang
--
Powered by www.kitware.com
http://www.cmake.org/Wiki/CMake_FAQ
Kitware offers various services to support the CMake community. For more
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
https://cmake.org/mailman/listinfo/cmake
--
Eric
--
Powered by www.kitware.com
http://www.cmake.org/Wiki/CMake_FAQ
Kitware offers various services to support the CMake community. For more
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
https://cmake.org/mailman/listinfo/cmake
Loading...