CUDA and CXX compiler - how to distinguish?

Hi,
I use the latest options to integrate CUDA and CPP code in one library by setting enable_language(CUDA). In my project, I apply typical options supported by CMAKE such as POSITION_INDEPENDENT_CODE which is nicely integrated in CMAKE.

However, I also use some compiler specific flags such as “-Wno-psabi”. These flags are known by GCC but lead to an error message when invoking the NVCC.

My question: how am I suppose to provide flags for GCC which are not in use by the NVCC? It seems that NVCC is always using the same flags as specific in CMAKE_CXX_FLAGS.

Thank you and best regards
Hauke

Ok, I have found some insides myself. Meanwhile I switched platform to WIndows but the problem persists:

  1. Involve “normal” cpp and “CUDA” cu files in one project.
  2. Suppress warning by using MSVC option /wd4244
  3. Found that I may specify compile options for a compiler using cmake generator expressions, https://foonathan.net/2018/10/cmake-warnings/: $<$<CXX_COMPILER_ID:MSVC>:/wd4244

In all “normal” cpp files, during compilation, that option is set. In the call to the “CUDA” compilation, however, the /wd4244 exression is ALSO added which then breaks the compilation command.

I had expected that /wd4244 is not added to NVCC command due to the generator expression.

Now, I got it:

$<$<COMPILE_LANGUAGE:C>:/wd4244>
$<$<COMPILE_LANGUAGE:CXX>:/wd4244>

This seems to do what I need.

Note that you can use $<$<COMPILE_LANGUAGE:C,CXX>:/wd4244> to simplify this. You may also want to consider possibly using $<COMPILE_LANG_AND_ID:C,MSVC> (this does not support multiple languages).