mirror of
https://github.com/Kitware/CMake.git
synced 2026-04-24 07:08:38 -05:00
Genex: Enable COMPILE_LANGUAGE for COMPILE_DEFINITIONS with VS and Xcode
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_DEFINITIONS` to match the selected language. This is not exactly the same as for other generators, but is the best VS and Xcode can do. It is also sufficient for many use cases since the set of definitions for C and C++ is frequently similar but may be distinct from those for other languages like CUDA. Issue: #17435
This commit is contained in:
@@ -32,8 +32,8 @@ add_executable(CudaOnlyWithDefs ${main})
|
||||
|
||||
target_compile_options(CudaOnlyWithDefs
|
||||
PRIVATE
|
||||
-DCOMPILE_LANG_$<COMPILE_LANGUAGE>
|
||||
-DLANG_IS_CUDA=$<COMPILE_LANGUAGE:CUDA>
|
||||
-DFLAG_COMPILE_LANG_$<COMPILE_LANGUAGE>
|
||||
-DFLAG_LANG_IS_CUDA=$<COMPILE_LANGUAGE:CUDA>
|
||||
-Xcompiler=-DHOST_DEFINE
|
||||
$<$<CONFIG:DEBUG>:$<BUILD_INTERFACE:${debug_compile_flags}>>
|
||||
)
|
||||
@@ -41,6 +41,8 @@ target_compile_options(CudaOnlyWithDefs
|
||||
target_compile_definitions(CudaOnlyWithDefs
|
||||
PRIVATE
|
||||
$<$<CONFIG:RELEASE>:$<BUILD_INTERFACE:${release_compile_defs}>>
|
||||
-DDEF_COMPILE_LANG_$<COMPILE_LANGUAGE>
|
||||
-DDEF_LANG_IS_CUDA=$<COMPILE_LANGUAGE:CUDA>
|
||||
)
|
||||
|
||||
if(APPLE)
|
||||
|
||||
@@ -10,16 +10,28 @@
|
||||
#error "PACKED_DEFINE not defined!"
|
||||
#endif
|
||||
|
||||
#ifndef COMPILE_LANG_CUDA
|
||||
#error "COMPILE_LANG_CUDA not defined!"
|
||||
#ifndef FLAG_COMPILE_LANG_CUDA
|
||||
#error "FLAG_COMPILE_LANG_CUDA not defined!"
|
||||
#endif
|
||||
|
||||
#ifndef LANG_IS_CUDA
|
||||
#error "LANG_IS_CUDA not defined!"
|
||||
#ifndef FLAG_LANG_IS_CUDA
|
||||
#error "FLAG_LANG_IS_CUDA not defined!"
|
||||
#endif
|
||||
|
||||
#if !LANG_IS_CUDA
|
||||
#error "Expected LANG_IS_CUDA"
|
||||
#if !FLAG_LANG_IS_CUDA
|
||||
#error "Expected FLAG_LANG_IS_CUDA"
|
||||
#endif
|
||||
|
||||
#ifndef DEF_COMPILE_LANG_CUDA
|
||||
#error "DEF_COMPILE_LANG_CUDA not defined!"
|
||||
#endif
|
||||
|
||||
#ifndef DEF_LANG_IS_CUDA
|
||||
#error "DEF_LANG_IS_CUDA not defined!"
|
||||
#endif
|
||||
|
||||
#if !DEF_LANG_IS_CUDA
|
||||
#error "Expected DEF_LANG_IS_CUDA"
|
||||
#endif
|
||||
|
||||
static __global__ void DetermineIfValidCudaDevice()
|
||||
|
||||
Reference in New Issue
Block a user