cmake/Source/cmIDEOptions.h

114 lines
3.3 KiB
C
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
2021-09-14 00:13:48 +02:00
#pragma once
2009-10-04 10:30:41 +03:00
2018-01-26 17:06:56 +01:00
#include "cmConfigure.h" // IWYU pragma: keep
2016-10-30 18:24:19 +01:00
2017-04-14 19:02:05 +02:00
#include <map>
#include <string>
#include <vector>
2016-07-09 11:21:54 +02:00
2017-04-14 19:02:05 +02:00
struct cmIDEFlagTable;
2009-10-04 10:30:41 +03:00
/** \class cmIDEOptions
* \brief Superclass for IDE option processing
*/
class cmIDEOptions
{
public:
cmIDEOptions();
virtual ~cmIDEOptions();
2018-04-23 21:13:27 +02:00
// Store definitions, includes and flags.
2009-10-04 10:30:41 +03:00
void AddDefine(const std::string& define);
2018-08-09 18:06:22 +02:00
void AddDefines(std::string const& defines);
2016-07-09 11:21:54 +02:00
void AddDefines(const std::vector<std::string>& defines);
2017-04-14 19:02:05 +02:00
std::vector<std::string> const& GetDefines() const;
2018-04-23 21:13:27 +02:00
void AddInclude(const std::string& includes);
2018-08-09 18:06:22 +02:00
void AddIncludes(std::string const& includes);
2018-04-23 21:13:27 +02:00
void AddIncludes(const std::vector<std::string>& includes);
std::vector<std::string> const& GetIncludes() const;
void AddFlag(std::string const& flag, std::string const& value);
void AddFlag(std::string const& flag, std::vector<std::string> const& value);
2015-04-27 22:25:09 +02:00
void AppendFlag(std::string const& flag, std::string const& value);
void AppendFlag(std::string const& flag,
std::vector<std::string> const& value);
2017-07-20 19:35:53 +02:00
void AppendFlagString(std::string const& flag, std::string const& value);
2018-04-23 21:13:27 +02:00
void RemoveFlag(std::string const& flag);
2015-04-27 22:25:09 +02:00
bool HasFlag(std::string const& flag) const;
2018-04-23 21:13:27 +02:00
const char* GetFlag(std::string const& flag) const;
2009-10-04 10:30:41 +03:00
protected:
// create a map of xml tags to the values they should have in the output
// for example, "BufferSecurityCheck" = "TRUE"
// first fill this table with the values for the configuration
// Debug, Release, etc,
// Then parse the command line flags specified in CMAKE_CXX_FLAGS
// and CMAKE_C_FLAGS
// and overwrite or add new values to this map
2016-07-09 11:21:54 +02:00
class FlagValue : public std::vector<std::string>
2015-04-27 22:25:09 +02:00
{
2020-02-01 23:06:01 +01:00
using derived = std::vector<std::string>;
2016-07-09 11:21:54 +02:00
2015-04-27 22:25:09 +02:00
public:
FlagValue& operator=(std::string const& r)
2016-07-09 11:21:54 +02:00
{
2015-04-27 22:25:09 +02:00
this->resize(1);
this->operator[](0) = r;
return *this;
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
FlagValue& operator=(std::vector<std::string> const& r)
2016-07-09 11:21:54 +02:00
{
2015-04-27 22:25:09 +02:00
this->derived::operator=(r);
return *this;
2016-07-09 11:21:54 +02:00
}
2019-11-11 23:01:05 +01:00
FlagValue& append_with_comma(std::string const& r)
{
return append_with_separator(r, ',');
}
2017-07-20 19:35:53 +02:00
FlagValue& append_with_space(std::string const& r)
2019-11-11 23:01:05 +01:00
{
return append_with_separator(r, ' ');
}
private:
FlagValue& append_with_separator(std::string const& r, char separator)
2017-07-20 19:35:53 +02:00
{
this->resize(1);
std::string& l = this->operator[](0);
if (!l.empty()) {
2019-11-11 23:01:05 +01:00
l += separator;
2017-07-20 19:35:53 +02:00
}
l += r;
return *this;
}
2015-04-27 22:25:09 +02:00
};
2016-07-09 11:21:54 +02:00
std::map<std::string, FlagValue> FlagMap;
2009-10-04 10:30:41 +03:00
// Preprocessor definitions.
std::vector<std::string> Defines;
2018-04-23 21:13:27 +02:00
// Include directories.
std::vector<std::string> Includes;
2009-10-04 10:30:41 +03:00
bool DoingDefine;
bool AllowDefine;
2018-04-23 21:13:27 +02:00
bool DoingInclude;
bool AllowInclude;
2009-10-04 10:30:41 +03:00
bool AllowSlash;
2015-04-27 22:25:09 +02:00
cmIDEFlagTable const* DoingFollowing;
2016-07-09 11:21:54 +02:00
enum
{
FlagTableCount = 16
};
2009-10-04 10:30:41 +03:00
cmIDEFlagTable const* FlagTable[FlagTableCount];
2018-08-09 18:06:22 +02:00
void HandleFlag(std::string const& flag);
bool CheckFlagTable(cmIDEFlagTable const* table, std::string const& flag,
2009-10-04 10:30:41 +03:00
bool& flag_handled);
2018-08-09 18:06:22 +02:00
void FlagMapUpdate(cmIDEFlagTable const* entry,
std::string const& new_value);
virtual void StoreUnknownFlag(std::string const& flag) = 0;
2009-10-04 10:30:41 +03:00
};