diff options
author | Alex Opie <alex@opie.nz> | 2024-06-01 03:46:48 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2024-06-03 15:28:49 (GMT) |
commit | 0f4d3664a94c96a131e1a4aec0698ed7f5f92521 (patch) | |
tree | 88923a2cb0a4dba2af81761769a4673590b17ebc /Tests/RunCMake | |
parent | 140766867b2c8f8dff0e4d0d73e481b6944b5284 (diff) | |
download | CMake-0f4d3664a94c96a131e1a4aec0698ed7f5f92521.zip CMake-0f4d3664a94c96a131e1a4aec0698ed7f5f92521.tar.gz CMake-0f4d3664a94c96a131e1a4aec0698ed7f5f92521.tar.bz2 |
CPack/NuGet: Build dependencies in groups
This allows particular frameworks to be targeted by
particular dependencies, and for empty dependency
groups to satisfy NuGet's framework-matching
requirements.
Diffstat (limited to 'Tests/RunCMake')
-rw-r--r-- | Tests/RunCMake/CMakeLists.txt | 4 | ||||
-rw-r--r-- | Tests/RunCMake/CPack_NuGet/.gitattributes | 3 | ||||
-rw-r--r-- | Tests/RunCMake/CPack_NuGet/NuGetLib-cpack-NuGet-check.cmake | 23 | ||||
-rw-r--r-- | Tests/RunCMake/CPack_NuGet/RunCMakeTest.cmake | 7 | ||||
-rw-r--r-- | Tests/RunCMake/CPack_NuGet/expected.nuspec | 38 | ||||
-rw-r--r-- | Tests/RunCMake/RunCPack/NuGetLib/CMakeLists.txt | 34 | ||||
-rw-r--r-- | Tests/RunCMake/RunCPack/NuGetLib/alsonotalib.dll | 0 | ||||
-rw-r--r-- | Tests/RunCMake/RunCPack/NuGetLib/notactuallyalib.dll | 0 |
8 files changed, 109 insertions, 0 deletions
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 94382fc..e205d9f 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -1141,6 +1141,10 @@ if(CMake_TEST_CPACK_WIX3 OR CMake_TEST_CPACK_WIX4) ) endif() +if(CMake_TEST_CPACK_NUGET) + add_RunCMake_test(CPack_NuGet) +endif() + # add a test to make sure symbols are exported from a shared library # for MSVC compilers CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS property is used add_RunCMake_test(AutoExportDll diff --git a/Tests/RunCMake/CPack_NuGet/.gitattributes b/Tests/RunCMake/CPack_NuGet/.gitattributes new file mode 100644 index 0000000..4a8bbd0 --- /dev/null +++ b/Tests/RunCMake/CPack_NuGet/.gitattributes @@ -0,0 +1,3 @@ +# Do not check whitespace in the nuspec file for comparison. It needs to +# look identical to the file generated in the test. +expected.nuspec -whitespace diff --git a/Tests/RunCMake/CPack_NuGet/NuGetLib-cpack-NuGet-check.cmake b/Tests/RunCMake/CPack_NuGet/NuGetLib-cpack-NuGet-check.cmake new file mode 100644 index 0000000..e83f007 --- /dev/null +++ b/Tests/RunCMake/CPack_NuGet/NuGetLib-cpack-NuGet-check.cmake @@ -0,0 +1,23 @@ +file(GLOB generated_nuspec "${RunCMake_TEST_BINARY_DIR}/_CPack_Packages/*/NuGet/GeneratorTest-1.2.3-*/CPack.NuGet.nuspec") +if(NOT generated_nuspec) + set(RunCMake_TEST_FAILED "No nuspec file generated under ${RunCMake_TEST_BINARY_DIR}") +else() + # Read in the generated nuspec file content + file(READ "${generated_nuspec}" actual_nuspec) + # Read in the expected file content + file(READ "${CMAKE_CURRENT_LIST_DIR}/expected.nuspec" expected_nuspec) + + # Compare the file contents + string(COMPARE EQUAL "${actual_nuspec}" "${expected_nuspec}" nuspec_matches) + + if(NOT nuspec_matches) + set(RunCMake_TEST_FAILED "generated nuspec file incorrect") + set(failure_msg "") + # This would be nicer with a `diff` output, but it needs to be portable + string(APPEND failure_msg "\nExpected file:\n") + string(APPEND failure_msg "${expected_nuspec}") + string(APPEND failure_msg "Actual file:\n") + string(APPEND failure_msg "${actual_nuspec}") + set(RunCMake_TEST_FAILURE_MESSAGE "${failure_msg}") + endif() +endif() diff --git a/Tests/RunCMake/CPack_NuGet/RunCMakeTest.cmake b/Tests/RunCMake/CPack_NuGet/RunCMakeTest.cmake new file mode 100644 index 0000000..af8ad31 --- /dev/null +++ b/Tests/RunCMake/CPack_NuGet/RunCMakeTest.cmake @@ -0,0 +1,7 @@ +include(RunCPack) + +set(env_PATH "$ENV{PATH}") + +set(RunCPack_GENERATORS NuGet) + +run_cpack(NuGetLib) diff --git a/Tests/RunCMake/CPack_NuGet/expected.nuspec b/Tests/RunCMake/CPack_NuGet/expected.nuspec new file mode 100644 index 0000000..d5c6c45 --- /dev/null +++ b/Tests/RunCMake/CPack_NuGet/expected.nuspec @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="utf-8"?> +<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd"> + <metadata> + <!-- Required elements--> + <id>GeneratorTest</id> + <version>1.2.3</version> + <description><![CDATA[A NuGet package for testing CMake's CPack NuGet generator]]></description> + <authors><![CDATA[ACME Inc]]></authors> + + <!-- Optional elements --> + + <owners><![CDATA[ACME Inc]]></owners> + <projectUrl><![CDATA[https://www.example.com]]></projectUrl> + + <license type="expression"><![CDATA[MIT]]></license> + + + + + <summary><![CDATA[A test NuGet package]]></summary> + + + + + <repository type="git" url="https://github.com/example/nugetlib.git" /> + <dependencies> + <group> + <dependency id="Baz" version="9.8.6" /> + </group> + <group targetFramework=".NETFramework4"> + <dependency id="Foo" version="1.23" /> + <dependency id="Bar" version="4.3.2" /> + </group> + <group targetFramework="net6.0" /> + </dependencies> + </metadata> + +</package> diff --git a/Tests/RunCMake/RunCPack/NuGetLib/CMakeLists.txt b/Tests/RunCMake/RunCPack/NuGetLib/CMakeLists.txt new file mode 100644 index 0000000..55ab638 --- /dev/null +++ b/Tests/RunCMake/RunCPack/NuGetLib/CMakeLists.txt @@ -0,0 +1,34 @@ +# Support for framework-specific dependencies were introduced in 3.30 +# TODO: update this version req to 3.30 +cmake_minimum_required(VERSION 3.29.20240531) +project(CPackNugetGenerator) + +install(FILES notactuallyalib.dll DESTINATION lib/net4) +install(FILES alsonotalib.dll DESTINATION lib/net6.0) + +# Create NuGet package +set(CPACK_GENERATOR NuGet) +set(CPACK_PACKAGE_NAME GeneratorTest) +set(CPACK_PACKAGE_VERSION "1.2.3") +set(CPACK_PACKAGE_VENDOR "ACME Inc") +set(CPACK_NUGET_PACKAGE_OWNERS "ACME Inc") +set(CPACK_PACKAGE_DESCRIPTION "A NuGet package for testing CMake's CPack NuGet generator") +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A test NuGet package") +set(CPACK_PACKAGE_HOMEPAGE_URL "https://www.example.com") +set(CPACK_NUGET_PACKAGE_REPOSITORY_URL "https://github.com/example/nugetlib.git") +set(CPACK_NUGET_PACKAGE_REPOSITORY_TYPE git) +set(CPACK_NUGET_PACKAGE_LICENSE_EXPRESSION "MIT") + +# Set up dependencies +set(CPACK_NUGET_PACKAGE_TFMS "net4;net6.0") +set(CPACK_NUGET_PACKAGE_DEPENDENCIES_net4 "Foo;Bar") +# NB: If a version number is omitted, the dependency will not be created +set(CPACK_NUGET_PACKAGE_DEPENDENCIES_net4_Foo_VERSION "1.23") +set(CPACK_NUGET_PACKAGE_DEPENDENCIES_net4_Bar_VERSION "4.3.2") +# NB: General dependencies (not framework-specific) go in this variable +set(CPACK_NUGET_PACKAGE_DEPENDENCIES "Baz") +set(CPACK_NUGET_PACKAGE_DEPENDENCIES_Baz_VERSION "9.8.6") +# NB: Since "net6.0" was listed but no dependencies have been specified, an empty group +# will be added to the nuspec file for this framework. This can be used to address `NU5128`_. + +include(CPack) diff --git a/Tests/RunCMake/RunCPack/NuGetLib/alsonotalib.dll b/Tests/RunCMake/RunCPack/NuGetLib/alsonotalib.dll new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/RunCMake/RunCPack/NuGetLib/alsonotalib.dll diff --git a/Tests/RunCMake/RunCPack/NuGetLib/notactuallyalib.dll b/Tests/RunCMake/RunCPack/NuGetLib/notactuallyalib.dll new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Tests/RunCMake/RunCPack/NuGetLib/notactuallyalib.dll |