ENH: add SUBDIR PREORDER and fix clean for non-relative paths
This commit is contained in:
parent
eae3d4cf06
commit
8b0b749a11
@ -228,6 +228,16 @@ IF(BUILD_TESTING)
|
|||||||
--build-two-config
|
--build-two-config
|
||||||
--test-command simple)
|
--test-command simple)
|
||||||
|
|
||||||
|
ADD_TEST(PreOrder ${CMAKE_CTEST_COMMAND}
|
||||||
|
--build-and-test
|
||||||
|
"${CMake_SOURCE_DIR}/Tests/PreOrder"
|
||||||
|
"${CMake_BINARY_DIR}/Tests/PreOrder"
|
||||||
|
--build-generator ${CMAKE_GENERATOR}
|
||||||
|
--build-project PreOrder
|
||||||
|
--build-makeprogram ${MAKEPROGRAM}
|
||||||
|
--build-two-config
|
||||||
|
--test-command simple)
|
||||||
|
|
||||||
ADD_TEST(conly ${CMAKE_CTEST_COMMAND}
|
ADD_TEST(conly ${CMAKE_CTEST_COMMAND}
|
||||||
--build-and-test
|
--build-and-test
|
||||||
"${CMake_SOURCE_DIR}/Tests/COnly"
|
"${CMake_SOURCE_DIR}/Tests/COnly"
|
||||||
|
@ -1781,13 +1781,20 @@ void cmLocalUnixMakefileGenerator::OutputBuildTargetInDirWindows(std::ostream& f
|
|||||||
const char* library,
|
const char* library,
|
||||||
const char* fullpath)
|
const char* fullpath)
|
||||||
{
|
{
|
||||||
std::string jumpBack =
|
std::string jumpBack;
|
||||||
cmSystemTools::RelativePath(cmSystemTools::GetProgramPath(path).c_str(),
|
if(m_UseRelativePaths)
|
||||||
m_Makefile->GetCurrentOutputDirectory());
|
{
|
||||||
|
cmSystemTools::Message("using relative paths??");
|
||||||
|
jumpBack = cmSystemTools::RelativePath(cmSystemTools::GetProgramPath(path).c_str(),
|
||||||
|
m_Makefile->GetCurrentOutputDirectory());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
jumpBack = m_Makefile->GetCurrentOutputDirectory();
|
||||||
|
}
|
||||||
jumpBack = this->ConvertToOutputForExisting(jumpBack.c_str());
|
jumpBack = this->ConvertToOutputForExisting(jumpBack.c_str());
|
||||||
std::string wpath = this->ConvertToOutputForExisting(path);
|
std::string wpath = this->ConvertToOutputForExisting(path);
|
||||||
std::string wfullpath = this->ConvertToOutputForExisting(fullpath);
|
std::string wfullpath = this->ConvertToOutputForExisting(fullpath);
|
||||||
|
|
||||||
fout << wfullpath
|
fout << wfullpath
|
||||||
<< ":\n\tcd " << wpath << "\n"
|
<< ":\n\tcd " << wpath << "\n"
|
||||||
<< "\t$(MAKE) -$(MAKEFLAGS) $(MAKESILENT) cmake.depends\n"
|
<< "\t$(MAKE) -$(MAKEFLAGS) $(MAKESILENT) cmake.depends\n"
|
||||||
@ -2008,23 +2015,32 @@ BuildInSubDirectoryWindows(std::ostream& fout,
|
|||||||
}
|
}
|
||||||
fout << "\t$(MAKE) -$(MAKEFLAGS) $(MAKESILENT) " << target2 << "\n";
|
fout << "\t$(MAKE) -$(MAKEFLAGS) $(MAKESILENT) " << target2 << "\n";
|
||||||
}
|
}
|
||||||
std::string currentDir = dir;
|
std::string currentDir;
|
||||||
cmSystemTools::ConvertToUnixSlashes(currentDir);
|
if(m_UseRelativePaths)
|
||||||
std::string cdback = "..";
|
|
||||||
unsigned int i = 0;
|
|
||||||
if(currentDir.size() > 2 && currentDir[0] == '.' && currentDir[1] == '/')
|
|
||||||
{
|
{
|
||||||
// start past ./ if it starts with ./
|
currentDir = dir;
|
||||||
i = 2;
|
cmSystemTools::ConvertToUnixSlashes(currentDir);
|
||||||
}
|
std::string cdback = "..";
|
||||||
for(; i < currentDir.size(); ++i)
|
unsigned int i = 0;
|
||||||
{
|
if(currentDir.size() > 2 && currentDir[0] == '.' && currentDir[1] == '/')
|
||||||
if(currentDir[i] == '/')
|
|
||||||
{
|
{
|
||||||
cdback += "/..";
|
// start past ./ if it starts with ./
|
||||||
|
i = 2;
|
||||||
}
|
}
|
||||||
|
for(; i < currentDir.size(); ++i)
|
||||||
|
{
|
||||||
|
if(currentDir[i] == '/')
|
||||||
|
{
|
||||||
|
cdback += "/..";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fout << "\tcd " << this->ConvertToOutputForExisting(cdback.c_str()) << "\n\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
currentDir = m_Makefile->GetCurrentOutputDirectory();
|
||||||
|
fout << "\tcd " << this->ConvertToOutputForExisting(currentDir.c_str()) << "\n\n";
|
||||||
}
|
}
|
||||||
fout << "\tcd " << this->ConvertToOutputForExisting(cdback.c_str()) << "\n\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2074,7 +2090,7 @@ OutputSubDirectoryVars(std::ostream& fout,
|
|||||||
const char* target2,
|
const char* target2,
|
||||||
const char* depend,
|
const char* depend,
|
||||||
const std::vector<std::pair<cmStdString, bool> >& SubDirectories,
|
const std::vector<std::pair<cmStdString, bool> >& SubDirectories,
|
||||||
bool silent)
|
bool silent, int order)
|
||||||
{
|
{
|
||||||
if(!depend)
|
if(!depend)
|
||||||
{
|
{
|
||||||
@ -2087,27 +2103,68 @@ OutputSubDirectoryVars(std::ostream& fout,
|
|||||||
fout << "# Variable for making " << target << " in subdirectories.\n";
|
fout << "# Variable for making " << target << " in subdirectories.\n";
|
||||||
fout << var << " = ";
|
fout << var << " = ";
|
||||||
unsigned int ii;
|
unsigned int ii;
|
||||||
|
|
||||||
|
// make sure all the pre-order subdirectories are fist
|
||||||
|
// other than that keep the same order that the user specified
|
||||||
|
std::vector<std::pair<cmStdString, bool> > orderedDirs;
|
||||||
|
// collect pre-order first
|
||||||
for(ii =0; ii < SubDirectories.size(); ii++)
|
for(ii =0; ii < SubDirectories.size(); ii++)
|
||||||
|
{
|
||||||
|
if(m_Makefile->IsDirectoryPreOrder(SubDirectories[ii].first.c_str()))
|
||||||
|
{
|
||||||
|
orderedDirs.push_back(SubDirectories[ii]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// now collect post order dirs
|
||||||
|
for(ii =0; ii < SubDirectories.size(); ii++)
|
||||||
|
{
|
||||||
|
if(!m_Makefile->IsDirectoryPreOrder(SubDirectories[ii].first.c_str()))
|
||||||
|
{
|
||||||
|
orderedDirs.push_back(SubDirectories[ii]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(ii =0; ii < orderedDirs.size(); ii++)
|
||||||
{
|
{
|
||||||
if(!SubDirectories[ii].second)
|
if(!orderedDirs[ii].second)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if(order == 1 && m_Makefile->IsDirectoryPreOrder(orderedDirs[ii].first.c_str()))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(order == 2 && !m_Makefile->IsDirectoryPreOrder(orderedDirs[ii].first.c_str()))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
fout << " \\\n";
|
fout << " \\\n";
|
||||||
std::string subdir = FixDirectoryName(SubDirectories[ii].first.c_str());
|
std::string subdir = FixDirectoryName(orderedDirs[ii].first.c_str());
|
||||||
fout << target << "_" << subdir.c_str();
|
fout << target << "_" << subdir.c_str();
|
||||||
}
|
}
|
||||||
fout << " \n\n";
|
fout << " \n\n";
|
||||||
|
|
||||||
fout << "# Targets for making " << target << " in subdirectories.\n";
|
fout << "# Targets for making " << target << " in subdirectories.\n";
|
||||||
std::string last = "";
|
std::string last = "";
|
||||||
for(unsigned int cc =0; cc < SubDirectories.size(); cc++)
|
for(unsigned int cc =0; cc < orderedDirs.size(); cc++)
|
||||||
{
|
{
|
||||||
if(!SubDirectories[cc].second)
|
if(!orderedDirs[cc].second)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
std::string subdir = FixDirectoryName(orderedDirs[cc].first.c_str());
|
||||||
|
if(order == 1 && m_Makefile->IsDirectoryPreOrder(orderedDirs[cc].first.c_str()))
|
||||||
|
{
|
||||||
|
last = subdir;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
std::string subdir = FixDirectoryName(SubDirectories[cc].first.c_str());
|
if(order == 2 && !m_Makefile->IsDirectoryPreOrder(orderedDirs[cc].first.c_str()))
|
||||||
|
{
|
||||||
|
last = subdir;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
fout << target << "_" << subdir.c_str() << ": " << depend;
|
fout << target << "_" << subdir.c_str() << ": " << depend;
|
||||||
|
|
||||||
// Make each subdirectory depend on previous one. This forces
|
// Make each subdirectory depend on previous one. This forces
|
||||||
@ -2122,7 +2179,7 @@ OutputSubDirectoryVars(std::ostream& fout,
|
|||||||
last = subdir;
|
last = subdir;
|
||||||
std::string dir = m_Makefile->GetCurrentOutputDirectory();
|
std::string dir = m_Makefile->GetCurrentOutputDirectory();
|
||||||
dir += "/";
|
dir += "/";
|
||||||
dir += SubDirectories[cc].first;
|
dir += orderedDirs[cc].first;
|
||||||
this->BuildInSubDirectory(fout, dir.c_str(),
|
this->BuildInSubDirectory(fout, dir.c_str(),
|
||||||
target1, target2, silent);
|
target1, target2, silent);
|
||||||
}
|
}
|
||||||
@ -2148,7 +2205,14 @@ void cmLocalUnixMakefileGenerator::OutputSubDirectoryRules(std::ostream& fout)
|
|||||||
"default_target",
|
"default_target",
|
||||||
0, "$(TARGETS)",
|
0, "$(TARGETS)",
|
||||||
SubDirectories,
|
SubDirectories,
|
||||||
false);
|
false, 1);
|
||||||
|
this->OutputSubDirectoryVars(fout,
|
||||||
|
"SUBDIR_PREORDER_BUILD",
|
||||||
|
"default_target",
|
||||||
|
"default_target",
|
||||||
|
0, "$(TARGETS)",
|
||||||
|
SubDirectories,
|
||||||
|
false, 2);
|
||||||
this->OutputSubDirectoryVars(fout, "SUBDIR_CLEAN", "clean",
|
this->OutputSubDirectoryVars(fout, "SUBDIR_CLEAN", "clean",
|
||||||
"clean",
|
"clean",
|
||||||
0, 0,
|
0, 0,
|
||||||
@ -2442,7 +2506,7 @@ void cmLocalUnixMakefileGenerator::OutputMakeRules(std::ostream& fout)
|
|||||||
this->OutputMakeRule(fout,
|
this->OutputMakeRule(fout,
|
||||||
"default build rule",
|
"default build rule",
|
||||||
"all",
|
"all",
|
||||||
"cmake.depends $(TARGETS) $(SUBDIR_BUILD)",
|
"cmake.depends $(SUBDIR_PREORDER_BUILD) $(TARGETS) $(SUBDIR_BUILD)",
|
||||||
0);
|
0);
|
||||||
this->OutputMakeRule(fout,
|
this->OutputMakeRule(fout,
|
||||||
"clean generated files",
|
"clean generated files",
|
||||||
|
@ -151,7 +151,7 @@ protected:
|
|||||||
const char* target1,
|
const char* target1,
|
||||||
const char* target2,
|
const char* target2,
|
||||||
bool silent = false);
|
bool silent = false);
|
||||||
|
///! order == 0, then all subdirs are output, 1 = post order, 2 = preorder
|
||||||
virtual void OutputSubDirectoryVars(std::ostream& fout,
|
virtual void OutputSubDirectoryVars(std::ostream& fout,
|
||||||
const char* var,
|
const char* var,
|
||||||
const char* target,
|
const char* target,
|
||||||
@ -160,7 +160,7 @@ protected:
|
|||||||
const char* depend,
|
const char* depend,
|
||||||
const std::vector<std::pair<cmStdString, bool> >&
|
const std::vector<std::pair<cmStdString, bool> >&
|
||||||
SubDirectories,
|
SubDirectories,
|
||||||
bool silent = false);
|
bool silent = false, int order = 0);
|
||||||
|
|
||||||
virtual void OutputMakeRule(std::ostream&,
|
virtual void OutputMakeRule(std::ostream&,
|
||||||
const char* comment,
|
const char* comment,
|
||||||
|
@ -840,8 +840,17 @@ void cmMakefile::AddLinkDirectory(const char* dir)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmMakefile::AddSubDirectory(const char* sub, bool topLevel)
|
bool cmMakefile::IsDirectoryPreOrder(const char* dir)
|
||||||
{
|
{
|
||||||
|
return (m_SubDirectoryOrder.find(dir) != m_SubDirectoryOrder.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
void cmMakefile::AddSubDirectory(const char* sub, bool topLevel, bool preorder)
|
||||||
|
{
|
||||||
|
if(preorder)
|
||||||
|
{
|
||||||
|
m_SubDirectoryOrder[sub] = preorder;
|
||||||
|
}
|
||||||
std::pair<cmStdString, bool> p(sub, topLevel);
|
std::pair<cmStdString, bool> p(sub, topLevel);
|
||||||
// make sure it isn't already there
|
// make sure it isn't already there
|
||||||
if (std::find(m_SubDirectories.begin(),
|
if (std::find(m_SubDirectories.begin(),
|
||||||
|
@ -216,7 +216,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Add a subdirectory to the build.
|
* Add a subdirectory to the build.
|
||||||
*/
|
*/
|
||||||
void AddSubDirectory(const char*, bool includeTopLevel=true);
|
void AddSubDirectory(const char*, bool includeTopLevel=true, bool preorder = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add an include directory to the build.
|
* Add an include directory to the build.
|
||||||
@ -275,16 +275,6 @@ public:
|
|||||||
void AddLibrary(const char *libname, int shared,
|
void AddLibrary(const char *libname, int shared,
|
||||||
const std::vector<std::string> &srcs);
|
const std::vector<std::string> &srcs);
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a class/source file to the build.
|
|
||||||
*/
|
|
||||||
//void AddSource(cmSourceFile& ,const char *srcListName);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove a class/source file from the build.
|
|
||||||
*/
|
|
||||||
//void RemoveSource(cmSourceFile& ,const char *srcListName);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a source group for consideration when adding a new source.
|
* Add a source group for consideration when adding a new source.
|
||||||
*/
|
*/
|
||||||
@ -648,6 +638,9 @@ public:
|
|||||||
* Return a location of a file in cmake or custom modules directory
|
* Return a location of a file in cmake or custom modules directory
|
||||||
*/
|
*/
|
||||||
std::string GetModulesFile(const char* name);
|
std::string GetModulesFile(const char* name);
|
||||||
|
|
||||||
|
///! Return true if the directory is preorder.
|
||||||
|
bool IsDirectoryPreOrder(const char* dir);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// add link libraries and directories to the target
|
// add link libraries and directories to the target
|
||||||
@ -720,6 +713,7 @@ private:
|
|||||||
typedef std::map<cmStdString, cmStdString> StringStringMap;
|
typedef std::map<cmStdString, cmStdString> StringStringMap;
|
||||||
StringStringMap m_MacrosMap;
|
StringStringMap m_MacrosMap;
|
||||||
|
|
||||||
|
std::map<cmStdString, bool> m_SubDirectoryOrder;
|
||||||
// used in AddDefinition for performance improvement
|
// used in AddDefinition for performance improvement
|
||||||
DefinitionMap::key_type m_TemporaryDefinitionKey;
|
DefinitionMap::key_type m_TemporaryDefinitionKey;
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ bool cmSubdirCommand::InitialPass(std::vector<std::string> const& args)
|
|||||||
}
|
}
|
||||||
bool res = true;
|
bool res = true;
|
||||||
bool intoplevel = true;
|
bool intoplevel = true;
|
||||||
|
bool preorder = false;
|
||||||
|
|
||||||
for(std::vector<std::string>::const_iterator i = args.begin();
|
for(std::vector<std::string>::const_iterator i = args.begin();
|
||||||
i != args.end(); ++i)
|
i != args.end(); ++i)
|
||||||
@ -35,11 +36,16 @@ bool cmSubdirCommand::InitialPass(std::vector<std::string> const& args)
|
|||||||
intoplevel = false;
|
intoplevel = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if(*i == "PREORDER")
|
||||||
|
{
|
||||||
|
preorder = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
std::string directory = std::string(m_Makefile->GetCurrentDirectory()) +
|
std::string directory = std::string(m_Makefile->GetCurrentDirectory()) +
|
||||||
"/" + i->c_str();
|
"/" + i->c_str();
|
||||||
if ( cmSystemTools::FileIsDirectory(directory.c_str()) )
|
if ( cmSystemTools::FileIsDirectory(directory.c_str()) )
|
||||||
{
|
{
|
||||||
m_Makefile->AddSubDirectory(i->c_str(), intoplevel);
|
m_Makefile->AddSubDirectory(i->c_str(), intoplevel, preorder);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
6
Tests/PreOrder/CMakeLists.txt
Normal file
6
Tests/PreOrder/CMakeLists.txt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# a simple test case
|
||||||
|
PROJECT (PreOrder)
|
||||||
|
SET(CMAKE_IGNORE_DEPENDENCIES_ORDERING 1)
|
||||||
|
SUBDIRS(PREORDER Library)
|
||||||
|
ADD_EXECUTABLE (simple simple.cxx)
|
||||||
|
TARGET_LINK_LIBRARIES(simple simpleLib)
|
2
Tests/PreOrder/Library/CMakeLists.txt
Normal file
2
Tests/PreOrder/Library/CMakeLists.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
ADD_LIBRARY(simpleLib simpleLib.cxx )
|
||||||
|
|
3
Tests/PreOrder/Library/simpleLib.cxx
Normal file
3
Tests/PreOrder/Library/simpleLib.cxx
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
void simpleLib()
|
||||||
|
{
|
||||||
|
}
|
6
Tests/PreOrder/simple.cxx
Normal file
6
Tests/PreOrder/simple.cxx
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
extern void simpleLib();
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
simpleLib();
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user