cmSbom: Add genex support for configurations

This commit is contained in:
Taylor Sasser
2026-06-04 13:12:53 -04:00
parent 675c1a2d7a
commit 32af67dc72
77 changed files with 561 additions and 189 deletions

View File

@@ -17,12 +17,13 @@ cmBuildSbomBuilder::cmBuildSbomBuilder(cmSbomArguments args,
{
}
bool cmBuildSbomBuilder::Generate(std::ostream& os)
bool cmBuildSbomBuilder::Generate(std::ostream& os, std::string const& config)
{
if (!this->LocalGenerator) {
return false;
}
return this->GenerateForTargets(os, cmGeneratorExpression::BuildInterface);
return this->GenerateForTargets(os, config,
cmGeneratorExpression::BuildInterface);
}
cmExportFileGenerator::ExportInfo cmBuildSbomBuilder::FindExportInfoFor(

View File

@@ -5,6 +5,7 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include <iosfwd>
#include <string>
#include <vector>
#include "cmExportFileGenerator.h"
@@ -23,7 +24,7 @@ public:
std::vector<cmExportSet*> exportSets,
cmLocalGenerator* lg = nullptr);
bool Generate(std::ostream& os) override;
bool Generate(std::ostream& os, std::string const& config) override;
protected:
cmExportFileGenerator::ExportInfo FindExportInfoFor(

View File

@@ -3,14 +3,16 @@
#include "cmBuildSbomGenerator.h"
#include "cmGeneratedFileStream.h"
#include "cmStringAlgorithms.h"
void cmBuildSbomGenerator::Compute(cmLocalGenerator* lg)
{
this->Builder->Compute(lg);
}
bool cmBuildSbomGenerator::GenerateForBuild()
bool cmBuildSbomGenerator::GenerateForBuild(std::string const& config)
{
cmGeneratedFileStream os(this->OutputFile);
return this->Builder->Generate(os);
cmGeneratedFileStream os(
cmStrCat(this->OutputFile, "-", config, ".spdx.json"));
return this->Builder->Generate(os, config);
}

View File

@@ -2,6 +2,7 @@
file LICENSE.rst or https://cmake.org/licensing for details. */
#pragma once
#include <iosfwd>
#include <string>
#include <utility>
#include <vector>
@@ -10,7 +11,6 @@
#include "cmBuildSbomBuilder.h"
#include "cmSbomArguments.h"
class cmExportSet;
class cmGeneratorTarget;
class cmLocalGenerator;
@@ -45,13 +45,19 @@ public:
{
return this->Builder->CoversTarget(target);
}
bool GenerateForBuild(std::ostream& os, std::string const& config)
{
return this->Builder->Generate(os, config);
}
std::string const& GetPackageName() const
{
return this->Builder->GetPackageName();
}
/** Open the output file and write the SBOM document to it. */
bool GenerateForBuild();
bool GenerateForBuild(std::string const& config);
private:
std::string OutputFile;

View File

@@ -453,7 +453,7 @@ static bool HandleSbomMode(std::vector<std::string> const& args,
std::string const dir =
arguments.GetDefaultDestination(mf.GetCurrentBinaryDirectory());
std::string const fpath = cmStrCat(dir, '/', arguments.GetPackageFileName());
std::string const fpath = cmStrCat(dir, '/', arguments.GetPackageName());
if (gg->IsBuildSbomFile(fpath)) {
status.SetError(cmStrCat("SBOM command already specified for the file "_s,
@@ -473,7 +473,6 @@ static bool HandleSbomMode(std::vector<std::string> const& args,
}
auto builder = cm::make_unique<cmBuildSbomGenerator>(arguments, sets, fpath);
cmBuildSbomGenerator* rawPtr = builder.get();
mf.AddBuildSbomGenerator(std::move(builder));
gg->AddBuildSbomGenerator(rawPtr);

View File

@@ -521,7 +521,6 @@ std::string const& cmGeneratorExpressionInterpreter::Evaluate(
nullptr,
context,
};
return this->CompiledGeneratorExpression->Evaluate(context, &dagChecker,
this->HeadTarget);
}

View File

@@ -43,6 +43,7 @@
#include "cmGeneratedFileStream.h"
#include "cmGeneratorExpression.h"
#include "cmGeneratorTarget.h"
#include "cmInstallDirs.h"
#include "cmInstallExportGenerator.h"
#include "cmInstallGenerator.h"
#include "cmInstallRuntimeDependencySet.h"
@@ -1731,12 +1732,6 @@ bool cmGlobalGenerator::Compute()
// explicit install(SBOM) call.
cmValue sbomFormat = this->GetGlobalSetting("CMAKE_INSTALL_SBOM_FORMATS");
if (sbomFormat.IsSet() && sbomEnabled && !isTryCompile) {
std::string location =
this->Makefiles[0]->GetSafeDefinition("CMAKE_INSTALL_LIBDIR");
if (location.empty()) {
location = "lib";
}
std::string projectName = this->LocalGenerators[0]->GetProjectName();
for (auto& exportSet : this->ExportSets) {
bool isCovered =
@@ -1748,17 +1743,23 @@ bool cmGlobalGenerator::Compute()
if (isCovered) {
continue;
}
cmSbomArguments sbomDefaultArgs;
sbomDefaultArgs.ProjectName = projectName;
sbomDefaultArgs.PackageName = exportSet.first;
std::string dest = cmStrCat(location, "/sbom/", projectName);
this->Makefiles[0]->AddInstallGenerator(
cm::make_unique<cmInstallSbomGenerator>(
std::vector<cmExportSet*>{ &exportSet.second }, dest, "",
std::vector<std::string>(), "",
cmInstallGenerator::SelectMessageLevel(this->Makefiles[0].get()),
false, std::move(sbomDefaultArgs),
cmInstallGenerator::CaptureContext(this->Makefiles[0].get())));
cmSbomArguments args;
args.ProjectName = projectName;
args.PackageName = exportSet.first;
std::string dest = args.GetDefaultDestination(
cm::InstallDirs::GetLibraryDirectory(this->Makefiles[0].get()));
auto installGen = cm::make_unique<cmInstallSbomGenerator>(
std::vector<cmExportSet*>{ &exportSet.second }, dest, "",
std::vector<std::string>(), "",
cmInstallGenerator::SelectMessageLevel(this->Makefiles[0].get()),
false, std::move(args),
cmInstallGenerator::CaptureContext(this->Makefiles[0].get()));
cmInstallSbomGenerator const* rawPtr = installGen.get();
this->Makefiles[0]->AddInstallGenerator(std::move(installGen));
this->AddInstallSbomGenerator(rawPtr);
}
}
#endif
@@ -1869,13 +1870,17 @@ void cmGlobalGenerator::Generate()
}
}
#ifndef CMAKE_BOOTSTRAP
for (auto& sbomGen : this->BuildSbomGenerators) {
if (!sbomGen->GenerateForBuild()) {
if (!cmSystemTools::GetErrorOccurredFlag()) {
this->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR,
"Could not write SBOM file.");
for (std::string const& c : this->Makefiles[0]->GetGeneratorConfigs(
cmMakefile::IncludeEmptyConfig)) {
if (!sbomGen->GenerateForBuild(c)) {
if (!cmSystemTools::GetErrorOccurredFlag()) {
this->GetCMakeInstance()->IssueMessage(MessageType::FATAL_ERROR,
"Could not write SBOM file.");
}
return;
}
return;
}
}
#endif

View File

@@ -2565,12 +2565,8 @@ bool HandleSbomMode(std::vector<std::string> const& args,
// Get or construct the destination path.
std::string dest = ica.GetDestination();
if (dest.empty()) {
if (helper.Makefile->GetSafeDefinition("CMAKE_SYSTEM_NAME") == "Windows") {
dest = arguments.GetDefaultDestination();
} else {
dest =
arguments.GetDefaultDestination(helper.GetLibraryDestination(nullptr));
}
dest =
arguments.GetDefaultDestination(helper.GetLibraryDestination(nullptr));
}
// Check for CMD_INSTALL_ABSOLUTE_DESTINATION diagnostics.
@@ -2578,8 +2574,7 @@ bool HandleSbomMode(std::vector<std::string> const& args,
cmGlobalGenerator* gg = helper.Makefile->GetGlobalGenerator();
std::string const fpath =
cmStrCat(dest, '/', arguments.GetPackageFileName());
std::string const fpath = cmStrCat(dest, '/', arguments.GetPackageName());
if (gg->IsInstallSbomFile(fpath)) {
status.SetError(cmStrCat("SBOM command already specified for the file "_s,
cmSystemTools::GetFilenameNameView(fpath), '.'));

View File

@@ -17,12 +17,14 @@ cmInstallSbomBuilder::cmInstallSbomBuilder(
{
}
bool cmInstallSbomBuilder::Generate(std::ostream& os)
bool cmInstallSbomBuilder::Generate(std::ostream& os,
std::string const& config)
{
if (!this->LocalGenerator) {
return false;
}
return this->GenerateForTargets(os, cmGeneratorExpression::InstallInterface);
return this->GenerateForTargets(os, config,
cmGeneratorExpression::InstallInterface);
}
cmExportFileGenerator::ExportInfo cmInstallSbomBuilder::FindExportInfoFor(

View File

@@ -5,6 +5,7 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include <iosfwd>
#include <string>
#include <vector>
#include "cmExportFileGenerator.h"
@@ -23,7 +24,7 @@ public:
std::vector<cmExportSet*> exportSets,
cmLocalGenerator* lg = nullptr);
bool Generate(std::ostream& os) override;
bool Generate(std::ostream& os, std::string const& config) override;
protected:
cmExportFileGenerator::ExportInfo FindExportInfoFor(

View File

@@ -2,6 +2,7 @@
file LICENSE.rst or https://cmake.org/licensing for details. */
#include "cmInstallSbomGenerator.h"
#include <ostream>
#include <utility>
#include <vector>
@@ -13,7 +14,9 @@
#include "cmInstallSbomBuilder.h"
#include "cmInstallType.h"
#include "cmLocalGenerator.h"
#include "cmMakefile.h"
#include "cmSbomArguments.h"
#include "cmScriptGenerator.h"
#include "cmStringAlgorithms.h"
#include "cmSystemTools.h"
@@ -26,8 +29,9 @@ cmInstallSbomGenerator::cmInstallSbomGenerator(
std::move(component), message, excludeFromAll, false,
std::move(context))
, FilePermissions(std::move(filePermissions))
, SbomFileName(args.GetPackageFileName())
, SbomFileName(args.GetPackageName())
, SbomFilePath(cmStrCat(this->Destination, '/', this->SbomFileName))
, SbomFormat(args.GetFormat())
, Builder(cm::make_unique<cmInstallSbomBuilder>(std::move(args),
std::move(exportSets)))
{
@@ -64,15 +68,20 @@ void cmInstallSbomGenerator::GenerateScript(std::ostream& os)
cmCryptoHash hasher(cmCryptoHash::AlgoMD5);
std::string const tempDir =
cmStrCat(this->LocalGenerator->GetCurrentBinaryDirectory(),
"/CMakeFiles/Sbom/", hasher.HashString(this->Destination));
"/CMakeFiles/sbom/", hasher.HashString(this->Destination));
cmSystemTools::MakeDirectory(tempDir);
this->TempSbomFilePath = cmStrCat(tempDir, '/', this->SbomFileName);
// Generate the SBOM file now, at cmake generate time.
cmGeneratedFileStream sbomStream(this->TempSbomFilePath);
this->Builder->Generate(sbomStream);
for (std::string const& c :
this->LocalGenerator->GetMakefile()->GetGeneratorConfigs(
cmMakefile::IncludeEmptyConfig)) {
std::string configName =
cmStrCat(tempDir, '/', this->SbomFileName, "-", c, ".spdx.json");
cmGeneratedFileStream sbomStream(configName);
this->TempSbomFiles.emplace(c, configName);
if (!this->Builder->Generate(sbomStream, c)) {
break;
}
}
// Emit the cmake_install.cmake script to copy the file at install time.
this->cmInstallGenerator::GenerateScript(os);
@@ -81,8 +90,12 @@ void cmInstallSbomGenerator::GenerateScript(std::ostream& os)
void cmInstallSbomGenerator::GenerateScriptActions(std::ostream& os,
Indent indent)
{
std::vector<std::string> files{ this->TempSbomFilePath };
this->AddInstallRule(os, this->Destination, cmInstallType_FILES, files,
false, this->FilePermissions.c_str(), nullptr, nullptr,
nullptr, indent);
for (auto const& i : this->TempSbomFiles) {
std::string configTest = this->CreateConfigTest(i.first);
os << indent << "if(" << configTest << ")\n";
this->AddInstallRule(os, this->Destination, cmInstallType_FILES,
{ i.second }, false, this->FilePermissions.c_str(),
nullptr, nullptr, nullptr, indent.Next());
os << indent << "endif()\n";
}
}

View File

@@ -5,18 +5,19 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include <iosfwd>
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "cmInstallGenerator.h"
#include "cmSbomArguments.h"
class cmDiagnosticContext;
class cmExportSet;
class cmGeneratorTarget;
class cmInstallSbomBuilder;
class cmLocalGenerator;
class cmSbomArguments;
/** \class cmInstallSbomGenerator
* \brief Generate installation rules for SBOM files.
@@ -59,10 +60,11 @@ protected:
void GenerateScriptActions(std::ostream& os, Indent indent) override;
private:
std::string TempSbomFilePath;
std::map<std::string, std::string> TempSbomFiles;
std::string const FilePermissions;
std::string const SbomFileName;
std::string const SbomFilePath;
cmSbomArguments::SbomFormat SbomFormat;
cmLocalGenerator* LocalGenerator = nullptr;
std::unique_ptr<cmInstallSbomBuilder> Builder;
};

View File

@@ -2,12 +2,8 @@
file LICENSE.rst or https://cmake.org/licensing for details. */
#include "cmSbomArguments.h"
#include <algorithm>
#include <cm/string_view>
#include "cmsys/String.h"
#include "cmExecutionStatus.h"
#include "cmGeneratorExpression.h"
#include "cmStringAlgorithms.h"
@@ -82,7 +78,7 @@ std::string cmSbomArguments::GetNamespace() const
return cmStrCat(this->PackageName, "::"_s);
}
std::string cmSbomArguments::GetPackageDirName() const
std::string cmSbomArguments::GetPackageName() const
{
return this->PackageName;
}
@@ -91,9 +87,9 @@ std::string cmSbomArguments::GetDefaultDestination(
std::string const& root) const
{
if (root.empty()) {
return cmStrCat("sbom/"_s, this->GetPackageDirName());
return cmStrCat("sbom/"_s, this->GetPackageName());
}
return cmStrCat(root, '/', "sbom/"_s, this->GetPackageDirName());
return cmStrCat(root, '/', "sbom/"_s, this->GetPackageName());
}
cmSbomArguments::SbomFormat cmSbomArguments::GetFormat() const
@@ -103,12 +99,3 @@ cmSbomArguments::SbomFormat cmSbomArguments::GetFormat() const
}
return ParseSbomFormat(this->Format);
}
std::string cmSbomArguments::GetPackageFileName() const
{
std::string const pkgNameOnDisk = this->GetPackageDirName();
std::string format = GetSbomFileExtension(this->GetFormat());
std::transform(format.begin(), format.end(), format.begin(),
cmsysString_tolower);
return cmStrCat(pkgNameOnDisk, format);
}

View File

@@ -35,8 +35,7 @@ public:
bool Check(cmExecutionStatus& status) const override;
std::string GetNamespace() const;
std::string GetPackageDirName() const;
std::string GetPackageFileName() const;
std::string GetPackageName() const;
std::string GetDefaultDestination(std::string const& root = {}) const;
SbomFormat GetFormat() const;

View File

@@ -115,10 +115,11 @@ bool cmSbomBuilder::CoversExportSet(cmExportSet const* set) const
}
bool cmSbomBuilder::GenerateForTargets(
std::ostream& os, cmGeneratorExpression::PreprocessContext preprocessContext)
std::ostream& os, std::string const& config,
cmGeneratorExpression::PreprocessContext preprocessContext)
{
cmSbomDocument doc;
doc.Graph.reserve(256);
doc.Graph.reserve(512);
cmSpdxCreationInfo const* ci =
insert_back(doc.Graph, this->GenerateCreationInfo());
@@ -131,19 +132,23 @@ bool cmSbomBuilder::GenerateForTargets(
this->PopulateLinkLibrariesProperty(target, preprocessContext, properties);
this->PopulateInterfaceLinkLibrariesProperty(target, preprocessContext,
properties);
targetProps.push_back(
TargetProperties{ insert_back(project->RootElements,
this->GenerateImportTarget(ci, target)),
target, std::move(properties) });
targetProps.push_back(TargetProperties{
insert_back(project->RootElements,
this->GenerateImportTarget(ci, target)),
target,
std::move(properties),
});
}
bool status = true;
for (TargetProperties const& target : targetProps) {
this->GenerateProperties(doc, project, ci, target, targetProps);
status &=
this->GenerateProperties(doc, project, ci, target, targetProps, config);
}
this->WriteSbom(doc, os);
return true;
if (status) {
this->WriteSbom(doc, os);
}
return status;
}
void cmSbomBuilder::WriteSbom(cmSbomDocument& doc, std::ostream& os) const
@@ -248,23 +253,31 @@ cmSpdxPackage cmSbomBuilder::GenerateImportTarget(
return package;
}
void cmSbomBuilder::GenerateLinkProperties(
bool cmSbomBuilder::GenerateLinkProperties(
cmSbomDocument& doc, cmSpdxDocument* project, cmSpdxCreationInfo const* ci,
std::string const& libraries, TargetProperties const& current,
std::vector<TargetProperties> const& allTargets) const
std::vector<TargetProperties> const& allTargets,
std::string const& config) const
{
auto itProp = current.Properties.find(libraries);
if (itProp == current.Properties.end()) {
return;
return true;
}
std::map<std::string, std::vector<std::string>> allowList = { { "LINK_ONLY",
{} } };
std::string interfaceLinkLibraries;
if (!cmGeneratorExpression::ForbidGeneratorExpressions(
current.Target, itProp->first, itProp->second, interfaceLinkLibraries,
allowList)) {
return;
cmGeneratorExpression ge(*current.Target->Makefile->GetCMakeInstance());
std::unique_ptr<cmCompiledGeneratorExpression> cge =
ge.Parse(itProp->second);
std::string evaluatedLibraries =
cge->Evaluate(current.Target->GetLocalGenerator(), config, current.Target);
if (cge->GetHadHeadSensitiveCondition()) {
current.Target->Makefile->IssueMessage(
MessageType::FATAL_ERROR,
cmStrCat("Property \"", libraries, "\" of target \"",
current.Target->GetName(),
"\" contains a generator expression that is not allowed for "
"SBOM generation."));
return false;
}
auto makeRel = [&](char const* id, char const* desc) {
@@ -316,26 +329,21 @@ void cmSbomBuilder::GenerateLinkProperties(
return { false, insert_back(project->Elements, std::move(pkg)) };
};
auto handleDependencies = [&](std::vector<std::string> const& names,
cmSpdxRelationship& internalDeps,
cmSpdxRelationship& externalDeps) {
for (auto const& n : names) {
auto res = addArtifact(n);
if (!res.second) {
continue;
}
if (res.first) {
internalDeps.To.push_back(res.second);
} else {
externalDeps.To.push_back(res.second);
}
cmList names{ evaluatedLibraries };
names.sort();
names.remove_duplicates();
for (std::string const& n : names) {
auto res = addArtifact(n);
if (!res.second) {
continue;
}
};
handleDependencies(allowList["LINK_ONLY"], linkLibraries, linkRequires);
handleDependencies(cmList{ interfaceLinkLibraries }, linkLibraries,
buildRequires);
if (res.first) {
linkLibraries.To.push_back(res.second);
} else {
buildRequires.To.push_back(res.second);
}
}
if (!linkLibraries.To.empty()) {
insert_back(doc.Graph, std::move(linkLibraries));
@@ -346,18 +354,22 @@ void cmSbomBuilder::GenerateLinkProperties(
if (!buildRequires.To.empty()) {
insert_back(doc.Graph, std::move(buildRequires));
}
return true;
}
bool cmSbomBuilder::GenerateProperties(
cmSbomDocument& doc, cmSpdxDocument* proj, cmSpdxCreationInfo const* ci,
TargetProperties const& current,
std::vector<TargetProperties> const& allTargets) const
std::vector<TargetProperties> const& allTargets,
std::string const& config) const
{
this->GenerateLinkProperties(doc, proj, ci, "LINK_LIBRARIES", current,
allTargets);
this->GenerateLinkProperties(doc, proj, ci, "INTERFACE_LINK_LIBRARIES",
current, allTargets);
return true;
bool status = true;
status &= this->GenerateLinkProperties(doc, proj, ci, "LINK_LIBRARIES",
current, allTargets, config);
status &= this->GenerateLinkProperties(
doc, proj, ci, "INTERFACE_LINK_LIBRARIES", current, allTargets, config);
return status;
}
bool cmSbomBuilder::PopulateLinkLibrariesProperty(
@@ -365,10 +377,11 @@ bool cmSbomBuilder::PopulateLinkLibrariesProperty(
cmGeneratorExpression::PreprocessContext preprocessRule,
ImportPropertyMap& properties)
{
static std::array<std::string, 3> const linkIfaceProps = {
{ "LINK_LIBRARIES", "LINK_LIBRARIES_DIRECT",
"LINK_LIBRARIES_DIRECT_EXCLUDE" }
};
static std::array<std::string, 3> const linkIfaceProps = { {
"LINK_LIBRARIES",
"LINK_LIBRARIES_DIRECT",
"LINK_LIBRARIES_DIRECT_EXCLUDE",
} };
bool hadLINK_LIBRARIES = false;
for (std::string const& linkIfaceProp : linkIfaceProps) {
if (cmValue input = target->GetProperty(linkIfaceProp)) {

View File

@@ -48,10 +48,9 @@ public:
* query CoversTarget() before any Generate() runs. */
void Compute(cmLocalGenerator* lg);
/** Produce the SBOM document on `os`. Implementations pick the
* generator-expression preprocess context (BuildInterface vs
* InstallInterface) and delegate to GenerateForTargets. */
virtual bool Generate(std::ostream& os) = 0;
/** Produce the SBOM document on `os`. Implementations select their own
* target set (via CollectTargets) and preprocess context. */
virtual bool Generate(std::ostream& os, std::string const& config) = 0;
/** Identifier this SBOM publishes itself as (the SPDX document name and
* the namespace under which other SBOMs refer to its contents). */
@@ -59,10 +58,13 @@ public:
/** True if `target` is one of the targets this SBOM directly describes. */
bool CoversTarget(cmGeneratorTarget const* target) const;
/** True if `set` is one of the export sets this SBOM was built from. */
bool CoversExportSet(cmExportSet const* set) const;
void AddConfiguration(std::string const& config)
{
this->Configurations.push_back(config);
}
/** Names of peer SBOMs (same build/install mode) that cover a target.
* Used by NoteLinkedTarget to attribute a cross-reference when no
* install(export) namespace is available. Sorted alphabetically. */
@@ -93,7 +95,7 @@ protected:
/** Generate an sbom for the targets in this->SbomTargets. Each leaf class
* calls this internally */
bool GenerateForTargets(
std::ostream& os,
std::ostream& os, std::string const& config,
cmGeneratorExpression::PreprocessContext preprocessContext);
using ImportPropertyMap = std::map<std::string, std::string>;
@@ -115,15 +117,18 @@ protected:
bool AddPackageInformation(cmSpdxPackage& artifact, std::string const& name,
cmPackageInformation const& package) const;
bool GenerateProperties(
cmSbomDocument& doc, cmSpdxDocument* project, cmSpdxCreationInfo const* ci,
TargetProperties const& current,
std::vector<TargetProperties> const& allTargets) const;
bool GenerateProperties(cmSbomDocument& doc, cmSpdxDocument* project,
cmSpdxCreationInfo const* ci,
TargetProperties const& current,
std::vector<TargetProperties> const& allTargets,
std::string const& config) const;
void GenerateLinkProperties(
cmSbomDocument& doc, cmSpdxDocument* project, cmSpdxCreationInfo const* ci,
std::string const& libraries, TargetProperties const& current,
std::vector<TargetProperties> const& allTargets) const;
bool GenerateLinkProperties(cmSbomDocument& doc, cmSpdxDocument* project,
cmSpdxCreationInfo const* ci,
std::string const& libraries,
TargetProperties const& current,
std::vector<TargetProperties> const& allTargets,
std::string const& config) const;
bool NoteLinkedTarget(cmGeneratorTarget const* target,
std::string const& linkedName,
@@ -176,4 +181,5 @@ private:
// Accumulated during generation
std::map<std::string, LinkInfo> LinkTargets;
std::map<std::string, cmPackageInformation> Requirements;
std::vector<std::string> Configurations;
};

View File

@@ -1,2 +1,2 @@
file(READ "${RunCMake_TEST_INSTALL_DIR}/lib/sbom/test_project/application_targets.spdx.json" content)
file(READ "${RunCMake_TEST_INSTALL_DIR}/lib/sbom/application_targets/application_targets-Debug.spdx.json" content)
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/ApplicationTarget-install-check.cmake)

View File

@@ -0,0 +1,11 @@
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/Assertions.cmake)
get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(_isMultiConfig)
file(READ "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/sbom/800147c20378e0c5769bafa56e83195d/foo-Debug.spdx.json" DebugSbom)
file(READ "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/sbom/800147c20378e0c5769bafa56e83195d/foo-Release.spdx.json" ReleaseSbom)
else()
file(READ "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/sbom/800147c20378e0c5769bafa56e83195d/foo-Debug.spdx.json" DebugSbom)
endif()
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/Config-check.cmake)

View File

@@ -0,0 +1 @@
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/Config.cmake)

View File

@@ -0,0 +1 @@
1

View File

@@ -0,0 +1,3 @@
CMake Error in CMakeLists.txt:
Property "INTERFACE_LINK_LIBRARIES" of target "foo" contains a generator
expression that is not allowed for SBOM generation.

View File

@@ -0,0 +1 @@
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/ForbiddenGenex.cmake)

View File

@@ -0,0 +1,11 @@
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/Assertions.cmake)
get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(_isMultiConfig)
file(READ "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/sbom/800147c20378e0c5769bafa56e83195d/foo-BarConfig.spdx.json" BarConfig)
file(READ "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/sbom/800147c20378e0c5769bafa56e83195d/foo-BazConfig.spdx.json" BazConfig)
else()
file(READ "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/sbom/800147c20378e0c5769bafa56e83195d/foo-BarConfig.spdx.json" BarConfig)
endif()
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/Genex-check.cmake)

View File

@@ -0,0 +1 @@
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/Genex.cmake)

View File

@@ -1,2 +1,2 @@
file(READ "${RunCMake_TEST_INSTALL_DIR}/lib/sbom/test_project/interface_targets.spdx.json" content)
file(READ "${RunCMake_TEST_INSTALL_DIR}/lib/sbom/interface_targets/interface_targets-Debug.spdx.json" content)
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/InterfaceTarget-install-check.cmake)

View File

@@ -1,2 +1,2 @@
file(READ "${RunCMake_TEST_INSTALL_DIR}/lib/sbom/test_project/test_targets.spdx.json" content)
file(READ "${RunCMake_TEST_INSTALL_DIR}/lib/sbom/test_targets/test_targets-Debug.spdx.json" content)
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/MissingPackageNamespace-install-check.cmake)

View File

@@ -1,20 +1,20 @@
set(failures "")
foreach(f explicit_root_sbom explicit_subdir_sbom)
if(NOT EXISTS "${RunCMake_TEST_INSTALL_DIR}/${f}.spdx.json")
list(APPEND failures "expected explicit SBOM ${f}.spdx.json to exist")
if(NOT EXISTS "${RunCMake_TEST_INSTALL_DIR}/${f}-Debug.spdx.json")
list(APPEND failures "expected explicit SBOM ${f}-Debug.spdx.json to exist")
endif()
endforeach()
foreach(f implicit_root implicit_subdir)
if(NOT EXISTS "${RunCMake_TEST_INSTALL_DIR}/lib/sbom/test_project/${f}.spdx.json")
list(APPEND failures "expected autogen SBOM ${f}.spdx.json to exist")
if(NOT EXISTS "${RunCMake_TEST_INSTALL_DIR}/lib/sbom/${f}/${f}-Debug.spdx.json")
list(APPEND failures "expected autogen SBOM ${f}-Debug.spdx.json to exist")
endif()
endforeach()
foreach(f explicit_root explicit_subdir)
if(EXISTS "${RunCMake_TEST_INSTALL_DIR}/lib/sbom/test_project/${f}.spdx.json")
list(APPEND failures "autogen wrongly produced ${f}.spdx.json (should be suppressed by explicit install(SBOM))")
if(EXISTS "${RunCMake_TEST_INSTALL_DIR}/lib/sbom/${f}/${f}-Debug.spdx.json")
list(APPEND failures "autogen wrongly produced ${f}-Debug.spdx.json (should be suppressed by explicit install(SBOM))")
endif()
endforeach()

View File

@@ -1,2 +1,2 @@
file(READ "${RunCMake_TEST_INSTALL_DIR}/lib/sbom/test/test_targets.spdx.json" content)
file(READ "${RunCMake_TEST_INSTALL_DIR}/lib/sbom/test_targets/test_targets-Debug.spdx.json" content)
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/ProjectMetadata-install-check.cmake)

View File

@@ -11,7 +11,7 @@ function(run_cmake_error test)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${test}-build)
set(RunCMake_TEST_OPTIONS ${common_test_options})
if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
list(APPEND RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=DEBUG)
list(APPEND RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
endif()
run_cmake(${test})
endfunction()
@@ -23,7 +23,7 @@ function(run_cmake_install test)
set(RunCMake_TEST_OPTIONS ${common_test_options} ${extra_options})
list(APPEND RunCMake_TEST_OPTIONS -DCMAKE_INSTALL_PREFIX=${RunCMake_TEST_INSTALL_DIR})
if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
list(APPEND RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=DEBUG)
list(APPEND RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
endif()
run_cmake(${test})
@@ -34,6 +34,14 @@ function(run_cmake_install test)
run_cmake_command(${test}-install ${CMAKE_COMMAND} --install . --config Debug)
endfunction()
function(run_cmake_configure test)
set(extra_options ${ARGN})
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${test}-build)
set(RunCMake_TEST_OPTIONS ${common_test_options} ${extra_options})
run_cmake(${test})
endfunction()
run_cmake_install(ApplicationTarget)
run_cmake_install(InterfaceTarget)
run_cmake_install(SharedTarget)
@@ -43,3 +51,7 @@ run_cmake_install(ProjectMetadata)
run_cmake_install(PartialCoverage)
run_cmake_error(ReferencesNonExportedTarget)
run_cmake_configure(Config)
run_cmake_configure(Genex)
run_cmake_configure(ForbiddenGenex)

View File

@@ -1,2 +1,2 @@
file(READ "${RunCMake_TEST_INSTALL_DIR}/lib/sbom/test_project/shared_targets.spdx.json" content)
file(READ "${RunCMake_TEST_INSTALL_DIR}/lib/sbom/shared_targets/shared_targets-Debug.spdx.json" content)
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/SharedTarget-install-check.cmake)

