summaryrefslogtreecommitdiffstats
path: root/cmake
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@qt.io>2022-01-04 10:30:04 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-01-08 20:02:21 +0000
commit9794fc4e54806a1fc97bc8af21a5851de4da10f3 (patch)
tree7eb958ed12d76a894ddf9ea85251e7146dbad813 /cmake
parent4ffbe5626a29a9e364cf6065206b08beacfecae5 (diff)
CMake: Add C/C++ compiler options to C/C++ sources only
When compiling CUDA sources in a user project, the Qt6::Platform target would pull in C/C++ related compiler flags, leading to compiler errors. Make sure that we only add those flags to C/C++ source files. Fixes: QTBUG-99548 Change-Id: Idbccd65fe8f66abd1da3fce95e563065d1ed3cc6 Reviewed-by: Kai Koehne <kai.koehne@qt.io> (cherry picked from commit ae294a42f001a0fe8191f20627f22ddd0e8358ed) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'cmake')
-rw-r--r--cmake/QtFlagHandlingHelpers.cmake9
1 files changed, 7 insertions, 2 deletions
diff --git a/cmake/QtFlagHandlingHelpers.cmake b/cmake/QtFlagHandlingHelpers.cmake
index 9c5aee5d90..b36f6cff0c 100644
--- a/cmake/QtFlagHandlingHelpers.cmake
+++ b/cmake/QtFlagHandlingHelpers.cmake
@@ -235,7 +235,8 @@ function(qt_set_msvc_cplusplus_options target visibility)
# For MSVC we need to explicitly pass -Zc:__cplusplus to get correct __cplusplus.
# Check qt_config_compile_test for more info.
if(MSVC AND MSVC_VERSION GREATER_EQUAL 1913)
- target_compile_options("${target}" ${visibility} "-Zc:__cplusplus" "-permissive-")
+ set(flags "-Zc:__cplusplus" "-permissive-")
+ target_compile_options("${target}" ${visibility} "$<$<COMPILE_LANGUAGE:CXX>:${flags}>")
endif()
endfunction()
@@ -247,7 +248,11 @@ function(qt_enable_utf8_sources target)
if(utf8_flags)
# Allow opting out by specifying the QT_NO_UTF8_SOURCE target property.
- set(genex_condition "$<NOT:$<BOOL:$<TARGET_PROPERTY:QT_NO_UTF8_SOURCE>>>")
+ set(opt_out_condition "$<NOT:$<BOOL:$<TARGET_PROPERTY:QT_NO_UTF8_SOURCE>>>")
+ # Only set the compiler option for C and C++.
+ set(language_condition "$<COMPILE_LANGUAGE:C,CXX>")
+ # Compose the full condition.
+ set(genex_condition "$<AND:${opt_out_condition},${language_condition}>")
set(utf8_flags "$<${genex_condition}:${utf8_flags}>")
target_compile_options("${target}" INTERFACE "${utf8_flags}")
endif()