summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2019-05-31 17:18:21 (GMT)
committerKitware Robot <kwrobot@kitware.com>2019-05-31 17:18:31 (GMT)
commit187928875d215df8757b291ad629a36df75da42b (patch)
tree320f5369e8d6d9c3b7eed592c079e6c6f849e99c
parent66bba23a4b4c6e7901524677f245d02a31b3eff8 (diff)
parent42e14d90b1b38df6c698ef230ab06ae9504436d5 (diff)
downloadCMake-187928875d215df8757b291ad629a36df75da42b.zip
CMake-187928875d215df8757b291ad629a36df75da42b.tar.gz
CMake-187928875d215df8757b291ad629a36df75da42b.tar.bz2
Merge topic 'vs-add-package-reference'
42e14d90b1 VS: Added support for VS package references for nuget Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: Leonid Pospelov <pospelovlm@yandex.ru> Merge-request: !3389
-rw-r--r--Help/manual/cmake-properties.7.rst1
-rw-r--r--Help/prop_tgt/VS_PACKAGE_REFERENCES.rst13
-rw-r--r--Help/release/dev/vs-add-package-references.rst6
-rw-r--r--Source/cmVisualStudio10TargetGenerator.cxx28
-rw-r--r--Source/cmVisualStudio10TargetGenerator.h3
-rw-r--r--Tests/RunCMake/VS10Project/RunCMakeTest.cmake1
-rw-r--r--Tests/RunCMake/VS10Project/VsPackageReferences-check.cmake39
-rw-r--r--Tests/RunCMake/VS10Project/VsPackageReferences.cmake4
8 files changed, 95 insertions, 0 deletions
diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst
index 9d2ad90..25aab8d 100644
--- a/Help/manual/cmake-properties.7.rst
+++ b/Help/manual/cmake-properties.7.rst
@@ -342,6 +342,7 @@ Properties on Targets
/prop_tgt/VS_KEYWORD
/prop_tgt/VS_MOBILE_EXTENSIONS_VERSION
/prop_tgt/VS_NO_SOLUTION_DEPLOY
+ /prop_tgt/VS_PACKAGE_REFERENCES
/prop_tgt/VS_PROJECT_IMPORT
/prop_tgt/VS_SCC_AUXPATH
/prop_tgt/VS_SCC_LOCALPATH
diff --git a/Help/prop_tgt/VS_PACKAGE_REFERENCES.rst b/Help/prop_tgt/VS_PACKAGE_REFERENCES.rst
new file mode 100644
index 0000000..5a0465b
--- /dev/null
+++ b/Help/prop_tgt/VS_PACKAGE_REFERENCES.rst
@@ -0,0 +1,13 @@
+VS_PACKAGE_REFERENCES
+---------------------
+
+Visual Studio package references for nuget.
+
+Adds one or more semicolon-delimited package references to a generated
+Visual Studio project. The version of the package will be
+underscore delimited. For example, ``boost_1.7.0;nunit_3.12.*``.
+
+.. code-block:: cmake
+
+ set_property(TARGET ${TARGET_NAME} PROPERTY
+ VS_PACKAGE_REFERENCES "boost_1.7.0")
diff --git a/Help/release/dev/vs-add-package-references.rst b/Help/release/dev/vs-add-package-references.rst
new file mode 100644
index 0000000..2d260dc
--- /dev/null
+++ b/Help/release/dev/vs-add-package-references.rst
@@ -0,0 +1,6 @@
+vs-add-package-references
+-------------------------
+
+* A :prop_tgt:`VS_PACKAGE_REFERENCES` target property was added to
+ tell :ref:`Visual Studio Generators` to add references to nuget
+ packages.
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx
index 3db3813..9368414 100644
--- a/Source/cmVisualStudio10TargetGenerator.cxx
+++ b/Source/cmVisualStudio10TargetGenerator.cxx
@@ -665,6 +665,7 @@ void cmVisualStudio10TargetGenerator::Generate()
this->WriteCustomCommands(e0);
this->WriteAllSources(e0);
this->WriteDotNetReferences(e0);
+ this->WritePackageReferences(e0);
this->WriteImports(e0);
this->WriteEmbeddedResourceGroup(e0);
this->WriteXamlFilesGroup(e0);
@@ -738,6 +739,33 @@ void cmVisualStudio10TargetGenerator::Generate()
this->WriteGroups();
}
+void cmVisualStudio10TargetGenerator::WritePackageReferences(Elem& e0)
+{
+ std::vector<std::string> packageReferences;
+ if (const char* vsPackageReferences =
+ this->GeneratorTarget->GetProperty("VS_PACKAGE_REFERENCES")) {
+ cmSystemTools::ExpandListArgument(vsPackageReferences, packageReferences);
+ }
+ if (!packageReferences.empty()) {
+ Elem e1(e0, "ItemGroup");
+ for (std::string const& ri : packageReferences) {
+ size_t versionIndex = ri.find_last_of('_');
+ if (versionIndex != std::string::npos) {
+ WritePackageReference(e1, ri.substr(0, versionIndex),
+ ri.substr(versionIndex + 1));
+ }
+ }
+ }
+}
+
+void cmVisualStudio10TargetGenerator::WritePackageReference(
+ Elem& e1, std::string const& ref, std::string const& version)
+{
+ Elem e2(e1, "PackageReference");
+ e2.Attribute("Include", ref);
+ e2.Attribute("Version", version);
+}
+
void cmVisualStudio10TargetGenerator::WriteDotNetReferences(Elem& e0)
{
std::vector<std::string> references;
diff --git a/Source/cmVisualStudio10TargetGenerator.h b/Source/cmVisualStudio10TargetGenerator.h
index b83950c..860b809 100644
--- a/Source/cmVisualStudio10TargetGenerator.h
+++ b/Source/cmVisualStudio10TargetGenerator.h
@@ -72,6 +72,9 @@ private:
void WriteExcludeFromBuild(Elem& e2,
std::vector<size_t> const& exclude_configs);
void WriteAllSources(Elem& e0);
+ void WritePackageReferences(Elem& e0);
+ void WritePackageReference(Elem& e1, std::string const& ref,
+ std::string const& version);
void WriteDotNetReferences(Elem& e0);
void WriteDotNetReference(Elem& e1, std::string const& ref,
std::string const& hint,
diff --git a/Tests/RunCMake/VS10Project/RunCMakeTest.cmake b/Tests/RunCMake/VS10Project/RunCMakeTest.cmake
index 9a0b7a9..55ca9ea 100644
--- a/Tests/RunCMake/VS10Project/RunCMakeTest.cmake
+++ b/Tests/RunCMake/VS10Project/RunCMakeTest.cmake
@@ -21,6 +21,7 @@ run_cmake(VSCSharpDefines)
run_cmake(VsSdkDirectories)
run_cmake(VsGlobals)
run_cmake(VsProjectImport)
+run_cmake(VsPackageReferences)
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/VsPackageReferences-check.cmake b/Tests/RunCMake/VS10Project/VsPackageReferences-check.cmake
new file mode 100644
index 0000000..4ff5327
--- /dev/null
+++ b/Tests/RunCMake/VS10Project/VsPackageReferences-check.cmake
@@ -0,0 +1,39 @@
+set(vcProjectFile "${RunCMake_TEST_BINARY_DIR}/foo.vcxproj")
+if(NOT EXISTS "${vcProjectFile}")
+ set(RunCMake_TEST_FAILED "Project file foo.vcxproj does not exist.")
+ return()
+endif()
+
+
+set(test1Library "boost")
+set(test1Version "1.7.0")
+
+
+set(test2Library "SFML")
+set(test2Version "2.2.0")
+
+set(Library1Found FALSE)
+set(Library2Found FALSE)
+
+file(STRINGS "${vcProjectFile}" lines)
+
+foreach(i 1 2)
+ set(testLibrary "${test${i}Library}")
+ set(testVersion "${test${i}Version}")
+ foreach(line IN LISTS lines)
+ if(line MATCHES "^ *<PackageReference Include=\"${testLibrary}\".*>$")
+ if(line MATCHES "^ *<PackageReference .* Version=\"${testVersion}\".*>$")
+ set(Library${i}Found TRUE)
+ message(STATUS "foo.vcxproj is using package reference ${testLibrary} with version ${testVersion}")
+ elseif()
+ message(STATUS "foo.vcxproj failed to define reference ${testLibrary} with version ${testVersion}")
+ set(Library${i}Found FALSE)
+ endif()
+ endif()
+ endforeach()
+endforeach()
+
+if(NOT Library1Found OR NOT Library2Found)
+ set(RunCMake_TEST_FAILED "Failed to find package references")
+ return()
+endif()
diff --git a/Tests/RunCMake/VS10Project/VsPackageReferences.cmake b/Tests/RunCMake/VS10Project/VsPackageReferences.cmake
new file mode 100644
index 0000000..224ab18
--- /dev/null
+++ b/Tests/RunCMake/VS10Project/VsPackageReferences.cmake
@@ -0,0 +1,4 @@
+enable_language(CXX)
+add_library(foo foo.cpp)
+
+set_property(TARGET foo PROPERTY VS_PACKAGE_REFERENCES "boost_1.7.0;SFML_2.2.0")