View File

@@ -1,2 +1,2 @@
file(READ "${RunCMake_TEST_BINARY_DIR}/sbom/application_targets/application_targets.spdx.json" content)
file(READ "${RunCMake_TEST_BINARY_DIR}/sbom/application_targets/application_targets-Debug.spdx.json" content)
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/ApplicationTarget-install-check.cmake)

View File

@@ -0,0 +1,11 @@
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/Assertions.cmake)
get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(_isMultiConfig)
file(READ "${RunCMake_TEST_BINARY_DIR}/sbom/foo/foo-Debug.spdx.json" DebugSbom)
file(READ "${RunCMake_TEST_BINARY_DIR}/sbom/foo/foo-Release.spdx.json" ReleaseSbom)
else()
file(READ "${RunCMake_TEST_BINARY_DIR}/sbom/foo/foo-Debug.spdx.json" DebugSbom)
endif()
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/Config-check.cmake)

View File

@@ -0,0 +1,6 @@
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/Config.cmake)
export(SBOM foo
EXPORTS foo
FORMAT "spdx-3.0+json"
)

View File

@@ -1,2 +1,2 @@
CMake Error at DuplicateSbom\.cmake:[0-9]+ \(export\):
export SBOM command already specified for the file mySbom\.spdx\.json\.
export SBOM command already specified for the file mySbom.

