1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License for more information.
11 ============================================================================*/
13 #include "cmDocumentVariables.h"
15 #include "cmCacheManager.h"
16 #include "cmMakefile.h"
17 #include "cmLocalGenerator.h"
18 #include "cmExternalMakefileProjectGenerator.h"
19 #include "cmCommands.h"
20 #include "cmCommand.h"
21 #include "cmFileTimeComparison.h"
22 #include "cmGeneratedFileStream.h"
23 #include "cmQtAutomoc.h"
24 #include "cmSourceFile.h"
25 #include "cmVersion.h"
27 #include "cmDocumentationFormatterText.h"
29 #if defined(CMAKE_BUILD_WITH_CMAKE)
30 # include "cmGraphVizWriter.h"
31 # include "cmDependsFortran.h" // For -E cmake_copy_f90_mod callback.
32 # include "cmVariableWatch.h"
33 # include <cmsys/Terminal.h>
34 # include <cmsys/CommandLineArguments.hxx>
37 #include <cmsys/Directory.hxx>
38 #include <cmsys/Process.h>
39 #include <cmsys/Glob.hxx>
40 #include <cmsys/RegularExpression.hxx>
42 // only build kdevelop generator on non-windows platforms
43 // when not bootstrapping cmake
45 # if defined(CMAKE_BUILD_WITH_CMAKE)
46 # define CMAKE_USE_KDEVELOP
50 #if defined(CMAKE_BUILD_WITH_CMAKE)
51 # define CMAKE_USE_ECLIPSE
54 #if defined(__MINGW32__) && !defined(CMAKE_BUILD_WITH_CMAKE)
55 # define CMAKE_BOOT_MINGW
58 // include the generator
59 #if defined(_WIN32) && !defined(__CYGWIN__)
60 # if !defined(CMAKE_BOOT_MINGW)
61 # include "cmGlobalVisualStudio6Generator.h"
62 # include "cmGlobalVisualStudio7Generator.h"
63 # include "cmGlobalVisualStudio71Generator.h"
64 # include "cmGlobalVisualStudio8Generator.h"
65 # include "cmGlobalVisualStudio9Generator.h"
66 # include "cmGlobalVisualStudio9IA64Generator.h"
67 # include "cmGlobalVisualStudio9Win64Generator.h"
68 # include "cmGlobalVisualStudio10Generator.h"
69 # include "cmGlobalVisualStudio10IA64Generator.h"
70 # include "cmGlobalVisualStudio10Win64Generator.h"
71 # include "cmGlobalVisualStudio11Generator.h"
72 # include "cmGlobalVisualStudio11Win64Generator.h"
73 # include "cmGlobalVisualStudio11ARMGenerator.h"
74 # include "cmGlobalVisualStudio8Win64Generator.h"
75 # include "cmGlobalBorlandMakefileGenerator.h"
76 # include "cmGlobalNMakeMakefileGenerator.h"
77 # include "cmGlobalJOMMakefileGenerator.h"
78 # include "cmGlobalWatcomWMakeGenerator.h"
79 # define CMAKE_HAVE_VS_GENERATORS
81 # include "cmGlobalMSYSMakefileGenerator.h"
82 # include "cmGlobalMinGWMakefileGenerator.h"
83 # include "cmWin32ProcessExecution.h"
86 #include "cmGlobalUnixMakefileGenerator3.h"
87 #include "cmGlobalNinjaGenerator.h"
90 #if defined(CMAKE_HAVE_VS_GENERATORS)
91 #include "cmCallVisualStudioMacro.h"
94 #if !defined(CMAKE_BOOT_MINGW)
95 # include "cmExtraCodeBlocksGenerator.h"
98 #ifdef CMAKE_USE_KDEVELOP
99 # include "cmGlobalKdevelopGenerator.h"
102 #ifdef CMAKE_USE_ECLIPSE
103 # include "cmExtraEclipseCDT4Generator.h"
106 #include <stdlib.h> // required for atoi
108 #if defined( __APPLE__ )
109 # if defined(CMAKE_BUILD_WITH_CMAKE)
110 # include "cmGlobalXCodeGenerator.h"
111 # define CMAKE_USE_XCODE 1
113 # include <sys/types.h>
114 # include <sys/time.h>
115 # include <sys/resource.h>
118 #include <sys/stat.h> // struct stat
120 #include <memory> // auto_ptr
122 static bool cmakeCheckStampFile(const char* stampName);
123 static bool cmakeCheckStampList(const char* stampName);
125 void cmNeedBackwardsCompatibility(const std::string& variable,
126 int access_type, void*, const char*, const cmMakefile*)
128 #ifdef CMAKE_BUILD_WITH_CMAKE
129 if (access_type == cmVariableWatch::UNKNOWN_VARIABLE_READ_ACCESS)
131 std::string message = "An attempt was made to access a variable: ";
134 " that has not been defined. Some variables were always defined "
135 "by CMake in versions prior to 1.6. To fix this you might need to set "
136 "the cache value of CMAKE_BACKWARDS_COMPATIBILITY to 1.4 or less. If "
137 "you are writing a CMakeLists file, (or have already set "
138 "CMAKE_BACKWARDS_COMPATABILITY to 1.4 or less) then you probably need "
139 "to include a CMake module to test for the feature this variable "
141 cmSystemTools::Error(message.c_str());
149 void cmWarnUnusedCliWarning(const std::string& variable,
150 int, void* ctx, const char*, const cmMakefile*)
152 cmake* cm = reinterpret_cast<cmake*>(ctx);
153 cm->MarkCliAsUsed(variable);
159 this->WarnUninitialized = false;
160 this->WarnUnused = false;
161 this->WarnUnusedCli = true;
162 this->CheckSystemVars = false;
163 this->SuppressDevWarnings = false;
164 this->DoSuppressDevWarnings = false;
165 this->DebugOutput = false;
166 this->DebugTryCompile = false;
167 this->ClearBuildSystem = false;
168 this->FileComparison = new cmFileTimeComparison;
170 this->Policies = new cmPolicies();
171 this->InitializeProperties();
175 if(!getrlimit(RLIMIT_STACK, &rlp))
177 if(rlp.rlim_cur != rlp.rlim_max)
179 rlp.rlim_cur = rlp.rlim_max;
180 setrlimit(RLIMIT_STACK, &rlp);
185 this->Verbose = false;
186 this->InTryCompile = false;
187 this->CacheManager = new cmCacheManager(this);
188 this->GlobalGenerator = 0;
189 this->ProgressCallback = 0;
190 this->ProgressCallbackClientData = 0;
191 this->CurrentWorkingMode = NORMAL_MODE;
193 #ifdef CMAKE_BUILD_WITH_CMAKE
194 this->VariableWatch = new cmVariableWatch;
195 this->VariableWatch->AddWatch("CMAKE_WORDS_BIGENDIAN",
196 cmNeedBackwardsCompatibility);
197 this->VariableWatch->AddWatch("CMAKE_SIZEOF_INT",
198 cmNeedBackwardsCompatibility);
199 this->VariableWatch->AddWatch("CMAKE_X_LIBS",
200 cmNeedBackwardsCompatibility);
203 this->AddDefaultGenerators();
204 this->AddDefaultExtraGenerators();
205 this->AddDefaultCommands();
207 // Make sure we can capture the build tool output.
208 cmSystemTools::EnableVSConsoleOutput();
213 delete this->CacheManager;
214 delete this->Policies;
215 if (this->GlobalGenerator)
217 delete this->GlobalGenerator;
218 this->GlobalGenerator = 0;
220 for(RegisteredCommandsMap::iterator j = this->Commands.begin();
221 j != this->Commands.end(); ++j)
225 #ifdef CMAKE_BUILD_WITH_CMAKE
226 delete this->VariableWatch;
228 delete this->FileComparison;
231 void cmake::InitializeProperties()
233 this->Properties.clear();
234 this->Properties.SetCMakeInstance(this);
235 this->AccessedProperties.clear();
236 this->PropertyDefinitions.clear();
238 // initialize properties
239 cmCacheManager::DefineProperties(this);
240 cmSourceFile::DefineProperties(this);
241 cmTarget::DefineProperties(this);
242 cmMakefile::DefineProperties(this);
243 cmTest::DefineProperties(this);
244 cmake::DefineProperties(this);
247 void cmake::CleanupCommandsAndMacros()
249 this->InitializeProperties();
250 std::vector<cmCommand*> commands;
251 for(RegisteredCommandsMap::iterator j = this->Commands.begin();
252 j != this->Commands.end(); ++j)
254 if ( !j->second->IsA("cmMacroHelperCommand") &&
255 !j->second->IsA("cmFunctionHelperCommand"))
257 commands.push_back(j->second);
264 this->Commands.erase(this->Commands.begin(), this->Commands.end());
265 std::vector<cmCommand*>::iterator it;
266 for ( it = commands.begin(); it != commands.end();
269 this->Commands[cmSystemTools::LowerCase((*it)->GetName())] = *it;
273 bool cmake::CommandExists(const char* name) const
275 std::string sName = cmSystemTools::LowerCase(name);
276 return (this->Commands.find(sName) != this->Commands.end());
279 cmCommand *cmake::GetCommand(const char *name)
282 std::string sName = cmSystemTools::LowerCase(name);
283 RegisteredCommandsMap::iterator pos = this->Commands.find(sName);
284 if (pos != this->Commands.end())
291 void cmake::RenameCommand(const char*oldName, const char* newName)
293 // if the command already exists, free the old one
294 std::string sOldName = cmSystemTools::LowerCase(oldName);
295 std::string sNewName = cmSystemTools::LowerCase(newName);
296 RegisteredCommandsMap::iterator pos = this->Commands.find(sOldName);
297 if ( pos == this->Commands.end() )
301 cmCommand* cmd = pos->second;
303 pos = this->Commands.find(sNewName);
304 if (pos != this->Commands.end())
307 this->Commands.erase(pos);
309 this->Commands.insert(RegisteredCommandsMap::value_type(sNewName, cmd));
310 pos = this->Commands.find(sOldName);
311 this->Commands.erase(pos);
314 void cmake::RemoveCommand(const char* name)
316 std::string sName = cmSystemTools::LowerCase(name);
317 RegisteredCommandsMap::iterator pos = this->Commands.find(sName);
318 if ( pos != this->Commands.end() )
321 this->Commands.erase(pos);
325 void cmake::AddCommand(cmCommand* wg)
327 std::string name = cmSystemTools::LowerCase(wg->GetName());
328 // if the command already exists, free the old one
329 RegisteredCommandsMap::iterator pos = this->Commands.find(name);
330 if (pos != this->Commands.end())
333 this->Commands.erase(pos);
335 this->Commands.insert( RegisteredCommandsMap::value_type(name, wg));
339 void cmake::RemoveUnscriptableCommands()
341 std::vector<std::string> unscriptableCommands;
342 cmake::RegisteredCommandsMap* commands = this->GetCommands();
343 for (cmake::RegisteredCommandsMap::const_iterator pos = commands->begin();
344 pos != commands->end();
347 if (!pos->second->IsScriptable())
349 unscriptableCommands.push_back(pos->first);
353 for(std::vector<std::string>::const_iterator it=unscriptableCommands.begin();
354 it != unscriptableCommands.end();
357 this->RemoveCommand(it->c_str());
362 bool cmake::SetCacheArgs(const std::vector<std::string>& args)
364 bool findPackageMode = false;
365 for(unsigned int i=1; i < args.size(); ++i)
367 std::string arg = args[i];
368 if(arg.find("-D",0) == 0)
370 std::string entry = arg.substr(2);
371 if(entry.size() == 0)
380 cmSystemTools::Error("-D must be followed with VAR=VALUE.");
384 std::string var, value;
385 cmCacheManager::CacheEntryType type = cmCacheManager::UNINITIALIZED;
386 if(cmCacheManager::ParseEntry(entry.c_str(), var, value, type))
388 this->CacheManager->AddCacheEntry(var.c_str(), value.c_str(),
389 "No help, variable specified on the command line.", type);
390 if(this->WarnUnusedCli)
392 this->WatchUnusedCli(var.c_str());
397 std::cerr << "Parse error in command line argument: " << arg << "\n"
398 << "Should be: VAR:type=value\n";
399 cmSystemTools::Error("No cmake script provided.");
403 else if(arg.find("-Wno-dev",0) == 0)
405 this->SuppressDevWarnings = true;
406 this->DoSuppressDevWarnings = true;
408 else if(arg.find("-Wdev",0) == 0)
410 this->SuppressDevWarnings = false;
411 this->DoSuppressDevWarnings = true;
413 else if(arg.find("-U",0) == 0)
415 std::string entryPattern = arg.substr(2);
416 if(entryPattern.size() == 0)
421 entryPattern = args[i];
425 cmSystemTools::Error("-U must be followed with VAR.");
429 cmsys::RegularExpression regex(
430 cmsys::Glob::PatternToRegex(entryPattern.c_str(), true, true).c_str());
431 //go through all cache entries and collect the vars which will be removed
432 std::vector<std::string> entriesToDelete;
433 cmCacheManager::CacheIterator it =
434 this->CacheManager->GetCacheIterator();
435 for ( it.Begin(); !it.IsAtEnd(); it.Next() )
437 cmCacheManager::CacheEntryType t = it.GetType();
438 if(t != cmCacheManager::STATIC)
440 std::string entryName = it.GetName();
441 if (regex.find(entryName.c_str()))
443 entriesToDelete.push_back(entryName);
448 // now remove them from the cache
449 for(std::vector<std::string>::const_iterator currentEntry =
450 entriesToDelete.begin();
451 currentEntry != entriesToDelete.end();
454 this->CacheManager->RemoveCacheEntry(currentEntry->c_str());
457 else if(arg.find("-C",0) == 0)
459 std::string path = arg.substr(2);
460 if ( path.size() == 0 )
469 cmSystemTools::Error("-C must be followed by a file name.");
473 std::cerr << "loading initial cache file " << path.c_str() << "\n";
474 this->ReadListFile(args, path.c_str());
476 else if(arg.find("-P",0) == 0)
481 cmSystemTools::Error("-P must be followed by a file name.");
484 std::string path = args[i];
485 if ( path.size() == 0 )
487 cmSystemTools::Error("No cmake script provided.");
490 this->ReadListFile(args, path.c_str());
492 else if (arg.find("--find-package",0) == 0)
494 findPackageMode = true;
500 return this->FindPackage(args);
506 void cmake::ReadListFile(const std::vector<std::string>& args,
509 // if a generator was not yet created, temporarily create one
510 cmGlobalGenerator *gg = this->GetGlobalGenerator();
511 bool created = false;
513 // if a generator was not specified use a generic one
516 gg = new cmGlobalGenerator;
517 gg->SetCMakeInstance(this);
521 // read in the list file to fill the cache
524 std::auto_ptr<cmLocalGenerator> lg(gg->CreateLocalGenerator());
525 lg->GetMakefile()->SetHomeOutputDirectory
526 (cmSystemTools::GetCurrentWorkingDirectory().c_str());
527 lg->GetMakefile()->SetStartOutputDirectory
528 (cmSystemTools::GetCurrentWorkingDirectory().c_str());
529 lg->GetMakefile()->SetHomeDirectory
530 (cmSystemTools::GetCurrentWorkingDirectory().c_str());
531 lg->GetMakefile()->SetStartDirectory
532 (cmSystemTools::GetCurrentWorkingDirectory().c_str());
533 if (this->GetWorkingMode() != NORMAL_MODE)
535 std::string file(cmSystemTools::CollapseFullPath(path));
536 cmSystemTools::ConvertToUnixSlashes(file);
537 lg->GetMakefile()->SetScriptModeFile(file.c_str());
539 lg->GetMakefile()->SetArgcArgv(args);
541 if (!lg->GetMakefile()->ReadListFile(0, path))
543 cmSystemTools::Error("Error processing file:", path);
547 // free generic one if generated
555 bool cmake::FindPackage(const std::vector<std::string>& args)
557 // if a generator was not yet created, temporarily create one
558 cmGlobalGenerator *gg = new cmGlobalGenerator;
559 gg->SetCMakeInstance(this);
560 this->SetGlobalGenerator(gg);
562 // read in the list file to fill the cache
563 std::auto_ptr<cmLocalGenerator> lg(gg->CreateLocalGenerator());
564 cmMakefile* mf = lg->GetMakefile();
565 mf->SetHomeOutputDirectory
566 (cmSystemTools::GetCurrentWorkingDirectory().c_str());
567 mf->SetStartOutputDirectory
568 (cmSystemTools::GetCurrentWorkingDirectory().c_str());
570 (cmSystemTools::GetCurrentWorkingDirectory().c_str());
571 mf->SetStartDirectory
572 (cmSystemTools::GetCurrentWorkingDirectory().c_str());
574 mf->SetArgcArgv(args);
576 std::string systemFile = mf->GetModulesFile("CMakeFindPackageMode.cmake");
577 mf->ReadListFile(0, systemFile.c_str());
579 std::string language = mf->GetSafeDefinition("LANGUAGE");
580 std::string mode = mf->GetSafeDefinition("MODE");
581 std::string packageName = mf->GetSafeDefinition("NAME");
582 bool packageFound = mf->IsOn("PACKAGE_FOUND");
583 bool quiet = mf->IsOn("PACKAGE_QUIET");
589 printf("%s not found.\n", packageName.c_str());
592 else if (mode == "EXIST")
596 printf("%s found.\n", packageName.c_str());
599 else if (mode == "COMPILE")
601 std::string includes = mf->GetSafeDefinition("PACKAGE_INCLUDE_DIRS");
602 std::vector<std::string> includeDirs;
603 cmSystemTools::ExpandListArgument(includes, includeDirs);
605 std::string includeFlags = lg->GetIncludeFlags(includeDirs,
606 language.c_str(), false);
608 std::string definitions = mf->GetSafeDefinition("PACKAGE_DEFINITIONS");
609 printf("%s %s\n", includeFlags.c_str(), definitions.c_str());
611 else if (mode == "LINK")
613 const char* targetName = "dummy";
614 std::vector<std::string> srcs;
615 cmTarget* tgt = mf->AddExecutable(targetName, srcs, true);
616 tgt->SetProperty("LINKER_LANGUAGE", language.c_str());
618 std::string libs = mf->GetSafeDefinition("PACKAGE_LIBRARIES");
619 std::vector<std::string> libList;
620 cmSystemTools::ExpandListArgument(libs, libList);
621 for(std::vector<std::string>::const_iterator libIt=libList.begin();
622 libIt != libList.end();
625 mf->AddLinkLibraryForTarget(targetName, libIt->c_str(),
630 std::string linkLibs;
632 std::string linkFlags;
633 lg->GetTargetFlags(linkLibs, flags, linkFlags, *tgt);
635 printf("%s\n", linkLibs.c_str() );
639 tgt->SetProperty("WIN32_EXECUTABLE", "ON");
643 tgt->SetProperty("MACOSX_BUNDLE", "ON");
647 // free generic one if generated
648 // this->SetGlobalGenerator(0); // setting 0-pointer is not possible
649 // delete gg; // this crashes inside the cmake instance
656 void cmake::SetArgs(const std::vector<std::string>& args,
657 bool directoriesSetBefore)
659 bool directoriesSet = directoriesSetBefore;
660 for(unsigned int i=1; i < args.size(); ++i)
662 std::string arg = args[i];
663 if(arg.find("-H",0) == 0)
665 directoriesSet = true;
666 std::string path = arg.substr(2);
667 path = cmSystemTools::CollapseFullPath(path.c_str());
668 cmSystemTools::ConvertToUnixSlashes(path);
669 this->SetHomeDirectory(path.c_str());
671 else if(arg.find("-S",0) == 0)
673 // There is no local generate anymore. Ignore -S option.
675 else if(arg.find("-O",0) == 0)
677 // There is no local generate anymore. Ignore -O option.
679 else if(arg.find("-B",0) == 0)
681 directoriesSet = true;
682 std::string path = arg.substr(2);
683 path = cmSystemTools::CollapseFullPath(path.c_str());
684 cmSystemTools::ConvertToUnixSlashes(path);
685 this->SetHomeOutputDirectory(path.c_str());
687 else if((i < args.size()-1) && (arg.find("--check-build-system",0) == 0))
689 this->CheckBuildSystemArgument = args[++i];
690 this->ClearBuildSystem = (atoi(args[++i].c_str()) > 0);
692 else if((i < args.size()-1) && (arg.find("--check-stamp-file",0) == 0))
694 this->CheckStampFile = args[++i];
696 else if((i < args.size()-1) && (arg.find("--check-stamp-list",0) == 0))
698 this->CheckStampList = args[++i];
700 #if defined(CMAKE_HAVE_VS_GENERATORS)
701 else if((i < args.size()-1) && (arg.find("--vs-solution-file",0) == 0))
703 this->VSSolutionFile = args[++i];
706 else if(arg.find("-V",0) == 0)
708 this->Verbose = true;
710 else if(arg.find("-D",0) == 0)
714 else if(arg.find("-U",0) == 0)
718 else if(arg.find("-C",0) == 0)
722 else if(arg.find("-P",0) == 0)
727 else if(arg.find("--find-package",0) == 0)
732 else if(arg.find("-Wno-dev",0) == 0)
736 else if(arg.find("-Wdev",0) == 0)
740 else if(arg.find("--graphviz=",0) == 0)
742 std::string path = arg.substr(strlen("--graphviz="));
743 path = cmSystemTools::CollapseFullPath(path.c_str());
744 cmSystemTools::ConvertToUnixSlashes(path);
745 this->GraphVizFile = path;
746 if ( this->GraphVizFile.empty() )
748 cmSystemTools::Error("No file specified for --graphviz");
751 else if(arg.find("--debug-trycompile",0) == 0)
753 std::cout << "debug trycompile on\n";
754 this->DebugTryCompileOn();
756 else if(arg.find("--debug-output",0) == 0)
758 std::cout << "Running with debug output on.\n";
759 this->SetDebugOutputOn(true);
761 else if(arg.find("--trace",0) == 0)
763 std::cout << "Running with trace output on.\n";
764 this->SetTrace(true);
766 else if(arg.find("--warn-uninitialized",0) == 0)
768 std::cout << "Warn about uninitialized values.\n";
769 this->SetWarnUninitialized(true);
771 else if(arg.find("--warn-unused-vars",0) == 0)
773 std::cout << "Finding unused variables.\n";
774 this->SetWarnUnused(true);
776 else if(arg.find("--no-warn-unused-cli",0) == 0)
778 std::cout << "Not searching for unused variables given on the " <<
780 this->SetWarnUnusedCli(false);
782 else if(arg.find("--check-system-vars",0) == 0)
784 std::cout << "Also check system files when warning about unused and " <<
785 "uninitialized variables.\n";
786 this->SetCheckSystemVars(true);
788 else if(arg.find("-G",0) == 0)
790 std::string value = arg.substr(2);
791 if(value.size() == 0)
796 cmSystemTools::Error("No generator specified for -G");
801 cmGlobalGenerator* gen =
802 this->CreateGlobalGenerator(value.c_str());
805 cmSystemTools::Error("Could not create named generator ",
810 this->SetGlobalGenerator(gen);
813 // no option assume it is the path to the source
816 directoriesSet = true;
817 this->SetDirectoriesFromFile(arg.c_str());
822 this->SetHomeOutputDirectory
823 (cmSystemTools::GetCurrentWorkingDirectory().c_str());
824 this->SetStartOutputDirectory
825 (cmSystemTools::GetCurrentWorkingDirectory().c_str());
826 this->SetHomeDirectory
827 (cmSystemTools::GetCurrentWorkingDirectory().c_str());
828 this->SetStartDirectory
829 (cmSystemTools::GetCurrentWorkingDirectory().c_str());
832 this->SetStartDirectory(this->GetHomeDirectory());
833 this->SetStartOutputDirectory(this->GetHomeOutputDirectory());
836 //----------------------------------------------------------------------------
837 void cmake::SetDirectoriesFromFile(const char* arg)
839 // Check if the argument refers to a CMakeCache.txt or
840 // CMakeLists.txt file.
841 std::string listPath;
842 std::string cachePath;
843 bool argIsFile = false;
844 if(cmSystemTools::FileIsDirectory(arg))
846 std::string path = cmSystemTools::CollapseFullPath(arg);
847 cmSystemTools::ConvertToUnixSlashes(path);
848 std::string cacheFile = path;
849 cacheFile += "/CMakeCache.txt";
850 std::string listFile = path;
851 listFile += "/CMakeLists.txt";
852 if(cmSystemTools::FileExists(cacheFile.c_str()))
856 if(cmSystemTools::FileExists(listFile.c_str()))
861 else if(cmSystemTools::FileExists(arg))
864 std::string fullPath = cmSystemTools::CollapseFullPath(arg);
865 std::string name = cmSystemTools::GetFilenameName(fullPath.c_str());
866 name = cmSystemTools::LowerCase(name);
867 if(name == "cmakecache.txt")
869 cachePath = cmSystemTools::GetFilenamePath(fullPath.c_str());
871 else if(name == "cmakelists.txt")
873 listPath = cmSystemTools::GetFilenamePath(fullPath.c_str());
878 // Specified file or directory does not exist. Try to set things
879 // up to produce a meaningful error message.
880 std::string fullPath = cmSystemTools::CollapseFullPath(arg);
881 std::string name = cmSystemTools::GetFilenameName(fullPath.c_str());
882 name = cmSystemTools::LowerCase(name);
883 if(name == "cmakecache.txt" || name == "cmakelists.txt")
886 listPath = cmSystemTools::GetFilenamePath(fullPath.c_str());
894 // If there is a CMakeCache.txt file, use its settings.
895 if(cachePath.length() > 0)
897 cmCacheManager* cachem = this->GetCacheManager();
898 cmCacheManager::CacheIterator it = cachem->NewIterator();
899 if(cachem->LoadCache(cachePath.c_str()) &&
900 it.Find("CMAKE_HOME_DIRECTORY"))
902 this->SetHomeOutputDirectory(cachePath.c_str());
903 this->SetStartOutputDirectory(cachePath.c_str());
904 this->SetHomeDirectory(it.GetValue());
905 this->SetStartDirectory(it.GetValue());
910 // If there is a CMakeLists.txt file, use it as the source tree.
911 if(listPath.length() > 0)
913 this->SetHomeDirectory(listPath.c_str());
914 this->SetStartDirectory(listPath.c_str());
918 // Source CMakeLists.txt file given. It was probably dropped
919 // onto the executable in a GUI. Default to an in-source build.
920 this->SetHomeOutputDirectory(listPath.c_str());
921 this->SetStartOutputDirectory(listPath.c_str());
925 // Source directory given on command line. Use current working
926 // directory as build tree.
927 std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
928 this->SetHomeOutputDirectory(cwd.c_str());
929 this->SetStartOutputDirectory(cwd.c_str());
934 // We didn't find a CMakeLists.txt or CMakeCache.txt file from the
935 // argument. Assume it is the path to the source tree, and use the
936 // current working directory as the build tree.
937 std::string full = cmSystemTools::CollapseFullPath(arg);
938 std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
939 this->SetHomeDirectory(full.c_str());
940 this->SetStartDirectory(full.c_str());
941 this->SetHomeOutputDirectory(cwd.c_str());
942 this->SetStartOutputDirectory(cwd.c_str());
945 // at the end of this CMAKE_ROOT and CMAKE_COMMAND should be added to the
947 int cmake::AddCMakePaths()
949 // Find the cmake executable
950 std::string cMakeSelf = cmSystemTools::GetExecutableDirectory();
951 cMakeSelf = cmSystemTools::GetRealPath(cMakeSelf.c_str());
952 cMakeSelf += "/cmake";
953 cMakeSelf += cmSystemTools::GetExecutableExtension();
955 // on the apple this might be the gui bundle
956 if(!cmSystemTools::FileExists(cMakeSelf.c_str()))
958 cMakeSelf = cmSystemTools::GetExecutableDirectory();
959 cMakeSelf = cmSystemTools::GetRealPath(cMakeSelf.c_str());
960 cMakeSelf += "../../../..";
961 cMakeSelf = cmSystemTools::GetRealPath(cMakeSelf.c_str());
962 cMakeSelf = cmSystemTools::CollapseFullPath(cMakeSelf.c_str());
963 cMakeSelf += "/cmake";
964 std::cerr << cMakeSelf.c_str() << "\n";
967 if(!cmSystemTools::FileExists(cMakeSelf.c_str()))
969 cmSystemTools::Error("CMake executable cannot be found at ",
973 // Save the value in the cache
974 this->CacheManager->AddCacheEntry
975 ("CMAKE_COMMAND",cMakeSelf.c_str(), "Path to CMake executable.",
976 cmCacheManager::INTERNAL);
977 // if the edit command is not yet in the cache,
978 // or if CMakeEditCommand has been set on this object,
979 // then set the CMAKE_EDIT_COMMAND in the cache
980 // This will mean that the last gui to edit the cache
981 // will be the one that make edit_cache uses.
982 if(!this->GetCacheDefinition("CMAKE_EDIT_COMMAND")
983 || !this->CMakeEditCommand.empty())
985 // Find and save the command to edit the cache
986 std::string editCacheCommand;
987 if(!this->CMakeEditCommand.empty())
989 editCacheCommand = cmSystemTools::GetFilenamePath(cMakeSelf)
991 + this->CMakeEditCommand
992 + cmSystemTools::GetFilenameExtension(cMakeSelf);
994 if( !cmSystemTools::FileExists(editCacheCommand.c_str()))
996 editCacheCommand = cmSystemTools::GetFilenamePath(cMakeSelf) +
997 "/ccmake" + cmSystemTools::GetFilenameExtension(cMakeSelf);
999 if( !cmSystemTools::FileExists(editCacheCommand.c_str()))
1001 editCacheCommand = cmSystemTools::GetFilenamePath(cMakeSelf) +
1002 "/cmake-gui" + cmSystemTools::GetFilenameExtension(cMakeSelf);
1004 if(cmSystemTools::FileExists(editCacheCommand.c_str()))
1006 this->CacheManager->AddCacheEntry
1007 ("CMAKE_EDIT_COMMAND", editCacheCommand.c_str(),
1008 "Path to cache edit program executable.", cmCacheManager::INTERNAL);
1011 std::string ctestCommand = cmSystemTools::GetFilenamePath(cMakeSelf) +
1012 "/ctest" + cmSystemTools::GetFilenameExtension(cMakeSelf);
1013 if(cmSystemTools::FileExists(ctestCommand.c_str()))
1015 this->CacheManager->AddCacheEntry
1016 ("CMAKE_CTEST_COMMAND", ctestCommand.c_str(),
1017 "Path to ctest program executable.", cmCacheManager::INTERNAL);
1019 std::string cpackCommand = cmSystemTools::GetFilenamePath(cMakeSelf) +
1020 "/cpack" + cmSystemTools::GetFilenameExtension(cMakeSelf);
1021 if(cmSystemTools::FileExists(cpackCommand.c_str()))
1023 this->CacheManager->AddCacheEntry
1024 ("CMAKE_CPACK_COMMAND", cpackCommand.c_str(),
1025 "Path to cpack program executable.", cmCacheManager::INTERNAL);
1028 // do CMAKE_ROOT, look for the environment variable first
1029 std::string cMakeRoot;
1030 std::string modules;
1031 if (getenv("CMAKE_ROOT"))
1033 cMakeRoot = getenv("CMAKE_ROOT");
1034 modules = cMakeRoot + "/Modules/CMake.cmake";
1036 if(!cmSystemTools::FileExists(modules.c_str()))
1039 cMakeRoot = cmSystemTools::GetRealPath(cMakeSelf.c_str());
1040 cMakeRoot = cmSystemTools::GetProgramPath(cMakeRoot.c_str());
1041 std::string::size_type slashPos = cMakeRoot.rfind("/");
1042 if(slashPos != std::string::npos)
1044 cMakeRoot = cMakeRoot.substr(0, slashPos);
1046 // is there no Modules direcory there?
1047 modules = cMakeRoot + "/Modules/CMake.cmake";
1050 if (!cmSystemTools::FileExists(modules.c_str()))
1052 // try exe/../share/cmake
1053 cMakeRoot += CMAKE_DATA_DIR;
1054 modules = cMakeRoot + "/Modules/CMake.cmake";
1056 #ifdef CMAKE_ROOT_DIR
1057 if (!cmSystemTools::FileExists(modules.c_str()))
1059 // try compiled in root directory
1060 cMakeRoot = CMAKE_ROOT_DIR;
1061 modules = cMakeRoot + "/Modules/CMake.cmake";
1064 if (!cmSystemTools::FileExists(modules.c_str()))
1067 cMakeRoot = cmSystemTools::GetProgramPath(cMakeSelf.c_str());
1068 cMakeRoot += CMAKE_DATA_DIR;
1069 modules = cMakeRoot + "/Modules/CMake.cmake";
1071 if(!cmSystemTools::FileExists(modules.c_str()))
1074 cMakeRoot = cmSystemTools::GetProgramPath(cMakeSelf.c_str());
1075 // is there no Modules direcory there?
1076 modules = cMakeRoot + "/Modules/CMake.cmake";
1078 if (!cmSystemTools::FileExists(modules.c_str()))
1080 // couldn't find modules
1081 cmSystemTools::Error("Could not find CMAKE_ROOT !!!\n"
1082 "CMake has most likely not been installed correctly.\n"
1083 "Modules directory not found in\n",
1087 this->CacheManager->AddCacheEntry
1088 ("CMAKE_ROOT", cMakeRoot.c_str(),
1089 "Path to CMake installation.", cmCacheManager::INTERNAL);
1092 std::string comspec = "cmw9xcom.exe";
1093 cmSystemTools::SetWindows9xComspecSubstitute(comspec.c_str());
1100 void CMakeCommandUsage(const char* program)
1102 cmOStringStream errorStream;
1104 #ifdef CMAKE_BUILD_WITH_CMAKE
1106 << "cmake version " << cmVersion::GetCMakeVersion() << "\n";
1109 << "cmake bootstrap\n";
1111 // If you add new commands, change here,
1112 // and in cmakemain.cxx in the options table
1114 << "Usage: " << program << " -E [command] [arguments ...]\n"
1115 << "Available commands: \n"
1116 << " chdir dir cmd [args]... - run command in a given directory\n"
1117 << " compare_files file1 file2 - check if file1 is same as file2\n"
1118 << " copy file destination - copy file to destination (either file "
1120 << " copy_directory source destination - copy directory 'source' "
1121 "content to directory 'destination'\n"
1122 << " copy_if_different in-file out-file - copy file if input has "
1124 << " echo [string]... - displays arguments as text\n"
1125 << " echo_append [string]... - displays arguments as text but no new "
1127 << " environment - display the current environment\n"
1128 << " make_directory dir - create a directory\n"
1129 << " md5sum file1 [...] - compute md5sum of files\n"
1130 << " remove [-f] file1 file2 ... - remove the file(s), use -f to force "
1132 << " remove_directory dir - remove a directory and its contents\n"
1133 << " rename oldname newname - rename a file or directory "
1135 << " tar [cxt][vfz][cvfj] file.tar "
1136 "file/dir1 file/dir2 ... - create a tar "
1138 << " time command [args] ... - run command and return elapsed time\n"
1139 << " touch file - touch a file.\n"
1140 << " touch_nocreate file - touch a file but do not create it.\n"
1141 #if defined(_WIN32) && !defined(__CYGWIN__)
1142 << "Available on Windows only:\n"
1143 << " comspec - on windows 9x use this for RunCommand\n"
1144 << " delete_regv key - delete registry value\n"
1145 << " write_regv key value - write registry value\n"
1147 << "Available on UNIX only:\n"
1148 << " create_symlink old new - create a symbolic link new -> old\n"
1152 cmSystemTools::Error(errorStream.str().c_str());
1155 int cmake::ExecuteCMakeCommand(std::vector<std::string>& args)
1157 // IF YOU ADD A NEW COMMAND, DOCUMENT IT ABOVE and in cmakemain.cxx
1158 if (args.size() > 1)
1161 if (args[1] == "copy" && args.size() == 4)
1163 if(!cmSystemTools::cmCopyFile(args[2].c_str(), args[3].c_str()))
1165 std::cerr << "Error copying file \"" << args[2].c_str()
1166 << "\" to \"" << args[3].c_str() << "\".\n";
1172 // Copy file if different.
1173 if (args[1] == "copy_if_different" && args.size() == 4)
1175 if(!cmSystemTools::CopyFileIfDifferent(args[2].c_str(),
1178 std::cerr << "Error copying file (if different) from \""
1179 << args[2].c_str() << "\" to \"" << args[3].c_str()
1186 // Copy directory content
1187 if (args[1] == "copy_directory" && args.size() == 4)
1189 if(!cmSystemTools::CopyADirectory(args[2].c_str(), args[3].c_str()))
1191 std::cerr << "Error copying directory from \""
1192 << args[2].c_str() << "\" to \"" << args[3].c_str()
1199 // Rename a file or directory
1200 if (args[1] == "rename" && args.size() == 4)
1202 if(!cmSystemTools::RenameFile(args[2].c_str(), args[3].c_str()))
1204 std::string e = cmSystemTools::GetLastSystemError();
1205 std::cerr << "Error renaming from \""
1206 << args[2].c_str() << "\" to \"" << args[3].c_str()
1207 << "\": " << e << "\n";
1214 if (args[1] == "compare_files" && args.size() == 4)
1216 if(cmSystemTools::FilesDiffer(args[2].c_str(), args[3].c_str()))
1218 std::cerr << "Files \""
1219 << args[2].c_str() << "\" to \"" << args[3].c_str()
1220 << "\" are different.\n";
1227 else if (args[1] == "echo" )
1230 const char* space = "";
1231 for ( cc = 2; cc < args.size(); cc ++ )
1233 std::cout << space << args[cc];
1236 std::cout << std::endl;
1240 // Echo string no new line
1241 else if (args[1] == "echo_append" )
1244 const char* space = "";
1245 for ( cc = 2; cc < args.size(); cc ++ )
1247 std::cout << space << args[cc];
1253 #if defined(CMAKE_BUILD_WITH_CMAKE)
1254 // Command to create a symbolic link. Fails on platforms not
1256 else if (args[1] == "environment" )
1258 std::vector<std::string> env = cmSystemTools::GetEnvironmentVariables();
1259 std::vector<std::string>::iterator it;
1260 for ( it = env.begin(); it != env.end(); ++ it )
1262 std::cout << it->c_str() << std::endl;
1268 else if (args[1] == "make_directory" && args.size() == 3)
1270 if(!cmSystemTools::MakeDirectory(args[2].c_str()))
1272 std::cerr << "Error making directory \"" << args[2].c_str()
1279 else if (args[1] == "remove_directory" && args.size() == 3)
1281 if(cmSystemTools::FileIsDirectory(args[2].c_str()) &&
1282 !cmSystemTools::RemoveADirectory(args[2].c_str()))
1284 std::cerr << "Error removing directory \"" << args[2].c_str()
1292 else if (args[1] == "remove" && args.size() > 2)
1295 for (std::string::size_type cc = 2; cc < args.size(); cc ++)
1297 if(args[cc] == "\\-f" || args[cc] == "-f")
1303 // Complain if the file could not be removed, still exists,
1304 // and the -f option was not given.
1305 if(!cmSystemTools::RemoveFile(args[cc].c_str()) && !force &&
1306 cmSystemTools::FileExists(args[cc].c_str()))
1315 else if (args[1] == "touch" && args.size() > 2)
1317 for (std::string::size_type cc = 2; cc < args.size(); cc ++)
1319 // Complain if the file could not be removed, still exists,
1320 // and the -f option was not given.
1321 if(!cmSystemTools::Touch(args[cc].c_str(), true))
1329 else if (args[1] == "touch_nocreate" && args.size() > 2)
1331 for (std::string::size_type cc = 2; cc < args.size(); cc ++)
1333 // Complain if the file could not be removed, still exists,
1334 // and the -f option was not given.
1335 if(!cmSystemTools::Touch(args[cc].c_str(), false))
1344 else if (args[1] == "time" && args.size() > 2)
1346 std::string command = args[2];
1347 for (std::string::size_type cc = 3; cc < args.size(); cc ++)
1350 command += args[cc];
1353 clock_t clock_start, clock_finish;
1354 time_t time_start, time_finish;
1357 clock_start = clock();
1359 cmSystemTools::RunSingleCommand(command.c_str(), 0, &ret);
1361 clock_finish = clock();
1364 double clocks_per_sec = static_cast<double>(CLOCKS_PER_SEC);
1365 std::cout << "Elapsed time: "
1366 << static_cast<long>(time_finish - time_start) << " s. (time)"
1368 << static_cast<double>(clock_finish - clock_start) / clocks_per_sec
1373 // Command to calculate the md5sum of a file
1374 else if (args[1] == "md5sum" && args.size() >= 3)
1378 for (std::string::size_type cc = 2; cc < args.size(); cc ++)
1380 const char *filename = args[cc].c_str();
1381 // Cannot compute md5sum of a directory
1382 if(cmSystemTools::FileIsDirectory(filename))
1384 std::cerr << "Error: " << filename << " is a directory" << std::endl;
1387 else if(!cmSystemTools::ComputeFileMD5(filename, md5out))
1389 // To mimic md5sum behavior in a shell:
1390 std::cerr << filename << ": No such file or directory" << std::endl;
1395 std::cout << std::string(md5out,32) << " " << filename << std::endl;
1401 // Command to change directory and run a program.
1402 else if (args[1] == "chdir" && args.size() >= 4)
1404 std::string directory = args[2];
1405 if(!cmSystemTools::FileExists(directory.c_str()))
1407 cmSystemTools::Error("Directory does not exist for chdir command: ",
1412 std::string command = "\"";
1415 for (std::string::size_type cc = 4; cc < args.size(); cc ++)
1418 command += args[cc];
1423 if ( cmSystemTools::RunSingleCommand(command.c_str(), 0, &retval,
1424 directory.c_str(), cmSystemTools::OUTPUT_MERGE, timeout) )
1432 // Command to start progress for a build
1433 else if (args[1] == "cmake_progress_start" && args.size() == 4)
1435 // basically remove the directory
1436 std::string dirName = args[2];
1437 dirName += "/Progress";
1438 cmSystemTools::RemoveADirectory(dirName.c_str());
1440 // is the last argument a filename that exists?
1441 FILE *countFile = fopen(args[3].c_str(),"r");
1445 if (1!=fscanf(countFile,"%i",&count))
1447 cmSystemTools::Message("Could not read from count file.");
1453 count = atoi(args[3].c_str());
1457 cmSystemTools::MakeDirectory(dirName.c_str());
1458 // write the count into the directory
1459 std::string fName = dirName;
1460 fName += "/count.txt";
1461 FILE *progFile = fopen(fName.c_str(),"w");
1464 fprintf(progFile,"%i\n",count);
1471 // Command to report progress for a build
1472 else if (args[1] == "cmake_progress_report" && args.size() >= 3)
1474 std::string dirName = args[2];
1475 dirName += "/Progress";
1481 fName += "/count.txt";
1482 progFile = fopen(fName.c_str(),"r");
1490 if (1!=fscanf(progFile,"%i",&count))
1492 cmSystemTools::Message("Could not read from progress file.");
1497 for (i = 3; i < args.size(); ++i)
1502 progFile = fopen(fName.c_str(),"w");
1505 fprintf(progFile,"empty");
1509 int fileNum = static_cast<int>
1510 (cmsys::Directory::GetNumberOfFilesInDirectory(dirName.c_str()));
1513 // print the progress
1514 fprintf(stdout,"[%3i%%] ",((fileNum-3)*100)/count);
1519 // Command to create a symbolic link. Fails on platforms not
1521 else if (args[1] == "create_symlink" && args.size() == 4)
1523 const char* destinationFileName = args[3].c_str();
1524 if ( cmSystemTools::FileExists(destinationFileName) )
1526 if ( cmSystemTools::FileIsSymlink(destinationFileName) )
1528 if ( !cmSystemTools::RemoveFile(destinationFileName) ||
1529 cmSystemTools::FileExists(destinationFileName) )
1539 return cmSystemTools::CreateSymlink(args[2].c_str(),
1540 args[3].c_str())? 0:1;
1543 // Internal CMake shared library support.
1544 else if (args[1] == "cmake_symlink_library" && args.size() == 5)
1546 return cmake::SymlinkLibrary(args);
1548 // Internal CMake versioned executable support.
1549 else if (args[1] == "cmake_symlink_executable" && args.size() == 4)
1551 return cmake::SymlinkExecutable(args);
1554 #if defined(CMAKE_HAVE_VS_GENERATORS)
1555 // Internal CMake support for calling Visual Studio macros.
1556 else if (args[1] == "cmake_call_visual_studio_macro" && args.size() >= 4)
1558 // args[2] = full path to .sln file or "ALL"
1559 // args[3] = name of Visual Studio macro to call
1560 // args[4..args.size()-1] = [optional] args for Visual Studio macro
1562 std::string macroArgs;
1564 if (args.size() > 4)
1566 macroArgs = args[4];
1568 for (size_t i = 5; i < args.size(); ++i)
1571 macroArgs += args[i];
1575 return cmCallVisualStudioMacro::CallMacro(args[2], args[3],
1580 // Internal CMake dependency scanning support.
1581 else if (args[1] == "cmake_depends" && args.size() >= 6)
1583 // Use the make system's VERBOSE environment variable to enable
1584 // verbose output. This can be skipped by also setting CMAKE_NO_VERBOSE
1585 // (which is set by the Eclipse and KDevelop generators).
1586 bool verbose = ((cmSystemTools::GetEnv("VERBOSE") != 0)
1587 && (cmSystemTools::GetEnv("CMAKE_NO_VERBOSE") == 0));
1589 // Create a cmake object instance to process dependencies.
1592 std::string homeDir;
1593 std::string startDir;
1594 std::string homeOutDir;
1595 std::string startOutDir;
1596 std::string depInfo;
1598 if(args.size() >= 8)
1602 // -E cmake_depends <generator>
1603 // <home-src-dir> <start-src-dir>
1604 // <home-out-dir> <start-out-dir>
1605 // <dep-info> [--color=$(COLOR)]
1607 // All paths are provided.
1611 homeOutDir = args[5];
1612 startOutDir = args[6];
1614 if(args.size() >= 9 &&
1615 args[8].length() >= 8 &&
1616 args[8].substr(0, 8) == "--color=")
1618 // Enable or disable color based on the switch value.
1619 color = (args[8].size() == 8 ||
1620 cmSystemTools::IsOn(args[8].substr(8).c_str()));
1625 // Support older signature for existing makefiles:
1627 // -E cmake_depends <generator>
1628 // <home-out-dir> <start-out-dir>
1631 // Just pretend the source directories are the same as the
1632 // binary directories so at least scanning will work.
1636 homeOutDir = args[3];
1637 startOutDir = args[3];
1641 // Create a local generator configured for the directory in
1642 // which dependencies will be scanned.
1643 homeDir = cmSystemTools::CollapseFullPath(homeDir.c_str());
1644 startDir = cmSystemTools::CollapseFullPath(startDir.c_str());
1645 homeOutDir = cmSystemTools::CollapseFullPath(homeOutDir.c_str());
1646 startOutDir = cmSystemTools::CollapseFullPath(startOutDir.c_str());
1647 cm.SetHomeDirectory(homeDir.c_str());
1648 cm.SetStartDirectory(startDir.c_str());
1649 cm.SetHomeOutputDirectory(homeOutDir.c_str());
1650 cm.SetStartOutputDirectory(startOutDir.c_str());
1651 if(cmGlobalGenerator* ggd = cm.CreateGlobalGenerator(gen.c_str()))
1653 cm.SetGlobalGenerator(ggd);
1654 std::auto_ptr<cmLocalGenerator> lgd(ggd->CreateLocalGenerator());
1655 lgd->GetMakefile()->SetStartDirectory(startDir.c_str());
1656 lgd->GetMakefile()->SetStartOutputDirectory(startOutDir.c_str());
1657 lgd->GetMakefile()->MakeStartDirectoriesCurrent();
1659 // Actually scan dependencies.
1660 return lgd->UpdateDependencies(depInfo.c_str(),
1661 verbose, color)? 0 : 2;
1666 // Internal CMake link script support.
1667 else if (args[1] == "cmake_link_script" && args.size() >= 3)
1669 return cmake::ExecuteLinkScript(args);
1672 // Internal CMake unimplemented feature notification.
1673 else if (args[1] == "cmake_unimplemented_variable")
1675 std::cerr << "Feature not implemented for this platform.";
1676 if(args.size() == 3)
1678 std::cerr << " Variable " << args[2] << " is not set.";
1680 std::cerr << std::endl;
1683 else if (args[1] == "vs_link_exe")
1685 return cmake::VisualStudioLink(args, 1);
1687 else if (args[1] == "vs_link_dll")
1689 return cmake::VisualStudioLink(args, 2);
1691 #ifdef CMAKE_BUILD_WITH_CMAKE
1692 // Internal CMake color makefile support.
1693 else if (args[1] == "cmake_echo_color")
1695 return cmake::ExecuteEchoColor(args);
1697 else if (args[1] == "cmake_automoc")
1699 cmQtAutomoc automoc;
1700 bool automocSuccess = automoc.Run(args[2].c_str());
1701 return automocSuccess ? 0 : 1;
1706 else if (args[1] == "tar" && args.size() > 3)
1708 std::string flags = args[2];
1709 std::string outFile = args[3];
1710 std::vector<cmStdString> files;
1711 for (std::string::size_type cc = 4; cc < args.size(); cc ++)
1713 files.push_back(args[cc]);
1717 bool verbose = false;
1718 if ( flags.find_first_of('j') != flags.npos )
1722 if ( flags.find_first_of('z') != flags.npos )
1726 if ( flags.find_first_of('v') != flags.npos )
1731 if ( flags.find_first_of('t') != flags.npos )
1733 if ( !cmSystemTools::ListTar(outFile.c_str(), gzip, verbose) )
1735 cmSystemTools::Error("Problem creating tar: ", outFile.c_str());
1739 else if ( flags.find_first_of('c') != flags.npos )
1741 if ( !cmSystemTools::CreateTar(
1742 outFile.c_str(), files, gzip, bzip2, verbose) )
1744 cmSystemTools::Error("Problem creating tar: ", outFile.c_str());
1748 else if ( flags.find_first_of('x') != flags.npos )
1750 if ( !cmSystemTools::ExtractTar(
1751 outFile.c_str(), gzip, verbose) )
1753 cmSystemTools::Error("Problem extracting tar: ", outFile.c_str());
1757 // OK, on windows 7 after we untar some files,
1758 // sometimes we can not rename the directory after
1759 // the untar is done. This breaks the external project
1760 // untar and rename code. So, by default we will wait
1761 // 1/10th of a second after the untar. If CMAKE_UNTAR_DELAY
1762 // is set in the env, its value will be used instead of 100.
1764 const char* delayVar = cmSystemTools::GetEnv("CMAKE_UNTAR_DELAY");
1767 delay = atoi(delayVar);
1771 cmSystemTools::Delay(delay);
1778 #if defined(CMAKE_BUILD_WITH_CMAKE)
1779 // Internal CMake Fortran module support.
1780 else if (args[1] == "cmake_copy_f90_mod" && args.size() >= 4)
1782 return cmDependsFortran::CopyModule(args)? 0 : 1;
1786 #if defined(_WIN32) && !defined(__CYGWIN__)
1787 // Write registry value
1788 else if (args[1] == "write_regv" && args.size() > 3)
1790 return cmSystemTools::WriteRegistryValue(args[2].c_str(),
1791 args[3].c_str()) ? 0 : 1;
1794 // Delete registry value
1795 else if (args[1] == "delete_regv" && args.size() > 2)
1797 return cmSystemTools::DeleteRegistryValue(args[2].c_str()) ? 0 : 1;
1800 else if (args[1] == "comspec" && args.size() > 2)
1803 std::string command = args[2];
1804 for ( cc = 3; cc < args.size(); cc ++ )
1806 command += " " + args[cc];
1808 return cmWin32ProcessExecution::Windows9xHack(command.c_str());
1813 ::CMakeCommandUsage(args[0].c_str());
1817 void cmake::AddExtraGenerator(const char* name,
1818 CreateExtraGeneratorFunctionType newFunction)
1820 cmExternalMakefileProjectGenerator* extraGenerator = newFunction();
1821 const std::vector<std::string>& supportedGlobalGenerators =
1822 extraGenerator->GetSupportedGlobalGenerators();
1824 for(std::vector<std::string>::const_iterator
1825 it = supportedGlobalGenerators.begin();
1826 it != supportedGlobalGenerators.end();
1829 std::string fullName = cmExternalMakefileProjectGenerator::
1830 CreateFullGeneratorName(it->c_str(), name);
1831 this->ExtraGenerators[fullName.c_str()] = newFunction;
1833 delete extraGenerator;
1836 void cmake::AddDefaultExtraGenerators()
1838 #if defined(CMAKE_BUILD_WITH_CMAKE)
1839 #if defined(_WIN32) && !defined(__CYGWIN__)
1843 this->AddExtraGenerator(cmExtraCodeBlocksGenerator::GetActualName(),
1844 &cmExtraCodeBlocksGenerator::New);
1846 #ifdef CMAKE_USE_ECLIPSE
1847 this->AddExtraGenerator(cmExtraEclipseCDT4Generator::GetActualName(),
1848 &cmExtraEclipseCDT4Generator::New);
1851 #ifdef CMAKE_USE_KDEVELOP
1852 this->AddExtraGenerator(cmGlobalKdevelopGenerator::GetActualName(),
1853 &cmGlobalKdevelopGenerator::New);
1854 // for kdevelop also add the generator with just the name of the
1855 // extra generator, since it was this way since cmake 2.2
1856 this->ExtraGenerators[cmGlobalKdevelopGenerator::GetActualName()]
1857 = &cmGlobalKdevelopGenerator::New;
1864 //----------------------------------------------------------------------------
1865 void cmake::GetRegisteredGenerators(std::vector<std::string>& names)
1867 for(RegisteredGeneratorsMap::const_iterator i = this->Generators.begin();
1868 i != this->Generators.end(); ++i)
1870 names.push_back(i->first);
1872 for(RegisteredExtraGeneratorsMap::const_iterator
1873 i = this->ExtraGenerators.begin();
1874 i != this->ExtraGenerators.end(); ++i)
1876 names.push_back(i->first);
1880 cmGlobalGenerator* cmake::CreateGlobalGenerator(const char* name)
1882 cmGlobalGenerator* generator = 0;
1883 cmExternalMakefileProjectGenerator* extraGenerator = 0;
1884 RegisteredGeneratorsMap::const_iterator genIt = this->Generators.find(name);
1885 if(genIt == this->Generators.end())
1887 RegisteredExtraGeneratorsMap::const_iterator extraGenIt =
1888 this->ExtraGenerators.find(name);
1889 if (extraGenIt == this->ExtraGenerators.end())
1893 extraGenerator = (extraGenIt->second)();
1894 genIt=this->Generators.find(extraGenerator->GetGlobalGeneratorName(name));
1895 if(genIt == this->Generators.end())
1897 delete extraGenerator;
1902 generator = (genIt->second)();
1903 generator->SetCMakeInstance(this);
1904 generator->SetExternalMakefileProjectGenerator(extraGenerator);
1908 void cmake::SetHomeDirectory(const char* dir)
1910 this->cmHomeDirectory = dir;
1911 cmSystemTools::ConvertToUnixSlashes(this->cmHomeDirectory);
1914 void cmake::SetHomeOutputDirectory(const char* lib)
1916 this->HomeOutputDirectory = lib;
1917 cmSystemTools::ConvertToUnixSlashes(this->HomeOutputDirectory);
1920 void cmake::SetGlobalGenerator(cmGlobalGenerator *gg)
1924 cmSystemTools::Error("Error SetGlobalGenerator called with null");
1927 // delete the old generator
1928 if (this->GlobalGenerator)
1930 delete this->GlobalGenerator;
1931 // restore the original environment variables CXX and CC
1933 std::string env = "CC=";
1934 if(this->CCEnvironment.size())
1936 env += this->CCEnvironment;
1938 cmSystemTools::PutEnv(env.c_str());
1940 if(this->CXXEnvironment.size())
1942 env += this->CXXEnvironment;
1944 cmSystemTools::PutEnv(env.c_str());
1948 this->GlobalGenerator = gg;
1950 // set the global flag for unix style paths on cmSystemTools as soon as
1951 // the generator is set. This allows gmake to be used on windows.
1952 cmSystemTools::SetForceUnixPaths
1953 (this->GlobalGenerator->GetForceUnixPaths());
1955 // Save the environment variables CXX and CC
1956 const char* cxx = getenv("CXX");
1957 const char* cc = getenv("CC");
1960 this->CXXEnvironment = cxx;
1964 this->CXXEnvironment = "";
1968 this->CCEnvironment = cc;
1972 this->CCEnvironment = "";
1974 // set the cmake instance just to be sure
1975 gg->SetCMakeInstance(this);
1978 int cmake::DoPreConfigureChecks()
1980 // Make sure the Start directory contains a CMakeLists.txt file.
1981 std::string srcList = this->GetHomeDirectory();
1982 srcList += "/CMakeLists.txt";
1983 if(!cmSystemTools::FileExists(srcList.c_str()))
1985 cmOStringStream err;
1986 if(cmSystemTools::FileIsDirectory(this->GetHomeDirectory()))
1988 err << "The source directory \"" << this->GetHomeDirectory()
1989 << "\" does not appear to contain CMakeLists.txt.\n";
1991 else if(cmSystemTools::FileExists(this->GetHomeDirectory()))
1993 err << "The source directory \"" << this->GetHomeDirectory()
1994 << "\" is a file, not a directory.\n";
1998 err << "The source directory \"" << this->GetHomeDirectory()
1999 << "\" does not exist.\n";
2001 err << "Specify --help for usage, or press the help button on the CMake "
2003 cmSystemTools::Error(err.str().c_str());
2007 // do a sanity check on some values
2008 if(this->CacheManager->GetCacheValue("CMAKE_HOME_DIRECTORY"))
2010 std::string cacheStart =
2011 this->CacheManager->GetCacheValue("CMAKE_HOME_DIRECTORY");
2012 cacheStart += "/CMakeLists.txt";
2013 std::string currentStart = this->GetHomeDirectory();
2014 currentStart += "/CMakeLists.txt";
2015 if(!cmSystemTools::SameFile(cacheStart.c_str(), currentStart.c_str()))
2017 std::string message = "The source \"";
2018 message += currentStart;
2019 message += "\" does not match the source \"";
2020 message += cacheStart;
2021 message += "\" used to generate cache. ";
2022 message += "Re-run cmake with a different source directory.";
2023 cmSystemTools::Error(message.c_str());
2033 struct SaveCacheEntry
2038 cmCacheManager::CacheEntryType type;
2041 int cmake::HandleDeleteCacheVariables(const char* var)
2043 std::vector<std::string> argsSplit;
2044 cmSystemTools::ExpandListArgument(std::string(var), argsSplit);
2045 // erase the property to avoid infinite recursion
2046 this->SetProperty("__CMAKE_DELETE_CACHE_CHANGE_VARS_", "");
2047 if(this->GetIsInTryCompile())
2051 cmCacheManager::CacheIterator ci = this->CacheManager->NewIterator();
2052 std::vector<SaveCacheEntry> saved;
2053 cmOStringStream warning;
2055 << "You have changed variables that require your cache to be deleted.\n"
2056 << "Configure will be re-run and you may have to reset some variables.\n"
2057 << "The following variables have changed:\n";
2058 for(std::vector<std::string>::iterator i = argsSplit.begin();
2059 i != argsSplit.end(); ++i)
2061 SaveCacheEntry save;
2063 warning << *i << "= ";
2066 warning << *i << "\n";
2067 if(ci.Find(save.key.c_str()))
2069 save.type = ci.GetType();
2070 save.help = ci.GetProperty("HELPSTRING");
2072 saved.push_back(save);
2076 this->CacheManager->DeleteCache(this->GetStartOutputDirectory());
2077 // load the empty cache
2079 // restore the changed compilers
2080 for(std::vector<SaveCacheEntry>::iterator i = saved.begin();
2081 i != saved.end(); ++i)
2083 this->AddCacheEntry(i->key.c_str(), i->value.c_str(),
2084 i->help.c_str(), i->type);
2086 cmSystemTools::Message(warning.str().c_str());
2087 // avoid reconfigure if there were errors
2088 if(!cmSystemTools::GetErrorOccuredFlag())
2091 return this->Configure();
2096 int cmake::Configure()
2098 if(this->DoSuppressDevWarnings)
2100 if(this->SuppressDevWarnings)
2102 this->CacheManager->
2103 AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS", "TRUE",
2104 "Suppress Warnings that are meant for"
2105 " the author of the CMakeLists.txt files.",
2106 cmCacheManager::INTERNAL);
2110 this->CacheManager->
2111 AddCacheEntry("CMAKE_SUPPRESS_DEVELOPER_WARNINGS", "FALSE",
2112 "Suppress Warnings that are meant for"
2113 " the author of the CMakeLists.txt files.",
2114 cmCacheManager::INTERNAL);
2117 int ret = this->ActualConfigure();
2118 const char* delCacheVars =
2119 this->GetProperty("__CMAKE_DELETE_CACHE_CHANGE_VARS_");
2120 if(delCacheVars && delCacheVars[0] != 0)
2122 return this->HandleDeleteCacheVariables(delCacheVars);
2128 int cmake::ActualConfigure()
2130 // Construct right now our path conversion table before it's too late:
2131 this->UpdateConversionPathTable();
2132 this->CleanupCommandsAndMacros();
2135 if ( this->GetWorkingMode() == NORMAL_MODE )
2137 res = this->DoPreConfigureChecks();
2145 this->CacheManager->AddCacheEntry
2146 ("CMAKE_HOME_DIRECTORY",
2147 this->GetHomeDirectory(),
2148 "Start directory with the top level CMakeLists.txt file for this "
2150 cmCacheManager::INTERNAL);
2153 // no generator specified on the command line
2154 if(!this->GlobalGenerator)
2156 const char* genName =
2157 this->CacheManager->GetCacheValue("CMAKE_GENERATOR");
2158 const char* extraGenName =
2159 this->CacheManager->GetCacheValue("CMAKE_EXTRA_GENERATOR");
2162 std::string fullName = cmExternalMakefileProjectGenerator::
2163 CreateFullGeneratorName(genName, extraGenName);
2164 this->GlobalGenerator = this->CreateGlobalGenerator(fullName.c_str());
2166 if(this->GlobalGenerator)
2168 // set the global flag for unix style paths on cmSystemTools as
2169 // soon as the generator is set. This allows gmake to be used
2171 cmSystemTools::SetForceUnixPaths
2172 (this->GlobalGenerator->GetForceUnixPaths());
2176 #if defined(__BORLANDC__) && defined(_WIN32)
2177 this->SetGlobalGenerator(new cmGlobalBorlandMakefileGenerator);
2178 #elif defined(_WIN32) && !defined(__CYGWIN__) && !defined(CMAKE_BOOT_MINGW)
2179 std::string installedCompiler;
2180 // Try to find the newest VS installed on the computer and
2181 // use that as a default if -G is not specified
2182 const std::string vsregBase =
2183 "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\";
2184 std::vector<std::string> vsVerions;
2185 vsVerions.push_back("VisualStudio\\");
2186 vsVerions.push_back("VCExpress\\");
2187 struct VSRegistryEntryName
2189 const char* MSVersion;
2190 const char* GeneratorName;
2192 VSRegistryEntryName version[] = {
2193 {"6.0", "Visual Studio 6"},
2194 {"7.0", "Visual Studio 7"},
2195 {"7.1", "Visual Studio 7 .NET 2003"},
2196 {"8.0", "Visual Studio 8 2005"},
2197 {"9.0", "Visual Studio 9 2008"},
2198 {"10.0", "Visual Studio 10"},
2200 for(size_t b=0; b < vsVerions.size() && installedCompiler.empty(); b++)
2202 for(int i =0; version[i].MSVersion != 0; i++)
2204 std::string reg = vsregBase + vsVerions[b] + version[i].MSVersion;
2205 reg += ";InstallDir]";
2206 cmSystemTools::ExpandRegistryValues(reg,
2207 cmSystemTools::KeyWOW64_32);
2208 if (!(reg == "/registry"))
2210 installedCompiler = version[i].GeneratorName;
2214 cmGlobalGenerator* gen
2215 = this->CreateGlobalGenerator(installedCompiler.c_str());
2218 gen = new cmGlobalNMakeMakefileGenerator;
2220 this->SetGlobalGenerator(gen);
2221 std::cout << "-- Building for: " << gen->GetName() << "\n";
2223 this->SetGlobalGenerator(new cmGlobalUnixMakefileGenerator3);
2226 if(!this->GlobalGenerator)
2228 cmSystemTools::Error("Could not create generator");
2233 const char* genName = this->CacheManager->GetCacheValue("CMAKE_GENERATOR");
2236 if(strcmp(this->GlobalGenerator->GetName(), genName) != 0)
2238 std::string message = "Error: generator : ";
2239 message += this->GlobalGenerator->GetName();
2240 message += "\nDoes not match the generator used previously: ";
2243 "\nEither remove the CMakeCache.txt file or choose a different"
2244 " binary directory.";
2245 cmSystemTools::Error(message.c_str());
2249 if(!this->CacheManager->GetCacheValue("CMAKE_GENERATOR"))
2251 this->CacheManager->AddCacheEntry("CMAKE_GENERATOR",
2252 this->GlobalGenerator->GetName(),
2253 "Name of generator.",
2254 cmCacheManager::INTERNAL);
2255 this->CacheManager->AddCacheEntry("CMAKE_EXTRA_GENERATOR",
2256 this->GlobalGenerator->GetExtraGeneratorName(),
2257 "Name of external makefile project generator.",
2258 cmCacheManager::INTERNAL);
2261 // reset any system configuration information, except for when we are
2262 // InTryCompile. With TryCompile the system info is taken from the parent's
2263 // info to save time
2264 if (!this->InTryCompile)
2266 this->GlobalGenerator->ClearEnabledLanguages();
2269 // Truncate log files
2270 if (!this->InTryCompile)
2272 this->TruncateOutputLog("CMakeOutput.log");
2273 this->TruncateOutputLog("CMakeError.log");
2276 // actually do the configure
2277 this->GlobalGenerator->Configure();
2278 // Before saving the cache
2279 // if the project did not define one of the entries below, add them now
2280 // so users can edit the values in the cache:
2282 // We used to always present LIBRARY_OUTPUT_PATH and
2283 // EXECUTABLE_OUTPUT_PATH. They are now documented as old-style and
2284 // should no longer be used. Therefore we present them only if the
2285 // project requires compatibility with CMake 2.4. We detect this
2286 // here by looking for the old CMAKE_BACKWARDS_COMPATABILITY
2287 // variable created when CMP0001 is not set to NEW.
2288 if(this->GetCacheManager()->GetCacheValue("CMAKE_BACKWARDS_COMPATIBILITY"))
2290 if(!this->CacheManager->GetCacheValue("LIBRARY_OUTPUT_PATH"))
2292 this->CacheManager->AddCacheEntry
2293 ("LIBRARY_OUTPUT_PATH", "",
2294 "Single output directory for building all libraries.",
2295 cmCacheManager::PATH);
2297 if(!this->CacheManager->GetCacheValue("EXECUTABLE_OUTPUT_PATH"))
2299 this->CacheManager->AddCacheEntry
2300 ("EXECUTABLE_OUTPUT_PATH", "",
2301 "Single output directory for building all executables.",
2302 cmCacheManager::PATH);
2305 if(!this->CacheManager->GetCacheValue("CMAKE_USE_RELATIVE_PATHS"))
2307 this->CacheManager->AddCacheEntry
2308 ("CMAKE_USE_RELATIVE_PATHS", "OFF",
2309 "If true, cmake will use relative paths in makefiles and projects.",
2310 cmCacheManager::BOOL);
2311 cmCacheManager::CacheIterator it =
2312 this->CacheManager->GetCacheIterator("CMAKE_USE_RELATIVE_PATHS");
2313 if ( !it.PropertyExists("ADVANCED") )
2315 it.SetProperty("ADVANCED", "1");
2319 if(cmSystemTools::GetFatalErrorOccured() &&
2320 (!this->CacheManager->GetCacheValue("CMAKE_MAKE_PROGRAM") ||
2321 cmSystemTools::IsOff(this->CacheManager->
2322 GetCacheValue("CMAKE_MAKE_PROGRAM"))))
2324 // We must have a bad generator selection. Wipe the cache entry so the
2325 // user can select another.
2326 this->CacheManager->RemoveCacheEntry("CMAKE_GENERATOR");
2327 this->CacheManager->RemoveCacheEntry("CMAKE_EXTRA_GENERATOR");
2329 // only save the cache if there were no fatal errors
2330 if ( this->GetWorkingMode() == NORMAL_MODE )
2332 this->CacheManager->SaveCache(this->GetHomeOutputDirectory());
2334 if ( !this->GraphVizFile.empty() )
2336 std::cout << "Generate graphviz: " << this->GraphVizFile << std::endl;
2337 this->GenerateGraphViz(this->GraphVizFile.c_str());
2339 if(cmSystemTools::GetErrorOccuredFlag())
2346 void cmake::PreLoadCMakeFiles()
2348 std::vector<std::string> args;
2349 std::string pre_load = this->GetHomeDirectory();
2350 if ( pre_load.size() > 0 )
2352 pre_load += "/PreLoad.cmake";
2353 if ( cmSystemTools::FileExists(pre_load.c_str()) )
2355 this->ReadListFile(args, pre_load.c_str());
2358 pre_load = this->GetHomeOutputDirectory();
2359 if ( pre_load.size() > 0 )
2361 pre_load += "/PreLoad.cmake";
2362 if ( cmSystemTools::FileExists(pre_load.c_str()) )
2364 this->ReadListFile(args, pre_load.c_str());
2369 // handle a command line invocation
2370 int cmake::Run(const std::vector<std::string>& args, bool noconfigure)
2372 // Process the arguments
2373 this->SetArgs(args);
2374 if(cmSystemTools::GetErrorOccuredFlag())
2379 // If we are given a stamp list file check if it is really out of date.
2380 if(!this->CheckStampList.empty() &&
2381 cmakeCheckStampList(this->CheckStampList.c_str()))
2386 // If we are given a stamp file check if it is really out of date.
2387 if(!this->CheckStampFile.empty() &&
2388 cmakeCheckStampFile(this->CheckStampFile.c_str()))
2393 // set the cmake command
2394 this->CMakeCommand = args[0];
2396 if ( this->GetWorkingMode() == NORMAL_MODE )
2399 if(this->LoadCache() < 0)
2401 cmSystemTools::Error("Error executing cmake::LoadCache(). Aborting.\n");
2407 this->AddCMakePaths();
2409 // Add any cache args
2410 if ( !this->SetCacheArgs(args) )
2412 cmSystemTools::Error("Problem processing arguments. Aborting.\n");
2416 // In script mode we terminate after running the script.
2417 if(this->GetWorkingMode() != NORMAL_MODE)
2419 if(cmSystemTools::GetErrorOccuredFlag())
2429 // If MAKEFLAGS are given in the environment, remove the environment
2430 // variable. This will prevent try-compile from succeeding when it
2431 // should fail (if "-i" is an option). We cannot simply test
2432 // whether "-i" is given and remove it because some make programs
2433 // encode the MAKEFLAGS variable in a strange way.
2434 if(getenv("MAKEFLAGS"))
2436 cmSystemTools::PutEnv("MAKEFLAGS=");
2439 this->PreLoadCMakeFiles();
2441 std::string systemFile = this->GetHomeOutputDirectory();
2442 systemFile += "/CMakeSystem.cmake";
2449 // now run the global generate
2450 // Check the state of the build system to see if we need to regenerate.
2451 if(!this->CheckBuildSystem())
2456 // If we are doing global generate, we better set start and start
2457 // output directory to the root of the project.
2458 std::string oldstartdir = this->GetStartDirectory();
2459 std::string oldstartoutputdir = this->GetStartOutputDirectory();
2460 this->SetStartDirectory(this->GetHomeDirectory());
2461 this->SetStartOutputDirectory(this->GetHomeOutputDirectory());
2462 int ret = this->Configure();
2463 if (ret || this->GetWorkingMode() != NORMAL_MODE)
2465 #if defined(CMAKE_HAVE_VS_GENERATORS)
2466 if(!this->VSSolutionFile.empty() && this->GlobalGenerator)
2468 // CMake is running to regenerate a Visual Studio build tree
2469 // during a build from the VS IDE. The build files cannot be
2470 // regenerated, so we should stop the build.
2471 cmSystemTools::Message(
2472 "CMake Configure step failed. "
2473 "Build files cannot be regenerated correctly. "
2474 "Attempting to stop IDE build.");
2475 cmGlobalVisualStudioGenerator* gg =
2476 static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator);
2477 gg->CallVisualStudioMacro(cmGlobalVisualStudioGenerator::MacroStop,
2478 this->VSSolutionFile.c_str());
2483 ret = this->Generate();
2484 std::string message = "Build files have been written to: ";
2485 message += this->GetHomeOutputDirectory();
2486 this->UpdateProgress(message.c_str(), -1);
2491 this->SetStartDirectory(oldstartdir.c_str());
2492 this->SetStartOutputDirectory(oldstartoutputdir.c_str());
2497 int cmake::Generate()
2499 if(!this->GlobalGenerator)
2503 this->GlobalGenerator->Generate();
2504 if(this->WarnUnusedCli)
2506 this->RunCheckForUnusedVariables();
2508 if(cmSystemTools::GetErrorOccuredFlag())
2512 if (this->GetProperty("REPORT_UNDEFINED_PROPERTIES"))
2514 this->ReportUndefinedPropertyAccesses
2515 (this->GetProperty("REPORT_UNDEFINED_PROPERTIES"));
2517 // Save the cache again after a successful Generate so that any internal
2518 // variables created during Generate are saved. (Specifically target GUIDs
2519 // for the Visual Studio and Xcode generators.)
2520 if ( this->GetWorkingMode() == NORMAL_MODE )
2522 this->CacheManager->SaveCache(this->GetHomeOutputDirectory());
2527 void cmake::AddCacheEntry(const char* key, const char* value,
2528 const char* helpString,
2531 this->CacheManager->AddCacheEntry(key, value,
2533 cmCacheManager::CacheEntryType(type));
2536 const char* cmake::GetCacheDefinition(const char* name) const
2538 return this->CacheManager->GetCacheValue(name);
2541 void cmake::AddDefaultCommands()
2543 std::list<cmCommand*> commands;
2544 GetBootstrapCommands(commands);
2545 GetPredefinedCommands(commands);
2546 for(std::list<cmCommand*>::iterator i = commands.begin();
2547 i != commands.end(); ++i)
2549 this->AddCommand(*i);
2553 void cmake::AddDefaultGenerators()
2555 #if defined(_WIN32) && !defined(__CYGWIN__)
2556 # if !defined(CMAKE_BOOT_MINGW)
2557 this->Generators[cmGlobalVisualStudio6Generator::GetActualName()] =
2558 &cmGlobalVisualStudio6Generator::New;
2559 this->Generators[cmGlobalVisualStudio7Generator::GetActualName()] =
2560 &cmGlobalVisualStudio7Generator::New;
2561 this->Generators[cmGlobalVisualStudio10Generator::GetActualName()] =
2562 &cmGlobalVisualStudio10Generator::New;
2563 this->Generators[cmGlobalVisualStudio10IA64Generator::GetActualName()] =
2564 &cmGlobalVisualStudio10IA64Generator::New;
2565 this->Generators[cmGlobalVisualStudio10Win64Generator::GetActualName()] =
2566 &cmGlobalVisualStudio10Win64Generator::New;
2567 this->Generators[cmGlobalVisualStudio11Generator::GetActualName()] =
2568 &cmGlobalVisualStudio11Generator::New;
2569 this->Generators[cmGlobalVisualStudio11Win64Generator::GetActualName()] =
2570 &cmGlobalVisualStudio11Win64Generator::New;
2571 this->Generators[cmGlobalVisualStudio11ARMGenerator::GetActualName()] =
2572 &cmGlobalVisualStudio11ARMGenerator::New;
2573 this->Generators[cmGlobalVisualStudio71Generator::GetActualName()] =
2574 &cmGlobalVisualStudio71Generator::New;
2575 this->Generators[cmGlobalVisualStudio8Generator::GetActualName()] =
2576 &cmGlobalVisualStudio8Generator::New;
2577 this->Generators[cmGlobalVisualStudio9Generator::GetActualName()] =
2578 &cmGlobalVisualStudio9Generator::New;
2579 this->Generators[cmGlobalVisualStudio9IA64Generator::GetActualName()] =
2580 &cmGlobalVisualStudio9IA64Generator::New;
2581 this->Generators[cmGlobalVisualStudio9Win64Generator::GetActualName()] =
2582 &cmGlobalVisualStudio9Win64Generator::New;
2583 this->Generators[cmGlobalVisualStudio8Win64Generator::GetActualName()] =
2584 &cmGlobalVisualStudio8Win64Generator::New;
2585 this->Generators[cmGlobalBorlandMakefileGenerator::GetActualName()] =
2586 &cmGlobalBorlandMakefileGenerator::New;
2587 this->Generators[cmGlobalNMakeMakefileGenerator::GetActualName()] =
2588 &cmGlobalNMakeMakefileGenerator::New;
2589 this->Generators[cmGlobalJOMMakefileGenerator::GetActualName()] =
2590 &cmGlobalJOMMakefileGenerator::New;
2591 this->Generators[cmGlobalWatcomWMakeGenerator::GetActualName()] =
2592 &cmGlobalWatcomWMakeGenerator::New;
2594 this->Generators[cmGlobalMSYSMakefileGenerator::GetActualName()] =
2595 &cmGlobalMSYSMakefileGenerator::New;
2596 this->Generators[cmGlobalMinGWMakefileGenerator::GetActualName()] =
2597 &cmGlobalMinGWMakefileGenerator::New;
2599 this->Generators[cmGlobalUnixMakefileGenerator3::GetActualName()] =
2600 &cmGlobalUnixMakefileGenerator3::New;
2601 this->Generators[cmGlobalNinjaGenerator::GetActualName()] =
2602 &cmGlobalNinjaGenerator::New;
2603 #ifdef CMAKE_USE_XCODE
2604 this->Generators[cmGlobalXCodeGenerator::GetActualName()] =
2605 &cmGlobalXCodeGenerator::New;
2609 int cmake::LoadCache()
2611 // could we not read the cache
2612 if (!this->CacheManager->LoadCache(this->GetHomeOutputDirectory()))
2614 // if it does exist, but isn't readable then warn the user
2615 std::string cacheFile = this->GetHomeOutputDirectory();
2616 cacheFile += "/CMakeCache.txt";
2617 if(cmSystemTools::FileExists(cacheFile.c_str()))
2619 cmSystemTools::Error(
2620 "There is a CMakeCache.txt file for the current binary tree but "
2621 "cmake does not have permission to read it. Please check the "
2622 "permissions of the directory you are trying to run CMake on.");
2627 if (this->CMakeCommand.size() < 2)
2629 cmSystemTools::Error(
2630 "cmake command was not specified prior to loading the cache in "
2635 // setup CMAKE_ROOT and CMAKE_COMMAND
2636 if(!this->AddCMakePaths())
2643 void cmake::SetProgressCallback(ProgressCallbackType f, void *cd)
2645 this->ProgressCallback = f;
2646 this->ProgressCallbackClientData = cd;
2649 void cmake::UpdateProgress(const char *msg, float prog)
2651 if(this->ProgressCallback && !this->InTryCompile)
2653 (*this->ProgressCallback)(msg, prog, this->ProgressCallbackClientData);
2658 void cmake::GetCommandDocumentation(std::vector<cmDocumentationEntry>& v,
2659 bool withCurrentCommands,
2660 bool withCompatCommands) const
2662 for(RegisteredCommandsMap::const_iterator j = this->Commands.begin();
2663 j != this->Commands.end(); ++j)
2665 if ((( withCompatCommands == false) && ( (*j).second->IsDiscouraged()))
2666 || ((withCurrentCommands == false) && (!(*j).second->IsDiscouraged()))
2667 || (!((*j).second->ShouldAppearInDocumentation()))
2673 cmDocumentationEntry e((*j).second->GetName(),
2674 (*j).second->GetTerseDocumentation(),
2675 (*j).second->GetFullDocumentation());
2680 void cmake::GetPolicyDocumentation(std::vector<cmDocumentationEntry>& v)
2682 this->Policies->GetDocumentation(v);
2685 void cmake::GetPropertiesDocumentation(std::map<std::string,
2686 cmDocumentationSection *>& v)
2688 // loop over the properties and put them into the doc structure
2689 std::map<cmProperty::ScopeType, cmPropertyDefinitionMap>::iterator i;
2690 i = this->PropertyDefinitions.begin();
2691 for (;i != this->PropertyDefinitions.end(); ++i)
2693 i->second.GetPropertiesDocumentation(v);
2697 void cmake::GetGeneratorDocumentation(std::vector<cmDocumentationEntry>& v)
2699 for(RegisteredGeneratorsMap::const_iterator i = this->Generators.begin();
2700 i != this->Generators.end(); ++i)
2702 cmDocumentationEntry e;
2703 cmGlobalGenerator* generator = (i->second)();
2704 generator->GetDocumentation(e);
2708 for(RegisteredExtraGeneratorsMap::const_iterator
2709 i = this->ExtraGenerators.begin(); i != this->ExtraGenerators.end(); ++i)
2711 cmDocumentationEntry e;
2712 cmExternalMakefileProjectGenerator* generator = (i->second)();
2713 generator->GetDocumentation(e, i->first.c_str());
2720 void cmake::UpdateConversionPathTable()
2722 // Update the path conversion table with any specified file:
2723 const char* tablepath =
2724 this->CacheManager->GetCacheValue("CMAKE_PATH_TRANSLATION_FILE");
2728 std::ifstream table( tablepath );
2731 cmSystemTools::Error("CMAKE_PATH_TRANSLATION_FILE set to ", tablepath,
2732 ". CMake can not open file.");
2733 cmSystemTools::ReportLastSystemError("CMake can not open file.");
2740 // two entries per line
2741 table >> a; table >> b;
2742 cmSystemTools::AddTranslationPath( a.c_str(), b.c_str());
2748 //----------------------------------------------------------------------------
2749 int cmake::CheckBuildSystem()
2751 // We do not need to rerun CMake. Check dependency integrity. Use
2752 // the make system's VERBOSE environment variable to enable verbose
2753 // output. This can be skipped by setting CMAKE_NO_VERBOSE (which is set
2754 // by the Eclipse and KDevelop generators).
2755 bool verbose = ((cmSystemTools::GetEnv("VERBOSE") != 0)
2756 && (cmSystemTools::GetEnv("CMAKE_NO_VERBOSE") == 0));
2758 // This method will check the integrity of the build system if the
2759 // option was given on the command line. It reads the given file to
2760 // determine whether CMake should rerun.
2762 // If no file is provided for the check, we have to rerun.
2763 if(this->CheckBuildSystemArgument.size() == 0)
2767 cmOStringStream msg;
2768 msg << "Re-run cmake no build system arguments\n";
2769 cmSystemTools::Stdout(msg.str().c_str());
2774 // If the file provided does not exist, we have to rerun.
2775 if(!cmSystemTools::FileExists(this->CheckBuildSystemArgument.c_str()))
2779 cmOStringStream msg;
2780 msg << "Re-run cmake missing file: "
2781 << this->CheckBuildSystemArgument.c_str() << "\n";
2782 cmSystemTools::Stdout(msg.str().c_str());
2787 // Read the rerun check file and use it to decide whether to do the
2790 cmGlobalGenerator gg;
2791 gg.SetCMakeInstance(&cm);
2792 std::auto_ptr<cmLocalGenerator> lg(gg.CreateLocalGenerator());
2793 cmMakefile* mf = lg->GetMakefile();
2794 if(!mf->ReadListFile(0, this->CheckBuildSystemArgument.c_str()) ||
2795 cmSystemTools::GetErrorOccuredFlag())
2799 cmOStringStream msg;
2800 msg << "Re-run cmake error reading : "
2801 << this->CheckBuildSystemArgument.c_str() << "\n";
2802 cmSystemTools::Stdout(msg.str().c_str());
2804 // There was an error reading the file. Just rerun.
2808 if(this->ClearBuildSystem)
2810 // Get the generator used for this build system.
2811 const char* genName = mf->GetDefinition("CMAKE_DEPENDS_GENERATOR");
2812 if(!genName || genName[0] == '\0')
2814 genName = "Unix Makefiles";
2817 // Create the generator and use it to clear the dependencies.
2818 std::auto_ptr<cmGlobalGenerator>
2819 ggd(this->CreateGlobalGenerator(genName));
2822 std::auto_ptr<cmLocalGenerator> lgd(ggd->CreateLocalGenerator());
2823 lgd->ClearDependencies(mf, verbose);
2827 // If any byproduct of makefile generation is missing we must re-run.
2828 std::vector<std::string> products;
2829 if(const char* productStr = mf->GetDefinition("CMAKE_MAKEFILE_PRODUCTS"))
2831 cmSystemTools::ExpandListArgument(productStr, products);
2833 for(std::vector<std::string>::const_iterator pi = products.begin();
2834 pi != products.end(); ++pi)
2836 if(!(cmSystemTools::FileExists(pi->c_str()) ||
2837 cmSystemTools::FileIsSymlink(pi->c_str())))
2841 cmOStringStream msg;
2842 msg << "Re-run cmake, missing byproduct: " << *pi << "\n";
2843 cmSystemTools::Stdout(msg.str().c_str());
2849 // Get the set of dependencies and outputs.
2850 std::vector<std::string> depends;
2851 std::vector<std::string> outputs;
2852 const char* dependsStr = mf->GetDefinition("CMAKE_MAKEFILE_DEPENDS");
2853 const char* outputsStr = mf->GetDefinition("CMAKE_MAKEFILE_OUTPUTS");
2854 if(dependsStr && outputsStr)
2856 cmSystemTools::ExpandListArgument(dependsStr, depends);
2857 cmSystemTools::ExpandListArgument(outputsStr, outputs);
2859 if(depends.empty() || outputs.empty())
2861 // Not enough information was provided to do the test. Just rerun.
2864 cmOStringStream msg;
2865 msg << "Re-run cmake no CMAKE_MAKEFILE_DEPENDS "
2866 "or CMAKE_MAKEFILE_OUTPUTS :\n";
2867 cmSystemTools::Stdout(msg.str().c_str());
2872 // Find the newest dependency.
2873 std::vector<std::string>::iterator dep = depends.begin();
2874 std::string dep_newest = *dep++;
2875 for(;dep != depends.end(); ++dep)
2878 if(this->FileComparison->FileTimeCompare(dep_newest.c_str(),
2879 dep->c_str(), &result))
2890 cmOStringStream msg;
2891 msg << "Re-run cmake: build system dependency is missing\n";
2892 cmSystemTools::Stdout(msg.str().c_str());
2898 // Find the oldest output.
2899 std::vector<std::string>::iterator out = outputs.begin();
2900 std::string out_oldest = *out++;
2901 for(;out != outputs.end(); ++out)
2904 if(this->FileComparison->FileTimeCompare(out_oldest.c_str(),
2905 out->c_str(), &result))
2916 cmOStringStream msg;
2917 msg << "Re-run cmake: build system output is missing\n";
2918 cmSystemTools::Stdout(msg.str().c_str());
2924 // If any output is older than any dependency then rerun.
2927 if(!this->FileComparison->FileTimeCompare(out_oldest.c_str(),
2934 cmOStringStream msg;
2935 msg << "Re-run cmake file: " << out_oldest.c_str()
2936 << " older than: " << dep_newest.c_str() << "\n";
2937 cmSystemTools::Stdout(msg.str().c_str());
2943 // No need to rerun.
2947 //----------------------------------------------------------------------------
2948 void cmake::TruncateOutputLog(const char* fname)
2950 std::string fullPath = this->GetHomeOutputDirectory();
2954 if ( ::stat(fullPath.c_str(), &st) )
2958 if ( !this->CacheManager->GetCacheValue("CMAKE_CACHEFILE_DIR") )
2960 cmSystemTools::RemoveFile(fullPath.c_str());
2963 off_t fsize = st.st_size;
2964 const off_t maxFileSize = 50 * 1024;
2965 if ( fsize < maxFileSize )
2967 //TODO: truncate file
2972 inline std::string removeQuotes(const std::string& s)
2974 if(s[0] == '\"' && s[s.size()-1] == '\"')
2976 return s.substr(1, s.size()-2);
2981 std::string cmake::FindCMakeProgram(const char* name) const
2984 if ((name) && (*name))
2986 const cmMakefile* mf
2987 = this->GetGlobalGenerator()->GetLocalGenerators()[0]->GetMakefile();
2988 #ifdef CMAKE_BUILD_WITH_CMAKE
2989 path = mf->GetRequiredDefinition("CMAKE_COMMAND");
2990 path = removeQuotes(path);
2991 path = cmSystemTools::GetFilenamePath(path.c_str());
2994 path += cmSystemTools::GetExecutableExtension();
2995 if(!cmSystemTools::FileExists(path.c_str()))
2997 path = mf->GetRequiredDefinition("CMAKE_COMMAND");
2998 path = cmSystemTools::GetFilenamePath(path.c_str());
3001 path += cmSystemTools::GetExecutableExtension();
3003 if(!cmSystemTools::FileExists(path.c_str()))
3005 path = mf->GetRequiredDefinition("CMAKE_COMMAND");
3006 path = cmSystemTools::GetFilenamePath(path.c_str());
3007 path += "/Release/";
3009 path += cmSystemTools::GetExecutableExtension();
3012 // Only for bootstrap
3013 path += mf->GetSafeDefinition("EXECUTABLE_OUTPUT_PATH");
3016 path += cmSystemTools::GetExecutableExtension();
3022 const char* cmake::GetCTestCommand()
3024 if ( this->CTestCommand.empty() )
3026 this->CTestCommand = this->FindCMakeProgram("ctest");
3028 if ( this->CTestCommand.empty() )
3030 cmSystemTools::Error("Cannot find the CTest executable");
3031 this->CTestCommand = "CTEST-COMMAND-NOT-FOUND";
3033 return this->CTestCommand.c_str();
3036 const char* cmake::GetCPackCommand()
3038 if ( this->CPackCommand.empty() )
3040 this->CPackCommand = this->FindCMakeProgram("cpack");
3042 if ( this->CPackCommand.empty() )
3044 cmSystemTools::Error("Cannot find the CPack executable");
3045 this->CPackCommand = "CPACK-COMMAND-NOT-FOUND";
3047 return this->CPackCommand.c_str();
3051 const char* cmake::GetCMakeCommand()
3053 return this->CMakeCommand.c_str();
3057 void cmake::MarkCliAsUsed(const std::string& variable)
3059 this->UsedCliVariables[variable] = true;
3062 void cmake::GenerateGraphViz(const char* fileName) const
3064 #ifdef CMAKE_BUILD_WITH_CMAKE
3065 std::auto_ptr<cmGraphVizWriter> gvWriter(
3066 new cmGraphVizWriter(this->GetGlobalGenerator()->GetLocalGenerators()));
3068 std::string settingsFile = this->GetHomeOutputDirectory();
3069 settingsFile += "/CMakeGraphVizOptions.cmake";
3070 std::string fallbackSettingsFile = this->GetHomeDirectory();
3071 fallbackSettingsFile += "/CMakeGraphVizOptions.cmake";
3073 gvWriter->ReadSettings(settingsFile.c_str(), fallbackSettingsFile.c_str());
3075 gvWriter->WritePerTargetFiles(fileName);
3076 gvWriter->WriteTargetDependersFiles(fileName);
3077 gvWriter->WriteGlobalFile(fileName);
3083 //----------------------------------------------------------------------------
3084 int cmake::SymlinkLibrary(std::vector<std::string>& args)
3087 std::string realName = args[2];
3088 std::string soName = args[3];
3089 std::string name = args[4];
3090 if(soName != realName)
3092 if(!cmake::SymlinkInternal(realName, soName))
3094 cmSystemTools::ReportLastSystemError("cmake_symlink_library");
3100 if(!cmake::SymlinkInternal(soName, name))
3102 cmSystemTools::ReportLastSystemError("cmake_symlink_library");
3109 //----------------------------------------------------------------------------
3110 int cmake::SymlinkExecutable(std::vector<std::string>& args)
3113 std::string realName = args[2];
3114 std::string name = args[3];
3115 if(name != realName)
3117 if(!cmake::SymlinkInternal(realName, name))
3119 cmSystemTools::ReportLastSystemError("cmake_symlink_executable");
3126 //----------------------------------------------------------------------------
3127 bool cmake::SymlinkInternal(std::string const& file, std::string const& link)
3129 if(cmSystemTools::FileExists(link.c_str()) ||
3130 cmSystemTools::FileIsSymlink(link.c_str()))
3132 cmSystemTools::RemoveFile(link.c_str());
3134 #if defined(_WIN32) && !defined(__CYGWIN__)
3135 return cmSystemTools::CopyFileAlways(file.c_str(), link.c_str());
3137 std::string linktext = cmSystemTools::GetFilenameName(file);
3138 return cmSystemTools::CreateSymlink(linktext.c_str(), link.c_str());
3142 //----------------------------------------------------------------------------
3143 #ifdef CMAKE_BUILD_WITH_CMAKE
3144 int cmake::ExecuteEchoColor(std::vector<std::string>& args)
3146 // The arguments are
3147 // argv[0] == <cmake-executable>
3148 // argv[1] == cmake_echo_color
3150 bool enabled = true;
3151 int color = cmsysTerminal_Color_Normal;
3152 bool newline = true;
3153 for(unsigned int i=2; i < args.size(); ++i)
3155 if(args[i].find("--switch=") == 0)
3157 // Enable or disable color based on the switch value.
3158 std::string value = args[i].substr(9);
3161 if(cmSystemTools::IsOn(value.c_str()))
3171 else if(args[i] == "--normal")
3173 color = cmsysTerminal_Color_Normal;
3175 else if(args[i] == "--black")
3177 color = cmsysTerminal_Color_ForegroundBlack;
3179 else if(args[i] == "--red")
3181 color = cmsysTerminal_Color_ForegroundRed;
3183 else if(args[i] == "--green")
3185 color = cmsysTerminal_Color_ForegroundGreen;
3187 else if(args[i] == "--yellow")
3189 color = cmsysTerminal_Color_ForegroundYellow;
3191 else if(args[i] == "--blue")
3193 color = cmsysTerminal_Color_ForegroundBlue;
3195 else if(args[i] == "--magenta")
3197 color = cmsysTerminal_Color_ForegroundMagenta;
3199 else if(args[i] == "--cyan")
3201 color = cmsysTerminal_Color_ForegroundCyan;
3203 else if(args[i] == "--white")
3205 color = cmsysTerminal_Color_ForegroundWhite;
3207 else if(args[i] == "--bold")
3209 color |= cmsysTerminal_Color_ForegroundBold;
3211 else if(args[i] == "--no-newline")
3215 else if(args[i] == "--newline")
3221 // Color is enabled. Print with the current color.
3222 cmSystemTools::MakefileColorEcho(color, args[i].c_str(),
3230 int cmake::ExecuteEchoColor(std::vector<std::string>&)
3236 //----------------------------------------------------------------------------
3237 int cmake::ExecuteLinkScript(std::vector<std::string>& args)
3239 // The arguments are
3240 // argv[0] == <cmake-executable>
3241 // argv[1] == cmake_link_script
3242 // argv[2] == <link-script-name>
3243 // argv[3] == --verbose=?
3244 bool verbose = false;
3245 if(args.size() >= 4)
3247 if(args[3].find("--verbose=") == 0)
3249 if(!cmSystemTools::IsOff(args[3].substr(10).c_str()))
3256 // Allocate a process instance.
3257 cmsysProcess* cp = cmsysProcess_New();
3260 std::cerr << "Error allocating process instance in link script."
3265 // Children should share stdout and stderr with this process.
3266 cmsysProcess_SetPipeShared(cp, cmsysProcess_Pipe_STDOUT, 1);
3267 cmsysProcess_SetPipeShared(cp, cmsysProcess_Pipe_STDERR, 1);
3269 // Run the command lines verbatim.
3270 cmsysProcess_SetOption(cp, cmsysProcess_Option_Verbatim, 1);
3272 // Read command lines from the script.
3273 std::ifstream fin(args[2].c_str());
3276 std::cerr << "Error opening link script \""
3277 << args[2] << "\"" << std::endl;
3281 // Run one command at a time.
3282 std::string command;
3284 while(result == 0 && cmSystemTools::GetLineFromStream(fin, command))
3286 // Setup this command line.
3287 const char* cmd[2] = {command.c_str(), 0};
3288 cmsysProcess_SetCommand(cp, cmd);
3290 // Report the command if verbose output is enabled.
3293 std::cout << command << std::endl;
3296 // Run the command and wait for it to exit.
3297 cmsysProcess_Execute(cp);
3298 cmsysProcess_WaitForExit(cp, 0);
3300 // Report failure if any.
3301 switch(cmsysProcess_GetState(cp))
3303 case cmsysProcess_State_Exited:
3305 int value = cmsysProcess_GetExitValue(cp);
3312 case cmsysProcess_State_Exception:
3313 std::cerr << "Error running link command: "
3314 << cmsysProcess_GetExceptionString(cp) << std::endl;
3317 case cmsysProcess_State_Error:
3318 std::cerr << "Error running link command: "
3319 << cmsysProcess_GetErrorString(cp) << std::endl;
3327 // Free the process instance.
3328 cmsysProcess_Delete(cp);
3330 // Return the final resulting return value.
3334 void cmake::DefineProperties(cmake *cm)
3337 ("REPORT_UNDEFINED_PROPERTIES", cmProperty::GLOBAL,
3338 "If set, report any undefined properties to this file.",
3339 "If this property is set to a filename then when CMake runs "
3340 "it will report any properties or variables that were accessed "
3341 "but not defined into the filename specified in this property."
3345 ("TARGET_SUPPORTS_SHARED_LIBS", cmProperty::GLOBAL,
3346 "Does the target platform support shared libraries.",
3347 "TARGET_SUPPORTS_SHARED_LIBS is a boolean specifying whether the target "
3348 "platform supports shared libraries. Basically all current general "
3349 "general purpose OS do so, the exception are usually embedded systems "
3350 "with no or special OSs.");
3353 ("TARGET_ARCHIVES_MAY_BE_SHARED_LIBS", cmProperty::GLOBAL,
3354 "Set if shared libraries may be named like archives.",
3355 "On AIX shared libraries may be named \"lib<name>.a\". "
3356 "This property is set to true on such platforms.");
3359 ("FIND_LIBRARY_USE_LIB64_PATHS", cmProperty::GLOBAL,
3360 "Whether FIND_LIBRARY should automatically search lib64 directories.",
3361 "FIND_LIBRARY_USE_LIB64_PATHS is a boolean specifying whether the "
3362 "FIND_LIBRARY command should automatically search the lib64 variant of "
3363 "directories called lib in the search path when building 64-bit "
3366 ("FIND_LIBRARY_USE_OPENBSD_VERSIONING", cmProperty::GLOBAL,
3367 "Whether FIND_LIBRARY should find OpenBSD-style shared libraries.",
3368 "This property is a boolean specifying whether the FIND_LIBRARY "
3369 "command should find shared libraries with OpenBSD-style versioned "
3370 "extension: \".so.<major>.<minor>\". "
3371 "The property is set to true on OpenBSD and false on other platforms.");
3373 ("ENABLED_FEATURES", cmProperty::GLOBAL,
3374 "List of features which are enabled during the CMake run.",
3375 "List of features which are enabled during the CMake run. By default "
3376 "it contains the names of all packages which were found. This is "
3377 "determined using the <NAME>_FOUND variables. Packages which are "
3378 "searched QUIET are not listed. A project can add its own features to "
3380 "This property is used by the macros in FeatureSummary.cmake.");
3382 ("DISABLED_FEATURES", cmProperty::GLOBAL,
3383 "List of features which are disabled during the CMake run.",
3384 "List of features which are disabled during the CMake run. By default "
3385 "it contains the names of all packages which were not found. This is "
3386 "determined using the <NAME>_FOUND variables. Packages which are "
3387 "searched QUIET are not listed. A project can add its own features to "
3389 "This property is used by the macros in FeatureSummary.cmake.");
3391 ("PACKAGES_FOUND", cmProperty::GLOBAL,
3392 "List of packages which were found during the CMake run.",
3393 "List of packages which were found during the CMake run. Whether a "
3394 "package has been found is determined using the <NAME>_FOUND variables.");
3396 ("PACKAGES_NOT_FOUND", cmProperty::GLOBAL,
3397 "List of packages which were not found during the CMake run.",
3398 "List of packages which were not found during the CMake run. Whether a "
3399 "package has been found is determined using the <NAME>_FOUND variables.");
3402 "__CMAKE_DELETE_CACHE_CHANGE_VARS_", cmProperty::GLOBAL,
3403 "Internal property",
3404 "Used to detect compiler changes, Do not set.");
3407 "DEBUG_CONFIGURATIONS", cmProperty::GLOBAL,
3408 "Specify which configurations are for debugging.",
3409 "The value must be a semi-colon separated list of configuration names. "
3410 "Currently this property is used only by the target_link_libraries "
3411 "command (see its documentation for details). "
3412 "Additional uses may be defined in the future. "
3414 "This property must be set at the top level of the project and before "
3415 "the first target_link_libraries command invocation. "
3416 "If any entry in the list does not match a valid configuration for "
3417 "the project the behavior is undefined.");
3420 "GLOBAL_DEPENDS_DEBUG_MODE", cmProperty::GLOBAL,
3421 "Enable global target dependency graph debug mode.",
3422 "CMake automatically analyzes the global inter-target dependency graph "
3423 "at the beginning of native build system generation. "
3424 "This property causes it to display details of its analysis to stderr.");
3427 "GLOBAL_DEPENDS_NO_CYCLES", cmProperty::GLOBAL,
3428 "Disallow global target dependency graph cycles.",
3429 "CMake automatically analyzes the global inter-target dependency graph "
3430 "at the beginning of native build system generation. "
3431 "It reports an error if the dependency graph contains a cycle that "
3432 "does not consist of all STATIC library targets. "
3433 "This property tells CMake to disallow all cycles completely, even "
3434 "among static libraries.");
3437 "ALLOW_DUPLICATE_CUSTOM_TARGETS", cmProperty::GLOBAL,
3438 "Allow duplicate custom targets to be created.",
3439 "Normally CMake requires that all targets built in a project have "
3440 "globally unique logical names (see policy CMP0002). "
3441 "This is necessary to generate meaningful project file names in "
3442 "Xcode and VS IDE generators. "
3443 "It also allows the target names to be referenced unambiguously.\n"
3444 "Makefile generators are capable of supporting duplicate custom target "
3446 "For projects that care only about Makefile generators and do "
3447 "not wish to support Xcode or VS IDE generators, one may set this "
3448 "property to true to allow duplicate custom targets. "
3449 "The property allows multiple add_custom_target command calls in "
3450 "different directories to specify the same target name. "
3451 "However, setting this property will cause non-Makefile generators "
3452 "to produce an error and refuse to generate the project."
3456 ("IN_TRY_COMPILE", cmProperty::GLOBAL,
3457 "Read-only property that is true during a try-compile configuration.",
3458 "True when building a project inside a TRY_COMPILE or TRY_RUN command.");
3460 ("ENABLED_LANGUAGES", cmProperty::GLOBAL,
3461 "Read-only property that contains the list of currently "
3462 "enabled languages",
3463 "Set to list of currently enabled languages.");
3466 ("RULE_LAUNCH_COMPILE", cmProperty::GLOBAL,
3467 "Specify a launcher for compile rules.",
3468 "Makefile generators prefix compiler commands with the given "
3469 "launcher command line. "
3470 "This is intended to allow launchers to intercept build problems "
3471 "with high granularity. "
3472 "Non-Makefile generators currently ignore this property.");
3474 ("RULE_LAUNCH_LINK", cmProperty::GLOBAL,
3475 "Specify a launcher for link rules.",
3476 "Makefile generators prefix link and archive commands with the given "
3477 "launcher command line. "
3478 "This is intended to allow launchers to intercept build problems "
3479 "with high granularity. "
3480 "Non-Makefile generators currently ignore this property.");
3482 ("RULE_LAUNCH_CUSTOM", cmProperty::GLOBAL,
3483 "Specify a launcher for custom rules.",
3484 "Makefile generators prefix custom commands with the given "
3485 "launcher command line. "
3486 "This is intended to allow launchers to intercept build problems "
3487 "with high granularity. "
3488 "Non-Makefile generators currently ignore this property.");
3491 ("RULE_MESSAGES", cmProperty::GLOBAL,
3492 "Specify whether to report a message for each make rule.",
3493 "This property specifies whether Makefile generators should add a "
3494 "progress message describing what each build rule does. "
3495 "If the property is not set the default is ON. "
3496 "Set the property to OFF to disable granular messages and report only "
3497 "as each target completes. "
3498 "This is intended to allow scripted builds to avoid the build time "
3499 "cost of detailed reports. "
3500 "If a CMAKE_RULE_MESSAGES cache entry exists its value initializes "
3501 "the value of this property. "
3502 "Non-Makefile generators currently ignore this property.");
3505 ("USE_FOLDERS", cmProperty::GLOBAL,
3506 "Use the FOLDER target property to organize targets into folders.",
3507 "If not set, CMake treats this property as OFF by default. "
3508 "CMake generators that are capable of organizing into a "
3509 "hierarchy of folders use the values of the FOLDER target "
3510 "property to name those folders. See also the documentation "
3511 "for the FOLDER target property.");
3514 ("PREDEFINED_TARGETS_FOLDER", cmProperty::GLOBAL,
3515 "Name of FOLDER for targets that are added automatically by CMake.",
3516 "If not set, CMake uses \"CMakePredefinedTargets\" as a default "
3517 "value for this property. Targets such as INSTALL, PACKAGE and "
3518 "RUN_TESTS will be organized into this FOLDER. See also the "
3519 "documentation for the FOLDER target property.");
3521 // ================================================================
3522 // define variables as well
3523 // ================================================================
3524 cmDocumentVariables::DefineVariables(cm);
3528 void cmake::DefineProperty(const char *name, cmProperty::ScopeType scope,
3529 const char *ShortDescription,
3530 const char *FullDescription,
3531 bool chained, const char *docSection)
3533 this->PropertyDefinitions[scope].DefineProperty(name,scope,ShortDescription,
3539 cmPropertyDefinition *cmake
3540 ::GetPropertyDefinition(const char *name,
3541 cmProperty::ScopeType scope)
3543 if (this->IsPropertyDefined(name,scope))
3545 return &(this->PropertyDefinitions[scope][name]);
3550 void cmake::RecordPropertyAccess(const char *name,
3551 cmProperty::ScopeType scope)
3553 this->AccessedProperties.insert
3554 (std::pair<cmStdString,cmProperty::ScopeType>(name,scope));
3557 void cmake::ReportUndefinedPropertyAccesses(const char *filename)
3559 FILE *progFile = fopen(filename,"w");
3560 if (!progFile || !this->GlobalGenerator)
3565 // what are the enabled languages?
3566 std::vector<std::string> enLangs;
3567 this->GlobalGenerator->GetEnabledLanguages(enLangs);
3569 // Common configuration names.
3570 // TODO: Compute current configuration(s).
3571 std::vector<std::string> enConfigs;
3572 enConfigs.push_back("");
3573 enConfigs.push_back("DEBUG");
3574 enConfigs.push_back("RELEASE");
3575 enConfigs.push_back("MINSIZEREL");
3576 enConfigs.push_back("RELWITHDEBINFO");
3578 // take all the defined properties and add definitions for all the enabled
3580 std::set<std::pair<cmStdString,cmProperty::ScopeType> > aliasedProperties;
3581 std::map<cmProperty::ScopeType, cmPropertyDefinitionMap>::iterator i;
3582 i = this->PropertyDefinitions.begin();
3583 for (;i != this->PropertyDefinitions.end(); ++i)
3585 cmPropertyDefinitionMap::iterator j;
3586 for (j = i->second.begin(); j != i->second.end(); ++j)
3588 // TODO: What if both <LANG> and <CONFIG> appear?
3589 if (j->first.find("<CONFIG>") != std::string::npos)
3591 std::vector<std::string>::const_iterator k;
3592 for (k = enConfigs.begin(); k != enConfigs.end(); ++k)
3594 std::string tmp = j->first;
3595 cmSystemTools::ReplaceString(tmp, "<CONFIG>", k->c_str());
3597 aliasedProperties.insert
3598 (std::pair<cmStdString,cmProperty::ScopeType>(tmp,i->first));
3601 if (j->first.find("<LANG>") != std::string::npos)
3603 std::vector<std::string>::const_iterator k;
3604 for (k = enLangs.begin(); k != enLangs.end(); ++k)
3606 std::string tmp = j->first;
3607 cmSystemTools::ReplaceString(tmp, "<LANG>", k->c_str());
3609 aliasedProperties.insert
3610 (std::pair<cmStdString,cmProperty::ScopeType>(tmp,i->first));
3616 std::set<std::pair<cmStdString,cmProperty::ScopeType> >::const_iterator ap;
3617 ap = this->AccessedProperties.begin();
3618 for (;ap != this->AccessedProperties.end(); ++ap)
3620 if (!this->IsPropertyDefined(ap->first.c_str(),ap->second) &&
3621 aliasedProperties.find(std::pair<cmStdString,cmProperty::ScopeType>
3622 (ap->first,ap->second)) ==
3623 aliasedProperties.end())
3625 const char *scopeStr = "";
3628 case cmProperty::TARGET:
3629 scopeStr = "TARGET";
3631 case cmProperty::SOURCE_FILE:
3632 scopeStr = "SOURCE_FILE";
3634 case cmProperty::DIRECTORY:
3635 scopeStr = "DIRECTORY";
3637 case cmProperty::TEST:
3640 case cmProperty::VARIABLE:
3641 scopeStr = "VARIABLE";
3643 case cmProperty::CACHED_VARIABLE:
3644 scopeStr = "CACHED_VARIABLE";
3647 scopeStr = "unknown";
3650 fprintf(progFile, "%s with scope %s\n", ap->first.c_str(), scopeStr);
3656 bool cmake::IsPropertyDefined(const char *name, cmProperty::ScopeType scope)
3658 return this->PropertyDefinitions[scope].IsPropertyDefined(name);
3661 bool cmake::IsPropertyChained(const char *name, cmProperty::ScopeType scope)
3663 return this->PropertyDefinitions[scope].IsPropertyChained(name);
3666 void cmake::SetProperty(const char* prop, const char* value)
3673 // Special hook to invalidate cached value.
3674 if(strcmp(prop, "DEBUG_CONFIGURATIONS") == 0)
3676 this->DebugConfigs.clear();
3679 this->Properties.SetProperty(prop, value, cmProperty::GLOBAL);
3682 void cmake::AppendProperty(const char* prop, const char* value, bool asString)
3689 // Special hook to invalidate cached value.
3690 if(strcmp(prop, "DEBUG_CONFIGURATIONS") == 0)
3692 this->DebugConfigs.clear();
3695 this->Properties.AppendProperty(prop, value, cmProperty::GLOBAL, asString);
3698 const char *cmake::GetProperty(const char* prop)
3700 return this->GetProperty(prop, cmProperty::GLOBAL);
3703 const char *cmake::GetProperty(const char* prop, cmProperty::ScopeType scope)
3711 // watch for special properties
3712 std::string propname = prop;
3713 std::string output = "";
3714 if ( propname == "CACHE_VARIABLES" )
3716 cmCacheManager::CacheIterator cit =
3717 this->GetCacheManager()->GetCacheIterator();
3718 for ( cit.Begin(); !cit.IsAtEnd(); cit.Next() )
3720 if ( output.size() )
3724 output += cit.GetName();
3726 this->SetProperty("CACHE_VARIABLES", output.c_str());
3728 else if ( propname == "COMMANDS" )
3730 cmake::RegisteredCommandsMap::iterator cmds
3731 = this->GetCommands()->begin();
3732 for (unsigned int cc=0 ; cmds != this->GetCommands()->end(); ++ cmds )
3738 output += cmds->first.c_str();
3741 this->SetProperty("COMMANDS",output.c_str());
3743 else if ( propname == "IN_TRY_COMPILE" )
3745 this->SetProperty("IN_TRY_COMPILE",
3746 this->GetIsInTryCompile()? "1":"0");
3748 else if ( propname == "ENABLED_LANGUAGES" )
3751 if(this->GlobalGenerator)
3753 std::vector<std::string> enLangs;
3754 this->GlobalGenerator->GetEnabledLanguages(enLangs);
3755 const char* sep = "";
3756 for(std::vector<std::string>::iterator i = enLangs.begin();
3757 i != enLangs.end(); ++i)
3764 this->SetProperty("ENABLED_LANGUAGES", lang.c_str());
3766 return this->Properties.GetPropertyValue(prop, scope, chain);
3769 bool cmake::GetPropertyAsBool(const char* prop)
3771 return cmSystemTools::IsOn(this->GetProperty(prop));
3774 int cmake::GetSystemInformation(std::vector<std::string>& args)
3776 // so create the directory
3777 std::string resultFile;
3778 std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
3779 std::string destPath = cwd + "/__cmake_systeminformation";
3780 cmSystemTools::RemoveADirectory(destPath.c_str());
3781 if (!cmSystemTools::MakeDirectory(destPath.c_str()))
3783 std::cerr << "Error: --system-information must be run from a "
3784 "writable directory!\n";
3788 // process the arguments
3789 bool writeToStdout = true;
3790 for(unsigned int i=1; i < args.size(); ++i)
3792 std::string arg = args[i];
3793 if(arg.find("-V",0) == 0)
3795 this->Verbose = true;
3797 else if(arg.find("-G",0) == 0)
3799 std::string value = arg.substr(2);
3800 if(value.size() == 0)
3803 if(i >= args.size())
3805 cmSystemTools::Error("No generator specified for -G");
3810 cmGlobalGenerator* gen =
3811 this->CreateGlobalGenerator(value.c_str());
3814 cmSystemTools::Error("Could not create named generator ",
3819 this->SetGlobalGenerator(gen);
3822 // no option assume it is the output file
3825 if (!cmSystemTools::FileIsFullPath(arg.c_str()))
3831 writeToStdout = false;
3836 // we have to find the module directory, so we can copy the files
3837 this->AddCMakePaths();
3838 std::string modulesPath =
3839 this->CacheManager->GetCacheValue("CMAKE_ROOT");
3840 modulesPath += "/Modules";
3841 std::string inFile = modulesPath;
3842 inFile += "/SystemInformation.cmake";
3843 std::string outFile = destPath;
3844 outFile += "/CMakeLists.txt";
3847 if(!cmSystemTools::cmCopyFile(inFile.c_str(), outFile.c_str()))
3849 std::cerr << "Error copying file \"" << inFile.c_str()
3850 << "\" to \"" << outFile.c_str() << "\".\n";
3854 // do we write to a file or to stdout?
3855 if (resultFile.size() == 0)
3858 resultFile += "/__cmake_systeminformation/results.txt";
3861 // now run cmake on the CMakeLists file
3862 cmSystemTools::ChangeDirectory(destPath.c_str());
3863 std::vector<std::string> args2;
3864 args2.push_back(args[0]);
3865 args2.push_back(destPath);
3866 std::string resultArg = "-DRESULT_FILE=";
3867 resultArg += resultFile;
3868 args2.push_back(resultArg);
3869 int res = this->Run(args2, false);
3873 std::cerr << "Error: --system-information failed on internal CMake!\n";
3877 // change back to the original directory
3878 cmSystemTools::ChangeDirectory(cwd.c_str());
3880 // echo results to stdout if needed
3883 FILE* fin = fopen(resultFile.c_str(), "r");
3886 const int bufferSize = 4096;
3887 char buffer[bufferSize];
3889 while((n = fread(buffer, 1, bufferSize, fin)) > 0)
3891 for(char* c = buffer; c < buffer+n; ++c)
3901 // clean up the directory
3902 cmSystemTools::RemoveADirectory(destPath.c_str());
3906 //----------------------------------------------------------------------------
3907 static bool cmakeCheckStampFile(const char* stampName)
3909 // The stamp file does not exist. Use the stamp dependencies to
3910 // determine whether it is really out of date. This works in
3911 // conjunction with cmLocalVisualStudio7Generator to avoid
3912 // repeatedly re-running CMake when the user rebuilds the entire
3914 std::string stampDepends = stampName;
3915 stampDepends += ".depend";
3916 #if defined(_WIN32) || defined(__CYGWIN__)
3917 std::ifstream fin(stampDepends.c_str(), std::ios::in | std::ios::binary);
3919 std::ifstream fin(stampDepends.c_str(), std::ios::in);
3923 // The stamp dependencies file cannot be read. Just assume the
3924 // build system is really out of date.
3925 std::cout << "CMake is re-running because " << stampName
3926 << " dependency file is missing.\n";
3930 // Compare the stamp dependencies against the dependency file itself.
3931 cmFileTimeComparison ftc;
3933 while(cmSystemTools::GetLineFromStream(fin, dep))
3936 if(dep.length() >= 1 && dep[0] != '#' &&
3937 (!ftc.FileTimeCompare(stampDepends.c_str(), dep.c_str(), &result)
3940 // The stamp depends file is older than this dependency. The
3941 // build system is really out of date.
3942 std::cout << "CMake is re-running because " << stampName
3943 << " is out-of-date.\n";
3944 std::cout << " the file '" << dep << "'\n";
3945 std::cout << " is newer than '" << stampDepends << "'\n";
3946 std::cout << " result='" << result << "'\n";
3951 // The build system is up to date. The stamp file has been removed
3952 // by the VS IDE due to a "rebuild" request. Just restore it.
3953 std::ofstream stamp(stampName);
3954 stamp << "# CMake generation timestamp file this directory.\n";
3957 // Notify the user why CMake is not re-running. It is safe to
3958 // just print to stdout here because this code is only reachable
3959 // through an undocumented flag used by the VS generator.
3960 std::cout << "CMake does not need to re-run because "
3961 << stampName << " is up-to-date.\n";
3966 cmSystemTools::Error("Cannot restore timestamp ", stampName);
3971 //----------------------------------------------------------------------------
3972 static bool cmakeCheckStampList(const char* stampList)
3974 // If the stamp list does not exist CMake must rerun to generate it.
3975 if(!cmSystemTools::FileExists(stampList))
3977 std::cout << "CMake is re-running because generate.stamp.list "
3981 std::ifstream fin(stampList);
3984 std::cout << "CMake is re-running because generate.stamp.list "
3985 << "could not be read.\n";
3989 // Check each stamp.
3990 std::string stampName;
3991 while(cmSystemTools::GetLineFromStream(fin, stampName))
3993 if(!cmakeCheckStampFile(stampName.c_str()))
4001 // For visual studio 2005 and newer manifest files need to be embeded into
4002 // exe and dll's. This code does that in such a way that incremental linking
4004 int cmake::VisualStudioLink(std::vector<std::string>& args, int type)
4010 bool verbose = false;
4011 if(cmSystemTools::GetEnv("VERBOSE"))
4015 std::vector<std::string> expandedArgs;
4016 for(std::vector<std::string>::iterator i = args.begin();
4017 i != args.end(); ++i)
4019 // check for nmake temporary files
4020 if((*i)[0] == '@' && i->find("@CMakeFiles") != 0 )
4022 std::ifstream fin(i->substr(1).c_str());
4024 while(cmSystemTools::GetLineFromStream(fin,
4027 cmSystemTools::ParseWindowsCommandLine(line.c_str(), expandedArgs);
4032 expandedArgs.push_back(*i);
4035 bool hasIncremental = false;
4036 bool hasManifest = true;
4037 for(std::vector<std::string>::iterator i = expandedArgs.begin();
4038 i != expandedArgs.end(); ++i)
4040 if(cmSystemTools::Strucmp(i->c_str(), "/INCREMENTAL:YES") == 0)
4042 hasIncremental = true;
4044 if(cmSystemTools::Strucmp(i->c_str(), "/INCREMENTAL") == 0)
4046 hasIncremental = true;
4048 if(cmSystemTools::Strucmp(i->c_str(), "/MANIFEST:NO") == 0)
4050 hasManifest = false;
4053 if(hasIncremental && hasManifest)
4057 std::cout << "Visual Studio Incremental Link with embeded manifests\n";
4059 return cmake::VisualStudioLinkIncremental(expandedArgs, type, verbose);
4065 std::cout << "Visual Studio Non-Incremental Link\n";
4069 std::cout << "Visual Studio Incremental Link without manifests\n";
4072 return cmake::VisualStudioLinkNonIncremental(expandedArgs,
4073 type, hasManifest, verbose);
4076 int cmake::ParseVisualStudioLinkCommand(std::vector<std::string>& args,
4077 std::vector<cmStdString>& command,
4078 std::string& targetName)
4080 std::vector<std::string>::iterator i = args.begin();
4082 i++; // skip vs_link_dll or vs_link_exe
4083 command.push_back(*i);
4084 i++; // move past link command
4085 for(; i != args.end(); ++i)
4087 command.push_back(*i);
4088 if(i->find("/Fe") == 0)
4090 targetName = i->substr(3);
4092 if(i->find("/out:") == 0)
4094 targetName = i->substr(5);
4097 if(targetName.size() == 0 || command.size() == 0)
4104 bool cmake::RunCommand(const char* comment,
4105 std::vector<cmStdString>& command,
4111 std::cout << comment << ":\n";
4112 for(std::vector<cmStdString>::iterator i = command.begin();
4113 i != command.end(); ++i)
4115 std::cout << i->c_str() << " ";
4121 // use rc command to create .res file
4122 cmSystemTools::RunSingleCommand(command,
4124 &retCode, 0, cmSystemTools::OUTPUT_NONE);
4125 // always print the output of the command, unless
4126 // it is the dumb rc command banner, but if the command
4127 // returned an error code then print the output anyway as
4128 // the banner may be mixed with some other important information.
4129 if(output.find("Resource Compiler Version") == output.npos
4132 std::cout << output;
4134 // if retCodeOut is requested then always return true
4135 // and set the retCodeOut to retCode
4138 *retCodeOut = retCode;
4143 std::cout << comment << " failed. with " << retCode << "\n";
4145 return retCode == 0;
4148 int cmake::VisualStudioLinkIncremental(std::vector<std::string>& args,
4149 int type, bool verbose)
4151 // This follows the steps listed here:
4152 // http://blogs.msdn.com/zakramer/archive/2006/05/22/603558.aspx
4154 // 1. Compiler compiles the application and generates the *.obj files.
4155 // 2. An empty manifest file is generated if this is a clean build and if
4156 // not the previous one is reused.
4157 // 3. The resource compiler (rc.exe) compiles the *.manifest file to a
4159 // 4. Linker generates the binary (EXE or DLL) with the /incremental
4160 // switch and embeds the dummy manifest file. The linker also generates
4161 // the real manifest file based on the binaries that your binary depends
4163 // 5. The manifest tool (mt.exe) is then used to generate the final
4166 // If the final manifest is changed, then 6 and 7 are run, if not
4167 // they are skipped, and it is done.
4169 // 6. The resource compiler is invoked one more time.
4170 // 7. Finally, the Linker does another incremental link, but since the
4171 // only thing that has changed is the *.res file that contains the
4172 // manifest it is a short link.
4173 std::vector<cmStdString> linkCommand;
4174 std::string targetName;
4175 if(cmake::ParseVisualStudioLinkCommand(args, linkCommand, targetName) == -1)
4179 std::string manifestArg = "/MANIFESTFILE:";
4180 std::vector<cmStdString> rcCommand;
4181 rcCommand.push_back(cmSystemTools::FindProgram("rc.exe"));
4182 std::vector<cmStdString> mtCommand;
4183 mtCommand.push_back(cmSystemTools::FindProgram("mt.exe"));
4184 std::string tempManifest;
4185 tempManifest = targetName;
4186 tempManifest += ".intermediate.manifest";
4187 std::string resourceInputFile = targetName;
4188 resourceInputFile += ".resource.txt";
4191 std::cout << "Create " << resourceInputFile.c_str() << "\n";
4193 // Create input file for rc command
4194 std::ofstream fout(resourceInputFile.c_str());
4199 std::string manifestFile = targetName;
4200 manifestFile += ".embed.manifest";
4201 std::string fullPath= cmSystemTools::CollapseFullPath(manifestFile.c_str());
4202 fout << type << " /* CREATEPROCESS_MANIFEST_RESOURCE_ID "
4203 "*/ 24 /* RT_MANIFEST */ " << "\"" << fullPath.c_str() << "\"";
4205 manifestArg += tempManifest;
4206 // add the manifest arg to the linkCommand
4207 linkCommand.push_back("/MANIFEST");
4208 linkCommand.push_back(manifestArg);
4209 // if manifestFile is not yet created, create an
4211 if(!cmSystemTools::FileExists(manifestFile.c_str()))
4215 std::cout << "Create empty: " << manifestFile.c_str() << "\n";
4217 std::ofstream foutTmp(manifestFile.c_str());
4219 std::string resourceFile = manifestFile;
4220 resourceFile += ".res";
4221 // add the resource file to the end of the link command
4222 linkCommand.push_back(resourceFile);
4223 std::string outputOpt = "/fo";
4224 outputOpt += resourceFile;
4225 rcCommand.push_back(outputOpt);
4226 rcCommand.push_back(resourceInputFile);
4227 // Run rc command to create resource
4228 if(!cmake::RunCommand("RC Pass 1", rcCommand, verbose))
4232 // Now run the link command to link and create manifest
4233 if(!cmake::RunCommand("LINK Pass 1", linkCommand, verbose))
4237 // create mt command
4238 std::string outArg("/out:");
4239 outArg+= manifestFile;
4240 mtCommand.push_back("/nologo");
4241 mtCommand.push_back(outArg);
4242 mtCommand.push_back("/notify_update");
4243 mtCommand.push_back("/manifest");
4244 mtCommand.push_back(tempManifest);
4245 // now run mt.exe to create the final manifest file
4247 cmake::RunCommand("MT", mtCommand, verbose, &mtRet);
4248 // if mt returns 0, then the manifest was not changed and
4249 // we do not need to do another link step
4254 // check for magic mt return value if mt returns the magic number
4255 // 1090650113 then it means that it updated the manifest file and we need
4256 // to do the final link. If mt has any value other than 0 or 1090650113
4257 // then there was some problem with the command itself and there was an
4258 // error so return the error code back out of cmake so make can report it.
4259 if(mtRet != 1090650113)
4263 // update the resource file with the new manifest from the mt command.
4264 if(!cmake::RunCommand("RC Pass 2", rcCommand, verbose))
4268 // Run the final incremental link that will put the new manifest resource
4269 // into the file incrementally.
4270 if(!cmake::RunCommand("FINAL LINK", linkCommand, verbose))
4277 int cmake::VisualStudioLinkNonIncremental(std::vector<std::string>& args,
4282 std::vector<cmStdString> linkCommand;
4283 std::string targetName;
4284 if(cmake::ParseVisualStudioLinkCommand(args, linkCommand, targetName) == -1)
4288 // Run the link command as given
4291 linkCommand.push_back("/MANIFEST");
4293 if(!cmake::RunCommand("LINK", linkCommand, verbose))
4301 std::vector<cmStdString> mtCommand;
4302 mtCommand.push_back(cmSystemTools::FindProgram("mt.exe"));
4303 mtCommand.push_back("/nologo");
4304 mtCommand.push_back("/manifest");
4305 std::string manifestFile = targetName;
4306 manifestFile += ".manifest";
4307 mtCommand.push_back(manifestFile);
4308 std::string outresource = "/outputresource:";
4309 outresource += targetName;
4310 outresource += ";#";
4319 mtCommand.push_back(outresource);
4320 // Now use the mt tool to embed the manifest into the exe or dll
4321 if(!cmake::RunCommand("MT", mtCommand, verbose))
4328 //----------------------------------------------------------------------------
4329 void cmake::IssueMessage(cmake::MessageType t, std::string const& text,
4330 cmListFileBacktrace const& backtrace)
4332 cmOStringStream msg;
4333 bool isError = false;
4334 // Construct the message header.
4335 if(t == cmake::FATAL_ERROR)
4338 msg << "CMake Error";
4340 else if(t == cmake::INTERNAL_ERROR)
4343 msg << "CMake Internal Error (please report a bug)";
4347 msg << "CMake Warning";
4348 if(t == cmake::AUTHOR_WARNING)
4350 // Allow suppression of these warnings.
4351 cmCacheManager::CacheIterator it = this->CacheManager
4352 ->GetCacheIterator("CMAKE_SUPPRESS_DEVELOPER_WARNINGS");
4353 if(!it.IsAtEnd() && it.GetValueAsBool())
4361 // Add the immediate context.
4362 cmListFileBacktrace::const_iterator i = backtrace.begin();
4363 if(i != backtrace.end())
4365 cmListFileContext const& lfc = *i;
4366 msg << (lfc.Line? " at ": " in ") << lfc;
4370 // Add the message text.
4373 cmDocumentationFormatterText formatter;
4374 formatter.SetIndent(" ");
4375 formatter.PrintFormatted(msg, text.c_str());
4378 // Add the rest of the context.
4379 if(i != backtrace.end())
4381 msg << "Call Stack (most recent call first):\n";
4382 while(i != backtrace.end())
4384 cmListFileContext const& lfc = *i;
4385 msg << " " << lfc << "\n";
4390 // Add a note about warning suppression.
4391 if(t == cmake::AUTHOR_WARNING)
4394 "This warning is for project developers. Use -Wno-dev to suppress it.";
4397 // Add a terminating blank line.
4400 // Output the message.
4403 cmSystemTools::SetErrorOccured();
4404 cmSystemTools::Message(msg.str().c_str(), "Error");
4408 cmSystemTools::Message(msg.str().c_str(), "Warning");
4412 //----------------------------------------------------------------------------
4413 std::vector<std::string> const& cmake::GetDebugConfigs()
4415 // Compute on-demand.
4416 if(this->DebugConfigs.empty())
4418 if(const char* config_list = this->GetProperty("DEBUG_CONFIGURATIONS"))
4420 // Expand the specified list and convert to upper-case.
4421 cmSystemTools::ExpandListArgument(config_list, this->DebugConfigs);
4422 for(std::vector<std::string>::iterator i = this->DebugConfigs.begin();
4423 i != this->DebugConfigs.end(); ++i)
4425 *i = cmSystemTools::UpperCase(*i);
4428 // If no configurations were specified, use a default list.
4429 if(this->DebugConfigs.empty())
4431 this->DebugConfigs.push_back("DEBUG");
4434 return this->DebugConfigs;
4438 int cmake::Build(const std::string& dir,
4439 const std::string& target,
4440 const std::string& config,
4441 const std::vector<std::string>& nativeOptions,
4443 cmSystemTools::OutputOption outputflag)
4445 if(!cmSystemTools::FileIsDirectory(dir.c_str()))
4447 std::cerr << "Error: " << dir << " is not a directory\n";
4450 std::string cachePath = dir;
4451 cmSystemTools::ConvertToUnixSlashes(cachePath);
4452 cmCacheManager* cachem = this->GetCacheManager();
4453 cmCacheManager::CacheIterator it = cachem->NewIterator();
4454 if(!cachem->LoadCache(cachePath.c_str()))
4456 std::cerr << "Error: could not load cache\n";
4459 if(!it.Find("CMAKE_GENERATOR"))
4461 std::cerr << "Error: could find generator in Cache\n";
4464 std::auto_ptr<cmGlobalGenerator> gen(
4465 this->CreateGlobalGenerator(it.GetValue()));
4467 std::string projName;
4468 std::string makeProgram;
4469 if(!it.Find("CMAKE_PROJECT_NAME"))
4471 std::cerr << "Error: could not find CMAKE_PROJECT_NAME in Cache\n";
4474 projName = it.GetValue();
4475 if(!it.Find("CMAKE_MAKE_PROGRAM"))
4477 std::cerr << "Error: could not find CMAKE_MAKE_PROGRAM in Cache\n";
4480 makeProgram = it.GetValue();
4481 return gen->Build(0, dir.c_str(),
4482 projName.c_str(), target.c_str(),
4484 makeProgram.c_str(),
4485 config.c_str(), clean, false, 0, outputflag,
4489 void cmake::WatchUnusedCli(const char* var)
4491 #ifdef CMAKE_BUILD_WITH_CMAKE
4492 this->VariableWatch->AddWatch(var, cmWarnUnusedCliWarning, this);
4493 if(this->UsedCliVariables.find(var) == this->UsedCliVariables.end())
4495 this->UsedCliVariables[var] = false;
4500 void cmake::UnwatchUnusedCli(const char* var)
4502 #ifdef CMAKE_BUILD_WITH_CMAKE
4503 this->VariableWatch->RemoveWatch(var, cmWarnUnusedCliWarning);
4504 this->UsedCliVariables.erase(var);
4508 void cmake::RunCheckForUnusedVariables()
4510 #ifdef CMAKE_BUILD_WITH_CMAKE
4511 bool haveUnused = false;
4512 cmOStringStream msg;
4513 msg << "Manually-specified variables were not used by the project:";
4514 for(std::map<cmStdString, bool>::const_iterator
4515 it = this->UsedCliVariables.begin();
4516 it != this->UsedCliVariables.end(); ++it)
4521 msg << "\n " << it->first;
4526 this->IssueMessage(cmake::WARNING, msg.str(), cmListFileBacktrace());