diff options
Diffstat (limited to 'Source')
88 files changed, 2351 insertions, 854 deletions
diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index d41b10c..3db3d9e 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -2,5 +2,5 @@ set(CMake_VERSION_MAJOR 2) set(CMake_VERSION_MINOR 8) set(CMake_VERSION_PATCH 11) -set(CMake_VERSION_TWEAK 20130727) +set(CMake_VERSION_TWEAK 20130826) #set(CMake_VERSION_RC 1) diff --git a/Source/CTest/cmCTestBatchTestHandler.cxx b/Source/CTest/cmCTestBatchTestHandler.cxx index a22c7be..934481b 100644 --- a/Source/CTest/cmCTestBatchTestHandler.cxx +++ b/Source/CTest/cmCTestBatchTestHandler.cxx @@ -89,7 +89,7 @@ void cmCTestBatchTestHandler::WriteTestCommand(int test, std::fstream& fout) command = cmSystemTools::ConvertToOutputPath(command.c_str()); //Prepends memcheck args to our command string if this is a memcheck - this->TestHandler->GenerateTestCommand(processArgs); + this->TestHandler->GenerateTestCommand(processArgs, test); processArgs.push_back(command); for(std::vector<std::string>::iterator arg = processArgs.begin(); diff --git a/Source/CTest/cmCTestMemCheckHandler.cxx b/Source/CTest/cmCTestMemCheckHandler.cxx index 8baa673..3ae2ac6 100644 --- a/Source/CTest/cmCTestMemCheckHandler.cxx +++ b/Source/CTest/cmCTestMemCheckHandler.cxx @@ -200,6 +200,7 @@ void cmCTestMemCheckHandler::Initialize() this->CustomMaximumPassedTestOutputSize = 0; this->CustomMaximumFailedTestOutputSize = 0; this->MemoryTester = ""; + this->MemoryTesterDynamicOptions.clear(); this->MemoryTesterOptions.clear(); this->MemoryTesterStyle = UNKNOWN; this->MemoryTesterOutputFile = ""; @@ -242,12 +243,28 @@ int cmCTestMemCheckHandler::PostProcessHandler() //---------------------------------------------------------------------- void cmCTestMemCheckHandler::GenerateTestCommand( - std::vector<std::string>& args) + std::vector<std::string>& args, int test) { std::vector<cmStdString>::size_type pp; - std::string memcheckcommand = ""; - memcheckcommand + cmStdString index; + cmOStringStream stream; + std::string memcheckcommand = cmSystemTools::ConvertToOutputPath(this->MemoryTester.c_str()); + stream << test; + index = stream.str(); + for ( pp = 0; pp < this->MemoryTesterDynamicOptions.size(); pp ++ ) + { + cmStdString arg = this->MemoryTesterDynamicOptions[pp]; + cmStdString::size_type pos = arg.find("??"); + if (pos != cmStdString::npos) + { + arg.replace(pos, 2, index); + } + args.push_back(arg); + memcheckcommand += " \""; + memcheckcommand += arg; + memcheckcommand += "\""; + } for ( pp = 0; pp < this->MemoryTesterOptions.size(); pp ++ ) { args.push_back(this->MemoryTesterOptions[pp]); @@ -478,7 +495,8 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking() = cmSystemTools::ParseArguments(memoryTesterOptions.c_str()); this->MemoryTesterOutputFile - = this->CTest->GetBinaryDir() + "/Testing/Temporary/MemoryChecker.log"; + = this->CTest->GetBinaryDir() + + "/Testing/Temporary/MemoryChecker.??.log"; switch ( this->MemoryTesterStyle ) { @@ -510,7 +528,7 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking() } std::string outputFile = "--log-file=" + this->MemoryTesterOutputFile; - this->MemoryTesterOptions.push_back(outputFile); + this->MemoryTesterDynamicOptions.push_back(outputFile); break; } case cmCTestMemCheckHandler::PURIFY: @@ -538,19 +556,19 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking() outputFile = "-log-file="; #endif outputFile += this->MemoryTesterOutputFile; - this->MemoryTesterOptions.push_back(outputFile); + this->MemoryTesterDynamicOptions.push_back(outputFile); break; } case cmCTestMemCheckHandler::BOUNDS_CHECKER: { this->BoundsCheckerXMLFile = this->MemoryTesterOutputFile; std::string dpbdFile = this->CTest->GetBinaryDir() - + "/Testing/Temporary/MemoryChecker.DPbd"; + + "/Testing/Temporary/MemoryChecker.??.DPbd"; this->BoundsCheckerDPBDFile = dpbdFile; - this->MemoryTesterOptions.push_back("/B"); - this->MemoryTesterOptions.push_back(dpbdFile); - this->MemoryTesterOptions.push_back("/X"); - this->MemoryTesterOptions.push_back(this->MemoryTesterOutputFile); + this->MemoryTesterDynamicOptions.push_back("/B"); + this->MemoryTesterDynamicOptions.push_back(dpbdFile); + this->MemoryTesterDynamicOptions.push_back("/X"); + this->MemoryTesterDynamicOptions.push_back(this->MemoryTesterOutputFile); this->MemoryTesterOptions.push_back("/M"); break; } @@ -898,25 +916,23 @@ bool cmCTestMemCheckHandler::ProcessMemCheckBoundsCheckerOutput( // This method puts the bounds checker output file into the output // for the test void -cmCTestMemCheckHandler::PostProcessBoundsCheckerTest(cmCTestTestResult& res) +cmCTestMemCheckHandler::PostProcessBoundsCheckerTest(cmCTestTestResult& res, + int test) { cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "PostProcessBoundsCheckerTest for : " << res.Name.c_str() << std::endl); - if ( !cmSystemTools::FileExists(this->MemoryTesterOutputFile.c_str()) ) + cmStdString ofile = testOutputFileName(test); + if ( ofile.empty() ) { - std::string log = "Cannot find memory tester output file: " - + this->MemoryTesterOutputFile; - cmCTestLog(this->CTest, ERROR_MESSAGE, log.c_str() << std::endl); return; } // put a scope around this to close ifs so the file can be removed { - std::ifstream ifs(this->MemoryTesterOutputFile.c_str()); + std::ifstream ifs(ofile.c_str()); if ( !ifs ) { - std::string log = "Cannot read memory tester output file: " - + this->MemoryTesterOutputFile; + std::string log = "Cannot read memory tester output file: " + ofile; cmCTestLog(this->CTest, ERROR_MESSAGE, log.c_str() << std::endl); return; } @@ -939,38 +955,39 @@ cmCTestMemCheckHandler::PostProcessBoundsCheckerTest(cmCTestTestResult& res) } void -cmCTestMemCheckHandler::PostProcessPurifyTest(cmCTestTestResult& res) +cmCTestMemCheckHandler::PostProcessPurifyTest(cmCTestTestResult& res, + int test) { cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "PostProcessPurifyTest for : " << res.Name.c_str() << std::endl); - appendMemTesterOutput(res); + appendMemTesterOutput(res, test); } void -cmCTestMemCheckHandler::PostProcessValgrindTest(cmCTestTestResult& res) +cmCTestMemCheckHandler::PostProcessValgrindTest(cmCTestTestResult& res, + int test) { cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "PostProcessValgrindTest for : " << res.Name.c_str() << std::endl); - appendMemTesterOutput(res); + appendMemTesterOutput(res, test); } void -cmCTestMemCheckHandler::appendMemTesterOutput(cmCTestTestResult& res) +cmCTestMemCheckHandler::appendMemTesterOutput(cmCTestTestResult& res, + int test) { - if ( !cmSystemTools::FileExists(this->MemoryTesterOutputFile.c_str()) ) + cmStdString ofile = testOutputFileName(test); + + if ( ofile.empty() ) { - std::string log = "Cannot find memory tester output file: " - + this->MemoryTesterOutputFile; - cmCTestLog(this->CTest, ERROR_MESSAGE, log.c_str() << std::endl); return; } - std::ifstream ifs(this->MemoryTesterOutputFile.c_str()); + std::ifstream ifs(ofile.c_str()); if ( !ifs ) { - std::string log = "Cannot read memory tester output file: " - + this->MemoryTesterOutputFile; + std::string log = "Cannot read memory tester output file: " + ofile; cmCTestLog(this->CTest, ERROR_MESSAGE, log.c_str() << std::endl); return; } @@ -981,3 +998,25 @@ cmCTestMemCheckHandler::appendMemTesterOutput(cmCTestTestResult& res) res.Output += "\n"; } } + +cmStdString +cmCTestMemCheckHandler::testOutputFileName(int test) +{ + cmStdString index; + cmOStringStream stream; + stream << test; + index = stream.str(); + cmStdString ofile = this->MemoryTesterOutputFile; + cmStdString::size_type pos = ofile.find("??"); + ofile.replace(pos, 2, index); + + if ( !cmSystemTools::FileExists(ofile.c_str()) ) + { + std::string log = "Cannot find memory tester output file: " + + ofile; + cmCTestLog(this->CTest, ERROR_MESSAGE, log.c_str() << std::endl); + ofile = ""; + } + + return ofile; +} diff --git a/Source/CTest/cmCTestMemCheckHandler.h b/Source/CTest/cmCTestMemCheckHandler.h index 0a8c1b3..040d2e0 100644 --- a/Source/CTest/cmCTestMemCheckHandler.h +++ b/Source/CTest/cmCTestMemCheckHandler.h @@ -37,7 +37,7 @@ public: protected: virtual int PreProcessHandler(); virtual int PostProcessHandler(); - virtual void GenerateTestCommand(std::vector<std::string>& args); + virtual void GenerateTestCommand(std::vector<std::string>& args, int test); private: @@ -89,6 +89,7 @@ private: std::string BoundsCheckerDPBDFile; std::string BoundsCheckerXMLFile; std::string MemoryTester; + std::vector<cmStdString> MemoryTesterDynamicOptions; std::vector<cmStdString> MemoryTesterOptions; int MemoryTesterStyle; std::string MemoryTesterOutputFile; @@ -117,12 +118,16 @@ private: bool ProcessMemCheckBoundsCheckerOutput(const std::string& str, std::string& log, int* results); - void PostProcessPurifyTest(cmCTestTestResult& res); - void PostProcessBoundsCheckerTest(cmCTestTestResult& res); - void PostProcessValgrindTest(cmCTestTestResult& res); + void PostProcessPurifyTest(cmCTestTestResult& res, int test); + void PostProcessBoundsCheckerTest(cmCTestTestResult& res, int test); + void PostProcessValgrindTest(cmCTestTestResult& res, int test); ///! append MemoryTesterOutputFile to the test log - void appendMemTesterOutput(cmCTestTestHandler::cmCTestTestResult& res); + void appendMemTesterOutput(cmCTestTestHandler::cmCTestTestResult& res, + int test); + + ///! generate the output filename for the given test index + cmStdString testOutputFileName(int test); }; #endif diff --git a/Source/CTest/cmCTestRunTest.cxx b/Source/CTest/cmCTestRunTest.cxx index ddd7e45..0e2fa41 100644 --- a/Source/CTest/cmCTestRunTest.cxx +++ b/Source/CTest/cmCTestRunTest.cxx @@ -389,13 +389,13 @@ void cmCTestRunTest::MemCheckPostProcess() switch ( handler->MemoryTesterStyle ) { case cmCTestMemCheckHandler::VALGRIND: - handler->PostProcessValgrindTest(this->TestResult); + handler->PostProcessValgrindTest(this->TestResult, this->Index); break; case cmCTestMemCheckHandler::PURIFY: - handler->PostProcessPurifyTest(this->TestResult); + handler->PostProcessPurifyTest(this->TestResult, this->Index); break; case cmCTestMemCheckHandler::BOUNDS_CHECKER: - handler->PostProcessBoundsCheckerTest(this->TestResult); + handler->PostProcessBoundsCheckerTest(this->TestResult, this->Index); break; default: break; @@ -524,7 +524,7 @@ void cmCTestRunTest::ComputeArguments() = cmSystemTools::ConvertToOutputPath(this->ActualCommand.c_str()); //Prepends memcheck args to our command string - this->TestHandler->GenerateTestCommand(this->Arguments); + this->TestHandler->GenerateTestCommand(this->Arguments, this->Index); for(std::vector<std::string>::iterator i = this->Arguments.begin(); i != this->Arguments.end(); ++i) { diff --git a/Source/CTest/cmCTestTestHandler.cxx b/Source/CTest/cmCTestTestHandler.cxx index 0508448..497774d 100644 --- a/Source/CTest/cmCTestTestHandler.cxx +++ b/Source/CTest/cmCTestTestHandler.cxx @@ -1107,7 +1107,7 @@ void cmCTestTestHandler::ProcessDirectory(std::vector<cmStdString> &passed, } //---------------------------------------------------------------------- -void cmCTestTestHandler::GenerateTestCommand(std::vector<std::string>&) +void cmCTestTestHandler::GenerateTestCommand(std::vector<std::string>&, int) { } @@ -1302,10 +1302,9 @@ int cmCTestTestHandler::ExecuteCommands(std::vector<cmStdString>& vec) for ( it = vec.begin(); it != vec.end(); ++it ) { int retVal = 0; - std::string cmd = cmSystemTools::ConvertToOutputPath(it->c_str()); - cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Run command: " << cmd + cmCTestLog(this->CTest, HANDLER_VERBOSE_OUTPUT, "Run command: " << *it << std::endl); - if ( !cmSystemTools::RunSingleCommand(cmd.c_str(), 0, &retVal, 0, + if ( !cmSystemTools::RunSingleCommand(it->c_str(), 0, &retVal, 0, cmSystemTools::OUTPUT_MERGE /*this->Verbose*/) || retVal != 0 ) { diff --git a/Source/CTest/cmCTestTestHandler.h b/Source/CTest/cmCTestTestHandler.h index 8e59e59..93b793b 100644 --- a/Source/CTest/cmCTestTestHandler.h +++ b/Source/CTest/cmCTestTestHandler.h @@ -153,7 +153,7 @@ protected: // compute a final test list virtual int PreProcessHandler(); virtual int PostProcessHandler(); - virtual void GenerateTestCommand(std::vector<std::string>& args); + virtual void GenerateTestCommand(std::vector<std::string>& args, int test); int ExecuteCommands(std::vector<cmStdString>& vec); void WriteTestResultHeader(std::ostream& os, cmCTestTestResult* result); diff --git a/Source/QtDialog/CMakeLists.txt b/Source/QtDialog/CMakeLists.txt index 1684fb2..ef25294 100644 --- a/Source/QtDialog/CMakeLists.txt +++ b/Source/QtDialog/CMakeLists.txt @@ -11,6 +11,9 @@ #============================================================================= project(QtDialog) +if(POLICY CMP0020) + cmake_policy(SET CMP0020 NEW) # Drop when CMake >= 2.8.11 required +endif() find_package(Qt5Widgets QUIET) if (Qt5Widgets_FOUND) include_directories(${Qt5Widgets_INCLUDE_DIRS}) @@ -29,6 +32,11 @@ if (Qt5Widgets_FOUND) add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}") + + if(WIN32 AND TARGET Qt5::Core) + get_property(_Qt5_Core_LOCATION TARGET Qt5::Core PROPERTY LOCATION) + get_filename_component(Qt_BIN_DIR "${_Qt5_Core_LOCATION}" PATH) + endif() else() set(QT_MIN_VERSION "4.4.0") find_package(Qt4 REQUIRED) @@ -38,6 +46,13 @@ else() endif() include(${QT_USE_FILE}) + + if(WIN32 AND EXISTS "${QT_QMAKE_EXECUTABLE}") + get_filename_component(_Qt_BIN_DIR "${QT_QMAKE_EXECUTABLE}" PATH) + if(EXISTS "${_Qt_BIN_DIR}/QtCore4.dll") + set(Qt_BIN_DIR ${_Qt_BIN_DIR}) + endif() + endif() endif() set(SRCS @@ -91,6 +106,9 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) add_executable(cmake-gui WIN32 MACOSX_BUNDLE ${SRCS}) target_link_libraries(cmake-gui CMakeLib ${QT_QTMAIN_LIBRARY} ${QT_LIBRARIES}) +if(Qt_BIN_DIR) + set_property(TARGET cmake-gui PROPERTY Qt_BIN_DIR ${Qt_BIN_DIR}) +endif() if(APPLE) set_target_properties(cmake-gui PROPERTIES diff --git a/Source/cmAddDependenciesCommand.cxx b/Source/cmAddDependenciesCommand.cxx index 04a304e..e4d7f7f 100644 --- a/Source/cmAddDependenciesCommand.cxx +++ b/Source/cmAddDependenciesCommand.cxx @@ -24,6 +24,13 @@ bool cmAddDependenciesCommand } std::string target_name = args[0]; + if(this->Makefile->IsAlias(target_name.c_str())) + { + cmOStringStream e; + e << "Cannot add target-level dependencies to alias target \"" + << target_name << "\".\n"; + this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); + } if(cmTarget* target = this->Makefile->FindTargetToUse(target_name.c_str())) { std::vector<std::string>::const_iterator s = args.begin(); diff --git a/Source/cmAddExecutableCommand.cxx b/Source/cmAddExecutableCommand.cxx index 6dd8e5c..5785259 100644 --- a/Source/cmAddExecutableCommand.cxx +++ b/Source/cmAddExecutableCommand.cxx @@ -30,6 +30,7 @@ bool cmAddExecutableCommand bool excludeFromAll = false; bool importTarget = false; bool importGlobal = false; + bool isAlias = false; while ( s != args.end() ) { if (*s == "WIN32") @@ -57,6 +58,11 @@ bool cmAddExecutableCommand ++s; importGlobal = true; } + else if(*s == "ALIAS") + { + ++s; + isAlias = true; + } else { break; @@ -83,6 +89,72 @@ bool cmAddExecutableCommand } return false; } + if (isAlias) + { + if(!cmGeneratorExpression::IsValidTargetName(exename.c_str())) + { + this->SetError(("Invalid name for ALIAS: " + exename).c_str()); + return false; + } + if(excludeFromAll) + { + this->SetError("EXCLUDE_FROM_ALL with ALIAS makes no sense."); + return false; + } + if(importTarget || importGlobal) + { + this->SetError("IMPORTED with ALIAS is not allowed."); + return false; + } + if(args.size() != 3) + { + cmOStringStream e; + e << "ALIAS requires exactly one target argument."; + this->SetError(e.str().c_str()); + return false; + } + + const char *aliasedName = s->c_str(); + if(this->Makefile->IsAlias(aliasedName)) + { + cmOStringStream e; + e << "cannot create ALIAS target \"" << exename + << "\" because target \"" << aliasedName << "\" is itself an ALIAS."; + this->SetError(e.str().c_str()); + return false; + } + cmTarget *aliasedTarget = + this->Makefile->FindTargetToUse(aliasedName, true); + if(!aliasedTarget) + { + cmOStringStream e; + e << "cannot create ALIAS target \"" << exename + << "\" because target \"" << aliasedName << "\" does not already " + "exist."; + this->SetError(e.str().c_str()); + return false; + } + cmTarget::TargetType type = aliasedTarget->GetType(); + if(type != cmTarget::EXECUTABLE) + { + cmOStringStream e; + e << "cannot create ALIAS target \"" << exename + << "\" because target \"" << aliasedName << "\" is not an " + "executable."; + this->SetError(e.str().c_str()); + return false; + } + if(aliasedTarget->IsImported()) + { + cmOStringStream e; + e << "cannot create ALIAS target \"" << exename + << "\" because target \"" << aliasedName << "\" is IMPORTED."; + this->SetError(e.str().c_str()); + return false; + } + this->Makefile->AddAlias(exename.c_str(), aliasedTarget); + return true; + } // Handle imported target creation. if(importTarget) diff --git a/Source/cmAddExecutableCommand.h b/Source/cmAddExecutableCommand.h index 1e9f9b3..2774ce8 100644 --- a/Source/cmAddExecutableCommand.h +++ b/Source/cmAddExecutableCommand.h @@ -107,6 +107,19 @@ public: "(and its per-configuration version IMPORTED_LOCATION_<CONFIG>) " "which specifies the location of the main executable file on disk. " "See documentation of the IMPORTED_* properties for more information." + "\n" + "The signature\n" + " add_executable(<name> ALIAS <target>)\n" + "creates an alias, such that <name> can be used to refer to <target> " + "in subsequent commands. The <name> does not appear in the generated " + "buildsystem as a make target. The <target> may not be an IMPORTED " + "target or an ALIAS. Alias targets can be used as linkable targets, " + "targets to read properties from, executables for custom commands and " + "custom targets. They can also be tested for existance with the " + "regular if(TARGET) subcommand. The <name> may not be used to modify " + "properties of <target>, that is, it may not be used as the operand of " + "set_property, set_target_properties, target_link_libraries etc. An " + "ALIAS target may not be installed of exported." ; } diff --git a/Source/cmAddLibraryCommand.cxx b/Source/cmAddLibraryCommand.cxx index fd39eec..cbc6ed1 100644 --- a/Source/cmAddLibraryCommand.cxx +++ b/Source/cmAddLibraryCommand.cxx @@ -43,6 +43,7 @@ bool cmAddLibraryCommand // the type of library. Otherwise, it is treated as a source or // source list name. There may be two keyword arguments, check for them bool haveSpecifiedType = false; + bool isAlias = false; while ( s != args.end() ) { std::string libType = *s; @@ -76,6 +77,11 @@ bool cmAddLibraryCommand type = cmTarget::UNKNOWN_LIBRARY; haveSpecifiedType = true; } + else if(libType == "ALIAS") + { + ++s; + isAlias = true; + } else if(*s == "EXCLUDE_FROM_ALL") { ++s; @@ -96,6 +102,80 @@ bool cmAddLibraryCommand break; } } + if (isAlias) + { + if(!cmGeneratorExpression::IsValidTargetName(libName.c_str())) + { + this->SetError(("Invalid name for ALIAS: " + libName).c_str()); + return false; + } + if(excludeFromAll) + { + this->SetError("EXCLUDE_FROM_ALL with ALIAS makes no sense."); + return false; + } + if(importTarget || importGlobal) + { + this->SetError("IMPORTED with ALIAS is not allowed."); + return false; + } + if(args.size() != 3) + { + cmOStringStream e; + e << "ALIAS requires exactly one target argument."; + this->SetError(e.str().c_str()); + return false; + } + + const char *aliasedName = s->c_str(); + if(this->Makefile->IsAlias(aliasedName)) + { + cmOStringStream e; + e << "cannot create ALIAS target \"" << libName + << "\" because target \"" << aliasedName << "\" is itself an ALIAS."; + this->SetError(e.str().c_str()); + return false; + } + cmTarget *aliasedTarget = + this->Makefile->FindTargetToUse(aliasedName, true); + if(!aliasedTarget) + { + cmOStringStream e; + e << "cannot create ALIAS target \"" << libName + << "\" because target \"" << aliasedName << "\" does not already " + "exist."; + this->SetError(e.str().c_str()); + return false; + } + cmTarget::TargetType aliasedType = aliasedTarget->GetType(); + if(aliasedType != cmTarget::SHARED_LIBRARY + && aliasedType != cmTarget::STATIC_LIBRARY + && aliasedType != cmTarget::MODULE_LIBRARY + && aliasedType != cmTarget::OBJECT_LIBRARY) + { + cmOStringStream e; + e << "cannot create ALIAS target \"" << libName + << "\" because target \"" << aliasedName << "\" is not a library."; + this->SetError(e.str().c_str()); + return false; + } + if(aliasedTarget->IsImported()) + { + cmOStringStream e; + e << "cannot create ALIAS target \"" << libName + << "\" because target \"" << aliasedName << "\" is IMPORTED."; + this->SetError(e.str().c_str()); + return false; + } + this->Makefile->AddAlias(libName.c_str(), aliasedTarget); + return true; + } + + if(importTarget && excludeFromAll) + { + this->SetError("excludeFromAll with IMPORTED target makes no sense."); + return false; + } /* ideally we should check whether for the linker language of the target CMAKE_${LANG}_CREATE_SHARED_LIBRARY is defined and if not default to diff --git a/Source/cmAddLibraryCommand.h b/Source/cmAddLibraryCommand.h index e5f27cb..59354b0 100644 --- a/Source/cmAddLibraryCommand.h +++ b/Source/cmAddLibraryCommand.h @@ -138,6 +138,19 @@ public: "Some native build systems may not like targets that have only " "object files, so consider adding at least one real source file " "to any target that references $<TARGET_OBJECTS:objlib>." + "\n" + "The signature\n" + " add_library(<name> ALIAS <target>)\n" + "creates an alias, such that <name> can be used to refer to <target> " + "in subsequent commands. The <name> does not appear in the generated " + "buildsystem as a make target. The <target> may not be an IMPORTED " + "target or an ALIAS. Alias targets can be used as linkable targets, " + "targets to read properties from. They can also be tested for " + "existance with the " + "regular if(TARGET) subcommand. The <name> may not be used to modify " + "properties of <target>, that is, it may not be used as the operand of " + "set_property, set_target_properties, target_link_libraries etc. An " + "ALIAS target may not be installed of exported." ; } diff --git a/Source/cmCPluginAPI.cxx b/Source/cmCPluginAPI.cxx index 48ae50e..cb62f21 100644 --- a/Source/cmCPluginAPI.cxx +++ b/Source/cmCPluginAPI.cxx @@ -422,8 +422,9 @@ int CCONV cmExecuteCommand(void *arg, const char *name, for(int i = 0; i < numArgs; ++i) { // Assume all arguments are quoted. - lff.Arguments.push_back(cmListFileArgument(args[i], true, - "[CMake-Plugin]", 0)); + lff.Arguments.push_back( + cmListFileArgument(args[i], cmListFileArgument::Quoted, + "[CMake-Plugin]", 0)); } cmExecutionStatus status; return mf->ExecuteCommand(lff,status); diff --git a/Source/cmCommandArgumentParserHelper.cxx b/Source/cmCommandArgumentParserHelper.cxx index 2f26b0c..dbeeb07 100644 --- a/Source/cmCommandArgumentParserHelper.cxx +++ b/Source/cmCommandArgumentParserHelper.cxx @@ -12,10 +12,10 @@ #include "cmCommandArgumentParserHelper.h" #include "cmSystemTools.h" -#include "cmCommandArgumentLexer.h" - #include "cmMakefile.h" +#include "cmCommandArgumentLexer.h" + int cmCommandArgument_yyparse( yyscan_t yyscanner ); // cmCommandArgumentParserHelper::cmCommandArgumentParserHelper() diff --git a/Source/cmDocumentVariables.cxx b/Source/cmDocumentVariables.cxx index cfd5e76..2c2d377 100644 --- a/Source/cmDocumentVariables.cxx +++ b/Source/cmDocumentVariables.cxx @@ -963,9 +963,10 @@ void cmDocumentVariables::DefineVariables(cmake* cm) "Enables tracing output for target properties.", "This variable can be populated with a list of properties to generate " "debug output for when evaluating target properties. Currently it can " - "only be used when evaluating the INCLUDE_DIRECTORIES target property. " - "In that case, it outputs a backtrace for each include directory in " - "the build. Default is unset.",false,"Variables That Change Behavior"); + "only be used when evaluating the INCLUDE_DIRECTORIES, " + "COMPILE_DEFINITIONS and COMPILE_OPTIONS target properties. " + "In that case, it outputs a backtrace for each entry in the target " + "property. Default is unset.", false, "Variables That Change Behavior"); // Variables defined by CMake that describe the system @@ -1426,6 +1427,49 @@ void cmDocumentVariables::DefineVariables(cmake* cm) "Same as CMAKE_C_FLAGS_* but used by the linker " "when creating executables.",false, "Variables that Control the Build"); + + cm->DefineProperty + ("CMAKE_MODULE_LINKER_FLAGS", cmProperty::VARIABLE, + "Linker flags to be used to create modules.", + "These flags will be used by the linker when creating a module." + ,false, + "Variables that Control the Build"); + + cm->DefineProperty + ("CMAKE_MODULE_LINKER_FLAGS_<CONFIG>", cmProperty::VARIABLE, + "Flags to be used when linking a module.", + "Same as CMAKE_C_FLAGS_* but used by the linker " + "when creating modules.",false, + "Variables that Control the Build"); + + cm->DefineProperty + ("CMAKE_SHARED_LINKER_FLAGS", cmProperty::VARIABLE, + "Linker flags to be used to create shared libraries.", + "These flags will be used by the linker when creating a shared library." + ,false, + "Variables that Control the Build"); + + cm->DefineProperty + ("CMAKE_SHARED_LINKER_FLAGS_<CONFIG>", cmProperty::VARIABLE, + "Flags to be used when linking a shared library.", + "Same as CMAKE_C_FLAGS_* but used by the linker " + "when creating shared libraries.",false, + "Variables that Control the Build"); + + cm->DefineProperty + ("CMAKE_STATIC_LINKER_FLAGS", cmProperty::VARIABLE, + "Linker flags to be used to create static libraries.", + "These flags will be used by the linker when creating a static library." + ,false, + "Variables that Control the Build"); + + cm->DefineProperty + ("CMAKE_STATIC_LINKER_FLAGS_<CONFIG>", cmProperty::VARIABLE, + "Flags to be used when linking a static library.", + "Same as CMAKE_C_FLAGS_* but used by the linker " + "when creating static libraries.",false, + "Variables that Control the Build"); + cm->DefineProperty ("CMAKE_LIBRARY_PATH_FLAG", cmProperty::VARIABLE, "The flag to be used to add a library search path to a compiler.", @@ -1518,6 +1562,22 @@ void cmDocumentVariables::DefineVariables(cmake* cm) "See that target property for additional information.", false, "Variables that Control the Build"); + cm->DefineProperty + ("CMAKE_<LANG>_VISIBILITY_PRESET", cmProperty::VARIABLE, + "Default value for <LANG>_VISIBILITY_PRESET of targets.", + "This variable is used to initialize the " + "<LANG>_VISIBILITY_PRESET property on all the targets. " + "See that target property for additional information.", + false, + "Variables that Control the Build"); + cm->DefineProperty + ("CMAKE_VISIBILITY_INLINES_HIDDEN", cmProperty::VARIABLE, + "Default value for VISIBILITY_INLINES_HIDDEN of targets.", + "This variable is used to initialize the " + "VISIBILITY_INLINES_HIDDEN property on all the targets. " + "See that target property for additional information.", + false, + "Variables that Control the Build"); // Variables defined when the a language is enabled These variables will // also be defined whenever CMake has loaded its support for compiling (LANG) diff --git a/Source/cmExportCommand.cxx b/Source/cmExportCommand.cxx index 9c3f314..f059ceb 100644 --- a/Source/cmExportCommand.cxx +++ b/Source/cmExportCommand.cxx @@ -114,6 +114,15 @@ bool cmExportCommand currentTarget != this->Targets.GetVector().end(); ++currentTarget) { + if (this->Makefile->IsAlias(currentTarget->c_str())) + { + cmOStringStream e; + e << "given ALIAS target \"" << *currentTarget + << "\" which may not be exported."; + this->SetError(e.str().c_str()); + return false; + } + if(cmTarget* target = this->Makefile->GetLocalGenerator()-> GetGlobalGenerator()->FindTarget(0, currentTarget->c_str())) diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx index 36802b5..ef336ea 100644 --- a/Source/cmExportFileGenerator.cxx +++ b/Source/cmExportFileGenerator.cxx @@ -287,11 +287,33 @@ void cmExportFileGenerator::PopulateIncludeDirectoriesInterface( const char *propName = "INTERFACE_INCLUDE_DIRECTORIES"; const char *input = target->GetProperty(propName); - if (!input && tei->InterfaceIncludeDirectories.empty()) + + cmListFileBacktrace lfbt; + cmGeneratorExpression ge(lfbt); + + std::string dirs = tei->InterfaceIncludeDirectories; + this->ReplaceInstallPrefix(dirs); + cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(dirs); + std::string exportDirs = cge->Evaluate(target->GetMakefile(), 0, + false, target); + + if (cge->GetHadContextSensitiveCondition()) + { + cmMakefile* mf = target->GetMakefile(); + cmOStringStream e; + e << "Target \"" << target->GetName() << "\" is installed with " + "INCLUDES DESTINATION set to a context sensitive path. Paths which " + "depend on the configuration, policy values or the link interface are " + "not supported. Consider using target_include_directories instead."; + mf->IssueMessage(cmake::FATAL_ERROR, e.str()); + return; + } + + if (!input && exportDirs.empty()) { return; } - if (!*input && tei->InterfaceIncludeDirectories.empty()) + if ((input && !*input) && exportDirs.empty()) { // Set to empty properties[propName] = ""; @@ -300,7 +322,7 @@ void cmExportFileGenerator::PopulateIncludeDirectoriesInterface( std::string includes = (input?input:""); const char* sep = input ? ";" : ""; - includes += sep + tei->InterfaceIncludeDirectories; + includes += sep + exportDirs; std::string prepro = cmGeneratorExpression::Preprocess(includes, preprocessRule, true); @@ -641,7 +663,7 @@ cmExportFileGenerator cmMakefile *mf = target->GetMakefile(); cmOStringStream e; e << "Target \"" << target->GetName() << "\" has policy CMP0022 enabled, " - "but also has old-style INTERFACE_LINK_LIBRARIES properties " + "but also has old-style LINK_INTERFACE_LIBRARIES properties " "populated, but it was exported without the " "EXPORT_LINK_INTERFACE_LIBRARIES to export the old-style properties"; mf->IssueMessage(cmake::FATAL_ERROR, e.str()); diff --git a/Source/cmExprParserHelper.cxx b/Source/cmExprParserHelper.cxx index 9c1795e..cc35f84 100644 --- a/Source/cmExprParserHelper.cxx +++ b/Source/cmExprParserHelper.cxx @@ -12,10 +12,10 @@ #include "cmExprParserHelper.h" #include "cmSystemTools.h" -#include "cmExprLexer.h" - #include "cmMakefile.h" +#include "cmExprLexer.h" + int cmExpr_yyparse( yyscan_t yyscanner ); // cmExprParserHelper::cmExprParserHelper() diff --git a/Source/cmFileCommand.h b/Source/cmFileCommand.h index 586fee2..aa755d1 100644 --- a/Source/cmFileCommand.h +++ b/Source/cmFileCommand.h @@ -90,7 +90,7 @@ public: " file(TIMESTAMP filename variable [<format string>] [UTC])\n" " file(GENERATE OUTPUT output_file\n" " <INPUT input_file|CONTENT input_content>\n" - " CONDITION expression)\n" + " [CONDITION expression])\n" "WRITE will write a message into a file called 'filename'. It " "overwrites the file if it already exists, and creates the file " "if it does not exist. (If the file is a build input, use " diff --git a/Source/cmGeneratorExpressionEvaluator.cxx b/Source/cmGeneratorExpressionEvaluator.cxx index b59298f..e0c8c9e 100644 --- a/Source/cmGeneratorExpressionEvaluator.cxx +++ b/Source/cmGeneratorExpressionEvaluator.cxx @@ -747,6 +747,18 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode "Target name not supported."); return std::string(); } + if(propertyName == "ALIASED_TARGET") + { + if(context->Makefile->IsAlias(targetName.c_str())) + { + if(cmTarget* tgt = + context->Makefile->FindTargetToUse(targetName.c_str())) + { + return tgt->GetName(); + } + } + return ""; + } target = context->Makefile->FindTargetToUse( targetName.c_str()); @@ -790,11 +802,12 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode if (propertyName == "LINKER_LANGUAGE") { - if (dagCheckerParent && dagCheckerParent->EvaluatingLinkLibraries()) + if (target->LinkLanguagePropagatesToDependents() && + dagCheckerParent && dagCheckerParent->EvaluatingLinkLibraries()) { reportError(context, content->GetOriginalExpression(), "LINKER_LANGUAGE target property can not be used while evaluating " - "link libraries"); + "link libraries for a static library"); return std::string(); } const char *lang = target->GetLinkerLanguage(context->Config); diff --git a/Source/cmGeneratorExpressionParser.cxx b/Source/cmGeneratorExpressionParser.cxx index a619cec..e1fb8f1 100644 --- a/Source/cmGeneratorExpressionParser.cxx +++ b/Source/cmGeneratorExpressionParser.cxx @@ -126,6 +126,9 @@ void cmGeneratorExpressionParser::ParseGeneratorExpression( std::vector<std::vector<cmGeneratorExpressionToken>::const_iterator> commaTokens; std::vector<cmGeneratorExpressionToken>::const_iterator colonToken; + + bool emptyParamTermination = false; + if (this->it != this->Tokens.end() && this->it->TokenType == cmGeneratorExpressionToken::ColonSeparator) { @@ -133,6 +136,10 @@ void cmGeneratorExpressionParser::ParseGeneratorExpression( parameters.resize(parameters.size() + 1); assert(this->it != this->Tokens.end()); ++this->it; + if(this->it == this->Tokens.end()) + { + emptyParamTermination = true; + } while (this->it != this->Tokens.end() && this->it->TokenType == cmGeneratorExpressionToken::CommaSeparator) @@ -141,6 +148,10 @@ void cmGeneratorExpressionParser::ParseGeneratorExpression( parameters.resize(parameters.size() + 1); assert(this->it != this->Tokens.end()); ++this->it; + if(this->it == this->Tokens.end()) + { + emptyParamTermination = true; + } } while (this->it != this->Tokens.end() && this->it->TokenType == cmGeneratorExpressionToken::ColonSeparator) @@ -164,6 +175,10 @@ void cmGeneratorExpressionParser::ParseGeneratorExpression( parameters.resize(parameters.size() + 1); assert(this->it != this->Tokens.end()); ++this->it; + if(this->it == this->Tokens.end()) + { + emptyParamTermination = true; + } } while (this->it != this->Tokens.end() && this->it->TokenType == cmGeneratorExpressionToken::ColonSeparator) @@ -203,7 +218,10 @@ void cmGeneratorExpressionParser::ParseGeneratorExpression( assert(parameters.size() > commaTokens.size()); for ( ; pit != pend; ++pit, ++commaIt) { - extendResult(result, *pit); + if (!pit->empty() && !emptyParamTermination) + { + extendResult(result, *pit); + } if (commaIt != commaTokens.end()) { extendText(result, *commaIt); diff --git a/Source/cmGetPropertyCommand.cxx b/Source/cmGetPropertyCommand.cxx index 985dc50..faba7cd 100644 --- a/Source/cmGetPropertyCommand.cxx +++ b/Source/cmGetPropertyCommand.cxx @@ -288,6 +288,18 @@ bool cmGetPropertyCommand::HandleTargetMode() return false; } + if(this->PropertyName == "ALIASED_TARGET") + { + if(this->Makefile->IsAlias(this->Name.c_str())) + { + if(cmTarget* target = + this->Makefile->FindTargetToUse(this->Name.c_str())) + { + return this->StoreResult(target->GetName()); + } + } + return false; + } if(cmTarget* target = this->Makefile->FindTargetToUse(this->Name.c_str())) { return this->StoreResult(target->GetProperty(this->PropertyName.c_str())); diff --git a/Source/cmGetTargetPropertyCommand.cxx b/Source/cmGetTargetPropertyCommand.cxx index 1947139..02f00a5 100644 --- a/Source/cmGetTargetPropertyCommand.cxx +++ b/Source/cmGetTargetPropertyCommand.cxx @@ -22,17 +22,30 @@ bool cmGetTargetPropertyCommand } std::string var = args[0].c_str(); const char* targetName = args[1].c_str(); + const char *prop = 0; - if(cmTarget* tgt = this->Makefile->FindTargetToUse(targetName)) + if(args[2] == "ALIASED_TARGET") { - cmTarget& target = *tgt; - const char *prop = target.GetProperty(args[2].c_str()); - if (prop) + if(this->Makefile->IsAlias(targetName)) { - this->Makefile->AddDefinition(var.c_str(), prop); - return true; + if(cmTarget* target = + this->Makefile->FindTargetToUse(targetName)) + { + prop = target->GetName(); + } } } + else if(cmTarget* tgt = this->Makefile->FindTargetToUse(targetName)) + { + cmTarget& target = *tgt; + prop = target.GetProperty(args[2].c_str()); + } + + if (prop) + { + this->Makefile->AddDefinition(var.c_str(), prop); + return true; + } this->Makefile->AddDefinition(var.c_str(), (var+"-NOTFOUND").c_str()); return true; } diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 9b6ac93..7f2b592 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1769,10 +1769,22 @@ cmLocalGenerator* cmGlobalGenerator::FindLocalGenerator(const char* start_dir) return 0; } +//---------------------------------------------------------------------------- +void cmGlobalGenerator::AddAlias(const char *name, cmTarget *tgt) +{ + this->AliasTargets[name] = tgt; +} + +//---------------------------------------------------------------------------- +bool cmGlobalGenerator::IsAlias(const char *name) +{ + return this->AliasTargets.find(name) != this->AliasTargets.end(); +} //---------------------------------------------------------------------------- cmTarget* -cmGlobalGenerator::FindTarget(const char* project, const char* name) +cmGlobalGenerator::FindTarget(const char* project, const char* name, + bool excludeAliases) { // if project specific if(project) @@ -1780,7 +1792,8 @@ cmGlobalGenerator::FindTarget(const char* project, const char* name) std::vector<cmLocalGenerator*>* gens = &this->ProjectMap[project]; for(unsigned int i = 0; i < gens->size(); ++i) { - cmTarget* ret = (*gens)[i]->GetMakefile()->FindTarget(name); + cmTarget* ret = (*gens)[i]->GetMakefile()->FindTarget(name, + excludeAliases); if(ret) { return ret; @@ -1790,6 +1803,15 @@ cmGlobalGenerator::FindTarget(const char* project, const char* name) // if all projects/directories else { + if (!excludeAliases) + { + std::map<cmStdString, cmTarget*>::iterator ai + = this->AliasTargets.find(name); + if (ai != this->AliasTargets.end()) + { + return ai->second; + } + } std::map<cmStdString,cmTarget *>::iterator i = this->TotalTargets.find ( name ); if ( i != this->TotalTargets.end() ) diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index 2fcdc43..18aba24 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -196,7 +196,11 @@ public: void FindMakeProgram(cmMakefile*); ///! Find a target by name by searching the local generators. - cmTarget* FindTarget(const char* project, const char* name); + cmTarget* FindTarget(const char* project, const char* name, + bool excludeAliases = false); + + void AddAlias(const char *name, cmTarget *tgt); + bool IsAlias(const char *name); /** Determine if a name resolves to a framework on disk or a built target that is a framework. */ @@ -347,6 +351,7 @@ protected: // All targets in the entire project. std::map<cmStdString,cmTarget *> TotalTargets; + std::map<cmStdString,cmTarget *> AliasTargets; std::map<cmStdString,cmTarget *> ImportedTargets; std::vector<cmGeneratorExpressionEvaluationFile*> EvaluationFiles; diff --git a/Source/cmGlobalVisualStudio10Generator.cxx b/Source/cmGlobalVisualStudio10Generator.cxx index 0837f99..b2a337c 100644 --- a/Source/cmGlobalVisualStudio10Generator.cxx +++ b/Source/cmGlobalVisualStudio10Generator.cxx @@ -30,17 +30,17 @@ public: if(!strcmp(name, vs10Win32generatorName)) { return new cmGlobalVisualStudio10Generator( - vs10Win32generatorName, NULL, NULL); + name, NULL, NULL); } if(!strcmp(name, vs10Win64generatorName)) { return new cmGlobalVisualStudio10Generator( - vs10Win64generatorName, "x64", "CMAKE_FORCE_WIN64"); + name, "x64", "CMAKE_FORCE_WIN64"); } if(!strcmp(name, vs10IA64generatorName)) { return new cmGlobalVisualStudio10Generator( - vs10IA64generatorName, "Itanium", "CMAKE_FORCE_IA64"); + name, "Itanium", "CMAKE_FORCE_IA64"); } return 0; } @@ -69,9 +69,9 @@ cmGlobalGeneratorFactory* cmGlobalVisualStudio10Generator::NewFactory() //---------------------------------------------------------------------------- cmGlobalVisualStudio10Generator::cmGlobalVisualStudio10Generator( - const char* name, const char* architectureId, + const char* name, const char* platformName, const char* additionalPlatformDefinition) - : cmGlobalVisualStudio8Generator(name, architectureId, + : cmGlobalVisualStudio8Generator(name, platformName, additionalPlatformDefinition) { this->FindMakeProgramFile = "CMakeVS10FindMake.cmake"; @@ -79,6 +79,7 @@ cmGlobalVisualStudio10Generator::cmGlobalVisualStudio10Generator( this->ExpressEdition = cmSystemTools::ReadRegistryValue( "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VCExpress\\10.0\\Setup\\VC;" "ProductDir", vc10Express, cmSystemTools::KeyWOW64_32); + this->MasmEnabled = false; } //---------------------------------------------------------------------------- @@ -161,13 +162,23 @@ void cmGlobalVisualStudio10Generator ::EnableLanguage(std::vector<std::string>const & lang, cmMakefile *mf, bool optional) { - if(this->ArchitectureId == "Itanium" || this->ArchitectureId == "x64") + if(this->PlatformName == "Itanium" || this->PlatformName == "x64") { if(this->IsExpressEdition() && !this->Find64BitTools(mf)) { return; } } + + for(std::vector<std::string>::const_iterator it = lang.begin(); + it != lang.end(); ++it) + { + if(*it == "ASM_MASM") + { + this->MasmEnabled = true; + } + } + cmGlobalVisualStudio8Generator::EnableLanguage(lang, mf, optional); } diff --git a/Source/cmGlobalVisualStudio10Generator.h b/Source/cmGlobalVisualStudio10Generator.h index dbe6044..0a95091 100644 --- a/Source/cmGlobalVisualStudio10Generator.h +++ b/Source/cmGlobalVisualStudio10Generator.h @@ -25,7 +25,7 @@ class cmGlobalVisualStudio10Generator : { public: cmGlobalVisualStudio10Generator(const char* name, - const char* architectureId, const char* additionalPlatformDefinition); + const char* platformName, const char* additionalPlatformDefinition); static cmGlobalGeneratorFactory* NewFactory(); virtual bool SetGeneratorToolset(std::string const& ts); @@ -54,6 +54,9 @@ public: /** Is the installed VS an Express edition? */ bool IsExpressEdition() const { return this->ExpressEdition; } + /** Is the Microsoft Assembler enabled? */ + bool IsMasmEnabled() const { return this->MasmEnabled; } + /** The toolset name for the target platform. */ const char* GetPlatformToolset(); @@ -83,6 +86,7 @@ protected: std::string PlatformToolset; bool ExpressEdition; + bool MasmEnabled; bool UseFolderProperty(); diff --git a/Source/cmGlobalVisualStudio11Generator.cxx b/Source/cmGlobalVisualStudio11Generator.cxx index 624d01d..8ae7331 100644 --- a/Source/cmGlobalVisualStudio11Generator.cxx +++ b/Source/cmGlobalVisualStudio11Generator.cxx @@ -13,31 +13,56 @@ #include "cmLocalVisualStudio10Generator.h" #include "cmMakefile.h" -static const char vs11Win32generatorName[] = "Visual Studio 11"; -static const char vs11Win64generatorName[] = "Visual Studio 11 Win64"; -static const char vs11ARMgeneratorName[] = "Visual Studio 11 ARM"; +static const char vs11generatorName[] = "Visual Studio 11"; class cmGlobalVisualStudio11Generator::Factory : public cmGlobalGeneratorFactory { public: virtual cmGlobalGenerator* CreateGlobalGenerator(const char* name) const { - if(!strcmp(name, vs11Win32generatorName)) + if(strstr(name, vs11generatorName) != name) + { + return 0; + } + + const char* p = name + sizeof(vs11generatorName) - 1; + if(p[0] == '\0') { return new cmGlobalVisualStudio11Generator( - vs11Win32generatorName, NULL, NULL); + name, NULL, NULL); + } + + if(p[0] != ' ') + { + return 0; } - if(!strcmp(name, vs11Win64generatorName)) + + ++p; + + if(!strcmp(p, "ARM")) { return new cmGlobalVisualStudio11Generator( - vs11Win64generatorName, "x64", "CMAKE_FORCE_WIN64"); + name, "ARM", NULL); } - if(!strcmp(name, vs11ARMgeneratorName)) + + if(!strcmp(p, "Win64")) { return new cmGlobalVisualStudio11Generator( - vs11ARMgeneratorName, "ARM", NULL); + name, "x64", "CMAKE_FORCE_WIN64"); } - return 0; + + std::set<std::string> installedSDKs = + cmGlobalVisualStudio11Generator::GetInstalledWindowsCESDKs(); + + if(installedSDKs.find(p) == installedSDKs.end()) + { + return 0; + } + + cmGlobalVisualStudio11Generator* ret = + new cmGlobalVisualStudio11Generator(name, p, NULL); + ret->WindowsCEVersion = "8.00"; + return ret; } virtual void GetDocumentation(cmDocumentationEntry& entry) const { @@ -51,9 +76,18 @@ public: } virtual void GetGenerators(std::vector<std::string>& names) const { - names.push_back(vs11Win32generatorName); - names.push_back(vs11Win64generatorName); - names.push_back(vs11ARMgeneratorName); } + names.push_back(vs11generatorName); + names.push_back(vs11generatorName + std::string(" ARM")); + names.push_back(vs11generatorName + std::string(" Win64")); + + std::set<std::string> installedSDKs = + cmGlobalVisualStudio11Generator::GetInstalledWindowsCESDKs(); + for(std::set<std::string>::const_iterator i = + installedSDKs.begin(); i != installedSDKs.end(); ++i) + { + names.push_back("Visual Studio 11 " + *i); + } + } }; //---------------------------------------------------------------------------- @@ -64,9 +98,9 @@ cmGlobalGeneratorFactory* cmGlobalVisualStudio11Generator::NewFactory() //---------------------------------------------------------------------------- cmGlobalVisualStudio11Generator::cmGlobalVisualStudio11Generator( - const char* name, const char* architectureId, + const char* name, const char* platformName, const char* additionalPlatformDefinition) - : cmGlobalVisualStudio10Generator(name, architectureId, + : cmGlobalVisualStudio10Generator(name, platformName, additionalPlatformDefinition) { this->FindMakeProgramFile = "CMakeVS11FindMake.cmake"; @@ -109,3 +143,36 @@ bool cmGlobalVisualStudio11Generator::UseFolderProperty() // Express editions in VS10 and earlier, but they are in VS11 Express. return cmGlobalVisualStudio8Generator::UseFolderProperty(); } + +//---------------------------------------------------------------------------- +std::set<std::string> +cmGlobalVisualStudio11Generator::GetInstalledWindowsCESDKs() +{ + const char sdksKey[] = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\" + "Windows CE Tools\\SDKs"; + + std::vector<std::string> subkeys; + cmSystemTools::GetRegistrySubKeys(sdksKey, subkeys, + cmSystemTools::KeyWOW64_32); + + std::set<std::string> ret; + for(std::vector<std::string>::const_iterator i = + subkeys.begin(); i != subkeys.end(); ++i) + { + std::string key = sdksKey; + key += '\\'; + key += *i; + key += ';'; + + std::string path; + if(cmSystemTools::ReadRegistryValue(key.c_str(), + path, + cmSystemTools::KeyWOW64_32) && + !path.empty()) + { + ret.insert(*i); + } + } + + return ret; +} diff --git a/Source/cmGlobalVisualStudio11Generator.h b/Source/cmGlobalVisualStudio11Generator.h index 174f1cc..7cc7e69 100644 --- a/Source/cmGlobalVisualStudio11Generator.h +++ b/Source/cmGlobalVisualStudio11Generator.h @@ -21,7 +21,7 @@ class cmGlobalVisualStudio11Generator: { public: cmGlobalVisualStudio11Generator(const char* name, - const char* architectureId, const char* additionalPlatformDefinition); + const char* platformName, const char* additionalPlatformDefinition); static cmGlobalGeneratorFactory* NewFactory(); virtual void WriteSLNHeader(std::ostream& fout); @@ -34,7 +34,9 @@ public: protected: virtual const char* GetIDEVersion() { return "11.0"; } bool UseFolderProperty(); + static std::set<std::string> GetInstalledWindowsCESDKs(); private: class Factory; + friend class Factory; }; #endif diff --git a/Source/cmGlobalVisualStudio12Generator.cxx b/Source/cmGlobalVisualStudio12Generator.cxx index d77b84d..c56dfff 100644 --- a/Source/cmGlobalVisualStudio12Generator.cxx +++ b/Source/cmGlobalVisualStudio12Generator.cxx @@ -25,17 +25,17 @@ public: if(!strcmp(name, vs12Win32generatorName)) { return new cmGlobalVisualStudio12Generator( - vs12Win32generatorName, NULL, NULL); + name, NULL, NULL); } if(!strcmp(name, vs12Win64generatorName)) { return new cmGlobalVisualStudio12Generator( - vs12Win64generatorName, "x64", "CMAKE_FORCE_WIN64"); + name, "x64", "CMAKE_FORCE_WIN64"); } if(!strcmp(name, vs12ARMgeneratorName)) { return new cmGlobalVisualStudio12Generator( - vs12ARMgeneratorName, "ARM", NULL); + name, "ARM", NULL); } return 0; } @@ -64,9 +64,9 @@ cmGlobalGeneratorFactory* cmGlobalVisualStudio12Generator::NewFactory() //---------------------------------------------------------------------------- cmGlobalVisualStudio12Generator::cmGlobalVisualStudio12Generator( - const char* name, const char* architectureId, + const char* name, const char* platformName, const char* additionalPlatformDefinition) - : cmGlobalVisualStudio11Generator(name, architectureId, + : cmGlobalVisualStudio11Generator(name, platformName, additionalPlatformDefinition) { this->FindMakeProgramFile = "CMakeVS12FindMake.cmake"; @@ -100,12 +100,3 @@ cmLocalGenerator *cmGlobalVisualStudio12Generator::CreateLocalGenerator() lg->SetGlobalGenerator(this); return lg; } - -//---------------------------------------------------------------------------- -bool cmGlobalVisualStudio12Generator::UseFolderProperty() -{ - // Intentionally skip over the parent class implementation and call the - // grand-parent class's implementation. Folders are not supported by the - // Express editions in VS10 and earlier, but they are in VS12 Express. - return cmGlobalVisualStudio8Generator::UseFolderProperty(); -} diff --git a/Source/cmGlobalVisualStudio12Generator.h b/Source/cmGlobalVisualStudio12Generator.h index 5844ee0..064e310 100644 --- a/Source/cmGlobalVisualStudio12Generator.h +++ b/Source/cmGlobalVisualStudio12Generator.h @@ -21,7 +21,7 @@ class cmGlobalVisualStudio12Generator: { public: cmGlobalVisualStudio12Generator(const char* name, - const char* architectureId, const char* additionalPlatformDefinition); + const char* platformName, const char* additionalPlatformDefinition); static cmGlobalGeneratorFactory* NewFactory(); virtual void WriteSLNHeader(std::ostream& fout); @@ -33,7 +33,6 @@ public: virtual std::string GetUserMacrosDirectory() { return ""; } protected: virtual const char* GetIDEVersion() { return "12.0"; } - bool UseFolderProperty(); private: class Factory; }; diff --git a/Source/cmGlobalVisualStudio71Generator.cxx b/Source/cmGlobalVisualStudio71Generator.cxx index 2494f55..51efc46 100644 --- a/Source/cmGlobalVisualStudio71Generator.cxx +++ b/Source/cmGlobalVisualStudio71Generator.cxx @@ -16,7 +16,8 @@ #include "cmake.h" //---------------------------------------------------------------------------- -cmGlobalVisualStudio71Generator::cmGlobalVisualStudio71Generator() +cmGlobalVisualStudio71Generator::cmGlobalVisualStudio71Generator( + const char* platformName) : cmGlobalVisualStudio7Generator(platformName) { this->FindMakeProgramFile = "CMakeVS71FindMake.cmake"; this->ProjectConfigurationSectionName = "ProjectConfiguration"; @@ -281,20 +282,20 @@ void cmGlobalVisualStudio71Generator const std::set<std::string>& configsPartOfDefaultBuild, const char* platformMapping) { + const char* platformName = + platformMapping ? platformMapping : this->GetPlatformName(); std::string guid = this->GetGUID(name); for(std::vector<std::string>::iterator i = this->Configurations.begin(); i != this->Configurations.end(); ++i) { fout << "\t\t{" << guid << "}." << *i - << ".ActiveCfg = " << *i << "|" - << (platformMapping ? platformMapping : "Win32") << std::endl; + << ".ActiveCfg = " << *i << "|" << platformName << std::endl; std::set<std::string>::const_iterator ci = configsPartOfDefaultBuild.find(*i); if(!(ci == configsPartOfDefaultBuild.end())) { fout << "\t\t{" << guid << "}." << *i - << ".Build.0 = " << *i << "|" - << (platformMapping ? platformMapping : "Win32") << std::endl; + << ".Build.0 = " << *i << "|" << platformName << std::endl; } } } diff --git a/Source/cmGlobalVisualStudio71Generator.h b/Source/cmGlobalVisualStudio71Generator.h index 6d91f97..e136db7 100644 --- a/Source/cmGlobalVisualStudio71Generator.h +++ b/Source/cmGlobalVisualStudio71Generator.h @@ -23,7 +23,7 @@ class cmGlobalVisualStudio71Generator : public cmGlobalVisualStudio7Generator { public: - cmGlobalVisualStudio71Generator(); + cmGlobalVisualStudio71Generator(const char* platformName = NULL); static cmGlobalGeneratorFactory* NewFactory() { return new cmGlobalGeneratorSimpleFactory <cmGlobalVisualStudio71Generator>(); } diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx index 9a34ecf..b475665 100644 --- a/Source/cmGlobalVisualStudio7Generator.cxx +++ b/Source/cmGlobalVisualStudio7Generator.cxx @@ -17,9 +17,16 @@ #include "cmMakefile.h" #include "cmake.h" -cmGlobalVisualStudio7Generator::cmGlobalVisualStudio7Generator() +cmGlobalVisualStudio7Generator::cmGlobalVisualStudio7Generator( + const char* platformName) { this->FindMakeProgramFile = "CMakeVS7FindMake.cmake"; + + if (!platformName) + { + platformName = "Win32"; + } + this->PlatformName = platformName; } @@ -144,6 +151,13 @@ cmLocalGenerator *cmGlobalVisualStudio7Generator::CreateLocalGenerator() return lg; } +//---------------------------------------------------------------------------- +void cmGlobalVisualStudio7Generator::AddPlatformDefinitions(cmMakefile* mf) +{ + cmGlobalVisualStudioGenerator::AddPlatformDefinitions(mf); + mf->AddDefinition("CMAKE_VS_PLATFORM_NAME", this->GetPlatformName()); +} + void cmGlobalVisualStudio7Generator::GenerateConfigurations(cmMakefile* mf) { // process the configurations @@ -601,20 +615,20 @@ void cmGlobalVisualStudio7Generator const std::set<std::string>& configsPartOfDefaultBuild, const char* platformMapping) { + const char* platformName = + platformMapping ? platformMapping : this->GetPlatformName(); std::string guid = this->GetGUID(name); for(std::vector<std::string>::iterator i = this->Configurations.begin(); i != this->Configurations.end(); ++i) { fout << "\t\t{" << guid << "}." << *i - << ".ActiveCfg = " << *i << "|" - << (platformMapping ? platformMapping : "Win32") << "\n"; + << ".ActiveCfg = " << *i << "|" << platformName << "\n"; std::set<std::string>::const_iterator ci = configsPartOfDefaultBuild.find(*i); if(!(ci == configsPartOfDefaultBuild.end())) { fout << "\t\t{" << guid << "}." << *i - << ".Build.0 = " << *i << "|" - << (platformMapping ? platformMapping : "Win32") << "\n"; + << ".Build.0 = " << *i << "|" << platformName << "\n"; } } } diff --git a/Source/cmGlobalVisualStudio7Generator.h b/Source/cmGlobalVisualStudio7Generator.h index 3ebb408..4d22cff 100644 --- a/Source/cmGlobalVisualStudio7Generator.h +++ b/Source/cmGlobalVisualStudio7Generator.h @@ -26,7 +26,7 @@ struct cmIDEFlagTable; class cmGlobalVisualStudio7Generator : public cmGlobalVisualStudioGenerator { public: - cmGlobalVisualStudio7Generator(); + cmGlobalVisualStudio7Generator(const char* platformName = NULL); static cmGlobalGeneratorFactory* NewFactory() { return new cmGlobalGeneratorSimpleFactory <cmGlobalVisualStudio7Generator>(); } @@ -36,9 +36,14 @@ public: return cmGlobalVisualStudio7Generator::GetActualName();} static const char* GetActualName() {return "Visual Studio 7";} + ///! Get the name for the platform. + const char* GetPlatformName() const { return this->PlatformName.c_str(); } + ///! Create a local generator appropriate to this Global Generator virtual cmLocalGenerator *CreateLocalGenerator(); + virtual void AddPlatformDefinitions(cmMakefile* mf); + /** Get the documentation entry for this generator. */ static void GetDocumentation(cmDocumentationEntry& entry); @@ -153,6 +158,7 @@ protected: // Set during OutputSLNFile with the name of the current project. // There is one SLN file per project. std::string CurrentProject; + std::string PlatformName; }; #define CMAKE_CHECK_BUILD_SYSTEM_TARGET "ZERO_CHECK" diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx index 864e8db..e4244e0 100644 --- a/Source/cmGlobalVisualStudio8Generator.cxx +++ b/Source/cmGlobalVisualStudio8Generator.cxx @@ -57,8 +57,7 @@ public: } cmGlobalVisualStudio8Generator* ret = new cmGlobalVisualStudio8Generator( - name, parser.GetArchitectureFamily(), NULL); - ret->PlatformName = p; + name, p, NULL); ret->WindowsCEVersion = parser.GetOSVersion(); return ret; } @@ -96,16 +95,14 @@ cmGlobalGeneratorFactory* cmGlobalVisualStudio8Generator::NewFactory() //---------------------------------------------------------------------------- cmGlobalVisualStudio8Generator::cmGlobalVisualStudio8Generator( - const char* name, const char* architectureId, + const char* name, const char* platformName, const char* additionalPlatformDefinition) + : cmGlobalVisualStudio71Generator(platformName) { this->FindMakeProgramFile = "CMakeVS8FindMake.cmake"; this->ProjectConfigurationSectionName = "ProjectConfigurationPlatforms"; this->Name = name; - if (architectureId) - { - this->ArchitectureId = architectureId; - } + if (additionalPlatformDefinition) { this->AdditionalPlatformDefinition = additionalPlatformDefinition; @@ -113,20 +110,6 @@ cmGlobalVisualStudio8Generator::cmGlobalVisualStudio8Generator( } //---------------------------------------------------------------------------- -const char* cmGlobalVisualStudio8Generator::GetPlatformName() const -{ - if (!this->PlatformName.empty()) - { - return this->PlatformName.c_str(); - } - if (this->ArchitectureId == "X86") - { - return "Win32"; - } - return this->ArchitectureId.c_str(); -} - -//---------------------------------------------------------------------------- ///! Create a local generator appropriate to this Global Generator cmLocalGenerator *cmGlobalVisualStudio8Generator::CreateLocalGenerator() { @@ -142,7 +125,6 @@ cmLocalGenerator *cmGlobalVisualStudio8Generator::CreateLocalGenerator() void cmGlobalVisualStudio8Generator::AddPlatformDefinitions(cmMakefile* mf) { cmGlobalVisualStudio71Generator::AddPlatformDefinitions(mf); - mf->AddDefinition("CMAKE_VS_PLATFORM_NAME", this->GetPlatformName()); if(this->TargetsWindowsCE()) { diff --git a/Source/cmGlobalVisualStudio8Generator.h b/Source/cmGlobalVisualStudio8Generator.h index bcbd7a0..d181742 100644 --- a/Source/cmGlobalVisualStudio8Generator.h +++ b/Source/cmGlobalVisualStudio8Generator.h @@ -24,14 +24,12 @@ class cmGlobalVisualStudio8Generator : public cmGlobalVisualStudio71Generator { public: cmGlobalVisualStudio8Generator(const char* name, - const char* architectureId, const char* additionalPlatformDefinition); + const char* platformName, const char* additionalPlatformDefinition); static cmGlobalGeneratorFactory* NewFactory(); ///! Get the name for the generator. virtual const char* GetName() const {return this->Name.c_str();} - const char* GetPlatformName() const; - /** Get the documentation entry for this generator. */ static void GetDocumentation(cmDocumentationEntry& entry); @@ -87,7 +85,6 @@ protected: const char* path, cmTarget &t); std::string Name; - std::string PlatformName; std::string WindowsCEVersion; private: diff --git a/Source/cmGlobalVisualStudio9Generator.cxx b/Source/cmGlobalVisualStudio9Generator.cxx index 2082384..fba6ed1 100644 --- a/Source/cmGlobalVisualStudio9Generator.cxx +++ b/Source/cmGlobalVisualStudio9Generator.cxx @@ -62,8 +62,7 @@ public: } cmGlobalVisualStudio9Generator* ret = new cmGlobalVisualStudio9Generator( - name, parser.GetArchitectureFamily(), NULL); - ret->PlatformName = p; + name, p, NULL); ret->WindowsCEVersion = parser.GetOSVersion(); return ret; } @@ -102,9 +101,9 @@ cmGlobalGeneratorFactory* cmGlobalVisualStudio9Generator::NewFactory() //---------------------------------------------------------------------------- cmGlobalVisualStudio9Generator::cmGlobalVisualStudio9Generator( - const char* name, const char* architectureId, + const char* name, const char* platformName, const char* additionalPlatformDefinition) - : cmGlobalVisualStudio8Generator(name, architectureId, + : cmGlobalVisualStudio8Generator(name, platformName, additionalPlatformDefinition) { this->FindMakeProgramFile = "CMakeVS9FindMake.cmake"; diff --git a/Source/cmGlobalVisualStudio9Generator.h b/Source/cmGlobalVisualStudio9Generator.h index 1310a93..202aa8d 100644 --- a/Source/cmGlobalVisualStudio9Generator.h +++ b/Source/cmGlobalVisualStudio9Generator.h @@ -25,7 +25,7 @@ class cmGlobalVisualStudio9Generator : { public: cmGlobalVisualStudio9Generator(const char* name, - const char* architectureId, const char* additionalPlatformDefinition); + const char* platformName, const char* additionalPlatformDefinition); static cmGlobalGeneratorFactory* NewFactory(); ///! create the correct local generator diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx index f4be0ce..5931016 100644 --- a/Source/cmGlobalVisualStudioGenerator.cxx +++ b/Source/cmGlobalVisualStudioGenerator.cxx @@ -21,7 +21,6 @@ //---------------------------------------------------------------------------- cmGlobalVisualStudioGenerator::cmGlobalVisualStudioGenerator() { - this->ArchitectureId = "X86"; this->AdditionalPlatformDefinition = NULL; } @@ -499,9 +498,6 @@ void cmGlobalVisualStudioGenerator::ComputeVSTargetDepends(cmTarget& target) //---------------------------------------------------------------------------- void cmGlobalVisualStudioGenerator::AddPlatformDefinitions(cmMakefile* mf) { - mf->AddDefinition("MSVC_C_ARCHITECTURE_ID", this->ArchitectureId.c_str()); - mf->AddDefinition("MSVC_CXX_ARCHITECTURE_ID", this->ArchitectureId.c_str()); - if(this->AdditionalPlatformDefinition) { mf->AddDefinition(this->AdditionalPlatformDefinition, "TRUE"); diff --git a/Source/cmGlobalVisualStudioGenerator.h b/Source/cmGlobalVisualStudioGenerator.h index 9d81170..b665158 100644 --- a/Source/cmGlobalVisualStudioGenerator.h +++ b/Source/cmGlobalVisualStudioGenerator.h @@ -104,7 +104,6 @@ protected: std::string GetUtilityDepend(cmTarget* target); typedef std::map<cmTarget*, cmStdString> UtilityDependsMap; UtilityDependsMap UtilityDepends; - std::string ArchitectureId; const char* AdditionalPlatformDefinition; private: diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 63de1a5..7cb2d1f 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -1769,27 +1769,31 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target, configName); } - const char* linkFlagsProp = "LINK_FLAGS"; if(target.GetType() == cmTarget::OBJECT_LIBRARY || target.GetType() == cmTarget::STATIC_LIBRARY) { - linkFlagsProp = "STATIC_LIBRARY_FLAGS"; - } - const char* targetLinkFlags = target.GetProperty(linkFlagsProp); - if(targetLinkFlags) - { - extraLinkOptions += " "; - extraLinkOptions += targetLinkFlags; + this->CurrentLocalGenerator + ->GetStaticLibraryFlags(extraLinkOptions, + cmSystemTools::UpperCase(configName), + &target); } - if(configName && *configName) + else { - std::string linkFlagsVar = linkFlagsProp; - linkFlagsVar += "_"; - linkFlagsVar += cmSystemTools::UpperCase(configName); - if(const char* linkFlags = target.GetProperty(linkFlagsVar.c_str())) + const char* targetLinkFlags = target.GetProperty("LINK_FLAGS"); + if(targetLinkFlags) { - extraLinkOptions += " "; - extraLinkOptions += linkFlags; + this->CurrentLocalGenerator-> + AppendFlags(extraLinkOptions, targetLinkFlags); + } + if(configName && *configName) + { + std::string linkFlagsVar = "LINK_FLAGS_"; + linkFlagsVar += cmSystemTools::UpperCase(configName); + if(const char* linkFlags = target.GetProperty(linkFlagsVar.c_str())) + { + this->CurrentLocalGenerator-> + AppendFlags(extraLinkOptions, linkFlags); + } } } diff --git a/Source/cmInstallCommand.cxx b/Source/cmInstallCommand.cxx index 4649eda..3c76bd6 100644 --- a/Source/cmInstallCommand.cxx +++ b/Source/cmInstallCommand.cxx @@ -295,13 +295,6 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args) return false; } - if(!includesArgs.GetIncludeDirs().empty() && exports.GetString().empty()) - { - this->SetError("TARGETS given INCLUDES DESTINATION, but EXPORT set " - "not specified."); - return false; - } - // Enforce argument rules too complex to specify for the // general-purpose parser. if(archiveArgs.GetNamelinkOnly() || @@ -369,6 +362,15 @@ bool cmInstallCommand::HandleTargetsMode(std::vector<std::string> const& args) targetIt!=targetList.GetVector().end(); ++targetIt) { + + if (this->Makefile->IsAlias(targetIt->c_str())) + { + cmOStringStream e; + e << "TARGETS given target \"" << (*targetIt) + << "\" which is an alias."; + this->SetError(e.str().c_str()); + return false; + } // Lookup this target in the current directory. if(cmTarget* target=this->Makefile->FindTarget(targetIt->c_str())) { diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx index 36d84f3..898f379 100644 --- a/Source/cmListFileCache.cxx +++ b/Source/cmListFileCache.cxx @@ -22,45 +22,58 @@ # pragma warn -8060 /* possibly incorrect assignment */ #endif -bool cmListFileCacheParseFunction(cmListFileLexer* lexer, - cmListFileFunction& function, - const char* filename); +//---------------------------------------------------------------------------- +struct cmListFileParser +{ + cmListFileParser(cmListFile* lf, cmMakefile* mf, const char* filename); + ~cmListFileParser(); + bool ParseFile(); + bool ParseFunction(const char* name, long line); + void AddArgument(cmListFileLexer_Token* token, + cmListFileArgument::Delimiter delim); + cmListFile* ListFile; + cmMakefile* Makefile; + const char* FileName; + cmListFileLexer* Lexer; + cmListFileFunction Function; + enum { SeparationOkay, SeparationWarning } Separation; +}; -bool cmListFile::ParseFile(const char* filename, - bool topLevel, - cmMakefile *mf) +//---------------------------------------------------------------------------- +cmListFileParser::cmListFileParser(cmListFile* lf, cmMakefile* mf, + const char* filename): + ListFile(lf), Makefile(mf), FileName(filename), + Lexer(cmListFileLexer_New()) { - if(!cmSystemTools::FileExists(filename)) - { - return false; - } +} - // Create the scanner. - cmListFileLexer* lexer = cmListFileLexer_New(); - if(!lexer) - { - cmSystemTools::Error("cmListFileCache: error allocating lexer "); - return false; - } +//---------------------------------------------------------------------------- +cmListFileParser::~cmListFileParser() +{ + cmListFileLexer_Delete(this->Lexer); +} +//---------------------------------------------------------------------------- +bool cmListFileParser::ParseFile() +{ // Open the file. - if(!cmListFileLexer_SetFileName(lexer, filename)) + if(!cmListFileLexer_SetFileName(this->Lexer, this->FileName)) { - cmListFileLexer_Delete(lexer); cmSystemTools::Error("cmListFileCache: error can not open file ", - filename); + this->FileName); return false; } // Use a simple recursive-descent parser to process the token // stream. - this->ModifiedTime = cmSystemTools::ModifiedTime(filename); - bool parseError = false; bool haveNewline = true; - cmListFileLexer_Token* token; - while(!parseError && (token = cmListFileLexer_Scan(lexer))) + while(cmListFileLexer_Token* token = + cmListFileLexer_Scan(this->Lexer)) { - if(token->type == cmListFileLexer_Token_Newline) + if(token->type == cmListFileLexer_Token_Space) + { + } + else if(token->type == cmListFileLexer_Token_Newline) { haveNewline = true; } @@ -69,51 +82,66 @@ bool cmListFile::ParseFile(const char* filename, if(haveNewline) { haveNewline = false; - cmListFileFunction inFunction; - inFunction.Name = token->text; - inFunction.FilePath = filename; - inFunction.Line = token->line; - if(cmListFileCacheParseFunction(lexer, inFunction, filename)) + if(this->ParseFunction(token->text, token->line)) { - this->Functions.push_back(inFunction); + this->ListFile->Functions.push_back(this->Function); } else { - parseError = true; + return false; } } else { cmOStringStream error; error << "Error in cmake code at\n" - << filename << ":" << token->line << ":\n" + << this->FileName << ":" << token->line << ":\n" << "Parse error. Expected a newline, got " - << cmListFileLexer_GetTypeAsString(lexer, token->type) + << cmListFileLexer_GetTypeAsString(this->Lexer, token->type) << " with text \"" << token->text << "\"."; cmSystemTools::Error(error.str().c_str()); - parseError = true; + return false; } } else { cmOStringStream error; error << "Error in cmake code at\n" - << filename << ":" << token->line << ":\n" + << this->FileName << ":" << token->line << ":\n" << "Parse error. Expected a command name, got " - << cmListFileLexer_GetTypeAsString(lexer, token->type) + << cmListFileLexer_GetTypeAsString(this->Lexer, token->type) << " with text \"" << token->text << "\"."; cmSystemTools::Error(error.str().c_str()); - parseError = true; + return false; } } - if (parseError) + return true; +} + +//---------------------------------------------------------------------------- +bool cmListFile::ParseFile(const char* filename, + bool topLevel, + cmMakefile *mf) +{ + if(!cmSystemTools::FileExists(filename)) + { + return false; + } + + bool parseError = false; + this->ModifiedTime = cmSystemTools::ModifiedTime(filename); + + { + cmListFileParser parser(this, mf, filename); + parseError = !parser.ParseFile(); + } + + if(parseError) { this->ModifiedTime = 0; } - cmListFileLexer_Delete(lexer); - // do we need a cmake_policy(VERSION call? if(topLevel) { @@ -196,7 +224,8 @@ bool cmListFile::ParseFile(const char* filename, { cmListFileFunction project; project.Name = "PROJECT"; - cmListFileArgument prj("Project", false, filename, 0); + cmListFileArgument prj("Project", cmListFileArgument::Unquoted, + filename, 0); project.Arguments.push_back(prj); this->Functions.insert(this->Functions.begin(),project); } @@ -208,17 +237,24 @@ bool cmListFile::ParseFile(const char* filename, return true; } -bool cmListFileCacheParseFunction(cmListFileLexer* lexer, - cmListFileFunction& function, - const char* filename) +//---------------------------------------------------------------------------- +bool cmListFileParser::ParseFunction(const char* name, long line) { + // Inintialize a new function call. + this->Function = cmListFileFunction(); + this->Function.FilePath = this->FileName; + this->Function.Name = name; + this->Function.Line = line; + // Command name has already been parsed. Read the left paren. cmListFileLexer_Token* token; - if(!(token = cmListFileLexer_Scan(lexer))) + while((token = cmListFileLexer_Scan(this->Lexer)) && + token->type == cmListFileLexer_Token_Space) {} + if(!token) { cmOStringStream error; - error << "Error in cmake code at\n" - << filename << ":" << cmListFileLexer_GetCurrentLine(lexer) << ":\n" + error << "Error in cmake code at\n" << this->FileName << ":" + << cmListFileLexer_GetCurrentLine(this->Lexer) << ":\n" << "Parse error. Function missing opening \"(\"."; cmSystemTools::Error(error.str().c_str()); return false; @@ -226,26 +262,33 @@ bool cmListFileCacheParseFunction(cmListFileLexer* lexer, if(token->type != cmListFileLexer_Token_ParenLeft) { cmOStringStream error; - error << "Error in cmake code at\n" - << filename << ":" << cmListFileLexer_GetCurrentLine(lexer) << ":\n" + error << "Error in cmake code at\n" << this->FileName << ":" + << cmListFileLexer_GetCurrentLine(this->Lexer) << ":\n" << "Parse error. Expected \"(\", got " - << cmListFileLexer_GetTypeAsString(lexer, token->type) + << cmListFileLexer_GetTypeAsString(this->Lexer, token->type) << " with text \"" << token->text << "\"."; cmSystemTools::Error(error.str().c_str()); return false; } // Arguments. - unsigned long lastLine = cmListFileLexer_GetCurrentLine(lexer); + unsigned long lastLine; unsigned long parenDepth = 0; - while((token = cmListFileLexer_Scan(lexer))) + this->Separation = SeparationOkay; + while((lastLine = cmListFileLexer_GetCurrentLine(this->Lexer), + token = cmListFileLexer_Scan(this->Lexer))) { + if(token->type == cmListFileLexer_Token_Space || + token->type == cmListFileLexer_Token_Newline) + { + this->Separation = SeparationOkay; + continue; + } if(token->type == cmListFileLexer_Token_ParenLeft) { parenDepth++; - cmListFileArgument a("(", - false, filename, token->line); - function.Arguments.push_back(a); + this->Separation = SeparationOkay; + this->AddArgument(token, cmListFileArgument::Unquoted); } else if(token->type == cmListFileLexer_Token_ParenRight) { @@ -254,43 +297,39 @@ bool cmListFileCacheParseFunction(cmListFileLexer* lexer, return true; } parenDepth--; - cmListFileArgument a(")", - false, filename, token->line); - function.Arguments.push_back(a); + this->Separation = SeparationOkay; + this->AddArgument(token, cmListFileArgument::Unquoted); + this->Separation = SeparationWarning; } else if(token->type == cmListFileLexer_Token_Identifier || token->type == cmListFileLexer_Token_ArgumentUnquoted) { - cmListFileArgument a(token->text, - false, filename, token->line); - function.Arguments.push_back(a); + this->AddArgument(token, cmListFileArgument::Unquoted); + this->Separation = SeparationWarning; } else if(token->type == cmListFileLexer_Token_ArgumentQuoted) { - cmListFileArgument a(token->text, - true, filename, token->line); - function.Arguments.push_back(a); + this->AddArgument(token, cmListFileArgument::Quoted); + this->Separation = SeparationWarning; } - else if(token->type != cmListFileLexer_Token_Newline) + else { // Error. cmOStringStream error; - error << "Error in cmake code at\n" - << filename << ":" << cmListFileLexer_GetCurrentLine(lexer) - << ":\n" + error << "Error in cmake code at\n" << this->FileName << ":" + << cmListFileLexer_GetCurrentLine(this->Lexer) << ":\n" << "Parse error. Function missing ending \")\". " << "Instead found " - << cmListFileLexer_GetTypeAsString(lexer, token->type) + << cmListFileLexer_GetTypeAsString(this->Lexer, token->type) << " with text \"" << token->text << "\"."; cmSystemTools::Error(error.str().c_str()); return false; } - lastLine = cmListFileLexer_GetCurrentLine(lexer); } cmOStringStream error; error << "Error in cmake code at\n" - << filename << ":" << lastLine << ":\n" + << this->FileName << ":" << lastLine << ":\n" << "Parse error. Function missing ending \")\". " << "End of file reached."; cmSystemTools::Error(error.str().c_str()); @@ -299,6 +338,45 @@ bool cmListFileCacheParseFunction(cmListFileLexer* lexer, } //---------------------------------------------------------------------------- +void cmListFileParser::AddArgument(cmListFileLexer_Token* token, + cmListFileArgument::Delimiter delim) +{ + cmListFileArgument a(token->text, delim, this->FileName, token->line); + this->Function.Arguments.push_back(a); + if(delim == cmListFileArgument::Unquoted) + { + // Warn about a future behavior change. + const char* c = a.Value.c_str(); + if(*c++ == '[') + { + while(*c == '=') + { ++c; } + if(*c == '[') + { + cmOStringStream m; + m << "Syntax Warning in cmake code at\n" + << " " << this->FileName << ":" << token->line << ":" + << token->column << "\n" + << "A future version of CMake may treat unquoted argument:\n" + << " " << a.Value << "\n" + << "as an opening long bracket. Double-quote the argument."; + this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, m.str().c_str()); + } + } + } + if(this->Separation == SeparationOkay) + { + return; + } + cmOStringStream m; + m << "Syntax Warning in cmake code at\n" + << " " << this->FileName << ":" << token->line << ":" + << token->column << "\n" + << "Argument not separated from preceding token by whitespace."; + this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, m.str().c_str()); +} + +//---------------------------------------------------------------------------- std::ostream& operator<<(std::ostream& os, cmListFileContext const& lfc) { os << lfc.FilePath; diff --git a/Source/cmListFileCache.h b/Source/cmListFileCache.h index fec3d07..7bb3b34 100644 --- a/Source/cmListFileCache.h +++ b/Source/cmListFileCache.h @@ -25,22 +25,27 @@ class cmMakefile; struct cmListFileArgument { - cmListFileArgument(): Value(), Quoted(false), FilePath(0), Line(0) {} + enum Delimiter + { + Unquoted, + Quoted + }; + cmListFileArgument(): Value(), Delim(Unquoted), FilePath(0), Line(0) {} cmListFileArgument(const cmListFileArgument& r): - Value(r.Value), Quoted(r.Quoted), FilePath(r.FilePath), Line(r.Line) {} - cmListFileArgument(const std::string& v, bool q, const char* file, - long line): Value(v), Quoted(q), + Value(r.Value), Delim(r.Delim), FilePath(r.FilePath), Line(r.Line) {} + cmListFileArgument(const std::string& v, Delimiter d, const char* file, + long line): Value(v), Delim(d), FilePath(file), Line(line) {} bool operator == (const cmListFileArgument& r) const { - return (this->Value == r.Value) && (this->Quoted == r.Quoted); + return (this->Value == r.Value) && (this->Delim == r.Delim); } bool operator != (const cmListFileArgument& r) const { return !(*this == r); } std::string Value; - bool Quoted; + Delimiter Delim; const char* FilePath; long Line; }; diff --git a/Source/cmListFileLexer.c b/Source/cmListFileLexer.c index e7965b5..2841fe5 100644 --- a/Source/cmListFileLexer.c +++ b/Source/cmListFileLexer.c @@ -9,7 +9,7 @@ #define FLEX_SCANNER #define YY_FLEX_MAJOR_VERSION 2 #define YY_FLEX_MINOR_VERSION 5 -#define YY_FLEX_SUBMINOR_VERSION 31 +#define YY_FLEX_SUBMINOR_VERSION 35 #if YY_FLEX_SUBMINOR_VERSION > 0 #define FLEX_BETA #endif @@ -31,7 +31,15 @@ /* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */ -#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + +/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, + * if you want the limit (max/min) macros for int types. + */ +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS 1 +#endif + #include <inttypes.h> typedef int8_t flex_int8_t; typedef uint8_t flex_uint8_t; @@ -46,7 +54,6 @@ typedef int flex_int32_t; typedef unsigned char flex_uint8_t; typedef unsigned short int flex_uint16_t; typedef unsigned int flex_uint32_t; -#endif /* ! C99 */ /* Limits of integral types. */ #ifndef INT8_MIN @@ -77,6 +84,8 @@ typedef unsigned int flex_uint32_t; #define UINT32_MAX (4294967295U) #endif +#endif /* ! C99 */ + #endif /* ! FLEXINT_H */ #ifdef __cplusplus @@ -86,11 +95,12 @@ typedef unsigned int flex_uint32_t; #else /* ! __cplusplus */ -#if __STDC__ +/* C99 requires __STDC__ to be defined as 1. */ +#if defined (__STDC__) #define YY_USE_CONST -#endif /* __STDC__ */ +#endif /* defined (__STDC__) */ #endif /* ! __cplusplus */ #ifdef YY_USE_CONST @@ -126,8 +136,6 @@ typedef void* yyscan_t; #define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column) #define yy_flex_debug yyg->yy_flex_debug_r -int cmListFileLexer_yylex_init (yyscan_t* scanner); - /* Enter a start condition. This macro really ought to take a parameter, * but we do it the disgusting crufty way forced on us by the ()-less * definition of BEGIN. @@ -151,9 +159,21 @@ int cmListFileLexer_yylex_init (yyscan_t* scanner); /* Size of default input buffer. */ #ifndef YY_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k. + * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. + * Ditto for the __ia64__ case accordingly. + */ +#define YY_BUF_SIZE 32768 +#else #define YY_BUF_SIZE 16384 +#endif /* __ia64__ */ #endif +/* The state buf must be large enough to hold one state per character in the main buffer. + */ +#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) + #ifndef YY_TYPEDEF_YY_BUFFER_STATE #define YY_TYPEDEF_YY_BUFFER_STATE typedef struct yy_buffer_state *YY_BUFFER_STATE; @@ -192,14 +212,9 @@ typedef struct yy_buffer_state *YY_BUFFER_STATE; } \ while ( 0 ) -/* The following is because we cannot portably get our hands on size_t - * (without autoconf's help, which isn't available because we want - * flex-generated scanners to compile on their own). - */ - #ifndef YY_TYPEDEF_YY_SIZE_T #define YY_TYPEDEF_YY_SIZE_T -typedef unsigned int yy_size_t; +typedef size_t yy_size_t; #endif #ifndef YY_STRUCT_YY_BUFFER_STATE @@ -354,8 +369,8 @@ static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner ); *yy_cp = '\0'; \ yyg->yy_c_buf_p = yy_cp; -#define YY_NUM_RULES 14 -#define YY_END_OF_BUFFER 15 +#define YY_NUM_RULES 16 +#define YY_END_OF_BUFFER 17 /* This struct is not used in this scanner, but its presence is necessary. */ struct yy_trans_info @@ -363,12 +378,13 @@ struct yy_trans_info flex_int32_t yy_verify; flex_int32_t yy_nxt; }; -static yyconst flex_int16_t yy_accept[39] = +static yyconst flex_int16_t yy_accept[45] = { 0, - 0, 0, 0, 0, 15, 6, 12, 1, 7, 2, - 6, 3, 4, 6, 13, 8, 9, 10, 11, 6, - 0, 6, 0, 2, 0, 5, 6, 8, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 + 0, 0, 0, 0, 17, 6, 14, 1, 8, 2, + 6, 3, 4, 6, 15, 9, 11, 12, 13, 6, + 0, 6, 0, 14, 2, 0, 5, 6, 9, 0, + 10, 0, 7, 0, 0, 0, 7, 0, 7, 0, + 0, 0, 0, 0 } ; static yyconst flex_int32_t yy_ec[256] = @@ -405,64 +421,70 @@ static yyconst flex_int32_t yy_ec[256] = static yyconst flex_int32_t yy_meta[13] = { 0, - 1, 1, 2, 1, 3, 1, 1, 1, 4, 4, - 4, 1 + 1, 2, 3, 2, 4, 1, 1, 1, 5, 5, + 5, 1 } ; -static yyconst flex_int16_t yy_base[48] = +static yyconst flex_int16_t yy_base[56] = { 0, - 0, 0, 10, 20, 34, 32, 89, 89, 89, 0, - 23, 89, 89, 35, 0, 18, 89, 89, 44, 0, - 49, 21, 0, 0, 19, 0, 0, 15, 59, 0, - 18, 0, 15, 12, 11, 10, 9, 89, 64, 68, - 72, 76, 80, 13, 84, 12, 10 + 0, 0, 10, 20, 38, 32, 0, 109, 109, 0, + 28, 109, 109, 35, 0, 23, 109, 109, 44, 0, + 49, 26, 0, 0, 0, 22, 0, 0, 18, 24, + 109, 0, 61, 20, 0, 18, 0, 17, 16, 0, + 12, 11, 10, 109, 73, 16, 78, 83, 88, 93, + 12, 98, 11, 103, 9 } ; -static yyconst flex_int16_t yy_def[48] = +static yyconst flex_int16_t yy_def[56] = { 0, - 38, 1, 39, 39, 38, 38, 38, 38, 38, 40, - 6, 38, 38, 6, 41, 42, 38, 38, 42, 6, - 38, 6, 43, 40, 44, 14, 6, 42, 42, 21, - 21, 45, 46, 44, 47, 46, 47, 0, 38, 38, - 38, 38, 38, 38, 38, 38, 38 + 44, 1, 45, 45, 44, 44, 46, 44, 44, 47, + 6, 44, 44, 6, 48, 49, 44, 44, 49, 6, + 44, 6, 50, 46, 47, 51, 14, 6, 49, 49, + 44, 21, 44, 21, 52, 53, 33, 51, 33, 54, + 55, 53, 55, 0, 44, 44, 44, 44, 44, 44, + 44, 44, 44, 44, 44 } ; -static yyconst flex_int16_t yy_nxt[102] = +static yyconst flex_int16_t yy_nxt[122] = { 0, 6, 7, 8, 7, 9, 10, 11, 12, 13, 6, - 14, 15, 17, 37, 18, 36, 34, 30, 20, 30, - 27, 19, 17, 20, 18, 35, 29, 27, 33, 29, - 25, 19, 20, 38, 38, 38, 21, 38, 22, 38, - 38, 20, 20, 23, 26, 26, 28, 38, 28, 30, - 30, 38, 38, 20, 38, 31, 38, 38, 30, 30, - 32, 28, 38, 28, 16, 16, 16, 16, 24, 38, - 24, 24, 27, 38, 27, 27, 28, 38, 38, 28, - 20, 38, 20, 20, 30, 38, 30, 30, 5, 38, - 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, - - 38 + 14, 15, 17, 43, 18, 42, 38, 24, 32, 33, + 32, 19, 17, 36, 18, 37, 33, 41, 29, 30, + 37, 19, 20, 36, 30, 26, 21, 44, 22, 44, + 44, 20, 20, 23, 27, 27, 31, 44, 29, 32, + 32, 44, 44, 33, 44, 34, 44, 44, 32, 32, + 35, 33, 44, 44, 44, 21, 44, 39, 44, 44, + 33, 33, 40, 16, 16, 16, 16, 16, 25, 25, + 44, 25, 25, 28, 28, 44, 28, 28, 29, 29, + 44, 44, 29, 20, 20, 44, 20, 20, 32, 32, + + 44, 32, 32, 33, 33, 44, 33, 33, 5, 44, + 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, + 44 } ; -static yyconst flex_int16_t yy_chk[102] = +static yyconst flex_int16_t yy_chk[122] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 3, 47, 3, 46, 44, 37, 36, 35, - 34, 3, 4, 33, 4, 31, 28, 25, 22, 16, - 11, 4, 6, 5, 0, 0, 6, 0, 6, 0, + 1, 1, 3, 55, 3, 53, 51, 46, 43, 42, + 41, 3, 4, 39, 4, 38, 36, 34, 30, 29, + 26, 4, 6, 22, 16, 11, 6, 5, 6, 0, 0, 6, 6, 6, 14, 14, 19, 0, 19, 21, 21, 0, 0, 21, 0, 21, 0, 0, 21, 21, - 21, 29, 0, 29, 39, 39, 39, 39, 40, 0, - 40, 40, 41, 0, 41, 41, 42, 0, 0, 42, - 43, 0, 43, 43, 45, 0, 45, 45, 38, 38, - 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, - - 38 + 21, 33, 0, 0, 0, 33, 0, 33, 0, 0, + 33, 33, 33, 45, 45, 45, 45, 45, 47, 47, + 0, 47, 47, 48, 48, 0, 48, 48, 49, 49, + 0, 0, 49, 50, 50, 0, 50, 50, 52, 52, + + 0, 52, 52, 54, 54, 0, 54, 54, 44, 44, + 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, + 44 } ; /* Table of booleans, true if rule could match eol. */ -static yyconst flex_int32_t yy_rule_can_match_eol[15] = +static yyconst flex_int32_t yy_rule_can_match_eol[17] = { 0, -1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, }; +1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, }; /* The intent behind this definition is that it'll catch * any uses of REJECT which flex missed. @@ -494,9 +516,11 @@ Run flex like this: Modify cmListFileLexer.c: - remove TABs + - remove use of the 'register' storage class specifier - remove the yyunput function - add a statement "(void)yyscanner;" to the top of these methods: yy_fatal_error, cmListFileLexer_yyalloc, cmListFileLexer_yyrealloc, cmListFileLexer_yyfree + - remove statement "yyscanner = NULL;" from cmListFileLexer_yylex_destroy - remove all YY_BREAK lines occurring right after return statements - remove the isatty forward declaration @@ -540,7 +564,7 @@ static void cmListFileLexerDestroy(cmListFileLexer* lexer); /*--------------------------------------------------------------------------*/ -#line 568 "cmListFileLexer.c" +#line 570 "cmListFileLexer.c" #define INITIAL 0 #define STRING 1 @@ -591,6 +615,12 @@ struct yyguts_t }; /* end struct yyguts_t */ +static int yy_init_globals (yyscan_t yyscanner ); + +int cmListFileLexer_yylex_init (yyscan_t* scanner); + +int cmListFileLexer_yylex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner); + /* Accessor methods to globals. These are made visible to non-reentrant scanners for convenience. */ @@ -620,6 +650,10 @@ int cmListFileLexer_yyget_lineno (yyscan_t yyscanner ); void cmListFileLexer_yyset_lineno (int line_number ,yyscan_t yyscanner ); +int cmListFileLexer_yyget_column (yyscan_t yyscanner ); + +void cmListFileLexer_yyset_column (int column_no ,yyscan_t yyscanner ); + /* Macros after this point can all be overridden by user definitions in * section 1. */ @@ -652,7 +686,12 @@ static int input (yyscan_t yyscanner ); /* Amount of stuff to slurp up with each read. */ #ifndef YY_READ_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k */ +#define YY_READ_BUF_SIZE 16384 +#else #define YY_READ_BUF_SIZE 8192 +#endif /* __ia64__ */ #endif /* Copy whatever the last rule matched to the standard output. */ @@ -660,7 +699,7 @@ static int input (yyscan_t yyscanner ); /* This used to be an fputs(), but since the string might contain NUL's, * we now use fwrite(). */ -#define ECHO (void) fwrite( yytext, yyleng, 1, yyout ) +#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0) #endif /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, @@ -754,14 +793,14 @@ YY_DECL int yy_act; struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; -#line 100 "cmListFileLexer.in.l" +#line 82 "cmListFileLexer.in.l" -#line 787 "cmListFileLexer.c" +#line 804 "cmListFileLexer.c" - if ( yyg->yy_init ) + if ( !yyg->yy_init ) { - yyg->yy_init = 0; + yyg->yy_init = 1; #ifdef YY_USER_INIT YY_USER_INIT; @@ -810,13 +849,13 @@ yy_match: while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 39 ) + if ( yy_current_state >= 45 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; ++yy_cp; } - while ( yy_base[yy_current_state] != 89 ); + while ( yy_base[yy_current_state] != 109 ); yy_find_action: yy_act = yy_accept[yy_current_state]; @@ -855,7 +894,7 @@ do_action: /* This label is used only to access EOF actions. */ case 1: /* rule 1 can match eol */ YY_RULE_SETUP -#line 102 "cmListFileLexer.in.l" +#line 84 "cmListFileLexer.in.l" { lexer->token.type = cmListFileLexer_Token_Newline; cmListFileLexerSetToken(lexer, yytext, yyleng); @@ -865,14 +904,14 @@ YY_RULE_SETUP } case 2: YY_RULE_SETUP -#line 110 "cmListFileLexer.in.l" +#line 92 "cmListFileLexer.in.l" { lexer->column += yyleng; } YY_BREAK case 3: YY_RULE_SETUP -#line 114 "cmListFileLexer.in.l" +#line 96 "cmListFileLexer.in.l" { lexer->token.type = cmListFileLexer_Token_ParenLeft; cmListFileLexerSetToken(lexer, yytext, yyleng); @@ -881,7 +920,7 @@ YY_RULE_SETUP } case 4: YY_RULE_SETUP -#line 121 "cmListFileLexer.in.l" +#line 103 "cmListFileLexer.in.l" { lexer->token.type = cmListFileLexer_Token_ParenRight; cmListFileLexerSetToken(lexer, yytext, yyleng); @@ -890,7 +929,7 @@ YY_RULE_SETUP } case 5: YY_RULE_SETUP -#line 128 "cmListFileLexer.in.l" +#line 110 "cmListFileLexer.in.l" { lexer->token.type = cmListFileLexer_Token_Identifier; cmListFileLexerSetToken(lexer, yytext, yyleng); @@ -899,7 +938,7 @@ YY_RULE_SETUP } case 6: YY_RULE_SETUP -#line 135 "cmListFileLexer.in.l" +#line 117 "cmListFileLexer.in.l" { lexer->token.type = cmListFileLexer_Token_ArgumentUnquoted; cmListFileLexerSetToken(lexer, yytext, yyleng); @@ -908,7 +947,16 @@ YY_RULE_SETUP } case 7: YY_RULE_SETUP -#line 142 "cmListFileLexer.in.l" +#line 124 "cmListFileLexer.in.l" +{ + lexer->token.type = cmListFileLexer_Token_ArgumentUnquoted; + cmListFileLexerSetToken(lexer, yytext, yyleng); + lexer->column += yyleng; + return 1; +} +case 8: +YY_RULE_SETUP +#line 131 "cmListFileLexer.in.l" { lexer->token.type = cmListFileLexer_Token_ArgumentQuoted; cmListFileLexerSetToken(lexer, "", 0); @@ -916,58 +964,69 @@ YY_RULE_SETUP BEGIN(STRING); } YY_BREAK -case 8: -/* rule 8 can match eol */ +case 9: YY_RULE_SETUP -#line 149 "cmListFileLexer.in.l" +#line 138 "cmListFileLexer.in.l" { cmListFileLexerAppend(lexer, yytext, yyleng); lexer->column += yyleng; } YY_BREAK -case 9: -/* rule 9 can match eol */ +case 10: +/* rule 10 can match eol */ YY_RULE_SETUP -#line 154 "cmListFileLexer.in.l" +#line 143 "cmListFileLexer.in.l" { cmListFileLexerAppend(lexer, yytext, yyleng); ++lexer->line; lexer->column = 1; } YY_BREAK -case 10: +case 11: +/* rule 11 can match eol */ +YY_RULE_SETUP +#line 149 "cmListFileLexer.in.l" +{ + cmListFileLexerAppend(lexer, yytext, yyleng); + ++lexer->line; + lexer->column = 1; +} + YY_BREAK +case 12: YY_RULE_SETUP -#line 160 "cmListFileLexer.in.l" +#line 155 "cmListFileLexer.in.l" { lexer->column += yyleng; BEGIN(INITIAL); return 1; } -case 11: +case 13: YY_RULE_SETUP -#line 166 "cmListFileLexer.in.l" +#line 161 "cmListFileLexer.in.l" { cmListFileLexerAppend(lexer, yytext, yyleng); lexer->column += yyleng; } YY_BREAK case YY_STATE_EOF(STRING): -#line 171 "cmListFileLexer.in.l" +#line 166 "cmListFileLexer.in.l" { lexer->token.type = cmListFileLexer_Token_BadString; BEGIN(INITIAL); return 1; } -case 12: +case 14: YY_RULE_SETUP -#line 177 "cmListFileLexer.in.l" +#line 172 "cmListFileLexer.in.l" { + lexer->token.type = cmListFileLexer_Token_Space; + cmListFileLexerSetToken(lexer, yytext, yyleng); lexer->column += yyleng; + return 1; } - YY_BREAK -case 13: +case 15: YY_RULE_SETUP -#line 181 "cmListFileLexer.in.l" +#line 179 "cmListFileLexer.in.l" { lexer->token.type = cmListFileLexer_Token_BadCharacter; cmListFileLexerSetToken(lexer, yytext, yyleng); @@ -975,18 +1034,18 @@ YY_RULE_SETUP return 1; } case YY_STATE_EOF(INITIAL): -#line 188 "cmListFileLexer.in.l" +#line 186 "cmListFileLexer.in.l" { lexer->token.type = cmListFileLexer_Token_None; cmListFileLexerSetToken(lexer, 0, 0); return 0; } -case 14: +case 16: YY_RULE_SETUP -#line 194 "cmListFileLexer.in.l" +#line 192 "cmListFileLexer.in.l" ECHO; YY_BREAK -#line 1025 "cmListFileLexer.c" +#line 1064 "cmListFileLexer.c" case YY_END_OF_BUFFER: { @@ -1171,7 +1230,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner) else { - size_t num_to_read = + int num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; while ( num_to_read <= 0 ) @@ -1216,7 +1275,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner) /* Read in more data. */ YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - yyg->yy_n_chars, num_to_read ); + yyg->yy_n_chars, (size_t) num_to_read ); YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; } @@ -1240,6 +1299,14 @@ static int yy_get_next_buffer (yyscan_t yyscanner) else ret_val = EOB_ACT_CONTINUE_SCAN; + if ((yy_size_t) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + /* Extend the array by 50%, plus the number we really need. */ + yy_size_t new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1); + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) cmListFileLexer_yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ,yyscanner ); + if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); + } + yyg->yy_n_chars += number_to_move; YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR; YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; @@ -1270,7 +1337,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 39 ) + if ( yy_current_state >= 45 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; @@ -1287,7 +1354,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner) static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state , yyscan_t yyscanner) { int yy_is_jam; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */ char *yy_cp = yyg->yy_c_buf_p; YY_CHAR yy_c = 1; @@ -1299,11 +1366,11 @@ static int yy_get_next_buffer (yyscan_t yyscanner) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 39 ) + if ( yy_current_state >= 45 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - yy_is_jam = (yy_current_state == 38); + yy_is_jam = (yy_current_state == 44); return yy_is_jam ? 0 : yy_current_state; } @@ -1633,6 +1700,8 @@ static void cmListFileLexer_yyensure_buffer_stack (yyscan_t yyscanner) yyg->yy_buffer_stack = (struct yy_buffer_state**)cmListFileLexer_yyalloc (num_to_alloc * sizeof(struct yy_buffer_state*) , yyscanner); + if ( ! yyg->yy_buffer_stack ) + YY_FATAL_ERROR( "out of dynamic memory in cmListFileLexer_yyensure_buffer_stack()" ); memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*)); @@ -1651,6 +1720,8 @@ static void cmListFileLexer_yyensure_buffer_stack (yyscan_t yyscanner) (yyg->yy_buffer_stack, num_to_alloc * sizeof(struct yy_buffer_state*) , yyscanner); + if ( ! yyg->yy_buffer_stack ) + YY_FATAL_ERROR( "out of dynamic memory in cmListFileLexer_yyensure_buffer_stack()" ); /* zero only the new slots.*/ memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*)); @@ -1695,26 +1766,26 @@ YY_BUFFER_STATE cmListFileLexer_yy_scan_buffer (char * base, yy_size_t size , /** Setup the input buffer state to scan a string. The next call to cmListFileLexer_yylex() will * scan from a @e copy of @a str. - * @param str a NUL-terminated string to scan + * @param yystr a NUL-terminated string to scan * @param yyscanner The scanner object. * @return the newly allocated buffer state object. * @note If you want to scan bytes that may contain NUL values, then use * cmListFileLexer_yy_scan_bytes() instead. */ -YY_BUFFER_STATE cmListFileLexer_yy_scan_string (yyconst char * yy_str , yyscan_t yyscanner) +YY_BUFFER_STATE cmListFileLexer_yy_scan_string (yyconst char * yystr , yyscan_t yyscanner) { - return cmListFileLexer_yy_scan_bytes(yy_str,strlen(yy_str) ,yyscanner); + return cmListFileLexer_yy_scan_bytes(yystr,strlen(yystr) ,yyscanner); } /** Setup the input buffer state to scan the given bytes. The next call to cmListFileLexer_yylex() will * scan from a @e copy of @a bytes. - * @param bytes the byte buffer to scan - * @param len the number of bytes in the buffer pointed to by @a bytes. + * @param yybytes the byte buffer to scan + * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. * @param yyscanner The scanner object. * @return the newly allocated buffer state object. */ -YY_BUFFER_STATE cmListFileLexer_yy_scan_bytes (yyconst char * bytes, int len , yyscan_t yyscanner) +YY_BUFFER_STATE cmListFileLexer_yy_scan_bytes (yyconst char * yybytes, int _yybytes_len , yyscan_t yyscanner) { YY_BUFFER_STATE b; char *buf; @@ -1722,15 +1793,15 @@ YY_BUFFER_STATE cmListFileLexer_yy_scan_bytes (yyconst char * bytes, int len , int i; /* Get memory for full buffer, including space for trailing EOB's. */ - n = len + 2; + n = _yybytes_len + 2; buf = (char *) cmListFileLexer_yyalloc(n ,yyscanner ); if ( ! buf ) YY_FATAL_ERROR( "out of dynamic memory in cmListFileLexer_yy_scan_bytes()" ); - for ( i = 0; i < len; ++i ) - buf[i] = bytes[i]; + for ( i = 0; i < _yybytes_len; ++i ) + buf[i] = yybytes[i]; - buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR; + buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; b = cmListFileLexer_yy_scan_buffer(buf,n ,yyscanner); if ( ! b ) @@ -1918,21 +1989,87 @@ void cmListFileLexer_yyset_debug (int bdebug , yyscan_t yyscanner) /* Accessor methods for yylval and yylloc */ +/* User-visible API */ + +/* cmListFileLexer_yylex_init is special because it creates the scanner itself, so it is + * the ONLY reentrant function that doesn't take the scanner as the last argument. + * That's why we explicitly handle the declaration, instead of using our macros. + */ + +int cmListFileLexer_yylex_init(yyscan_t* ptr_yy_globals) + +{ + if (ptr_yy_globals == NULL){ + errno = EINVAL; + return 1; + } + + *ptr_yy_globals = (yyscan_t) cmListFileLexer_yyalloc ( sizeof( struct yyguts_t ), NULL ); + + if (*ptr_yy_globals == NULL){ + errno = ENOMEM; + return 1; + } + + /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for releases. */ + memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t)); + + return yy_init_globals ( *ptr_yy_globals ); +} + +/* cmListFileLexer_yylex_init_extra has the same functionality as cmListFileLexer_yylex_init, but follows the + * convention of taking the scanner as the last argument. Note however, that + * this is a *pointer* to a scanner, as it will be allocated by this call (and + * is the reason, too, why this function also must handle its own declaration). + * The user defined value in the first argument will be available to cmListFileLexer_yyalloc in + * the yyextra field. + */ + +int cmListFileLexer_yylex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_yy_globals ) + +{ + struct yyguts_t dummy_yyguts; + + cmListFileLexer_yyset_extra (yy_user_defined, &dummy_yyguts); + + if (ptr_yy_globals == NULL){ + errno = EINVAL; + return 1; + } + + *ptr_yy_globals = (yyscan_t) cmListFileLexer_yyalloc ( sizeof( struct yyguts_t ), &dummy_yyguts ); + + if (*ptr_yy_globals == NULL){ + errno = ENOMEM; + return 1; + } + + /* By setting to 0xAA, we expose bugs in + yy_init_globals. Leave at 0x00 for releases. */ + memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t)); + + cmListFileLexer_yyset_extra (yy_user_defined, *ptr_yy_globals); + + return yy_init_globals ( *ptr_yy_globals ); +} + static int yy_init_globals (yyscan_t yyscanner) { struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* Initialization is the same as for the non-reentrant scanner. - This function is called once per scanner lifetime. */ + * This function is called from cmListFileLexer_yylex_destroy(), so don't allocate here. + */ yyg->yy_buffer_stack = 0; yyg->yy_buffer_stack_top = 0; yyg->yy_buffer_stack_max = 0; yyg->yy_c_buf_p = (char *) 0; - yyg->yy_init = 1; + yyg->yy_init = 0; yyg->yy_start = 0; + yyg->yy_start_stack_ptr = 0; yyg->yy_start_stack_depth = 0; - yyg->yy_start_stack = (int *) 0; + yyg->yy_start_stack = NULL; /* Defined in main.c */ #ifdef YY_STDINIT @@ -1949,33 +2086,6 @@ static int yy_init_globals (yyscan_t yyscanner) return 0; } -/* User-visible API */ - -/* cmListFileLexer_yylex_init is special because it creates the scanner itself, so it is - * the ONLY reentrant function that doesn't take the scanner as the last argument. - * That's why we explicitly handle the declaration, instead of using our macros. - */ - -int cmListFileLexer_yylex_init(yyscan_t* ptr_yy_globals) - -{ - if (ptr_yy_globals == NULL){ - errno = EINVAL; - return 1; - } - - *ptr_yy_globals = (yyscan_t) cmListFileLexer_yyalloc ( sizeof( struct yyguts_t ), NULL ); - - if (*ptr_yy_globals == NULL){ - errno = ENOMEM; - return 1; - } - - memset(*ptr_yy_globals,0,sizeof(struct yyguts_t)); - - return yy_init_globals ( *ptr_yy_globals ); -} - /* cmListFileLexer_yylex_destroy is for both reentrant and non-reentrant scanners. */ int cmListFileLexer_yylex_destroy (yyscan_t yyscanner) { @@ -1996,6 +2106,10 @@ int cmListFileLexer_yylex_destroy (yyscan_t yyscanner) cmListFileLexer_yyfree(yyg->yy_start_stack ,yyscanner ); yyg->yy_start_stack = NULL; + /* Reset the globals. This is important in a non-reentrant scanner so the next time + * cmListFileLexer_yylex() is called, initialization will occur. */ + yy_init_globals( yyscanner); + /* Destroy the main struct (reentrant only). */ cmListFileLexer_yyfree ( yyscanner , yyscanner ); return 0; @@ -2009,7 +2123,6 @@ int cmListFileLexer_yylex_destroy (yyscan_t yyscanner) static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner) { int i; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; for ( i = 0; i < n; ++i ) s1[i] = s2[i]; } @@ -2019,7 +2132,6 @@ static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yysca static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner) { int n; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; for ( n = 0; s[n]; ++n ) ; @@ -2054,19 +2166,7 @@ void cmListFileLexer_yyfree (void * ptr , yyscan_t yyscanner) #define YYTABLES_NAME "yytables" -#undef YY_NEW_FILE -#undef YY_FLUSH_BUFFER -#undef yy_set_bol -#undef yy_new_buffer -#undef yy_set_interactive -#undef yytext_ptr -#undef YY_DO_BEFORE_ACTION - -#ifdef YY_DECL_IS_OURS -#undef YY_DECL_IS_OURS -#undef YY_DECL -#endif -#line 194 "cmListFileLexer.in.l" +#line 192 "cmListFileLexer.in.l" @@ -2122,7 +2222,7 @@ static void cmListFileLexerAppend(cmListFileLexer* lexer, const char* text, } /* We need to extend the buffer. */ - temp = (char*)malloc(newSize); + temp = malloc(newSize); if(lexer->token.text) { memcpy(temp, lexer->token.text, lexer->token.length); @@ -2303,6 +2403,7 @@ const char* cmListFileLexer_GetTypeAsString(cmListFileLexer* lexer, switch(type) { case cmListFileLexer_Token_None: return "nothing"; + case cmListFileLexer_Token_Space: return "space"; case cmListFileLexer_Token_Newline: return "newline"; case cmListFileLexer_Token_Identifier: return "identifier"; case cmListFileLexer_Token_ParenLeft: return "left paren"; diff --git a/Source/cmListFileLexer.h b/Source/cmListFileLexer.h index 5f4db33..cc78b5c 100644 --- a/Source/cmListFileLexer.h +++ b/Source/cmListFileLexer.h @@ -15,6 +15,7 @@ typedef enum cmListFileLexer_Type_e { cmListFileLexer_Token_None, + cmListFileLexer_Token_Space, cmListFileLexer_Token_Newline, cmListFileLexer_Token_Identifier, cmListFileLexer_Token_ParenLeft, diff --git a/Source/cmListFileLexer.in.l b/Source/cmListFileLexer.in.l index eedf494..12b53ee 100644 --- a/Source/cmListFileLexer.in.l +++ b/Source/cmListFileLexer.in.l @@ -24,6 +24,7 @@ Modify cmListFileLexer.c: - remove the yyunput function - add a statement "(void)yyscanner;" to the top of these methods: yy_fatal_error, cmListFileLexer_yyalloc, cmListFileLexer_yyrealloc, cmListFileLexer_yyfree + - remove statement "yyscanner = NULL;" from cmListFileLexer_yylex_destroy - remove all YY_BREAK lines occurring right after return statements - remove the isatty forward declaration @@ -75,6 +76,8 @@ static void cmListFileLexerDestroy(cmListFileLexer* lexer); %x STRING MAKEVAR \$\([A-Za-z0-9_]*\) +UNQUOTED ([^ \t\r\n\(\)#\\\"]|\\.) +LEGACY {MAKEVAR}|{UNQUOTED}|\"({MAKEVAR}|{UNQUOTED}|[ \t])*\" %% @@ -111,7 +114,14 @@ MAKEVAR \$\([A-Za-z0-9_]*\) return 1; } -({MAKEVAR}|[^ \t\r\n\(\)#\\\"]|\\.)({MAKEVAR}|[^ \t\r\n\(\)#\\\"]|\\.|\"({MAKEVAR}|[^\r\n\(\)#\\\"]|\\.)*\")* { +({UNQUOTED})({UNQUOTED})* { + lexer->token.type = cmListFileLexer_Token_ArgumentUnquoted; + cmListFileLexerSetToken(lexer, yytext, yyleng); + lexer->column += yyleng; + return 1; +} + +({MAKEVAR}|{UNQUOTED})({LEGACY})* { lexer->token.type = cmListFileLexer_Token_ArgumentUnquoted; cmListFileLexerSetToken(lexer, yytext, yyleng); lexer->column += yyleng; @@ -125,11 +135,17 @@ MAKEVAR \$\([A-Za-z0-9_]*\) BEGIN(STRING); } -<STRING>([^\\\n\"]|\\(.|\n))+ { +<STRING>([^\\\n\"]|\\.)+ { cmListFileLexerAppend(lexer, yytext, yyleng); lexer->column += yyleng; } +<STRING>\\\n { + cmListFileLexerAppend(lexer, yytext, yyleng); + ++lexer->line; + lexer->column = 1; +} + <STRING>\n { cmListFileLexerAppend(lexer, yytext, yyleng); ++lexer->line; @@ -153,8 +169,11 @@ MAKEVAR \$\([A-Za-z0-9_]*\) return 1; } -[ \t\r] { +[ \t\r]+ { + lexer->token.type = cmListFileLexer_Token_Space; + cmListFileLexerSetToken(lexer, yytext, yyleng); lexer->column += yyleng; + return 1; } . { @@ -405,6 +424,7 @@ const char* cmListFileLexer_GetTypeAsString(cmListFileLexer* lexer, switch(type) { case cmListFileLexer_Token_None: return "nothing"; + case cmListFileLexer_Token_Space: return "space"; case cmListFileLexer_Token_Newline: return "newline"; case cmListFileLexer_Token_Identifier: return "identifier"; case cmListFileLexer_Token_ParenLeft: return "left paren"; diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index b187d6b..9c04109 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1038,20 +1038,11 @@ cmLocalGenerator::ExpandRuleVariable(std::string const& variable, // If this is the compiler then look for the extra variable // _COMPILER_ARG1 which must be the first argument to the compiler const char* compilerArg1 = 0; - const char* compilerTarget = 0; - const char* compilerOptionTarget = 0; if(actualReplace == "CMAKE_${LANG}_COMPILER") { std::string arg1 = actualReplace + "_ARG1"; cmSystemTools::ReplaceString(arg1, "${LANG}", lang); compilerArg1 = this->Makefile->GetDefinition(arg1.c_str()); - compilerTarget - = this->Makefile->GetDefinition( - (std::string("CMAKE_") + lang + "_COMPILER_TARGET").c_str()); - compilerOptionTarget - = this->Makefile->GetDefinition( - (std::string("CMAKE_") + lang + - "_COMPILE_OPTION_TARGET").c_str()); } if(actualReplace.find("${LANG}") != actualReplace.npos) { @@ -1072,11 +1063,6 @@ cmLocalGenerator::ExpandRuleVariable(std::string const& variable, ret += " "; ret += compilerArg1; } - if (compilerTarget && compilerOptionTarget) - { - ret += compilerOptionTarget; - ret += compilerTarget; - } return ret; } return replace; @@ -1541,6 +1527,25 @@ void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs, } } +void cmLocalGenerator::GetStaticLibraryFlags(std::string& flags, + std::string const& config, + cmTarget* target) +{ + this->AppendFlags(flags, + this->Makefile->GetSafeDefinition("CMAKE_STATIC_LINKER_FLAGS")); + if(!config.empty()) + { + std::string name = "CMAKE_STATIC_LINKER_FLAGS_" + config; + this->AppendFlags(flags, this->Makefile->GetSafeDefinition(name.c_str())); + } + this->AppendFlags(flags, target->GetProperty("STATIC_LIBRARY_FLAGS")); + if(!config.empty()) + { + std::string name = "STATIC_LIBRARY_FLAGS_" + config; + this->AppendFlags(flags, target->GetProperty(name.c_str())); + } +} + void cmLocalGenerator::GetTargetFlags(std::string& linkLibs, std::string& flags, std::string& linkFlags, @@ -1557,26 +1562,7 @@ void cmLocalGenerator::GetTargetFlags(std::string& linkLibs, switch(target->GetType()) { case cmTarget::STATIC_LIBRARY: - { - const char* targetLinkFlags = - target->GetProperty("STATIC_LIBRARY_FLAGS"); - if(targetLinkFlags) - { - linkFlags += targetLinkFlags; - linkFlags += " "; - } - if(!buildType.empty()) - { - std::string build = "STATIC_LIBRARY_FLAGS_"; - build += buildType; - targetLinkFlags = target->GetProperty(build.c_str()); - if(targetLinkFlags) - { - linkFlags += targetLinkFlags; - linkFlags += " "; - } - } - } + this->GetStaticLibraryFlags(linkFlags, buildType, target->Target); break; case cmTarget::MODULE_LIBRARY: libraryLinkVariable = "CMAKE_MODULE_LINKER_FLAGS"; diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index ed0f6e3..10f0b1a 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -348,6 +348,11 @@ public: std::string const& dir_max, bool* hasSourceExtension = 0); + /** Fill out the static linker flags for the given target. */ + void GetStaticLibraryFlags(std::string& flags, + std::string const& config, + cmTarget* target); + /** Fill out these strings for the given target. Libraries to link, * flags, and linkflags. */ void GetTargetFlags(std::string& linkLibs, diff --git a/Source/cmLocalVisualStudio6Generator.cxx b/Source/cmLocalVisualStudio6Generator.cxx index df6e1f1..e5b4057 100644 --- a/Source/cmLocalVisualStudio6Generator.cxx +++ b/Source/cmLocalVisualStudio6Generator.cxx @@ -573,22 +573,20 @@ cmLocalVisualStudio6Generator // Add the rule with the given dependencies and commands. const char* no_main_dependency = 0; - this->Makefile->AddCustomCommandToOutput(output, - depends, - no_main_dependency, - origCommand.GetCommandLines(), - comment.c_str(), - origCommand.GetWorkingDirectory()); + if(cmSourceFile* outsf = + this->Makefile->AddCustomCommandToOutput( + output, depends, no_main_dependency, + origCommand.GetCommandLines(), comment.c_str(), + origCommand.GetWorkingDirectory())) + { + target.AddSourceFile(outsf); + } // Replace the dependencies with the output of this rule so that the // next rule added will run after this one. depends.clear(); depends.push_back(output); - // Add a source file representing this output to the project. - cmSourceFile* outsf = this->Makefile->GetSourceFileWithOutput(output); - target.AddSourceFile(outsf); - // Free the fake output name. delete [] output; } @@ -1171,18 +1169,42 @@ void cmLocalVisualStudio6Generator std::string extraLinkOptionsRelWithDebInfo; if(target.GetType() == cmTarget::EXECUTABLE) { - extraLinkOptions = - this->Makefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS"); + extraLinkOptions = this->Makefile-> + GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS"); + extraLinkOptionsDebug = this->Makefile-> + GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS_DEBUG"); + extraLinkOptionsRelease = this->Makefile-> + GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS_RELEASE"); + extraLinkOptionsMinSizeRel = this->Makefile-> + GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS_MINSIZEREL"); + extraLinkOptionsRelWithDebInfo = this->Makefile-> + GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO"); } if(target.GetType() == cmTarget::SHARED_LIBRARY) { - extraLinkOptions = - this->Makefile->GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS"); + extraLinkOptions = this->Makefile-> + GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS"); + extraLinkOptionsDebug = this->Makefile-> + GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS_DEBUG"); + extraLinkOptionsRelease = this->Makefile-> + GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS_RELEASE"); + extraLinkOptionsMinSizeRel = this->Makefile-> + GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL"); + extraLinkOptionsRelWithDebInfo = this->Makefile-> + GetRequiredDefinition("CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO"); } if(target.GetType() == cmTarget::MODULE_LIBRARY) { - extraLinkOptions = - this->Makefile->GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS"); + extraLinkOptions = this->Makefile-> + GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS"); + extraLinkOptionsDebug = this->Makefile-> + GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS_DEBUG"); + extraLinkOptionsRelease = this->Makefile-> + GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS_RELEASE"); + extraLinkOptionsMinSizeRel = this->Makefile-> + GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS_MINSIZEREL"); + extraLinkOptionsRelWithDebInfo = this->Makefile-> + GetRequiredDefinition("CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO"); } // Get extra linker options for this target. @@ -1435,38 +1457,39 @@ void cmLocalVisualStudio6Generator std::string staticLibOptionsRelWithDebInfo; if(target.GetType() == cmTarget::STATIC_LIBRARY ) { - if(const char* libflags = target.GetProperty("STATIC_LIBRARY_FLAGS")) - { - staticLibOptions = libflags; - staticLibOptionsDebug = libflags; - staticLibOptionsRelease = libflags; - staticLibOptionsMinSizeRel = libflags; - staticLibOptionsRelWithDebInfo = libflags; - } - if(const char* libflagsDebug = - target.GetProperty("STATIC_LIBRARY_FLAGS_DEBUG")) - { - staticLibOptionsDebug += " "; - staticLibOptionsDebug = libflagsDebug; - } - if(const char* libflagsRelease = - target.GetProperty("STATIC_LIBRARY_FLAGS_RELEASE")) - { - staticLibOptionsRelease += " "; - staticLibOptionsRelease = libflagsRelease; - } - if(const char* libflagsMinSizeRel = - target.GetProperty("STATIC_LIBRARY_FLAGS_MINSIZEREL")) - { - staticLibOptionsMinSizeRel += " "; - staticLibOptionsMinSizeRel = libflagsMinSizeRel; - } - if(const char* libflagsRelWithDebInfo = - target.GetProperty("STATIC_LIBRARY_FLAGS_RELWITHDEBINFO")) - { - staticLibOptionsRelWithDebInfo += " "; - staticLibOptionsRelWithDebInfo = libflagsRelWithDebInfo; - } + const char *libflagsGlobal = + this->Makefile->GetSafeDefinition("CMAKE_STATIC_LINKER_FLAGS"); + this->AppendFlags(staticLibOptions, libflagsGlobal); + this->AppendFlags(staticLibOptionsDebug, libflagsGlobal); + this->AppendFlags(staticLibOptionsRelease, libflagsGlobal); + this->AppendFlags(staticLibOptionsMinSizeRel, libflagsGlobal); + this->AppendFlags(staticLibOptionsRelWithDebInfo, libflagsGlobal); + + this->AppendFlags(staticLibOptionsDebug, this->Makefile-> + GetSafeDefinition("CMAKE_STATIC_LINKER_FLAGS_DEBUG")); + this->AppendFlags(staticLibOptionsRelease, this->Makefile-> + GetSafeDefinition("CMAKE_STATIC_LINKER_FLAGS_RELEASE")); + this->AppendFlags(staticLibOptionsMinSizeRel, this->Makefile-> + GetSafeDefinition("CMAKE_STATIC_LINKER_FLAGS_MINSIZEREL")); + this->AppendFlags(staticLibOptionsRelWithDebInfo, this->Makefile-> + GetSafeDefinition("CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO")); + + const char *libflags = target.GetProperty("STATIC_LIBRARY_FLAGS"); + this->AppendFlags(staticLibOptions, libflags); + this->AppendFlags(staticLibOptionsDebug, libflags); + this->AppendFlags(staticLibOptionsRelease, libflags); + this->AppendFlags(staticLibOptionsMinSizeRel, libflags); + this->AppendFlags(staticLibOptionsRelWithDebInfo, libflags); + + this->AppendFlags(staticLibOptionsDebug, + target.GetProperty("STATIC_LIBRARY_FLAGS_DEBUG")); + this->AppendFlags(staticLibOptionsRelease, + target.GetProperty("STATIC_LIBRARY_FLAGS_RELEASE")); + this->AppendFlags(staticLibOptionsMinSizeRel, + target.GetProperty("STATIC_LIBRARY_FLAGS_MINSIZEREL")); + this->AppendFlags(staticLibOptionsRelWithDebInfo, + target.GetProperty("STATIC_LIBRARY_FLAGS_RELWITHDEBINFO")); + std::string objects; this->OutputObjects(target, "LIB", objects); if(!objects.empty()) diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 9ecd53d..58cc6f4 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -146,11 +146,10 @@ void cmLocalVisualStudio7Generator::FixGlobalTargets() force += "/"; force += tgt.GetName(); force += "_force"; - this->Makefile->AddCustomCommandToOutput(force.c_str(), no_depends, - no_main_dependency, - force_commands, " ", 0, true); if(cmSourceFile* file = - this->Makefile->GetSourceFileWithOutput(force.c_str())) + this->Makefile->AddCustomCommandToOutput( + force.c_str(), no_depends, no_main_dependency, + force_commands, " ", 0, true)) { tgt.AddSourceFile(file); } @@ -920,7 +919,7 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout, } this->OutputTargetRules(fout, configName, target, libName); - this->OutputBuildTool(fout, configName, target, targetOptions.IsDebug()); + this->OutputBuildTool(fout, configName, target, targetOptions); fout << "\t\t</Configuration>\n"; } @@ -941,9 +940,7 @@ cmLocalVisualStudio7Generator } void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout, - const char* configName, - cmTarget &target, - bool isDebug) + const char* configName, cmTarget &target, const Options& targetOptions) { cmGlobalVisualStudio7Generator* gg = static_cast<cmGlobalVisualStudio7Generator*>(this->GlobalGenerator); @@ -1039,17 +1036,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout, } } std::string libflags; - if(const char* flags = target.GetProperty("STATIC_LIBRARY_FLAGS")) - { - libflags += flags; - } - std::string libFlagsConfig = "STATIC_LIBRARY_FLAGS_"; - libFlagsConfig += configTypeUpper; - if(const char* flagsConfig = target.GetProperty(libFlagsConfig.c_str())) - { - libflags += " "; - libflags += flagsConfig; - } + this->GetStaticLibraryFlags(libflags, configTypeUpper, &target); if(!libflags.empty()) { fout << "\t\t\t\tAdditionalOptions=\"" << libflags << "\"\n"; @@ -1121,7 +1108,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout, temp += targetNamePDB; fout << "\t\t\t\tProgramDatabaseFile=\"" << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n"; - if(isDebug) + if(targetOptions.IsDebug()) { fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n"; } @@ -1219,7 +1206,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout, fout << "\t\t\t\tProgramDatabaseFile=\"" << path << "/" << targetNamePDB << "\"\n"; - if(isDebug) + if(targetOptions.IsDebug()) { fout << "\t\t\t\tGenerateDebugInformation=\"TRUE\"\n"; } @@ -1233,9 +1220,14 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout, { fout << "\t\t\t\tSubSystem=\"8\"\n"; } - fout << "\t\t\t\tEntryPointSymbol=\"" - << (isWin32Executable ? "WinMainCRTStartup" : "mainACRTStartup") - << "\"\n"; + + if(!linkOptions.GetFlag("EntryPointSymbol")) + { + const char* entryPointSymbol = targetOptions.UsingUnicode() ? + (isWin32Executable ? "wWinMainCRTStartup" : "mainWCRTStartup") : + (isWin32Executable ? "WinMainCRTStartup" : "mainACRTStartup"); + fout << "\t\t\t\tEntryPointSymbol=\"" << entryPointSymbol << "\"\n"; + } } else if ( this->FortranProject ) { diff --git a/Source/cmLocalVisualStudio7Generator.h b/Source/cmLocalVisualStudio7Generator.h index d9e2ef0..92e4d3c 100644 --- a/Source/cmLocalVisualStudio7Generator.h +++ b/Source/cmLocalVisualStudio7Generator.h @@ -90,7 +90,7 @@ private: void OutputTargetRules(std::ostream& fout, const char* configName, cmTarget &target, const char *libName); void OutputBuildTool(std::ostream& fout, const char* configName, - cmTarget& t, bool debug); + cmTarget& t, const Options& targetOptions); void OutputLibraryDirectories(std::ostream& fout, std::vector<std::string> const& dirs); void WriteProjectSCC(std::ostream& fout, cmTarget& target); diff --git a/Source/cmMacroCommand.cxx b/Source/cmMacroCommand.cxx index bd7ec00..8ba612c 100644 --- a/Source/cmMacroCommand.cxx +++ b/Source/cmMacroCommand.cxx @@ -227,7 +227,7 @@ bool cmMacroHelperCommand::InvokeInitialPass } arg.Value = tmps; - arg.Quoted = k->Quoted; + arg.Delim = k->Delim; arg.FilePath = k->FilePath; arg.Line = k->Line; newLFF.Arguments.push_back(arg); diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 2cd19cf..57b86fd 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -41,6 +41,7 @@ #include <stack> #include <ctype.h> // for isspace +#include <assert.h> class cmMakefile::Internals { @@ -149,6 +150,7 @@ cmMakefile::cmMakefile(const cmMakefile& mf): Internal(new Internals) this->Initialize(); this->CheckSystemVars = mf.CheckSystemVars; this->ListFileStack = mf.ListFileStack; + this->OutputToSource = mf.OutputToSource; } //---------------------------------------------------------------------------- @@ -1009,11 +1011,32 @@ cmMakefile::AddCustomCommandToOutput(const std::vector<std::string>& outputs, cc->SetEscapeOldStyle(escapeOldStyle); cc->SetEscapeAllowMakeVars(true); file->SetCustomCommand(cc); + this->UpdateOutputToSourceMap(outputs, file); } return file; } //---------------------------------------------------------------------------- +void +cmMakefile::UpdateOutputToSourceMap(std::vector<std::string> const& outputs, + cmSourceFile* source) +{ + for(std::vector<std::string>::const_iterator o = outputs.begin(); + o != outputs.end(); ++o) + { + this->UpdateOutputToSourceMap(*o, source); + } +} + +//---------------------------------------------------------------------------- +void +cmMakefile::UpdateOutputToSourceMap(std::string const& output, + cmSourceFile* source) +{ + this->OutputToSource[output] = source; +} + +//---------------------------------------------------------------------------- cmSourceFile* cmMakefile::AddCustomCommandToOutput(const char* output, const std::vector<std::string>& depends, @@ -1437,6 +1460,14 @@ void cmMakefile::AddLinkDirectoryForTarget(const char *target, cmTargets::iterator i = this->Targets.find(target); if ( i != this->Targets.end()) { + if(this->IsAlias(target)) + { + cmOStringStream e; + e << "ALIAS target \"" << target << "\" " + << "may not be linked into another target."; + this->IssueMessage(cmake::FATAL_ERROR, e.str().c_str()); + return; + } i->second.AddLinkDirectory( d ); } else @@ -1923,6 +1954,12 @@ void cmMakefile::AddGlobalLinkInformation(const char* name, cmTarget& target) } +void cmMakefile::AddAlias(const char* lname, cmTarget *tgt) +{ + this->AliasTargets[lname] = tgt; + this->LocalGenerator->GetGlobalGenerator()->AddAlias(lname, tgt); +} + cmTarget* cmMakefile::AddLibrary(const char* lname, cmTarget::TargetType type, const std::vector<std::string> &srcs, bool excludeFromAll) @@ -1979,7 +2016,7 @@ cmMakefile::AddNewTarget(cmTarget::TargetType type, const char* name) return &it->second; } -cmSourceFile *cmMakefile::GetSourceFileWithOutput(const char *cname) +cmSourceFile *cmMakefile::LinearGetSourceFileWithOutput(const char *cname) { std::string name = cname; std::string out; @@ -2015,6 +2052,25 @@ cmSourceFile *cmMakefile::GetSourceFileWithOutput(const char *cname) return 0; } +cmSourceFile *cmMakefile::GetSourceFileWithOutput(const char *cname) +{ + std::string name = cname; + + // If the queried path is not absolute we use the backward compatible + // linear-time search for an output with a matching suffix. + if(!cmSystemTools::FileIsFullPath(cname)) + { + return LinearGetSourceFileWithOutput(cname); + } + // Otherwise we use an efficient lookup map. + OutputToSourceMap::iterator o = this->OutputToSource.find(name); + if (o != this->OutputToSource.end()) + { + return (*o).second; + } + return 0; +} + #if defined(CMAKE_BUILD_WITH_CMAKE) cmSourceGroup* cmMakefile::GetSourceGroup(const std::vector<std::string>&name) { @@ -2784,7 +2840,7 @@ bool cmMakefile::ExpandArguments( // If the argument is quoted, it should be one argument. // Otherwise, it may be a list of arguments. - if(i->Quoted) + if(i->Delim == cmListFileArgument::Quoted) { outArgs.push_back(value); } @@ -3363,7 +3419,11 @@ int cmMakefile::ConfigureFile(const char* infile, const char* outfile, std::string sinfile = infile; this->AddCMakeDependFile(sinfile); cmSystemTools::ConvertToUnixSlashes(soutfile); - this->AddCMakeOutputFile(soutfile); + // Re-generate if non-temporary outputs are missing. + if(soutfile.find("CMakeTmp") == soutfile.npos) + { + this->AddCMakeOutputFile(soutfile); + } mode_t perm = 0; cmSystemTools::GetPermissions(sinfile.c_str(), perm); std::string::size_type pos = soutfile.rfind('/'); @@ -3754,8 +3814,17 @@ const char* cmMakefile::GetFeature(const char* feature, const char* config) return 0; } -cmTarget* cmMakefile::FindTarget(const char* name) +cmTarget* cmMakefile::FindTarget(const char* name, bool excludeAliases) { + if (!excludeAliases) + { + std::map<std::string, cmTarget*>::iterator i + = this->AliasTargets.find(name); + if (i != this->AliasTargets.end()) + { + return i->second; + } + } cmTargets& tgts = this->GetTargets(); cmTargets::iterator i = tgts.find ( name ); @@ -4081,7 +4150,7 @@ void cmMakefile::DefineProperties(cmake *cm) "List of options to pass to the compiler.", "This property specifies the list of directories given " "so far for this property. " - "This property exists on directories and targets. " + "This property exists on directories and targets." "\n" "The target property values are used by the generators to set " "the options for the compiler.\n" @@ -4180,7 +4249,7 @@ cmMakefile::AddImportedTarget(const char* name, cmTarget::TargetType type, } //---------------------------------------------------------------------------- -cmTarget* cmMakefile::FindTargetToUse(const char* name) +cmTarget* cmMakefile::FindTargetToUse(const char* name, bool excludeAliases) { // Look for an imported target. These take priority because they // are more local in scope and do not have to be globally unique. @@ -4192,15 +4261,25 @@ cmTarget* cmMakefile::FindTargetToUse(const char* name) } // Look for a target built in this directory. - if(cmTarget* t = this->FindTarget(name)) + if(cmTarget* t = this->FindTarget(name, excludeAliases)) { return t; } // Look for a target built in this project. - return this->LocalGenerator->GetGlobalGenerator()->FindTarget(0, name); + return this->LocalGenerator->GetGlobalGenerator()->FindTarget(0, name, + excludeAliases); +} + +//---------------------------------------------------------------------------- +bool cmMakefile::IsAlias(const char *name) +{ + if (this->AliasTargets.find(name) != this->AliasTargets.end()) + return true; + return this->GetLocalGenerator()->GetGlobalGenerator()->IsAlias(name); } +//---------------------------------------------------------------------------- cmGeneratorTarget* cmMakefile::FindGeneratorTargetToUse(const char* name) { cmTarget *t = this->FindTargetToUse(name); @@ -4211,6 +4290,14 @@ cmGeneratorTarget* cmMakefile::FindGeneratorTargetToUse(const char* name) bool cmMakefile::EnforceUniqueName(std::string const& name, std::string& msg, bool isCustom) { + if(this->IsAlias(name.c_str())) + { + cmOStringStream e; + e << "cannot create target \"" << name + << "\" because an alias with the same name already exists."; + msg = e.str(); + return false; + } if(cmTarget* existing = this->FindTargetToUse(name.c_str())) { // The name given conflicts with an existing target. Produce an diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 871fa1b..8bce9fd 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -29,6 +29,9 @@ #include <cmsys/auto_ptr.hxx> #include <cmsys/RegularExpression.hxx> +#if defined(CMAKE_BUILD_WITH_CMAKE) +# include <cmsys/hash_map.hxx> +#endif class cmFunctionBlocker; class cmCommand; @@ -337,6 +340,7 @@ public: cmTarget* AddLibrary(const char *libname, cmTarget::TargetType type, const std::vector<std::string> &srcs, bool excludeFromAll = false); + void AddAlias(const char *libname, cmTarget *tgt); #if defined(CMAKE_BUILD_WITH_CMAKE) /** @@ -536,11 +540,12 @@ public: this->GeneratorTargets = targets; } - cmTarget* FindTarget(const char* name); + cmTarget* FindTarget(const char* name, bool excludeAliases = false); /** Find a target to use in place of the given name. The target returned may be imported or built within the project. */ - cmTarget* FindTargetToUse(const char* name); + cmTarget* FindTargetToUse(const char* name, bool excludeAliases = false); + bool IsAlias(const char *name); cmGeneratorTarget* FindGeneratorTargetToUse(const char* name); /** @@ -902,6 +907,7 @@ protected: // libraries, classes, and executables cmTargets Targets; + std::map<std::string, cmTarget*> AliasTargets; cmGeneratorTargetsType GeneratorTargets; std::vector<cmSourceFile*> SourceFiles; @@ -1036,6 +1042,26 @@ private: bool GeneratingBuildSystem; + /** + * Old version of GetSourceFileWithOutput(const char*) kept for + * backward-compatibility. It implements a linear search and support + * relative file paths. It is used as a fall back by + * GetSourceFileWithOutput(const char*). + */ + cmSourceFile *LinearGetSourceFileWithOutput(const char *cname); + + // A map for fast output to input look up. +#if defined(CMAKE_BUILD_WITH_CMAKE) + typedef cmsys::hash_map<std::string, cmSourceFile*> OutputToSourceMap; +#else + typedef std::map<std::string, cmSourceFile*> OutputToSourceMap; +#endif + OutputToSourceMap OutputToSource; + + void UpdateOutputToSourceMap(std::vector<std::string> const& outputs, + cmSourceFile* source); + void UpdateOutputToSourceMap(std::string const& output, + cmSourceFile* source); }; //---------------------------------------------------------------------------- diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx index 347f26d..ea9663f 100644 --- a/Source/cmMakefileLibraryTargetGenerator.cxx +++ b/Source/cmMakefileLibraryTargetGenerator.cxx @@ -144,12 +144,8 @@ void cmMakefileLibraryTargetGenerator::WriteStaticLibraryRules() } std::string extraFlags; - this->LocalGenerator->AppendFlags - (extraFlags,this->Target->GetProperty("STATIC_LIBRARY_FLAGS")); - std::string staticLibraryFlagsConfig = "STATIC_LIBRARY_FLAGS_"; - staticLibraryFlagsConfig += cmSystemTools::UpperCase(this->ConfigName); - this->LocalGenerator->AppendFlags - (extraFlags, this->Target->GetProperty(staticLibraryFlagsConfig.c_str())); + this->LocalGenerator->GetStaticLibraryFlags(extraFlags, + cmSystemTools::UpperCase(this->ConfigName), this->Target); this->WriteLibraryRules(linkRuleVar.c_str(), extraFlags.c_str(), false); } diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx index 0ba673e..a823f05 100644 --- a/Source/cmPolicies.cxx +++ b/Source/cmPolicies.cxx @@ -543,7 +543,7 @@ cmPolicies::cmPolicies() "the INCLUDE_DIRECTORIES target property. " "The NEW behavior for this policy is to issue a FATAL_ERROR if " "INCLUDE_DIRECTORIES contains a relative path.", - 2,8,11,20130516, cmPolicies::WARN); + 2,8,12,0, cmPolicies::WARN); this->DefinePolicy( CMP0022, "CMP0022", @@ -574,7 +574,7 @@ cmPolicies::cmPolicies() "The NEW behavior for this policy is to use the INTERFACE_LINK_LIBRARIES " "property for in-build targets, and ignore the old properties matching " "(IMPORTED_)?LINK_INTERFACE_LIBRARIES(_<CONFIG>)?.", - 2,8,11,20130516, cmPolicies::WARN); + 2,8,12,0, cmPolicies::WARN); this->DefinePolicy( CMP0023, "CMP0023", @@ -600,7 +600,7 @@ cmPolicies::cmPolicies() "target_link_libraries signatures to be mixed. " "The NEW behavior for this policy is to not to allow mixing of the " "keyword and plain signatures.", - 2,8,11,20130724, cmPolicies::WARN); + 2,8,12,0, cmPolicies::WARN); } cmPolicies::~cmPolicies() diff --git a/Source/cmSetPropertyCommand.cxx b/Source/cmSetPropertyCommand.cxx index b5e5225..4207860 100644 --- a/Source/cmSetPropertyCommand.cxx +++ b/Source/cmSetPropertyCommand.cxx @@ -244,6 +244,11 @@ bool cmSetPropertyCommand::HandleTargetMode() for(std::set<cmStdString>::const_iterator ni = this->Names.begin(); ni != this->Names.end(); ++ni) { + if (this->Makefile->IsAlias(ni->c_str())) + { + this->SetError("can not be used on an ALIAS target."); + return false; + } if(cmTarget* target = this->Makefile->FindTargetToUse(ni->c_str())) { // Handle the current target. diff --git a/Source/cmSetTargetPropertiesCommand.cxx b/Source/cmSetTargetPropertiesCommand.cxx index a2b50a8..78ef393 100644 --- a/Source/cmSetTargetPropertiesCommand.cxx +++ b/Source/cmSetTargetPropertiesCommand.cxx @@ -72,6 +72,11 @@ bool cmSetTargetPropertiesCommand int i; for(i = 0; i < numFiles; ++i) { + if (this->Makefile->IsAlias(args[i].c_str())) + { + this->SetError("can not be used on an ALIAS target."); + return false; + } bool ret = cmSetTargetPropertiesCommand::SetOneTarget (args[i].c_str(),propertyPairs,this->Makefile); if (!ret) diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 37344dc..9ec4938 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -638,6 +638,12 @@ bool cmSystemTools::RunSingleCommand(std::vector<cmStdString>const& command, cmsysProcess_SetOption(cp, cmsysProcess_Option_HideWindow, 1); } + if (outputflag == OUTPUT_PASSTHROUGH) + { + cmsysProcess_SetPipeShared(cp, cmsysProcess_Pipe_STDOUT, 1); + cmsysProcess_SetPipeShared(cp, cmsysProcess_Pipe_STDERR, 1); + } + cmsysProcess_SetTimeout(cp, timeout); cmsysProcess_Execute(cp); @@ -645,7 +651,7 @@ bool cmSystemTools::RunSingleCommand(std::vector<cmStdString>const& command, char* data; int length; int pipe; - if ( output || outputflag != OUTPUT_NONE ) + if(outputflag != OUTPUT_PASSTHROUGH && (output || outputflag != OUTPUT_NONE)) { while((pipe = cmsysProcess_WaitForData(cp, &data, &length, 0)) > 0) { diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index 9614449..9d7dae9 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -211,7 +211,7 @@ public: * user-viewable output from the program being run will be generated. * OUTPUT_MERGE is the legacy behaviour where stdout and stderr are merged * into stdout. OUTPUT_NORMAL passes through the output to stdout/stderr as - * it was received. + * it was received. OUTPUT_PASSTHROUGH passes through the original handles. * * If timeout is specified, the command will be terminated after * timeout expires. Timeout is specified in seconds. @@ -230,7 +230,8 @@ public: { OUTPUT_NONE = 0, OUTPUT_MERGE, - OUTPUT_NORMAL + OUTPUT_NORMAL, + OUTPUT_PASSTHROUGH }; static bool RunSingleCommand(const char* command, std::string* output = 0, int* retVal = 0, const char* dir = 0, diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index dd1bdde..147c332 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -304,7 +304,7 @@ void cmTarget::DefineProperties(cmake *cm) "List of options to pass to the compiler.", "This property specifies the list of options specified " "so far for this property. " - "This property exists on directories and targets. " + "This property exists on directories and targets." "\n" "The target property values are used by the generators to set " "the options for the compiler.\n" @@ -945,6 +945,11 @@ void cmTarget::DefineProperties(cmake *cm) "OSX_ARCHITECTURES."); cm->DefineProperty + ("NAME", cmProperty::TARGET, + "Logical name for the target.", + "Read-only logical name for the target as used by CMake."); + + cm->DefineProperty ("EXPORT_NAME", cmProperty::TARGET, "Exported name for target files.", "This sets the name for the IMPORTED target generated when it this " @@ -964,6 +969,12 @@ void cmTarget::DefineProperties(cmake *cm) "This is the configuration-specific version of OUTPUT_NAME."); cm->DefineProperty + ("ALIASED_TARGET", cmProperty::TARGET, + "Name of target aliased by this target.", + "If this is an ALIAS target, this property contains the name of the " + "target aliased."); + + cm->DefineProperty ("<CONFIG>_OUTPUT_NAME", cmProperty::TARGET, "Old per-configuration target file base name.", "This is a configuration-specific version of OUTPUT_NAME. " @@ -1001,22 +1012,13 @@ void cmTarget::DefineProperties(cmake *cm) "(such as \"lib\") on a library name."); cm->DefineProperty - ("C_VISIBILITY_PRESET", cmProperty::TARGET, + ("<LANG>_VISIBILITY_PRESET", cmProperty::TARGET, "Value for symbol visibility compile flags", - "The C_VISIBILITY_PRESET property determines the value passed used in " - "a visibility related compile option, such as -fvisibility=. This " - "property only has an affect for libraries and executables with " + "The <LANG>_VISIBILITY_PRESET property determines the value passed in " + "a visibility related compile option, such as -fvisibility= for <LANG>. " + "This property only has an affect for libraries and executables with " "exports. This property is initialized by the value of the variable " - "CMAKE_C_VISIBILITY_PRESET if it is set when a target is created."); - - cm->DefineProperty - ("CXX_VISIBILITY_PRESET", cmProperty::TARGET, - "Value for symbol visibility compile flags", - "The CXX_VISIBILITY_PRESET property determines the value passed used in " - "a visibility related compile option, such as -fvisibility=. This " - "property only has an affect for libraries and executables with " - "exports. This property is initialized by the value of the variable " - "CMAKE_CXX_VISIBILITY_PRESET if it is set when a target is created."); + "CMAKE_<LANG>_VISIBILITY_PRESET if it is set when a target is created."); cm->DefineProperty ("VISIBILITY_INLINES_HIDDEN", cmProperty::TARGET, @@ -2530,6 +2532,7 @@ void cmTarget::GetTllSignatureTraces(cmOStringStream &s, = (sig == cmTarget::KeywordTLLSignature ? "keyword" : "plain"); s << "The uses of the " << sigString << " signature are here:\n"; + std::set<cmStdString> emitted; for(std::vector<cmListFileBacktrace>::const_iterator it = sigs.begin(); it != sigs.end(); ++it) { @@ -2537,7 +2540,12 @@ void cmTarget::GetTllSignatureTraces(cmOStringStream &s, if(i != it->end()) { cmListFileContext const& lfc = *i; - s << " * " << (lfc.Line? "": " in ") << lfc << std::endl; + cmOStringStream line; + line << " * " << (lfc.Line? "": " in ") << lfc << std::endl; + if (emitted.insert(line.str()).second) + { + s << line.str(); + } ++i; } } @@ -2974,7 +2982,13 @@ void cmTarget::SetProperty(const char* prop, const char* value) { return; } - + if (strcmp(prop, "NAME") == 0) + { + cmOStringStream e; + e << "NAME property is read-only\n"; + this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str().c_str()); + return; + } if(strcmp(prop,"INCLUDE_DIRECTORIES") == 0) { cmListFileBacktrace lfbt; @@ -3041,6 +3055,13 @@ void cmTarget::AppendProperty(const char* prop, const char* value, { return; } + if (strcmp(prop, "NAME") == 0) + { + cmOStringStream e; + e << "NAME property is read-only\n"; + this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str().c_str()); + return; + } if(strcmp(prop,"INCLUDE_DIRECTORIES") == 0) { cmListFileBacktrace lfbt; @@ -3282,7 +3303,10 @@ static void processIncludeDirectories(cmTarget *tgt, if (!noMessage) { tgt->GetMakefile()->IssueMessage(messageType, e.str().c_str()); - return; + if (messageType == cmake::FATAL_ERROR) + { + return; + } } } @@ -4056,6 +4080,11 @@ const char *cmTarget::GetProperty(const char* prop, return 0; } + if (strcmp(prop, "NAME") == 0) + { + return this->GetName(); + } + // Watch for special "computed" properties that are dependent on // other properties or variables. Always recompute them. if(this->GetType() == cmTarget::EXECUTABLE || @@ -6248,7 +6277,7 @@ void cmTarget::ComputeImportInfo(std::string const& desired_config, } // Get the link languages. - if(this->GetType() == cmTarget::STATIC_LIBRARY) + if(this->LinkLanguagePropagatesToDependents()) { std::string linkProp = "IMPORTED_LINK_INTERFACE_LANGUAGES"; linkProp += suffix; @@ -6474,6 +6503,15 @@ bool cmTarget::ComputeLinkInterface(const char* config, LinkInterface& iface, break; } } + else + { + iface.Libraries = impl->Libraries; + if(this->LinkLanguagePropagatesToDependents()) + { + // Targets using this archive need its language runtime libraries. + iface.Languages = impl->Languages; + } + } } } @@ -6502,7 +6540,8 @@ bool cmTarget::ComputeLinkInterface(const char* config, LinkInterface& iface, headTarget, this, &dagChecker), iface.Libraries); - if(this->GetType() == cmTarget::SHARED_LIBRARY) + if(this->GetType() == cmTarget::SHARED_LIBRARY + || this->GetType() == cmTarget::STATIC_LIBRARY) { // Shared libraries may have runtime implementation dependencies // on other shared libraries that are not in the interface. @@ -6536,6 +6575,11 @@ bool cmTarget::ComputeLinkInterface(const char* config, LinkInterface& iface, } } } + if(this->LinkLanguagePropagatesToDependents()) + { + // Targets using this archive need its language runtime libraries. + iface.Languages = impl->Languages; + } } } else if (this->GetPolicyStatusCMP0022() == cmPolicies::WARN @@ -6550,7 +6594,7 @@ bool cmTarget::ComputeLinkInterface(const char* config, LinkInterface& iface, iface.ImplementationIsInterface = true; iface.Libraries = impl->Libraries; iface.WrongConfigLibraries = impl->WrongConfigLibraries; - if(this->GetType() == cmTarget::STATIC_LIBRARY) + if(this->LinkLanguagePropagatesToDependents()) { // Targets using this archive need its language runtime libraries. iface.Languages = impl->Languages; diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 24a71ed..27b74ca 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -549,6 +549,9 @@ public: void FinalizeSystemIncludeDirectories(); + bool LinkLanguagePropagatesToDependents() const + { return this->TargetTypeValue == STATIC_LIBRARY; } + private: // The set of include directories that are marked as system include // directories. diff --git a/Source/cmTargetLinkLibrariesCommand.cxx b/Source/cmTargetLinkLibrariesCommand.cxx index 0ee9420..863b391 100644 --- a/Source/cmTargetLinkLibrariesCommand.cxx +++ b/Source/cmTargetLinkLibrariesCommand.cxx @@ -31,6 +31,11 @@ bool cmTargetLinkLibrariesCommand return false; } + if (this->Makefile->IsAlias(args[0].c_str())) + { + this->SetError("can not be used on an ALIAS target."); + return false; + } // Lookup the target for which libraries are specified. this->Target = this->Makefile->GetCMakeInstance() diff --git a/Source/cmTargetPropCommandBase.cxx b/Source/cmTargetPropCommandBase.cxx index 287ce46..1862cb6 100644 --- a/Source/cmTargetPropCommandBase.cxx +++ b/Source/cmTargetPropCommandBase.cxx @@ -19,13 +19,18 @@ bool cmTargetPropCommandBase ::HandleArguments(std::vector<std::string> const& args, const char *prop, ArgumentFlags flags) { - if(args.size() < 3) + if(args.size() < 2) { this->SetError("called with incorrect number of arguments"); return false; } // Lookup the target for which libraries are specified. + if (this->Makefile->IsAlias(args[0].c_str())) + { + this->SetError("can not be used on an ALIAS target."); + return false; + } this->Target = this->Makefile->GetCMakeInstance() ->GetGlobalGenerator()->FindTarget(0, args[0].c_str()); @@ -53,7 +58,7 @@ bool cmTargetPropCommandBase if ((flags & PROCESS_SYSTEM) && args[argIndex] == "SYSTEM") { - if (args.size() < 4) + if (args.size() < 3) { this->SetError("called with incorrect number of arguments"); return false; @@ -65,7 +70,7 @@ bool cmTargetPropCommandBase bool prepend = false; if ((flags & PROCESS_BEFORE) && args[argIndex] == "BEFORE") { - if (args.size() < 4) + if (args.size() < 3) { this->SetError("called with incorrect number of arguments"); return false; diff --git a/Source/cmVariableWatch.cxx b/Source/cmVariableWatch.cxx index 3905e9b..8ad6fce 100644 --- a/Source/cmVariableWatch.cxx +++ b/Source/cmVariableWatch.cxx @@ -37,37 +37,63 @@ cmVariableWatch::cmVariableWatch() cmVariableWatch::~cmVariableWatch() { + cmVariableWatch::StringToVectorOfPairs::iterator svp_it; + + for ( svp_it = this->WatchMap.begin(); + svp_it != this->WatchMap.end(); ++svp_it ) + { + cmVariableWatch::VectorOfPairs::iterator p_it; + + for ( p_it = svp_it->second.begin(); + p_it != svp_it->second.end(); ++p_it ) + { + delete *p_it; + } + } } -void cmVariableWatch::AddWatch(const std::string& variable, - WatchMethod method, void* client_data /*=0*/) +bool cmVariableWatch::AddWatch(const std::string& variable, + WatchMethod method, void* client_data /*=0*/, + DeleteData delete_data /*=0*/) { - cmVariableWatch::Pair p; - p.Method = method; - p.ClientData = client_data; + cmVariableWatch::Pair* p = new cmVariableWatch::Pair; + p->Method = method; + p->ClientData = client_data; + p->DeleteDataCall = delete_data; cmVariableWatch::VectorOfPairs* vp = &this->WatchMap[variable]; cmVariableWatch::VectorOfPairs::size_type cc; for ( cc = 0; cc < vp->size(); cc ++ ) { - cmVariableWatch::Pair* pair = &(*vp)[cc]; - if ( pair->Method == method ) + cmVariableWatch::Pair* pair = (*vp)[cc]; + if ( pair->Method == method && + client_data && client_data == pair->ClientData) { - (*vp)[cc] = p; - return; + // Callback already exists + return false; } } vp->push_back(p); + return true; } void cmVariableWatch::RemoveWatch(const std::string& variable, - WatchMethod method) + WatchMethod method, + void* client_data /*=0*/) { + if ( !this->WatchMap.count(variable) ) + { + return; + } cmVariableWatch::VectorOfPairs* vp = &this->WatchMap[variable]; cmVariableWatch::VectorOfPairs::iterator it; for ( it = vp->begin(); it != vp->end(); ++it ) { - if ( it->Method == method ) + if ( (*it)->Method == method && + // If client_data is NULL, we want to disconnect all watches against + // the given method; otherwise match ClientData as well. + (!client_data || (client_data == (*it)->ClientData))) { + delete *it; vp->erase(it); return; } @@ -87,7 +113,7 @@ void cmVariableWatch::VariableAccessed(const std::string& variable, cmVariableWatch::VectorOfPairs::const_iterator it; for ( it = vp->begin(); it != vp->end(); it ++ ) { - it->Method(variable, access_type, it->ClientData, + (*it)->Method(variable, access_type, (*it)->ClientData, newValue, mf); } } diff --git a/Source/cmVariableWatch.h b/Source/cmVariableWatch.h index 7dd4ac5..790c75a 100644 --- a/Source/cmVariableWatch.h +++ b/Source/cmVariableWatch.h @@ -26,6 +26,7 @@ class cmVariableWatch public: typedef void (*WatchMethod)(const std::string& variable, int access_type, void* client_data, const char* newValue, const cmMakefile* mf); + typedef void (*DeleteData)(void* client_data); cmVariableWatch(); ~cmVariableWatch(); @@ -33,9 +34,10 @@ public: /** * Add watch to the variable */ - void AddWatch(const std::string& variable, WatchMethod method, - void* client_data=0); - void RemoveWatch(const std::string& variable, WatchMethod method); + bool AddWatch(const std::string& variable, WatchMethod method, + void* client_data=0, DeleteData delete_data=0); + void RemoveWatch(const std::string& variable, WatchMethod method, + void* client_data=0); /** * This method is called when variable is accessed @@ -67,10 +69,18 @@ protected: { WatchMethod Method; void* ClientData; - Pair() : Method(0), ClientData(0) {} + DeleteData DeleteDataCall; + Pair() : Method(0), ClientData(0), DeleteDataCall(0) {} + ~Pair() + { + if (this->DeleteDataCall && this->ClientData) + { + this->DeleteDataCall(this->ClientData); + } + } }; - typedef std::vector< Pair > VectorOfPairs; + typedef std::vector< Pair* > VectorOfPairs; typedef std::map<cmStdString, VectorOfPairs > StringToVectorOfPairs; StringToVectorOfPairs WatchMap; diff --git a/Source/cmVariableWatchCommand.cxx b/Source/cmVariableWatchCommand.cxx index 297a92b..33e159b 100644 --- a/Source/cmVariableWatchCommand.cxx +++ b/Source/cmVariableWatchCommand.cxx @@ -14,63 +14,27 @@ #include "cmVariableWatch.h" //---------------------------------------------------------------------------- -static void cmVariableWatchCommandVariableAccessed( - const std::string& variable, int access_type, void* client_data, - const char* newValue, const cmMakefile* mf) +struct cmVariableWatchCallbackData { - cmVariableWatchCommand* command - = static_cast<cmVariableWatchCommand*>(client_data); - command->VariableAccessed(variable, access_type, newValue, mf); -} + bool InCallback; + std::string Command; +}; //---------------------------------------------------------------------------- -cmVariableWatchCommand::cmVariableWatchCommand() +static void cmVariableWatchCommandVariableAccessed( + const std::string& variable, int access_type, void* client_data, + const char* newValue, const cmMakefile* mf) { - this->InCallback = false; -} + cmVariableWatchCallbackData* data + = static_cast<cmVariableWatchCallbackData*>(client_data); -//---------------------------------------------------------------------------- -bool cmVariableWatchCommand -::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &) -{ - if ( args.size() < 1 ) - { - this->SetError("must be called with at least one argument."); - return false; - } - std::string variable = args[0]; - if ( args.size() > 1 ) - { - std::string command = args[1]; - this->Handlers[variable].Commands.push_back(args[1]); - } - if ( variable == "CMAKE_CURRENT_LIST_FILE" ) - { - cmOStringStream ostr; - ostr << "cannot be set on the variable: " << variable.c_str(); - this->SetError(ostr.str().c_str()); - return false; - } - - this->Makefile->GetCMakeInstance()->GetVariableWatch()->AddWatch( - variable, cmVariableWatchCommandVariableAccessed, this); - - return true; -} - -//---------------------------------------------------------------------------- -void cmVariableWatchCommand::VariableAccessed(const std::string& variable, - int access_type, const char* newValue, const cmMakefile* mf) -{ - if ( this->InCallback ) + if ( data->InCallback ) { return; } - this->InCallback = true; + data->InCallback = true; cmListFileFunction newLFF; - cmVariableWatchCommandHandler *handler = &this->Handlers[variable]; - cmVariableWatchCommandHandler::VectorOfCommands::iterator it; cmListFileArgument arg; bool processed = false; const char* accessString = cmVariableWatch::GetAccessAsString(access_type); @@ -80,22 +44,25 @@ void cmVariableWatchCommand::VariableAccessed(const std::string& variable, cmMakefile* makefile = const_cast<cmMakefile*>(mf); std::string stack = makefile->GetProperty("LISTFILE_STACK"); - for ( it = handler->Commands.begin(); it != handler->Commands.end(); - ++ it ) + if ( !data->Command.empty() ) { - std::string command = *it; newLFF.Arguments.clear(); newLFF.Arguments.push_back( - cmListFileArgument(variable, true, "unknown", 9999)); + cmListFileArgument(variable, cmListFileArgument::Quoted, + "unknown", 9999)); newLFF.Arguments.push_back( - cmListFileArgument(accessString, true, "unknown", 9999)); + cmListFileArgument(accessString, cmListFileArgument::Quoted, + "unknown", 9999)); newLFF.Arguments.push_back( - cmListFileArgument(newValue?newValue:"", true, "unknown", 9999)); + cmListFileArgument(newValue?newValue:"", cmListFileArgument::Quoted, + "unknown", 9999)); newLFF.Arguments.push_back( - cmListFileArgument(currentListFile, true, "unknown", 9999)); + cmListFileArgument(currentListFile, cmListFileArgument::Quoted, + "unknown", 9999)); newLFF.Arguments.push_back( - cmListFileArgument(stack, true, "unknown", 9999)); - newLFF.Name = command; + cmListFileArgument(stack, cmListFileArgument::Quoted, + "unknown", 9999)); + newLFF.Name = data->Command; newLFF.FilePath = "Some weird path"; newLFF.Line = 9999; cmExecutionStatus status; @@ -106,10 +73,10 @@ void cmVariableWatchCommand::VariableAccessed(const std::string& variable, cmOStringStream error; error << "Error in cmake code at\n" << arg.FilePath << ":" << arg.Line << ":\n" - << "A command failed during the invocation of callback\"" - << command << "\"."; + << "A command failed during the invocation of callback \"" + << data->Command << "\"."; cmSystemTools::Error(error.str().c_str()); - this->InCallback = false; + data->InCallback = false; return; } processed = true; @@ -118,8 +85,75 @@ void cmVariableWatchCommand::VariableAccessed(const std::string& variable, { cmOStringStream msg; msg << "Variable \"" << variable.c_str() << "\" was accessed using " - << accessString << " with value \"" << newValue << "\"."; + << accessString << " with value \"" << (newValue?newValue:"") << "\"."; makefile->IssueMessage(cmake::LOG, msg.str()); } - this->InCallback = false; + + data->InCallback = false; +} + +//---------------------------------------------------------------------------- +static void deleteVariableWatchCallbackData(void* client_data) +{ + cmVariableWatchCallbackData* data + = static_cast<cmVariableWatchCallbackData*>(client_data); + delete data; +} + +//---------------------------------------------------------------------------- +cmVariableWatchCommand::cmVariableWatchCommand() +{ +} + +//---------------------------------------------------------------------------- +cmVariableWatchCommand::~cmVariableWatchCommand() +{ + std::set<std::string>::const_iterator it; + for ( it = this->WatchedVariables.begin(); + it != this->WatchedVariables.end(); + ++it ) + { + this->Makefile->GetCMakeInstance()->GetVariableWatch()->RemoveWatch( + *it, cmVariableWatchCommandVariableAccessed); + } +} + +//---------------------------------------------------------------------------- +bool cmVariableWatchCommand +::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &) +{ + if ( args.size() < 1 ) + { + this->SetError("must be called with at least one argument."); + return false; + } + std::string variable = args[0]; + std::string command; + if ( args.size() > 1 ) + { + command = args[1]; + } + if ( variable == "CMAKE_CURRENT_LIST_FILE" ) + { + cmOStringStream ostr; + ostr << "cannot be set on the variable: " << variable.c_str(); + this->SetError(ostr.str().c_str()); + return false; + } + + cmVariableWatchCallbackData* data = new cmVariableWatchCallbackData; + + data->InCallback = false; + data->Command = command; + + this->WatchedVariables.insert(variable); + if ( !this->Makefile->GetCMakeInstance()->GetVariableWatch()->AddWatch( + variable, cmVariableWatchCommandVariableAccessed, + data, deleteVariableWatchCallbackData) ) + { + deleteVariableWatchCallbackData(data); + return false; + } + + return true; } diff --git a/Source/cmVariableWatchCommand.h b/Source/cmVariableWatchCommand.h index 3abc088..545535c 100644 --- a/Source/cmVariableWatchCommand.h +++ b/Source/cmVariableWatchCommand.h @@ -14,13 +14,6 @@ #include "cmCommand.h" -class cmVariableWatchCommandHandler -{ -public: - typedef std::vector<std::string> VectorOfCommands; - VectorOfCommands Commands; -}; - /** \class cmVariableWatchCommand * \brief Watch when the variable changes and invoke command * @@ -39,6 +32,9 @@ public: //! Default constructor cmVariableWatchCommand(); + //! Destructor. + ~cmVariableWatchCommand(); + /** * This is called when the command is first encountered in * the CMakeLists.txt file. @@ -83,13 +79,8 @@ public: cmTypeMacro(cmVariableWatchCommand, cmCommand); - void VariableAccessed(const std::string& variable, int access_type, - const char* newValue, const cmMakefile* mf); - protected: - std::map<std::string, cmVariableWatchCommandHandler> Handlers; - - bool InCallback; + std::set<std::string> WatchedVariables; }; diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index d59de11..ea05347 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -307,6 +307,11 @@ void cmVisualStudio10TargetGenerator::Generate() this->WriteString( "<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n", 1); this->WriteString("<ImportGroup Label=\"ExtensionSettings\">\n", 1); + if (this->GlobalGenerator->IsMasmEnabled()) + { + this->WriteString("<Import Project=\"$(VCTargetsPath)\\" + "BuildCustomizations\\masm.props\" />\n", 2); + } this->WriteString("</ImportGroup>\n", 1); this->WriteString("<ImportGroup Label=\"PropertySheets\">\n", 1); this->WriteString("<Import Project=\"" VS10_USER_PROPS "\"" @@ -326,6 +331,11 @@ void cmVisualStudio10TargetGenerator::Generate() "<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\"" " />\n", 1); this->WriteString("<ImportGroup Label=\"ExtensionTargets\">\n", 1); + if (this->GlobalGenerator->IsMasmEnabled()) + { + this->WriteString("<Import Project=\"$(VCTargetsPath)\\" + "BuildCustomizations\\masm.targets\" />\n", 2); + } this->WriteString("</ImportGroup>\n", 1); this->WriteString("</Project>", 0); // The groups are stored in a separate file for VS 10 @@ -982,24 +992,37 @@ void cmVisualStudio10TargetGenerator::WriteAllSources() si != this->GeneratorTarget->ObjectSources.end(); ++si) { const char* lang = (*si)->GetLanguage(); - bool cl = strcmp(lang, "C") == 0 || strcmp(lang, "CXX") == 0; - bool rc = strcmp(lang, "RC") == 0; - const char* tool = cl? "ClCompile" : (rc? "ResourceCompile" : "None"); - this->WriteSource(tool, *si, " "); - // ouput any flags specific to this source file - if(cl && this->OutputSourceSpecificFlags(*si)) + const char* tool = NULL; + if (strcmp(lang, "C") == 0 || strcmp(lang, "CXX") == 0) + { + tool = "ClCompile"; + } + else if (strcmp(lang, "ASM_MASM") == 0 && + this->GlobalGenerator->IsMasmEnabled()) + { + tool = "MASM"; + } + else if (strcmp(lang, "RC") == 0) { - // if the source file has specific flags the tag - // is ended on a new line - this->WriteString("</ClCompile>\n", 2); + tool = "ResourceCompile"; } - else if(rc && this->OutputSourceSpecificFlags(*si)) + + if (tool) { - this->WriteString("</ResourceCompile>\n", 2); + this->WriteSource(tool, *si, " "); + if (this->OutputSourceSpecificFlags(*si)) + { + this->WriteString("</", 2); + (*this->BuildFileStream ) << tool << ">\n"; + } + else + { + (*this->BuildFileStream ) << " />\n"; + } } else { - (*this->BuildFileStream ) << " />\n"; + this->WriteSource("None", *si); } } @@ -1389,7 +1412,7 @@ OutputIncludes(std::vector<std::string> const & includes) for(std::vector<std::string>::const_iterator i = includes.begin(); i != includes.end(); ++i) { - *this->BuildFileStream << *i << ";"; + *this->BuildFileStream << cmVS10EscapeXML(*i) << ";"; } this->WriteString("%(AdditionalIncludeDirectories)" "</AdditionalIncludeDirectories>\n", 0); @@ -1417,20 +1440,17 @@ cmVisualStudio10TargetGenerator::WriteLibOptions(std::string const& config) { return; } - const char* libflags = this->Target->GetProperty("STATIC_LIBRARY_FLAGS"); - std::string flagsConfigVar = "STATIC_LIBRARY_FLAGS_"; - flagsConfigVar += cmSystemTools::UpperCase(config); - const char* libflagsConfig = - this->Target->GetProperty(flagsConfigVar.c_str()); - if(libflags || libflagsConfig) + std::string libflags; + this->LocalGenerator->GetStaticLibraryFlags(libflags, + cmSystemTools::UpperCase(config), this->Target); + if(!libflags.empty()) { this->WriteString("<Lib>\n", 2); cmVisualStudioGeneratorOptions libOptions(this->LocalGenerator, cmVisualStudioGeneratorOptions::Linker, cmVSGetLibFlagTable(this->LocalGenerator), 0, this); - libOptions.Parse(libflags?libflags:""); - libOptions.Parse(libflagsConfig?libflagsConfig:""); + libOptions.Parse(libflags.c_str()); libOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", ""); libOptions.OutputFlagMap(*this->BuildFileStream, " "); this->WriteString("</Lib>\n", 2); @@ -1523,11 +1543,11 @@ cmVisualStudio10TargetGenerator::ComputeLinkOptions(std::string const& config) } if ( this->Target->GetPropertyAsBool("WIN32_EXECUTABLE") ) { - flags += " /SUBSYSTEM:WINDOWS"; + linkOptions.AddFlag("SubSystem", "Windows"); } else { - flags += " /SUBSYSTEM:CONSOLE"; + linkOptions.AddFlag("SubSystem", "Console"); } std::string standardLibsVar = "CMAKE_"; standardLibsVar += linkLanguage; diff --git a/Source/cmVisualStudioGeneratorOptions.cxx b/Source/cmVisualStudioGeneratorOptions.cxx index f4df1a9..6aca787 100644 --- a/Source/cmVisualStudioGeneratorOptions.cxx +++ b/Source/cmVisualStudioGeneratorOptions.cxx @@ -100,13 +100,13 @@ void cmVisualStudioGeneratorOptions::SetVerboseMakefile(bool verbose) } } -bool cmVisualStudioGeneratorOptions::IsDebug() +bool cmVisualStudioGeneratorOptions::IsDebug() const { return this->FlagMap.find("DebugInformationFormat") != this->FlagMap.end(); } //---------------------------------------------------------------------------- -bool cmVisualStudioGeneratorOptions::UsingUnicode() +bool cmVisualStudioGeneratorOptions::UsingUnicode() const { // Look for the a _UNICODE definition. for(std::vector<std::string>::const_iterator di = this->Defines.begin(); @@ -120,7 +120,7 @@ bool cmVisualStudioGeneratorOptions::UsingUnicode() return false; } //---------------------------------------------------------------------------- -bool cmVisualStudioGeneratorOptions::UsingSBCS() +bool cmVisualStudioGeneratorOptions::UsingSBCS() const { // Look for the a _SBCS definition. for(std::vector<std::string>::const_iterator di = this->Defines.begin(); diff --git a/Source/cmVisualStudioGeneratorOptions.h b/Source/cmVisualStudioGeneratorOptions.h index a1a55da..90f7667 100644 --- a/Source/cmVisualStudioGeneratorOptions.h +++ b/Source/cmVisualStudioGeneratorOptions.h @@ -47,10 +47,10 @@ public: void SetVerboseMakefile(bool verbose); // Check for specific options. - bool UsingUnicode(); - bool UsingSBCS(); + bool UsingUnicode() const; + bool UsingSBCS() const; - bool IsDebug(); + bool IsDebug() const; // Write options to output. void OutputPreprocessorDefinitions(std::ostream& fout, const char* prefix, diff --git a/Source/cmVisualStudioWCEPlatformParser.cxx b/Source/cmVisualStudioWCEPlatformParser.cxx index b302246..219a5eb 100644 --- a/Source/cmVisualStudioWCEPlatformParser.cxx +++ b/Source/cmVisualStudioWCEPlatformParser.cxx @@ -20,8 +20,12 @@ int cmVisualStudioWCEPlatformParser::ParseVersion(const char* version) const std::string vckey = registryBase + "\\Setup\\VC;ProductDir"; const std::string vskey = registryBase + "\\Setup\\VS;ProductDir"; - if(!cmSystemTools::ReadRegistryValue(vckey.c_str(), this->VcInstallDir) || - !cmSystemTools::ReadRegistryValue(vskey.c_str(), this->VsInstallDir)) + if(!cmSystemTools::ReadRegistryValue(vckey.c_str(), + this->VcInstallDir, + cmSystemTools::KeyWOW64_32) || + !cmSystemTools::ReadRegistryValue(vskey.c_str(), + this->VsInstallDir, + cmSystemTools::KeyWOW64_32)) { return 0; } diff --git a/Source/cmWhileCommand.cxx b/Source/cmWhileCommand.cxx index 4000345..7d2eead 100644 --- a/Source/cmWhileCommand.cxx +++ b/Source/cmWhileCommand.cxx @@ -49,9 +49,9 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf, unsigned int i; for(i =0; i < this->Args.size(); ++i) { - err += (this->Args[i].Quoted?"\"":""); + err += (this->Args[i].Delim?"\"":""); err += this->Args[i].Value; - err += (this->Args[i].Quoted?"\"":""); + err += (this->Args[i].Delim?"\"":""); err += " "; } err += "("; diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx index 77a5e43..68d8339 100644 --- a/Source/cmakemain.cxx +++ b/Source/cmakemain.cxx @@ -62,7 +62,10 @@ static const char * cmDocumentationDescription[][3] = " --config <cfg> = For multi-configuration tools, choose <cfg>.\n" \ " --clean-first = Build target 'clean' first, then build.\n" \ " (To clean only, use --target 'clean'.)\n" \ - " --use-stderr = Don't merge stdout/stderr.\n" \ + " --use-stderr = Don't merge stdout/stderr output and pass the\n" \ + " original stdout/stderr handles to the native\n" \ + " tool so it can use the capabilities of the\n" \ + " calling terminal (e.g. colored output).\n" \ " -- = Pass remaining options to the native tool.\n" //---------------------------------------------------------------------------- @@ -108,9 +111,11 @@ static const char * cmDocumentationOptions[][3] = "to stdout. This can be used to use cmake instead of pkg-config to find " "installed libraries in plain Makefile-based projects or in " "autoconf-based projects (via share/aclocal/cmake.m4)."}, - {"--graphviz=[file]", "Generate graphviz of dependencies.", + {"--graphviz=[file]", "Generate graphviz of dependencies, see " + "CMakeGraphVizOptions.cmake for more.", "Generate a graphviz input file that will contain all the library and " - "executable dependencies in the project."}, + "executable dependencies in the project. See the documentation for " + "CMakeGraphVizOptions.cmake for more details. "}, {"--system-information [file]", "Dump information about this system.", "Dump a wide range of information about the current system. If run " "from the top of a binary tree for a CMake project it will dump " @@ -604,7 +609,7 @@ static int do_build(int ac, char** av) } else if(strcmp(av[i], "--use-stderr") == 0) { - outputflag = cmSystemTools::OUTPUT_NORMAL; + outputflag = cmSystemTools::OUTPUT_PASSTHROUGH; } else if(strcmp(av[i], "--") == 0) { diff --git a/Source/cmcldeps.cxx b/Source/cmcldeps.cxx index 262d83b..8571557 100644 --- a/Source/cmcldeps.cxx +++ b/Source/cmcldeps.cxx @@ -62,8 +62,8 @@ static std::string trimLeadingSpace(const std::string& cmdline) { return cmdline.substr(i); } -static void doEscape(std::string& str, const std::string& search, - const std::string& repl) { +static void replaceAll(std::string& str, const std::string& search, + const std::string& repl) { std::string::size_type pos = 0; while ((pos = str.find(search, pos)) != std::string::npos) { str.replace(pos, search.size(), repl); @@ -71,6 +71,10 @@ static void doEscape(std::string& str, const std::string& search, } } +bool startsWith(const std::string& str, const std::string& what) { + return str.compare(0, what.size(), what) == 0; +} + // Strips one argument from the cmdline and returns it. "surrounding quotes" // are removed from the argument if there were any. static std::string getArg(std::string& cmdline) { @@ -117,6 +121,13 @@ static void parseCommandLine(LPTSTR wincmdline, rest = trimLeadingSpace(cmdline); } +// Not all backslashes need to be escaped in a depfile, but it's easier that +// way. See the re2c grammar in ninja's source code for more info. +static void escapePath(std::string &path) { + replaceAll(path, "\\", "\\\\"); + replaceAll(path, " ", "\\ "); +} + static void outputDepFile(const std::string& dfile, const std::string& objfile, std::vector<std::string>& incs) { @@ -132,16 +143,24 @@ static void outputDepFile(const std::string& dfile, const std::string& objfile, // FIXME should this be fatal or not? delete obj? delete d? if (!out) return; + std::string cwd = cmSystemTools::GetCurrentWorkingDirectory(); + replaceAll(cwd, "/", "\\"); + cwd += "\\"; std::string tmp = objfile; - doEscape(tmp, " ", "\\ "); + escapePath(tmp); fprintf(out, "%s: \\\n", tmp.c_str()); std::vector<std::string>::iterator it = incs.begin(); for (; it != incs.end(); ++it) { tmp = *it; - doEscape(tmp, "\\", "/"); - doEscape(tmp, " ", "\\ "); + // The paths need to match the ones used to identify build artifacts in the + // build.ninja file. Therefore we need to canonicalize the path to use + // backward slashes and relativize the path to the build directory. + replaceAll(tmp, "/", "\\"); + if (startsWith(tmp, cwd)) + tmp = tmp.substr(cwd.size()); + escapePath(tmp); fprintf(out, "%s \\\n", tmp.c_str()); } @@ -150,10 +169,6 @@ static void outputDepFile(const std::string& dfile, const std::string& objfile, } -bool startsWith(const std::string& str, const std::string& what) { - return str.compare(0, what.size(), what) == 0; -} - bool contains(const std::string& str, const std::string& what) { return str.find(what) != std::string::npos; } diff --git a/Source/kwsys/CMakeLists.txt b/Source/kwsys/CMakeLists.txt index 6f0281d..0f27836 100644 --- a/Source/kwsys/CMakeLists.txt +++ b/Source/kwsys/CMakeLists.txt @@ -649,6 +649,68 @@ IF(KWSYS_USE_SystemInformation) SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY COMPILE_DEFINITIONS KWSYS_CXX_HAS__ATOI64=1) ENDIF() + IF(UNIX) + INCLUDE(CheckIncludeFileCXX) + # check for simple stack trace + # usually it's in libc but on FreeBSD + # it's in libexecinfo + FIND_LIBRARY(EXECINFO_LIB "execinfo") + IF (NOT EXECINFO_LIB) + SET(EXECINFO_LIB "") + ENDIF() + CHECK_INCLUDE_FILE_CXX("execinfo.h" KWSYS_CXX_HAS_EXECINFOH) + IF (KWSYS_CXX_HAS_EXECINFOH) + # we have the backtrace header check if it + # can be used with this compiler + SET(KWSYS_PLATFORM_CXX_TEST_LINK_LIBRARIES ${EXECINFO_LIB}) + KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_BACKTRACE + "Checking whether backtrace works with this C++ compiler" DIRECT) + SET(KWSYS_PLATFORM_CXX_TEST_LINK_LIBRARIES) + IF (KWSYS_CXX_HAS_BACKTRACE) + # backtrace is supported by this system and compiler. + # now check for the more advanced capabilities. + SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY + COMPILE_DEFINITIONS KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE=1) + # check for symbol lookup using dladdr + CHECK_INCLUDE_FILE_CXX("dlfcn.h" KWSYS_CXX_HAS_DLFCNH) + IF (KWSYS_CXX_HAS_DLFCNH) + # we have symbol lookup libraries and headers + # check if they can be used with this compiler + SET(KWSYS_PLATFORM_CXX_TEST_LINK_LIBRARIES ${CMAKE_DL_LIBS}) + KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_DLADDR + "Checking whether dladdr works with this C++ compiler" DIRECT) + SET(KWSYS_PLATFORM_CXX_TEST_LINK_LIBRARIES) + IF (KWSYS_CXX_HAS_DLADDR) + # symbol lookup is supported by this system + # and compiler. + SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY + COMPILE_DEFINITIONS KWSYS_SYSTEMINFORMATION_HAS_SYMBOL_LOOKUP=1) + ENDIF() + ENDIF() + # c++ demangling support + # check for cxxabi headers + CHECK_INCLUDE_FILE_CXX("cxxabi.h" KWSYS_CXX_HAS_CXXABIH) + IF (KWSYS_CXX_HAS_CXXABIH) + # check if cxxabi can be used with this + # system and compiler. + KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_CXXABI + "Checking whether cxxabi works with this C++ compiler" DIRECT) + IF (KWSYS_CXX_HAS_CXXABI) + # c++ demangle using cxxabi is supported with + # this system and compiler + SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY + COMPILE_DEFINITIONS KWSYS_SYSTEMINFORMATION_HAS_CPP_DEMANGLE=1) + ENDIF() + ENDIF() + # basic backtrace works better with release build + # don't bother with advanced features for release + SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY + COMPILE_DEFINITIONS_DEBUG KWSYS_SYSTEMINFORMATION_HAS_DEBUG_BUILD=1) + SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY + COMPILE_DEFINITIONS_RELWITHDEBINFO KWSYS_SYSTEMINFORMATION_HAS_DEBUG_BUILD=1) + ENDIF() + ENDIF() + ENDIF() IF(BORLAND) KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_BORLAND_ASM "Checking whether Borland CXX compiler supports assembler instructions" DIRECT) @@ -913,12 +975,23 @@ IF(KWSYS_C_SRCS OR KWSYS_CXX_SRCS) ENDIF(UNIX) ENDIF(KWSYS_USE_DynamicLoader) - IF(KWSYS_USE_SystemInformation AND WIN32) - TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} ws2_32) - IF(KWSYS_SYS_HAS_PSAPI) - TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} Psapi) + IF(KWSYS_USE_SystemInformation) + IF(WIN32) + TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} ws2_32) + IF(KWSYS_SYS_HAS_PSAPI) + TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} Psapi) + ENDIF() + ELSEIF(UNIX) + IF (EXECINFO_LIB AND KWSYS_CXX_HAS_BACKTRACE) + # backtrace on FreeBSD is not in libc + TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} ${EXECINFO_LIB}) + ENDIF() + IF (KWSYS_CXX_HAS_DLADDR) + # for symbol lookup using dladdr + TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} ${CMAKE_DL_LIBS}) + ENDIF() ENDIF() - ENDIF(KWSYS_USE_SystemInformation AND WIN32) + ENDIF() # Apply user-defined target properties to the library. IF(KWSYS_PROPERTIES_CXX) diff --git a/Source/kwsys/SystemInformation.cxx b/Source/kwsys/SystemInformation.cxx index 9db1dee..beefd7d 100644 --- a/Source/kwsys/SystemInformation.cxx +++ b/Source/kwsys/SystemInformation.cxx @@ -18,6 +18,10 @@ # include <winsock.h> // WSADATA, include before sys/types.h #endif +#if (defined(__GNUC__) || defined(__PGI)) && !defined(_GNU_SOURCE) +# define _GNU_SOURCE +#endif + // TODO: // We need an alternative implementation for many functions in this file // when USE_ASM_INSTRUCTIONS gets defined as 0. @@ -114,8 +118,15 @@ typedef int siginfo_t; # define KWSYS_SYSTEMINFORMATION_IMPLEMENT_FQDN # endif # if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__-0 >= 1050 -# include <execinfo.h> -# define KWSYS_SYSTEMINFORMATION_HAVE_BACKTRACE +# if defined(KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE) +# include <execinfo.h> +# if defined(KWSYS_SYSTEMINFORMATION_HAS_CPP_DEMANGLE) +# include <cxxabi.h> +# endif +# if defined(KWSYS_SYSTEMINFORMATION_HAS_SYMBOL_LOOKUP) +# include <dlfcn.h> +# endif +# endif # endif #endif @@ -130,10 +141,13 @@ typedef int siginfo_t; # define KWSYS_SYSTEMINFORMATION_IMPLEMENT_FQDN # endif # endif -# if defined(__GNUC__) +# if defined(KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE) # include <execinfo.h> -# if !(defined(__LSB_VERSION__) && __LSB_VERSION__ < 41) -# define KWSYS_SYSTEMINFORMATION_HAVE_BACKTRACE +# if defined(KWSYS_SYSTEMINFORMATION_HAS_CPP_DEMANGLE) +# include <cxxabi.h> +# endif +# if defined(KWSYS_SYSTEMINFORMATION_HAS_SYMBOL_LOOKUP) +# include <dlfcn.h> # endif # endif # if defined(KWSYS_CXX_HAS_RLIMIT64) @@ -357,6 +371,10 @@ public: static void SetStackTraceOnError(int enable); + // get current stack + static + kwsys_stl::string GetProgramStack(int firstFrame, int wholePath); + /** Run the different checks */ void RunCPUCheck(); void RunOSCheck(); @@ -812,6 +830,11 @@ void SystemInformation::SetStackTraceOnError(int enable) SystemInformationImplementation::SetStackTraceOnError(enable); } +kwsys_stl::string SystemInformation::GetProgramStack(int firstFrame, int wholePath) +{ + return SystemInformationImplementation::GetProgramStack(firstFrame, wholePath); +} + /** Run the different checks */ void SystemInformation::RunCPUCheck() { @@ -908,6 +931,12 @@ int LoadLines( } continue; } + char *pBuf=buf; + while(*pBuf) + { + if (*pBuf=='\n') *pBuf='\0'; + pBuf+=1; + } lines.push_back(buf); ++nRead; } @@ -1046,12 +1075,29 @@ void StacktraceSignalHandler( #if defined(__linux) || defined(__APPLE__) kwsys_ios::ostringstream oss; oss + << kwsys_ios::endl << "=========================================================" << kwsys_ios::endl << "Process id " << getpid() << " "; switch (sigNo) { + case SIGINT: + oss << "Caught SIGINT"; + break; + + case SIGTERM: + oss << "Caught SIGTERM"; + break; + + case SIGABRT: + oss << "Caught SIGABRT"; + break; + case SIGFPE: - oss << "Caught SIGFPE "; + oss + << "Caught SIGFPE at " + << (sigInfo->si_addr==0?"0x":"") + << sigInfo->si_addr + << " "; switch (sigInfo->si_code) { # if defined(FPE_INTDIV) @@ -1099,7 +1145,11 @@ void StacktraceSignalHandler( break; case SIGSEGV: - oss << "Caught SIGSEGV "; + oss + << "Caught SIGSEGV at " + << (sigInfo->si_addr==0?"0x":"") + << sigInfo->si_addr + << " "; switch (sigInfo->si_code) { case SEGV_MAPERR: @@ -1116,16 +1166,12 @@ void StacktraceSignalHandler( } break; - case SIGINT: - oss << "Caught SIGTERM"; - break; - - case SIGTERM: - oss << "Caught SIGTERM"; - break; - case SIGBUS: - oss << "Caught SIGBUS type "; + oss + << "Caught SIGBUS at " + << (sigInfo->si_addr==0?"0x":"") + << sigInfo->si_addr + << " "; switch (sigInfo->si_code) { case BUS_ADRALN: @@ -1134,13 +1180,25 @@ void StacktraceSignalHandler( # if defined(BUS_ADRERR) case BUS_ADRERR: - oss << "non-exestent physical address"; + oss << "nonexistent physical address"; break; # endif # if defined(BUS_OBJERR) case BUS_OBJERR: - oss << "object specific hardware error"; + oss << "object-specific hardware error"; + break; +# endif + +# if defined(BUS_MCEERR_AR) + case BUS_MCEERR_AR: + oss << "Hardware memory error consumed on a machine check; action required."; + break; +# endif + +# if defined(BUS_MCEERR_AO) + case BUS_MCEERR_AO: + oss << "Hardware memory error detected in process but not consumed; action optional."; break; # endif @@ -1151,7 +1209,11 @@ void StacktraceSignalHandler( break; case SIGILL: - oss << "Caught SIGILL "; + oss + << "Caught SIGILL at " + << (sigInfo->si_addr==0?"0x":"") + << sigInfo->si_addr + << " "; switch (sigInfo->si_code) { case ILL_ILLOPC: @@ -1205,20 +1267,16 @@ void StacktraceSignalHandler( oss << "Caught " << sigNo << " code " << sigInfo->si_code; break; } - oss << kwsys_ios::endl; -#if defined(KWSYS_SYSTEMINFORMATION_HAVE_BACKTRACE) - oss << "Program Stack:" << kwsys_ios::endl; - void *stackSymbols[128]; - int n=backtrace(stackSymbols,128); - char **stackText=backtrace_symbols(stackSymbols,n); - for (int i=0; i<n; ++i) - { - oss << " " << stackText[i] << kwsys_ios::endl; - } -#endif oss - << "=========================================================" << kwsys_ios::endl; + << kwsys_ios::endl + << "Program Stack:" << kwsys_ios::endl + << SystemInformationImplementation::GetProgramStack(2,0) + << "=========================================================" << kwsys_ios::endl; kwsys_ios::cerr << oss.str() << kwsys_ios::endl; + + // restore the previously registered handlers + // and abort + SystemInformationImplementation::SetStackTraceOnError(0); abort(); #else // avoid warning C4100 @@ -1227,8 +1285,213 @@ void StacktraceSignalHandler( #endif } #endif + +#if defined(KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE) +#define safes(_arg)((_arg)?(_arg):"???") + +// Description: +// A container for symbol properties. Each instance +// must be Initialized. +class SymbolProperties +{ +public: + SymbolProperties(); + + // Description: + // The SymbolProperties instance must be initialized by + // passing a stack address. + void Initialize(void *address); + + // Description: + // Get the symbol's stack address. + void *GetAddress() const { return this->Address; } + + // Description: + // If not set paths will be removed. eg, from a binary + // or source file. + void SetReportPath(int rp){ this->ReportPath=rp; } + + // Description: + // Set/Get the name of the binary file that the symbol + // is found in. + void SetBinary(const char *binary) + { this->Binary=safes(binary); } + + kwsys_stl::string GetBinary() const; + + // Description: + // Set the name of the function that the symbol is found in. + // If c++ demangling is supported it will be demangled. + void SetFunction(const char *function) + { this->Function=this->Demangle(function); } + + kwsys_stl::string GetFunction() const + { return this->Function; } + + // Description: + // Set/Get the name of the source file where the symbol + // is defined. + void SetSourceFile(const char *sourcefile) + { this->SourceFile=safes(sourcefile); } + + kwsys_stl::string GetSourceFile() const + { return this->GetFileName(this->SourceFile); } + + // Description: + // Set/Get the line number where the symbol is defined + void SetLineNumber(long linenumber){ this->LineNumber=linenumber; } + long GetLineNumber() const { return this->LineNumber; } + + // Description: + // Set the address where the biinary image is mapped + // into memory. + void SetBinaryBaseAddress(void *address) + { this->BinaryBaseAddress=address; } + +private: + void *GetRealAddress() const + { return (void*)((char*)this->Address-(char*)this->BinaryBaseAddress); } + + kwsys_stl::string GetFileName(const kwsys_stl::string &path) const; + kwsys_stl::string Demangle(const char *symbol) const; + +private: + kwsys_stl::string Binary; + void *BinaryBaseAddress; + void *Address; + kwsys_stl::string SourceFile; + kwsys_stl::string Function; + long LineNumber; + int ReportPath; +}; + +// -------------------------------------------------------------------------- +kwsys_ios::ostream &operator<<( + kwsys_ios::ostream &os, + const SymbolProperties &sp) +{ +#if defined(KWSYS_SYSTEMINFORMATION_HAS_SYMBOL_LOOKUP) + os + << kwsys_ios::hex << sp.GetAddress() << " : " + << sp.GetFunction() + << " [(" << sp.GetBinary() << ") " + << sp.GetSourceFile() << ":" + << kwsys_ios::dec << sp.GetLineNumber() << "]"; +#elif defined(KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE) + void *addr = sp.GetAddress(); + char **syminfo = backtrace_symbols(&addr,1); + os << safes(syminfo[0]); + free(syminfo); +#else + (void)os; + (void)sp; +#endif + return os; +} + +// -------------------------------------------------------------------------- +SymbolProperties::SymbolProperties() +{ + // not using an initializer list + // to avoid some PGI compiler warnings + this->SetBinary("???"); + this->SetBinaryBaseAddress(NULL); + this->Address = NULL; + this->SetSourceFile("???"); + this->SetFunction("???"); + this->SetLineNumber(-1); + this->SetReportPath(0); + // avoid PGI compiler warnings + this->GetRealAddress(); + this->GetFunction(); + this->GetSourceFile(); + this->GetLineNumber(); +} + +// -------------------------------------------------------------------------- +kwsys_stl::string SymbolProperties::GetFileName(const kwsys_stl::string &path) const +{ + kwsys_stl::string file(path); + if (!this->ReportPath) + { + size_t at = file.rfind("/"); + if (at!=kwsys_stl::string::npos) + { + file = file.substr(at+1,kwsys_stl::string::npos); + } + } + return file; +} + +// -------------------------------------------------------------------------- +kwsys_stl::string SymbolProperties::GetBinary() const +{ +// only linux has proc fs +#if defined(__linux__) + if (this->Binary=="/proc/self/exe") + { + kwsys_stl::string binary; + char buf[1024]={'\0'}; + ssize_t ll=0; + if ((ll=readlink("/proc/self/exe",buf,1024))>0) + { + buf[ll]='\0'; + binary=buf; + } + else + { + binary="/proc/self/exe"; + } + return this->GetFileName(binary); + } +#endif + return this->GetFileName(this->Binary); +} + +// -------------------------------------------------------------------------- +kwsys_stl::string SymbolProperties::Demangle(const char *symbol) const +{ + kwsys_stl::string result = safes(symbol); +#if defined(KWSYS_SYSTEMINFORMATION_HAS_CPP_DEMANGLE) + int status = 0; + size_t bufferLen = 1024; + char *buffer = (char*)malloc(1024); + char *demangledSymbol = + abi::__cxa_demangle(symbol, buffer, &bufferLen, &status); + if (!status) + { + result = demangledSymbol; + } + free(buffer); +#else + (void)symbol; +#endif + return result; +} + +// -------------------------------------------------------------------------- +void SymbolProperties::Initialize(void *address) +{ + this->Address = address; +#if defined(KWSYS_SYSTEMINFORMATION_HAS_SYMBOL_LOOKUP) + // first fallback option can demangle c++ functions + Dl_info info; + int ierr=dladdr(this->Address,&info); + if (ierr && info.dli_sname && info.dli_saddr) + { + this->SetBinary(info.dli_fname); + this->SetFunction(info.dli_sname); + } +#else + // second fallback use builtin backtrace_symbols + // to decode the bactrace. +#endif +} +#endif // don't define this class if we're not using it + } // anonymous namespace + SystemInformationImplementation::SystemInformationImplementation() { this->TotalVirtualMemory = 0; @@ -3336,12 +3599,61 @@ SystemInformationImplementation::GetProcessId() } /** +return current program stack in a string +demangle cxx symbols if possible. +*/ +kwsys_stl::string SystemInformationImplementation::GetProgramStack( + int firstFrame, + int wholePath) +{ + kwsys_stl::string programStack = "" +#if !defined(KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE) + "WARNING: The stack could not be examined " + "because backtrace is not supported.\n" +#elif !defined(KWSYS_SYSTEMINFORMATION_HAS_DEBUG_BUILD) + "WARNING: The stack trace will not use advanced " + "capabilities because this is a release build.\n" +#else +# if !defined(KWSYS_SYSTEMINFORMATION_HAS_SYMBOL_LOOKUP) + "WARNING: Function names will not be demangled because " + "dladdr is not available.\n" +# endif +# if !defined(KWSYS_SYSTEMINFORMATION_HAS_CPP_DEMANGLE) + "WARNING: Function names will not be demangled " + "because cxxabi is not available.\n" +# endif +#endif + ; + + kwsys_ios::ostringstream oss; +#if defined(KWSYS_SYSTEMINFORMATION_HAS_BACKTRACE) + void *stackSymbols[256]; + int nFrames=backtrace(stackSymbols,256); + for (int i=firstFrame; i<nFrames; ++i) + { + SymbolProperties symProps; + symProps.SetReportPath(wholePath); + symProps.Initialize(stackSymbols[i]); + oss << symProps << kwsys_ios::endl; + } +#else + (void)firstFrame; + (void)wholePath; +#endif + programStack += oss.str(); + + return programStack; +} + + +/** when set print stack trace in response to common signals. */ void SystemInformationImplementation::SetStackTraceOnError(int enable) { #if !defined(_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__) static int saOrigValid=0; + static struct sigaction saABRTOrig; static struct sigaction saSEGVOrig; static struct sigaction saTERMOrig; static struct sigaction saINTOrig; @@ -3349,9 +3661,11 @@ void SystemInformationImplementation::SetStackTraceOnError(int enable) static struct sigaction saBUSOrig; static struct sigaction saFPEOrig; + if (enable && !saOrigValid) { // save the current actions + sigaction(SIGABRT,0,&saABRTOrig); sigaction(SIGSEGV,0,&saSEGVOrig); sigaction(SIGTERM,0,&saTERMOrig); sigaction(SIGINT,0,&saINTOrig); @@ -3365,9 +3679,10 @@ void SystemInformationImplementation::SetStackTraceOnError(int enable) // install ours struct sigaction sa; sa.sa_sigaction=(SigAction)StacktraceSignalHandler; - sa.sa_flags=SA_SIGINFO|SA_RESTART; + sa.sa_flags=SA_SIGINFO|SA_RESTART|SA_RESETHAND; sigemptyset(&sa.sa_mask); + sigaction(SIGABRT,&sa,0); sigaction(SIGSEGV,&sa,0); sigaction(SIGTERM,&sa,0); sigaction(SIGINT,&sa,0); @@ -3379,6 +3694,7 @@ void SystemInformationImplementation::SetStackTraceOnError(int enable) if (!enable && saOrigValid) { // restore previous actions + sigaction(SIGABRT,&saABRTOrig,0); sigaction(SIGSEGV,&saSEGVOrig,0); sigaction(SIGTERM,&saTERMOrig,0); sigaction(SIGINT,&saINTOrig,0); diff --git a/Source/kwsys/SystemInformation.hxx.in b/Source/kwsys/SystemInformation.hxx.in index f7c454e..a9fd05d 100644 --- a/Source/kwsys/SystemInformation.hxx.in +++ b/Source/kwsys/SystemInformation.hxx.in @@ -136,6 +136,12 @@ public: static void SetStackTraceOnError(int enable); + // format and return the current program stack in a string. In + // order to produce an informative stack trace the application + // should be dynamically linked and compiled with debug symbols. + static + kwsys_stl::string GetProgramStack(int firstFrame, int wholePath); + /** Run the different checks */ void RunCPUCheck(); void RunOSCheck(); diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index 935b836..e9a1fd3 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/SystemTools.cxx @@ -695,6 +695,52 @@ void SystemTools::ReplaceString(kwsys_stl::string& source, #endif #if defined(_WIN32) && !defined(__CYGWIN__) +static bool SystemToolsParseRegistryKey(const char* key, + HKEY& primaryKey, + kwsys_stl::string& second, + kwsys_stl::string& valuename) +{ + kwsys_stl::string primary = key; + + size_t start = primary.find("\\"); + if (start == kwsys_stl::string::npos) + { + return false; + } + + size_t valuenamepos = primary.find(";"); + if (valuenamepos != kwsys_stl::string::npos) + { + valuename = primary.substr(valuenamepos+1); + } + + second = primary.substr(start+1, valuenamepos-start-1); + primary = primary.substr(0, start); + + if (primary == "HKEY_CURRENT_USER") + { + primaryKey = HKEY_CURRENT_USER; + } + if (primary == "HKEY_CURRENT_CONFIG") + { + primaryKey = HKEY_CURRENT_CONFIG; + } + if (primary == "HKEY_CLASSES_ROOT") + { + primaryKey = HKEY_CLASSES_ROOT; + } + if (primary == "HKEY_LOCAL_MACHINE") + { + primaryKey = HKEY_LOCAL_MACHINE; + } + if (primary == "HKEY_USERS") + { + primaryKey = HKEY_USERS; + } + + return true; +} + static DWORD SystemToolsMakeRegistryMode(DWORD mode, SystemTools::KeyWOW64 view) { @@ -718,6 +764,55 @@ static DWORD SystemToolsMakeRegistryMode(DWORD mode, } #endif +#if defined(_WIN32) && !defined(__CYGWIN__) +bool +SystemTools::GetRegistrySubKeys(const char *key, + kwsys_stl::vector<kwsys_stl::string>& subkeys, + KeyWOW64 view) +{ + HKEY primaryKey = HKEY_CURRENT_USER; + kwsys_stl::string second; + kwsys_stl::string valuename; + if (!SystemToolsParseRegistryKey(key, primaryKey, second, valuename)) + { + return false; + } + + HKEY hKey; + if(RegOpenKeyEx(primaryKey, + second.c_str(), + 0, + SystemToolsMakeRegistryMode(KEY_READ, view), + &hKey) != ERROR_SUCCESS) + { + return false; + } + else + { + char name[1024]; + DWORD dwNameSize = sizeof(name)/sizeof(name[0]); + + DWORD i = 0; + while (RegEnumKey(hKey, i, name, dwNameSize) == ERROR_SUCCESS) + { + subkeys.push_back(name); + ++i; + } + + RegCloseKey(hKey); + } + + return true; +} +#else +bool SystemTools::GetRegistrySubKeys(const char *, + kwsys_stl::vector<kwsys_stl::string>&, + KeyWOW64) +{ + return false; +} +#endif + // Read a registry value. // Example : // HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.1\InstallPath @@ -730,47 +825,14 @@ bool SystemTools::ReadRegistryValue(const char *key, kwsys_stl::string &value, KeyWOW64 view) { bool valueset = false; - kwsys_stl::string primary = key; + HKEY primaryKey = HKEY_CURRENT_USER; kwsys_stl::string second; kwsys_stl::string valuename; - - size_t start = primary.find("\\"); - if (start == kwsys_stl::string::npos) + if (!SystemToolsParseRegistryKey(key, primaryKey, second, valuename)) { return false; } - size_t valuenamepos = primary.find(";"); - if (valuenamepos != kwsys_stl::string::npos) - { - valuename = primary.substr(valuenamepos+1); - } - - second = primary.substr(start+1, valuenamepos-start-1); - primary = primary.substr(0, start); - - HKEY primaryKey = HKEY_CURRENT_USER; - if (primary == "HKEY_CURRENT_USER") - { - primaryKey = HKEY_CURRENT_USER; - } - if (primary == "HKEY_CURRENT_CONFIG") - { - primaryKey = HKEY_CURRENT_CONFIG; - } - if (primary == "HKEY_CLASSES_ROOT") - { - primaryKey = HKEY_CLASSES_ROOT; - } - if (primary == "HKEY_LOCAL_MACHINE") - { - primaryKey = HKEY_LOCAL_MACHINE; - } - if (primary == "HKEY_USERS") - { - primaryKey = HKEY_USERS; - } - HKEY hKey; if(RegOpenKeyEx(primaryKey, second.c_str(), @@ -834,47 +896,14 @@ bool SystemTools::ReadRegistryValue(const char *, kwsys_stl::string &, bool SystemTools::WriteRegistryValue(const char *key, const char *value, KeyWOW64 view) { - kwsys_stl::string primary = key; + HKEY primaryKey = HKEY_CURRENT_USER; kwsys_stl::string second; kwsys_stl::string valuename; - - size_t start = primary.find("\\"); - if (start == kwsys_stl::string::npos) + if (!SystemToolsParseRegistryKey(key, primaryKey, second, valuename)) { return false; } - size_t valuenamepos = primary.find(";"); - if (valuenamepos != kwsys_stl::string::npos) - { - valuename = primary.substr(valuenamepos+1); - } - - second = primary.substr(start+1, valuenamepos-start-1); - primary = primary.substr(0, start); - - HKEY primaryKey = HKEY_CURRENT_USER; - if (primary == "HKEY_CURRENT_USER") - { - primaryKey = HKEY_CURRENT_USER; - } - if (primary == "HKEY_CURRENT_CONFIG") - { - primaryKey = HKEY_CURRENT_CONFIG; - } - if (primary == "HKEY_CLASSES_ROOT") - { - primaryKey = HKEY_CLASSES_ROOT; - } - if (primary == "HKEY_LOCAL_MACHINE") - { - primaryKey = HKEY_LOCAL_MACHINE; - } - if (primary == "HKEY_USERS") - { - primaryKey = HKEY_USERS; - } - HKEY hKey; DWORD dwDummy; char lpClass[] = ""; @@ -919,47 +948,14 @@ bool SystemTools::WriteRegistryValue(const char *, const char *, KeyWOW64) #if defined(_WIN32) && !defined(__CYGWIN__) bool SystemTools::DeleteRegistryValue(const char *key, KeyWOW64 view) { - kwsys_stl::string primary = key; + HKEY primaryKey = HKEY_CURRENT_USER; kwsys_stl::string second; kwsys_stl::string valuename; - - size_t start = primary.find("\\"); - if (start == kwsys_stl::string::npos) + if (!SystemToolsParseRegistryKey(key, primaryKey, second, valuename)) { return false; } - size_t valuenamepos = primary.find(";"); - if (valuenamepos != kwsys_stl::string::npos) - { - valuename = primary.substr(valuenamepos+1); - } - - second = primary.substr(start+1, valuenamepos-start-1); - primary = primary.substr(0, start); - - HKEY primaryKey = HKEY_CURRENT_USER; - if (primary == "HKEY_CURRENT_USER") - { - primaryKey = HKEY_CURRENT_USER; - } - if (primary == "HKEY_CURRENT_CONFIG") - { - primaryKey = HKEY_CURRENT_CONFIG; - } - if (primary == "HKEY_CLASSES_ROOT") - { - primaryKey = HKEY_CLASSES_ROOT; - } - if (primary == "HKEY_LOCAL_MACHINE") - { - primaryKey = HKEY_LOCAL_MACHINE; - } - if (primary == "HKEY_USERS") - { - primaryKey = HKEY_USERS; - } - HKEY hKey; if(RegOpenKeyEx(primaryKey, second.c_str(), @@ -4869,7 +4865,8 @@ static int SystemToolsDebugReport(int, char* message, int*) void SystemTools::EnableMSVCDebugHook() { - if (getenv("DART_TEST_FROM_DART")) + if (getenv("DART_TEST_FROM_DART") || + getenv("DASHBOARD_TEST_FROM_CTEST")) { _CrtSetReportHook(SystemToolsDebugReport); } diff --git a/Source/kwsys/SystemTools.hxx.in b/Source/kwsys/SystemTools.hxx.in index e55d431..d6dae39 100644 --- a/Source/kwsys/SystemTools.hxx.in +++ b/Source/kwsys/SystemTools.hxx.in @@ -716,6 +716,13 @@ public: enum KeyWOW64 { KeyWOW64_Default, KeyWOW64_32, KeyWOW64_64 }; /** + * Get a list of subkeys. + */ + static bool GetRegistrySubKeys(const char *key, + kwsys_stl::vector<kwsys_stl::string>& subkeys, + KeyWOW64 view = KeyWOW64_Default); + + /** * Read a registry value */ static bool ReadRegistryValue(const char *key, kwsys_stl::string &value, diff --git a/Source/kwsys/auto_ptr.hxx.in b/Source/kwsys/auto_ptr.hxx.in index 857b1db..ad9654c 100644 --- a/Source/kwsys/auto_ptr.hxx.in +++ b/Source/kwsys/auto_ptr.hxx.in @@ -31,6 +31,17 @@ # define @KWSYS_NAMESPACE@_AUTO_PTR_CAST(a) a #endif +// In C++11, clang will warn about using dynamic exception specifications +// as they are deprecated. But as this class is trying to faithfully +// mimic std::auto_ptr, we want to keep the 'throw()' decorations below. +// So we suppress the warning. +#if defined(__clang__) && defined(__has_warning) +# if __has_warning("-Wdeprecated") +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wdeprecated" +# endif +#endif + namespace @KWSYS_NAMESPACE@ { @@ -198,4 +209,11 @@ public: } // namespace @KWSYS_NAMESPACE@ +// Undo warning suppression. +#if defined(__clang__) && defined(__has_warning) +# if __has_warning("-Wdeprecated") +# pragma clang diagnostic pop +# endif +#endif + #endif diff --git a/Source/kwsys/hashtable.hxx.in b/Source/kwsys/hashtable.hxx.in index c835503..651de82 100644 --- a/Source/kwsys/hashtable.hxx.in +++ b/Source/kwsys/hashtable.hxx.in @@ -62,6 +62,17 @@ # pragma set woff 3970 /* pointer to int conversion */ 3321 3968 #endif +// In C++11, clang will warn about using dynamic exception specifications +// as they are deprecated. But as this class is trying to faithfully +// mimic unordered_set and unordered_map, we want to keep the 'throw()' +// decorations below. So we suppress the warning. +#if defined(__clang__) && defined(__has_warning) +# if __has_warning("-Wdeprecated") +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wdeprecated" +# endif +#endif + #if @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_TEMPLATE # define @KWSYS_NAMESPACE@_HASH_DEFAULT_ALLOCATOR(T) @KWSYS_NAMESPACE@_stl::allocator< T > #elif @KWSYS_NAMESPACE@_STL_HAS_ALLOCATOR_NONTEMPLATE @@ -1268,6 +1279,13 @@ using @KWSYS_NAMESPACE@::operator==; using @KWSYS_NAMESPACE@::operator!=; #endif +// Undo warning suppression. +#if defined(__clang__) && defined(__has_warning) +# if __has_warning("-Wdeprecated") +# pragma clang diagnostic pop +# endif +#endif + #if defined(_MSC_VER) # pragma warning (pop) #endif diff --git a/Source/kwsys/kwsysPlatformTests.cmake b/Source/kwsys/kwsysPlatformTests.cmake index d042450..f9ee254 100644 --- a/Source/kwsys/kwsysPlatformTests.cmake +++ b/Source/kwsys/kwsysPlatformTests.cmake @@ -19,6 +19,7 @@ MACRO(KWSYS_PLATFORM_TEST lang var description invert) ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${KWSYS_PLATFORM_TEST_FILE_${lang}} COMPILE_DEFINITIONS -DTEST_${var} ${KWSYS_PLATFORM_TEST_DEFINES} ${KWSYS_PLATFORM_TEST_EXTRA_FLAGS} + CMAKE_FLAGS "-DLINK_LIBRARIES:STRING=${KWSYS_PLATFORM_TEST_LINK_LIBRARIES}" OUTPUT_VARIABLE OUTPUT) IF(${var}_COMPILED) FILE(APPEND @@ -150,9 +151,11 @@ ENDMACRO(KWSYS_PLATFORM_C_TEST_RUN) MACRO(KWSYS_PLATFORM_CXX_TEST var description invert) SET(KWSYS_PLATFORM_TEST_DEFINES ${KWSYS_PLATFORM_CXX_TEST_DEFINES}) SET(KWSYS_PLATFORM_TEST_EXTRA_FLAGS ${KWSYS_PLATFORM_CXX_TEST_EXTRA_FLAGS}) + SET(KWSYS_PLATFORM_TEST_LINK_LIBRARIES ${KWSYS_PLATFORM_CXX_TEST_LINK_LIBRARIES}) KWSYS_PLATFORM_TEST(CXX "${var}" "${description}" "${invert}") SET(KWSYS_PLATFORM_TEST_DEFINES) SET(KWSYS_PLATFORM_TEST_EXTRA_FLAGS) + SET(KWSYS_PLATFORM_TEST_LINK_LIBRARIES) ENDMACRO(KWSYS_PLATFORM_CXX_TEST) MACRO(KWSYS_PLATFORM_CXX_TEST_RUN var description invert) diff --git a/Source/kwsys/kwsysPlatformTestsCXX.cxx b/Source/kwsys/kwsysPlatformTestsCXX.cxx index a7e3b50..be7a09e 100644 --- a/Source/kwsys/kwsysPlatformTestsCXX.cxx +++ b/Source/kwsys/kwsysPlatformTestsCXX.cxx @@ -513,6 +513,54 @@ int main() } #endif +#ifdef TEST_KWSYS_CXX_HAS_BACKTRACE +#if defined(__PATHSCALE__) || defined(__PATHCC__) \ + || (defined(__LSB_VERSION__) && (__LSB_VERSION__ < 41)) +backtrace doesnt work with this compiler or os +#endif +#if (defined(__GNUC__) || defined(__PGI)) && !defined(_GNU_SOURCE) +# define _GNU_SOURCE +#endif +#include <execinfo.h> +int main() +{ + void *stackSymbols[256]; + backtrace(stackSymbols,256); + backtrace_symbols(&stackSymbols[0],1); + return 0; +} +#endif + +#ifdef TEST_KWSYS_CXX_HAS_DLADDR +#if (defined(__GNUC__) || defined(__PGI)) && !defined(_GNU_SOURCE) +# define _GNU_SOURCE +#endif +#include <dlfcn.h> +int main() +{ + Dl_info info; + int ierr=dladdr((void*)main,&info); + return 0; +} +#endif + +#ifdef TEST_KWSYS_CXX_HAS_CXXABI +#if (defined(__GNUC__) || defined(__PGI)) && !defined(_GNU_SOURCE) +# define _GNU_SOURCE +#endif +#include <cxxabi.h> +int main() +{ + int status = 0; + size_t bufferLen = 512; + char buffer[512] = {'\0'}; + const char *function="_ZN5kwsys17SystemInformation15GetProgramStackEii"; + char *demangledFunction = + abi::__cxa_demangle(function, buffer, &bufferLen, &status); + return status; +} +#endif + #ifdef TEST_KWSYS_CXX_TYPE_INFO /* Collect fundamental type information and save it to a CMake script. */ diff --git a/Source/kwsys/testSystemInformation.cxx b/Source/kwsys/testSystemInformation.cxx index 738043f..53d51ac 100644 --- a/Source/kwsys/testSystemInformation.cxx +++ b/Source/kwsys/testSystemInformation.cxx @@ -95,7 +95,24 @@ int testSystemInformation(int, char*[]) kwsys_ios::cout << "CPU feature " << i << "\n"; } } - //int GetProcessorCacheXSize(long int); -// bool DoesCPUSupportFeature(long int); + + /* test stack trace + */ + kwsys_ios::cout + << "Program Stack:" << kwsys_ios::endl + << kwsys::SystemInformation::GetProgramStack(0,0) << kwsys_ios::endl + << kwsys_ios::endl; + + /* test segv handler + info.SetStackTraceOnError(1); + double *d = (double*)100; + *d=0; + */ + + /* test abort handler + info.SetStackTraceOnError(1); + abort(); + */ + return 0; } |