View File

@@ -1,2 +1,2 @@
file(READ "${RunCMake_TEST_BINARY_DIR}/sbom/mySbom/mySbom.spdx.json" content)
file(READ "${RunCMake_TEST_BINARY_DIR}/sbom/mySbom/mySbom-Debug.spdx.json" content)
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/EmptyNamespaceFallback-install-check.cmake)

View File

@@ -0,0 +1 @@
1

View File

@@ -0,0 +1,3 @@
CMake Error in CMakeLists.txt:
Property "INTERFACE_LINK_LIBRARIES" of target "foo" contains a generator
expression that is not allowed for SBOM generation.

View File

@@ -0,0 +1,5 @@
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/ForbiddenGenex.cmake)
export(SBOM foo
EXPORTS foo
FORMAT "spdx-3.0+json"
)

View File

@@ -0,0 +1,11 @@
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/Assertions.cmake)
get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(_isMultiConfig)
file(READ "${RunCMake_TEST_BINARY_DIR}/sbom/foo/foo-BarConfig.spdx.json" BarConfig)
file(READ "${RunCMake_TEST_BINARY_DIR}/sbom/foo/foo-BazConfig.spdx.json" BazConfig)
else()
file(READ "${RunCMake_TEST_BINARY_DIR}/sbom/foo/foo-BarConfig.spdx.json" BarConfig)
endif()
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/Genex-check.cmake)

