From 347c5f4b46396e974ff164b44f23b37eef779138 Mon Sep 17 00:00:00 2001 From: Bill Hoffman Date: Wed, 8 Feb 2006 10:58:36 -0500 Subject: [PATCH] ENH: add working directory support --- Modules/CMakeFortranInformation.cmake | 11 ++++++++++ Source/CMakeLists.txt | 14 +++++++++++- Source/cmAddCustomCommandCommand.cxx | 16 +++++++++++--- Source/cmAddCustomCommandCommand.h | 6 ++++- Source/cmAddCustomTargetCommand.cxx | 14 ++++++++++-- Source/cmAddCustomTargetCommand.h | 5 ++++- Source/cmCPluginAPI.cxx | 8 ++++--- Source/cmCustomCommand.cxx | 18 ++++++++++++--- Source/cmCustomCommand.h | 7 +++++- Source/cmFLTKWrapUICommand.cxx | 7 ++++-- Source/cmGlobalGenerator.cxx | 4 +++- Source/cmGlobalVisualStudio6Generator.cxx | 5 +++-- Source/cmGlobalVisualStudio7Generator.cxx | 3 +++ Source/cmGlobalVisualStudio8Generator.cxx | 5 ++++- Source/cmGlobalXCodeGenerator.cxx | 6 +++++ Source/cmIncludeExternalMSProjectCommand.cxx | 2 ++ Source/cmLocalGenerator.cxx | 8 +++++++ Source/cmLocalGenerator.h | 1 + Source/cmLocalUnixMakefileGenerator3.cxx | 10 +++++++-- Source/cmLocalVisualStudio6Generator.cxx | 14 +++++++++--- Source/cmLocalVisualStudio7Generator.cxx | 13 ++++++----- Source/cmMakefile.cxx | 23 +++++++++++--------- Source/cmMakefile.h | 6 +++-- Source/cmQTWrapCPPCommand.cxx | 4 +++- Source/cmQTWrapUICommand.cxx | 10 ++++++--- Source/cmVTKWrapJavaCommand.cxx | 4 +++- 26 files changed, 176 insertions(+), 48 deletions(-) diff --git a/Modules/CMakeFortranInformation.cmake b/Modules/CMakeFortranInformation.cmake index 19aa5f794..39def56a8 100644 --- a/Modules/CMakeFortranInformation.cmake +++ b/Modules/CMakeFortranInformation.cmake @@ -115,6 +115,17 @@ IF(NOT CMAKE_Fortran_LINK_EXECUTABLE) ENDIF(NOT CMAKE_Fortran_LINK_EXECUTABLE) +IF(NOT CMAKE_NOT_USING_CONFIG_FLAGS) + SET (CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG_INIT}" CACHE STRING + "Flags used by the compiler during debug builds.") + SET (CMAKE_Fortran_FLAGS_MINSIZEREL "${CMAKE_Fortran_FLAGS_MINSIZEREL_INIT}" CACHE STRING + "Flags used by the compiler during release minsize builds.") + SET (CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE_INIT}" CACHE STRING + "Flags used by the compiler during release builds (/MD /Ob1 /Oi /Ot /Oy /Gs will produce slightly less optimized but smaller files).") + SET (CMAKE_Fortran_FLAGS_RELWITHDEBINFO "${CMAKE_Fortran_FLAGS_RELWITHDEBINFO_INIT}" CACHE STRING + "Flags used by the compiler during Release with Debug Info builds.") + +ENDIF(NOT CMAKE_NOT_USING_CONFIG_FLAGS) MARK_AS_ADVANCED( CMAKE_Fortran_FLAGS diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index c7ef79c5a..2c242824b 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -365,7 +365,19 @@ IF(BUILD_TESTING) --build-exe-dir "${CMake_BINARY_DIR}/Tests/CustomCommand/bin" --test-command CustomCommand ) - +IF(FALSE) + ADD_TEST(CustomCommandWorkingDirectory ${CMAKE_CTEST_COMMAND} + --build-and-test + "${CMake_SOURCE_DIR}/Tests/CustomCommandWorkingDirectory" + "${CMake_BINARY_DIR}/Tests/CustomCommandWorkingDirectory" + --build-two-config + --build-generator ${CMAKE_TEST_GENERATOR} + --build-project TestWorkingDir + --build-makeprogram ${CMAKE_TEST_MAKEPROGRAM} + --build-exe-dir "${CMake_BINARY_DIR}/Tests/CustomCommandWorkingDirectory" + --test-command working + ) +ENDIF(FALSE) ADD_TEST(FindPackageTest ${CMAKE_CTEST_COMMAND} --build-and-test "${CMake_SOURCE_DIR}/Tests/FindPackageTest" diff --git a/Source/cmAddCustomCommandCommand.cxx b/Source/cmAddCustomCommandCommand.cxx index c0750a594..15df8eded 100644 --- a/Source/cmAddCustomCommandCommand.cxx +++ b/Source/cmAddCustomCommandCommand.cxx @@ -31,7 +31,8 @@ bool cmAddCustomCommandCommand::InitialPass(std::vector const& args return false; } - std::string source, target, comment, output, main_dependency; + std::string source, target, comment, output, main_dependency, + working; std::vector depends, outputs; // Accumulate one command line at a time. @@ -51,6 +52,7 @@ bool cmAddCustomCommandCommand::InitialPass(std::vector const& args doing_output, doing_outputs, doing_comment, + doing_working_directory, doing_nothing }; @@ -107,6 +109,10 @@ bool cmAddCustomCommandCommand::InitialPass(std::vector const& args { doing = doing_output; } + else if (copy == "WORKING_DIRECTORY") + { + doing = doing_working_directory; + } else if (copy == "MAIN_DEPENDENCY") { doing = doing_main_dependency; @@ -141,6 +147,9 @@ bool cmAddCustomCommandCommand::InitialPass(std::vector const& args switch (doing) { + case doing_working_directory: + working = copy; + break; case doing_source: source = copy; break; @@ -210,14 +219,15 @@ bool cmAddCustomCommandCommand::InitialPass(std::vector const& args std::vector no_depends; m_Makefile->AddCustomCommandToTarget(target.c_str(), no_depends, commandLines, cctype, - comment.c_str()); + comment.c_str(), working.c_str()); } else if(target.empty()) { // Target is empty, use the output. m_Makefile->AddCustomCommandToOutput(output.c_str(), depends, main_dependency.c_str(), - commandLines, comment.c_str()); + commandLines, comment.c_str(), + working.c_str()); } else { diff --git a/Source/cmAddCustomCommandCommand.h b/Source/cmAddCustomCommandCommand.h index 94c3959e5..96f85f651 100644 --- a/Source/cmAddCustomCommandCommand.h +++ b/Source/cmAddCustomCommandCommand.h @@ -71,6 +71,7 @@ public: " [COMMAND command2 [ARGS] [args2...] ...]\n" " [MAIN_DEPENDENCY depend]\n" " [DEPENDS [depends...]]\n" + " [WORKING_DIRECTORY dir]\n" " [COMMENT comment])\n" "This defines a new command that can be executed during the build " "process. Note that MAIN_DEPENDENCY is completely optional and is " @@ -89,6 +90,7 @@ public: " PRE_BUILD | PRE_LINK | POST_BUILD\n" " COMMAND command1 [ARGS] [args1...]\n" " [COMMAND command2 [ARGS] [args2...] ...]\n" + " [WORKING_DIRECTORY dir]\n" " [COMMENT comment])\n" "This defines a new command that will be associated with " "building the specified target. When the command will " @@ -98,7 +100,9 @@ public: " POST_BUILD - run after the target has been built\n" "Note that the PRE_BUILD option is only supported on Visual " "Studio 7 or later. For all other generators PRE_BUILD " - "will be treated as PRE_LINK."; + "will be treated as PRE_LINK." + "If WORKING_DIRECTORY is specified the command a cd \"dir\" is " + "done prior to running the command."; } cmTypeMacro(cmAddCustomCommandCommand, cmCommand); diff --git a/Source/cmAddCustomTargetCommand.cxx b/Source/cmAddCustomTargetCommand.cxx index 02ae1615d..f1f1a7775 100644 --- a/Source/cmAddCustomTargetCommand.cxx +++ b/Source/cmAddCustomTargetCommand.cxx @@ -33,11 +33,13 @@ bool cmAddCustomTargetCommand::InitialPass(std::vector const& args) // Accumulate dependencies. std::vector depends; + std::string working_directory; // Keep track of parser state. enum tdoing { doing_command, - doing_depends + doing_depends, + doing_working_directory }; tdoing doing = doing_command; @@ -62,6 +64,10 @@ bool cmAddCustomTargetCommand::InitialPass(std::vector const& args) { doing = doing_depends; } + if(copy == "WORKING_DIRECTORY") + { + doing = doing_working_directory; + } else if(copy == "COMMAND") { doing = doing_command; @@ -77,6 +83,9 @@ bool cmAddCustomTargetCommand::InitialPass(std::vector const& args) { switch (doing) { + case doing_working_directory: + working_directory = copy; + break; case doing_command: currentLine.push_back(copy); break; @@ -109,7 +118,8 @@ bool cmAddCustomTargetCommand::InitialPass(std::vector const& args) // Add the utility target to the makefile. const char* no_output = 0; - m_Makefile->AddUtilityCommand(args[0].c_str(), all, no_output, depends, + m_Makefile->AddUtilityCommand(args[0].c_str(), all, no_output, + working_directory.c_str(), depends, commandLines); return true; diff --git a/Source/cmAddCustomTargetCommand.h b/Source/cmAddCustomTargetCommand.h index 6772d58ee..7bc8c5d30 100644 --- a/Source/cmAddCustomTargetCommand.h +++ b/Source/cmAddCustomTargetCommand.h @@ -66,6 +66,7 @@ public: " ADD_CUSTOM_TARGET(Name [ALL] [command1 [args1...]]\n" " [COMMAND command2 [args2...] ...]\n" " [DEPENDS depend depend depend ... ])\n" + " [WORKING_DIRECTORY dir]\n" "Adds a target with the given name that executes the given commands " "every time the target is built. If the ALL option is specified " "it indicates that this target should be added to the default build " @@ -73,7 +74,9 @@ public: "The command and arguments are optional. If not specified, " "it will create an empty target. The ADD_DEPENDENCIES command can be " "used in conjunction with this command to drive custom target " - "generation. The command cannot be called ALL."; + "generation. The command cannot be called ALL. " + "If WORKING_DIRECTORY is set, then the command will be run in that " + "directory."; } cmTypeMacro(cmAddCustomTargetCommand, cmCommand); diff --git a/Source/cmCPluginAPI.cxx b/Source/cmCPluginAPI.cxx index ba3786460..63b379a57 100644 --- a/Source/cmCPluginAPI.cxx +++ b/Source/cmCPluginAPI.cxx @@ -240,7 +240,7 @@ void CCONV cmAddUtilityCommand(void *arg, const char* utilityName, // Pass the call to the makefile instance. mf->AddUtilityCommand(utilityName, (all ? true : false), - output, depends2, commandLines); + output, 0, depends2, commandLines); } void CCONV cmAddCustomCommand(void *arg, const char* source, const char* command, @@ -319,8 +319,9 @@ void CCONV cmAddCustomCommandToOutput(void *arg, const char* output, // Pass the call to the makefile instance. const char* no_comment = 0; + const char* no_working_dir = 0; mf->AddCustomCommandToOutput(output, depends2, main_dependency, - commandLines, no_comment); + commandLines, no_comment, no_working_dir); } void CCONV cmAddCustomCommandToTarget(void *arg, const char* target, @@ -362,8 +363,9 @@ void CCONV cmAddCustomCommandToTarget(void *arg, const char* target, // Pass the call to the makefile instance. std::vector no_depends; const char* no_comment = 0; + const char* no_working_dir = 0; mf->AddCustomCommandToTarget(target, no_depends, commandLines, - cctype, no_comment); + cctype, no_comment, no_working_dir); } void CCONV cmAddLinkLibraryForTarget(void *arg, const char *tgt, const char*value, diff --git a/Source/cmCustomCommand.cxx b/Source/cmCustomCommand.cxx index 8d794f7f5..ca52460ab 100644 --- a/Source/cmCustomCommand.cxx +++ b/Source/cmCustomCommand.cxx @@ -27,7 +27,8 @@ cmCustomCommand::cmCustomCommand(const cmCustomCommand& r): m_Output(r.m_Output), m_Depends(r.m_Depends), m_CommandLines(r.m_CommandLines), - m_Comment(r.m_Comment) + m_Comment(r.m_Comment), + m_WorkingDirectory(r.m_WorkingDirectory) { m_Used = false; } @@ -36,11 +37,12 @@ cmCustomCommand::cmCustomCommand(const cmCustomCommand& r): cmCustomCommand::cmCustomCommand(const char* output, const std::vector& depends, const cmCustomCommandLines& commandLines, - const char* comment): + const char* comment, const char* workingDirectory): m_Output(output?output:""), m_Depends(depends), m_CommandLines(commandLines), - m_Comment(comment?comment:"") + m_Comment(comment?comment:""), + m_WorkingDirectory(workingDirectory?workingDirectory:"") { m_Used = false; } @@ -51,6 +53,16 @@ const char* cmCustomCommand::GetOutput() const return m_Output.c_str(); } +//---------------------------------------------------------------------------- +const char* cmCustomCommand::GetWorkingDirectory() const +{ + if(m_WorkingDirectory.size() == 0) + { + return 0; + } + return m_WorkingDirectory.c_str(); +} + //---------------------------------------------------------------------------- const std::vector& cmCustomCommand::GetDepends() const { diff --git a/Source/cmCustomCommand.h b/Source/cmCustomCommand.h index 966cab3ec..e48d53179 100644 --- a/Source/cmCustomCommand.h +++ b/Source/cmCustomCommand.h @@ -35,11 +35,15 @@ public: cmCustomCommand(const char* output, const std::vector& depends, const cmCustomCommandLines& commandLines, - const char* comment); + const char* comment, + const char* workingDirectory); /** Get the output file produced by the command. */ const char* GetOutput() const; + /** Get the working directory. */ + const char* GetWorkingDirectory() const; + /** Get the vector that holds the list of dependencies. */ const std::vector& GetDepends() const; @@ -58,6 +62,7 @@ private: std::vector m_Depends; cmCustomCommandLines m_CommandLines; std::string m_Comment; + std::string m_WorkingDirectory; bool m_Used; }; diff --git a/Source/cmFLTKWrapUICommand.cxx b/Source/cmFLTKWrapUICommand.cxx index 8a543235d..ed8f70f53 100644 --- a/Source/cmFLTKWrapUICommand.cxx +++ b/Source/cmFLTKWrapUICommand.cxx @@ -81,12 +81,15 @@ bool cmFLTKWrapUICommand::InitialPass(std::vector const& args) // Add command for generating the .h and .cxx files const char* no_main_dependency = 0; const char* no_comment = 0; + const char* no_working_dir = 0; m_Makefile->AddCustomCommandToOutput(cxxres.c_str(), depends, no_main_dependency, - commandLines, no_comment); + commandLines, no_comment, + no_working_dir); m_Makefile->AddCustomCommandToOutput(hname.c_str(), depends, no_main_dependency, - commandLines, no_comment); + commandLines, no_comment, + no_working_dir); cmSourceFile *sf = m_Makefile->GetSource(cxxres.c_str()); sf->GetDepends().push_back(hname); diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 0f965eba3..c3145c6c4 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1164,6 +1164,7 @@ void cmGlobalGenerator::SetupTests() if (total_tests > 0) { const char* no_output = 0; + const char* no_working_dir = 0; std::vector no_depends; std::map >::iterator it; for(it = m_ProjectMap.begin(); it!= m_ProjectMap.end(); ++it) @@ -1176,7 +1177,8 @@ void cmGlobalGenerator::SetupTests() if(const char* outDir = mf->GetDefinition("CMAKE_CFG_INTDIR")) { mf->AddUtilityCommand("RUN_TESTS", false, no_output, no_depends, - ctest.c_str(), "-C", outDir); + no_working_dir, + ctest.c_str(), "-C", outDir); } } } diff --git a/Source/cmGlobalVisualStudio6Generator.cxx b/Source/cmGlobalVisualStudio6Generator.cxx index 5781bff71..e9731e09c 100644 --- a/Source/cmGlobalVisualStudio6Generator.cxx +++ b/Source/cmGlobalVisualStudio6Generator.cxx @@ -158,6 +158,7 @@ void cmGlobalVisualStudio6Generator::Generate() // of one configuration only. const char* no_output = 0; std::vector no_depends; + const char* no_working_dir = 0; std::map >::iterator it; for(it = m_ProjectMap.begin(); it!= m_ProjectMap.end(); ++it) { @@ -166,12 +167,12 @@ void cmGlobalVisualStudio6Generator::Generate() if(gen.size()) { gen[0]->GetMakefile()-> - AddUtilityCommand("ALL_BUILD", false, no_output, no_depends, + AddUtilityCommand("ALL_BUILD", false, no_output, no_depends, no_working_dir, "echo", "Build all projects"); std::string cmake_command = m_LocalGenerators[0]->GetMakefile()->GetRequiredDefinition("CMAKE_COMMAND"); gen[0]->GetMakefile()-> - AddUtilityCommand("INSTALL", false, no_output, no_depends, + AddUtilityCommand("INSTALL", false, no_output, no_depends, no_working_dir, cmake_command.c_str(), "-DBUILD_TYPE=$(IntDir)", "-P", "cmake_install.cmake"); diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx index 5e3eb3b4e..fb96d365f 100644 --- a/Source/cmGlobalVisualStudio7Generator.cxx +++ b/Source/cmGlobalVisualStudio7Generator.cxx @@ -190,6 +190,7 @@ void cmGlobalVisualStudio7Generator::Generate() // add a special target that depends on ALL projects for easy build // of one configuration only. const char* no_output = 0; + const char* no_working_dir = 0; std::vector no_depends; std::map >::iterator it; for(it = m_ProjectMap.begin(); it!= m_ProjectMap.end(); ++it) @@ -200,11 +201,13 @@ void cmGlobalVisualStudio7Generator::Generate() { gen[0]->GetMakefile()-> AddUtilityCommand("ALL_BUILD", false, no_output, no_depends, + no_working_dir, "echo", "Build all projects"); std::string cmake_command = m_LocalGenerators[0]->GetMakefile()->GetRequiredDefinition("CMAKE_COMMAND"); gen[0]->GetMakefile()-> AddUtilityCommand("INSTALL", false, no_output, no_depends, + no_working_dir, cmake_command.c_str(), "-DBUILD_TYPE=$(OutDir)", "-P", "cmake_install.cmake"); diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx index e4948a327..c13efd0ba 100644 --- a/Source/cmGlobalVisualStudio8Generator.cxx +++ b/Source/cmGlobalVisualStudio8Generator.cxx @@ -67,6 +67,7 @@ void cmGlobalVisualStudio8Generator::Generate() // Add a special target on which all other targets depend that // checks the build system and optionally re-runs CMake. const char* no_output = 0; + const char* no_working_directory = 0; std::vector no_depends; std::map >::iterator it; for(it = m_ProjectMap.begin(); it!= m_ProjectMap.end(); ++it) @@ -82,6 +83,7 @@ void cmGlobalVisualStudio8Generator::Generate() std::string cmake_command = mf->GetRequiredDefinition("CMAKE_COMMAND"); mf->AddUtilityCommand(CMAKE_CHECK_BUILD_SYSTEM_TARGET, true, no_output, no_depends, + no_working_directory, "echo", "Checking build system"); // Add a custom rule to re-run CMake if any input files changed. @@ -127,9 +129,10 @@ void cmGlobalVisualStudio8Generator::Generate() // target. const char* no_comment = 0; const char* no_main_dependency = 0; + const char* no_working_directory = 0; mf->AddCustomCommandToOutput( CMAKE_CHECK_BUILD_SYSTEM_TARGET ".vcproj.cmake", listFiles, - no_main_dependency, commandLines, no_comment, true); + no_main_dependency, commandLines, no_comment, no_working_directory, true); } } } diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 51c568708..7e2a82821 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -279,8 +279,10 @@ cmGlobalXCodeGenerator::AddExtraTargets(cmLocalGenerator* root, cmMakefile* mf = root->GetMakefile(); // Add ALL_BUILD const char* no_output = 0; + const char* no_working_directory = 0; std::vector no_depends; mf->AddUtilityCommand("ALL_BUILD", false, no_output, no_depends, + no_working_directory, "echo", "Build all projects"); cmTarget* allbuild = mf->FindTarget("ALL_BUILD"); // ADD install @@ -288,12 +290,14 @@ cmGlobalXCodeGenerator::AddExtraTargets(cmLocalGenerator* root, if(m_XcodeVersion == 15) { mf->AddUtilityCommand("install", false, no_output, no_depends, + no_working_directory, cmake_command.c_str(), "-P", "cmake_install.cmake"); } else { mf->AddUtilityCommand("install", false, no_output, no_depends, + no_working_directory, cmake_command.c_str(), "-DBUILD_TYPE=$(CONFIGURATION)", "-P", "cmake_install.cmake"); @@ -317,6 +321,7 @@ cmGlobalXCodeGenerator::AddExtraTargets(cmLocalGenerator* root, std::string ctest_command = mf->GetRequiredDefinition("CMAKE_CTEST_COMMAND"); mf->AddUtilityCommand("RUN_TESTS", false, no_output, no_depends, + no_working_directory, ctest_command.c_str()); } // Add XCODE depend helper @@ -338,6 +343,7 @@ cmGlobalXCodeGenerator::AddExtraTargets(cmLocalGenerator* root, cmCustomCommandLines commandLines; commandLines.push_back(makecommand); mf->AddUtilityCommand("XCODE_DEPEND_HELPER", false, no_output, no_depends, + no_working_directory, commandLines); // Add Re-Run CMake rules diff --git a/Source/cmIncludeExternalMSProjectCommand.cxx b/Source/cmIncludeExternalMSProjectCommand.cxx index ad3f94c6f..f3dc6ae07 100644 --- a/Source/cmIncludeExternalMSProjectCommand.cxx +++ b/Source/cmIncludeExternalMSProjectCommand.cxx @@ -44,8 +44,10 @@ bool cmIncludeExternalMSProjectCommand::InitialPass(std::vector con utility_name += args[0]; const char* no_output = 0; + const char* no_working_directory = 0; m_Makefile->AddUtilityCommand(utility_name.c_str(), true, no_output, depends, + no_working_directory, args[0].c_str(), args[1].c_str()); } diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index bd64dc93b..5fd0477f7 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1749,10 +1749,18 @@ void cmLocalGenerator::AppendFlags(std::string& flags, //---------------------------------------------------------------------------- std::string cmLocalGenerator::ConstructScript(const cmCustomCommandLines& commandLines, + const char* workingDirectory, const char* newline) + { // Store the script in a string. std::string script; + if(workingDirectory) + { + script += "cd "; + script += this->Convert(workingDirectory, START_OUTPUT, SHELL); + script += newline; + } // Write each command on a single line. for(cmCustomCommandLines::const_iterator cl = commandLines.begin(); diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index f60ad22e6..f9dd4681c 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -165,6 +165,7 @@ public: protected: /** Construct a script from the given list of command lines. */ std::string ConstructScript(const cmCustomCommandLines& commandLines, + const char* workingDirectory, const char* newline = "\n"); ///! Fill out these strings for the given target. Libraries to link, flags, and linkflags. diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index b66e40714..ebf806022 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -2405,13 +2405,19 @@ cmLocalUnixMakefileGenerator3 cmSystemTools::SetForceUnixPaths(true); } } - commands1.push_back(cmd); } } // push back the custom commands - this->CreateCDCommand(commands1,m_Makefile->GetStartOutputDirectory(), + const char* dir =m_Makefile->GetStartOutputDirectory(); + // if the command specified a working directory use it. + if(cc.GetWorkingDirectory()) + { + dir = cc.GetWorkingDirectory(); + } + + this->CreateCDCommand(commands1, dir, m_Makefile->GetHomeOutputDirectory()); commands.insert(commands.end(), commands1.begin(), commands1.end()); } diff --git a/Source/cmLocalVisualStudio6Generator.cxx b/Source/cmLocalVisualStudio6Generator.cxx index 54f83243e..6f4551d1d 100644 --- a/Source/cmLocalVisualStudio6Generator.cxx +++ b/Source/cmLocalVisualStudio6Generator.cxx @@ -252,8 +252,9 @@ void cmLocalVisualStudio6Generator::AddDSPBuildRule() cmCustomCommandLines commandLines; commandLines.push_back(commandLine); const char* no_comment = 0; + const char* no_working_directory = 0; m_Makefile->AddCustomCommandToOutput(dspname.c_str(), listFiles, makefileIn.c_str(), - commandLines, no_comment, true); + commandLines, no_comment, no_working_directory, true); } @@ -448,7 +449,9 @@ void cmLocalVisualStudio6Generator::WriteGroup(const cmSourceGroup *sg, cmTarget if (command) { std::string script = - this->ConstructScript(command->GetCommandLines(), "\\\n\t"); + this->ConstructScript(command->GetCommandLines(), + command->GetWorkingDirectory(), + "\\\n\t"); const char* comment = command->GetComment(); const char* flags = compileFlags.size() ? compileFlags.c_str(): 0; this->WriteCustomRule(fout, source.c_str(), script.c_str(), @@ -511,11 +514,13 @@ cmLocalVisualStudio6Generator // Add the rule with the given dependencies and commands. const char* no_main_dependency = 0; const char* no_comment = 0; + const char* no_working_directory = 0; m_Makefile->AddCustomCommandToOutput(output, depends, no_main_dependency, commandLines, - no_comment); + no_comment, + no_working_directory); // Replace the dependencies with the output of this rule so that the // next rule added will run after this one. @@ -724,6 +729,7 @@ cmLocalVisualStudio6Generator::CreateTargetRules(cmTarget &target, prelink_newline = ""; } customRuleCode += this->ConstructScript(cr->GetCommandLines(), + cr->GetWorkingDirectory(), prelink_newline); } for (std::vector::const_iterator cr = @@ -735,6 +741,7 @@ cmLocalVisualStudio6Generator::CreateTargetRules(cmTarget &target, prelink_newline = ""; } customRuleCode += this->ConstructScript(cr->GetCommandLines(), + cr->GetWorkingDirectory(), prelink_newline); } if(prelink_total > 0) @@ -760,6 +767,7 @@ cmLocalVisualStudio6Generator::CreateTargetRules(cmTarget &target, postbuild_newline = ""; } customRuleCode += this->ConstructScript(cr->GetCommandLines(), + cr->GetWorkingDirectory(), postbuild_newline); } if(postbuild_total > 0) diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 01eecde7b..4b03bbd42 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -254,9 +254,10 @@ void cmLocalVisualStudio7Generator::AddVCProjBuildRule() cmCustomCommandLines commandLines; commandLines.push_back(commandLine); + const char* no_working_directory = 0; const char* no_comment = 0; m_Makefile->AddCustomCommandToOutput(dspname.c_str(), listFiles, makefileIn.c_str(), - commandLines, no_comment, true); + commandLines, no_comment, no_working_directory, true); } @@ -1096,7 +1097,8 @@ void cmLocalVisualStudio7Generator::WriteGroup(const cmSourceGroup *sg, cmTarget if (command) { // Construct the entire set of commands in one string. - std::string script = this->ConstructScript(command->GetCommandLines()); + std::string script = this->ConstructScript(command->GetCommandLines(), + command->GetWorkingDirectory()); const char* comment = command->GetComment(); const char* flags = compileFlags.size() ? compileFlags.c_str(): 0; this->WriteCustomRule(fout, source.c_str(), script.c_str(), @@ -1254,7 +1256,7 @@ void cmLocalVisualStudio7Generator::OutputTargetRules(std::ostream& fout, fout << "\nCommandLine=\""; init = true; } - std::string script = this->ConstructScript(cr->GetCommandLines()); + std::string script = this->ConstructScript(cr->GetCommandLines(), cr->GetWorkingDirectory()); fout << this->EscapeForXML(script.c_str()).c_str(); } if (init) @@ -1275,7 +1277,8 @@ void cmLocalVisualStudio7Generator::OutputTargetRules(std::ostream& fout, fout << "\nCommandLine=\""; init = true; } - std::string script = this->ConstructScript(cr->GetCommandLines()); + std::string script = this->ConstructScript(cr->GetCommandLines(), + cr->GetWorkingDirectory()); fout << this->EscapeForXML(script.c_str()).c_str(); } if (init) @@ -1296,7 +1299,7 @@ void cmLocalVisualStudio7Generator::OutputTargetRules(std::ostream& fout, fout << "\nCommandLine=\""; init = true; } - std::string script = this->ConstructScript(cr->GetCommandLines()); + std::string script = this->ConstructScript(cr->GetCommandLines(), cr->GetWorkingDirectory()); fout << this->EscapeForXML(script.c_str()).c_str(); } if (init) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 772d6e61d..4eae62286 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -469,7 +469,8 @@ cmMakefile::AddCustomCommandToTarget(const char* target, const std::vector& depends, const cmCustomCommandLines& commandLines, cmTarget::CustomCommandType type, - const char* comment) + const char* comment, + const char* workingDir) { // Find the target to which to add the custom command. cmTargets::iterator ti = m_Targets.find(target); @@ -477,7 +478,7 @@ cmMakefile::AddCustomCommandToTarget(const char* target, { // Add the command to the appropriate build step for the target. const char* no_output = 0; - cmCustomCommand cc(no_output, depends, commandLines, comment); + cmCustomCommand cc(no_output, depends, commandLines, comment, workingDir); switch(type) { case cmTarget::PRE_BUILD: @@ -512,6 +513,7 @@ cmMakefile::AddCustomCommandToOutput(const char* output, const char* main_dependency, const cmCustomCommandLines& commandLines, const char* comment, + const char* workingDir, bool replace) { // Choose a source file on which to store the custom command. @@ -586,7 +588,7 @@ cmMakefile::AddCustomCommandToOutput(const char* output, if(file) { cmCustomCommand* cc = - new cmCustomCommand(output, depends2, commandLines, comment); + new cmCustomCommand(output, depends2, commandLines, comment, workingDir); file->SetCustomCommand(cc); } } @@ -608,7 +610,7 @@ cmMakefile::AddCustomCommandOldStyle(const char* target, // same then it added a post-build rule to the target. Preserve // this behavior. this->AddCustomCommandToTarget(target, depends, commandLines, - cmTarget::POST_BUILD, comment); + cmTarget::POST_BUILD, comment, 0); return; } @@ -627,7 +629,7 @@ cmMakefile::AddCustomCommandOldStyle(const char* target, { // The source looks like a real file. Use it as the main dependency. this->AddCustomCommandToOutput(output, depends, source, - commandLines, comment); + commandLines, comment, 0); } else { @@ -636,7 +638,7 @@ cmMakefile::AddCustomCommandOldStyle(const char* target, std::vector depends2 = depends; depends2.push_back(source); this->AddCustomCommandToOutput(output, depends2, no_main_dependency, - commandLines, comment); + commandLines, comment, 0); } // If the rule was added to the source (and not a .rule file), @@ -664,6 +666,7 @@ cmMakefile::AddCustomCommandOldStyle(const char* target, void cmMakefile::AddUtilityCommand(const char* utilityName, bool all, const char* output, const std::vector& depends, + const char* workingDirectory, const char* command, const char* arg1, const char* arg2, @@ -693,12 +696,14 @@ void cmMakefile::AddUtilityCommand(const char* utilityName, bool all, commandLines.push_back(commandLine); // Call the real signature of this method. - this->AddUtilityCommand(utilityName, all, output, depends, commandLines); + this->AddUtilityCommand(utilityName, all, output, workingDirectory, + depends, commandLines); } //---------------------------------------------------------------------------- void cmMakefile::AddUtilityCommand(const char* utilityName, bool all, const char* output, + const char* workingDirectory, const std::vector& depends, const cmCustomCommandLines& commandLines) { @@ -707,9 +712,8 @@ void cmMakefile::AddUtilityCommand(const char* utilityName, bool all, target.SetType(cmTarget::UTILITY, utilityName); target.SetInAll(all); target.SetMakefile(this); - // Store the custom command in the target. - cmCustomCommand cc(output, depends, commandLines, 0); + cmCustomCommand cc(output, depends, commandLines, 0, workingDirectory); target.GetPostBuildCommands().push_back(cc); // Add the target to the set of targets. @@ -1442,7 +1446,6 @@ const char *cmMakefile::ExpandVariablesInString(std::string& source, { cmSystemTools::Message(error.str().c_str()); } - //std::cerr << "[" << source.c_str() << "] results in: [" << parser.GetResult() << "]" << std::endl; } } diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 3f289c10f..f6418ba87 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -138,12 +138,12 @@ public: const std::vector& depends, const cmCustomCommandLines& commandLines, cmTarget::CustomCommandType type, - const char* comment); + const char* comment, const char* workingDir); void AddCustomCommandToOutput(const char* output, const std::vector& depends, const char* main_dependency, const cmCustomCommandLines& commandLines, - const char* comment, + const char* comment, const char* workingDir, bool replace = false); void AddCustomCommandOldStyle(const char* target, const std::vector& outputs, @@ -171,6 +171,7 @@ public: void AddUtilityCommand(const char* utilityName, bool all, const char* output, const std::vector& depends, + const char* workingDirectory, const char* command, const char* arg1=0, const char* arg2=0, @@ -178,6 +179,7 @@ public: const char* arg4=0); void AddUtilityCommand(const char* utilityName, bool all, const char* output, + const char* workingDirectory, const std::vector& depends, const cmCustomCommandLines& commandLines); diff --git a/Source/cmQTWrapCPPCommand.cxx b/Source/cmQTWrapCPPCommand.cxx index 39eb3621e..4a3fd8a4d 100644 --- a/Source/cmQTWrapCPPCommand.cxx +++ b/Source/cmQTWrapCPPCommand.cxx @@ -127,10 +127,12 @@ void cmQTWrapCPPCommand::FinalPass() realdepends.push_back(m_WrapHeaders[classNum]); const char* no_main_dependency = 0; + const char* no_working_dir = 0; m_Makefile->AddCustomCommandToOutput(res.c_str(), realdepends, no_main_dependency, commandLines, - "QT Wrapped File"); + "QT Wrapped File", + no_working_dir); } } diff --git a/Source/cmQTWrapUICommand.cxx b/Source/cmQTWrapUICommand.cxx index ef57c0168..cb15cfd8c 100644 --- a/Source/cmQTWrapUICommand.cxx +++ b/Source/cmQTWrapUICommand.cxx @@ -179,11 +179,13 @@ void cmQTWrapUICommand::FinalPass() depends.push_back(m_WrapUserInterface[classNum]); const char* no_main_dependency = 0; const char* no_comment = 0; + const char* no_working_dir = 0; m_Makefile->AddCustomCommandToOutput(hres.c_str(), depends, no_main_dependency, hCommandLines, - no_comment); + no_comment, + no_working_dir); depends.push_back(hres); @@ -191,7 +193,8 @@ void cmQTWrapUICommand::FinalPass() depends, no_main_dependency, cxxCommandLines, - no_comment); + no_comment, + no_working_dir); depends.clear(); depends.push_back(hres); @@ -200,6 +203,7 @@ void cmQTWrapUICommand::FinalPass() depends, no_main_dependency, mocCommandLines, - no_comment); + no_comment, + no_working_dir); } } diff --git a/Source/cmVTKWrapJavaCommand.cxx b/Source/cmVTKWrapJavaCommand.cxx index 67e6bba07..9fe0d3bda 100644 --- a/Source/cmVTKWrapJavaCommand.cxx +++ b/Source/cmVTKWrapJavaCommand.cxx @@ -182,6 +182,8 @@ void cmVTKWrapJavaCommand::FinalPass() } const char* no_output = 0; + const char* no_working_directory = 0; m_Makefile->AddUtilityCommand((m_LibraryName+"JavaClasses").c_str(), - true, no_output, alldepends, ""); + true, no_output, + alldepends, "", no_working_directory); }