diff options
-rw-r--r-- | Help/manual/cmake-properties.7.rst | 1 | ||||
-rw-r--r-- | Help/prop_tgt/VS_DPI_AWARE.rst | 14 | ||||
-rw-r--r-- | Help/release/dev/vs-dpi-aware.rst | 6 | ||||
-rw-r--r-- | Source/cmVisualStudio10TargetGenerator.cxx | 33 | ||||
-rw-r--r-- | Tests/RunCMake/VS10Project/RunCMakeTest.cmake | 2 | ||||
-rw-r--r-- | Tests/RunCMake/VS10Project/VsDpiAware-check.cmake | 41 | ||||
-rw-r--r-- | Tests/RunCMake/VS10Project/VsDpiAware.cmake | 19 | ||||
-rw-r--r-- | Tests/RunCMake/VS10Project/VsDpiAwareBadParam-result.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/VS10Project/VsDpiAwareBadParam-stderr.txt | 3 | ||||
-rw-r--r-- | Tests/RunCMake/VS10Project/VsDpiAwareBadParam.cmake | 8 |
10 files changed, 120 insertions, 8 deletions
diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst index 77b1ae8..0beca82 100644 --- a/Help/manual/cmake-properties.7.rst +++ b/Help/manual/cmake-properties.7.rst @@ -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 diff --git a/Help/prop_tgt/VS_DPI_AWARE.rst b/Help/prop_tgt/VS_DPI_AWARE.rst new file mode 100644 index 0000000..82640cc --- /dev/null +++ b/Help/prop_tgt/VS_DPI_AWARE.rst @@ -0,0 +1,14 @@ +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") diff --git a/Help/release/dev/vs-dpi-aware.rst b/Help/release/dev/vs-dpi-aware.rst new file mode 100644 index 0000000..f76f26c --- /dev/null +++ b/Help/release/dev/vs-dpi-aware.rst @@ -0,0 +1,6 @@ +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. diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 634c990..85feacd 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -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)); + } + } } } diff --git a/Tests/RunCMake/VS10Project/RunCMakeTest.cmake b/Tests/RunCMake/VS10Project/RunCMakeTest.cmake index 55ca9ea..5b2c7cb 100644 --- a/Tests/RunCMake/VS10Project/RunCMakeTest.cmake +++ b/Tests/RunCMake/VS10Project/RunCMakeTest.cmake @@ -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) diff --git a/Tests/RunCMake/VS10Project/VsDpiAware-check.cmake b/Tests/RunCMake/VS10Project/VsDpiAware-check.cmake new file mode 100644 index 0000000..fbb64f0 --- /dev/null +++ b/Tests/RunCMake/VS10Project/VsDpiAware-check.cmake @@ -0,0 +1,41 @@ +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") diff --git a/Tests/RunCMake/VS10Project/VsDpiAware.cmake b/Tests/RunCMake/VS10Project/VsDpiAware.cmake new file mode 100644 index 0000000..74e3d21 --- /dev/null +++ b/Tests/RunCMake/VS10Project/VsDpiAware.cmake @@ -0,0 +1,19 @@ +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) diff --git a/Tests/RunCMake/VS10Project/VsDpiAwareBadParam-result.txt b/Tests/RunCMake/VS10Project/VsDpiAwareBadParam-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/VS10Project/VsDpiAwareBadParam-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/VS10Project/VsDpiAwareBadParam-stderr.txt b/Tests/RunCMake/VS10Project/VsDpiAwareBadParam-stderr.txt new file mode 100644 index 0000000..95fc5ca --- /dev/null +++ b/Tests/RunCMake/VS10Project/VsDpiAwareBadParam-stderr.txt @@ -0,0 +1,3 @@ +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. diff --git a/Tests/RunCMake/VS10Project/VsDpiAwareBadParam.cmake b/Tests/RunCMake/VS10Project/VsDpiAwareBadParam.cmake new file mode 100644 index 0000000..e05452b --- /dev/null +++ b/Tests/RunCMake/VS10Project/VsDpiAwareBadParam.cmake @@ -0,0 +1,8 @@ +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") |