Commit cd92f8f8 authored by mattw-mattw's avatar mattw-mattw Committed by Brad King
Browse files

VS: Add VS_DPI_AWARE target property

Enables setting the visual studio project property for Manifests,
controlling the DPI Aware setting.
parent 6f7b68e7
......@@ -331,6 +331,7 @@ Properties on Targets
/prop_tgt/VS_DOTNET_REFERENCES
/prop_tgt/VS_DOTNET_REFERENCES_COPY_LOCAL
/prop_tgt/VS_DOTNET_TARGET_FRAMEWORK_VERSION
/prop_tgt/VS_DPI_AWARE
/prop_tgt/VS_GLOBAL_KEYWORD
/prop_tgt/VS_GLOBAL_PROJECT_TYPES
/prop_tgt/VS_GLOBAL_ROOTNAMESPACE
......
VS_DPI_AWARE
------------
Set the Manifest Tool -> Input and Output -> DPI Awareness in the Visual Studio
target project properties.
Valid values are ``PerMonitor``, ``ON``, or ``OFF``.
For example:
.. code-block:: cmake
add_executable(myproject myproject.cpp)
set_property(TARGET myproject PROPERTY VS_DPI_AWARE "PerMonitor")
vs-dpi-aware
------------
* The :prop_tgt:`VS_DPI_AWARE` target property was added to tell
:ref:`Visual Studio Generators` to set the ``EnableDpiAwareness``
property in ``.vcxproj`` files.
......@@ -3252,15 +3252,32 @@ void cmVisualStudio10TargetGenerator::WriteManifestOptions(
std::vector<cmSourceFile const*> manifest_srcs;
this->GeneratorTarget->GetManifests(manifest_srcs, config);
if (!manifest_srcs.empty()) {
std::ostringstream oss;
for (cmSourceFile const* mi : manifest_srcs) {
std::string m = this->ConvertPath(mi->GetFullPath(), false);
ConvertToWindowsSlash(m);
oss << m << ";";
}
const char* dpiAware = this->GeneratorTarget->GetProperty("VS_DPI_AWARE");
if (!manifest_srcs.empty() || dpiAware) {
Elem e2(e1, "Manifest");
e2.Element("AdditionalManifestFiles", oss.str());
if (!manifest_srcs.empty()) {
std::ostringstream oss;
for (cmSourceFile const* mi : manifest_srcs) {
std::string m = this->ConvertPath(mi->GetFullPath(), false);
ConvertToWindowsSlash(m);
oss << m << ";";
}
e2.Element("AdditionalManifestFiles", oss.str());
}
if (dpiAware) {
if (!strcmp(dpiAware, "PerMonitor")) {
e2.Element("EnableDpiAwareness", "PerMonitorHighDPIAware");
} else if (cmSystemTools::IsOn(dpiAware)) {
e2.Element("EnableDpiAwareness", "true");
} else if (cmSystemTools::IsOff(dpiAware)) {
e2.Element("EnableDpiAwareness", "false");
} else {
cmSystemTools::Error("Bad parameter for VS_DPI_AWARE: " +
std::string(dpiAware));
}
}
}
}
......
......@@ -22,6 +22,8 @@ run_cmake(VsSdkDirectories)
run_cmake(VsGlobals)
run_cmake(VsProjectImport)
run_cmake(VsPackageReferences)
run_cmake(VsDpiAware)
run_cmake(VsDpiAwareBadParam)
if(CMAKE_C_COMPILER_ID STREQUAL "MSVC" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 19.05)
run_cmake(VsJustMyCode)
......
macro(VSDpiAware_check tgt dpiaware_match_expect)
set(vcProjectFile "${RunCMake_TEST_BINARY_DIR}/${tgt}.vcxproj")
if(NOT EXISTS "${vcProjectFile}")
set(RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj does not exist.")
return()
endif()
set(HAVE_DPIAWARE_MATCH 0)
set(IN_MANIFEST_SETTINGS 0)
file(STRINGS "${vcProjectFile}" lines)
foreach(line IN LISTS lines)
if(line MATCHES "^ *<Manifest>")
set(IN_MANIFEST_SETTINGS 1)
elseif(line MATCHES "^ *</Manifest>")
set(IN_MANIFEST_SETTINGS 0)
elseif(IN_MANIFEST_SETTINGS AND (line MATCHES "^ *<EnableDpiAwareness>([^<>]+)</EnableDpiAwareness>"))
set(dpiaware_match_actual "${CMAKE_MATCH_1}")
if(NOT "${dpiaware_match_actual}" STREQUAL "${dpiaware_match_expect}")
set(RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj has <EnableDpiAwareness> '${dpiaware_match_actual}', not '${dpiaware_match_expect}'.")
return()
endif()
set(HAVE_DPIAWARE_MATCH 1)
break()
endif()
endforeach()
if(NOT HAVE_DPIAWARE_MATCH AND NOT "${dpiaware_match_expect}" STREQUAL "")
set(RunCMake_TEST_FAILED "Project file ${tgt}.vcxproj does not have a <EnableDpiAwareness> property group.")
return()
endif()
endmacro()
VSDpiAware_check(DPIAWARE-default-C "")
VSDpiAware_check(DPIAWARE-default-CXX "")
VSDpiAware_check(DPIAWARE-TGT-PERMONITOR-C "PerMonitorHighDPIAware")
VSDpiAware_check(DPIAWARE-TGT-PERMONITOR-CXX "PerMonitorHighDPIAware")
VSDpiAware_check(DPIAWARE-TGT-ON-C "true")
VSDpiAware_check(DPIAWARE-TGT-ON-CXX "true")
VSDpiAware_check(DPIAWARE-TGT-OFF-C "false")
VSDpiAware_check(DPIAWARE-TGT-OFF-CXX "false")
set(CMAKE_CONFIGURATION_TYPES Debug)
enable_language(C)
enable_language(CXX)
add_executable(DPIAWARE-default-C empty.c)
add_executable(DPIAWARE-default-CXX empty.cxx)
add_executable(DPIAWARE-TGT-PERMONITOR-C empty.c)
set_property(TARGET DPIAWARE-TGT-PERMONITOR-C PROPERTY VS_DPI_AWARE "PerMonitor")
add_executable(DPIAWARE-TGT-PERMONITOR-CXX empty.cxx)
set_property(TARGET DPIAWARE-TGT-PERMONITOR-CXX PROPERTY VS_DPI_AWARE "PerMonitor")
add_executable(DPIAWARE-TGT-ON-C empty.c)
set_property(TARGET DPIAWARE-TGT-ON-C PROPERTY VS_DPI_AWARE ON)
add_executable(DPIAWARE-TGT-ON-CXX empty.cxx)
set_property(TARGET DPIAWARE-TGT-ON-CXX PROPERTY VS_DPI_AWARE ON)
add_executable(DPIAWARE-TGT-OFF-C empty.c)
set_property(TARGET DPIAWARE-TGT-OFF-C PROPERTY VS_DPI_AWARE OFF)
add_executable(DPIAWARE-TGT-OFF-CXX empty.cxx)
set_property(TARGET DPIAWARE-TGT-OFF-CXX PROPERTY VS_DPI_AWARE OFF)
CMake Error: Bad parameter for VS_DPI_AWARE: Bar
CMake Error: Bad parameter for VS_DPI_AWARE: Foo
CMake Generate step failed. Build files cannot be regenerated correctly.
set(CMAKE_CONFIGURATION_TYPES Debug)
enable_language(C)
enable_language(CXX)
add_executable(DPIAWARE-TGT-BADPARAM-C empty.c)
set_property(TARGET DPIAWARE-TGT-BADPARAM-C PROPERTY VS_DPI_AWARE "Foo")
add_executable(DPIAWARE-TGT-BADPARAM-CXX empty.cxx)
set_property(TARGET DPIAWARE-TGT-BADPARAM-CXX PROPERTY VS_DPI_AWARE "Bar")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment