mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-07 06:09:52 -06:00
Merge topic 'cps-use-license' into release-4.2
94b6e36b6b find_package: Respect CPS license
Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !11343
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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
Tests/RunCMake/find_package-CPS/cps/packagelicensetest.cps
Normal file
16
Tests/RunCMake/find_package-CPS/cps/packagelicensetest.cps
Normal file
@@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user