# CUDA and CXX compiler - how to distinguish?

**URL:** https://discourse.cmake.org/t/cuda-and-cxx-compiler-how-to-distinguish/1990
**Category:** Usage
**Created:** [October 12, 2020, 8:05am UTC](https://discourse.cmake.org/t/cuda-and-cxx-compiler-how-to-distinguish/1990 "2020-10-12T08:05:54Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![hkhauke](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/f08c70/32.png) [@hkhauke](https://discourse.cmake.org/u/hkhauke)
#### Post date: [October 12, 2020, 8:05am UTC](https://discourse.cmake.org/t/cuda-and-cxx-compiler-how-to-distinguish/1990/1 "2020-10-12T08:05:54Z")

</div>

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

---

<div class="post-metadata">

### Author: ![hkhauke](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/f08c70/32.png) [@hkhauke](https://discourse.cmake.org/u/hkhauke)
#### Post date: [October 12, 2020, 8:57am UTC](https://discourse.cmake.org/t/cuda-and-cxx-compiler-how-to-distinguish/1990/2 "2020-10-12T08:57:15Z")

</div>

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/:](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.

---

<div class="post-metadata">

### Author: ![hkhauke](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/f08c70/32.png) [@hkhauke](https://discourse.cmake.org/u/hkhauke)
#### Post date: [October 12, 2020, 9:12am UTC](https://discourse.cmake.org/t/cuda-and-cxx-compiler-how-to-distinguish/1990/3 "2020-10-12T09:12:31Z")

</div>

Now, I got it:

$\<$\<COMPILE\_LANGUAGE:C\>:/wd4244\>  
$\<$\<COMPILE\_LANGUAGE:CXX\>:/wd4244\>

This seems to do what I need.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [November 25, 2020, 12:00am UTC](https://discourse.cmake.org/t/cuda-and-cxx-compiler-how-to-distinguish/1990/4 "2020-11-25T00:00:29Z")

</div>

> [@hkhauke](#):
>
> $\<$\<COMPILE\_LANGUAGE:C\>:/wd4244\>  
> $\<$\<COMPILE\_LANGUAGE:CXX\>:/wd4244\>

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).
