Browse Source

Merge topic 'cps-use-license' into release-4.2

94b6e36b6b find_package: Respect CPS license

Acked-by: Kitware Robot <[email protected]>
Acked-by: buildbot <[email protected]>
Merge-request: !11343
Brad King 1 tháng trước cách đây
mục cha
commit
cd28c759ff

+ 9 - 0
Source/cmPackageInfoReader.cxx

@@ -488,6 +488,15 @@ std::unique_ptr<cmPackageInfoReader> cmPackageInfoReader::Read(
     reader->DefaultLicense = defaultLicense.asString();
   } else if (parent) {
     reader->DefaultLicense = parent->DefaultLicense;
+  } else {
+    // If there is no 'default_license', check for 'license'. Note that we
+    // intentionally allow `default_license` on an appendix to override the
+    // parent, but we do not consider `license` on an appendix. This is
+    // consistent with not allowing LICENSE and APPENDIX to be used together.
+    Json::Value const& packageLicense = reader->Data["license"];
+    if (!packageLicense.isNull()) {
+      reader->DefaultLicense = packageLicense.asString();
+    }
   }
 
   return reader;

+ 13 - 9
Tests/RunCMake/find_package-CPS/License.cmake

@@ -8,20 +8,24 @@ set(CMAKE_FIND_PACKAGE_SORT_DIRECTION DEC)
 find_package(LicenseTest REQUIRED)
 
 function(expect_license COMPONENT EXPECTED)
-  set(target LicenseTest::${COMPONENT})
-  if(TARGET ${target})
-    get_target_property(license ${target} "SPDX_LICENSE")
+  if(TARGET ${COMPONENT})
+    get_target_property(license ${COMPONENT} "SPDX_LICENSE")
     if (NOT "${license}" STREQUAL "${EXPECTED}")
       message(SEND_ERROR
-        "Target ${target} has wrong license '${license}'"
+        "Target ${COMPONENT} has wrong license '${license}'"
         " (expected '${EXPECTED}') !")
     endif()
   else()
-    message(SEND_ERROR "Expected target ${target} was not found !")
+    message(SEND_ERROR "Expected target ${COMPONENT} was not found !")
   endif()
 endfunction()
 
-expect_license(SpecifiedOnTarget "Apache-2.0")
-expect_license(InheritFromRoot "BSD-3-Clause")
-expect_license(InheritFromAppendix "Apache-2.0")
-expect_license(DisableInheritance "license-NOTFOUND")
+expect_license(LicenseTest::SpecifiedOnTarget "Apache-2.0")
+expect_license(LicenseTest::InheritFromRoot "BSD-3-Clause")
+expect_license(LicenseTest::InheritFromAppendix "Apache-2.0")
+expect_license(LicenseTest::DisableInheritance "license-NOTFOUND")
+
+find_package(PackageLicenseTest REQUIRED)
+
+expect_license(PackageLicenseTest::SpecifiedOnTarget "Apache-2.0")
+expect_license(PackageLicenseTest::InheritFromRoot "BSD-3-Clause")

+ 16 - 0
Tests/RunCMake/find_package-CPS/cps/packagelicensetest.cps

@@ -0,0 +1,16 @@
+{
+  "cps_version": "0.13",
+  "name": "PackageLicenseTest",
+  "version": "1.0",
+  "license": "BSD-3-Clause",
+  "cps_path": "@prefix@/cps",
+  "components": {
+    "SpecifiedOnTarget": {
+      "type": "interface",
+      "license": "Apache-2.0"
+    },
+    "InheritFromRoot": {
+      "type": "interface"
+    }
+  }
+}