From 56a96d1f1f1f63d03a693e6c2c98b208cfaa3f01 Mon Sep 17 00:00:00 2001 From: halx99 Date: Thu, 2 May 2024 00:02:06 +0800 Subject: VS: Add option to import .props in .vcxproj.filters files Adds new target property VS_FILTER_PROPS Fixes: #25948 --- Auxiliary/vim/syntax/cmake.vim | 1 + Help/manual/cmake-properties.7.rst | 1 + Help/prop_tgt/VS_FILTER_PROPS.rst | 10 +++++ Help/release/dev/vs-filter-props.rst | 6 +++ Source/cmVisualStudio10TargetGenerator.cxx | 12 ++++++ .../RunCMake/VS10Project/VsCustomProps-check.cmake | 45 ++++++++++++---------- Tests/RunCMake/VS10Project/VsCustomProps.cmake | 3 +- 7 files changed, 57 insertions(+), 21 deletions(-) create mode 100644 Help/prop_tgt/VS_FILTER_PROPS.rst create mode 100644 Help/release/dev/vs-filter-props.rst diff --git a/Auxiliary/vim/syntax/cmake.vim b/Auxiliary/vim/syntax/cmake.vim index 5629356..5d412c2 100644 --- a/Auxiliary/vim/syntax/cmake.vim +++ b/Auxiliary/vim/syntax/cmake.vim @@ -450,6 +450,7 @@ syn keyword cmakeProperty contained \ VS_STARTUP_PROJECT \ VS_TOOL_OVERRIDE \ VS_USER_PROPS + \ VS_FILTER_PROPS \ VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION \ VS_WINRT_COMPONENT \ VS_WINRT_EXTENSIONS diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst index 6ccc23e..7e640df 100644 --- a/Help/manual/cmake-properties.7.rst +++ b/Help/manual/cmake-properties.7.rst @@ -448,6 +448,7 @@ Properties on Targets /prop_tgt/VS_SOURCE_SETTINGS_tool /prop_tgt/VS_USE_DEBUG_LIBRARIES /prop_tgt/VS_USER_PROPS + /prop_tgt/VS_FILTER_PROPS /prop_tgt/VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION /prop_tgt/VS_WINRT_COMPONENT /prop_tgt/VS_WINRT_REFERENCES diff --git a/Help/prop_tgt/VS_FILTER_PROPS.rst b/Help/prop_tgt/VS_FILTER_PROPS.rst new file mode 100644 index 0000000..3de0a16 --- /dev/null +++ b/Help/prop_tgt/VS_FILTER_PROPS.rst @@ -0,0 +1,10 @@ +VS_FILTER_PROPS +--------------- + +.. versionadded:: 3.30 + +Sets the filter props file to be included in the visual studio +C++ project filter file. + +The ``*.filter.props`` files can be used for Visual Studio wide +configuration which is independent from cmake. diff --git a/Help/release/dev/vs-filter-props.rst b/Help/release/dev/vs-filter-props.rst new file mode 100644 index 0000000..5a09511 --- /dev/null +++ b/Help/release/dev/vs-filter-props.rst @@ -0,0 +1,6 @@ +vs-filter-props +--------------- + +* A :prop_tgt:`VS_FILTER_PROPS` target property was added to tell + :ref:`Visual Studio Generators` for VS 2010 and above to use a + custom MSBuild filter ``.props`` file. diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index bca4719..140a20b 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -2074,6 +2074,18 @@ void cmVisualStudio10TargetGenerator::WriteGroups() "gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms"); } } + { + if (cmValue p = this->GeneratorTarget->GetProperty("VS_FILTER_PROPS")) { + auto props = *p; + if (!props.empty()) { + ConvertToWindowsSlash(props); + Elem(e0, "Import") + .Attribute("Project", props) + .Attribute("Condition", cmStrCat("exists('", props, "')")) + .Attribute("Label", "LocalAppDataPlatform"); + } + } + } } fout << '\n'; diff --git a/Tests/RunCMake/VS10Project/VsCustomProps-check.cmake b/Tests/RunCMake/VS10Project/VsCustomProps-check.cmake index 22a3df0..ad585d5 100644 --- a/Tests/RunCMake/VS10Project/VsCustomProps-check.cmake +++ b/Tests/RunCMake/VS10Project/VsCustomProps-check.cmake @@ -1,25 +1,30 @@ -set(vcProjectFile "${RunCMake_TEST_BINARY_DIR}/foo.vcxproj") -if(NOT EXISTS "${vcProjectFile}") - set(RunCMake_TEST_FAILED "Project file ${vcProjectFile} does not exist.") - return() -endif() +macro(check_custom_prop suffix) + set(vcProjectFile "${RunCMake_TEST_BINARY_DIR}/foo.vcxproj${suffix}") + if(NOT EXISTS "${vcProjectFile}") + set(RunCMake_TEST_FAILED "Project file ${vcProjectFile} does not exist.") + return() + endif() -set(importFound FALSE) + set(importFound FALSE) -set(props_file "${RunCMake_SOURCE_DIR}/my.props") -file(TO_NATIVE_PATH "${props_file}" check_file) -file(STRINGS "${vcProjectFile}" lines) -foreach(line IN LISTS lines) - if(line MATCHES "^ *