View File

@@ -0,0 +1,5 @@
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/Genex.cmake)
export(SBOM foo
EXPORTS foo
FORMAT "spdx-3.0+json"
)

View File

@@ -1,2 +1,2 @@
file(READ "${RunCMake_TEST_BINARY_DIR}/sbom/interface_targets/interface_targets.spdx.json" content)
file(READ "${RunCMake_TEST_BINARY_DIR}/sbom/interface_targets/interface_targets-Debug.spdx.json" content)
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/InterfaceTarget-install-check.cmake)

View File

@@ -1,2 +1,2 @@
file(READ "${RunCMake_TEST_BINARY_DIR}/sbom/test_targets/test_targets.spdx.json" content)
file(READ "${RunCMake_TEST_BINARY_DIR}/sbom/test_targets/test_targets-Debug.spdx.json" content)
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/MissingPackageNamespace-install-check.cmake)

View File

@@ -1,2 +1,2 @@
file(READ "${RunCMake_TEST_BINARY_DIR}/sbom/mySbom/mySbom.spdx.json" content)
file(READ "${RunCMake_TEST_BINARY_DIR}/sbom/mySbom/mySbom-Debug.spdx.json" content)
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/MultiSetSingleSbom-install-check.cmake)

View File

@@ -1,3 +1,3 @@
file(READ "${RunCMake_TEST_BINARY_DIR}/sbom/test_targets/test_targets.spdx.json" content)
file(READ "${RunCMake_TEST_BINARY_DIR}/sbom/test_targets/test_targets-Debug.spdx.json" content)
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/ProjectMetadata-install-check.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/ProjectMetadataExplicitAssertions.cmake)

