diff options
Diffstat (limited to 'Source/cmake.cxx')
-rw-r--r-- | Source/cmake.cxx | 343 |
1 files changed, 304 insertions, 39 deletions
diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 1b49837..71dca3a 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -20,6 +20,7 @@ #include "cmCommand.h" #include "cmFileTimeComparison.h" #include "cmGeneratedFileStream.h" +#include "cmQtAutomoc.h" #include "cmSourceFile.h" #include "cmVersion.h" #include "cmTest.h" @@ -62,9 +63,13 @@ # include "cmGlobalVisualStudio71Generator.h" # include "cmGlobalVisualStudio8Generator.h" # include "cmGlobalVisualStudio9Generator.h" +# include "cmGlobalVisualStudio9IA64Generator.h" # include "cmGlobalVisualStudio9Win64Generator.h" # include "cmGlobalVisualStudio10Generator.h" +# include "cmGlobalVisualStudio10IA64Generator.h" # include "cmGlobalVisualStudio10Win64Generator.h" +# include "cmGlobalVisualStudio11Generator.h" +# include "cmGlobalVisualStudio11Win64Generator.h" # include "cmGlobalVisualStudio8Win64Generator.h" # include "cmGlobalBorlandMakefileGenerator.h" # include "cmGlobalNMakeMakefileGenerator.h" @@ -138,9 +143,20 @@ void cmNeedBackwardsCompatibility(const std::string& variable, #endif } +void cmWarnUnusedCliWarning(const std::string& variable, + int, void* ctx, const char*, const cmMakefile*) +{ + cmake* cm = reinterpret_cast<cmake*>(ctx); + cm->MarkCliAsUsed(variable); +} + cmake::cmake() { this->Trace = false; + this->WarnUninitialized = false; + this->WarnUnused = false; + this->WarnUnusedCli = true; + this->CheckSystemVars = false; this->SuppressDevWarnings = false; this->DoSuppressDevWarnings = false; this->DebugOutput = false; @@ -169,7 +185,7 @@ cmake::cmake() this->GlobalGenerator = 0; this->ProgressCallback = 0; this->ProgressCallbackClientData = 0; - this->ScriptMode = false; + this->CurrentWorkingMode = NORMAL_MODE; #ifdef CMAKE_BUILD_WITH_CMAKE this->VariableWatch = new cmVariableWatch; @@ -342,6 +358,7 @@ void cmake::RemoveUnscriptableCommands() // Parse the args bool cmake::SetCacheArgs(const std::vector<std::string>& args) { + bool findPackageMode = false; for(unsigned int i=1; i < args.size(); ++i) { std::string arg = args[i]; @@ -367,6 +384,10 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args) { this->CacheManager->AddCacheEntry(var.c_str(), value.c_str(), "No help, variable specified on the command line.", type); + if(this->WarnUnusedCli) + { + this->WatchUnusedCli(var.c_str()); + } } else { @@ -447,7 +468,7 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args) } } std::cerr << "loading initial cache file " << path.c_str() << "\n"; - this->ReadListFile(path.c_str()); + this->ReadListFile(args, path.c_str()); } else if(arg.find("-P",0) == 0) { @@ -463,13 +484,24 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args) cmSystemTools::Error("No cmake script provided."); return false; } - this->ReadListFile(path.c_str()); + this->ReadListFile(args, path.c_str()); + } + else if (arg.find("--find-package",0) == 0) + { + findPackageMode = true; } } + + if (findPackageMode) + { + return this->FindPackage(args); + } + return true; } -void cmake::ReadListFile(const char *path) +void cmake::ReadListFile(const std::vector<std::string>& args, + const char *path) { // if a generator was not yet created, temporarily create one cmGlobalGenerator *gg = this->GetGlobalGenerator(); @@ -495,6 +527,14 @@ void cmake::ReadListFile(const char *path) (cmSystemTools::GetCurrentWorkingDirectory().c_str()); lg->GetMakefile()->SetStartDirectory (cmSystemTools::GetCurrentWorkingDirectory().c_str()); + if (this->GetWorkingMode() != NORMAL_MODE) + { + std::string file(cmSystemTools::CollapseFullPath(path)); + cmSystemTools::ConvertToUnixSlashes(file); + lg->GetMakefile()->SetScriptModeFile(file.c_str()); + + lg->GetMakefile()->SetArgcArgv(args); + } if (!lg->GetMakefile()->ReadListFile(0, path)) { cmSystemTools::Error("Error processing file:", path); @@ -508,10 +548,116 @@ void cmake::ReadListFile(const char *path) } } + +bool cmake::FindPackage(const std::vector<std::string>& args) +{ + // if a generator was not yet created, temporarily create one + cmGlobalGenerator *gg = new cmGlobalGenerator; + gg->SetCMakeInstance(this); + this->SetGlobalGenerator(gg); + + // read in the list file to fill the cache + std::auto_ptr<cmLocalGenerator> lg(gg->CreateLocalGenerator()); + cmMakefile* mf = lg->GetMakefile(); + mf->SetHomeOutputDirectory + (cmSystemTools::GetCurrentWorkingDirectory().c_str()); + mf->SetStartOutputDirectory + (cmSystemTools::GetCurrentWorkingDirectory().c_str()); + mf->SetHomeDirectory + (cmSystemTools::GetCurrentWorkingDirectory().c_str()); + mf->SetStartDirectory + (cmSystemTools::GetCurrentWorkingDirectory().c_str()); + + mf->SetArgcArgv(args); + + std::string systemFile = mf->GetModulesFile("CMakeFindPackageMode.cmake"); + mf->ReadListFile(0, systemFile.c_str()); + + std::string language = mf->GetSafeDefinition("LANGUAGE"); + std::string mode = mf->GetSafeDefinition("MODE"); + std::string packageName = mf->GetSafeDefinition("NAME"); + bool packageFound = mf->IsOn("PACKAGE_FOUND"); + bool quiet = mf->IsOn("PACKAGE_QUIET"); + + if (!packageFound) + { + if (!quiet) + { + printf("%s not found.\n", packageName.c_str()); + } + } + else if (mode == "EXIST") + { + if (!quiet) + { + printf("%s found.\n", packageName.c_str()); + } + } + else if (mode == "COMPILE") + { + std::string includes = mf->GetSafeDefinition("PACKAGE_INCLUDE_DIRS"); + std::vector<std::string> includeDirs; + cmSystemTools::ExpandListArgument(includes, includeDirs); + for(std::vector<std::string>::const_iterator dirIt=includeDirs.begin(); + dirIt != includeDirs.end(); + ++dirIt) + { + mf->AddIncludeDirectory(dirIt->c_str(), false); + } + + std::string includeFlags = lg->GetIncludeFlags(language.c_str(), false); + std::string definitions = mf->GetSafeDefinition("PACKAGE_DEFINITIONS"); + printf("%s %s\n", includeFlags.c_str(), definitions.c_str()); + } + else if (mode == "LINK") + { + const char* targetName = "dummy"; + std::vector<std::string> srcs; + cmTarget* tgt = mf->AddExecutable(targetName, srcs, true); + tgt->SetProperty("LINKER_LANGUAGE", language.c_str()); + + std::string libs = mf->GetSafeDefinition("PACKAGE_LIBRARIES"); + std::vector<std::string> libList; + cmSystemTools::ExpandListArgument(libs, libList); + for(std::vector<std::string>::const_iterator libIt=libList.begin(); + libIt != libList.end(); + ++libIt) + { + mf->AddLinkLibraryForTarget(targetName, libIt->c_str(), + cmTarget::GENERAL); + } + + + std::string linkLibs; + std::string flags; + std::string linkFlags; + lg->GetTargetFlags(linkLibs, flags, linkFlags, *tgt); + + printf("%s\n", linkLibs.c_str() ); + +/* if ( use_win32 ) + { + tgt->SetProperty("WIN32_EXECUTABLE", "ON"); + } + if ( use_macbundle) + { + tgt->SetProperty("MACOSX_BUNDLE", "ON"); + }*/ + } + + // free generic one if generated +// this->SetGlobalGenerator(0); // setting 0-pointer is not possible +// delete gg; // this crashes inside the cmake instance + + return packageFound; +} + + // Parse the args -void cmake::SetArgs(const std::vector<std::string>& args) +void cmake::SetArgs(const std::vector<std::string>& args, + bool directoriesSetBefore) { - bool directoriesSet = false; + bool directoriesSet = directoriesSetBefore; for(unsigned int i=1; i < args.size(); ++i) { std::string arg = args[i]; @@ -579,6 +725,11 @@ void cmake::SetArgs(const std::vector<std::string>& args) // skip for now i++; } + else if(arg.find("--find-package",0) == 0) + { + // skip for now + i++; + } else if(arg.find("-Wno-dev",0) == 0) { // skip for now @@ -613,6 +764,28 @@ void cmake::SetArgs(const std::vector<std::string>& args) std::cout << "Running with trace output on.\n"; this->SetTrace(true); } + else if(arg.find("--warn-uninitialized",0) == 0) + { + std::cout << "Warn about uninitialized values.\n"; + this->SetWarnUninitialized(true); + } + else if(arg.find("--warn-unused-vars",0) == 0) + { + std::cout << "Finding unused variables.\n"; + this->SetWarnUnused(true); + } + else if(arg.find("--no-warn-unused-cli",0) == 0) + { + std::cout << "Not searching for unused variables given on the " << + "command line.\n"; + this->SetWarnUnusedCli(false); + } + else if(arg.find("--check-system-vars",0) == 0) + { + std::cout << "Also check system files when warning about unused and " << + "uninitialized variables.\n"; + this->SetCheckSystemVars(true); + } else if(arg.find("-G",0) == 0) { std::string value = arg.substr(2); @@ -942,36 +1115,37 @@ void CMakeCommandUsage(const char* program) << "Usage: " << program << " -E [command] [arguments ...]\n" << "Available commands: \n" << " chdir dir cmd [args]... - run command in a given directory\n" - << " rename oldname newname - rename a file or directory " - "(on one volume)\n" + << " compare_files file1 file2 - check if file1 is same as file2\n" << " copy file destination - copy file to destination (either file " "or directory)\n" - << " copy_if_different in-file out-file - copy file if input has " - "changed\n" << " copy_directory source destination - copy directory 'source' " "content to directory 'destination'\n" - << " compare_files file1 file2 - check if file1 is same as file2\n" + << " copy_if_different in-file out-file - copy file if input has " + "changed\n" << " echo [string]... - displays arguments as text\n" << " echo_append [string]... - displays arguments as text but no new " "line\n" << " environment - display the current environment\n" << " make_directory dir - create a directory\n" << " md5sum file1 [...] - compute md5sum of files\n" - << " remove_directory dir - remove a directory and its contents\n" << " remove [-f] file1 file2 ... - remove the file(s), use -f to force " "it\n" + << " remove_directory dir - remove a directory and its contents\n" + << " rename oldname newname - rename a file or directory " + "(on one volume)\n" << " tar [cxt][vfz][cvfj] file.tar " "file/dir1 file/dir2 ... - create a tar " "archive\n" << " time command [args] ... - run command and return elapsed time\n" << " touch file - touch a file.\n" << " touch_nocreate file - touch a file but do not create it.\n" - << " build build_dir - build the project in build_dir.\n" #if defined(_WIN32) && !defined(__CYGWIN__) - << " write_regv key value - write registry value\n" - << " delete_regv key - delete registry value\n" + << "Available on Windows only:\n" << " comspec - on windows 9x use this for RunCommand\n" + << " delete_regv key - delete registry value\n" + << " write_regv key value - write registry value\n" #else + << "Available on UNIX only:\n" << " create_symlink old new - create a symbolic link new -> old\n" #endif ; @@ -1248,7 +1422,7 @@ int cmake::ExecuteCMakeCommand(std::vector<std::string>& args) int retval = 0; int timeout = 0; if ( cmSystemTools::RunSingleCommand(command.c_str(), 0, &retval, - directory.c_str(), true, timeout) ) + directory.c_str(), cmSystemTools::OUTPUT_MERGE, timeout) ) { return retval; } @@ -1521,6 +1695,12 @@ int cmake::ExecuteCMakeCommand(std::vector<std::string>& args) { return cmake::ExecuteEchoColor(args); } + else if (args[1] == "cmake_automoc") + { + cmQtAutomoc automoc; + automoc.Run(args[2].c_str()); + return 0; + } #endif // Tar files @@ -1953,7 +2133,7 @@ int cmake::ActualConfigure() this->CleanupCommandsAndMacros(); int res = 0; - if ( !this->ScriptMode ) + if ( this->GetWorkingMode() == NORMAL_MODE ) { res = this->DoPreConfigureChecks(); } @@ -2000,8 +2180,11 @@ int cmake::ActualConfigure() std::string installedCompiler; // Try to find the newest VS installed on the computer and // use that as a default if -G is not specified - std::string vsregBase = - "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\"; + const std::string vsregBase = + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\"; + std::vector<std::string> vsVerions; + vsVerions.push_back("VisualStudio\\"); + vsVerions.push_back("VCExpress\\"); struct VSRegistryEntryName { const char* MSVersion; @@ -2015,14 +2198,18 @@ int cmake::ActualConfigure() {"9.0", "Visual Studio 9 2008"}, {"10.0", "Visual Studio 10"}, {0, 0}}; - for(int i =0; version[i].MSVersion != 0; i++) + for(size_t b=0; b < vsVerions.size() && installedCompiler.empty(); b++) { - std::string reg = vsregBase + version[i].MSVersion; - reg += ";InstallDir]"; - cmSystemTools::ExpandRegistryValues(reg); - if (!(reg == "/registry")) + for(int i =0; version[i].MSVersion != 0; i++) { - installedCompiler = version[i].GeneratorName; + std::string reg = vsregBase + vsVerions[b] + version[i].MSVersion; + reg += ";InstallDir]"; + cmSystemTools::ExpandRegistryValues(reg, + cmSystemTools::KeyWOW64_32); + if (!(reg == "/registry")) + { + installedCompiler = version[i].GeneratorName; + } } } cmGlobalGenerator* gen @@ -2141,7 +2328,7 @@ int cmake::ActualConfigure() this->CacheManager->RemoveCacheEntry("CMAKE_EXTRA_GENERATOR"); } // only save the cache if there were no fatal errors - if ( !this->ScriptMode ) + if ( this->GetWorkingMode() == NORMAL_MODE ) { this->CacheManager->SaveCache(this->GetHomeOutputDirectory()); } @@ -2159,13 +2346,14 @@ int cmake::ActualConfigure() void cmake::PreLoadCMakeFiles() { + std::vector<std::string> args; std::string pre_load = this->GetHomeDirectory(); if ( pre_load.size() > 0 ) { pre_load += "/PreLoad.cmake"; if ( cmSystemTools::FileExists(pre_load.c_str()) ) { - this->ReadListFile(pre_load.c_str()); + this->ReadListFile(args, pre_load.c_str()); } } pre_load = this->GetHomeOutputDirectory(); @@ -2174,7 +2362,7 @@ void cmake::PreLoadCMakeFiles() pre_load += "/PreLoad.cmake"; if ( cmSystemTools::FileExists(pre_load.c_str()) ) { - this->ReadListFile(pre_load.c_str()); + this->ReadListFile(args, pre_load.c_str()); } } } @@ -2206,7 +2394,7 @@ int cmake::Run(const std::vector<std::string>& args, bool noconfigure) // set the cmake command this->CMakeCommand = args[0]; - if ( !this->ScriptMode ) + if ( this->GetWorkingMode() == NORMAL_MODE ) { // load the cache if(this->LoadCache() < 0) @@ -2227,7 +2415,7 @@ int cmake::Run(const std::vector<std::string>& args, bool noconfigure) } // In script mode we terminate after running the script. - if(this->ScriptMode) + if(this->GetWorkingMode() != NORMAL_MODE) { if(cmSystemTools::GetErrorOccuredFlag()) { @@ -2273,7 +2461,7 @@ int cmake::Run(const std::vector<std::string>& args, bool noconfigure) this->SetStartDirectory(this->GetHomeDirectory()); this->SetStartOutputDirectory(this->GetHomeOutputDirectory()); int ret = this->Configure(); - if (ret || this->ScriptMode) + if (ret || this->GetWorkingMode() != NORMAL_MODE) { #if defined(CMAKE_HAVE_VS_GENERATORS) if(!this->VSSolutionFile.empty() && this->GlobalGenerator) @@ -2314,6 +2502,10 @@ int cmake::Generate() return -1; } this->GlobalGenerator->Generate(); + if(this->WarnUnusedCli) + { + this->RunCheckForUnusedVariables(); + } if(cmSystemTools::GetErrorOccuredFlag()) { return -1; @@ -2323,6 +2515,13 @@ int cmake::Generate() this->ReportUndefinedPropertyAccesses (this->GetProperty("REPORT_UNDEFINED_PROPERTIES")); } + // Save the cache again after a successful Generate so that any internal + // variables created during Generate are saved. (Specifically target GUIDs + // for the Visual Studio and Xcode generators.) + if ( this->GetWorkingMode() == NORMAL_MODE ) + { + this->CacheManager->SaveCache(this->GetHomeOutputDirectory()); + } return 0; } @@ -2362,14 +2561,22 @@ void cmake::AddDefaultGenerators() &cmGlobalVisualStudio7Generator::New; this->Generators[cmGlobalVisualStudio10Generator::GetActualName()] = &cmGlobalVisualStudio10Generator::New; + this->Generators[cmGlobalVisualStudio10IA64Generator::GetActualName()] = + &cmGlobalVisualStudio10IA64Generator::New; this->Generators[cmGlobalVisualStudio10Win64Generator::GetActualName()] = &cmGlobalVisualStudio10Win64Generator::New; + this->Generators[cmGlobalVisualStudio11Generator::GetActualName()] = + &cmGlobalVisualStudio11Generator::New; + this->Generators[cmGlobalVisualStudio11Win64Generator::GetActualName()] = + &cmGlobalVisualStudio11Win64Generator::New; this->Generators[cmGlobalVisualStudio71Generator::GetActualName()] = &cmGlobalVisualStudio71Generator::New; this->Generators[cmGlobalVisualStudio8Generator::GetActualName()] = &cmGlobalVisualStudio8Generator::New; this->Generators[cmGlobalVisualStudio9Generator::GetActualName()] = &cmGlobalVisualStudio9Generator::New; + this->Generators[cmGlobalVisualStudio9IA64Generator::GetActualName()] = + &cmGlobalVisualStudio9IA64Generator::New; this->Generators[cmGlobalVisualStudio9Win64Generator::GetActualName()] = &cmGlobalVisualStudio9Win64Generator::New; this->Generators[cmGlobalVisualStudio8Win64Generator::GetActualName()] = @@ -2657,7 +2864,7 @@ int cmake::CheckBuildSystem() return 1; } - // Find find the newest dependency. + // Find the newest dependency. std::vector<std::string>::iterator dep = depends.begin(); std::string dep_newest = *dep++; for(;dep != depends.end(); ++dep) @@ -2683,7 +2890,7 @@ int cmake::CheckBuildSystem() } } - // Find find the oldest output. + // Find the oldest output. std::vector<std::string>::iterator out = outputs.begin(); std::string out_oldest = *out++; for(;out != outputs.end(); ++out) @@ -2836,6 +3043,17 @@ const char* cmake::GetCPackCommand() } +const char* cmake::GetCMakeCommand() +{ + return this->CMakeCommand.c_str(); +} + + +void cmake::MarkCliAsUsed(const std::string& variable) +{ + this->UsedCliVariables[variable] = true; +} + void cmake::GenerateGraphViz(const char* fileName) const { #ifdef CMAKE_BUILD_WITH_CMAKE @@ -2850,6 +3068,7 @@ void cmake::GenerateGraphViz(const char* fileName) const gvWriter->ReadSettings(settingsFile.c_str(), fallbackSettingsFile.c_str()); gvWriter->WritePerTargetFiles(fileName); + gvWriter->WriteTargetDependersFiles(fileName); gvWriter->WriteGlobalFile(fileName); #endif @@ -3453,7 +3672,7 @@ void cmake::SetProperty(const char* prop, const char* value) this->Properties.SetProperty(prop, value, cmProperty::GLOBAL); } -void cmake::AppendProperty(const char* prop, const char* value) +void cmake::AppendProperty(const char* prop, const char* value, bool asString) { if (!prop) { @@ -3466,7 +3685,7 @@ void cmake::AppendProperty(const char* prop, const char* value) this->DebugConfigs.clear(); } - this->Properties.AppendProperty(prop, value, cmProperty::GLOBAL); + this->Properties.AppendProperty(prop, value, cmProperty::GLOBAL, asString); } const char *cmake::GetProperty(const char* prop) @@ -3895,7 +4114,7 @@ bool cmake::RunCommand(const char* comment, // use rc command to create .res file cmSystemTools::RunSingleCommand(command, &output, - &retCode, 0, false); + &retCode, 0, cmSystemTools::OUTPUT_NONE); // always print the output of the command, unless // it is the dumb rc command banner, but if the command // returned an error code then print the output anyway as @@ -4060,7 +4279,10 @@ int cmake::VisualStudioLinkNonIncremental(std::vector<std::string>& args, return -1; } // Run the link command as given - linkCommand.push_back("/MANIFEST"); + if (hasManifest) + { + linkCommand.push_back("/MANIFEST"); + } if(!cmake::RunCommand("LINK", linkCommand, verbose)) { return -1; @@ -4210,7 +4432,8 @@ int cmake::Build(const std::string& dir, const std::string& target, const std::string& config, const std::vector<std::string>& nativeOptions, - bool clean) + bool clean, + cmSystemTools::OutputOption outputflag) { if(!cmSystemTools::FileIsDirectory(dir.c_str())) { @@ -4252,6 +4475,48 @@ int cmake::Build(const std::string& dir, projName.c_str(), target.c_str(), &output, makeProgram.c_str(), - config.c_str(), clean, false, 0, true, + config.c_str(), clean, false, 0, outputflag, 0, nativeOptions); } + +void cmake::WatchUnusedCli(const char* var) +{ +#ifdef CMAKE_BUILD_WITH_CMAKE + this->VariableWatch->AddWatch(var, cmWarnUnusedCliWarning, this); + if(this->UsedCliVariables.find(var) == this->UsedCliVariables.end()) + { + this->UsedCliVariables[var] = false; + } +#endif +} + +void cmake::UnwatchUnusedCli(const char* var) +{ +#ifdef CMAKE_BUILD_WITH_CMAKE + this->VariableWatch->RemoveWatch(var, cmWarnUnusedCliWarning); + this->UsedCliVariables.erase(var); +#endif +} + +void cmake::RunCheckForUnusedVariables() +{ +#ifdef CMAKE_BUILD_WITH_CMAKE + bool haveUnused = false; + cmOStringStream msg; + msg << "Manually-specified variables were not used by the project:"; + for(std::map<cmStdString, bool>::const_iterator + it = this->UsedCliVariables.begin(); + it != this->UsedCliVariables.end(); ++it) + { + if(!it->second) + { + haveUnused = true; + msg << "\n " << it->first; + } + } + if(haveUnused) + { + this->IssueMessage(cmake::WARNING, msg.str(), cmListFileBacktrace()); + } +#endif +} |