ENH: fix EXECUTABLE_OUTPUT_PATH and LIBRARY_OUTPUT_PATH for unix
This commit is contained in:
parent
f6f8dde5a8
commit
78ee6660a7
|
@ -55,6 +55,30 @@ cmUnixMakefileGenerator::cmUnixMakefileGenerator()
|
||||||
|
|
||||||
void cmUnixMakefileGenerator::GenerateMakefile()
|
void cmUnixMakefileGenerator::GenerateMakefile()
|
||||||
{
|
{
|
||||||
|
// suppoirt override in output directories
|
||||||
|
if (m_Makefile->GetDefinition("LIBRARY_OUTPUT_PATH"))
|
||||||
|
{
|
||||||
|
m_LibraryOutputPath = m_Makefile->GetDefinition("LIBRARY_OUTPUT_PATH");
|
||||||
|
if(m_LibraryOutputPath.size() &&
|
||||||
|
m_LibraryOutputPath[m_LibraryOutputPath.size() -1] != '/')
|
||||||
|
{
|
||||||
|
m_LibraryOutputPath += "/";
|
||||||
|
}
|
||||||
|
cmSystemTools::MakeDirectory(m_LibraryOutputPath.c_str());
|
||||||
|
m_Makefile->GetLinkDirectories().push_back(m_LibraryOutputPath);
|
||||||
|
}
|
||||||
|
if (m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
|
||||||
|
{
|
||||||
|
m_ExecutableOutputPath = m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
|
||||||
|
if(m_ExecutableOutputPath.size() &&
|
||||||
|
m_ExecutableOutputPath[m_ExecutableOutputPath.size() -1] != '/')
|
||||||
|
{
|
||||||
|
m_ExecutableOutputPath += "/";
|
||||||
|
}
|
||||||
|
cmSystemTools::MakeDirectory(m_ExecutableOutputPath.c_str());
|
||||||
|
m_Makefile->GetLinkDirectories().push_back(m_ExecutableOutputPath);
|
||||||
|
}
|
||||||
|
|
||||||
if(m_CacheOnly)
|
if(m_CacheOnly)
|
||||||
{
|
{
|
||||||
// Generate the cache only stuff
|
// Generate the cache only stuff
|
||||||
|
@ -211,7 +235,7 @@ void cmUnixMakefileGenerator::OutputTargetRules(std::ostream& fout)
|
||||||
if (l->second.GetType() == cmTarget::LIBRARY &&
|
if (l->second.GetType() == cmTarget::LIBRARY &&
|
||||||
l->second.IsInAll())
|
l->second.IsInAll())
|
||||||
{
|
{
|
||||||
fout << " \\\nlib" << l->first.c_str();
|
fout << " \\\n" << m_LibraryOutputPath << "lib" << l->first.c_str();
|
||||||
if(dll)
|
if(dll)
|
||||||
{
|
{
|
||||||
fout << m_Makefile->GetDefinition("CMAKE_SHLIB_SUFFIX");
|
fout << m_Makefile->GetDefinition("CMAKE_SHLIB_SUFFIX");
|
||||||
|
@ -230,7 +254,7 @@ void cmUnixMakefileGenerator::OutputTargetRules(std::ostream& fout)
|
||||||
l->second.GetType() == cmTarget::WIN32_EXECUTABLE) &&
|
l->second.GetType() == cmTarget::WIN32_EXECUTABLE) &&
|
||||||
l->second.IsInAll())
|
l->second.IsInAll())
|
||||||
{
|
{
|
||||||
fout << " \\\n" << l->first.c_str();
|
fout << " \\\n" << m_ExecutableOutputPath << l->first.c_str();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// list utilities last
|
// list utilities last
|
||||||
|
@ -318,26 +342,37 @@ void cmUnixMakefileGenerator::OutputLinkLibraries(std::ostream& fout,
|
||||||
libDir != libdirs.end(); ++libDir)
|
libDir != libdirs.end(); ++libDir)
|
||||||
{
|
{
|
||||||
std::string libpath = cmSystemTools::EscapeSpaces(libDir->c_str());
|
std::string libpath = cmSystemTools::EscapeSpaces(libDir->c_str());
|
||||||
if(libpath != "/usr/lib")
|
bool skipPath = false;
|
||||||
|
if (m_LibraryOutputPath.size())
|
||||||
{
|
{
|
||||||
if(emitted.insert(libpath).second)
|
if(m_LibraryOutputPath != libpath
|
||||||
|
&& (libpath.find(m_Makefile->GetHomeOutputDirectory())
|
||||||
|
!= std::string::npos))
|
||||||
{
|
{
|
||||||
std::string::size_type pos = libDir->find("-L");
|
emitted.insert(libpath);
|
||||||
if((pos == std::string::npos || pos > 0)
|
|
||||||
&& libDir->find("${") == std::string::npos)
|
|
||||||
{
|
|
||||||
linkLibs += "-L";
|
|
||||||
if(outputRuntime)
|
|
||||||
{
|
|
||||||
runtimeDirs.push_back( libpath );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
linkLibs += libpath;
|
|
||||||
linkLibs += " ";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(libpath == "/usr/lib" )
|
||||||
|
{
|
||||||
|
emitted.insert(libpath);
|
||||||
|
}
|
||||||
|
if(emitted.insert(libpath).second)
|
||||||
|
{
|
||||||
|
std::string::size_type pos = libDir->find("-L");
|
||||||
|
if((pos == std::string::npos || pos > 0)
|
||||||
|
&& libDir->find("${") == std::string::npos)
|
||||||
|
{
|
||||||
|
linkLibs += "-L";
|
||||||
|
if(outputRuntime)
|
||||||
|
{
|
||||||
|
runtimeDirs.push_back( libpath );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
linkLibs += libpath;
|
||||||
|
linkLibs += " ";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string librariesLinked;
|
std::string librariesLinked;
|
||||||
const cmTarget::LinkLibraries& libs = tgt.GetLinkLibraries();
|
const cmTarget::LinkLibraries& libs = tgt.GetLinkLibraries();
|
||||||
cmRegularExpression reg("lib(.*)(\\.so$|\\.a|\\.sl$)");
|
cmRegularExpression reg("lib(.*)(\\.so$|\\.a|\\.sl$)");
|
||||||
|
@ -429,6 +464,7 @@ void cmUnixMakefileGenerator::OutputLinkLibraries(std::ostream& fout,
|
||||||
|
|
||||||
void cmUnixMakefileGenerator::OutputTargets(std::ostream& fout)
|
void cmUnixMakefileGenerator::OutputTargets(std::ostream& fout)
|
||||||
{
|
{
|
||||||
|
|
||||||
bool dll = cmCacheManager::GetInstance()->IsOn("BUILD_SHARED_LIBS");
|
bool dll = cmCacheManager::GetInstance()->IsOn("BUILD_SHARED_LIBS");
|
||||||
|
|
||||||
// for each target
|
// for each target
|
||||||
|
@ -441,18 +477,21 @@ void cmUnixMakefileGenerator::OutputTargets(std::ostream& fout)
|
||||||
fout << "#---------------------------------------------------------\n";
|
fout << "#---------------------------------------------------------\n";
|
||||||
fout << "# rules for a library\n";
|
fout << "# rules for a library\n";
|
||||||
fout << "#\n";
|
fout << "#\n";
|
||||||
fout << "lib" << l->first << ".a: ${" <<
|
fout << m_LibraryOutputPath << "lib" << l->first << ".a: ${" <<
|
||||||
l->first << "_SRC_OBJS} \n";
|
l->first << "_SRC_OBJS} \n";
|
||||||
fout << "\t${CMAKE_AR} cr lib" << l->first << ".a ${" <<
|
fout << "\t${CMAKE_AR} cr "
|
||||||
|
<< m_LibraryOutputPath << "lib" << l->first << ".a ${" <<
|
||||||
l->first << "_SRC_OBJS} \n";
|
l->first << "_SRC_OBJS} \n";
|
||||||
fout << "\t${CMAKE_RANLIB} lib" << l->first << ".a\n";
|
fout << "\t${CMAKE_RANLIB} "
|
||||||
|
<< m_LibraryOutputPath << "lib" << l->first << ".a\n";
|
||||||
fout << std::endl;
|
fout << std::endl;
|
||||||
|
|
||||||
fout << "lib" << l->first << "$(SHLIB_SUFFIX): ${" <<
|
fout << m_LibraryOutputPath << "lib" << l->first << "$(SHLIB_SUFFIX): ${" <<
|
||||||
l->first << "_SRC_OBJS} ${CMAKE_DEPEND_LIBS}\n";
|
l->first << "_SRC_OBJS} ${CMAKE_DEPEND_LIBS}\n";
|
||||||
fout << "\trm -f lib" << l->first << "$(SHLIB_SUFFIX)\n";
|
fout << "\trm -f lib" << l->first << "$(SHLIB_SUFFIX)\n";
|
||||||
fout << "\t$(CMAKE_CXX_COMPILER) ${CMAKE_SHLIB_LINK_FLAGS} ${CMAKE_SHLIB_BUILD_FLAGS} ${CMAKE_CXX_FLAGS} -o \\\n";
|
fout << "\t$(CMAKE_CXX_COMPILER) ${CMAKE_SHLIB_LINK_FLAGS} "
|
||||||
fout << "\t lib" << l->first << "$(SHLIB_SUFFIX) \\\n";
|
"${CMAKE_SHLIB_BUILD_FLAGS} ${CMAKE_CXX_FLAGS} -o \\\n";
|
||||||
|
fout << "\t " << m_LibraryOutputPath << "lib" << l->first << "$(SHLIB_SUFFIX) \\\n";
|
||||||
fout << "\t ${" << l->first <<
|
fout << "\t ${" << l->first <<
|
||||||
"_SRC_OBJS} ";
|
"_SRC_OBJS} ";
|
||||||
this->OutputLinkLibraries(fout, l->first.c_str(), l->second);
|
this->OutputLinkLibraries(fout, l->first.c_str(), l->second);
|
||||||
|
@ -461,7 +500,7 @@ void cmUnixMakefileGenerator::OutputTargets(std::ostream& fout)
|
||||||
else if ((l->second.GetType() == cmTarget::EXECUTABLE)
|
else if ((l->second.GetType() == cmTarget::EXECUTABLE)
|
||||||
|| (l->second.GetType() == cmTarget::WIN32_EXECUTABLE))
|
|| (l->second.GetType() == cmTarget::WIN32_EXECUTABLE))
|
||||||
{
|
{
|
||||||
fout << l->first << ": ${" <<
|
fout << m_ExecutableOutputPath << l->first << ": ${" <<
|
||||||
l->first << "_SRC_OBJS} ${CMAKE_DEPEND_LIBS}\n";
|
l->first << "_SRC_OBJS} ${CMAKE_DEPEND_LIBS}\n";
|
||||||
fout << "\t${CMAKE_CXX_COMPILER} ";
|
fout << "\t${CMAKE_CXX_COMPILER} ";
|
||||||
if (dll)
|
if (dll)
|
||||||
|
@ -470,7 +509,7 @@ void cmUnixMakefileGenerator::OutputTargets(std::ostream& fout)
|
||||||
}
|
}
|
||||||
fout << "${CMAKE_CXXFLAGS} ${" << l->first << "_SRC_OBJS} ";
|
fout << "${CMAKE_CXXFLAGS} ${" << l->first << "_SRC_OBJS} ";
|
||||||
this->OutputLinkLibraries(fout, NULL,l->second);
|
this->OutputLinkLibraries(fout, NULL,l->second);
|
||||||
fout << " -o " << l->first << "\n\n";
|
fout << " -o " << m_ExecutableOutputPath << l->first << "\n\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -502,7 +541,15 @@ void cmUnixMakefileGenerator::OutputDependencies(std::ostream& fout)
|
||||||
if(cacheValue)
|
if(cacheValue)
|
||||||
{
|
{
|
||||||
std::string libpath = cacheValue;
|
std::string libpath = cacheValue;
|
||||||
libpath += "/lib";
|
if(m_LibraryOutputPath.size())
|
||||||
|
{
|
||||||
|
libpath = m_LibraryOutputPath;
|
||||||
|
libpath += "lib";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
libpath += "/lib";
|
||||||
|
}
|
||||||
libpath += lib2->first;
|
libpath += lib2->first;
|
||||||
bool dll = cmCacheManager::GetInstance()->IsOn("BUILD_SHARED_LIBS");
|
bool dll = cmCacheManager::GetInstance()->IsOn("BUILD_SHARED_LIBS");
|
||||||
if(dll)
|
if(dll)
|
||||||
|
@ -542,12 +589,19 @@ void cmUnixMakefileGenerator::OutputDependencies(std::ostream& fout)
|
||||||
library += ".a";
|
library += ".a";
|
||||||
}
|
}
|
||||||
std::string libpath = cacheValue;
|
std::string libpath = cacheValue;
|
||||||
libpath += "/";
|
if(m_LibraryOutputPath.size())
|
||||||
|
{
|
||||||
|
libpath = m_LibraryOutputPath;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
libpath += "/";
|
||||||
|
}
|
||||||
libpath += library;
|
libpath += library;
|
||||||
// put out a rule to build the library if it does not exist
|
// put out a rule to build the library if it does not exist
|
||||||
fout << libpath.c_str()
|
fout << libpath.c_str()
|
||||||
<< ":\n\tcd " << cacheValue
|
<< ":\n\tcd " << cacheValue
|
||||||
<< "; make " << library.c_str() << "\n\n";
|
<< "; make " << m_LibraryOutputPath << library.c_str() << "\n\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,6 +120,8 @@ private:
|
||||||
private:
|
private:
|
||||||
bool m_CacheOnly;
|
bool m_CacheOnly;
|
||||||
bool m_Recurse;
|
bool m_Recurse;
|
||||||
|
std::string m_ExecutableOutputPath;
|
||||||
|
std::string m_LibraryOutputPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -129,11 +129,24 @@ void cmake::SetArgs(cmMakefile& builder, const std::vector<std::string>& args)
|
||||||
// at the end of this CMAKE_ROOT and CMAAKE_COMMAND should be added to the cache
|
// at the end of this CMAKE_ROOT and CMAAKE_COMMAND should be added to the cache
|
||||||
void cmake::AddCMakePaths(const std::vector<std::string>& args)
|
void cmake::AddCMakePaths(const std::vector<std::string>& args)
|
||||||
{
|
{
|
||||||
// Find our own exectuable.
|
// Find our own executable.
|
||||||
std::string cMakeSelf = args[0];
|
std::string cMakeSelf = args[0];
|
||||||
cmSystemTools::ConvertToUnixSlashes(cMakeSelf);
|
cmSystemTools::ConvertToUnixSlashes(cMakeSelf);
|
||||||
cMakeSelf = cmSystemTools::FindProgram(cMakeSelf.c_str());
|
cMakeSelf = cmSystemTools::FindProgram(cMakeSelf.c_str());
|
||||||
|
|
||||||
|
if(!cmCacheManager::GetInstance()->GetCacheValue("LIBRARY_OUTPUT_PATH"))
|
||||||
|
{
|
||||||
|
cmCacheManager::GetInstance()->AddCacheEntry("LIBRARY_OUTPUT_PATH", "",
|
||||||
|
"Single output directory for building all libraries.",
|
||||||
|
cmCacheManager::PATH);
|
||||||
|
}
|
||||||
|
if(!cmCacheManager::GetInstance()->GetCacheValue("EXECUTABLE_OUTPUT_PATH"))
|
||||||
|
{
|
||||||
|
cmCacheManager::GetInstance()->AddCacheEntry("EXECUTABLE_OUTPUT_PATH", "",
|
||||||
|
"Single output directory for building all executables.",
|
||||||
|
cmCacheManager::PATH);
|
||||||
|
}
|
||||||
|
|
||||||
// Save the value in the cache
|
// Save the value in the cache
|
||||||
cmCacheManager::GetInstance()->AddCacheEntry
|
cmCacheManager::GetInstance()->AddCacheEntry
|
||||||
("CMAKE_COMMAND",
|
("CMAKE_COMMAND",
|
||||||
|
|
Loading…
Reference in New Issue