cmCxxModuleMapper: add source to handle module mapper contents

This will allow all generators to share an implementation for actually
writing out the module map formats.
This commit is contained in:
Ben Boeckel 2022-06-02 17:18:37 -04:00
parent a046a45aad
commit 02d0f0e752
4 changed files with 80 additions and 0 deletions

View File

@ -197,6 +197,8 @@ set(SRCS
cmCustomCommandLines.cxx
cmCustomCommandLines.h
cmCustomCommandTypes.h
cmCxxModuleMapper.cxx
cmCxxModuleMapper.h
cmDefinitions.cxx
cmDefinitions.h
cmDependencyProvider.h

View File

@ -0,0 +1,30 @@
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCxxModuleMapper.h"
#include <cassert>
#include "cmScanDepFormat.h"
cm::optional<std::string> CxxModuleLocations::BmiGeneratorPathForModule(
std::string const& logical_name) const
{
if (auto l = this->BmiLocationForModule(logical_name)) {
return this->PathForGenerator(*l);
}
return {};
}
cm::static_string_view CxxModuleMapExtension(
cm::optional<CxxModuleMapFormat> format)
{
return ".bmi"_s;
}
std::string CxxModuleMapContent(CxxModuleMapFormat format,
CxxModuleLocations const& loc,
cmScanDepInfo const& obj)
{
assert(false);
return {};
}

View File

@ -0,0 +1,47 @@
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#pragma once
#include "cmConfigure.h" // IWYU pragma: keep
#include <functional>
#include <string>
#include <cm/optional>
#include <cmext/string_view>
struct cmScanDepInfo;
enum class CxxModuleMapFormat
{
};
struct CxxModuleLocations
{
// The path from which all relative paths should be computed. If
// this is relative, it is relative to the compiler's working
// directory.
std::string RootDirectory;
// A function to convert a full path to a path for the generator.
std::function<std::string(std::string const&)> PathForGenerator;
// Lookup the BMI location of a logical module name.
std::function<cm::optional<std::string>(std::string const&)>
BmiLocationForModule;
// Returns the generator path (if known) for the BMI given a
// logical module name.
cm::optional<std::string> BmiGeneratorPathForModule(
std::string const& logical_name) const;
};
// Return the extension to use for a given modulemap format.
cm::static_string_view CxxModuleMapExtension(
cm::optional<CxxModuleMapFormat> format);
// Return the contents of the module map in the given format for the
// object file.
std::string CxxModuleMapContent(CxxModuleMapFormat format,
CxxModuleLocations const& loc,
cmScanDepInfo const& obj);

View File

@ -328,6 +328,7 @@ CMAKE_CXX_SOURCES="\
cmCustomCommand \
cmCustomCommandGenerator \
cmCustomCommandLines \
cmCxxModuleMapper \
cmDefinePropertyCommand \
cmDefinitions \
cmDocumentationFormatter \