CMake/Source/cmDefinitions.cxx

119 lines
3.3 KiB
C++
Raw Normal View History

Simplify CMake per-source license notices Per-source copyright/license notice headers that spell out copyright holder names and years are hard to maintain and often out-of-date or plain wrong. Precise contributor information is already maintained automatically by the version control tool. Ultimately it is the receiver of a file who is responsible for determining its licensing status, and per-source notices are merely a convenience. Therefore it is simpler and more accurate for each source to have a generic notice of the license name and references to more detailed information on copyright holders and full license terms. Our `Copyright.txt` file now contains a list of Contributors whose names appeared source-level copyright notices. It also references version control history for more precise information. Therefore we no longer need to spell out the list of Contributors in each source file notice. Replace CMake per-source copyright/license notice headers with a short description of the license and links to `Copyright.txt` and online information available from "https://cmake.org/licensing". The online URL also handles cases of modules being copied out of our source into other projects, so we can drop our notices about replacing links with full license text. Run the `Utilities/Scripts/filter-notices.bash` script to perform the majority of the replacements mechanically. Manually fix up shebang lines and trailing newlines in a few files. Manually update the notices in a few files that the script does not handle.
2016-09-27 22:01:08 +03:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmDefinitions.h"
#include <assert.h>
#include <set>
#include <utility>
cmDefinitions::Def cmDefinitions::NoDef;
cmDefinitions::Def const& cmDefinitions::GetInternal(const std::string& key,
StackIter begin,
StackIter end, bool raise)
{
assert(begin != end);
MapType::iterator i = begin->Map.find(key);
if (i != begin->Map.end()) {
i->second.Used = true;
return i->second;
}
StackIter it = begin;
++it;
if (it == end) {
return cmDefinitions::NoDef;
}
Def const& def = cmDefinitions::GetInternal(key, it, end, raise);
if (!raise) {
return def;
}
return begin->Map.insert(MapType::value_type(key, def)).first->second;
}
const char* cmDefinitions::Get(const std::string& key, StackIter begin,
StackIter end)
{
Def const& def = cmDefinitions::GetInternal(key, begin, end, false);
2016-06-27 23:44:16 +03:00
return def.Exists ? def.c_str() : CM_NULLPTR;
}
void cmDefinitions::Raise(const std::string& key, StackIter begin,
StackIter end)
{
cmDefinitions::GetInternal(key, begin, end, true);
}
bool cmDefinitions::HasKey(const std::string& key, StackIter begin,
StackIter end)
{
for (StackIter it = begin; it != end; ++it) {
MapType::const_iterator i = it->Map.find(key);
if (i != it->Map.end()) {
return true;
}
}
return false;
}
void cmDefinitions::Set(const std::string& key, const char* value)
{
Def def(value);
this->Map[key] = def;
}
std::vector<std::string> cmDefinitions::UnusedKeys() const
{
std::vector<std::string> keys;
keys.reserve(this->Map.size());
// Consider local definitions.
for (MapType::const_iterator mi = this->Map.begin(); mi != this->Map.end();
++mi) {
if (!mi->second.Used) {
keys.push_back(mi->first);
}
}
return keys;
}
cmDefinitions cmDefinitions::MakeClosure(StackIter begin, StackIter end)
{
cmDefinitions closure;
std::set<std::string> undefined;
for (StackIter it = begin; it != end; ++it) {
// Consider local definitions.
for (MapType::const_iterator mi = it->Map.begin(); mi != it->Map.end();
++mi) {
// Use this key if it is not already set or unset.
if (closure.Map.find(mi->first) == closure.Map.end() &&
undefined.find(mi->first) == undefined.end()) {
if (mi->second.Exists) {
closure.Map.insert(*mi);
} else {
undefined.insert(mi->first);
}
}
}
}
return closure;
}
std::vector<std::string> cmDefinitions::ClosureKeys(StackIter begin,
StackIter end)
{
std::set<std::string> bound;
std::vector<std::string> defined;
for (StackIter it = begin; it != end; ++it) {
defined.reserve(defined.size() + it->Map.size());
for (MapType::const_iterator mi = it->Map.begin(); mi != it->Map.end();
++mi) {
// Use this key if it is not already set or unset.
if (bound.insert(mi->first).second && mi->second.Exists) {
defined.push_back(mi->first);
}
}
}
return defined;
}