PageRenderTime 71ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/cmake-2.8.9-rc2/Source/cmake.cxx

#
C++ | 4533 lines | 4195 code | 148 blank | 190 comment | 494 complexity | 2e688e365eee01c8e03ba36b9d47bbce MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, Apache-2.0
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmake.h"
  11. #include "cmDocumentVariables.h"
  12. #include "time.h"
  13. #include "cmCacheManager.h"
  14. #include "cmMakefile.h"
  15. #include "cmLocalGenerator.h"
  16. #include "cmExternalMakefileProjectGenerator.h"
  17. #include "cmCommands.h"
  18. #include "cmCommand.h"
  19. #include "cmFileTimeComparison.h"
  20. #include "cmGeneratedFileStream.h"
  21. #include "cmQtAutomoc.h"
  22. #include "cmSourceFile.h"
  23. #include "cmVersion.h"
  24. #include "cmTest.h"
  25. #include "cmDocumentationFormatterText.h"
  26. #if defined(CMAKE_BUILD_WITH_CMAKE)
  27. # include "cmGraphVizWriter.h"
  28. # include "cmDependsFortran.h" // For -E cmake_copy_f90_mod callback.
  29. # include "cmVariableWatch.h"
  30. # include <cmsys/Terminal.h>
  31. # include <cmsys/CommandLineArguments.hxx>
  32. #endif
  33. #include <cmsys/Directory.hxx>
  34. #include <cmsys/Process.h>
  35. #include <cmsys/Glob.hxx>
  36. #include <cmsys/RegularExpression.hxx>
  37. // only build kdevelop generator on non-windows platforms
  38. // when not bootstrapping cmake
  39. #if !defined(_WIN32)
  40. # if defined(CMAKE_BUILD_WITH_CMAKE)
  41. # define CMAKE_USE_KDEVELOP
  42. # endif
  43. #endif
  44. #if defined(CMAKE_BUILD_WITH_CMAKE)
  45. # define CMAKE_USE_ECLIPSE
  46. #endif
  47. #if defined(__MINGW32__) && !defined(CMAKE_BUILD_WITH_CMAKE)
  48. # define CMAKE_BOOT_MINGW
  49. #endif
  50. // include the generator
  51. #if defined(_WIN32) && !defined(__CYGWIN__)
  52. # if !defined(CMAKE_BOOT_MINGW)
  53. # include "cmGlobalVisualStudio6Generator.h"
  54. # include "cmGlobalVisualStudio7Generator.h"
  55. # include "cmGlobalVisualStudio71Generator.h"
  56. # include "cmGlobalVisualStudio8Generator.h"
  57. # include "cmGlobalVisualStudio9Generator.h"
  58. # include "cmGlobalVisualStudio9IA64Generator.h"
  59. # include "cmGlobalVisualStudio9Win64Generator.h"
  60. # include "cmGlobalVisualStudio10Generator.h"
  61. # include "cmGlobalVisualStudio10IA64Generator.h"
  62. # include "cmGlobalVisualStudio10Win64Generator.h"
  63. # include "cmGlobalVisualStudio11Generator.h"
  64. # include "cmGlobalVisualStudio11Win64Generator.h"
  65. # include "cmGlobalVisualStudio11ARMGenerator.h"
  66. # include "cmGlobalVisualStudio8Win64Generator.h"
  67. # include "cmGlobalBorlandMakefileGenerator.h"
  68. # include "cmGlobalNMakeMakefileGenerator.h"
  69. # include "cmGlobalJOMMakefileGenerator.h"
  70. # include "cmGlobalWatcomWMakeGenerator.h"
  71. # define CMAKE_HAVE_VS_GENERATORS
  72. # endif
  73. # include "cmGlobalMSYSMakefileGenerator.h"
  74. # include "cmGlobalMinGWMakefileGenerator.h"
  75. # include "cmWin32ProcessExecution.h"
  76. #else
  77. #endif
  78. #include "cmGlobalUnixMakefileGenerator3.h"
  79. #ifdef CMAKE_USE_NINJA
  80. # include "cmGlobalNinjaGenerator.h"
  81. #endif
  82. #if defined(CMAKE_HAVE_VS_GENERATORS)
  83. #include "cmCallVisualStudioMacro.h"
  84. #endif
  85. #if !defined(CMAKE_BOOT_MINGW)
  86. # include "cmExtraCodeBlocksGenerator.h"
  87. #endif
  88. #ifdef CMAKE_USE_KDEVELOP
  89. # include "cmGlobalKdevelopGenerator.h"
  90. #endif
  91. #ifdef CMAKE_USE_ECLIPSE
  92. # include "cmExtraEclipseCDT4Generator.h"
  93. #endif
  94. #include <stdlib.h> // required for atoi
  95. #if defined( __APPLE__ )
  96. # if defined(CMAKE_BUILD_WITH_CMAKE)
  97. # include "cmGlobalXCodeGenerator.h"
  98. # define CMAKE_USE_XCODE 1
  99. # endif
  100. # include <sys/types.h>
  101. # include <sys/time.h>
  102. # include <sys/resource.h>
  103. #endif
  104. #include <sys/stat.h> // struct stat
  105. #include <memory> // auto_ptr
  106. static bool cmakeCheckStampFile(const char* stampName);
  107. static bool cmakeCheckStampList(const char* stampName);
  108. void cmNeedBackwardsCompatibility(const std::string& variable,
  109. int access_type, void*, const char*, const cmMakefile*)
  110. {
  111. #ifdef CMAKE_BUILD_WITH_CMAKE
  112. if (access_type == cmVariableWatch::UNKNOWN_VARIABLE_READ_ACCESS)
  113. {
  114. std::string message = "An attempt was made to access a variable: ";
  115. message += variable;
  116. message +=
  117. " that has not been defined. Some variables were always defined "
  118. "by CMake in versions prior to 1.6. To fix this you might need to set "
  119. "the cache value of CMAKE_BACKWARDS_COMPATIBILITY to 1.4 or less. If "
  120. "you are writing a CMakeLists file, (or have already set "
  121. "CMAKE_BACKWARDS_COMPATABILITY to 1.4 or less) then you probably need "
  122. "to include a CMake module to test for the feature this variable "
  123. "defines.";
  124. cmSystemTools::Error(message.c_str());
  125. }
  126. #else
  127. (void)variable;
  128. (void)access_type;
  129. #endif
  130. }
  131. void cmWarnUnusedCliWarning(const std::string& variable,
  132. int, void* ctx, const char*, const cmMakefile*)
  133. {
  134. cmake* cm = reinterpret_cast<cmake*>(ctx);
  135. cm->MarkCliAsUsed(variable);
  136. }
  137. cmake::cmake()
  138. {
  139. this->Trace = false;
  140. this->WarnUninitialized = false;
  141. this->WarnUnused = false;
  142. this->WarnUnusedCli = true;
  143. this->CheckSystemVars = false;
  144. this->SuppressDevWarnings = false;
  145. this->DoSuppressDevWarnings = false;
  146. this->DebugOutput = false;
  147. this->DebugTryCompile = false;
  148. this->ClearBuildSystem = false;
  149. this->FileComparison = new cmFileTimeComparison;
  150. this->Policies = new cmPolicies();
  151. this->InitializeProperties();
  152. #ifdef __APPLE__
  153. struct rlimit rlp;
  154. if(!getrlimit(RLIMIT_STACK, &rlp))
  155. {
  156. if(rlp.rlim_cur != rlp.rlim_max)
  157. {
  158. rlp.rlim_cur = rlp.rlim_max;
  159. setrlimit(RLIMIT_STACK, &rlp);
  160. }
  161. }
  162. #endif
  163. this->Verbose = false;
  164. this->InTryCompile = false;
  165. this->CacheManager = new cmCacheManager(this);
  166. this->GlobalGenerator = 0;
  167. this->ProgressCallback = 0;
  168. this->ProgressCallbackClientData = 0;
  169. this->CurrentWorkingMode = NORMAL_MODE;
  170. #ifdef CMAKE_BUILD_WITH_CMAKE
  171. this->VariableWatch = new cmVariableWatch;
  172. this->VariableWatch->AddWatch("CMAKE_WORDS_BIGENDIAN",
  173. cmNeedBackwardsCompatibility);
  174. this->VariableWatch->AddWatch("CMAKE_SIZEOF_INT",
  175. cmNeedBackwardsCompatibility);
  176. this->VariableWatch->AddWatch("CMAKE_X_LIBS",
  177. cmNeedBackwardsCompatibility);
  178. #endif
  179. this->AddDefaultGenerators();
  180. this->AddDefaultExtraGenerators();
  181. this->AddDefaultCommands();
  182. // Make sure we can capture the build tool output.
  183. cmSystemTools::EnableVSConsoleOutput();
  184. }
  185. cmake::~cmake()
  186. {
  187. delete this->CacheManager;
  188. delete this->Policies;
  189. if (this->GlobalGenerator)
  190. {
  191. delete this->GlobalGenerator;
  192. this->GlobalGenerator = 0;
  193. }
  194. for(RegisteredCommandsMap::iterator j = this->Commands.begin();
  195. j != this->Commands.end(); ++j)
  196. {
  197. delete (*j).second;
  198. }
  199. #ifdef CMAKE_BUILD_WITH_CMAKE
  200. delete this->VariableWatch;
  201. #endif
  202. delete this->FileComparison;
  203. }
  204. void cmake::InitializeProperties()
  205. {
  206. this->Properties.clear();
  207. this->Properties.SetCMakeInstance(this);
  208. this->AccessedProperties.clear();
  209. this->PropertyDefinitions.clear();
  210. // initialize properties
  211. cmCacheManager::DefineProperties(this);
  212. cmSourceFile::DefineProperties(this);
  213. cmTarget::DefineProperties(this);
  214. cmMakefile::DefineProperties(this);
  215. cmTest::DefineProperties(this);
  216. cmake::DefineProperties(this);
  217. }
  218. void cmake::CleanupCommandsAndMacros()
  219. {
  220. this->InitializeProperties();
  221. std::vector<cmCommand*> commands;
  222. for(RegisteredCommandsMap::iterator j = this->Commands.begin();
  223. j != this->Commands.end(); ++j)
  224. {
  225. if ( !j->second->IsA("cmMacroHelperCommand") &&
  226. !j->second->IsA("cmFunctionHelperCommand"))
  227. {
  228. commands.push_back(j->second);
  229. }
  230. else
  231. {
  232. delete j->second;
  233. }
  234. }
  235. this->Commands.erase(this->Commands.begin(), this->Commands.end());
  236. std::vector<cmCommand*>::iterator it;
  237. for ( it = commands.begin(); it != commands.end();
  238. ++ it )
  239. {
  240. this->Commands[cmSystemTools::LowerCase((*it)->GetName())] = *it;
  241. }
  242. }
  243. bool cmake::CommandExists(const char* name) const
  244. {
  245. std::string sName = cmSystemTools::LowerCase(name);
  246. return (this->Commands.find(sName) != this->Commands.end());
  247. }
  248. cmCommand *cmake::GetCommand(const char *name)
  249. {
  250. cmCommand* rm = 0;
  251. std::string sName = cmSystemTools::LowerCase(name);
  252. RegisteredCommandsMap::iterator pos = this->Commands.find(sName);
  253. if (pos != this->Commands.end())
  254. {
  255. rm = (*pos).second;
  256. }
  257. return rm;
  258. }
  259. void cmake::RenameCommand(const char*oldName, const char* newName)
  260. {
  261. // if the command already exists, free the old one
  262. std::string sOldName = cmSystemTools::LowerCase(oldName);
  263. std::string sNewName = cmSystemTools::LowerCase(newName);
  264. RegisteredCommandsMap::iterator pos = this->Commands.find(sOldName);
  265. if ( pos == this->Commands.end() )
  266. {
  267. return;
  268. }
  269. cmCommand* cmd = pos->second;
  270. pos = this->Commands.find(sNewName);
  271. if (pos != this->Commands.end())
  272. {
  273. delete pos->second;
  274. this->Commands.erase(pos);
  275. }
  276. this->Commands.insert(RegisteredCommandsMap::value_type(sNewName, cmd));
  277. pos = this->Commands.find(sOldName);
  278. this->Commands.erase(pos);
  279. }
  280. void cmake::RemoveCommand(const char* name)
  281. {
  282. std::string sName = cmSystemTools::LowerCase(name);
  283. RegisteredCommandsMap::iterator pos = this->Commands.find(sName);
  284. if ( pos != this->Commands.end() )
  285. {
  286. delete pos->second;
  287. this->Commands.erase(pos);
  288. }
  289. }
  290. void cmake::AddCommand(cmCommand* wg)
  291. {
  292. std::string name = cmSystemTools::LowerCase(wg->GetName());
  293. // if the command already exists, free the old one
  294. RegisteredCommandsMap::iterator pos = this->Commands.find(name);
  295. if (pos != this->Commands.end())
  296. {
  297. delete pos->second;
  298. this->Commands.erase(pos);
  299. }
  300. this->Commands.insert( RegisteredCommandsMap::value_type(name, wg));
  301. }
  302. void cmake::RemoveUnscriptableCommands()
  303. {
  304. std::vector<std::string> unscriptableCommands;
  305. cmake::RegisteredCommandsMap* commands = this->GetCommands();
  306. for (cmake::RegisteredCommandsMap::const_iterator pos = commands->begin();
  307. pos != commands->end();
  308. ++pos)
  309. {
  310. if (!pos->second->IsScriptable())
  311. {
  312. unscriptableCommands.push_back(pos->first);
  313. }
  314. }
  315. for(std::vector<std::string>::const_iterator it=unscriptableCommands.begin();
  316. it != unscriptableCommands.end();
  317. ++it)
  318. {
  319. this->RemoveCommand(it->c_str());
  320. }
  321. }
  322. // Parse the args
  323. bool cmake::SetCacheArgs(const std::vector<std::string>& args)
  324. {
  325. bool findPackageMode = false;
  326. for(unsigned int i=1; i < args.size(); ++i)
  327. {
  328. std::string arg = args[i];
  329. if(arg.find("-D",0) == 0)
  330. {
  331. std::string entry = arg.substr(2);
  332. if(entry.size() == 0)
  333. {
  334. ++i;
  335. if(i < args.size())
  336. {
  337. entry = args[i];
  338. }
  339. else
  340. {
  341. cmSystemTools::Error("-D must be followed with VAR=VALUE.");
  342. return false;
  343. }
  344. }
  345. std::string var, value;
  346. cmCacheManager::CacheEntryType type = cmCacheManager::UNINITIALIZED;
  347. if(cmCacheManager::ParseEntry(entry.c_str(), var, value, type))
  348. {
  349. this->CacheManager->AddCacheEntry(var.c_str(), value.c_str(),
  350. "No help, variable specified on the command line.", type);
  351. if(this->WarnUnusedCli)
  352. {
  353. this->WatchUnusedCli(var.c_str());
  354. }
  355. }
  356. else
  357. {
  358. std::cerr << "Parse error in command line argument: " << arg << "\n"
  359. << "Should be: VAR:type=value\n";
  360. cmSystemTools::Error("No cmake script provided.");
  361. return false;
  362. }
  363. }
  364. else if(arg.find("-Wno-dev",0) == 0)
  365. {
  366. this->SuppressDevWarnings = true;
  367. this->DoSuppressDevWarnings = true;
  368. }
  369. else if(arg.find("-Wdev",0) == 0)
  370. {
  371. this->SuppressDevWarnings = false;
  372. this->DoSuppressDevWarnings = true;
  373. }
  374. else if(arg.find("-U",0) == 0)
  375. {
  376. std::string entryPattern = arg.substr(2);
  377. if(entryPattern.size() == 0)
  378. {
  379. ++i;
  380. if(i < args.size())
  381. {
  382. entryPattern = args[i];
  383. }
  384. else
  385. {
  386. cmSystemTools::Error("-U must be followed with VAR.");
  387. return false;
  388. }
  389. }
  390. cmsys::RegularExpression regex(
  391. cmsys::Glob::PatternToRegex(entryPattern.c_str(), true, true).c_str());
  392. //go through all cache entries and collect the vars which will be removed
  393. std::vector<std::string> entriesToDelete;
  394. cmCacheManager::CacheIterator it =
  395. this->CacheManager->GetCacheIterator();
  396. for ( it.Begin(); !it.IsAtEnd(); it.Next() )
  397. {
  398. cmCacheManager::CacheEntryType t = it.GetType();
  399. if(t != cmCacheManager::STATIC)
  400. {
  401. std::string entryName = it.GetName();
  402. if (regex.find(entryName.c_str()))
  403. {
  404. entriesToDelete.push_back(entryName);
  405. }
  406. }
  407. }
  408. // now remove them from the cache
  409. for(std::vector<std::string>::const_iterator currentEntry =
  410. entriesToDelete.begin();
  411. currentEntry != entriesToDelete.end();
  412. ++currentEntry)
  413. {
  414. this->CacheManager->RemoveCacheEntry(currentEntry->c_str());
  415. }
  416. }
  417. else if(arg.find("-C",0) == 0)
  418. {
  419. std::string path = arg.substr(2);
  420. if ( path.size() == 0 )
  421. {
  422. ++i;
  423. if(i < args.size())
  424. {
  425. path = args[i];
  426. }
  427. else
  428. {
  429. cmSystemTools::Error("-C must be followed by a file name.");
  430. return false;
  431. }
  432. }
  433. std::cerr << "loading initial cache file " << path.c_str() << "\n";
  434. this->ReadListFile(args, path.c_str());
  435. }
  436. else if(arg.find("-P",0) == 0)
  437. {
  438. i++;
  439. if(i >= args.size())
  440. {
  441. cmSystemTools::Error("-P must be followed by a file name.");
  442. return false;
  443. }
  444. std::string path = args[i];
  445. if ( path.size() == 0 )
  446. {
  447. cmSystemTools::Error("No cmake script provided.");
  448. return false;
  449. }
  450. this->ReadListFile(args, path.c_str());
  451. }
  452. else if (arg.find("--find-package",0) == 0)
  453. {
  454. findPackageMode = true;
  455. }
  456. }
  457. if (findPackageMode)
  458. {
  459. return this->FindPackage(args);
  460. }
  461. return true;
  462. }
  463. void cmake::ReadListFile(const std::vector<std::string>& args,
  464. const char *path)
  465. {
  466. // if a generator was not yet created, temporarily create one
  467. cmGlobalGenerator *gg = this->GetGlobalGenerator();
  468. bool created = false;
  469. // if a generator was not specified use a generic one
  470. if (!gg)
  471. {
  472. gg = new cmGlobalGenerator;
  473. gg->SetCMakeInstance(this);
  474. created = true;
  475. }
  476. // read in the list file to fill the cache
  477. if(path)
  478. {
  479. std::auto_ptr<cmLocalGenerator> lg(gg->CreateLocalGenerator());
  480. lg->GetMakefile()->SetHomeOutputDirectory
  481. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  482. lg->GetMakefile()->SetStartOutputDirectory
  483. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  484. lg->GetMakefile()->SetHomeDirectory
  485. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  486. lg->GetMakefile()->SetStartDirectory
  487. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  488. if (this->GetWorkingMode() != NORMAL_MODE)
  489. {
  490. std::string file(cmSystemTools::CollapseFullPath(path));
  491. cmSystemTools::ConvertToUnixSlashes(file);
  492. lg->GetMakefile()->SetScriptModeFile(file.c_str());
  493. lg->GetMakefile()->SetArgcArgv(args);
  494. }
  495. if (!lg->GetMakefile()->ReadListFile(0, path))
  496. {
  497. cmSystemTools::Error("Error processing file:", path);
  498. }
  499. }
  500. // free generic one if generated
  501. if (created)
  502. {
  503. delete gg;
  504. }
  505. }
  506. bool cmake::FindPackage(const std::vector<std::string>& args)
  507. {
  508. // if a generator was not yet created, temporarily create one
  509. cmGlobalGenerator *gg = new cmGlobalGenerator;
  510. gg->SetCMakeInstance(this);
  511. this->SetGlobalGenerator(gg);
  512. // read in the list file to fill the cache
  513. std::auto_ptr<cmLocalGenerator> lg(gg->CreateLocalGenerator());
  514. cmMakefile* mf = lg->GetMakefile();
  515. mf->SetHomeOutputDirectory
  516. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  517. mf->SetStartOutputDirectory
  518. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  519. mf->SetHomeDirectory
  520. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  521. mf->SetStartDirectory
  522. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  523. mf->SetArgcArgv(args);
  524. std::string systemFile = mf->GetModulesFile("CMakeFindPackageMode.cmake");
  525. mf->ReadListFile(0, systemFile.c_str());
  526. std::string language = mf->GetSafeDefinition("LANGUAGE");
  527. std::string mode = mf->GetSafeDefinition("MODE");
  528. std::string packageName = mf->GetSafeDefinition("NAME");
  529. bool packageFound = mf->IsOn("PACKAGE_FOUND");
  530. bool quiet = mf->IsOn("PACKAGE_QUIET");
  531. if (!packageFound)
  532. {
  533. if (!quiet)
  534. {
  535. printf("%s not found.\n", packageName.c_str());
  536. }
  537. }
  538. else if (mode == "EXIST")
  539. {
  540. if (!quiet)
  541. {
  542. printf("%s found.\n", packageName.c_str());
  543. }
  544. }
  545. else if (mode == "COMPILE")
  546. {
  547. std::string includes = mf->GetSafeDefinition("PACKAGE_INCLUDE_DIRS");
  548. std::vector<std::string> includeDirs;
  549. cmSystemTools::ExpandListArgument(includes, includeDirs);
  550. std::string includeFlags = lg->GetIncludeFlags(includeDirs,
  551. language.c_str(), false);
  552. std::string definitions = mf->GetSafeDefinition("PACKAGE_DEFINITIONS");
  553. printf("%s %s\n", includeFlags.c_str(), definitions.c_str());
  554. }
  555. else if (mode == "LINK")
  556. {
  557. const char* targetName = "dummy";
  558. std::vector<std::string> srcs;
  559. cmTarget* tgt = mf->AddExecutable(targetName, srcs, true);
  560. tgt->SetProperty("LINKER_LANGUAGE", language.c_str());
  561. std::string libs = mf->GetSafeDefinition("PACKAGE_LIBRARIES");
  562. std::vector<std::string> libList;
  563. cmSystemTools::ExpandListArgument(libs, libList);
  564. for(std::vector<std::string>::const_iterator libIt=libList.begin();
  565. libIt != libList.end();
  566. ++libIt)
  567. {
  568. mf->AddLinkLibraryForTarget(targetName, libIt->c_str(),
  569. cmTarget::GENERAL);
  570. }
  571. std::string linkLibs;
  572. std::string flags;
  573. std::string linkFlags;
  574. lg->GetTargetFlags(linkLibs, flags, linkFlags, *tgt);
  575. printf("%s\n", linkLibs.c_str() );
  576. /* if ( use_win32 )
  577. {
  578. tgt->SetProperty("WIN32_EXECUTABLE", "ON");
  579. }
  580. if ( use_macbundle)
  581. {
  582. tgt->SetProperty("MACOSX_BUNDLE", "ON");
  583. }*/
  584. }
  585. // free generic one if generated
  586. // this->SetGlobalGenerator(0); // setting 0-pointer is not possible
  587. // delete gg; // this crashes inside the cmake instance
  588. return packageFound;
  589. }
  590. // Parse the args
  591. void cmake::SetArgs(const std::vector<std::string>& args,
  592. bool directoriesSetBefore)
  593. {
  594. bool directoriesSet = directoriesSetBefore;
  595. for(unsigned int i=1; i < args.size(); ++i)
  596. {
  597. std::string arg = args[i];
  598. if(arg.find("-H",0) == 0)
  599. {
  600. directoriesSet = true;
  601. std::string path = arg.substr(2);
  602. path = cmSystemTools::CollapseFullPath(path.c_str());
  603. cmSystemTools::ConvertToUnixSlashes(path);
  604. this->SetHomeDirectory(path.c_str());
  605. }
  606. else if(arg.find("-S",0) == 0)
  607. {
  608. // There is no local generate anymore. Ignore -S option.
  609. }
  610. else if(arg.find("-O",0) == 0)
  611. {
  612. // There is no local generate anymore. Ignore -O option.
  613. }
  614. else if(arg.find("-B",0) == 0)
  615. {
  616. directoriesSet = true;
  617. std::string path = arg.substr(2);
  618. path = cmSystemTools::CollapseFullPath(path.c_str());
  619. cmSystemTools::ConvertToUnixSlashes(path);
  620. this->SetHomeOutputDirectory(path.c_str());
  621. }
  622. else if((i < args.size()-1) && (arg.find("--check-build-system",0) == 0))
  623. {
  624. this->CheckBuildSystemArgument = args[++i];
  625. this->ClearBuildSystem = (atoi(args[++i].c_str()) > 0);
  626. }
  627. else if((i < args.size()-1) && (arg.find("--check-stamp-file",0) == 0))
  628. {
  629. this->CheckStampFile = args[++i];
  630. }
  631. else if((i < args.size()-1) && (arg.find("--check-stamp-list",0) == 0))
  632. {
  633. this->CheckStampList = args[++i];
  634. }
  635. #if defined(CMAKE_HAVE_VS_GENERATORS)
  636. else if((i < args.size()-1) && (arg.find("--vs-solution-file",0) == 0))
  637. {
  638. this->VSSolutionFile = args[++i];
  639. }
  640. #endif
  641. else if(arg.find("-V",0) == 0)
  642. {
  643. this->Verbose = true;
  644. }
  645. else if(arg.find("-D",0) == 0)
  646. {
  647. // skip for now
  648. }
  649. else if(arg.find("-U",0) == 0)
  650. {
  651. // skip for now
  652. }
  653. else if(arg.find("-C",0) == 0)
  654. {
  655. // skip for now
  656. }
  657. else if(arg.find("-P",0) == 0)
  658. {
  659. // skip for now
  660. i++;
  661. }
  662. else if(arg.find("--find-package",0) == 0)
  663. {
  664. // skip for now
  665. i++;
  666. }
  667. else if(arg.find("-Wno-dev",0) == 0)
  668. {
  669. // skip for now
  670. }
  671. else if(arg.find("-Wdev",0) == 0)
  672. {
  673. // skip for now
  674. }
  675. else if(arg.find("--graphviz=",0) == 0)
  676. {
  677. std::string path = arg.substr(strlen("--graphviz="));
  678. path = cmSystemTools::CollapseFullPath(path.c_str());
  679. cmSystemTools::ConvertToUnixSlashes(path);
  680. this->GraphVizFile = path;
  681. if ( this->GraphVizFile.empty() )
  682. {
  683. cmSystemTools::Error("No file specified for --graphviz");
  684. }
  685. }
  686. else if(arg.find("--debug-trycompile",0) == 0)
  687. {
  688. std::cout << "debug trycompile on\n";
  689. this->DebugTryCompileOn();
  690. }
  691. else if(arg.find("--debug-output",0) == 0)
  692. {
  693. std::cout << "Running with debug output on.\n";
  694. this->SetDebugOutputOn(true);
  695. }
  696. else if(arg.find("--trace",0) == 0)
  697. {
  698. std::cout << "Running with trace output on.\n";
  699. this->SetTrace(true);
  700. }
  701. else if(arg.find("--warn-uninitialized",0) == 0)
  702. {
  703. std::cout << "Warn about uninitialized values.\n";
  704. this->SetWarnUninitialized(true);
  705. }
  706. else if(arg.find("--warn-unused-vars",0) == 0)
  707. {
  708. std::cout << "Finding unused variables.\n";
  709. this->SetWarnUnused(true);
  710. }
  711. else if(arg.find("--no-warn-unused-cli",0) == 0)
  712. {
  713. std::cout << "Not searching for unused variables given on the " <<
  714. "command line.\n";
  715. this->SetWarnUnusedCli(false);
  716. }
  717. else if(arg.find("--check-system-vars",0) == 0)
  718. {
  719. std::cout << "Also check system files when warning about unused and " <<
  720. "uninitialized variables.\n";
  721. this->SetCheckSystemVars(true);
  722. }
  723. else if(arg.find("-G",0) == 0)
  724. {
  725. std::string value = arg.substr(2);
  726. if(value.size() == 0)
  727. {
  728. ++i;
  729. if(i >= args.size())
  730. {
  731. cmSystemTools::Error("No generator specified for -G");
  732. return;
  733. }
  734. value = args[i];
  735. }
  736. cmGlobalGenerator* gen =
  737. this->CreateGlobalGenerator(value.c_str());
  738. if(!gen)
  739. {
  740. cmSystemTools::Error("Could not create named generator ",
  741. value.c_str());
  742. }
  743. else
  744. {
  745. this->SetGlobalGenerator(gen);
  746. }
  747. }
  748. // no option assume it is the path to the source
  749. else
  750. {
  751. directoriesSet = true;
  752. this->SetDirectoriesFromFile(arg.c_str());
  753. }
  754. }
  755. if(!directoriesSet)
  756. {
  757. this->SetHomeOutputDirectory
  758. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  759. this->SetStartOutputDirectory
  760. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  761. this->SetHomeDirectory
  762. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  763. this->SetStartDirectory
  764. (cmSystemTools::GetCurrentWorkingDirectory().c_str());
  765. }
  766. this->SetStartDirectory(this->GetHomeDirectory());
  767. this->SetStartOutputDirectory(this->GetHomeOutputDirectory());
  768. }
  769. //----------------------------------------------------------------------------
  770. void cmake::SetDirectoriesFromFile(const char* arg)
  771. {
  772. // Check if the argument refers to a CMakeCache.txt or
  773. // CMakeLists.txt file.
  774. std::string listPath;
  775. std::string cachePath;
  776. bool argIsFile = false;
  777. if(cmSystemTools::FileIsDirectory(arg))
  778. {
  779. std::string path = cmSystemTools::CollapseFullPath(arg);
  780. cmSystemTools::ConvertToUnixSlashes(path);
  781. std::string cacheFile = path;
  782. cacheFile += "/CMakeCache.txt";
  783. std::string listFile = path;
  784. listFile += "/CMakeLists.txt";
  785. if(cmSystemTools::FileExists(cacheFile.c_str()))
  786. {
  787. cachePath = path;
  788. }
  789. if(cmSystemTools::FileExists(listFile.c_str()))
  790. {
  791. listPath = path;
  792. }
  793. }
  794. else if(cmSystemTools::FileExists(arg))
  795. {
  796. argIsFile = true;
  797. std::string fullPath = cmSystemTools::CollapseFullPath(arg);
  798. std::string name = cmSystemTools::GetFilenameName(fullPath.c_str());
  799. name = cmSystemTools::LowerCase(name);
  800. if(name == "cmakecache.txt")
  801. {
  802. cachePath = cmSystemTools::GetFilenamePath(fullPath.c_str());
  803. }
  804. else if(name == "cmakelists.txt")
  805. {
  806. listPath = cmSystemTools::GetFilenamePath(fullPath.c_str());
  807. }
  808. }
  809. else
  810. {
  811. // Specified file or directory does not exist. Try to set things
  812. // up to produce a meaningful error message.
  813. std::string fullPath = cmSystemTools::CollapseFullPath(arg);
  814. std::string name = cmSystemTools::GetFilenameName(fullPath.c_str());
  815. name = cmSystemTools::LowerCase(name);
  816. if(name == "cmakecache.txt" || name == "cmakelists.txt")
  817. {
  818. argIsFile = true;
  819. listPath = cmSystemTools::GetFilenamePath(fullPath.c_str());
  820. }
  821. else
  822. {
  823. listPath = fullPath;
  824. }
  825. }
  826. // If there is a CMakeCache.txt file, use its settings.
  827. if(cachePath.length() > 0)
  828. {
  829. cmCacheManager* cachem = this->GetCacheManager();
  830. cmCacheManager::CacheIterator it = cachem->NewIterator();
  831. if(cachem->LoadCache(cachePath.c_str()) &&
  832. it.Find("CMAKE_HOME_DIRECTORY"))
  833. {
  834. this->SetHomeOutputDirectory(cachePath.c_str());
  835. this->SetStartOutputDirectory(cachePath.c_str());
  836. this->SetHomeDirectory(it.GetValue());
  837. this->SetStartDirectory(it.GetValue());
  838. return;
  839. }
  840. }
  841. // If there is a CMakeLists.txt file, use it as the source tree.
  842. if(listPath.length() > 0)
  843. {
  844. this->SetHomeDirectory(listPath.c_str());
  845. this->SetStartDirectory(listPath.c_str());
  846. if(argIsFile)
  847. {
  848. // Source CMakeLists.txt file given. It was probably dropped
  849. // onto the executable in a GUI. Default to an in-source build.
  850. this->SetHomeOutputDirectory(listPath.c_str());
  851. this->SetStartOutputDirectory(listPath.c_str());
  852. }
  853. else
  854. {
  855. // Source directory given on command line. Use current working
  856. // directory as build tree.
  857. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  858. this->SetHomeOutputDirectory(cwd.c_str());
  859. this->SetStartOutputDirectory(cwd.c_str());
  860. }
  861. return;
  862. }
  863. // We didn't find a CMakeLists.txt or CMakeCache.txt file from the
  864. // argument. Assume it is the path to the source tree, and use the
  865. // current working directory as the build tree.
  866. std::string full = cmSystemTools::CollapseFullPath(arg);
  867. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  868. this->SetHomeDirectory(full.c_str());
  869. this->SetStartDirectory(full.c_str());
  870. this->SetHomeOutputDirectory(cwd.c_str());
  871. this->SetStartOutputDirectory(cwd.c_str());
  872. }
  873. // at the end of this CMAKE_ROOT and CMAKE_COMMAND should be added to the
  874. // cache
  875. int cmake::AddCMakePaths()
  876. {
  877. // Find the cmake executable
  878. std::string cMakeSelf = cmSystemTools::GetExecutableDirectory();
  879. cMakeSelf = cmSystemTools::GetRealPath(cMakeSelf.c_str());
  880. cMakeSelf += "/cmake";
  881. cMakeSelf += cmSystemTools::GetExecutableExtension();
  882. #if __APPLE__
  883. // on the apple this might be the gui bundle
  884. if(!cmSystemTools::FileExists(cMakeSelf.c_str()))
  885. {
  886. cMakeSelf = cmSystemTools::GetExecutableDirectory();
  887. cMakeSelf = cmSystemTools::GetRealPath(cMakeSelf.c_str());
  888. cMakeSelf += "../../../..";
  889. cMakeSelf = cmSystemTools::GetRealPath(cMakeSelf.c_str());
  890. cMakeSelf = cmSystemTools::CollapseFullPath(cMakeSelf.c_str());
  891. cMakeSelf += "/cmake";
  892. std::cerr << cMakeSelf.c_str() << "\n";
  893. }
  894. #endif
  895. if(!cmSystemTools::FileExists(cMakeSelf.c_str()))
  896. {
  897. cmSystemTools::Error("CMake executable cannot be found at ",
  898. cMakeSelf.c_str());
  899. return 0;
  900. }
  901. // Save the value in the cache
  902. this->CacheManager->AddCacheEntry
  903. ("CMAKE_COMMAND",cMakeSelf.c_str(), "Path to CMake executable.",
  904. cmCacheManager::INTERNAL);
  905. // if the edit command is not yet in the cache,
  906. // or if CMakeEditCommand has been set on this object,
  907. // then set the CMAKE_EDIT_COMMAND in the cache
  908. // This will mean that the last gui to edit the cache
  909. // will be the one that make edit_cache uses.
  910. if(!this->GetCacheDefinition("CMAKE_EDIT_COMMAND")
  911. || !this->CMakeEditCommand.empty())
  912. {
  913. // Find and save the command to edit the cache
  914. std::string editCacheCommand;
  915. if(!this->CMakeEditCommand.empty())
  916. {
  917. editCacheCommand = cmSystemTools::GetFilenamePath(cMakeSelf)
  918. + std::string("/")
  919. + this->CMakeEditCommand
  920. + cmSystemTools::GetFilenameExtension(cMakeSelf);
  921. }
  922. if( !cmSystemTools::FileExists(editCacheCommand.c_str()))
  923. {
  924. editCacheCommand = cmSystemTools::GetFilenamePath(cMakeSelf) +
  925. "/ccmake" + cmSystemTools::GetFilenameExtension(cMakeSelf);
  926. }
  927. if( !cmSystemTools::FileExists(editCacheCommand.c_str()))
  928. {
  929. editCacheCommand = cmSystemTools::GetFilenamePath(cMakeSelf) +
  930. "/cmake-gui" + cmSystemTools::GetFilenameExtension(cMakeSelf);
  931. }
  932. if(cmSystemTools::FileExists(editCacheCommand.c_str()))
  933. {
  934. this->CacheManager->AddCacheEntry
  935. ("CMAKE_EDIT_COMMAND", editCacheCommand.c_str(),
  936. "Path to cache edit program executable.", cmCacheManager::INTERNAL);
  937. }
  938. }
  939. std::string ctestCommand = cmSystemTools::GetFilenamePath(cMakeSelf) +
  940. "/ctest" + cmSystemTools::GetFilenameExtension(cMakeSelf);
  941. if(cmSystemTools::FileExists(ctestCommand.c_str()))
  942. {
  943. this->CacheManager->AddCacheEntry
  944. ("CMAKE_CTEST_COMMAND", ctestCommand.c_str(),
  945. "Path to ctest program executable.", cmCacheManager::INTERNAL);
  946. }
  947. std::string cpackCommand = cmSystemTools::GetFilenamePath(cMakeSelf) +
  948. "/cpack" + cmSystemTools::GetFilenameExtension(cMakeSelf);
  949. if(cmSystemTools::FileExists(cpackCommand.c_str()))
  950. {
  951. this->CacheManager->AddCacheEntry
  952. ("CMAKE_CPACK_COMMAND", cpackCommand.c_str(),
  953. "Path to cpack program executable.", cmCacheManager::INTERNAL);
  954. }
  955. // do CMAKE_ROOT, look for the environment variable first
  956. std::string cMakeRoot;
  957. std::string modules;
  958. if (getenv("CMAKE_ROOT"))
  959. {
  960. cMakeRoot = getenv("CMAKE_ROOT");
  961. modules = cMakeRoot + "/Modules/CMake.cmake";
  962. }
  963. if(!cmSystemTools::FileExists(modules.c_str()))
  964. {
  965. // next try exe/..
  966. cMakeRoot = cmSystemTools::GetRealPath(cMakeSelf.c_str());
  967. cMakeRoot = cmSystemTools::GetProgramPath(cMakeRoot.c_str());
  968. std::string::size_type slashPos = cMakeRoot.rfind("/");
  969. if(slashPos != std::string::npos)
  970. {
  971. cMakeRoot = cMakeRoot.substr(0, slashPos);
  972. }
  973. // is there no Modules direcory there?
  974. modules = cMakeRoot + "/Modules/CMake.cmake";
  975. }
  976. if (!cmSystemTools::FileExists(modules.c_str()))
  977. {
  978. // try exe/../share/cmake
  979. cMakeRoot += CMAKE_DATA_DIR;
  980. modules = cMakeRoot + "/Modules/CMake.cmake";
  981. }
  982. #ifdef CMAKE_ROOT_DIR
  983. if (!cmSystemTools::FileExists(modules.c_str()))
  984. {
  985. // try compiled in root directory
  986. cMakeRoot = CMAKE_ROOT_DIR;
  987. modules = cMakeRoot + "/Modules/CMake.cmake";
  988. }
  989. #endif
  990. if (!cmSystemTools::FileExists(modules.c_str()))
  991. {
  992. // try
  993. cMakeRoot = cmSystemTools::GetProgramPath(cMakeSelf.c_str());
  994. cMakeRoot += CMAKE_DATA_DIR;
  995. modules = cMakeRoot + "/Modules/CMake.cmake";
  996. }
  997. if(!cmSystemTools::FileExists(modules.c_str()))
  998. {
  999. // next try exe
  1000. cMakeRoot = cmSystemTools::GetProgramPath(cMakeSelf.c_str());
  1001. // is there no Modules direcory there?
  1002. modules = cMakeRoot + "/Modules/CMake.cmake";
  1003. }
  1004. if (!cmSystemTools::FileExists(modules.c_str()))
  1005. {
  1006. // couldn't find modules
  1007. cmSystemTools::Error("Could not find CMAKE_ROOT !!!\n"
  1008. "CMake has most likely not been installed correctly.\n"
  1009. "Modules directory not found in\n",
  1010. cMakeRoot.c_str());
  1011. return 0;
  1012. }
  1013. this->CacheManager->AddCacheEntry
  1014. ("CMAKE_ROOT", cMakeRoot.c_str(),
  1015. "Path to CMake installation.", cmCacheManager::INTERNAL);
  1016. #ifdef _WIN32
  1017. std::string comspec = "cmw9xcom.exe";
  1018. cmSystemTools::SetWindows9xComspecSubstitute(comspec.c_str());
  1019. #endif
  1020. return 1;
  1021. }
  1022. void CMakeCommandUsage(const char* program)
  1023. {
  1024. cmOStringStream errorStream;
  1025. #ifdef CMAKE_BUILD_WITH_CMAKE
  1026. errorStream
  1027. << "cmake version " << cmVersion::GetCMakeVersion() << "\n";
  1028. #else
  1029. errorStream
  1030. << "cmake bootstrap\n";
  1031. #endif
  1032. // If you add new commands, change here,
  1033. // and in cmakemain.cxx in the options table
  1034. errorStream
  1035. << "Usage: " << program << " -E [command] [arguments ...]\n"
  1036. << "Available commands: \n"
  1037. << " chdir dir cmd [args]... - run command in a given directory\n"
  1038. << " compare_files file1 file2 - check if file1 is same as file2\n"
  1039. << " copy file destination - copy file to destination (either file "
  1040. "or directory)\n"
  1041. << " copy_directory source destination - copy directory 'source' "
  1042. "content to directory 'destination'\n"
  1043. << " copy_if_different in-file out-file - copy file if input has "
  1044. "changed\n"
  1045. << " echo [string]... - displays arguments as text\n"
  1046. << " echo_append [string]... - displays arguments as text but no new "
  1047. "line\n"
  1048. << " environment - display the current environment\n"
  1049. << " make_directory dir - create a directory\n"
  1050. << " md5sum file1 [...] - compute md5sum of files\n"
  1051. << " remove [-f] file1 file2 ... - remove the file(s), use -f to force "
  1052. "it\n"
  1053. << " remove_directory dir - remove a directory and its contents\n"
  1054. << " rename oldname newname - rename a file or directory "
  1055. "(on one volume)\n"
  1056. << " tar [cxt][vfz][cvfj] file.tar "
  1057. "file/dir1 file/dir2 ... - create a tar "
  1058. "archive\n"
  1059. << " time command [args] ... - run command and return elapsed time\n"
  1060. << " touch file - touch a file.\n"
  1061. << " touch_nocreate file - touch a file but do not create it.\n"
  1062. #if defined(_WIN32) && !defined(__CYGWIN__)
  1063. << "Available on Windows only:\n"
  1064. << " comspec - on windows 9x use this for RunCommand\n"
  1065. << " delete_regv key - delete registry value\n"
  1066. << " write_regv key value - write registry value\n"
  1067. #else
  1068. << "Available on UNIX only:\n"
  1069. << " create_symlink old new - create a symbolic link new -> old\n"
  1070. #endif
  1071. ;
  1072. cmSystemTools::Error(errorStream.str().c_str());
  1073. }
  1074. int cmake::ExecuteCMakeCommand(std::vector<std::string>& args)
  1075. {
  1076. // IF YOU ADD A NEW COMMAND, DOCUMENT IT ABOVE and in cmakemain.cxx
  1077. if (args.size() > 1)
  1078. {
  1079. // Copy file
  1080. if (args[1] == "copy" && args.size() == 4)
  1081. {
  1082. if(!cmSystemTools::cmCopyFile(args[2].c_str(), args[3].c_str()))
  1083. {
  1084. std::cerr << "Error copying file \"" << args[2].c_str()
  1085. << "\" to \"" << args[3].c_str() << "\".\n";
  1086. return 1;
  1087. }
  1088. return 0;
  1089. }
  1090. // Copy file if different.
  1091. if (args[1] == "copy_if_different" && args.size() == 4)
  1092. {
  1093. if(!cmSystemTools::CopyFileIfDifferent(args[2].c_str(),
  1094. args[3].c_str()))
  1095. {
  1096. std::cerr << "Error copying file (if different) from \""
  1097. << args[2].c_str() << "\" to \"" << args[3].c_str()
  1098. << "\".\n";
  1099. return 1;
  1100. }
  1101. return 0;
  1102. }
  1103. // Copy directory content
  1104. if (args[1] == "copy_directory" && args.size() == 4)
  1105. {
  1106. if(!cmSystemTools::CopyADirectory(args[2].c_str(), args[3].c_str()))
  1107. {
  1108. std::cerr << "Error copying directory from \""
  1109. << args[2].c_str() << "\" to \"" << args[3].c_str()
  1110. << "\".\n";
  1111. return 1;
  1112. }
  1113. return 0;
  1114. }
  1115. // Rename a file or directory
  1116. if (args[1] == "rename" && args.size() == 4)
  1117. {
  1118. if(!cmSystemTools::RenameFile(args[2].c_str(), args[3].c_str()))
  1119. {
  1120. std::string e = cmSystemTools::GetLastSystemError();
  1121. std::cerr << "Error renaming from \""
  1122. << args[2].c_str() << "\" to \"" << args[3].c_str()
  1123. << "\": " << e << "\n";
  1124. return 1;
  1125. }
  1126. return 0;
  1127. }
  1128. // Compare files
  1129. if (args[1] == "compare_files" && args.size() == 4)
  1130. {
  1131. if(cmSystemTools::FilesDiffer(args[2].c_str(), args[3].c_str()))
  1132. {
  1133. std::cerr << "Files \""
  1134. << args[2].c_str() << "\" to \"" << args[3].c_str()
  1135. << "\" are different.\n";
  1136. return 1;
  1137. }
  1138. return 0;
  1139. }
  1140. // Echo string
  1141. else if (args[1] == "echo" )
  1142. {
  1143. unsigned int cc;
  1144. const char* space = "";
  1145. for ( cc = 2; cc < args.size(); cc ++ )
  1146. {
  1147. std::cout << space << args[cc];
  1148. space = " ";
  1149. }
  1150. std::cout << std::endl;
  1151. return 0;
  1152. }
  1153. // Echo string no new line
  1154. else if (args[1] == "echo_append" )
  1155. {
  1156. unsigned int cc;
  1157. const char* space = "";
  1158. for ( cc = 2; cc < args.size(); cc ++ )
  1159. {
  1160. std::cout << space << args[cc];
  1161. space = " ";
  1162. }
  1163. return 0;
  1164. }
  1165. #if defined(CMAKE_BUILD_WITH_CMAKE)
  1166. // Command to create a symbolic link. Fails on platforms not
  1167. // supporting them.
  1168. else if (args[1] == "environment" )
  1169. {
  1170. std::vector<std::string> env = cmSystemTools::GetEnvironmentVariables();
  1171. std::vector<std::string>::iterator it;
  1172. for ( it = env.begin(); it != env.end(); ++ it )
  1173. {
  1174. std::cout << it->c_str() << std::endl;
  1175. }
  1176. return 0;
  1177. }
  1178. #endif
  1179. else if (args[1] == "make_directory" && args.size() == 3)
  1180. {
  1181. if(!cmSystemTools::MakeDirectory(args[2].c_str()))
  1182. {
  1183. std::cerr << "Error making directory \"" << args[2].c_str()
  1184. << "\".\n";
  1185. return 1;
  1186. }
  1187. return 0;
  1188. }
  1189. else if (args[1] == "remove_directory" && args.size() == 3)
  1190. {
  1191. if(cmSystemTools::FileIsDirectory(args[2].c_str()) &&
  1192. !cmSystemTools::RemoveADirectory(args[2].c_str()))
  1193. {
  1194. std::cerr << "Error removing directory \"" << args[2].c_str()
  1195. << "\".\n";
  1196. return 1;
  1197. }
  1198. return 0;
  1199. }
  1200. // Remove file
  1201. else if (args[1] == "remove" && args.size() > 2)
  1202. {
  1203. bool force = false;
  1204. for (std::string::size_type cc = 2; cc < args.size(); cc ++)
  1205. {
  1206. if(args[cc] == "\\-f" || args[cc] == "-f")
  1207. {
  1208. force = true;
  1209. }
  1210. else
  1211. {
  1212. // Complain if the file could not be removed, still exists,
  1213. // and the -f option was not given.
  1214. if(!cmSystemTools::RemoveFile(args[cc].c_str()) && !force &&
  1215. cmSystemTools::FileExists(args[cc].c_str()))
  1216. {
  1217. return 1;
  1218. }
  1219. }
  1220. }
  1221. return 0;
  1222. }
  1223. // Touch file
  1224. else if (args[1] == "touch" && args.size() > 2)
  1225. {
  1226. for (std::string::size_type cc = 2; cc < args.size(); cc ++)
  1227. {
  1228. // Complain if the file could not be removed, still exists,
  1229. // and the -f option was not given.
  1230. if(!cmSystemTools::Touch(args[cc].c_str(), true))
  1231. {
  1232. return 1;
  1233. }
  1234. }
  1235. return 0;
  1236. }
  1237. // Touch file
  1238. else if (args[1] == "touch_nocreate" && args.size() > 2)
  1239. {
  1240. for (std::string::size_type cc = 2; cc < args.size(); cc ++)
  1241. {
  1242. // Complain if the file could not be removed, still exists,
  1243. // and the -f option was not given.
  1244. if(!cmSystemTools::Touch(args[cc].c_str(), false))
  1245. {
  1246. return 1;
  1247. }
  1248. }
  1249. return 0;
  1250. }
  1251. // Clock command
  1252. else if (args[1] == "time" && args.size() > 2)
  1253. {
  1254. std::string command = args[2];
  1255. for (std::string::size_type cc = 3; cc < args.size(); cc ++)
  1256. {
  1257. command += " ";
  1258. command += args[cc];
  1259. }
  1260. clock_t clock_start, clock_finish;
  1261. time_t time_start, time_finish;
  1262. time(&time_start);
  1263. clock_start = clock();
  1264. int ret =0;
  1265. cmSystemTools::RunSingleCommand(command.c_str(), 0, &ret);
  1266. clock_finish = clock();
  1267. time(&time_finish);
  1268. double clocks_per_sec = static_cast<double>(CLOCKS_PER_SEC);
  1269. std::cout << "Elapsed time: "
  1270. << static_cast<long>(time_finish - time_start) << " s. (time)"
  1271. << ", "
  1272. << static_cast<double>(clock_finish - clock_start) / clocks_per_sec
  1273. << " s. (clock)"
  1274. << "\n";
  1275. return ret;
  1276. }
  1277. // Command to calculate the md5sum of a file
  1278. else if (args[1] == "md5sum" && args.size() >= 3)
  1279. {
  1280. char md5out[32];
  1281. int retval = 0;
  1282. for (std::string::size_type cc = 2; cc < args.size(); cc ++)
  1283. {
  1284. const char *filename = args[cc].c_str();
  1285. // Cannot compute md5sum of a directory
  1286. if(cmSystemTools::FileIsDirectory(filename))
  1287. {
  1288. std::cerr << "Error: " << filename << " is a directory" << std::endl;
  1289. retval++;
  1290. }
  1291. else if(!cmSystemTools::ComputeFileMD5(filename, md5out))
  1292. {
  1293. // To mimic md5sum behavior in a shell:
  1294. std::cerr << filename << ": No such file or directory" << std::endl;
  1295. retval++;
  1296. }
  1297. else
  1298. {
  1299. std::cout << std::string(md5out,32) << " " << filename << std::endl;
  1300. }
  1301. }
  1302. return retval;
  1303. }
  1304. // Command to change directory and run a program.
  1305. else if (args[1] == "chdir" && args.size() >= 4)
  1306. {
  1307. std::string directory = args[2];
  1308. if(!cmSystemTools::FileExists(directory.c_str()))
  1309. {
  1310. cmSystemTools::Error("Directory does not exist for chdir command: ",
  1311. args[2].c_str());
  1312. return 1;
  1313. }
  1314. std::string command = "\"";
  1315. command += args[3];
  1316. command += "\"";
  1317. for (std::string::size_type cc = 4; cc < args.size(); cc ++)
  1318. {
  1319. command += " \"";
  1320. command += args[cc];
  1321. command += "\"";
  1322. }
  1323. int retval = 0;
  1324. int timeout = 0;
  1325. if ( cmSystemTools::RunSingleCommand(command.c_str(), 0, &retval,
  1326. directory.c_str(), cmSystemTools::OUTPUT_MERGE, timeout) )
  1327. {
  1328. return retval;
  1329. }
  1330. return 1;
  1331. }
  1332. // Command to start progress for a build
  1333. else if (args[1] == "cmake_progress_start" && args.size() == 4)
  1334. {
  1335. // basically remove the directory
  1336. std::string dirName = args[2];
  1337. dirName += "/Progress";
  1338. cmSystemTools::RemoveADirectory(dirName.c_str());
  1339. // is the last argument a filename that exists?
  1340. FILE *countFile = fopen(args[3].c_str(),"r");
  1341. int count;
  1342. if (countFile)
  1343. {
  1344. if (1!=fscanf(countFile,"%i",&count))
  1345. {
  1346. cmSystemTools::Message("Could not read from count file.");
  1347. }
  1348. fclose(countFile);
  1349. }
  1350. else
  1351. {
  1352. count = atoi(args[3].c_str());
  1353. }
  1354. if (count)
  1355. {
  1356. cmSystemTools::MakeDirectory(dirName.c_str());
  1357. // write the count into the directory
  1358. std::string fName = dirName;
  1359. fName += "/count.txt";
  1360. FILE *progFile = fopen(fName.c_str(),"w");
  1361. if (progFile)
  1362. {
  1363. fprintf(progFile,"%i\n",count);
  1364. fclose(progFile);
  1365. }
  1366. }
  1367. return 0;
  1368. }
  1369. // Command to report progress for a build
  1370. else if (args[1] == "cmake_progress_report" && args.size() >= 3)
  1371. {
  1372. std::string dirName = args[2];
  1373. dirName += "/Progress";
  1374. std::string fName;
  1375. FILE *progFile;
  1376. // read the count
  1377. fName = dirName;
  1378. fName += "/count.txt";
  1379. progFile = fopen(fName.c_str(),"r");
  1380. int count = 0;
  1381. if (!progFile)
  1382. {
  1383. return 0;
  1384. }
  1385. else
  1386. {
  1387. if (1!=fscanf(progFile,"%i",&count))
  1388. {
  1389. cmSystemTools::Message("Could not read from progress file.");
  1390. }
  1391. fclose(progFile);
  1392. }
  1393. unsigned int i;
  1394. for (i = 3; i < args.size(); ++i)
  1395. {
  1396. fName = dirName;
  1397. fName += "/";
  1398. fName += args[i];
  1399. progFile = fopen(fName.c_str(),"w");
  1400. if (progFile)
  1401. {
  1402. fprintf(progFile,"empty");
  1403. fclose(progFile);
  1404. }
  1405. }
  1406. int fileNum = static_cast<int>
  1407. (cmsys::Directory::GetNumberOfFilesInDirectory(dirName.c_str()));
  1408. if (count > 0)
  1409. {
  1410. // print the progress
  1411. fprintf(stdout,"[%3i%%] ",((fileNum-3)*100)/count);
  1412. }
  1413. return 0;
  1414. }
  1415. // Command to create a symbolic link. Fails on platforms not
  1416. // supporting them.
  1417. else if (args[1] == "create_symlink" && args.size() == 4)
  1418. {
  1419. const char* destinationFileName = args[3].c_str();
  1420. if ( cmSystemTools::FileExists(destinationFileName) )
  1421. {
  1422. if ( cmSystemTools::FileIsSymlink(destinationFileName) )
  1423. {
  1424. if ( !cmSystemTools::RemoveFile(destinationFileName) ||
  1425. cmSystemTools::FileExists(destinationFileName) )
  1426. {
  1427. return 0;
  1428. }
  1429. }
  1430. else
  1431. {
  1432. return 0;
  1433. }
  1434. }
  1435. return cmSystemTools::CreateSymlink(args[2].c_str(),
  1436. args[3].c_str())? 0:1;
  1437. }
  1438. // Internal CMake shared library support.
  1439. else if (args[1] == "cmake_symlink_library" && args.size() == 5)
  1440. {
  1441. return cmake::SymlinkLibrary(args);
  1442. }
  1443. // Internal CMake versioned executable support.
  1444. else if (args[1] == "cmake_symlink_executable" && args.size() == 4)
  1445. {
  1446. return cmake::SymlinkExecutable(args);
  1447. }
  1448. #if defined(CMAKE_HAVE_VS_GENERATORS)
  1449. // Internal CMake support for calling Visual Studio macros.
  1450. else if (args[1] == "cmake_call_visual_studio_macro" && args.size() >= 4)
  1451. {
  1452. // args[2] = full path to .sln file or "ALL"
  1453. // args[3] = name of Visual Studio macro to call
  1454. // args[4..args.size()-1] = [optional] args for Visual Studio macro
  1455. std::string macroArgs;
  1456. if (args.size() > 4)
  1457. {
  1458. macroArgs = args[4];
  1459. for (size_t i = 5; i < args.size(); ++i)
  1460. {
  1461. macroArgs += " ";
  1462. macroArgs += args[i];
  1463. }
  1464. }
  1465. return cmCallVisualStudioMacro::CallMacro(args[2], args[3],
  1466. macroArgs, true);
  1467. }
  1468. #endif
  1469. // Internal CMake dependency scanning support.
  1470. else if (args[1] == "cmake_depends" && args.size() >= 6)
  1471. {
  1472. // Use the make system's VERBOSE environment variable to enable
  1473. // verbose output. This can be skipped by also setting CMAKE_NO_VERBOSE
  1474. // (which is set by the Eclipse and KDevelop generators).
  1475. bool verbose = ((cmSystemTools::GetEnv("VERBOSE") != 0)
  1476. && (cmSystemTools::GetEnv("CMAKE_NO_VERBOSE") == 0));
  1477. // Create a cmake object instance to process dependencies.
  1478. cmake cm;
  1479. std::string gen;
  1480. std::string homeDir;
  1481. std::string startDir;
  1482. std::string homeOutDir;
  1483. std::string startOutDir;
  1484. std::string depInfo;
  1485. bool color = false;
  1486. if(args.size() >= 8)
  1487. {
  1488. // Full signature:
  1489. //
  1490. // -E cmake_depends <generator>
  1491. // <home-src-dir> <start-src-dir>
  1492. // <home-out-dir> <start-out-dir>
  1493. // <dep-info> [--color=$(COLOR)]
  1494. //
  1495. // All paths are provided.
  1496. gen = args[2];
  1497. homeDir = args[3];
  1498. startDir = args[4];
  1499. homeOutDir = args[5];
  1500. startOutDir = args[6];
  1501. depInfo = args[7];
  1502. if(args.size() >= 9 &&
  1503. args[8].length() >= 8 &&
  1504. args[8].substr(0, 8) == "--color=")
  1505. {
  1506. // Enable or disable color based on the switch value.
  1507. color = (args[8].size() == 8 ||
  1508. cmSystemTools::IsOn(args[8].substr(8).c_str()));
  1509. }
  1510. }
  1511. else
  1512. {
  1513. // Support older signature for existing makefiles:
  1514. //
  1515. // -E cmake_depends <generator>
  1516. // <home-out-dir> <start-out-dir>
  1517. // <dep-info>
  1518. //
  1519. // Just pretend the source directories are the same as the
  1520. // binary directories so at least scanning will work.
  1521. gen = args[2];
  1522. homeDir = args[3];
  1523. startDir = args[4];
  1524. homeOutDir = args[3];
  1525. startOutDir = args[3];
  1526. depInfo = args[5];
  1527. }
  1528. // Create a local generator configured for the directory in
  1529. // which dependencies will be scanned.
  1530. homeDir = cmSystemTools::CollapseFullPath(homeDir.c_str());
  1531. startDir = cmSystemTools::CollapseFullPath(startDir.c_str());
  1532. homeOutDir = cmSystemTools::CollapseFullPath(homeOutDir.c_str());
  1533. startOutDir = cmSystemTools::CollapseFullPath(startOutDir.c_str());
  1534. cm.SetHomeDirectory(homeDir.c_str());
  1535. cm.SetStartDirectory(startDir.c_str());
  1536. cm.SetHomeOutputDirectory(homeOutDir.c_str());
  1537. cm.SetStartOutputDirectory(startOutDir.c_str());
  1538. if(cmGlobalGenerator* ggd = cm.CreateGlobalGenerator(gen.c_str()))
  1539. {
  1540. cm.SetGlobalGenerator(ggd);
  1541. std::auto_ptr<cmLocalGenerator> lgd(ggd->CreateLocalGenerator());
  1542. lgd->GetMakefile()->SetStartDirectory(startDir.c_str());
  1543. lgd->GetMakefile()->SetStartOutputDirectory(startOutDir.c_str());
  1544. lgd->GetMakefile()->MakeStartDirectoriesCurrent();
  1545. // Actually scan dependencies.
  1546. return lgd->UpdateDependencies(depInfo.c_str(),
  1547. verbose, color)? 0 : 2;
  1548. }
  1549. return 1;
  1550. }
  1551. // Internal CMake link script support.
  1552. else if (args[1] == "cmake_link_script" && args.size() >= 3)
  1553. {
  1554. return cmake::ExecuteLinkScript(args);
  1555. }
  1556. // Internal CMake unimplemented feature notification.
  1557. else if (args[1] == "cmake_unimplemented_variable")
  1558. {
  1559. std::cerr << "Feature not implemented for this platform.";
  1560. if(args.size() == 3)
  1561. {
  1562. std::cerr << " Variable " << args[2] << " is not set.";
  1563. }
  1564. std::cerr << std::endl;
  1565. return 1;
  1566. }
  1567. else if (args[1] == "vs_link_exe")
  1568. {
  1569. return cmake::VisualStudioLink(args, 1);
  1570. }
  1571. else if (args[1] == "vs_link_dll")
  1572. {
  1573. return cmake::VisualStudioLink(args, 2);
  1574. }
  1575. #ifdef CMAKE_BUILD_WITH_CMAKE
  1576. // Internal CMake color makefile support.
  1577. else if (args[1] == "cmake_echo_color")
  1578. {
  1579. return cmake::ExecuteEchoColor(args);
  1580. }
  1581. else if (args[1] == "cmake_automoc")
  1582. {
  1583. cmQtAutomoc automoc;
  1584. bool automocSuccess = automoc.Run(args[2].c_str());
  1585. return automocSuccess ? 0 : 1;
  1586. }
  1587. #endif
  1588. // Tar files
  1589. else if (args[1] == "tar" && args.size() > 3)
  1590. {
  1591. std::string flags = args[2];
  1592. std::string outFile = args[3];
  1593. std::vector<cmStdString> files;
  1594. for (std::string::size_type cc = 4; cc < args.size(); cc ++)
  1595. {
  1596. files.push_back(args[cc]);
  1597. }
  1598. bool gzip = false;
  1599. bool bzip2 = false;
  1600. bool verbose = false;
  1601. if ( flags.find_first_of('j') != flags.npos )
  1602. {
  1603. bzip2 = true;
  1604. }
  1605. if ( flags.find_first_of('z') != flags.npos )
  1606. {
  1607. gzip = true;
  1608. }
  1609. if ( flags.find_first_of('v') != flags.npos )
  1610. {
  1611. verbose = true;
  1612. }
  1613. if ( flags.find_first_of('t') != flags.npos )
  1614. {
  1615. if ( !cmSystemTools::ListTar(outFile.c_str(), gzip, verbose) )
  1616. {
  1617. cmSystemTools::Error("Problem creating tar: ", outFile.c_str());
  1618. return 1;
  1619. }
  1620. }
  1621. else if ( flags.find_first_of('c') != flags.npos )
  1622. {
  1623. if ( !cmSystemTools::CreateTar(
  1624. outFile.c_str(), files, gzip, bzip2, verbose) )
  1625. {
  1626. cmSystemTools::Error("Problem creating tar: ", outFile.c_str());
  1627. return 1;
  1628. }
  1629. }
  1630. else if ( flags.find_first_of('x') != flags.npos )
  1631. {
  1632. if ( !cmSystemTools::ExtractTar(
  1633. outFile.c_str(), gzip, verbose) )
  1634. {
  1635. cmSystemTools::Error("Problem extracting tar: ", outFile.c_str());
  1636. return 1;
  1637. }
  1638. #ifdef WIN32
  1639. // OK, on windows 7 after we untar some files,
  1640. // sometimes we can not rename the directory after
  1641. // the untar is done. This breaks the external project
  1642. // untar and rename code. So, by default we will wait
  1643. // 1/10th of a second after the untar. If CMAKE_UNTAR_DELAY
  1644. // is set in the env, its value will be used instead of 100.
  1645. int delay = 100;
  1646. const char* delayVar = cmSystemTools::GetEnv("CMAKE_UNTAR_DELAY");
  1647. if(delayVar)
  1648. {
  1649. delay = atoi(delayVar);
  1650. }
  1651. if(delay)
  1652. {
  1653. cmSystemTools::Delay(delay);
  1654. }
  1655. #endif
  1656. }
  1657. return 0;
  1658. }
  1659. #if defined(CMAKE_BUILD_WITH_CMAKE)
  1660. // Internal CMake Fortran module support.
  1661. else if (args[1] == "cmake_copy_f90_mod" && args.size() >= 4)
  1662. {
  1663. return cmDependsFortran::CopyModule(args)? 0 : 1;
  1664. }
  1665. #endif
  1666. #if defined(_WIN32) && !defined(__CYGWIN__)
  1667. // Write registry value
  1668. else if (args[1] == "write_regv" && args.size() > 3)
  1669. {
  1670. return cmSystemTools::WriteRegistryValue(args[2].c_str(),
  1671. args[3].c_str()) ? 0 : 1;
  1672. }
  1673. // Delete registry value
  1674. else if (args[1] == "delete_regv" && args.size() > 2)
  1675. {
  1676. return cmSystemTools::DeleteRegistryValue(args[2].c_str()) ? 0 : 1;
  1677. }
  1678. // Remove file
  1679. else if (args[1] == "comspec" && args.size() > 2)
  1680. {
  1681. unsigned int cc;
  1682. std::string command = args[2];
  1683. for ( cc = 3; cc < args.size(); cc ++ )
  1684. {
  1685. command += " " + args[cc];
  1686. }
  1687. return cmWin32ProcessExecution::Windows9xHack(command.c_str());
  1688. }
  1689. #endif
  1690. }
  1691. ::CMakeCommandUsage(args[0].c_str());
  1692. return 1;
  1693. }
  1694. void cmake::AddExtraGenerator(const char* name,
  1695. CreateExtraGeneratorFunctionType newFunction)
  1696. {
  1697. cmExternalMakefileProjectGenerator* extraGenerator = newFunction();
  1698. const std::vector<std::string>& supportedGlobalGenerators =
  1699. extraGenerator->GetSupportedGlobalGenerators();
  1700. for(std::vector<std::string>::const_iterator
  1701. it = supportedGlobalGenerators.begin();
  1702. it != supportedGlobalGenerators.end();
  1703. ++it )
  1704. {
  1705. std::string fullName = cmExternalMakefileProjectGenerator::
  1706. CreateFullGeneratorName(it->c_str(), name);
  1707. this->ExtraGenerators[fullName.c_str()] = newFunction;
  1708. }
  1709. delete extraGenerator;
  1710. }
  1711. void cmake::AddDefaultExtraGenerators()
  1712. {
  1713. #if defined(CMAKE_BUILD_WITH_CMAKE)
  1714. #if defined(_WIN32) && !defined(__CYGWIN__)
  1715. // e.g. kdevelop4 ?
  1716. #endif
  1717. this->AddExtraGenerator(cmExtraCodeBlocksGenerator::GetActualName(),
  1718. &cmExtraCodeBlocksGenerator::New);
  1719. #ifdef CMAKE_USE_ECLIPSE
  1720. this->AddExtraGenerator(cmExtraEclipseCDT4Generator::GetActualName(),
  1721. &cmExtraEclipseCDT4Generator::New);
  1722. #endif
  1723. #ifdef CMAKE_USE_KDEVELOP
  1724. this->AddExtraGenerator(cmGlobalKdevelopGenerator::GetActualName(),
  1725. &cmGlobalKdevelopGenerator::New);
  1726. // for kdevelop also add the generator with just the name of the
  1727. // extra generator, since it was this way since cmake 2.2
  1728. this->ExtraGenerators[cmGlobalKdevelopGenerator::GetActualName()]
  1729. = &cmGlobalKdevelopGenerator::New;
  1730. #endif
  1731. #endif
  1732. }
  1733. //----------------------------------------------------------------------------
  1734. void cmake::GetRegisteredGenerators(std::vector<std::string>& names)
  1735. {
  1736. for(RegisteredGeneratorsMap::const_iterator i = this->Generators.begin();
  1737. i != this->Generators.end(); ++i)
  1738. {
  1739. names.push_back(i->first);
  1740. }
  1741. for(RegisteredExtraGeneratorsMap::const_iterator
  1742. i = this->ExtraGenerators.begin();
  1743. i != this->ExtraGenerators.end(); ++i)
  1744. {
  1745. names.push_back(i->first);
  1746. }
  1747. }
  1748. cmGlobalGenerator* cmake::CreateGlobalGenerator(const char* name)
  1749. {
  1750. cmGlobalGenerator* generator = 0;
  1751. cmExternalMakefileProjectGenerator* extraGenerator = 0;
  1752. RegisteredGeneratorsMap::const_iterator genIt = this->Generators.find(name);
  1753. if(genIt == this->Generators.end())
  1754. {
  1755. RegisteredExtraGeneratorsMap::const_iterator extraGenIt =
  1756. this->ExtraGenerators.find(name);
  1757. if (extraGenIt == this->ExtraGenerators.end())
  1758. {
  1759. return 0;
  1760. }
  1761. extraGenerator = (extraGenIt->second)();
  1762. genIt=this->Generators.find(extraGenerator->GetGlobalGeneratorName(name));
  1763. if(genIt == this->Generators.end())
  1764. {
  1765. delete extraGenerator;
  1766. return 0;
  1767. }
  1768. }
  1769. generator = (genIt->second)();
  1770. generator->SetCMakeInstance(this);
  1771. generator->SetExternalMakefileProjectGenerator(extraGenerator);
  1772. return generator;
  1773. }
  1774. void cmake::SetHomeDirectory(const char* dir)
  1775. {
  1776. this->cmHomeDirectory = dir;
  1777. cmSystemTools::ConvertToUnixSlashes(this->cmHomeDirectory);
  1778. }
  1779. void cmake::SetHomeOutputDirectory(const char* lib)
  1780. {
  1781. this->HomeOutputDirectory = lib;
  1782. cmSystemTools::ConvertToUnixSlashes(this->HomeOutputDirectory);
  1783. }
  1784. void cmake::SetGlobalGenerator(cmGlobalGenerator *gg)
  1785. {
  1786. if(!gg)
  1787. {
  1788. cmSystemTools::Error("Error SetGlobalGenerator called with null");
  1789. return;
  1790. }
  1791. // delete the old generator
  1792. if (this->GlobalGenerator)
  1793. {
  1794. delete this->GlobalGenerator;
  1795. // restore the original environment variables CXX and CC
  1796. // Restore CC
  1797. std::string env = "CC=";
  1798. if(this->CCEnvironment.size())
  1799. {
  1800. env += this->CCEnvironment;
  1801. }
  1802. cmSystemTools::PutEnv(env.c_str());
  1803. env = "CXX=";
  1804. if(this->CXXEnvironment.size())
  1805. {
  1806. env += this->CXXEnvironment;
  1807. }
  1808. cmSystemTools::PutEnv(env.c_str());
  1809. }
  1810. // set the new
  1811. this->GlobalGenerator = gg;
  1812. // set the global flag for unix style paths on cmSystemTools as soon as
  1813. // the generator is set. This allows gmake to be used on windows.
  1814. cmSystemTools::SetForceUnixPaths
  1815. (this->GlobalGenerator->GetForceUnixPaths());
  1816. // Save the environment variables CXX and CC
  1817. const char* cxx = getenv("CXX");
  1818. const char* cc = getenv("CC");
  1819. if(cxx)
  1820. {
  1821. this->CXXEnvironment = cxx;
  1822. }
  1823. else
  1824. {
  1825. this->CXXEnvironment = "";
  1826. }
  1827. if(cc)
  1828. {
  1829. this->CCEnvironment = cc;
  1830. }
  1831. else
  1832. {
  1833. this->CCEnvironment = "";
  1834. }
  1835. // set the cmake instance just to be sure
  1836. gg->SetCMakeInstance(this);
  1837. }
  1838. int cmake::DoPreConfigureChecks()
  1839. {
  1840. // Make sure the Start directory contains a CMakeLists.txt file.
  1841. std::string srcList = this->GetHomeDirectory();
  1842. srcList += "/CMakeLists.txt";
  1843. if(!cmSystemTools::FileExists(srcList.c_str()))
  1844. {
  1845. cmOStringStream err;
  1846. if(cmSystemTools::FileIsDirectory(this->GetHomeDirectory()))
  1847. {
  1848. err << "The source directory \"" << this->GetHomeDirectory()
  1849. << "\" does not appear to contain CMakeLists.txt.\n";
  1850. }
  1851. else if(cmSystemTools::FileExists(this->GetHomeDirectory()))
  1852. {
  1853. err << "The source directory \"" << this->GetHomeDirectory()
  1854. << "\" is a file, not a directory.\n";
  1855. }
  1856. else
  1857. {
  1858. err << "The source directory \"" << this->GetHomeDirectory()
  1859. << "\" does not exist.\n";
  1860. }
  1861. err << "Specify --help for usage, or press the help button on the CMake "
  1862. "GUI.";
  1863. cmSystemTools::Error(err.str().c_str());
  1864. return -2;
  1865. }
  1866. // do a sanity check on some values
  1867. if(this->CacheManager->GetCacheValue("CMAKE_HOME_DIRECTORY"))
  1868. {
  1869. std::string cacheStart =
  1870. this->CacheManager->GetCacheValue("CMAKE_HOME_DIRECTORY");
  1871. cacheStart += "/CMakeLists.txt";
  1872. std::string currentStart = this->GetHomeDirectory();
  1873. currentStart += "/CMakeLists.txt";
  1874. if(!cmSystemTools::SameFile(cacheStart.c_str(), currentStart.c_str()))
  1875. {
  1876. std::string message = "The source \"";
  1877. message += currentStart;
  1878. message += "\" does not match the source \"";
  1879. message += cacheStart;
  1880. message += "\" used to generate cache. ";
  1881. message += "Re-run cmake with a different source directory.";
  1882. cmSystemTools::Error(message.c_str());
  1883. return -2;
  1884. }
  1885. }
  1886. else
  1887. {
  1888. return 0;
  1889. }
  1890. return 1;
  1891. }
  1892. struct SaveCacheEntry
  1893. {
  1894. std::string key;
  1895. std::string value;
  1896. std::string help;
  1897. cmCacheManager::CacheEntryType type;
  1898. };
  1899. int cmake::HandleDeleteCacheVariables(const char* var)
  1900. {
  1901. std::vector<std::string> argsSplit;
  1902. cmSystemTools::ExpandListArgument(std::string(var), argsSplit);
  1903. // erase the property to avoid infinite recursion
  1904. this->SetProperty("__CMAKE_DELETE_CACHE_CHANGE_VARS_", "");
  1905. if(this->GetIsInTryCompile())
  1906. {
  1907. return 0;
  1908. }
  1909. cmCacheManager::CacheIterator ci = this->CacheManager->NewIterator();
  1910. std::vector<SaveCacheEntry> saved;
  1911. cmOStringStream warning;
  1912. warning
  1913. << "You have changed variables that require your cache to be deleted.\n"
  1914. << "Configure will be re-run and you may have to reset some variables.\n"
  1915. << "The following variables have changed:\n";
  1916. for(std::vector<std::string>::iterator i = argsSplit.begin();
  1917. i != argsSplit.end(); ++i)
  1918. {
  1919. SaveCacheEntry save;
  1920. save.key = *i;
  1921. warning << *i << "= ";
  1922. i++;
  1923. save.value = *i;
  1924. warning << *i << "\n";
  1925. if(ci.Find(save.key.c_str()))
  1926. {
  1927. save.type = ci.GetType();
  1928. save.help = ci.GetProperty("HELPSTRING");
  1929. }
  1930. saved.push_back(save);
  1931. }
  1932. // remove the cache
  1933. this->CacheManager->DeleteCache(this->GetStartOutputDirectory());
  1934. // load the empty cache
  1935. this->LoadCache();
  1936. // restore the changed compilers
  1937. for(std::vector<SaveCacheEntry>::iterator i = saved.begin();
  1938. i != saved.end(); ++i)
  1939. {
  1940. this->AddCacheEntry(i->key.c_str(), i->value.c_str(),
  1941. i->help.c_str(), i->type);
  1942. }
  1943. cmSystemTools::Message(warning.str().c_str());
  1944. // avoid reconfigure if there were errors
  1945. if(!cmSystemTools::GetErrorOccuredFlag())
  1946. {
  1947. // re-run configure
  1948. return this->Configure();
  1949. }
  1950. return 0;
  1951. }
  1952. int cmake::Configure()
  1953. {
  1954. if(this->DoSuppressDevWarnings)
  1955. {
  1956. if(this->SuppressDevWarnings)
  1957. {
  1958. this->CacheManager->
  1959. AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS", "TRUE",
  1960. "Suppress Warnings that are meant for"
  1961. " the author of the CMakeLists.txt files.",
  1962. cmCacheManager::INTERNAL);
  1963. }
  1964. else
  1965. {
  1966. this->CacheManager->
  1967. AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS", "FALSE",
  1968. "Suppress Warnings that are meant for"
  1969. " the author of the CMakeLists.txt files.",
  1970. cmCacheManager::INTERNAL);
  1971. }
  1972. }
  1973. int ret = this->ActualConfigure();
  1974. const char* delCacheVars =
  1975. this->GetProperty("__CMAKE_DELETE_CACHE_CHANGE_VARS_");
  1976. if(delCacheVars && delCacheVars[0] != 0)
  1977. {
  1978. return this->HandleDeleteCacheVariables(delCacheVars);
  1979. }
  1980. return ret;
  1981. }
  1982. int cmake::ActualConfigure()
  1983. {
  1984. // Construct right now our path conversion table before it's too late:
  1985. this->UpdateConversionPathTable();
  1986. this->CleanupCommandsAndMacros();
  1987. int res = 0;
  1988. if ( this->GetWorkingMode() == NORMAL_MODE )
  1989. {
  1990. res = this->DoPreConfigureChecks();
  1991. }
  1992. if ( res < 0 )
  1993. {
  1994. return -2;
  1995. }
  1996. if ( !res )
  1997. {
  1998. this->CacheManager->AddCacheEntry
  1999. ("CMAKE_HOME_DIRECTORY",
  2000. this->GetHomeDirectory(),
  2001. "Start directory with the top level CMakeLists.txt file for this "
  2002. "project",
  2003. cmCacheManager::INTERNAL);
  2004. }
  2005. // no generator specified on the command line
  2006. if(!this->GlobalGenerator)
  2007. {
  2008. const char* genName =
  2009. this->CacheManager->GetCacheValue("CMAKE_GENERATOR");
  2010. const char* extraGenName =
  2011. this->CacheManager->GetCacheValue("CMAKE_EXTRA_GENERATOR");
  2012. if(genName)
  2013. {
  2014. std::string fullName = cmExternalMakefileProjectGenerator::
  2015. CreateFullGeneratorName(genName, extraGenName);
  2016. this->GlobalGenerator = this->CreateGlobalGenerator(fullName.c_str());
  2017. }
  2018. if(this->GlobalGenerator)
  2019. {
  2020. // set the global flag for unix style paths on cmSystemTools as
  2021. // soon as the generator is set. This allows gmake to be used
  2022. // on windows.
  2023. cmSystemTools::SetForceUnixPaths
  2024. (this->GlobalGenerator->GetForceUnixPaths());
  2025. }
  2026. else
  2027. {
  2028. #if defined(__BORLANDC__) && defined(_WIN32)
  2029. this->SetGlobalGenerator(new cmGlobalBorlandMakefileGenerator);
  2030. #elif defined(_WIN32) && !defined(__CYGWIN__) && !defined(CMAKE_BOOT_MINGW)
  2031. std::string installedCompiler;
  2032. // Try to find the newest VS installed on the computer and
  2033. // use that as a default if -G is not specified
  2034. const std::string vsregBase =
  2035. "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\";
  2036. std::vector<std::string> vsVerions;
  2037. vsVerions.push_back("VisualStudio\\");
  2038. vsVerions.push_back("VCExpress\\");
  2039. struct VSRegistryEntryName
  2040. {
  2041. const char* MSVersion;
  2042. const char* GeneratorName;
  2043. };
  2044. VSRegistryEntryName version[] = {
  2045. {"6.0", "Visual Studio 6"},
  2046. {"7.0", "Visual Studio 7"},
  2047. {"7.1", "Visual Studio 7 .NET 2003"},
  2048. {"8.0", "Visual Studio 8 2005"},
  2049. {"9.0", "Visual Studio 9 2008"},
  2050. {"10.0", "Visual Studio 10"},
  2051. {0, 0}};
  2052. for(size_t b=0; b < vsVerions.size() && installedCompiler.empty(); b++)
  2053. {
  2054. for(int i =0; version[i].MSVersion != 0; i++)
  2055. {
  2056. std::string reg = vsregBase + vsVerions[b] + version[i].MSVersion;
  2057. reg += ";InstallDir]";
  2058. cmSystemTools::ExpandRegistryValues(reg,
  2059. cmSystemTools::KeyWOW64_32);
  2060. if (!(reg == "/registry"))
  2061. {
  2062. installedCompiler = version[i].GeneratorName;
  2063. }
  2064. }
  2065. }
  2066. cmGlobalGenerator* gen
  2067. = this->CreateGlobalGenerator(installedCompiler.c_str());
  2068. if(!gen)
  2069. {
  2070. gen = new cmGlobalNMakeMakefileGenerator;
  2071. }
  2072. this->SetGlobalGenerator(gen);
  2073. std::cout << "-- Building for: " << gen->GetName() << "\n";
  2074. #else
  2075. this->SetGlobalGenerator(new cmGlobalUnixMakefileGenerator3);
  2076. #endif
  2077. }
  2078. if(!this->GlobalGenerator)
  2079. {
  2080. cmSystemTools::Error("Could not create generator");
  2081. return -1;
  2082. }
  2083. }
  2084. const char* genName = this->CacheManager->GetCacheValue("CMAKE_GENERATOR");
  2085. if(genName)
  2086. {
  2087. if(strcmp(this->GlobalGenerator->GetName(), genName) != 0)
  2088. {
  2089. std::string message = "Error: generator : ";
  2090. message += this->GlobalGenerator->GetName();
  2091. message += "\nDoes not match the generator used previously: ";
  2092. message += genName;
  2093. message +=
  2094. "\nEither remove the CMakeCache.txt file or choose a different"
  2095. " binary directory.";
  2096. cmSystemTools::Error(message.c_str());
  2097. return -2;
  2098. }
  2099. }
  2100. if(!this->CacheManager->GetCacheValue("CMAKE_GENERATOR"))
  2101. {
  2102. this->CacheManager->AddCacheEntry("CMAKE_GENERATOR",
  2103. this->GlobalGenerator->GetName(),
  2104. "Name of generator.",
  2105. cmCacheManager::INTERNAL);
  2106. this->CacheManager->AddCacheEntry("CMAKE_EXTRA_GENERATOR",
  2107. this->GlobalGenerator->GetExtraGeneratorName(),
  2108. "Name of external makefile project generator.",
  2109. cmCacheManager::INTERNAL);
  2110. }
  2111. // reset any system configuration information, except for when we are
  2112. // InTryCompile. With TryCompile the system info is taken from the parent's
  2113. // info to save time
  2114. if (!this->InTryCompile)
  2115. {
  2116. this->GlobalGenerator->ClearEnabledLanguages();
  2117. }
  2118. // Truncate log files
  2119. if (!this->InTryCompile)
  2120. {
  2121. this->TruncateOutputLog("CMakeOutput.log");
  2122. this->TruncateOutputLog("CMakeError.log");
  2123. }
  2124. // actually do the configure
  2125. this->GlobalGenerator->Configure();
  2126. // Before saving the cache
  2127. // if the project did not define one of the entries below, add them now
  2128. // so users can edit the values in the cache:
  2129. // We used to always present LIBRARY_OUTPUT_PATH and
  2130. // EXECUTABLE_OUTPUT_PATH. They are now documented as old-style and
  2131. // should no longer be used. Therefore we present them only if the
  2132. // project requires compatibility with CMake 2.4. We detect this
  2133. // here by looking for the old CMAKE_BACKWARDS_COMPATABILITY
  2134. // variable created when CMP0001 is not set to NEW.
  2135. if(this->GetCacheManager()->GetCacheValue("CMAKE_BACKWARDS_COMPATIBILITY"))
  2136. {
  2137. if(!this->CacheManager->GetCacheValue("LIBRARY_OUTPUT_PATH"))
  2138. {
  2139. this->CacheManager->AddCacheEntry
  2140. ("LIBRARY_OUTPUT_PATH", "",
  2141. "Single output directory for building all libraries.",
  2142. cmCacheManager::PATH);
  2143. }
  2144. if(!this->CacheManager->GetCacheValue("EXECUTABLE_OUTPUT_PATH"))
  2145. {
  2146. this->CacheManager->AddCacheEntry
  2147. ("EXECUTABLE_OUTPUT_PATH", "",
  2148. "Single output directory for building all executables.",
  2149. cmCacheManager::PATH);
  2150. }
  2151. }
  2152. if(!this->CacheManager->GetCacheValue("CMAKE_USE_RELATIVE_PATHS"))
  2153. {
  2154. this->CacheManager->AddCacheEntry
  2155. ("CMAKE_USE_RELATIVE_PATHS", "OFF",
  2156. "If true, cmake will use relative paths in makefiles and projects.",
  2157. cmCacheManager::BOOL);
  2158. cmCacheManager::CacheIterator it =
  2159. this->CacheManager->GetCacheIterator("CMAKE_USE_RELATIVE_PATHS");
  2160. if ( !it.PropertyExists("ADVANCED") )
  2161. {
  2162. it.SetProperty("ADVANCED", "1");
  2163. }
  2164. }
  2165. if(cmSystemTools::GetFatalErrorOccured() &&
  2166. (!this->CacheManager->GetCacheValue("CMAKE_MAKE_PROGRAM") ||
  2167. cmSystemTools::IsOff(this->CacheManager->
  2168. GetCacheValue("CMAKE_MAKE_PROGRAM"))))
  2169. {
  2170. // We must have a bad generator selection. Wipe the cache entry so the
  2171. // user can select another.
  2172. this->CacheManager->RemoveCacheEntry("CMAKE_GENERATOR");
  2173. this->CacheManager->RemoveCacheEntry("CMAKE_EXTRA_GENERATOR");
  2174. }
  2175. // only save the cache if there were no fatal errors
  2176. if ( this->GetWorkingMode() == NORMAL_MODE )
  2177. {
  2178. this->CacheManager->SaveCache(this->GetHomeOutputDirectory());
  2179. }
  2180. if ( !this->GraphVizFile.empty() )
  2181. {
  2182. std::cout << "Generate graphviz: " << this->GraphVizFile << std::endl;
  2183. this->GenerateGraphViz(this->GraphVizFile.c_str());
  2184. }
  2185. if(cmSystemTools::GetErrorOccuredFlag())
  2186. {
  2187. return -1;
  2188. }
  2189. return 0;
  2190. }
  2191. void cmake::PreLoadCMakeFiles()
  2192. {
  2193. std::vector<std::string> args;
  2194. std::string pre_load = this->GetHomeDirectory();
  2195. if ( pre_load.size() > 0 )
  2196. {
  2197. pre_load += "/PreLoad.cmake";
  2198. if ( cmSystemTools::FileExists(pre_load.c_str()) )
  2199. {
  2200. this->ReadListFile(args, pre_load.c_str());
  2201. }
  2202. }
  2203. pre_load = this->GetHomeOutputDirectory();
  2204. if ( pre_load.size() > 0 )
  2205. {
  2206. pre_load += "/PreLoad.cmake";
  2207. if ( cmSystemTools::FileExists(pre_load.c_str()) )
  2208. {
  2209. this->ReadListFile(args, pre_load.c_str());
  2210. }
  2211. }
  2212. }
  2213. // handle a command line invocation
  2214. int cmake::Run(const std::vector<std::string>& args, bool noconfigure)
  2215. {
  2216. // Process the arguments
  2217. this->SetArgs(args);
  2218. if(cmSystemTools::GetErrorOccuredFlag())
  2219. {
  2220. return -1;
  2221. }
  2222. // If we are given a stamp list file check if it is really out of date.
  2223. if(!this->CheckStampList.empty() &&
  2224. cmakeCheckStampList(this->CheckStampList.c_str()))
  2225. {
  2226. return 0;
  2227. }
  2228. // If we are given a stamp file check if it is really out of date.
  2229. if(!this->CheckStampFile.empty() &&
  2230. cmakeCheckStampFile(this->CheckStampFile.c_str()))
  2231. {
  2232. return 0;
  2233. }
  2234. // set the cmake command
  2235. this->CMakeCommand = args[0];
  2236. if ( this->GetWorkingMode() == NORMAL_MODE )
  2237. {
  2238. // load the cache
  2239. if(this->LoadCache() < 0)
  2240. {
  2241. cmSystemTools::Error("Error executing cmake::LoadCache(). Aborting.\n");
  2242. return -1;
  2243. }
  2244. }
  2245. else
  2246. {
  2247. this->AddCMakePaths();
  2248. }
  2249. // Add any cache args
  2250. if ( !this->SetCacheArgs(args) )
  2251. {
  2252. cmSystemTools::Error("Problem processing arguments. Aborting.\n");
  2253. return -1;
  2254. }
  2255. // In script mode we terminate after running the script.
  2256. if(this->GetWorkingMode() != NORMAL_MODE)
  2257. {
  2258. if(cmSystemTools::GetErrorOccuredFlag())
  2259. {
  2260. return -1;
  2261. }
  2262. else
  2263. {
  2264. return 0;
  2265. }
  2266. }
  2267. // If MAKEFLAGS are given in the environment, remove the environment
  2268. // variable. This will prevent try-compile from succeeding when it
  2269. // should fail (if "-i" is an option). We cannot simply test
  2270. // whether "-i" is given and remove it because some make programs
  2271. // encode the MAKEFLAGS variable in a strange way.
  2272. if(getenv("MAKEFLAGS"))
  2273. {
  2274. cmSystemTools::PutEnv("MAKEFLAGS=");
  2275. }
  2276. this->PreLoadCMakeFiles();
  2277. std::string systemFile = this->GetHomeOutputDirectory();
  2278. systemFile += "/CMakeSystem.cmake";
  2279. if ( noconfigure )
  2280. {
  2281. return 0;
  2282. }
  2283. // now run the global generate
  2284. // Check the state of the build system to see if we need to regenerate.
  2285. if(!this->CheckBuildSystem())
  2286. {
  2287. return 0;
  2288. }
  2289. // If we are doing global generate, we better set start and start
  2290. // output directory to the root of the project.
  2291. std::string oldstartdir = this->GetStartDirectory();
  2292. std::string oldstartoutputdir = this->GetStartOutputDirectory();
  2293. this->SetStartDirectory(this->GetHomeDirectory());
  2294. this->SetStartOutputDirectory(this->GetHomeOutputDirectory());
  2295. int ret = this->Configure();
  2296. if (ret || this->GetWorkingMode() != NORMAL_MODE)
  2297. {
  2298. #if defined(CMAKE_HAVE_VS_GENERATORS)
  2299. if(!this->VSSolutionFile.empty() && this->GlobalGenerator)
  2300. {
  2301. // CMake is running to regenerate a Visual Studio build tree
  2302. // during a build from the VS IDE. The build files cannot be
  2303. // regenerated, so we should stop the build.
  2304. cmSystemTools::Message(
  2305. "CMake Configure step failed. "
  2306. "Build files cannot be regenerated correctly. "
  2307. "Attempting to stop IDE build.");
  2308. cmGlobalVisualStudioGenerator* gg =
  2309. static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator);
  2310. gg->CallVisualStudioMacro(cmGlobalVisualStudioGenerator::MacroStop,
  2311. this->VSSolutionFile.c_str());
  2312. }
  2313. #endif
  2314. return ret;
  2315. }
  2316. ret = this->Generate();
  2317. std::string message = "Build files have been written to: ";
  2318. message += this->GetHomeOutputDirectory();
  2319. this->UpdateProgress(message.c_str(), -1);
  2320. if(ret)
  2321. {
  2322. return ret;
  2323. }
  2324. this->SetStartDirectory(oldstartdir.c_str());
  2325. this->SetStartOutputDirectory(oldstartoutputdir.c_str());
  2326. return ret;
  2327. }
  2328. int cmake::Generate()
  2329. {
  2330. if(!this->GlobalGenerator)
  2331. {
  2332. return -1;
  2333. }
  2334. this->GlobalGenerator->Generate();
  2335. if(this->WarnUnusedCli)
  2336. {
  2337. this->RunCheckForUnusedVariables();
  2338. }
  2339. if(cmSystemTools::GetErrorOccuredFlag())
  2340. {
  2341. return -1;
  2342. }
  2343. if (this->GetProperty("REPORT_UNDEFINED_PROPERTIES"))
  2344. {
  2345. this->ReportUndefinedPropertyAccesses
  2346. (this->GetProperty("REPORT_UNDEFINED_PROPERTIES"));
  2347. }
  2348. // Save the cache again after a successful Generate so that any internal
  2349. // variables created during Generate are saved. (Specifically target GUIDs
  2350. // for the Visual Studio and Xcode generators.)
  2351. if ( this->GetWorkingMode() == NORMAL_MODE )
  2352. {
  2353. this->CacheManager->SaveCache(this->GetHomeOutputDirectory());
  2354. }
  2355. return 0;
  2356. }
  2357. void cmake::AddCacheEntry(const char* key, const char* value,
  2358. const char* helpString,
  2359. int type)
  2360. {
  2361. this->CacheManager->AddCacheEntry(key, value,
  2362. helpString,
  2363. cmCacheManager::CacheEntryType(type));
  2364. }
  2365. const char* cmake::GetCacheDefinition(const char* name) const
  2366. {
  2367. return this->CacheManager->GetCacheValue(name);
  2368. }
  2369. void cmake::AddDefaultCommands()
  2370. {
  2371. std::list<cmCommand*> commands;
  2372. GetBootstrapCommands(commands);
  2373. GetPredefinedCommands(commands);
  2374. for(std::list<cmCommand*>::iterator i = commands.begin();
  2375. i != commands.end(); ++i)
  2376. {
  2377. this->AddCommand(*i);
  2378. }
  2379. }
  2380. void cmake::AddDefaultGenerators()
  2381. {
  2382. #if defined(_WIN32) && !defined(__CYGWIN__)
  2383. # if !defined(CMAKE_BOOT_MINGW)
  2384. this->Generators[cmGlobalVisualStudio6Generator::GetActualName()] =
  2385. &cmGlobalVisualStudio6Generator::New;
  2386. this->Generators[cmGlobalVisualStudio7Generator::GetActualName()] =
  2387. &cmGlobalVisualStudio7Generator::New;
  2388. this->Generators[cmGlobalVisualStudio10Generator::GetActualName()] =
  2389. &cmGlobalVisualStudio10Generator::New;
  2390. this->Generators[cmGlobalVisualStudio10IA64Generator::GetActualName()] =
  2391. &cmGlobalVisualStudio10IA64Generator::New;
  2392. this->Generators[cmGlobalVisualStudio10Win64Generator::GetActualName()] =
  2393. &cmGlobalVisualStudio10Win64Generator::New;
  2394. this->Generators[cmGlobalVisualStudio11Generator::GetActualName()] =
  2395. &cmGlobalVisualStudio11Generator::New;
  2396. this->Generators[cmGlobalVisualStudio11Win64Generator::GetActualName()] =
  2397. &cmGlobalVisualStudio11Win64Generator::New;
  2398. this->Generators[cmGlobalVisualStudio11ARMGenerator::GetActualName()] =
  2399. &cmGlobalVisualStudio11ARMGenerator::New;
  2400. this->Generators[cmGlobalVisualStudio71Generator::GetActualName()] =
  2401. &cmGlobalVisualStudio71Generator::New;
  2402. this->Generators[cmGlobalVisualStudio8Generator::GetActualName()] =
  2403. &cmGlobalVisualStudio8Generator::New;
  2404. this->Generators[cmGlobalVisualStudio9Generator::GetActualName()] =
  2405. &cmGlobalVisualStudio9Generator::New;
  2406. this->Generators[cmGlobalVisualStudio9IA64Generator::GetActualName()] =
  2407. &cmGlobalVisualStudio9IA64Generator::New;
  2408. this->Generators[cmGlobalVisualStudio9Win64Generator::GetActualName()] =
  2409. &cmGlobalVisualStudio9Win64Generator::New;
  2410. this->Generators[cmGlobalVisualStudio8Win64Generator::GetActualName()] =
  2411. &cmGlobalVisualStudio8Win64Generator::New;
  2412. this->Generators[cmGlobalBorlandMakefileGenerator::GetActualName()] =
  2413. &cmGlobalBorlandMakefileGenerator::New;
  2414. this->Generators[cmGlobalNMakeMakefileGenerator::GetActualName()] =
  2415. &cmGlobalNMakeMakefileGenerator::New;
  2416. this->Generators[cmGlobalJOMMakefileGenerator::GetActualName()] =
  2417. &cmGlobalJOMMakefileGenerator::New;
  2418. this->Generators[cmGlobalWatcomWMakeGenerator::GetActualName()] =
  2419. &cmGlobalWatcomWMakeGenerator::New;
  2420. # endif
  2421. this->Generators[cmGlobalMSYSMakefileGenerator::GetActualName()] =
  2422. &cmGlobalMSYSMakefileGenerator::New;
  2423. this->Generators[cmGlobalMinGWMakefileGenerator::GetActualName()] =
  2424. &cmGlobalMinGWMakefileGenerator::New;
  2425. #endif
  2426. this->Generators[cmGlobalUnixMakefileGenerator3::GetActualName()] =
  2427. &cmGlobalUnixMakefileGenerator3::New;
  2428. #ifdef CMAKE_USE_NINJA
  2429. this->Generators[cmGlobalNinjaGenerator::GetActualName()] =
  2430. &cmGlobalNinjaGenerator::New;
  2431. #endif
  2432. #ifdef CMAKE_USE_XCODE
  2433. this->Generators[cmGlobalXCodeGenerator::GetActualName()] =
  2434. &cmGlobalXCodeGenerator::New;
  2435. #endif
  2436. }
  2437. int cmake::LoadCache()
  2438. {
  2439. // could we not read the cache
  2440. if (!this->CacheManager->LoadCache(this->GetHomeOutputDirectory()))
  2441. {
  2442. // if it does exist, but isn't readable then warn the user
  2443. std::string cacheFile = this->GetHomeOutputDirectory();
  2444. cacheFile += "/CMakeCache.txt";
  2445. if(cmSystemTools::FileExists(cacheFile.c_str()))
  2446. {
  2447. cmSystemTools::Error(
  2448. "There is a CMakeCache.txt file for the current binary tree but "
  2449. "cmake does not have permission to read it. Please check the "
  2450. "permissions of the directory you are trying to run CMake on.");
  2451. return -1;
  2452. }
  2453. }
  2454. if (this->CMakeCommand.size() < 2)
  2455. {
  2456. cmSystemTools::Error(
  2457. "cmake command was not specified prior to loading the cache in "
  2458. "cmake.cxx");
  2459. return -1;
  2460. }
  2461. // setup CMAKE_ROOT and CMAKE_COMMAND
  2462. if(!this->AddCMakePaths())
  2463. {
  2464. return -3;
  2465. }
  2466. return 0;
  2467. }
  2468. void cmake::SetProgressCallback(ProgressCallbackType f, void *cd)
  2469. {
  2470. this->ProgressCallback = f;
  2471. this->ProgressCallbackClientData = cd;
  2472. }
  2473. void cmake::UpdateProgress(const char *msg, float prog)
  2474. {
  2475. if(this->ProgressCallback && !this->InTryCompile)
  2476. {
  2477. (*this->ProgressCallback)(msg, prog, this->ProgressCallbackClientData);
  2478. return;
  2479. }
  2480. }
  2481. void cmake::GetCommandDocumentation(std::vector<cmDocumentationEntry>& v,
  2482. bool withCurrentCommands,
  2483. bool withCompatCommands) const
  2484. {
  2485. for(RegisteredCommandsMap::const_iterator j = this->Commands.begin();
  2486. j != this->Commands.end(); ++j)
  2487. {
  2488. if ((( withCompatCommands == false) && ( (*j).second->IsDiscouraged()))
  2489. || ((withCurrentCommands == false) && (!(*j).second->IsDiscouraged()))
  2490. || (!((*j).second->ShouldAppearInDocumentation()))
  2491. )
  2492. {
  2493. continue;
  2494. }
  2495. cmDocumentationEntry e((*j).second->GetName(),
  2496. (*j).second->GetTerseDocumentation(),
  2497. (*j).second->GetFullDocumentation());
  2498. v.push_back(e);
  2499. }
  2500. }
  2501. void cmake::GetPolicyDocumentation(std::vector<cmDocumentationEntry>& v)
  2502. {
  2503. this->Policies->GetDocumentation(v);
  2504. }
  2505. void cmake::GetPropertiesDocumentation(std::map<std::string,
  2506. cmDocumentationSection *>& v)
  2507. {
  2508. // loop over the properties and put them into the doc structure
  2509. std::map<cmProperty::ScopeType, cmPropertyDefinitionMap>::iterator i;
  2510. i = this->PropertyDefinitions.begin();
  2511. for (;i != this->PropertyDefinitions.end(); ++i)
  2512. {
  2513. i->second.GetPropertiesDocumentation(v);
  2514. }
  2515. }
  2516. void cmake::GetGeneratorDocumentation(std::vector<cmDocumentationEntry>& v)
  2517. {
  2518. for(RegisteredGeneratorsMap::const_iterator i = this->Generators.begin();
  2519. i != this->Generators.end(); ++i)
  2520. {
  2521. cmDocumentationEntry e;
  2522. cmGlobalGenerator* generator = (i->second)();
  2523. generator->GetDocumentation(e);
  2524. delete generator;
  2525. v.push_back(e);
  2526. }
  2527. for(RegisteredExtraGeneratorsMap::const_iterator
  2528. i = this->ExtraGenerators.begin(); i != this->ExtraGenerators.end(); ++i)
  2529. {
  2530. cmDocumentationEntry e;
  2531. cmExternalMakefileProjectGenerator* generator = (i->second)();
  2532. generator->GetDocumentation(e, i->first.c_str());
  2533. e.Name = i->first;
  2534. delete generator;
  2535. v.push_back(e);
  2536. }
  2537. }
  2538. void cmake::UpdateConversionPathTable()
  2539. {
  2540. // Update the path conversion table with any specified file:
  2541. const char* tablepath =
  2542. this->CacheManager->GetCacheValue("CMAKE_PATH_TRANSLATION_FILE");
  2543. if(tablepath)
  2544. {
  2545. std::ifstream table( tablepath );
  2546. if(!table)
  2547. {
  2548. cmSystemTools::Error("CMAKE_PATH_TRANSLATION_FILE set to ", tablepath,
  2549. ". CMake can not open file.");
  2550. cmSystemTools::ReportLastSystemError("CMake can not open file.");
  2551. }
  2552. else
  2553. {
  2554. std::string a, b;
  2555. while(!table.eof())
  2556. {
  2557. // two entries per line
  2558. table >> a; table >> b;
  2559. cmSystemTools::AddTranslationPath( a.c_str(), b.c_str());
  2560. }
  2561. }
  2562. }
  2563. }
  2564. //----------------------------------------------------------------------------
  2565. int cmake::CheckBuildSystem()
  2566. {
  2567. // We do not need to rerun CMake. Check dependency integrity. Use
  2568. // the make system's VERBOSE environment variable to enable verbose
  2569. // output. This can be skipped by setting CMAKE_NO_VERBOSE (which is set
  2570. // by the Eclipse and KDevelop generators).
  2571. bool verbose = ((cmSystemTools::GetEnv("VERBOSE") != 0)
  2572. && (cmSystemTools::GetEnv("CMAKE_NO_VERBOSE") == 0));
  2573. // This method will check the integrity of the build system if the
  2574. // option was given on the command line. It reads the given file to
  2575. // determine whether CMake should rerun.
  2576. // If no file is provided for the check, we have to rerun.
  2577. if(this->CheckBuildSystemArgument.size() == 0)
  2578. {
  2579. if(verbose)
  2580. {
  2581. cmOStringStream msg;
  2582. msg << "Re-run cmake no build system arguments\n";
  2583. cmSystemTools::Stdout(msg.str().c_str());
  2584. }
  2585. return 1;
  2586. }
  2587. // If the file provided does not exist, we have to rerun.
  2588. if(!cmSystemTools::FileExists(this->CheckBuildSystemArgument.c_str()))
  2589. {
  2590. if(verbose)
  2591. {
  2592. cmOStringStream msg;
  2593. msg << "Re-run cmake missing file: "
  2594. << this->CheckBuildSystemArgument.c_str() << "\n";
  2595. cmSystemTools::Stdout(msg.str().c_str());
  2596. }
  2597. return 1;
  2598. }
  2599. // Read the rerun check file and use it to decide whether to do the
  2600. // global generate.
  2601. cmake cm;
  2602. cmGlobalGenerator gg;
  2603. gg.SetCMakeInstance(&cm);
  2604. std::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
  2605. cmMakefile* mf = lg->GetMakefile();
  2606. if(!mf->ReadListFile(0, this->CheckBuildSystemArgument.c_str()) ||
  2607. cmSystemTools::GetErrorOccuredFlag())
  2608. {
  2609. if(verbose)
  2610. {
  2611. cmOStringStream msg;
  2612. msg << "Re-run cmake error reading : "
  2613. << this->CheckBuildSystemArgument.c_str() << "\n";
  2614. cmSystemTools::Stdout(msg.str().c_str());
  2615. }
  2616. // There was an error reading the file. Just rerun.
  2617. return 1;
  2618. }
  2619. if(this->ClearBuildSystem)
  2620. {
  2621. // Get the generator used for this build system.
  2622. const char* genName = mf->GetDefinition("CMAKE_DEPENDS_GENERATOR");
  2623. if(!genName || genName[0] == '\0')
  2624. {
  2625. genName = "Unix Makefiles";
  2626. }
  2627. // Create the generator and use it to clear the dependencies.
  2628. std::auto_ptr<cmGlobalGenerator>
  2629. ggd(this->CreateGlobalGenerator(genName));
  2630. if(ggd.get())
  2631. {
  2632. std::auto_ptr<cmLocalGenerator> lgd(ggd->CreateLocalGenerator());
  2633. lgd->ClearDependencies(mf, verbose);
  2634. }
  2635. }
  2636. // If any byproduct of makefile generation is missing we must re-run.
  2637. std::vector<std::string> products;
  2638. if(const char* productStr = mf->GetDefinition("CMAKE_MAKEFILE_PRODUCTS"))
  2639. {
  2640. cmSystemTools::ExpandListArgument(productStr, products);
  2641. }
  2642. for(std::vector<std::string>::const_iterator pi = products.begin();
  2643. pi != products.end(); ++pi)
  2644. {
  2645. if(!(cmSystemTools::FileExists(pi->c_str()) ||
  2646. cmSystemTools::FileIsSymlink(pi->c_str())))
  2647. {
  2648. if(verbose)
  2649. {
  2650. cmOStringStream msg;
  2651. msg << "Re-run cmake, missing byproduct: " << *pi << "\n";
  2652. cmSystemTools::Stdout(msg.str().c_str());
  2653. }
  2654. return 1;
  2655. }
  2656. }
  2657. // Get the set of dependencies and outputs.
  2658. std::vector<std::string> depends;
  2659. std::vector<std::string> outputs;
  2660. const char* dependsStr = mf->GetDefinition("CMAKE_MAKEFILE_DEPENDS");
  2661. const char* outputsStr = mf->GetDefinition("CMAKE_MAKEFILE_OUTPUTS");
  2662. if(dependsStr && outputsStr)
  2663. {
  2664. cmSystemTools::ExpandListArgument(dependsStr, depends);
  2665. cmSystemTools::ExpandListArgument(outputsStr, outputs);
  2666. }
  2667. if(depends.empty() || outputs.empty())
  2668. {
  2669. // Not enough information was provided to do the test. Just rerun.
  2670. if(verbose)
  2671. {
  2672. cmOStringStream msg;
  2673. msg << "Re-run cmake no CMAKE_MAKEFILE_DEPENDS "
  2674. "or CMAKE_MAKEFILE_OUTPUTS :\n";
  2675. cmSystemTools::Stdout(msg.str().c_str());
  2676. }
  2677. return 1;
  2678. }
  2679. // Find the newest dependency.
  2680. std::vector<std::string>::iterator dep = depends.begin();
  2681. std::string dep_newest = *dep++;
  2682. for(;dep != depends.end(); ++dep)
  2683. {
  2684. int result = 0;
  2685. if(this->FileComparison->FileTimeCompare(dep_newest.c_str(),
  2686. dep->c_str(), &result))
  2687. {
  2688. if(result < 0)
  2689. {
  2690. dep_newest = *dep;
  2691. }
  2692. }
  2693. else
  2694. {
  2695. if(verbose)
  2696. {
  2697. cmOStringStream msg;
  2698. msg << "Re-run cmake: build system dependency is missing\n";
  2699. cmSystemTools::Stdout(msg.str().c_str());
  2700. }
  2701. return 1;
  2702. }
  2703. }
  2704. // Find the oldest output.
  2705. std::vector<std::string>::iterator out = outputs.begin();
  2706. std::string out_oldest = *out++;
  2707. for(;out != outputs.end(); ++out)
  2708. {
  2709. int result = 0;
  2710. if(this->FileComparison->FileTimeCompare(out_oldest.c_str(),
  2711. out->c_str(), &result))
  2712. {
  2713. if(result > 0)
  2714. {
  2715. out_oldest = *out;
  2716. }
  2717. }
  2718. else
  2719. {
  2720. if(verbose)
  2721. {
  2722. cmOStringStream msg;
  2723. msg << "Re-run cmake: build system output is missing\n";
  2724. cmSystemTools::Stdout(msg.str().c_str());
  2725. }
  2726. return 1;
  2727. }
  2728. }
  2729. // If any output is older than any dependency then rerun.
  2730. {
  2731. int result = 0;
  2732. if(!this->FileComparison->FileTimeCompare(out_oldest.c_str(),
  2733. dep_newest.c_str(),
  2734. &result) ||
  2735. result < 0)
  2736. {
  2737. if(verbose)
  2738. {
  2739. cmOStringStream msg;
  2740. msg << "Re-run cmake file: " << out_oldest.c_str()
  2741. << " older than: " << dep_newest.c_str() << "\n";
  2742. cmSystemTools::Stdout(msg.str().c_str());
  2743. }
  2744. return 1;
  2745. }
  2746. }
  2747. // No need to rerun.
  2748. return 0;
  2749. }
  2750. //----------------------------------------------------------------------------
  2751. void cmake::TruncateOutputLog(const char* fname)
  2752. {
  2753. std::string fullPath = this->GetHomeOutputDirectory();
  2754. fullPath += "/";
  2755. fullPath += fname;
  2756. struct stat st;
  2757. if ( ::stat(fullPath.c_str(), &st) )
  2758. {
  2759. return;
  2760. }
  2761. if ( !this->CacheManager->GetCacheValue("CMAKE_CACHEFILE_DIR") )
  2762. {
  2763. cmSystemTools::RemoveFile(fullPath.c_str());
  2764. return;
  2765. }
  2766. off_t fsize = st.st_size;
  2767. const off_t maxFileSize = 50 * 1024;
  2768. if ( fsize < maxFileSize )
  2769. {
  2770. //TODO: truncate file
  2771. return;
  2772. }
  2773. }
  2774. inline std::string removeQuotes(const std::string& s)
  2775. {
  2776. if(s[0] == '\"' && s[s.size()-1] == '\"')
  2777. {
  2778. return s.substr(1, s.size()-2);
  2779. }
  2780. return s;
  2781. }
  2782. std::string cmake::FindCMakeProgram(const char* name) const
  2783. {
  2784. std::string path;
  2785. if ((name) && (*name))
  2786. {
  2787. const cmMakefile* mf
  2788. = this->GetGlobalGenerator()->GetLocalGenerators()[0]->GetMakefile();
  2789. #ifdef CMAKE_BUILD_WITH_CMAKE
  2790. path = mf->GetRequiredDefinition("CMAKE_COMMAND");
  2791. path = removeQuotes(path);
  2792. path = cmSystemTools::GetFilenamePath(path.c_str());
  2793. path += "/";
  2794. path += name;
  2795. path += cmSystemTools::GetExecutableExtension();
  2796. if(!cmSystemTools::FileExists(path.c_str()))
  2797. {
  2798. path = mf->GetRequiredDefinition("CMAKE_COMMAND");
  2799. path = cmSystemTools::GetFilenamePath(path.c_str());
  2800. path += "/Debug/";
  2801. path += name;
  2802. path += cmSystemTools::GetExecutableExtension();
  2803. }
  2804. if(!cmSystemTools::FileExists(path.c_str()))
  2805. {
  2806. path = mf->GetRequiredDefinition("CMAKE_COMMAND");
  2807. path = cmSystemTools::GetFilenamePath(path.c_str());
  2808. path += "/Release/";
  2809. path += name;
  2810. path += cmSystemTools::GetExecutableExtension();
  2811. }
  2812. #else
  2813. // Only for bootstrap
  2814. path += mf->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
  2815. path += "/";
  2816. path += name;
  2817. path += cmSystemTools::GetExecutableExtension();
  2818. #endif
  2819. }
  2820. return path;
  2821. }
  2822. const char* cmake::GetCTestCommand()
  2823. {
  2824. if ( this->CTestCommand.empty() )
  2825. {
  2826. this->CTestCommand = this->FindCMakeProgram("ctest");
  2827. }
  2828. if ( this->CTestCommand.empty() )
  2829. {
  2830. cmSystemTools::Error("Cannot find the CTest executable");
  2831. this->CTestCommand = "CTEST-COMMAND-NOT-FOUND";
  2832. }
  2833. return this->CTestCommand.c_str();
  2834. }
  2835. const char* cmake::GetCPackCommand()
  2836. {
  2837. if ( this->CPackCommand.empty() )
  2838. {
  2839. this->CPackCommand = this->FindCMakeProgram("cpack");
  2840. }
  2841. if ( this->CPackCommand.empty() )
  2842. {
  2843. cmSystemTools::Error("Cannot find the CPack executable");
  2844. this->CPackCommand = "CPACK-COMMAND-NOT-FOUND";
  2845. }
  2846. return this->CPackCommand.c_str();
  2847. }
  2848. const char* cmake::GetCMakeCommand()
  2849. {
  2850. return this->CMakeCommand.c_str();
  2851. }
  2852. void cmake::MarkCliAsUsed(const std::string& variable)
  2853. {
  2854. this->UsedCliVariables[variable] = true;
  2855. }
  2856. void cmake::GenerateGraphViz(const char* fileName) const
  2857. {
  2858. #ifdef CMAKE_BUILD_WITH_CMAKE
  2859. std::auto_ptr<cmGraphVizWriter> gvWriter(
  2860. new cmGraphVizWriter(this->GetGlobalGenerator()->GetLocalGenerators()));
  2861. std::string settingsFile = this->GetHomeOutputDirectory();
  2862. settingsFile += "/CMakeGraphVizOptions.cmake";
  2863. std::string fallbackSettingsFile = this->GetHomeDirectory();
  2864. fallbackSettingsFile += "/CMakeGraphVizOptions.cmake";
  2865. gvWriter->ReadSettings(settingsFile.c_str(), fallbackSettingsFile.c_str());
  2866. gvWriter->WritePerTargetFiles(fileName);
  2867. gvWriter->WriteTargetDependersFiles(fileName);
  2868. gvWriter->WriteGlobalFile(fileName);
  2869. #endif
  2870. }
  2871. //----------------------------------------------------------------------------
  2872. int cmake::SymlinkLibrary(std::vector<std::string>& args)
  2873. {
  2874. int result = 0;
  2875. std::string realName = args[2];
  2876. std::string soName = args[3];
  2877. std::string name = args[4];
  2878. if(soName != realName)
  2879. {
  2880. if(!cmake::SymlinkInternal(realName, soName))
  2881. {
  2882. cmSystemTools::ReportLastSystemError("cmake_symlink_library");
  2883. result = 1;
  2884. }
  2885. }
  2886. if(name != soName)
  2887. {
  2888. if(!cmake::SymlinkInternal(soName, name))
  2889. {
  2890. cmSystemTools::ReportLastSystemError("cmake_symlink_library");
  2891. result = 1;
  2892. }
  2893. }
  2894. return result;
  2895. }
  2896. //----------------------------------------------------------------------------
  2897. int cmake::SymlinkExecutable(std::vector<std::string>& args)
  2898. {
  2899. int result = 0;
  2900. std::string realName = args[2];
  2901. std::string name = args[3];
  2902. if(name != realName)
  2903. {
  2904. if(!cmake::SymlinkInternal(realName, name))
  2905. {
  2906. cmSystemTools::ReportLastSystemError("cmake_symlink_executable");
  2907. result = 1;
  2908. }
  2909. }
  2910. return result;
  2911. }
  2912. //----------------------------------------------------------------------------
  2913. bool cmake::SymlinkInternal(std::string const& file, std::string const& link)
  2914. {
  2915. if(cmSystemTools::FileExists(link.c_str()) ||
  2916. cmSystemTools::FileIsSymlink(link.c_str()))
  2917. {
  2918. cmSystemTools::RemoveFile(link.c_str());
  2919. }
  2920. #if defined(_WIN32) && !defined(__CYGWIN__)
  2921. return cmSystemTools::CopyFileAlways(file.c_str(), link.c_str());
  2922. #else
  2923. std::string linktext = cmSystemTools::GetFilenameName(file);
  2924. return cmSystemTools::CreateSymlink(linktext.c_str(), link.c_str());
  2925. #endif
  2926. }
  2927. //----------------------------------------------------------------------------
  2928. #ifdef CMAKE_BUILD_WITH_CMAKE
  2929. int cmake::ExecuteEchoColor(std::vector<std::string>& args)
  2930. {
  2931. // The arguments are
  2932. // argv[0] == <cmake-executable>
  2933. // argv[1] == cmake_echo_color
  2934. bool enabled = true;
  2935. int color = cmsysTerminal_Color_Normal;
  2936. bool newline = true;
  2937. for(unsigned int i=2; i < args.size(); ++i)
  2938. {
  2939. if(args[i].find("--switch=") == 0)
  2940. {
  2941. // Enable or disable color based on the switch value.
  2942. std::string value = args[i].substr(9);
  2943. if(!value.empty())
  2944. {
  2945. if(cmSystemTools::IsOn(value.c_str()))
  2946. {
  2947. enabled = true;
  2948. }
  2949. else
  2950. {
  2951. enabled = false;
  2952. }
  2953. }
  2954. }
  2955. else if(args[i] == "--normal")
  2956. {
  2957. color = cmsysTerminal_Color_Normal;
  2958. }
  2959. else if(args[i] == "--black")
  2960. {
  2961. color = cmsysTerminal_Color_ForegroundBlack;
  2962. }
  2963. else if(args[i] == "--red")
  2964. {
  2965. color = cmsysTerminal_Color_ForegroundRed;
  2966. }
  2967. else if(args[i] == "--green")
  2968. {
  2969. color = cmsysTerminal_Color_ForegroundGreen;
  2970. }
  2971. else if(args[i] == "--yellow")
  2972. {
  2973. color = cmsysTerminal_Color_ForegroundYellow;
  2974. }
  2975. else if(args[i] == "--blue")
  2976. {
  2977. color = cmsysTerminal_Color_ForegroundBlue;
  2978. }
  2979. else if(args[i] == "--magenta")
  2980. {
  2981. color = cmsysTerminal_Color_ForegroundMagenta;
  2982. }
  2983. else if(args[i] == "--cyan")
  2984. {
  2985. color = cmsysTerminal_Color_ForegroundCyan;
  2986. }
  2987. else if(args[i] == "--white")
  2988. {
  2989. color = cmsysTerminal_Color_ForegroundWhite;
  2990. }
  2991. else if(args[i] == "--bold")
  2992. {
  2993. color |= cmsysTerminal_Color_ForegroundBold;
  2994. }
  2995. else if(args[i] == "--no-newline")
  2996. {
  2997. newline = false;
  2998. }
  2999. else if(args[i] == "--newline")
  3000. {
  3001. newline = true;
  3002. }
  3003. else
  3004. {
  3005. // Color is enabled. Print with the current color.
  3006. cmSystemTools::MakefileColorEcho(color, args[i].c_str(),
  3007. newline, enabled);
  3008. }
  3009. }
  3010. return 0;
  3011. }
  3012. #else
  3013. int cmake::ExecuteEchoColor(std::vector<std::string>&)
  3014. {
  3015. return 1;
  3016. }
  3017. #endif
  3018. //----------------------------------------------------------------------------
  3019. int cmake::ExecuteLinkScript(std::vector<std::string>& args)
  3020. {
  3021. // The arguments are
  3022. // argv[0] == <cmake-executable>
  3023. // argv[1] == cmake_link_script
  3024. // argv[2] == <link-script-name>
  3025. // argv[3] == --verbose=?
  3026. bool verbose = false;
  3027. if(args.size() >= 4)
  3028. {
  3029. if(args[3].find("--verbose=") == 0)
  3030. {
  3031. if(!cmSystemTools::IsOff(args[3].substr(10).c_str()))
  3032. {
  3033. verbose = true;
  3034. }
  3035. }
  3036. }
  3037. // Allocate a process instance.
  3038. cmsysProcess* cp = cmsysProcess_New();
  3039. if(!cp)
  3040. {
  3041. std::cerr << "Error allocating process instance in link script."
  3042. << std::endl;
  3043. return 1;
  3044. }
  3045. // Children should share stdout and stderr with this process.
  3046. cmsysProcess_SetPipeShared(cp, cmsysProcess_Pipe_STDOUT, 1);
  3047. cmsysProcess_SetPipeShared(cp, cmsysProcess_Pipe_STDERR, 1);
  3048. // Run the command lines verbatim.
  3049. cmsysProcess_SetOption(cp, cmsysProcess_Option_Verbatim, 1);
  3050. // Read command lines from the script.
  3051. std::ifstream fin(args[2].c_str());
  3052. if(!fin)
  3053. {
  3054. std::cerr << "Error opening link script \""
  3055. << args[2] << "\"" << std::endl;
  3056. return 1;
  3057. }
  3058. // Run one command at a time.
  3059. std::string command;
  3060. int result = 0;
  3061. while(result == 0 && cmSystemTools::GetLineFromStream(fin, command))
  3062. {
  3063. // Setup this command line.
  3064. const char* cmd[2] = {command.c_str(), 0};
  3065. cmsysProcess_SetCommand(cp, cmd);
  3066. // Report the command if verbose output is enabled.
  3067. if(verbose)
  3068. {
  3069. std::cout << command << std::endl;
  3070. }
  3071. // Run the command and wait for it to exit.
  3072. cmsysProcess_Execute(cp);
  3073. cmsysProcess_WaitForExit(cp, 0);
  3074. // Report failure if any.
  3075. switch(cmsysProcess_GetState(cp))
  3076. {
  3077. case cmsysProcess_State_Exited:
  3078. {
  3079. int value = cmsysProcess_GetExitValue(cp);
  3080. if(value != 0)
  3081. {
  3082. result = value;
  3083. }
  3084. }
  3085. break;
  3086. case cmsysProcess_State_Exception:
  3087. std::cerr << "Error running link command: "
  3088. << cmsysProcess_GetExceptionString(cp) << std::endl;
  3089. result = 1;
  3090. break;
  3091. case cmsysProcess_State_Error:
  3092. std::cerr << "Error running link command: "
  3093. << cmsysProcess_GetErrorString(cp) << std::endl;
  3094. result = 2;
  3095. break;
  3096. default:
  3097. break;
  3098. };
  3099. }
  3100. // Free the process instance.
  3101. cmsysProcess_Delete(cp);
  3102. // Return the final resulting return value.
  3103. return result;
  3104. }
  3105. void cmake::DefineProperties(cmake *cm)
  3106. {
  3107. cm->DefineProperty
  3108. ("REPORT_UNDEFINED_PROPERTIES", cmProperty::GLOBAL,
  3109. "If set, report any undefined properties to this file.",
  3110. "If this property is set to a filename then when CMake runs "
  3111. "it will report any properties or variables that were accessed "
  3112. "but not defined into the filename specified in this property."
  3113. );
  3114. cm->DefineProperty
  3115. ("TARGET_SUPPORTS_SHARED_LIBS", cmProperty::GLOBAL,
  3116. "Does the target platform support shared libraries.",
  3117. "TARGET_SUPPORTS_SHARED_LIBS is a boolean specifying whether the target "
  3118. "platform supports shared libraries. Basically all current general "
  3119. "general purpose OS do so, the exception are usually embedded systems "
  3120. "with no or special OSs.");
  3121. cm->DefineProperty
  3122. ("TARGET_ARCHIVES_MAY_BE_SHARED_LIBS", cmProperty::GLOBAL,
  3123. "Set if shared libraries may be named like archives.",
  3124. "On AIX shared libraries may be named \"lib<name>.a\". "
  3125. "This property is set to true on such platforms.");
  3126. cm->DefineProperty
  3127. ("FIND_LIBRARY_USE_LIB64_PATHS", cmProperty::GLOBAL,
  3128. "Whether FIND_LIBRARY should automatically search lib64 directories.",
  3129. "FIND_LIBRARY_USE_LIB64_PATHS is a boolean specifying whether the "
  3130. "FIND_LIBRARY command should automatically search the lib64 variant of "
  3131. "directories called lib in the search path when building 64-bit "
  3132. "binaries.");
  3133. cm->DefineProperty
  3134. ("FIND_LIBRARY_USE_OPENBSD_VERSIONING", cmProperty::GLOBAL,
  3135. "Whether FIND_LIBRARY should find OpenBSD-style shared libraries.",
  3136. "This property is a boolean specifying whether the FIND_LIBRARY "
  3137. "command should find shared libraries with OpenBSD-style versioned "
  3138. "extension: \".so.<major>.<minor>\". "
  3139. "The property is set to true on OpenBSD and false on other platforms.");
  3140. cm->DefineProperty
  3141. ("ENABLED_FEATURES", cmProperty::GLOBAL,
  3142. "List of features which are enabled during the CMake run.",
  3143. "List of features which are enabled during the CMake run. By default "
  3144. "it contains the names of all packages which were found. This is "
  3145. "determined using the <NAME>_FOUND variables. Packages which are "
  3146. "searched QUIET are not listed. A project can add its own features to "
  3147. "this list. "
  3148. "This property is used by the macros in FeatureSummary.cmake.");
  3149. cm->DefineProperty
  3150. ("DISABLED_FEATURES", cmProperty::GLOBAL,
  3151. "List of features which are disabled during the CMake run.",
  3152. "List of features which are disabled during the CMake run. By default "
  3153. "it contains the names of all packages which were not found. This is "
  3154. "determined using the <NAME>_FOUND variables. Packages which are "
  3155. "searched QUIET are not listed. A project can add its own features to "
  3156. "this list. "
  3157. "This property is used by the macros in FeatureSummary.cmake.");
  3158. cm->DefineProperty
  3159. ("PACKAGES_FOUND", cmProperty::GLOBAL,
  3160. "List of packages which were found during the CMake run.",
  3161. "List of packages which were found during the CMake run. Whether a "
  3162. "package has been found is determined using the <NAME>_FOUND variables.");
  3163. cm->DefineProperty
  3164. ("PACKAGES_NOT_FOUND", cmProperty::GLOBAL,
  3165. "List of packages which were not found during the CMake run.",
  3166. "List of packages which were not found during the CMake run. Whether a "
  3167. "package has been found is determined using the <NAME>_FOUND variables.");
  3168. cm->DefineProperty(
  3169. "__CMAKE_DELETE_CACHE_CHANGE_VARS_", cmProperty::GLOBAL,
  3170. "Internal property",
  3171. "Used to detect compiler changes, Do not set.");
  3172. cm->DefineProperty(
  3173. "DEBUG_CONFIGURATIONS", cmProperty::GLOBAL,
  3174. "Specify which configurations are for debugging.",
  3175. "The value must be a semi-colon separated list of configuration names. "
  3176. "Currently this property is used only by the target_link_libraries "
  3177. "command (see its documentation for details). "
  3178. "Additional uses may be defined in the future. "
  3179. "\n"
  3180. "This property must be set at the top level of the project and before "
  3181. "the first target_link_libraries command invocation. "
  3182. "If any entry in the list does not match a valid configuration for "
  3183. "the project the behavior is undefined.");
  3184. cm->DefineProperty(
  3185. "GLOBAL_DEPENDS_DEBUG_MODE", cmProperty::GLOBAL,
  3186. "Enable global target dependency graph debug mode.",
  3187. "CMake automatically analyzes the global inter-target dependency graph "
  3188. "at the beginning of native build system generation. "
  3189. "This property causes it to display details of its analysis to stderr.");
  3190. cm->DefineProperty(
  3191. "GLOBAL_DEPENDS_NO_CYCLES", cmProperty::GLOBAL,
  3192. "Disallow global target dependency graph cycles.",
  3193. "CMake automatically analyzes the global inter-target dependency graph "
  3194. "at the beginning of native build system generation. "
  3195. "It reports an error if the dependency graph contains a cycle that "
  3196. "does not consist of all STATIC library targets. "
  3197. "This property tells CMake to disallow all cycles completely, even "
  3198. "among static libraries.");
  3199. cm->DefineProperty(
  3200. "ALLOW_DUPLICATE_CUSTOM_TARGETS", cmProperty::GLOBAL,
  3201. "Allow duplicate custom targets to be created.",
  3202. "Normally CMake requires that all targets built in a project have "
  3203. "globally unique logical names (see policy CMP0002). "
  3204. "This is necessary to generate meaningful project file names in "
  3205. "Xcode and VS IDE generators. "
  3206. "It also allows the target names to be referenced unambiguously.\n"
  3207. "Makefile generators are capable of supporting duplicate custom target "
  3208. "names. "
  3209. "For projects that care only about Makefile generators and do "
  3210. "not wish to support Xcode or VS IDE generators, one may set this "
  3211. "property to true to allow duplicate custom targets. "
  3212. "The property allows multiple add_custom_target command calls in "
  3213. "different directories to specify the same target name. "
  3214. "However, setting this property will cause non-Makefile generators "
  3215. "to produce an error and refuse to generate the project."
  3216. );
  3217. cm->DefineProperty
  3218. ("IN_TRY_COMPILE", cmProperty::GLOBAL,
  3219. "Read-only property that is true during a try-compile configuration.",
  3220. "True when building a project inside a TRY_COMPILE or TRY_RUN command.");
  3221. cm->DefineProperty
  3222. ("ENABLED_LANGUAGES", cmProperty::GLOBAL,
  3223. "Read-only property that contains the list of currently "
  3224. "enabled languages",
  3225. "Set to list of currently enabled languages.");
  3226. cm->DefineProperty
  3227. ("RULE_LAUNCH_COMPILE", cmProperty::GLOBAL,
  3228. "Specify a launcher for compile rules.",
  3229. "Makefile generators prefix compiler commands with the given "
  3230. "launcher command line. "
  3231. "This is intended to allow launchers to intercept build problems "
  3232. "with high granularity. "
  3233. "Non-Makefile generators currently ignore this property.");
  3234. cm->DefineProperty
  3235. ("RULE_LAUNCH_LINK", cmProperty::GLOBAL,
  3236. "Specify a launcher for link rules.",
  3237. "Makefile generators prefix link and archive commands with the given "
  3238. "launcher command line. "
  3239. "This is intended to allow launchers to intercept build problems "
  3240. "with high granularity. "
  3241. "Non-Makefile generators currently ignore this property.");
  3242. cm->DefineProperty
  3243. ("RULE_LAUNCH_CUSTOM", cmProperty::GLOBAL,
  3244. "Specify a launcher for custom rules.",
  3245. "Makefile generators prefix custom commands with the given "
  3246. "launcher command line. "
  3247. "This is intended to allow launchers to intercept build problems "
  3248. "with high granularity. "
  3249. "Non-Makefile generators currently ignore this property.");
  3250. cm->DefineProperty
  3251. ("RULE_MESSAGES", cmProperty::GLOBAL,
  3252. "Specify whether to report a message for each make rule.",
  3253. "This property specifies whether Makefile generators should add a "
  3254. "progress message describing what each build rule does. "
  3255. "If the property is not set the default is ON. "
  3256. "Set the property to OFF to disable granular messages and report only "
  3257. "as each target completes. "
  3258. "This is intended to allow scripted builds to avoid the build time "
  3259. "cost of detailed reports. "
  3260. "If a CMAKE_RULE_MESSAGES cache entry exists its value initializes "
  3261. "the value of this property. "
  3262. "Non-Makefile generators currently ignore this property.");
  3263. cm->DefineProperty
  3264. ("USE_FOLDERS", cmProperty::GLOBAL,
  3265. "Use the FOLDER target property to organize targets into folders.",
  3266. "If not set, CMake treats this property as OFF by default. "
  3267. "CMake generators that are capable of organizing into a "
  3268. "hierarchy of folders use the values of the FOLDER target "
  3269. "property to name those folders. See also the documentation "
  3270. "for the FOLDER target property.");
  3271. cm->DefineProperty
  3272. ("PREDEFINED_TARGETS_FOLDER", cmProperty::GLOBAL,
  3273. "Name of FOLDER for targets that are added automatically by CMake.",
  3274. "If not set, CMake uses \"CMakePredefinedTargets\" as a default "
  3275. "value for this property. Targets such as INSTALL, PACKAGE and "
  3276. "RUN_TESTS will be organized into this FOLDER. See also the "
  3277. "documentation for the FOLDER target property.");
  3278. // ================================================================
  3279. // define variables as well
  3280. // ================================================================
  3281. cmDocumentVariables::DefineVariables(cm);
  3282. }
  3283. void cmake::DefineProperty(const char *name, cmProperty::ScopeType scope,
  3284. const char *ShortDescription,
  3285. const char *FullDescription,
  3286. bool chained, const char *docSection)
  3287. {
  3288. this->PropertyDefinitions[scope].DefineProperty(name,scope,ShortDescription,
  3289. FullDescription,
  3290. docSection,
  3291. chained);
  3292. }
  3293. cmPropertyDefinition *cmake
  3294. ::GetPropertyDefinition(const char *name,
  3295. cmProperty::ScopeType scope)
  3296. {
  3297. if (this->IsPropertyDefined(name,scope))
  3298. {
  3299. return &(this->PropertyDefinitions[scope][name]);
  3300. }
  3301. return 0;
  3302. }
  3303. void cmake::RecordPropertyAccess(const char *name,
  3304. cmProperty::ScopeType scope)
  3305. {
  3306. this->AccessedProperties.insert
  3307. (std::pair<cmStdString,cmProperty::ScopeType>(name,scope));
  3308. }
  3309. void cmake::ReportUndefinedPropertyAccesses(const char *filename)
  3310. {
  3311. FILE *progFile = fopen(filename,"w");
  3312. if (!progFile || !this->GlobalGenerator)
  3313. {
  3314. return;
  3315. }
  3316. // what are the enabled languages?
  3317. std::vector<std::string> enLangs;
  3318. this->GlobalGenerator->GetEnabledLanguages(enLangs);
  3319. // Common configuration names.
  3320. // TODO: Compute current configuration(s).
  3321. std::vector<std::string> enConfigs;
  3322. enConfigs.push_back("");
  3323. enConfigs.push_back("DEBUG");
  3324. enConfigs.push_back("RELEASE");
  3325. enConfigs.push_back("MINSIZEREL");
  3326. enConfigs.push_back("RELWITHDEBINFO");
  3327. // take all the defined properties and add definitions for all the enabled
  3328. // languages
  3329. std::set<std::pair<cmStdString,cmProperty::ScopeType> > aliasedProperties;
  3330. std::map<cmProperty::ScopeType, cmPropertyDefinitionMap>::iterator i;
  3331. i = this->PropertyDefinitions.begin();
  3332. for (;i != this->PropertyDefinitions.end(); ++i)
  3333. {
  3334. cmPropertyDefinitionMap::iterator j;
  3335. for (j = i->second.begin(); j != i->second.end(); ++j)
  3336. {
  3337. // TODO: What if both <LANG> and <CONFIG> appear?
  3338. if (j->first.find("<CONFIG>") != std::string::npos)
  3339. {
  3340. std::vector<std::string>::const_iterator k;
  3341. for (k = enConfigs.begin(); k != enConfigs.end(); ++k)
  3342. {
  3343. std::string tmp = j->first;
  3344. cmSystemTools::ReplaceString(tmp, "<CONFIG>", k->c_str());
  3345. // add alias
  3346. aliasedProperties.insert
  3347. (std::pair<cmStdString,cmProperty::ScopeType>(tmp,i->first));
  3348. }
  3349. }
  3350. if (j->first.find("<LANG>") != std::string::npos)
  3351. {
  3352. std::vector<std::string>::const_iterator k;
  3353. for (k = enLangs.begin(); k != enLangs.end(); ++k)
  3354. {
  3355. std::string tmp = j->first;
  3356. cmSystemTools::ReplaceString(tmp, "<LANG>", k->c_str());
  3357. // add alias
  3358. aliasedProperties.insert
  3359. (std::pair<cmStdString,cmProperty::ScopeType>(tmp,i->first));
  3360. }
  3361. }
  3362. }
  3363. }
  3364. std::set<std::pair<cmStdString,cmProperty::ScopeType> >::const_iterator ap;
  3365. ap = this->AccessedProperties.begin();
  3366. for (;ap != this->AccessedProperties.end(); ++ap)
  3367. {
  3368. if (!this->IsPropertyDefined(ap->first.c_str(),ap->second) &&
  3369. aliasedProperties.find(std::pair<cmStdString,cmProperty::ScopeType>
  3370. (ap->first,ap->second)) ==
  3371. aliasedProperties.end())
  3372. {
  3373. const char *scopeStr = "";
  3374. switch (ap->second)
  3375. {
  3376. case cmProperty::TARGET:
  3377. scopeStr = "TARGET";
  3378. break;
  3379. case cmProperty::SOURCE_FILE:
  3380. scopeStr = "SOURCE_FILE";
  3381. break;
  3382. case cmProperty::DIRECTORY:
  3383. scopeStr = "DIRECTORY";
  3384. break;
  3385. case cmProperty::TEST:
  3386. scopeStr = "TEST";
  3387. break;
  3388. case cmProperty::VARIABLE:
  3389. scopeStr = "VARIABLE";
  3390. break;
  3391. case cmProperty::CACHED_VARIABLE:
  3392. scopeStr = "CACHED_VARIABLE";
  3393. break;
  3394. default:
  3395. scopeStr = "unknown";
  3396. break;
  3397. }
  3398. fprintf(progFile, "%s with scope %s\n", ap->first.c_str(), scopeStr);
  3399. }
  3400. }
  3401. fclose(progFile);
  3402. }
  3403. bool cmake::IsPropertyDefined(const char *name, cmProperty::ScopeType scope)
  3404. {
  3405. return this->PropertyDefinitions[scope].IsPropertyDefined(name);
  3406. }
  3407. bool cmake::IsPropertyChained(const char *name, cmProperty::ScopeType scope)
  3408. {
  3409. return this->PropertyDefinitions[scope].IsPropertyChained(name);
  3410. }
  3411. void cmake::SetProperty(const char* prop, const char* value)
  3412. {
  3413. if (!prop)
  3414. {
  3415. return;
  3416. }
  3417. // Special hook to invalidate cached value.
  3418. if(strcmp(prop, "DEBUG_CONFIGURATIONS") == 0)
  3419. {
  3420. this->DebugConfigs.clear();
  3421. }
  3422. this->Properties.SetProperty(prop, value, cmProperty::GLOBAL);
  3423. }
  3424. void cmake::AppendProperty(const char* prop, const char* value, bool asString)
  3425. {
  3426. if (!prop)
  3427. {
  3428. return;
  3429. }
  3430. // Special hook to invalidate cached value.
  3431. if(strcmp(prop, "DEBUG_CONFIGURATIONS") == 0)
  3432. {
  3433. this->DebugConfigs.clear();
  3434. }
  3435. this->Properties.AppendProperty(prop, value, cmProperty::GLOBAL, asString);
  3436. }
  3437. const char *cmake::GetProperty(const char* prop)
  3438. {
  3439. return this->GetProperty(prop, cmProperty::GLOBAL);
  3440. }
  3441. const char *cmake::GetProperty(const char* prop, cmProperty::ScopeType scope)
  3442. {
  3443. if(!prop)
  3444. {
  3445. return 0;
  3446. }
  3447. bool chain = false;
  3448. // watch for special properties
  3449. std::string propname = prop;
  3450. std::string output = "";
  3451. if ( propname == "CACHE_VARIABLES" )
  3452. {
  3453. cmCacheManager::CacheIterator cit =
  3454. this->GetCacheManager()->GetCacheIterator();
  3455. for ( cit.Begin(); !cit.IsAtEnd(); cit.Next() )
  3456. {
  3457. if ( output.size() )
  3458. {
  3459. output += ";";
  3460. }
  3461. output += cit.GetName();
  3462. }
  3463. this->SetProperty("CACHE_VARIABLES", output.c_str());
  3464. }
  3465. else if ( propname == "COMMANDS" )
  3466. {
  3467. cmake::RegisteredCommandsMap::iterator cmds
  3468. = this->GetCommands()->begin();
  3469. for (unsigned int cc=0 ; cmds != this->GetCommands()->end(); ++ cmds )
  3470. {
  3471. if ( cc > 0 )
  3472. {
  3473. output += ";";
  3474. }
  3475. output += cmds->first.c_str();
  3476. cc++;
  3477. }
  3478. this->SetProperty("COMMANDS",output.c_str());
  3479. }
  3480. else if ( propname == "IN_TRY_COMPILE" )
  3481. {
  3482. this->SetProperty("IN_TRY_COMPILE",
  3483. this->GetIsInTryCompile()? "1":"0");
  3484. }
  3485. else if ( propname == "ENABLED_LANGUAGES" )
  3486. {
  3487. std::string lang;
  3488. if(this->GlobalGenerator)
  3489. {
  3490. std::vector<std::string> enLangs;
  3491. this->GlobalGenerator->GetEnabledLanguages(enLangs);
  3492. const char* sep = "";
  3493. for(std::vector<std::string>::iterator i = enLangs.begin();
  3494. i != enLangs.end(); ++i)
  3495. {
  3496. lang += sep;
  3497. sep = ";";
  3498. lang += *i;
  3499. }
  3500. }
  3501. this->SetProperty("ENABLED_LANGUAGES", lang.c_str());
  3502. }
  3503. return this->Properties.GetPropertyValue(prop, scope, chain);
  3504. }
  3505. bool cmake::GetPropertyAsBool(const char* prop)
  3506. {
  3507. return cmSystemTools::IsOn(this->GetProperty(prop));
  3508. }
  3509. int cmake::GetSystemInformation(std::vector<std::string>& args)
  3510. {
  3511. // so create the directory
  3512. std::string resultFile;
  3513. std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
  3514. std::string destPath = cwd + "/__cmake_systeminformation";
  3515. cmSystemTools::RemoveADirectory(destPath.c_str());
  3516. if (!cmSystemTools::MakeDirectory(destPath.c_str()))
  3517. {
  3518. std::cerr << "Error: --system-information must be run from a "
  3519. "writable directory!\n";
  3520. return 1;
  3521. }
  3522. // process the arguments
  3523. bool writeToStdout = true;
  3524. for(unsigned int i=1; i < args.size(); ++i)
  3525. {
  3526. std::string arg = args[i];
  3527. if(arg.find("-V",0) == 0)
  3528. {
  3529. this->Verbose = true;
  3530. }
  3531. else if(arg.find("-G",0) == 0)
  3532. {
  3533. std::string value = arg.substr(2);
  3534. if(value.size() == 0)
  3535. {
  3536. ++i;
  3537. if(i >= args.size())
  3538. {
  3539. cmSystemTools::Error("No generator specified for -G");
  3540. return -1;
  3541. }
  3542. value = args[i];
  3543. }
  3544. cmGlobalGenerator* gen =
  3545. this->CreateGlobalGenerator(value.c_str());
  3546. if(!gen)
  3547. {
  3548. cmSystemTools::Error("Could not create named generator ",
  3549. value.c_str());
  3550. }
  3551. else
  3552. {
  3553. this->SetGlobalGenerator(gen);
  3554. }
  3555. }
  3556. // no option assume it is the output file
  3557. else
  3558. {
  3559. if (!cmSystemTools::FileIsFullPath(arg.c_str()))
  3560. {
  3561. resultFile = cwd;
  3562. resultFile += "/";
  3563. }
  3564. resultFile += arg;
  3565. writeToStdout = false;
  3566. }
  3567. }
  3568. // we have to find the module directory, so we can copy the files
  3569. this->AddCMakePaths();
  3570. std::string modulesPath =
  3571. this->CacheManager->GetCacheValue("CMAKE_ROOT");
  3572. modulesPath += "/Modules";
  3573. std::string inFile = modulesPath;
  3574. inFile += "/SystemInformation.cmake";
  3575. std::string outFile = destPath;
  3576. outFile += "/CMakeLists.txt";
  3577. // Copy file
  3578. if(!cmSystemTools::cmCopyFile(inFile.c_str(), outFile.c_str()))
  3579. {
  3580. std::cerr << "Error copying file \"" << inFile.c_str()
  3581. << "\" to \"" << outFile.c_str() << "\".\n";
  3582. return 1;
  3583. }
  3584. // do we write to a file or to stdout?
  3585. if (resultFile.size() == 0)
  3586. {
  3587. resultFile = cwd;
  3588. resultFile += "/__cmake_systeminformation/results.txt";
  3589. }
  3590. // now run cmake on the CMakeLists file
  3591. cmSystemTools::ChangeDirectory(destPath.c_str());
  3592. std::vector<std::string> args2;
  3593. args2.push_back(args[0]);
  3594. args2.push_back(destPath);
  3595. std::string resultArg = "-DRESULT_FILE=";
  3596. resultArg += resultFile;
  3597. args2.push_back(resultArg);
  3598. int res = this->Run(args2, false);
  3599. if (res != 0)
  3600. {
  3601. std::cerr << "Error: --system-information failed on internal CMake!\n";
  3602. return res;
  3603. }
  3604. // change back to the original directory
  3605. cmSystemTools::ChangeDirectory(cwd.c_str());
  3606. // echo results to stdout if needed
  3607. if (writeToStdout)
  3608. {
  3609. FILE* fin = fopen(resultFile.c_str(), "r");
  3610. if(fin)
  3611. {
  3612. const int bufferSize = 4096;
  3613. char buffer[bufferSize];
  3614. size_t n;
  3615. while((n = fread(buffer, 1, bufferSize, fin)) > 0)
  3616. {
  3617. for(char* c = buffer; c < buffer+n; ++c)
  3618. {
  3619. putc(*c, stdout);
  3620. }
  3621. fflush(stdout);
  3622. }
  3623. fclose(fin);
  3624. }
  3625. }
  3626. // clean up the directory
  3627. cmSystemTools::RemoveADirectory(destPath.c_str());
  3628. return 0;
  3629. }
  3630. //----------------------------------------------------------------------------
  3631. static bool cmakeCheckStampFile(const char* stampName)
  3632. {
  3633. // The stamp file does not exist. Use the stamp dependencies to
  3634. // determine whether it is really out of date. This works in
  3635. // conjunction with cmLocalVisualStudio7Generator to avoid
  3636. // repeatedly re-running CMake when the user rebuilds the entire
  3637. // solution.
  3638. std::string stampDepends = stampName;
  3639. stampDepends += ".depend";
  3640. #if defined(_WIN32) || defined(__CYGWIN__)
  3641. std::ifstream fin(stampDepends.c_str(), std::ios::in | std::ios::binary);
  3642. #else
  3643. std::ifstream fin(stampDepends.c_str(), std::ios::in);
  3644. #endif
  3645. if(!fin)
  3646. {
  3647. // The stamp dependencies file cannot be read. Just assume the
  3648. // build system is really out of date.
  3649. std::cout << "CMake is re-running because " << stampName
  3650. << " dependency file is missing.\n";
  3651. return false;
  3652. }
  3653. // Compare the stamp dependencies against the dependency file itself.
  3654. cmFileTimeComparison ftc;
  3655. std::string dep;
  3656. while(cmSystemTools::GetLineFromStream(fin, dep))
  3657. {
  3658. int result;
  3659. if(dep.length() >= 1 && dep[0] != '#' &&
  3660. (!ftc.FileTimeCompare(stampDepends.c_str(), dep.c_str(), &result)
  3661. || result < 0))
  3662. {
  3663. // The stamp depends file is older than this dependency. The
  3664. // build system is really out of date.
  3665. std::cout << "CMake is re-running because " << stampName
  3666. << " is out-of-date.\n";
  3667. std::cout << " the file '" << dep << "'\n";
  3668. std::cout << " is newer than '" << stampDepends << "'\n";
  3669. std::cout << " result='" << result << "'\n";
  3670. return false;
  3671. }
  3672. }
  3673. // The build system is up to date. The stamp file has been removed
  3674. // by the VS IDE due to a "rebuild" request. Just restore it.
  3675. std::ofstream stamp(stampName);
  3676. stamp << "# CMake generation timestamp file this directory.\n";
  3677. if(stamp)
  3678. {
  3679. // Notify the user why CMake is not re-running. It is safe to
  3680. // just print to stdout here because this code is only reachable
  3681. // through an undocumented flag used by the VS generator.
  3682. std::cout << "CMake does not need to re-run because "
  3683. << stampName << " is up-to-date.\n";
  3684. return true;
  3685. }
  3686. else
  3687. {
  3688. cmSystemTools::Error("Cannot restore timestamp ", stampName);
  3689. return false;
  3690. }
  3691. }
  3692. //----------------------------------------------------------------------------
  3693. static bool cmakeCheckStampList(const char* stampList)
  3694. {
  3695. // If the stamp list does not exist CMake must rerun to generate it.
  3696. if(!cmSystemTools::FileExists(stampList))
  3697. {
  3698. std::cout << "CMake is re-running because generate.stamp.list "
  3699. << "is missing.\n";
  3700. return false;
  3701. }
  3702. std::ifstream fin(stampList);
  3703. if(!fin)
  3704. {
  3705. std::cout << "CMake is re-running because generate.stamp.list "
  3706. << "could not be read.\n";
  3707. return false;
  3708. }
  3709. // Check each stamp.
  3710. std::string stampName;
  3711. while(cmSystemTools::GetLineFromStream(fin, stampName))
  3712. {
  3713. if(!cmakeCheckStampFile(stampName.c_str()))
  3714. {
  3715. return false;
  3716. }
  3717. }
  3718. return true;
  3719. }
  3720. // For visual studio 2005 and newer manifest files need to be embeded into
  3721. // exe and dll's. This code does that in such a way that incremental linking
  3722. // still works.
  3723. int cmake::VisualStudioLink(std::vector<std::string>& args, int type)
  3724. {
  3725. if(args.size() < 2)
  3726. {
  3727. return -1;
  3728. }
  3729. bool verbose = false;
  3730. if(cmSystemTools::GetEnv("VERBOSE"))
  3731. {
  3732. verbose = true;
  3733. }
  3734. std::vector<std::string> expandedArgs;
  3735. for(std::vector<std::string>::iterator i = args.begin();
  3736. i != args.end(); ++i)
  3737. {
  3738. // check for nmake temporary files
  3739. if((*i)[0] == '@' && i->find("@CMakeFiles") != 0 )
  3740. {
  3741. std::ifstream fin(i->substr(1).c_str());
  3742. std::string line;
  3743. while(cmSystemTools::GetLineFromStream(fin,
  3744. line))
  3745. {
  3746. cmSystemTools::ParseWindowsCommandLine(line.c_str(), expandedArgs);
  3747. }
  3748. }
  3749. else
  3750. {
  3751. expandedArgs.push_back(*i);
  3752. }
  3753. }
  3754. bool hasIncremental = false;
  3755. bool hasManifest = true;
  3756. for(std::vector<std::string>::iterator i = expandedArgs.begin();
  3757. i != expandedArgs.end(); ++i)
  3758. {
  3759. if(cmSystemTools::Strucmp(i->c_str(), "/INCREMENTAL:YES") == 0)
  3760. {
  3761. hasIncremental = true;
  3762. }
  3763. if(cmSystemTools::Strucmp(i->c_str(), "/INCREMENTAL") == 0)
  3764. {
  3765. hasIncremental = true;
  3766. }
  3767. if(cmSystemTools::Strucmp(i->c_str(), "/MANIFEST:NO") == 0)
  3768. {
  3769. hasManifest = false;
  3770. }
  3771. }
  3772. if(hasIncremental && hasManifest)
  3773. {
  3774. if(verbose)
  3775. {
  3776. std::cout << "Visual Studio Incremental Link with embeded manifests\n";
  3777. }
  3778. return cmake::VisualStudioLinkIncremental(expandedArgs, type, verbose);
  3779. }
  3780. if(verbose)
  3781. {
  3782. if(!hasIncremental)
  3783. {
  3784. std::cout << "Visual Studio Non-Incremental Link\n";
  3785. }
  3786. else
  3787. {
  3788. std::cout << "Visual Studio Incremental Link without manifests\n";
  3789. }
  3790. }
  3791. return cmake::VisualStudioLinkNonIncremental(expandedArgs,
  3792. type, hasManifest, verbose);
  3793. }
  3794. int cmake::ParseVisualStudioLinkCommand(std::vector<std::string>& args,
  3795. std::vector<cmStdString>& command,
  3796. std::string& targetName)
  3797. {
  3798. std::vector<std::string>::iterator i = args.begin();
  3799. i++; // skip -E
  3800. i++; // skip vs_link_dll or vs_link_exe
  3801. command.push_back(*i);
  3802. i++; // move past link command
  3803. for(; i != args.end(); ++i)
  3804. {
  3805. command.push_back(*i);
  3806. if(i->find("/Fe") == 0)
  3807. {
  3808. targetName = i->substr(3);
  3809. }
  3810. if(i->find("/out:") == 0)
  3811. {
  3812. targetName = i->substr(5);
  3813. }
  3814. }
  3815. if(targetName.size() == 0 || command.size() == 0)
  3816. {
  3817. return -1;
  3818. }
  3819. return 0;
  3820. }
  3821. bool cmake::RunCommand(const char* comment,
  3822. std::vector<cmStdString>& command,
  3823. bool verbose,
  3824. int* retCodeOut)
  3825. {
  3826. if(verbose)
  3827. {
  3828. std::cout << comment << ":\n";
  3829. for(std::vector<cmStdString>::iterator i = command.begin();
  3830. i != command.end(); ++i)
  3831. {
  3832. std::cout << i->c_str() << " ";
  3833. }
  3834. std::cout << "\n";
  3835. }
  3836. std::string output;
  3837. int retCode =0;
  3838. // use rc command to create .res file
  3839. cmSystemTools::RunSingleCommand(command,
  3840. &output,
  3841. &retCode, 0, cmSystemTools::OUTPUT_NONE);
  3842. // always print the output of the command, unless
  3843. // it is the dumb rc command banner, but if the command
  3844. // returned an error code then print the output anyway as
  3845. // the banner may be mixed with some other important information.
  3846. if(output.find("Resource Compiler Version") == output.npos
  3847. || retCode !=0)
  3848. {
  3849. std::cout << output;
  3850. }
  3851. // if retCodeOut is requested then always return true
  3852. // and set the retCodeOut to retCode
  3853. if(retCodeOut)
  3854. {
  3855. *retCodeOut = retCode;
  3856. return true;
  3857. }
  3858. if(retCode != 0)
  3859. {
  3860. std::cout << comment << " failed. with " << retCode << "\n";
  3861. }
  3862. return retCode == 0;
  3863. }
  3864. int cmake::VisualStudioLinkIncremental(std::vector<std::string>& args,
  3865. int type, bool verbose)
  3866. {
  3867. // This follows the steps listed here:
  3868. // http://blogs.msdn.com/zakramer/archive/2006/05/22/603558.aspx
  3869. // 1. Compiler compiles the application and generates the *.obj files.
  3870. // 2. An empty manifest file is generated if this is a clean build and if
  3871. // not the previous one is reused.
  3872. // 3. The resource compiler (rc.exe) compiles the *.manifest file to a
  3873. // *.res file.
  3874. // 4. Linker generates the binary (EXE or DLL) with the /incremental
  3875. // switch and embeds the dummy manifest file. The linker also generates
  3876. // the real manifest file based on the binaries that your binary depends
  3877. // on.
  3878. // 5. The manifest tool (mt.exe) is then used to generate the final
  3879. // manifest.
  3880. // If the final manifest is changed, then 6 and 7 are run, if not
  3881. // they are skipped, and it is done.
  3882. // 6. The resource compiler is invoked one more time.
  3883. // 7. Finally, the Linker does another incremental link, but since the
  3884. // only thing that has changed is the *.res file that contains the
  3885. // manifest it is a short link.
  3886. std::vector<cmStdString> linkCommand;
  3887. std::string targetName;
  3888. if(cmake::ParseVisualStudioLinkCommand(args, linkCommand, targetName) == -1)
  3889. {
  3890. return -1;
  3891. }
  3892. std::string manifestArg = "/MANIFESTFILE:";
  3893. std::vector<cmStdString> rcCommand;
  3894. rcCommand.push_back(cmSystemTools::FindProgram("rc.exe"));
  3895. std::vector<cmStdString> mtCommand;
  3896. mtCommand.push_back(cmSystemTools::FindProgram("mt.exe"));
  3897. std::string tempManifest;
  3898. tempManifest = targetName;
  3899. tempManifest += ".intermediate.manifest";
  3900. std::string resourceInputFile = targetName;
  3901. resourceInputFile += ".resource.txt";
  3902. if(verbose)
  3903. {
  3904. std::cout << "Create " << resourceInputFile.c_str() << "\n";
  3905. }
  3906. // Create input file for rc command
  3907. std::ofstream fout(resourceInputFile.c_str());
  3908. if(!fout)
  3909. {
  3910. return -1;
  3911. }
  3912. std::string manifestFile = targetName;
  3913. manifestFile += ".embed.manifest";
  3914. std::string fullPath= cmSystemTools::CollapseFullPath(manifestFile.c_str());
  3915. fout << type << " /* CREATEPROCESS_MANIFEST_RESOURCE_ID "
  3916. "*/ 24 /* RT_MANIFEST */ " << "\"" << fullPath.c_str() << "\"";
  3917. fout.close();
  3918. manifestArg += tempManifest;
  3919. // add the manifest arg to the linkCommand
  3920. linkCommand.push_back("/MANIFEST");
  3921. linkCommand.push_back(manifestArg);
  3922. // if manifestFile is not yet created, create an
  3923. // empty one
  3924. if(!cmSystemTools::FileExists(manifestFile.c_str()))
  3925. {
  3926. if(verbose)
  3927. {
  3928. std::cout << "Create empty: " << manifestFile.c_str() << "\n";
  3929. }
  3930. std::ofstream foutTmp(manifestFile.c_str());
  3931. }
  3932. std::string resourceFile = manifestFile;
  3933. resourceFile += ".res";
  3934. // add the resource file to the end of the link command
  3935. linkCommand.push_back(resourceFile);
  3936. std::string outputOpt = "/fo";
  3937. outputOpt += resourceFile;
  3938. rcCommand.push_back(outputOpt);
  3939. rcCommand.push_back(resourceInputFile);
  3940. // Run rc command to create resource
  3941. if(!cmake::RunCommand("RC Pass 1", rcCommand, verbose))
  3942. {
  3943. return -1;
  3944. }
  3945. // Now run the link command to link and create manifest
  3946. if(!cmake::RunCommand("LINK Pass 1", linkCommand, verbose))
  3947. {
  3948. return -1;
  3949. }
  3950. // create mt command
  3951. std::string outArg("/out:");
  3952. outArg+= manifestFile;
  3953. mtCommand.push_back("/nologo");
  3954. mtCommand.push_back(outArg);
  3955. mtCommand.push_back("/notify_update");
  3956. mtCommand.push_back("/manifest");
  3957. mtCommand.push_back(tempManifest);
  3958. // now run mt.exe to create the final manifest file
  3959. int mtRet =0;
  3960. cmake::RunCommand("MT", mtCommand, verbose, &mtRet);
  3961. // if mt returns 0, then the manifest was not changed and
  3962. // we do not need to do another link step
  3963. if(mtRet == 0)
  3964. {
  3965. return 0;
  3966. }
  3967. // check for magic mt return value if mt returns the magic number
  3968. // 1090650113 then it means that it updated the manifest file and we need
  3969. // to do the final link. If mt has any value other than 0 or 1090650113
  3970. // then there was some problem with the command itself and there was an
  3971. // error so return the error code back out of cmake so make can report it.
  3972. if(mtRet != 1090650113)
  3973. {
  3974. return mtRet;
  3975. }
  3976. // update the resource file with the new manifest from the mt command.
  3977. if(!cmake::RunCommand("RC Pass 2", rcCommand, verbose))
  3978. {
  3979. return -1;
  3980. }
  3981. // Run the final incremental link that will put the new manifest resource
  3982. // into the file incrementally.
  3983. if(!cmake::RunCommand("FINAL LINK", linkCommand, verbose))
  3984. {
  3985. return -1;
  3986. }
  3987. return 0;
  3988. }
  3989. int cmake::VisualStudioLinkNonIncremental(std::vector<std::string>& args,
  3990. int type,
  3991. bool hasManifest,
  3992. bool verbose)
  3993. {
  3994. std::vector<cmStdString> linkCommand;
  3995. std::string targetName;
  3996. if(cmake::ParseVisualStudioLinkCommand(args, linkCommand, targetName) == -1)
  3997. {
  3998. return -1;
  3999. }
  4000. // Run the link command as given
  4001. if (hasManifest)
  4002. {
  4003. linkCommand.push_back("/MANIFEST");
  4004. }
  4005. if(!cmake::RunCommand("LINK", linkCommand, verbose))
  4006. {
  4007. return -1;
  4008. }
  4009. if(!hasManifest)
  4010. {
  4011. return 0;
  4012. }
  4013. std::vector<cmStdString> mtCommand;
  4014. mtCommand.push_back(cmSystemTools::FindProgram("mt.exe"));
  4015. mtCommand.push_back("/nologo");
  4016. mtCommand.push_back("/manifest");
  4017. std::string manifestFile = targetName;
  4018. manifestFile += ".manifest";
  4019. mtCommand.push_back(manifestFile);
  4020. std::string outresource = "/outputresource:";
  4021. outresource += targetName;
  4022. outresource += ";#";
  4023. if(type == 1)
  4024. {
  4025. outresource += "1";
  4026. }
  4027. else if(type == 2)
  4028. {
  4029. outresource += "2";
  4030. }
  4031. mtCommand.push_back(outresource);
  4032. // Now use the mt tool to embed the manifest into the exe or dll
  4033. if(!cmake::RunCommand("MT", mtCommand, verbose))
  4034. {
  4035. return -1;
  4036. }
  4037. return 0;
  4038. }
  4039. //----------------------------------------------------------------------------
  4040. void cmake::IssueMessage(cmake::MessageType t, std::string const& text,
  4041. cmListFileBacktrace const& backtrace)
  4042. {
  4043. cmOStringStream msg;
  4044. bool isError = false;
  4045. // Construct the message header.
  4046. if(t == cmake::FATAL_ERROR)
  4047. {
  4048. isError = true;
  4049. msg << "CMake Error";
  4050. }
  4051. else if(t == cmake::INTERNAL_ERROR)
  4052. {
  4053. isError = true;
  4054. msg << "CMake Internal Error (please report a bug)";
  4055. }
  4056. else
  4057. {
  4058. msg << "CMake Warning";
  4059. if(t == cmake::AUTHOR_WARNING)
  4060. {
  4061. // Allow suppression of these warnings.
  4062. cmCacheManager::CacheIterator it = this->CacheManager
  4063. ->GetCacheIterator("CMAKE_SUPPRESS_DEVELOPER_WARNINGS");
  4064. if(!it.IsAtEnd() && it.GetValueAsBool())
  4065. {
  4066. return;
  4067. }
  4068. msg << " (dev)";
  4069. }
  4070. }
  4071. // Add the immediate context.
  4072. cmListFileBacktrace::const_iterator i = backtrace.begin();
  4073. if(i != backtrace.end())
  4074. {
  4075. cmListFileContext const& lfc = *i;
  4076. msg << (lfc.Line? " at ": " in ") << lfc;
  4077. ++i;
  4078. }
  4079. // Add the message text.
  4080. {
  4081. msg << ":\n";
  4082. cmDocumentationFormatterText formatter;
  4083. formatter.SetIndent(" ");
  4084. formatter.PrintFormatted(msg, text.c_str());
  4085. }
  4086. // Add the rest of the context.
  4087. if(i != backtrace.end())
  4088. {
  4089. msg << "Call Stack (most recent call first):\n";
  4090. while(i != backtrace.end())
  4091. {
  4092. cmListFileContext const& lfc = *i;
  4093. msg << " " << lfc << "\n";
  4094. ++i;
  4095. }
  4096. }
  4097. // Add a note about warning suppression.
  4098. if(t == cmake::AUTHOR_WARNING)
  4099. {
  4100. msg <<
  4101. "This warning is for project developers. Use -Wno-dev to suppress it.";
  4102. }
  4103. // Add a terminating blank line.
  4104. msg << "\n";
  4105. // Output the message.
  4106. if(isError)
  4107. {
  4108. cmSystemTools::SetErrorOccured();
  4109. cmSystemTools::Message(msg.str().c_str(), "Error");
  4110. }
  4111. else
  4112. {
  4113. cmSystemTools::Message(msg.str().c_str(), "Warning");
  4114. }
  4115. }
  4116. //----------------------------------------------------------------------------
  4117. std::vector<std::string> const& cmake::GetDebugConfigs()
  4118. {
  4119. // Compute on-demand.
  4120. if(this->DebugConfigs.empty())
  4121. {
  4122. if(const char* config_list = this->GetProperty("DEBUG_CONFIGURATIONS"))
  4123. {
  4124. // Expand the specified list and convert to upper-case.
  4125. cmSystemTools::ExpandListArgument(config_list, this->DebugConfigs);
  4126. for(std::vector<std::string>::iterator i = this->DebugConfigs.begin();
  4127. i != this->DebugConfigs.end(); ++i)
  4128. {
  4129. *i = cmSystemTools::UpperCase(*i);
  4130. }
  4131. }
  4132. // If no configurations were specified, use a default list.
  4133. if(this->DebugConfigs.empty())
  4134. {
  4135. this->DebugConfigs.push_back("DEBUG");
  4136. }
  4137. }
  4138. return this->DebugConfigs;
  4139. }
  4140. int cmake::Build(const std::string& dir,
  4141. const std::string& target,
  4142. const std::string& config,
  4143. const std::vector<std::string>& nativeOptions,
  4144. bool clean,
  4145. cmSystemTools::OutputOption outputflag)
  4146. {
  4147. if(!cmSystemTools::FileIsDirectory(dir.c_str()))
  4148. {
  4149. std::cerr << "Error: " << dir << " is not a directory\n";
  4150. return 1;
  4151. }
  4152. std::string cachePath = dir;
  4153. cmSystemTools::ConvertToUnixSlashes(cachePath);
  4154. cmCacheManager* cachem = this->GetCacheManager();
  4155. cmCacheManager::CacheIterator it = cachem->NewIterator();
  4156. if(!cachem->LoadCache(cachePath.c_str()))
  4157. {
  4158. std::cerr << "Error: could not load cache\n";
  4159. return 1;
  4160. }
  4161. if(!it.Find("CMAKE_GENERATOR"))
  4162. {
  4163. std::cerr << "Error: could find generator in Cache\n";
  4164. return 1;
  4165. }
  4166. std::auto_ptr<cmGlobalGenerator> gen(
  4167. this->CreateGlobalGenerator(it.GetValue()));
  4168. std::string output;
  4169. std::string projName;
  4170. std::string makeProgram;
  4171. if(!it.Find("CMAKE_PROJECT_NAME"))
  4172. {
  4173. std::cerr << "Error: could not find CMAKE_PROJECT_NAME in Cache\n";
  4174. return 1;
  4175. }
  4176. projName = it.GetValue();
  4177. if(!it.Find("CMAKE_MAKE_PROGRAM"))
  4178. {
  4179. std::cerr << "Error: could not find CMAKE_MAKE_PROGRAM in Cache\n";
  4180. return 1;
  4181. }
  4182. makeProgram = it.GetValue();
  4183. return gen->Build(0, dir.c_str(),
  4184. projName.c_str(), target.c_str(),
  4185. &output,
  4186. makeProgram.c_str(),
  4187. config.c_str(), clean, false, 0, outputflag,
  4188. 0, nativeOptions);
  4189. }
  4190. void cmake::WatchUnusedCli(const char* var)
  4191. {
  4192. #ifdef CMAKE_BUILD_WITH_CMAKE
  4193. this->VariableWatch->AddWatch(var, cmWarnUnusedCliWarning, this);
  4194. if(this->UsedCliVariables.find(var) == this->UsedCliVariables.end())
  4195. {
  4196. this->UsedCliVariables[var] = false;
  4197. }
  4198. #endif
  4199. }
  4200. void cmake::UnwatchUnusedCli(const char* var)
  4201. {
  4202. #ifdef CMAKE_BUILD_WITH_CMAKE
  4203. this->VariableWatch->RemoveWatch(var, cmWarnUnusedCliWarning);
  4204. this->UsedCliVariables.erase(var);
  4205. #endif
  4206. }
  4207. void cmake::RunCheckForUnusedVariables()
  4208. {
  4209. #ifdef CMAKE_BUILD_WITH_CMAKE
  4210. bool haveUnused = false;
  4211. cmOStringStream msg;
  4212. msg << "Manually-specified variables were not used by the project:";
  4213. for(std::map<cmStdString, bool>::const_iterator
  4214. it = this->UsedCliVariables.begin();
  4215. it != this->UsedCliVariables.end(); ++it)
  4216. {
  4217. if(!it->second)
  4218. {
  4219. haveUnused = true;
  4220. msg << "\n " << it->first;
  4221. }
  4222. }
  4223. if(haveUnused)
  4224. {
  4225. this->IssueMessage(cmake::WARNING, msg.str(), cmListFileBacktrace());
  4226. }
  4227. #endif
  4228. }