From 4cb9d2fd96cd39c17d194c62bff47a6ba45097db Mon Sep 17 00:00:00 2001 From: Ken Martin Date: Mon, 12 Sep 2005 13:46:16 -0400 Subject: ENH: better format for ADD_SUBDIRECTORY command --- Source/cmAddSubDirectoryCommand.cxx | 64 +++++++++++++++++++++++++++---------- Source/cmAddSubDirectoryCommand.h | 15 +++++---- 2 files changed, 55 insertions(+), 24 deletions(-) diff --git a/Source/cmAddSubDirectoryCommand.cxx b/Source/cmAddSubDirectoryCommand.cxx index 440f19d..9e56c12 100644 --- a/Source/cmAddSubDirectoryCommand.cxx +++ b/Source/cmAddSubDirectoryCommand.cxx @@ -26,8 +26,8 @@ bool cmAddSubDirectoryCommand::InitialPass(std::vector const& args) } // store the binpath - std::string binArg = args[0]; - std::string srcArg; + std::string srcArg = args[0]; + std::string binArg; bool intoplevel = true; @@ -41,9 +41,9 @@ bool cmAddSubDirectoryCommand::InitialPass(std::vector const& args) intoplevel = false; continue; } - else if (!srcArg.size()) + else if (!binArg.size()) { - srcArg = *i; + binArg = *i; } else { @@ -52,19 +52,15 @@ bool cmAddSubDirectoryCommand::InitialPass(std::vector const& args) } } - // if srcArg not provided use binArg - if (!srcArg.size()) - { - srcArg = binArg; - } - - // now we have all the arguments - - // if they specified a relative path then compute the full + // check for relative arguments + bool relativeSource = true; + std::string binPath = binArg; std::string srcPath = std::string(m_Makefile->GetCurrentDirectory()) + "/" + srcArg; + // if the path does not exist then the arg was relative if (!cmSystemTools::FileIsDirectory(srcPath.c_str())) { + relativeSource = false; srcPath = srcArg; if (!cmSystemTools::FileIsDirectory(srcPath.c_str())) { @@ -75,13 +71,47 @@ bool cmAddSubDirectoryCommand::InitialPass(std::vector const& args) } } - std::string binPath = binArg; - if (!cmSystemTools::FileIsFullPath(binPath.c_str())) + // at this point srcPath has the full path to the source directory + // now we need to compute the binPath if it was not provided + + // if the argument was provided then use it + if (binArg.size()) { - binPath = std::string(m_Makefile->GetCurrentOutputDirectory()) + - "/" + binArg.c_str(); + if (!cmSystemTools::FileIsFullPath(binPath.c_str())) + { + binPath = std::string(m_Makefile->GetCurrentOutputDirectory()) + + "/" + binArg.c_str(); + } + } + // otherwise compute the binPath from the srcPath + else + { + // if the srcArg was relative then we just do the same for the binPath + if (relativeSource) + { + binPath = std::string(m_Makefile->GetCurrentOutputDirectory()) + + "/" + srcArg; + } + // otherwise we try to remove the CurrentDirectory from the srcPath and + // replace it with the CurrentOutputDirectory. This may not really work + // because the source dir they provided may not be "in" the source + // tree. This is an error if this happens. + else + { + // try replacing the home dir with the home output dir + binPath = srcPath; + if (!cmSystemTools::FindLastString(binPath.c_str(), + m_Makefile->GetHomeDirectory())) + { + this->SetError("A full source directory was specified that is not in the source tree but no binary directory was specified. If you specify an out of tree source directory then you must provide the binary directory as well."); + return false; + } + cmSystemTools::ReplaceString(binPath,m_Makefile->GetHomeDirectory(), + m_Makefile->GetHomeOutputDirectory()); + } } + // now we have all the arguments m_Makefile->AddSubDirectory(srcPath.c_str(), binPath.c_str(), intoplevel, false, true); diff --git a/Source/cmAddSubDirectoryCommand.h b/Source/cmAddSubDirectoryCommand.h index c54659c..a5c4fe9 100644 --- a/Source/cmAddSubDirectoryCommand.h +++ b/Source/cmAddSubDirectoryCommand.h @@ -62,16 +62,17 @@ public: virtual const char* GetFullDocumentation() { return - " ADD_SUBDIRECTORY(binary_dir [source_dir]\n" + " ADD_SUBDIRECTORY(source_dir [binary_dir] \n" " [EXCLUDE_FROM_ALL])\n" - "Add a subdirectory to the build. The binary_dir specifies the " - "directory in which to store the build files. If it is a relative " - "path it will be evaluated with respect to the current output " + "Add a subdirectory to the build. The source_dir specifies the " + "directory in which the source CmakeLists.txt and code files are " + "located. If it is a relative " + "path it will be evaluated with respect to the current " "directory (the typical usage), but it may also be an absolute path. " - "The source_dir specifies the directory in which to find the source " + "The binary_dir specifies the directory in which to place the output " "files. If it is a relative path it will be evaluated with respect " - "to the current source directory, but it may also be an absolute " - "path. If source_dir is not specified the value of binary_dir, " + "to the current otuput directory, but it may also be an absolute " + "path. If binary_dir is not specified, the value of source_dir, " "before expanding any relative path, will be used (the typical usage). " "The CMakeLists.txt file in the specified source directory will " "be processed immediately by CMake before processing in the current " -- cgit v0.12