mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-06 13:51:33 -06:00
Original behaviour would unconditionally enable WinRT for all projects so source file flag generation code can acknowledge WinRT being present and disable it for C language source files. An unintentional result of that approach is that WinRT is enabled for ALL projects, including C++ projects/source files with no way to disable it Instead use `CMAKE_VS_WINRT_BY_DEFAULT` as a hint that the platform is WinRT-by-default and set global `CompileAsWinRT` flag to `false` unless it was explicitly requested by either `WINRT_COMPONENT` option or `/ZW` compilation option - similar to what Windows Phone/Windows Store platform logic does In case WinRT compilation is enabled for a project by either of aforementioned methods, C language source file override logic will still kick in and disable CompileAsWinRT for C source files Fixes: #20063
67 lines
2.3 KiB
CMake
67 lines
2.3 KiB
CMake
macro(checkCompileAsWinRT projectPath)
|
|
if(RunCMake_TEST_FAILED)
|
|
return()
|
|
endif()
|
|
|
|
if (NOT EXISTS "${projectPath}")
|
|
set(RunCMake_TEST_FAILED "Project file ${projectPath} does not exist.")
|
|
return()
|
|
endif()
|
|
|
|
get_filename_component(projectName "${projectPath}" NAME_WE)
|
|
|
|
cmake_parse_arguments("" "" "GLOBAL" "OVERRIDES_ENABLE;OVERRIDES_DISABLE" ${ARGN})
|
|
|
|
unset(sourceOverride)
|
|
|
|
file(STRINGS "${projectPath}" lines)
|
|
set(foundGlobalWinRT false)
|
|
|
|
foreach(line IN LISTS lines)
|
|
if(line MATCHES "^ *<CompileAsWinRT( Condition=\"[^\\\"]+\")?>(true|false)</CompileAsWinRT>$")
|
|
set(value ${CMAKE_MATCH_2})
|
|
|
|
if(sourceOverride)
|
|
set(expectedList)
|
|
|
|
if(value)
|
|
set(expectedList _OVERRIDES_ENABLE)
|
|
else()
|
|
set(expectedList _OVERRIDES_DISABLE)
|
|
endif()
|
|
|
|
if(NOT sourceOverride IN_LIST ${expectedList})
|
|
set(RunCMake_TEST_FAILED
|
|
"${projectName}: Unexpected CompileAsWinRT override ${value} for ${sourceOverride}")
|
|
return()
|
|
endif()
|
|
else()
|
|
if (NOT _GLOBAL STREQUAL value)
|
|
set(RunCMake_TEST_FAILED
|
|
"${projectName}: Global CompileAsWinRT value is ${value}, but expected ${_GLOBAL}")
|
|
return()
|
|
endif()
|
|
|
|
set(foundGlobalWinRT true)
|
|
endif()
|
|
elseif(line MATCHES "^ *<ClCompile Include=\"([^\"]+)\">$")
|
|
get_filename_component(sourceOverride "${CMAKE_MATCH_1}" NAME)
|
|
elseif(line MATCHES "^ *</ClCompile>$")
|
|
unset(sourceOverride)
|
|
endif()
|
|
endforeach()
|
|
|
|
if(NOT foundGlobalWinRT AND DEFINED _GLOBAL)
|
|
set(RunCMake_TEST_FAILED "${projectName}: Global CompileAsWinRT not found or have invalid value, but expected")
|
|
return()
|
|
endif()
|
|
endmacro()
|
|
|
|
checkCompileAsWinRT("${RunCMake_TEST_BINARY_DIR}/noFlagOnlyC.vcxproj" GLOBAL false)
|
|
checkCompileAsWinRT("${RunCMake_TEST_BINARY_DIR}/noFlagMixedCAndCxx.vcxproj" GLOBAL false)
|
|
checkCompileAsWinRT("${RunCMake_TEST_BINARY_DIR}/noFlagOnlyCxx.vcxproj" GLOBAL false)
|
|
|
|
checkCompileAsWinRT("${RunCMake_TEST_BINARY_DIR}/flagOnlyC.vcxproj" GLOBAL true OVERRIDES_DISABLE empty.c)
|
|
checkCompileAsWinRT("${RunCMake_TEST_BINARY_DIR}/flagMixedCAndCxx.vcxproj" GLOBAL true OVERRIDES_DISABLE empty.c)
|
|
checkCompileAsWinRT("${RunCMake_TEST_BINARY_DIR}/flagOnlyCxx.vcxproj" GLOBAL true)
|