View File

@@ -1,3 +1,3 @@
file(READ "${RunCMake_TEST_BINARY_DIR}/sbom/bar_sbom/bar_sbom.spdx.json" BAR_CONTENT)
file(READ "${RunCMake_TEST_BINARY_DIR}/sbom/foo_sbom/foo_sbom.spdx.json" FOO_CONTENT)
file(READ "${RunCMake_TEST_BINARY_DIR}/sbom/bar_sbom/bar_sbom-Debug.spdx.json" BAR_CONTENT)
file(READ "${RunCMake_TEST_BINARY_DIR}/sbom/foo_sbom/foo_sbom-Debug.spdx.json" FOO_CONTENT)
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/Requirements-install-check.cmake)

View File

@@ -9,7 +9,7 @@ function(run_cmake_error test)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${test}-build)
set(RunCMake_TEST_OPTIONS ${common_test_options})
if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
list(APPEND RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=DEBUG)
list(APPEND RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
endif()
run_cmake(${test})
endfunction()
@@ -21,7 +21,7 @@ function(run_cmake_install test)
set(RunCMake_TEST_OPTIONS ${common_test_options} ${extra_options})
list(APPEND RunCMake_TEST_OPTIONS -DCMAKE_INSTALL_PREFIX=${RunCMake_TEST_INSTALL_DIR})
if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
list(APPEND RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=DEBUG)
list(APPEND RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
endif()
run_cmake(${test})
@@ -32,6 +32,13 @@ function(run_cmake_install test)
run_cmake_command(${test}-install ${CMAKE_COMMAND} --install . --config Debug)
endfunction()
function(run_cmake_configure test)
set(extra_options ${ARGN})
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${test}-build)
set(RunCMake_TEST_OPTIONS ${common_test_options} ${extra_options})
run_cmake(${test})
endfunction()
run_cmake_install(ApplicationTarget)
run_cmake_install(InstallExportPlusSbomSameSet)
run_cmake_install(InterfaceTarget)
@@ -50,3 +57,7 @@ run_cmake_error(ReferencesNonExportedTarget)
run_cmake_error(MultiNamespaceAmbiguity)
run_cmake_error(MultiSetAmbiguity)
run_cmake_error(DuplicateSbom)
run_cmake_configure(Config)
run_cmake_configure(Genex)
run_cmake_configure(ForbiddenGenex)

View File

@@ -1,2 +1,2 @@
file(READ "${RunCMake_TEST_BINARY_DIR}/sbom/bar_sbom/bar_sbom.spdx.json" BAR_CONTENT)
file(READ "${RunCMake_TEST_BINARY_DIR}/sbom/bar_sbom/bar_sbom-Debug.spdx.json" BAR_CONTENT)
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/SbomNamespaceAmbiguity-install-check.cmake)

