diff options
author | Brad King <brad.king@kitware.com> | 2017-11-17 19:46:53 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2017-11-20 18:51:25 (GMT) |
commit | 2ae880fa8f04a2026939b1df9613b64a301aa522 (patch) | |
tree | a0b87a17d369cb7b81360752bdbb8ab4d9ebdd29 /Tests/CudaOnly | |
parent | 2b7d59f3109483bfa45dc41e2a2f6a2f82addfec (diff) | |
download | CMake-2ae880fa8f04a2026939b1df9613b64a301aa522.zip CMake-2ae880fa8f04a2026939b1df9613b64a301aa522.tar.gz CMake-2ae880fa8f04a2026939b1df9613b64a301aa522.tar.bz2 |
Genex: Enable COMPILE_LANGUAGE for COMPILE_OPTIONS with Visual Studio
Since commit v3.9.0-rc4~3^2~1 (VS: Fix target_compile_options for CUDA,
2017-06-21), the evaluation of `COMPILE_LANGUAGE` receives the proper
language. The set of compile flags used for a target's C and C++
sources is based on the linker language. By default this is always the
C++ flags if any C++ sources appear in the target, and otherwise the C
flags. Therefore we can define the `COMPILE_LANGUAGE` generator
expression in `COMPILE_OPTIONS` to match the selected language.
This is not exactly the same as for other generators, but is the best VS
can do. It is also sufficient for many use cases since the set of
allowed flags for C and C++ is almost the same in Visual Studio.
Furthermore, since the VS generator moves many of the flags to
declarative `.vcxproj` elements, it will automatically avoid passing
C++ flags for C sources.
Issue: #17435
Diffstat (limited to 'Tests/CudaOnly')
-rw-r--r-- | Tests/CudaOnly/WithDefs/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Tests/CudaOnly/WithDefs/main.notcu | 12 |
2 files changed, 14 insertions, 0 deletions
diff --git a/Tests/CudaOnly/WithDefs/CMakeLists.txt b/Tests/CudaOnly/WithDefs/CMakeLists.txt index 9b82366..5bd93a4 100644 --- a/Tests/CudaOnly/WithDefs/CMakeLists.txt +++ b/Tests/CudaOnly/WithDefs/CMakeLists.txt @@ -32,6 +32,8 @@ add_executable(CudaOnlyWithDefs ${main}) target_compile_options(CudaOnlyWithDefs PRIVATE + -DCOMPILE_LANG_$<COMPILE_LANGUAGE> + -DLANG_IS_CUDA=$<COMPILE_LANGUAGE:CUDA> -Xcompiler=-DHOST_DEFINE $<$<CONFIG:DEBUG>:$<BUILD_INTERFACE:${debug_compile_flags}>> ) diff --git a/Tests/CudaOnly/WithDefs/main.notcu b/Tests/CudaOnly/WithDefs/main.notcu index d2eff3f..bfb3577 100644 --- a/Tests/CudaOnly/WithDefs/main.notcu +++ b/Tests/CudaOnly/WithDefs/main.notcu @@ -10,6 +10,18 @@ #error "PACKED_DEFINE not defined!" #endif +#ifndef COMPILE_LANG_CUDA +#error "COMPILE_LANG_CUDA not defined!" +#endif + +#ifndef LANG_IS_CUDA +#error "LANG_IS_CUDA not defined!" +#endif + +#if !LANG_IS_CUDA +#error "Expected LANG_IS_CUDA" +#endif + static __global__ void DetermineIfValidCudaDevice() { } |