~ubuntu-branches/ubuntu/jaunty/cmake/jaunty-security

« back to all changes in this revision

Viewing changes to Source/cmCacheManager.cxx

  • Committer: Bazaar Package Importer
  • Author(s): A. Maitland Bottoms
  • Date: 2006-06-18 16:34:11 UTC
  • mfrom: (1.4.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060618163411-pi234s3v6jwlcmof
Tags: 2.4.2-1
* New upstream release (Closes: #338324)
* Put cmake .vim files into /usr/share/vim/addons/plugin/
  where they can be used. (Closes: #366663)
* Install cmake-mode.el so it can be used. (Closes: #366664)
* Ensure cmake FindKDE locates KDE libraries on Debian
  based distributions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
  Program:   CMake - Cross-Platform Makefile Generator
4
4
  Module:    $RCSfile: cmCacheManager.cxx,v $
5
5
  Language:  C++
6
 
  Date:      $Date: 2005/08/11 18:02:19 $
7
 
  Version:   $Revision: 1.85.2.1 $
 
6
  Date:      $Date: 2006/05/11 02:15:08 $
 
7
  Version:   $Revision: 1.92.2.1 $
8
8
 
9
9
  Copyright (c) 2002 Kitware, Inc., Insight Consortium.  All rights reserved.
10
10
  See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
11
11
 
12
 
     This software is distributed WITHOUT ANY WARRANTY; without even 
13
 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
 
12
     This software is distributed WITHOUT ANY WARRANTY; without even
 
13
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14
14
     PURPOSE.  See the above copyright notices for more information.
15
15
 
16
16
=========================================================================*/
20
20
#include "cmCacheManager.h"
21
21
#include "cmMakefile.h"
22
22
 
 
23
#include <cmsys/Directory.hxx>
 
24
#include <cmsys/Glob.hxx>
 
25
 
23
26
#include <cmsys/RegularExpression.hxx>
24
27
 
25
28
#if defined(_WIN32) || defined(__CYGWIN__)
26
29
# include <windows.h>
27
30
#endif // _WIN32
28
31
 
29
 
const char* cmCacheManagerTypes[] = 
 
32
const char* cmCacheManagerTypes[] =
30
33
{ "BOOL",
31
34
  "PATH",
32
35
  "FILEPATH",
78
81
  return this->LoadCache(path, internal, emptySet, emptySet);
79
82
}
80
83
 
81
 
bool cmCacheManager::ParseEntry(const char* entry, 
 
84
bool cmCacheManager::ParseEntry(const char* entry,
82
85
                                std::string& var,
83
86
                                std::string& value)
84
87
{
85
88
  // input line is:         key:type=value
86
 
  static cmsys::RegularExpression reg("^([^:]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
 
89
  static cmsys::RegularExpression reg(
 
90
    "^([^:]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
87
91
  // input line is:         "key":type=value
88
 
  static cmsys::RegularExpression regQuoted("^\"([^\"]*)\"=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
 
92
  static cmsys::RegularExpression regQuoted(
 
93
    "^\"([^\"]*)\"=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
89
94
  bool flag = false;
90
95
  if(regQuoted.find(entry))
91
96
    {
102
107
 
103
108
  // if value is enclosed in single quotes ('foo') then remove them
104
109
  // it is used to enclose trailing space or tab
105
 
  if (flag && 
 
110
  if (flag &&
106
111
      value.size() >= 2 &&
107
 
      value[0] == '\'' && 
108
 
      value[value.size() - 1] == '\'') 
 
112
      value[0] == '\'' &&
 
113
      value[value.size() - 1] == '\'')
109
114
    {
110
 
    value = value.substr(1, 
 
115
    value = value.substr(1,
111
116
                         value.size() - 2);
112
117
    }
113
118
 
114
119
  return flag;
115
120
}
116
121
 
117
 
bool cmCacheManager::ParseEntry(const char* entry, 
 
122
bool cmCacheManager::ParseEntry(const char* entry,
118
123
                                std::string& var,
119
124
                                std::string& value,
120
125
                                CacheEntryType& type)
121
126
{
122
127
  // input line is:         key:type=value
123
 
  static cmsys::RegularExpression reg("^([^:]*):([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
 
128
  static cmsys::RegularExpression reg(
 
129
    "^([^:]*):([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
124
130
  // input line is:         "key":type=value
125
 
  static cmsys::RegularExpression regQuoted("^\"([^\"]*)\":([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
 
131
  static cmsys::RegularExpression regQuoted(
 
132
    "^\"([^\"]*)\":([^=]*)=(.*[^\r\t ]|[\r\t ]*)[\r\t ]*$");
126
133
  bool flag = false;
127
134
  if(regQuoted.find(entry))
128
135
    {
141
148
 
142
149
  // if value is enclosed in single quotes ('foo') then remove them
143
150
  // it is used to enclose trailing space or tab
144
 
  if (flag && 
 
151
  if (flag &&
145
152
      value.size() >= 2 &&
146
 
      value[0] == '\'' && 
147
 
      value[value.size() - 1] == '\'') 
 
153
      value[0] == '\'' &&
 
154
      value[value.size() - 1] == '\'')
148
155
    {
149
 
    value = value.substr(1, 
 
156
    value = value.substr(1,
150
157
                         value.size() - 2);
151
158
    }
152
159
 
153
160
  return flag;
154
161
}
155
162
 
 
163
void cmCacheManager::CleanCMakeFiles(const char* path)
 
164
{
 
165
  std::string glob = path;
 
166
  glob += "/CMakeFiles/*.cmake";
 
167
  cmsys::Glob globIt;
 
168
  globIt.FindFiles(glob);
 
169
  std::vector<std::string> files = globIt.GetFiles();
 
170
  for(std::vector<std::string>::iterator i = files.begin();
 
171
      i != files.end(); ++i)
 
172
    {
 
173
    cmSystemTools::RemoveFile(i->c_str());
 
174
    }
 
175
}
 
176
 
156
177
bool cmCacheManager::LoadCache(const char* path,
157
178
                               bool internal,
158
179
                               std::set<cmStdString>& excludes,
163
184
  // clear the old cache, if we are reading in internal values
164
185
  if ( internal )
165
186
    {
166
 
    m_Cache.clear();
167
 
    }
 
187
    this->Cache.clear();
 
188
    }
 
189
  if(!cmSystemTools::FileExists(cacheFile.c_str()))
 
190
    {
 
191
    this->CleanCMakeFiles(path);
 
192
    return false;
 
193
    }
 
194
 
168
195
  std::ifstream fin(cacheFile.c_str());
169
196
  if(!fin)
170
197
    {
194
221
      }
195
222
    while(realbuffer[0] == '/' && realbuffer[1] == '/')
196
223
      {
197
 
      e.m_Properties["HELPSTRING"] += &realbuffer[2];
 
224
      e.Properties["HELPSTRING"] += &realbuffer[2];
198
225
      cmSystemTools::GetLineFromStream(fin, buffer);
199
226
      realbuffer = buffer.c_str();
200
227
      if(!fin)
202
229
        continue;
203
230
        }
204
231
      }
205
 
    if(cmCacheManager::ParseEntry(realbuffer, entryKey, e.m_Value, e.m_Type))
 
232
    if(cmCacheManager::ParseEntry(realbuffer, entryKey, e.Value, e.Type))
206
233
      {
207
234
      if ( excludes.find(entryKey) == excludes.end() )
208
235
        {
210
237
        // If the entry is not internal to the cache being loaded
211
238
        // or if it is in the list of internal entries to be
212
239
        // imported, load it.
213
 
        if ( internal || (e.m_Type != INTERNAL) || 
 
240
        if ( internal || (e.Type != INTERNAL) || 
214
241
             (includes.find(entryKey) != includes.end()) )
215
242
          {
216
243
          // If we are loading the cache from another project,
218
245
          // not visible in the gui
219
246
          if (!internal)
220
247
            {
221
 
            e.m_Type = INTERNAL;
222
 
            e.m_Properties["HELPSTRING"] = "DO NOT EDIT, ";
223
 
            e.m_Properties["HELPSTRING"] += entryKey;
224
 
            e.m_Properties["HELPSTRING"] += " loaded from external file.  "
 
248
            e.Type = INTERNAL;
 
249
            e.Properties["HELPSTRING"] = "DO NOT EDIT, ";
 
250
            e.Properties["HELPSTRING"] += entryKey;
 
251
            e.Properties["HELPSTRING"] += " loaded from external file.  "
225
252
              "To change this value edit this file: ";
226
 
            e.m_Properties["HELPSTRING"] += path;
227
 
            e.m_Properties["HELPSTRING"] += "/CMakeCache.txt"   ;
 
253
            e.Properties["HELPSTRING"] += path;
 
254
            e.Properties["HELPSTRING"] += "/CMakeCache.txt"   ;
228
255
            }
229
 
          if ( e.m_Type == cmCacheManager::INTERNAL &&
 
256
          if ( e.Type == cmCacheManager::INTERNAL &&
230
257
               (entryKey.size() > strlen("-ADVANCED")) &&
231
 
               strcmp(entryKey.c_str() + (entryKey.size() - strlen("-ADVANCED")),
232
 
                      "-ADVANCED") == 0 )
 
258
               strcmp(entryKey.c_str() + (entryKey.size() -
 
259
                   strlen("-ADVANCED")), "-ADVANCED") == 0 )
233
260
            {
234
 
            std::string value = e.m_Value;
235
 
            std::string akey = entryKey.substr(0, (entryKey.size() - strlen("-ADVANCED")));
236
 
            cmCacheManager::CacheIterator it = this->GetCacheIterator(akey.c_str());
 
261
            std::string value = e.Value;
 
262
            std::string akey = 
 
263
              entryKey.substr(0, (entryKey.size() - strlen("-ADVANCED")));
 
264
            cmCacheManager::CacheIterator it = 
 
265
              this->GetCacheIterator(akey.c_str());
237
266
            if ( it.IsAtEnd() )
238
267
              {
239
 
              e.m_Type = cmCacheManager::UNINITIALIZED;
240
 
              m_Cache[akey] = e;
 
268
              e.Type = cmCacheManager::UNINITIALIZED;
 
269
              this->Cache[akey] = e;
241
270
              }
242
271
            if (!it.Find(akey.c_str()))
243
272
              {
245
274
              }
246
275
            it.SetProperty("ADVANCED", value.c_str());
247
276
            }
248
 
          else if ( e.m_Type == cmCacheManager::INTERNAL &&
 
277
          else if ( e.Type == cmCacheManager::INTERNAL &&
249
278
                    (entryKey.size() > strlen("-MODIFIED")) &&
250
 
                    strcmp(entryKey.c_str() + (entryKey.size() - strlen("-MODIFIED")),
251
 
                           "-MODIFIED") == 0 )
 
279
                    strcmp(entryKey.c_str() + (entryKey.size() -
 
280
                        strlen("-MODIFIED")), "-MODIFIED") == 0 )
252
281
            {
253
 
            std::string value = e.m_Value;
254
 
            std::string akey = entryKey.substr(0, (entryKey.size() - strlen("-MODIFIED")));
255
 
            cmCacheManager::CacheIterator it = this->GetCacheIterator(akey.c_str());
 
282
            std::string value = e.Value;
 
283
            std::string akey = 
 
284
              entryKey.substr(0, (entryKey.size() - strlen("-MODIFIED")));
 
285
            cmCacheManager::CacheIterator it = 
 
286
              this->GetCacheIterator(akey.c_str());
256
287
            if ( it.IsAtEnd() )
257
288
              {
258
 
              e.m_Type = cmCacheManager::UNINITIALIZED;
259
 
              m_Cache[akey] = e;
 
289
              e.Type = cmCacheManager::UNINITIALIZED;
 
290
              this->Cache[akey] = e;
260
291
              }
261
292
            if (!it.Find(akey.c_str()))
262
293
              {
266
297
            }
267
298
          else
268
299
            {
269
 
            e.m_Initialized = true;
270
 
            m_Cache[entryKey] = e;
 
300
            e.Initialized = true;
 
301
            this->Cache[entryKey] = e;
271
302
            }
272
303
          }
273
304
        }
288
319
    this->AddCacheEntry("CMAKE_CACHE_MAJOR_VERSION", "0",
289
320
                        "Major version of cmake used to create the "
290
321
                        "current loaded cache", cmCacheManager::INTERNAL);
291
 
    
 
322
 
292
323
    }
293
324
  // check to make sure the cache directory has not
294
325
  // been moved
300
331
    currentcwd += "/CMakeCache.txt";
301
332
    oldcwd += "/CMakeCache.txt";
302
333
    if(!cmSystemTools::SameFile(oldcwd.c_str(), currentcwd.c_str()))
303
 
      { 
304
 
      std::string message = 
 
334
      {
 
335
      std::string message =
305
336
        std::string("The current CMakeCache.txt directory ") +
306
 
        currentcwd + std::string(" is different than the directory ") + 
 
337
        currentcwd + std::string(" is different than the directory ") +
307
338
        std::string(this->GetCacheValue("CMAKE_CACHEFILE_DIR")) +
308
339
        std::string(" where CMackeCache.txt was created. This may result "
309
340
                    "in binaries being created in the wrong place. If you "
310
341
                    "are not sure, reedit the CMakeCache.txt");
311
 
      cmSystemTools::Error(message.c_str());   
 
342
      cmSystemTools::Error(message.c_str());
312
343
      }
313
344
    }
314
345
  return true;
315
346
}
316
347
 
317
 
bool cmCacheManager::SaveCache(cmMakefile* mf) 
 
348
bool cmCacheManager::SaveCache(cmMakefile* mf)
318
349
{
319
350
  return this->SaveCache(mf->GetHomeOutputDirectory());
320
351
}
321
352
 
322
353
 
323
 
bool cmCacheManager::SaveCache(const char* path) 
 
354
bool cmCacheManager::SaveCache(const char* path)
324
355
{
325
356
  std::string cacheFile = path;
326
357
  cacheFile += "/CMakeCache.txt";
328
359
  tempFile += ".tmp";
329
360
  std::ofstream fout(tempFile.c_str());
330
361
  if(!fout)
331
 
    {  
332
 
    cmSystemTools::Error("Unable to open cache file for save. ", 
 
362
    {
 
363
    cmSystemTools::Error("Unable to open cache file for save. ",
333
364
                         cacheFile.c_str());
334
365
    cmSystemTools::ReportLastSystemError("");
335
366
    return false;
336
367
    }
337
368
  // before writing the cache, update the version numbers
338
 
  // to the 
 
369
  // to the
339
370
  char temp[1024];
340
371
  sprintf(temp, "%d", cmMakefile::GetMinorVersion());
341
372
  this->AddCacheEntry("CMAKE_CACHE_MINOR_VERSION", temp,
346
377
                      "Major version of cmake used to create the "
347
378
                      "current loaded cache", cmCacheManager::INTERNAL);
348
379
 
349
 
  this->AddCacheEntry("CMAKE_CACHE_RELEASE_VERSION", cmMakefile::GetReleaseVersion(),
 
380
  this->AddCacheEntry("CMAKE_CACHE_RELEASE_VERSION",
 
381
                      cmMakefile::GetReleaseVersion(),
350
382
                      "Major version of cmake used to create the "
351
383
                      "current loaded cache", cmCacheManager::INTERNAL);
352
384
 
364
396
                      " was created", cmCacheManager::INTERNAL);
365
397
 
366
398
  fout << "# This is the CMakeCache file.\n"
367
 
       << "# For build in directory: " << currentcwd << "\n"
368
 
       << "# You can edit this file to change values found and used by cmake.\n"
369
 
       << "# If you do not want to change any of the values, simply exit the editor.\n"
370
 
       << "# If you do want to change a value, simply edit, save, and exit the editor.\n"
 
399
       << "# For build in directory: " << currentcwd << "\n";
 
400
  cmCacheManager::CacheEntry* cmakeCacheEntry
 
401
    = this->GetCacheEntry("CMAKE_COMMAND");
 
402
  if ( cmakeCacheEntry )
 
403
    {
 
404
    fout << "# It was generated by CMake: " << 
 
405
      cmakeCacheEntry->Value << std::endl;
 
406
    }
 
407
 
 
408
  fout << "# You can edit this file to change values found and used by cmake."
 
409
       << std::endl
 
410
       << "# If you do not want to change any of the values, simply exit the "
 
411
       "editor." << std::endl
 
412
       << "# If you do want to change a value, simply edit, save, and exit "
 
413
       "the editor." << std::endl
371
414
       << "# The syntax for the file is as follows:\n"
372
415
       << "# KEY:TYPE=VALUE\n"
373
416
       << "# KEY is the name of a variable in the cache.\n"
374
 
       << "# TYPE is a hint to GUI's for the type of VALUE, DO NOT EDIT TYPE!.\n"
 
417
       << "# TYPE is a hint to GUI's for the type of VALUE, DO NOT EDIT "
 
418
       "TYPE!." << std::endl
375
419
       << "# VALUE is the current value for the KEY.\n\n";
376
420
 
377
421
  fout << "########################\n";
379
423
  fout << "########################\n";
380
424
  fout << "\n";
381
425
 
382
 
  for( std::map<cmStdString, CacheEntry>::const_iterator i = m_Cache.begin();
383
 
       i != m_Cache.end(); ++i)
 
426
  for( std::map<cmStdString, CacheEntry>::const_iterator i = 
 
427
         this->Cache.begin(); i != this->Cache.end(); ++i)
384
428
    {
385
429
    const CacheEntry& ce = (*i).second; 
386
 
    CacheEntryType t = ce.m_Type;
387
 
    if(t == cmCacheManager::UNINITIALIZED || !ce.m_Initialized)
 
430
    CacheEntryType t = ce.Type;
 
431
    if(t == cmCacheManager::UNINITIALIZED || !ce.Initialized)
388
432
      {
389
433
      /*
390
434
        // This should be added in, but is not for now.
391
 
      cmSystemTools::Error("Cache entry \"", (*i).first.c_str(), 
 
435
      cmSystemTools::Error("Cache entry \"", (*i).first.c_str(),
392
436
                           "\" is uninitialized");
393
437
      */
394
438
      }
396
440
      {
397
441
      // Format is key:type=value
398
442
      std::map<cmStdString,cmStdString>::const_iterator it = 
399
 
        ce.m_Properties.find("HELPSTRING");
400
 
      if ( it == ce.m_Properties.end() )
 
443
        ce.Properties.find("HELPSTRING");
 
444
      if ( it == ce.Properties.end() )
401
445
        {
402
446
        cmCacheManager::OutputHelpString(fout, "Missing description");
403
447
        }
406
450
        cmCacheManager::OutputHelpString(fout, it->second);
407
451
        }
408
452
      std::string key;
409
 
      // support : in key name by double quoting 
 
453
      // support : in key name by double quoting
410
454
      if((*i).first.find(':') != std::string::npos ||
411
455
        (*i).first.find("//") == 0)
412
456
        {
421
465
      fout << key.c_str() << ":"
422
466
           << cmCacheManagerTypes[t] << "=";
423
467
      // if value has trailing space or tab, enclose it in single quotes
424
 
      if (ce.m_Value.size() &&
425
 
          (ce.m_Value[ce.m_Value.size() - 1] == ' ' || 
426
 
           ce.m_Value[ce.m_Value.size() - 1] == '\t'))
 
468
      if (ce.Value.size() &&
 
469
          (ce.Value[ce.Value.size() - 1] == ' ' || 
 
470
           ce.Value[ce.Value.size() - 1] == '\t'))
427
471
        {
428
 
        fout << '\'' << ce.m_Value << '\'';
 
472
        fout << '\'' << ce.Value << '\'';
429
473
        }
430
474
      else
431
475
        {
432
 
        fout << ce.m_Value;
 
476
        fout << ce.Value;
433
477
        }
434
478
      fout << "\n\n";
435
479
      }
463
507
      helpstring += i.GetName();
464
508
      rkey += "-ADVANCED";
465
509
      cmCacheManager::OutputHelpString(fout, helpstring.c_str());
466
 
      // support : in key name by double quoting 
 
510
      // support : in key name by double quoting
467
511
      if(rkey.find(':') != std::string::npos ||
468
512
         rkey.find("//") == 0)
469
513
        {
491
535
      helpstring += i.GetName();
492
536
      rkey += "-MODIFIED";
493
537
      cmCacheManager::OutputHelpString(fout, helpstring.c_str());
494
 
      // support : in key name by double quoting 
 
538
      // support : in key name by double quoting
495
539
      if(rkey.find(':') != std::string::npos ||
496
540
         rkey.find("//") == 0)
497
541
        {
522
566
        helpstring = "";
523
567
        }
524
568
      cmCacheManager::OutputHelpString(fout, helpstring.c_str());
525
 
      // support : in key name by double quoting 
 
569
      // support : in key name by double quoting
526
570
      if(rkey.find(':') != std::string::npos ||
527
571
         rkey.find("//") == 0)
528
572
        {
539
583
      // if value has trailing space or tab, enclose it in single quotes
540
584
      std::string value = i.GetValue();
541
585
      if (value.size() &&
542
 
          (value[value.size() - 1] == ' ' || 
 
586
          (value[value.size() - 1] == ' ' ||
543
587
           value[value.size() - 1] == '\t'))
544
588
        {
545
589
        fout << '\'' << value << '\'';
548
592
        {
549
593
        fout << value;
550
594
        }
551
 
      fout << "\n";      
 
595
      fout << "\n";
552
596
      }
553
597
    }
554
598
  fout << "\n";
563
607
  std::ofstream checkCache(checkCacheFile.c_str());
564
608
  if(!checkCache)
565
609
    {
566
 
    cmSystemTools::Error("Unable to open check cache file for write. ", 
 
610
    cmSystemTools::Error("Unable to open check cache file for write. ",
567
611
                         checkCacheFile.c_str());
568
612
    return false;
569
613
    }
570
 
  checkCache << "# This file is generated by cmake for dependency checking of the CMakeCache.txt file\n";
 
614
  checkCache << "# This file is generated by cmake for dependency checking "
 
615
    "of the CMakeCache.txt file\n";
571
616
  return true;
572
617
}
573
618
 
574
 
bool cmCacheManager::DeleteCache(const char* path) 
 
619
bool cmCacheManager::DeleteCache(const char* path)
575
620
{
576
621
  std::string cacheFile = path;
 
622
  cmSystemTools::ConvertToUnixSlashes(cacheFile);
 
623
  std::string cmakeFiles = cacheFile;
577
624
  cacheFile += "/CMakeCache.txt";
578
625
  cmSystemTools::RemoveFile(cacheFile.c_str());
 
626
  // now remove the files in the CMakeFiles directory
 
627
  // this cleans up language cache files
 
628
  cmsys::Directory dir;
 
629
  cmakeFiles += "/CMakeFiles";
 
630
  dir.Load(cmakeFiles.c_str());
 
631
  for (unsigned long fileNum = 0;
 
632
    fileNum <  dir.GetNumberOfFiles();
 
633
    ++fileNum)
 
634
    {
 
635
    if(!cmSystemTools::
 
636
       FileIsDirectory(dir.GetFile(fileNum)))
 
637
      {
 
638
      std::string fullPath = cmakeFiles;
 
639
      fullPath += "/";
 
640
      fullPath += dir.GetFile(fileNum);
 
641
      cmSystemTools::RemoveFile(fullPath.c_str());
 
642
      }
 
643
    }
579
644
  return true;
580
645
}
581
646
 
582
 
void cmCacheManager::OutputHelpString(std::ofstream& fout, 
 
647
void cmCacheManager::OutputHelpString(std::ofstream& fout,
583
648
                                      const std::string& helpString)
584
649
{
585
650
  std::string::size_type end = helpString.size();
615
680
 
616
681
void cmCacheManager::RemoveCacheEntry(const char* key)
617
682
{
618
 
  CacheEntryMap::iterator i = m_Cache.find(key);
619
 
  if(i != m_Cache.end())
 
683
  CacheEntryMap::iterator i = this->Cache.find(key);
 
684
  if(i != this->Cache.end())
620
685
    {
621
 
    m_Cache.erase(i);
 
686
    this->Cache.erase(i);
622
687
    }
623
688
  else
624
689
    {
629
694
 
630
695
cmCacheManager::CacheEntry *cmCacheManager::GetCacheEntry(const char* key)
631
696
{
632
 
  CacheEntryMap::iterator i = m_Cache.find(key);
633
 
  if(i != m_Cache.end())
 
697
  CacheEntryMap::iterator i = this->Cache.find(key);
 
698
  if(i != this->Cache.end())
634
699
    {
635
700
    return &i->second;
636
701
    }
637
702
  return 0;
638
703
}
639
704
 
640
 
cmCacheManager::CacheIterator cmCacheManager::GetCacheIterator(const char *key)
 
705
cmCacheManager::CacheIterator cmCacheManager::GetCacheIterator(
 
706
  const char *key)
641
707
{
642
708
  return CacheIterator(*this, key);
643
709
}
644
710
 
645
711
const char* cmCacheManager::GetCacheValue(const char* key) const
646
712
{
647
 
  CacheEntryMap::const_iterator i = m_Cache.find(key);
648
 
  if(i != m_Cache.end() &&
649
 
    i->second.m_Initialized)
 
713
  CacheEntryMap::const_iterator i = this->Cache.find(key);
 
714
  if(i != this->Cache.end() &&
 
715
    i->second.Initialized)
650
716
    {
651
 
    return i->second.m_Value.c_str();
 
717
    return i->second.Value.c_str();
652
718
    }
653
719
  return 0;
654
720
}
658
724
{
659
725
  out << "=================================================" << std::endl;
660
726
  out << "CMakeCache Contents:" << std::endl;
661
 
  for(std::map<cmStdString, CacheEntry>::const_iterator i = m_Cache.begin();
662
 
      i != m_Cache.end(); ++i)
 
727
  for(std::map<cmStdString, CacheEntry>::const_iterator i = 
 
728
        this->Cache.begin(); i != this->Cache.end(); ++i)
663
729
    {
664
 
    if((*i).second.m_Type != INTERNAL)
 
730
    if((*i).second.Type != INTERNAL)
665
731
      {
666
 
      out << (*i).first.c_str() << " = " << (*i).second.m_Value.c_str() << std::endl;
 
732
      out << (*i).first.c_str() << " = " << (*i).second.Value.c_str() 
 
733
          << std::endl;
667
734
      }
668
735
    }
669
736
  out << "\n\n";
670
 
  out << "To change values in the CMakeCache, \nedit CMakeCache.txt in your output directory.\n";
 
737
  out << "To change values in the CMakeCache, "
 
738
    << std::endl << "edit CMakeCache.txt in your output directory.\n";
671
739
  out << "=================================================" << std::endl;
672
740
}
673
741
 
674
742
 
675
 
void cmCacheManager::AddCacheEntry(const char* key, 
676
 
                                   const char* value, 
 
743
void cmCacheManager::AddCacheEntry(const char* key,
 
744
                                   const char* value,
677
745
                                   const char* helpString,
678
746
                                   CacheEntryType type)
679
747
{
680
 
  CacheEntry& e = m_Cache[key];
 
748
  CacheEntry& e = this->Cache[key];
681
749
  if ( value )
682
750
    {
683
 
    e.m_Value = value;
684
 
    e.m_Initialized = true;
 
751
    e.Value = value;
 
752
    e.Initialized = true;
685
753
    }
686
 
  else 
 
754
  else
687
755
    {
688
 
    e.m_Value = "";
 
756
    e.Value = "";
689
757
    }
690
 
  e.m_Type = type;
 
758
  e.Type = type;
691
759
  // make sure we only use unix style paths
692
760
  if(type == FILEPATH || type == PATH)
693
761
    {
694
 
    cmSystemTools::ConvertToUnixSlashes(e.m_Value);
 
762
    cmSystemTools::ConvertToUnixSlashes(e.Value);
695
763
    }
696
764
  if ( helpString )
697
765
    {
698
 
    e.m_Properties["HELPSTRING"] = helpString;
 
766
    e.Properties["HELPSTRING"] = helpString;
699
767
    }
700
 
  else 
 
768
  else
701
769
    {
702
 
    e.m_Properties["HELPSTRING"] = "(This variable does not exists and should not be used)";
 
770
    e.Properties["HELPSTRING"] = 
 
771
      "(This variable does not exists and should not be used)";
703
772
    }
704
 
  m_Cache[key] = e;
 
773
  this->Cache[key] = e;
705
774
}
706
775
 
707
 
void cmCacheManager::AddCacheEntry(const char* key, bool v, 
 
776
void cmCacheManager::AddCacheEntry(const char* key, bool v,
708
777
                                   const char* helpString)
709
778
{
710
779
  if(v)
719
788
 
720
789
bool cmCacheManager::CacheIterator::IsAtEnd() const
721
790
{
722
 
  return m_Position == m_Container.m_Cache.end();
 
791
  return this->Position == this->Container.Cache.end();
723
792
}
724
793
 
725
 
void cmCacheManager::CacheIterator::Begin() 
 
794
void cmCacheManager::CacheIterator::Begin()
726
795
{
727
 
  m_Position = m_Container.m_Cache.begin(); 
 
796
  this->Position = this->Container.Cache.begin(); 
728
797
}
729
798
 
730
799
bool cmCacheManager::CacheIterator::Find(const char* key)
731
800
{
732
 
  m_Position = m_Container.m_Cache.find(key);
 
801
  this->Position = this->Container.Cache.find(key);
733
802
  return !this->IsAtEnd();
734
803
}
735
804
 
736
 
void cmCacheManager::CacheIterator::Next() 
 
805
void cmCacheManager::CacheIterator::Next()
737
806
{
738
807
  if (!this->IsAtEnd())
739
808
    {
740
 
    ++m_Position; 
 
809
    ++this->Position; 
741
810
    }
742
811
}
743
812
 
750
819
  CacheEntry* entry = &this->GetEntry();
751
820
  if ( value )
752
821
    {
753
 
    entry->m_Value = value;
754
 
    entry->m_Initialized = true;
 
822
    entry->Value = value;
 
823
    entry->Initialized = true;
755
824
    }
756
825
  else
757
826
    {
758
 
    entry->m_Value = "";
 
827
    entry->Value = "";
759
828
    }
760
829
}
761
830
 
762
 
const char* cmCacheManager::CacheIterator::GetProperty(const char* property) const
 
831
const char* cmCacheManager::CacheIterator::GetProperty(
 
832
  const char* property) const
763
833
{
764
834
  // make sure it is not at the end
765
835
  if (this->IsAtEnd())
769
839
 
770
840
  if ( !strcmp(property, "TYPE") || !strcmp(property, "VALUE") )
771
841
    {
772
 
    cmSystemTools::Error("Property \"", property, 
 
842
    cmSystemTools::Error("Property \"", property,
773
843
                         "\" cannot be accessed through the GetProperty()");
774
844
    return 0;
775
845
    }
776
846
  const CacheEntry* ent = &this->GetEntry();
777
847
  std::map<cmStdString,cmStdString>::const_iterator it = 
778
 
    ent->m_Properties.find(property);
779
 
  if ( it == ent->m_Properties.end() )
 
848
    ent->Properties.find(property);
 
849
  if ( it == ent->Properties.end() )
780
850
    {
781
851
    return 0;
782
852
    }
783
853
  return it->second.c_str();
784
854
}
785
855
 
786
 
void cmCacheManager::CacheIterator::SetProperty(const char* p, const char* v) 
 
856
void cmCacheManager::CacheIterator::SetProperty(const char* p, const char* v)
787
857
{
788
858
  // make sure it is not at the end
789
859
  if (this->IsAtEnd())
793
863
 
794
864
  if ( !strcmp(p, "TYPE") || !strcmp(p, "VALUE") )
795
865
    {
796
 
    cmSystemTools::Error("Property \"", p, 
 
866
    cmSystemTools::Error("Property \"", p,
797
867
                         "\" cannot be accessed through the SetProperty()");
798
868
    return;
799
869
    }
800
870
  CacheEntry* ent = &this->GetEntry();
801
 
  ent->m_Properties[p] = v;
 
871
  ent->Properties[p] = v;
802
872
}
803
873
 
 
874
 
804
875
bool cmCacheManager::CacheIterator::GetValueAsBool() const 
805
876
806
 
  return cmSystemTools::IsOn(this->GetEntry().m_Value.c_str()); 
 
877
  return cmSystemTools::IsOn(this->GetEntry().Value.c_str()); 
807
878
}
808
879
 
809
 
bool cmCacheManager::CacheIterator::GetPropertyAsBool(const char* property) const
 
880
bool cmCacheManager::CacheIterator::GetPropertyAsBool(
 
881
  const char* property) const
810
882
{
811
883
  // make sure it is not at the end
812
884
  if (this->IsAtEnd())
813
885
    {
814
886
    return false;
815
887
    }
816
 
  
 
888
 
817
889
  if ( !strcmp(property, "TYPE") || !strcmp(property, "VALUE") )
818
890
    {
819
 
    cmSystemTools::Error("Property \"", property, 
820
 
                         "\" cannot be accessed through the GetPropertyAsBool()");
 
891
    cmSystemTools::Error("Property \"", property,
 
892
      "\" cannot be accessed through the GetPropertyAsBool()");
821
893
    return false;
822
894
    }
823
895
  const CacheEntry* ent = &this->GetEntry();
824
896
  std::map<cmStdString,cmStdString>::const_iterator it = 
825
 
    ent->m_Properties.find(property);
826
 
  if ( it == ent->m_Properties.end() )
 
897
    ent->Properties.find(property);
 
898
  if ( it == ent->Properties.end() )
827
899
    {
828
900
    return false;
829
901
    }
831
903
}
832
904
 
833
905
 
834
 
void cmCacheManager::CacheIterator::SetProperty(const char* p, bool v) 
 
906
void cmCacheManager::CacheIterator::SetProperty(const char* p, bool v)
835
907
{
836
908
  // make sure it is not at the end
837
909
  if (this->IsAtEnd())
841
913
 
842
914
  if ( !strcmp(p, "TYPE") || !strcmp(p, "VALUE") )
843
915
    {
844
 
    cmSystemTools::Error("Property \"", p, 
 
916
    cmSystemTools::Error("Property \"", p,
845
917
                         "\" cannot be accessed through the SetProperty()");
846
918
    return;
847
919
    }
848
920
  CacheEntry* ent = &this->GetEntry();
849
 
  ent->m_Properties[p] = v ? "ON" : "OFF";
 
921
  ent->Properties[p] = v ? "ON" : "OFF";
850
922
}
851
923
 
852
924
bool cmCacheManager::CacheIterator::PropertyExists(const char* property) const
859
931
 
860
932
  if ( !strcmp(property, "TYPE") || !strcmp(property, "VALUE") )
861
933
    {
862
 
    cmSystemTools::Error("Property \"", property, 
863
 
                         "\" cannot be accessed through the PropertyExists()");
 
934
    cmSystemTools::Error("Property \"", property,
 
935
      "\" cannot be accessed through the PropertyExists()");
864
936
    return false;
865
937
    }
866
938
  const CacheEntry* ent = &this->GetEntry();
867
939
  std::map<cmStdString,cmStdString>::const_iterator it = 
868
 
    ent->m_Properties.find(property);
869
 
  if ( it == ent->m_Properties.end() )
 
940
    ent->Properties.find(property);
 
941
  if ( it == ent->Properties.end() )
870
942
    {
871
943
    return false;
872
944
    }