View File

@@ -1,3 +1,3 @@
file(READ "${RunCMake_TEST_BINARY_DIR}/sbom/bar/bar.spdx.json" BAR_CONTENT)
file(READ "${RunCMake_TEST_BINARY_DIR}/sbom/foo/foo.spdx.json" FOO_CONTENT)
file(READ "${RunCMake_TEST_BINARY_DIR}/sbom/bar/bar-Debug.spdx.json" BAR_CONTENT)
file(READ "${RunCMake_TEST_BINARY_DIR}/sbom/foo/foo-Debug.spdx.json" FOO_CONTENT)
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/SbomNamespaceFallback-install-check.cmake)

View File

@@ -1,2 +1,2 @@
file(READ "${RunCMake_TEST_BINARY_DIR}/sbom/shared_targets/shared_targets.spdx.json" content)
file(READ "${RunCMake_TEST_BINARY_DIR}/sbom/shared_targets/shared_targets-Debug.spdx.json" content)
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/SharedTarget-install-check.cmake)

View File

@@ -1,2 +1,2 @@
file(READ "${RunCMake_TEST_BINARY_DIR}/sbom/mySbom/mySbom.spdx.json" content)
file(READ "${RunCMake_TEST_BINARY_DIR}/sbom/mySbom/mySbom-Debug.spdx.json" content)
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/TargetInMultipleSets-install-check.cmake)

View File

@@ -1,2 +1,2 @@
file(READ "${RunCMake_TEST_INSTALL_DIR}/application_targets.spdx.json" content)
file(READ "${RunCMake_TEST_INSTALL_DIR}/application_targets-Debug.spdx.json" content)
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/ApplicationTarget-install-check.cmake)

View File

@@ -0,0 +1,11 @@
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/Assertions.cmake)
get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(_isMultiConfig)
file(READ "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/sbom/5058f1af8388633f609cadb75a75dc9d/foo-Debug.spdx.json" DebugSbom)
file(READ "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/sbom/5058f1af8388633f609cadb75a75dc9d/foo-Release.spdx.json" ReleaseSbom)
else()
file(READ "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/sbom/5058f1af8388633f609cadb75a75dc9d/foo-Debug.spdx.json" DebugSbom)
endif()
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/Config-check.cmake)

View File

@@ -0,0 +1,6 @@
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/Config.cmake)
install(SBOM foo
EXPORTS foo
FORMAT "spdx-3.0+json"
DESTINATION .
)

