2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2009-07-22 22:22:45 +04:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2009-07-22 22:22:45 +04:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2009-07-22 22:22:45 +04:00
|
|
|
#ifndef cmDefinitions_h
|
|
|
|
#define cmDefinitions_h
|
|
|
|
|
|
|
|
#include "cmStandardIncludes.h"
|
2015-05-30 18:08:34 +03:00
|
|
|
|
|
|
|
#include "cmLinkedTree.h"
|
|
|
|
|
2014-03-12 09:48:06 +04:00
|
|
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
2015-05-16 07:57:53 +03:00
|
|
|
#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
|
|
|
|
#include <unordered_map>
|
|
|
|
#else
|
2014-03-12 09:48:06 +04:00
|
|
|
#include "cmsys/hash_map.hxx"
|
|
|
|
#endif
|
2015-05-16 07:57:53 +03:00
|
|
|
#endif
|
2009-07-22 22:22:45 +04:00
|
|
|
|
2015-04-26 17:00:18 +03:00
|
|
|
#include <list>
|
|
|
|
|
2009-07-22 22:22:45 +04:00
|
|
|
/** \class cmDefinitions
|
|
|
|
* \brief Store a scope of variable definitions for CMake language.
|
|
|
|
*
|
|
|
|
* This stores the state of variable definitions (set or unset) for
|
|
|
|
* one scope. Sets are always local. Gets search parent scopes
|
|
|
|
* transitively and save results locally.
|
|
|
|
*/
|
|
|
|
class cmDefinitions
|
|
|
|
{
|
2015-05-30 18:08:34 +03:00
|
|
|
typedef cmLinkedTree<cmDefinitions>::iterator StackIter;
|
2016-05-16 17:34:04 +03:00
|
|
|
|
2009-07-22 22:22:45 +04:00
|
|
|
public:
|
2016-05-16 17:34:04 +03:00
|
|
|
static const char* Get(const std::string& key, StackIter begin,
|
|
|
|
StackIter end);
|
2009-07-22 22:22:45 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
static void Raise(const std::string& key, StackIter begin, StackIter end);
|
2015-05-17 14:21:02 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
static bool HasKey(const std::string& key, StackIter begin, StackIter end);
|
2015-05-17 14:37:41 +03:00
|
|
|
|
2009-07-22 22:22:45 +04:00
|
|
|
/** Set (or unset if null) a value associated with a key. */
|
2015-04-25 17:29:54 +03:00
|
|
|
void Set(const std::string& key, const char* value);
|
2009-07-22 22:22:45 +04:00
|
|
|
|
2015-05-17 17:19:55 +03:00
|
|
|
std::vector<std::string> UnusedKeys() const;
|
2010-08-24 22:40:51 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
static std::vector<std::string> ClosureKeys(StackIter begin, StackIter end);
|
2009-07-22 22:22:45 +04:00
|
|
|
|
2015-05-30 18:08:34 +03:00
|
|
|
static cmDefinitions MakeClosure(StackIter begin, StackIter end);
|
2015-04-26 16:44:26 +03:00
|
|
|
|
2009-07-22 22:22:45 +04:00
|
|
|
private:
|
|
|
|
// String with existence boolean.
|
2016-05-16 17:34:04 +03:00
|
|
|
struct Def : public std::string
|
2009-07-22 22:22:45 +04:00
|
|
|
{
|
2014-02-10 09:21:34 +04:00
|
|
|
private:
|
|
|
|
typedef std::string std_string;
|
2016-05-16 17:34:04 +03:00
|
|
|
|
2014-02-10 09:21:34 +04:00
|
|
|
public:
|
2016-05-16 17:34:04 +03:00
|
|
|
Def()
|
|
|
|
: std_string()
|
|
|
|
, Exists(false)
|
|
|
|
, Used(false)
|
|
|
|
{
|
|
|
|
}
|
2015-05-17 17:19:55 +03:00
|
|
|
Def(const char* v)
|
2016-05-16 17:34:04 +03:00
|
|
|
: std_string(v ? v : "")
|
|
|
|
, Exists(v ? true : false)
|
|
|
|
, Used(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
Def(const std_string& v)
|
|
|
|
: std_string(v)
|
|
|
|
, Exists(true)
|
|
|
|
, Used(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
Def(Def const& d)
|
|
|
|
: std_string(d)
|
|
|
|
, Exists(d.Exists)
|
|
|
|
, Used(d.Used)
|
|
|
|
{
|
|
|
|
}
|
2009-07-22 22:22:45 +04:00
|
|
|
bool Exists;
|
2015-05-17 17:19:55 +03:00
|
|
|
bool Used;
|
2009-07-22 22:22:45 +04:00
|
|
|
};
|
|
|
|
static Def NoDef;
|
|
|
|
|
2014-03-12 09:48:06 +04:00
|
|
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
2015-05-16 07:57:53 +03:00
|
|
|
#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
|
|
|
|
typedef std::unordered_map<std::string, Def> MapType;
|
|
|
|
#else
|
2014-03-12 09:48:06 +04:00
|
|
|
typedef cmsys::hash_map<std::string, Def> MapType;
|
2015-05-16 07:57:53 +03:00
|
|
|
#endif
|
2014-03-12 09:48:06 +04:00
|
|
|
#else
|
2014-02-10 09:21:34 +04:00
|
|
|
typedef std::map<std::string, Def> MapType;
|
2014-03-12 09:48:06 +04:00
|
|
|
#endif
|
2009-07-22 22:22:45 +04:00
|
|
|
MapType Map;
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
static Def const& GetInternal(const std::string& key, StackIter begin,
|
|
|
|
StackIter end, bool raise);
|
2009-07-22 22:22:45 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|