2009-09-28 15:43:28 +00:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2009-07-22 18:22:45 +00:00
|
|
|
|
2009-09-28 15:43:28 +00:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2009-07-22 18:22:45 +00:00
|
|
|
|
2009-09-28 15:43:28 +00: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 18:22:45 +00:00
|
|
|
#ifndef cmDefinitions_h
|
|
|
|
#define cmDefinitions_h
|
|
|
|
|
|
|
|
#include "cmStandardIncludes.h"
|
2014-03-12 05:48:06 +00:00
|
|
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
2015-05-16 04:57:53 +00:00
|
|
|
#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
|
|
|
|
#include <unordered_map>
|
|
|
|
#else
|
2014-03-12 05:48:06 +00:00
|
|
|
#include "cmsys/hash_map.hxx"
|
|
|
|
#endif
|
2015-05-16 04:57:53 +00:00
|
|
|
#endif
|
2009-07-22 18:22:45 +00:00
|
|
|
|
2015-04-26 14:00:18 +00:00
|
|
|
#include <list>
|
|
|
|
|
2009-07-22 18:22:45 +00: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-16 03:33:25 +00:00
|
|
|
typedef std::list<cmDefinitions>::reverse_iterator StackIter;
|
|
|
|
typedef std::list<cmDefinitions>::const_reverse_iterator StackConstIter;
|
2009-07-22 18:22:45 +00:00
|
|
|
public:
|
2014-10-24 16:58:12 +00:00
|
|
|
/** Get the value associated with a key; null if none.
|
|
|
|
Store the result locally if it came from a parent. */
|
2015-04-30 23:50:45 +00:00
|
|
|
static const char* Get(const std::string& key,
|
2015-05-16 03:33:25 +00:00
|
|
|
StackIter begin, StackIter end);
|
2009-07-22 18:22:45 +00:00
|
|
|
|
|
|
|
/** Set (or unset if null) a value associated with a key. */
|
2015-04-25 14:29:54 +00:00
|
|
|
void Set(const std::string& key, const char* value);
|
2009-07-22 18:22:45 +00:00
|
|
|
|
2015-04-25 14:33:26 +00:00
|
|
|
void Erase(const std::string& key);
|
|
|
|
|
2010-08-24 18:40:51 +00:00
|
|
|
/** Get the set of all local keys. */
|
2015-04-26 14:34:13 +00:00
|
|
|
std::vector<std::string> LocalKeys() const;
|
2010-08-24 18:40:51 +00:00
|
|
|
|
2015-05-16 03:33:30 +00:00
|
|
|
static std::vector<std::string> ClosureKeys(StackConstIter begin,
|
|
|
|
StackConstIter end);
|
2009-07-22 18:22:45 +00:00
|
|
|
|
2015-05-16 03:33:25 +00:00
|
|
|
static cmDefinitions MakeClosure(StackConstIter begin, StackConstIter end);
|
2015-04-26 13:44:26 +00:00
|
|
|
|
2009-07-22 18:22:45 +00:00
|
|
|
private:
|
|
|
|
// String with existence boolean.
|
2014-02-10 05:21:34 +00:00
|
|
|
struct Def: public std::string
|
2009-07-22 18:22:45 +00:00
|
|
|
{
|
2014-02-10 05:21:34 +00:00
|
|
|
private:
|
|
|
|
typedef std::string std_string;
|
|
|
|
public:
|
|
|
|
Def(): std_string(), Exists(false) {}
|
|
|
|
Def(const char* v): std_string(v?v:""), Exists(v?true:false) {}
|
2014-02-22 00:06:54 +00:00
|
|
|
Def(const std_string& v): std_string(v), Exists(true) {}
|
2014-02-10 05:21:34 +00:00
|
|
|
Def(Def const& d): std_string(d), Exists(d.Exists) {}
|
2009-07-22 18:22:45 +00:00
|
|
|
bool Exists;
|
|
|
|
};
|
|
|
|
static Def NoDef;
|
|
|
|
|
2014-03-12 05:48:06 +00:00
|
|
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
2015-05-16 04:57:53 +00:00
|
|
|
#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
|
|
|
|
typedef std::unordered_map<std::string, Def> MapType;
|
|
|
|
#else
|
2014-03-12 05:48:06 +00:00
|
|
|
typedef cmsys::hash_map<std::string, Def> MapType;
|
2015-05-16 04:57:53 +00:00
|
|
|
#endif
|
2014-03-12 05:48:06 +00:00
|
|
|
#else
|
2014-02-10 05:21:34 +00:00
|
|
|
typedef std::map<std::string, Def> MapType;
|
2014-03-12 05:48:06 +00:00
|
|
|
#endif
|
2009-07-22 18:22:45 +00:00
|
|
|
MapType Map;
|
|
|
|
|
2015-04-30 23:13:38 +00:00
|
|
|
static Def const& GetInternal(const std::string& key,
|
2015-05-16 03:33:25 +00:00
|
|
|
StackIter begin, StackIter end);
|
2009-07-22 18:22:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|