View File

@@ -1,2 +1,2 @@
CMake Error at DuplicateSbom\.cmake:[0-9]+ \(install\):
install SBOM command already specified for the file mySbom\.spdx\.json\.
install SBOM command already specified for the file mySbom.

View File

@@ -1,2 +1,2 @@
file(READ "${RunCMake_TEST_INSTALL_DIR}/mySbom.spdx.json" content)
file(READ "${RunCMake_TEST_INSTALL_DIR}/mySbom-Debug.spdx.json" content)
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/EmptyNamespaceFallback-install-check.cmake)

View File

@@ -0,0 +1 @@
1

View File

@@ -0,0 +1,3 @@
CMake Error in CMakeLists.txt:
Property "INTERFACE_LINK_LIBRARIES" of target "foo" contains a generator
expression that is not allowed for SBOM generation.

View File

@@ -0,0 +1,6 @@
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/ForbiddenGenex.cmake)
install(SBOM foo
EXPORTS foo
FORMAT "spdx-3.0+json"
DESTINATION .
)

View File

@@ -0,0 +1,11 @@
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/Assertions.cmake)
get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(_isMultiConfig)
file(READ "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/sbom/5058f1af8388633f609cadb75a75dc9d/foo-BarConfig.spdx.json" BarConfig)
file(READ "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/sbom/5058f1af8388633f609cadb75a75dc9d/foo-BazConfig.spdx.json" BazConfig)
else()
file(READ "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/sbom/5058f1af8388633f609cadb75a75dc9d/foo-BarConfig.spdx.json" BarConfig)
endif()
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/Genex-check.cmake)

View File

@@ -0,0 +1,6 @@
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/Genex.cmake)
install(SBOM foo
EXPORTS foo
FORMAT "spdx-3.0+json"
DESTINATION .
)

View File

@@ -1,2 +1,2 @@
file(READ "${RunCMake_TEST_INSTALL_DIR}/interface_targets.spdx.json" content)
file(READ "${RunCMake_TEST_INSTALL_DIR}/interface_targets-Debug.spdx.json" content)
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/InterfaceTarget-install-check.cmake)

View File

@@ -1,2 +1,2 @@
file(READ "${RunCMake_TEST_INSTALL_DIR}/test_targets.spdx.json" content)
file(READ "${RunCMake_TEST_INSTALL_DIR}/test_targets-Debug.spdx.json" content)
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/MissingPackageNamespace-install-check.cmake)

View File

@@ -1,2 +1,2 @@
file(READ "${RunCMake_TEST_INSTALL_DIR}/mySbom.spdx.json" content)
file(READ "${RunCMake_TEST_INSTALL_DIR}/mySbom-Debug.spdx.json" content)
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/MultiSetSingleSbom-install-check.cmake)

View File

@@ -1,3 +1,3 @@
file(READ "${RunCMake_TEST_INSTALL_DIR}/test_targets.spdx.json" content)
file(READ "${RunCMake_TEST_INSTALL_DIR}/test_targets-Debug.spdx.json" content)
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/ProjectMetadata-install-check.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/ProjectMetadataExplicitAssertions.cmake)

View File

@@ -1,3 +1,3 @@
file(READ "${RunCMake_TEST_INSTALL_DIR}/bar_sbom.spdx.json" BAR_CONTENT)
file(READ "${RunCMake_TEST_INSTALL_DIR}/foo_sbom.spdx.json" FOO_CONTENT)
file(READ "${RunCMake_TEST_INSTALL_DIR}/bar_sbom-Debug.spdx.json" BAR_CONTENT)
file(READ "${RunCMake_TEST_INSTALL_DIR}/foo_sbom-Debug.spdx.json" FOO_CONTENT)
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/Requirements-install-check.cmake)

View File

@@ -9,7 +9,7 @@ function(run_cmake_error test)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${test}-build)
set(RunCMake_TEST_OPTIONS ${common_test_options})
if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
list(APPEND RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=DEBUG)
list(APPEND RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
endif()
run_cmake(${test})
endfunction()
@@ -21,7 +21,7 @@ function(run_cmake_install test)
set(RunCMake_TEST_OPTIONS ${common_test_options} ${extra_options})
list(APPEND RunCMake_TEST_OPTIONS -DCMAKE_INSTALL_PREFIX=${RunCMake_TEST_INSTALL_DIR})
if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
list(APPEND RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=DEBUG)
list(APPEND RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
endif()
run_cmake(${test})
@@ -32,13 +32,16 @@ function(run_cmake_install test)
run_cmake_command(${test}-install ${CMAKE_COMMAND} --install . --config Debug)
endfunction()
function(run_cmake_configure test)
set(extra_options ${ARGN})
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${test}-build)
set(RunCMake_TEST_OPTIONS ${common_test_options} ${extra_options})
run_cmake(${test})
endfunction()
run_cmake_install(ApplicationTarget)
run_cmake_install(InstallExportPlusSbomSameSet)
run_cmake_install(InterfaceTarget)
run_cmake_install(SharedTarget)
run_cmake_install(Requirements)
run_cmake_install(SbomNamespaceFallback)
run_cmake_install(MultiSetSingleSbom)
run_cmake_install(TargetInMultipleSets)
run_cmake_install(EmptyNamespaceFallback -Wauthor)
run_cmake_install(SbomNamespaceAmbiguity -Wauthor)
@@ -51,3 +54,7 @@ run_cmake_error(ReferencesNonExportedTarget)
run_cmake_error(MultiNamespaceAmbiguity)
run_cmake_error(MultiSetAmbiguity)
run_cmake_error(DuplicateSbom)
run_cmake_configure(Config)
run_cmake_configure(Genex)
run_cmake_configure(ForbiddenGenex)

View File

@@ -1,2 +1,2 @@
file(READ "${RunCMake_TEST_INSTALL_DIR}/bar_sbom.spdx.json" BAR_CONTENT)
file(READ "${RunCMake_TEST_INSTALL_DIR}/bar_sbom-Debug.spdx.json" BAR_CONTENT)
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/SbomNamespaceAmbiguity-install-check.cmake)

View File

@@ -1,3 +1,3 @@
file(READ "${RunCMake_TEST_INSTALL_DIR}/bar.spdx.json" BAR_CONTENT)
file(READ "${RunCMake_TEST_INSTALL_DIR}/foo.spdx.json" FOO_CONTENT)
file(READ "${RunCMake_TEST_INSTALL_DIR}/bar-Debug.spdx.json" BAR_CONTENT)
file(READ "${RunCMake_TEST_INSTALL_DIR}/foo-Debug.spdx.json" FOO_CONTENT)
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/SbomNamespaceFallback-install-check.cmake)

View File

@@ -1,2 +1,2 @@
file(READ "${RunCMake_TEST_INSTALL_DIR}/shared_targets.spdx.json" content)
file(READ "${RunCMake_TEST_INSTALL_DIR}/shared_targets-Debug.spdx.json" content)
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/SharedTarget-install-check.cmake)

View File

@@ -1,2 +1,2 @@
file(READ "${RunCMake_TEST_INSTALL_DIR}/mySbom.spdx.json" content)
file(READ "${RunCMake_TEST_INSTALL_DIR}/mySbom-Debug.spdx.json" content)
include(${CMAKE_CURRENT_LIST_DIR}/../Sbom/TargetInMultipleSets-install-check.cmake)

View File

@@ -0,0 +1,15 @@
include(${CMAKE_CURRENT_LIST_DIR}/Assertions.cmake)
function(check_config VAR_NAME1)
if(NOT "${${VAR_NAME1}}" STREQUAL "")
set(RunCMake_TEST_FAILED "${ERROR_MSG}" PARENT_SCOPE)
endif()
endfunction()
get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(_isMultiConfig)
check_config(DebugSbom)
check_config(ReleaseSbom)
else()
check_config(DebugSbom)
endif()

View File

@@ -0,0 +1,12 @@
get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(_isMultiConfig)
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "" FORCE)
else()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "" FORCE)
endif()
endif()
project(Config C)
add_library(foo ${CMAKE_CURRENT_LIST_DIR}/test.c)
install(TARGETS foo EXPORT foo DESTINATION .)

View File

@@ -0,0 +1,7 @@
include(${CMAKE_CURRENT_LIST_DIR}/Assertions.cmake)
set(out_dir "${RunCMake_BINARY_DIR}/EmptyConfig-build")
file(READ "${out_dir}/foo.cps" content)
expect_object("${content}" "components" "foo" "configurations" "noconfig")

View File

@@ -0,0 +1,9 @@
project(EmptyConfig CXX)
set(CMAKE_BUILD_TYPE "" CACHE STRING "" FORCE)
set(CMAKE_CONFIGURATION_TYPES "" CACHE STRING "" FORCE)
add_library(foo foo.cxx)
install(TARGETS foo EXPORT foo)
install(SBOM foo EXPORT foo)

View File

@@ -0,0 +1,14 @@
project(ForbiddenGenex C)
add_library(foo ${CMAKE_CURRENT_LIST_DIR}/test.c)
find_package(
bar 1.3.4 REQUIRED
NO_DEFAULT_PATH
PATHS ${CMAKE_CURRENT_LIST_DIR}
)
target_link_libraries(foo INTERFACE
$<TARGET_PROPERTY:foo>
)
install(TARGETS foo EXPORT foo DESTINATION .)

View File

@@ -0,0 +1,111 @@
include(${CMAKE_CURRENT_LIST_DIR}/Assertions.cmake)
set(CREATION_INFO_EXPECTED [=[
{
"@id": "_:Build#CreationInfo",
"comment": "This SBOM was generated from the CMakeLists.txt File",
"createdBy":
[
"https://gitlab.kitware.com/cmake/cmake"
],
"specVersion": "3.0.1",
"type": "CreationInfo"
}
]=])
set(SPDX_DOCUMENT_EXPECTED [=[
{
"spdxId" : "urn:interface_targets#SPDXDocument",
"name": "interface_targets",
"profileConformance" :
[
"core",
"software"
],
"creationInfo" : "_:Build#CreationInfo",
"type" : "SpdxDocument"
}
]=])
set(APPLICATION_EXPECTED [=[
{
"spdxId" : "urn:interface#Package",
"name" : "interface",
"software_primaryPurpose" : "library",
"type" : "software_Package"
}
]=])
set(DEPENDENCY_EXPECTED [=[
{
"spdxId" : "urn:bar:bar#Package",
"name" : "bar:bar",
"originatedBy" :
[
{
"name" : "bar",
"type" : "Organization"
}
],
"software_packageVersion" : "1.3.5",
"type" : "software_Package"
}
]=])
set(BAR_LINKED_LIBRARIES_EXPECTED [=[
{
"creationInfo" : "_:Build#CreationInfo",
"description" : "Linked Libraries",
"from" : "urn:interface#Package",
"relationshipType" : "dependsOn",
"spdxId" : "urn:Static#Relationship",
"to" :
[
"urn:bar:bar#Package"
],
"type" : "Relationship"
}
]=])
set(BAZ_LINKED_LIBRARIES_EXPECTED [=[
{
"creationInfo" : "_:Build#CreationInfo",
"description" : "Required Build-Time Libraries",
"from" : "urn:foo#Package",
"relationshipType" : "dependsOn",
"spdxId" : "urn:Shared#Relationship",
"to" :
[
"urn:baz#Package"
],
"type" : "Relationship"
}
]=])
function(check_config VAR_NAME LIBS)
set(content "${${VAR_NAME}}")
if("${content}" STREQUAL "")
set(RunCMake_TEST_FAILED "Error: Variable '${VAR_NAME}' is empty or not defined." PARENT_SCOPE)
return()
endif()
expect_value("${VAR_NAME}" "https://spdx.org/rdf/3.0.1/spdx-context.jsonld" "@context")
string(JSON CREATION_INFO GET "${content}" "@graph" "0")
expect_object("${CREATION_INFO}" CREATION_INFO_EXPECTED)
string(JSON SPDX_DOCUMENT GET "${content}" "@graph" "1")
expect_object("${SPDX_DOCUMENT}" SPDX_DOCUMENT_EXPECTED)
expect_object("${SPDX_DOCUMENT}" APPLICATION_EXPECTED "rootElement")
expect_object("${SPDX_DOCUMENT}" DEPENDENCY_EXPECTED "element")
string(JSON LINKED_LIBRARIES GET "${content}" "@graph" "2")
expect_object("${LINKED_LIBRARIES}" ${LIBS})
endfunction()
get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(_isMultiConfig)
check_config(BarConfig BAR_LINKED_LIBRARIES_EXPECTED)
check_config(BazConfig BAZ_LINKED_LIBRARIES_EXPECTED)
else()
check_config(BarConfig BAR_LINKED_LIBRARIES_EXPECTED)
endif()

View File

@@ -0,0 +1,28 @@
get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(_isMultiConfig)
set(CMAKE_CONFIGURATION_TYPES "BarConfig;BazConfig" CACHE STRING "" FORCE)
else()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "BarConfig" CACHE STRING "" FORCE)
endif()
endif()
project(Genex C)
add_library(foo INTERFACE)
find_package(
bar 1.3.4 REQUIRED
NO_DEFAULT_PATH
PATHS ${CMAKE_CURRENT_LIST_DIR}
)
find_package(
baz 1.3.4 REQUIRED
NO_DEFAULT_PATH
PATHS ${CMAKE_CURRENT_LIST_DIR}
)
target_link_libraries(foo INTERFACE $<$<CONFIG:BarConfig>:bar::bar>)
target_link_libraries(foo INTERFACE $<$<CONFIG:BazConfig>:baz>)
install(TARGETS foo EXPORT foo)