ENH: change LINK_LIBRARY to add to targets
This commit is contained in:
parent
b5b46599fe
commit
27fe57b716
|
@ -72,13 +72,4 @@ bool cmAddLibraryCommand::InitialPass(std::vector<std::string> const& argsIn)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmAddLibraryCommand::FinalPass()
|
|
||||||
{
|
|
||||||
const cmTarget::LinkLibraries& libs = m_Makefile->GetLinkLibraries();
|
|
||||||
|
|
||||||
for( cmTarget::LinkLibraries::const_iterator i = libs.begin();
|
|
||||||
i != libs.end(); ++i )
|
|
||||||
{
|
|
||||||
m_Makefile->AddDependencyToCache( m_LibName.c_str(), i->first );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -43,13 +43,6 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual bool InitialPass(std::vector<std::string> const& args);
|
virtual bool InitialPass(std::vector<std::string> const& args);
|
||||||
|
|
||||||
/**
|
|
||||||
* This is called at the end after all the information specified by
|
|
||||||
* the command is accumulated. This is where we add in the
|
|
||||||
* dependencies that were globally specified.
|
|
||||||
*/
|
|
||||||
virtual void FinalPass();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the command as specified in CMakeList.txt.
|
* The name of the command as specified in CMakeList.txt.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -428,8 +428,6 @@ void cmMakefile::GenerateMakefile()
|
||||||
l != m_Targets.end(); l++)
|
l != m_Targets.end(); l++)
|
||||||
{
|
{
|
||||||
l->second.GenerateSourceFilesFromSourceLists(*this);
|
l->second.GenerateSourceFilesFromSourceLists(*this);
|
||||||
l->second.MergeLibraries(m_LinkLibraries);
|
|
||||||
l->second.MergeDirectories(m_LinkDirectories);
|
|
||||||
l->second.AnalyzeLibDependencies(*this);
|
l->second.AnalyzeLibDependencies(*this);
|
||||||
}
|
}
|
||||||
// now do the generation
|
// now do the generation
|
||||||
|
@ -520,10 +518,11 @@ void cmMakefile::AddLinkLibrary(const char* lib, cmTarget::LinkLibraryType llt)
|
||||||
void cmMakefile::AddLinkLibraryForTarget(const char *target,
|
void cmMakefile::AddLinkLibraryForTarget(const char *target,
|
||||||
const char* lib,
|
const char* lib,
|
||||||
cmTarget::LinkLibraryType llt)
|
cmTarget::LinkLibraryType llt)
|
||||||
{
|
{
|
||||||
if (m_Targets.find(target) != m_Targets.end())
|
cmTargets::iterator i = m_Targets.find(target);
|
||||||
|
if ( i != m_Targets.end())
|
||||||
{
|
{
|
||||||
m_Targets[target].AddLinkLibrary( *this, target, lib, llt );
|
i->second.AddLinkLibrary( *this, target, lib, llt );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -531,6 +530,21 @@ void cmMakefile::AddLinkLibraryForTarget(const char *target,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cmMakefile::AddLinkDirectoryForTarget(const char *target,
|
||||||
|
const char* d)
|
||||||
|
{
|
||||||
|
cmTargets::iterator i = m_Targets.find(target);
|
||||||
|
if ( i != m_Targets.end())
|
||||||
|
{
|
||||||
|
i->second.AddLinkDirectory( d );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cmSystemTools::Error("Attempt to add link directories to non-existant target: ",
|
||||||
|
target, " for directory ", d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void cmMakefile::AddLinkLibrary(const char* lib)
|
void cmMakefile::AddLinkLibrary(const char* lib)
|
||||||
{
|
{
|
||||||
this->AddLinkLibrary(lib,cmTarget::GENERAL);
|
this->AddLinkLibrary(lib,cmTarget::GENERAL);
|
||||||
|
@ -654,7 +668,20 @@ void cmMakefile::AddLibrary(const char* lname, int shared,
|
||||||
|
|
||||||
target.SetInAll(true);
|
target.SetInAll(true);
|
||||||
target.GetSourceLists() = srcs;
|
target.GetSourceLists() = srcs;
|
||||||
|
std::vector<std::string>::iterator j;
|
||||||
|
for(j = m_LinkDirectories.begin();
|
||||||
|
j != m_LinkDirectories.end(); ++j)
|
||||||
|
{
|
||||||
|
target.AddLinkDirectory(j->c_str());
|
||||||
|
}
|
||||||
m_Targets.insert(cmTargets::value_type(lname,target));
|
m_Targets.insert(cmTargets::value_type(lname,target));
|
||||||
|
cmTarget::LinkLibraries::iterator i;
|
||||||
|
for(i = m_LinkLibraries.begin(); i != m_LinkLibraries.end(); ++i)
|
||||||
|
{
|
||||||
|
this->AddLinkLibraryForTarget(lname, i->first.c_str(), i->second);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Add an entry into the cache
|
// Add an entry into the cache
|
||||||
cmCacheManager::GetInstance()->
|
cmCacheManager::GetInstance()->
|
||||||
|
@ -727,7 +754,18 @@ void cmMakefile::AddExecutable(const char *exeName,
|
||||||
}
|
}
|
||||||
target.SetInAll(true);
|
target.SetInAll(true);
|
||||||
target.GetSourceLists() = srcs;
|
target.GetSourceLists() = srcs;
|
||||||
|
std::vector<std::string>::iterator j;
|
||||||
|
for(j = m_LinkDirectories.begin();
|
||||||
|
j != m_LinkDirectories.end(); ++j)
|
||||||
|
{
|
||||||
|
target.AddLinkDirectory(j->c_str());
|
||||||
|
}
|
||||||
m_Targets.insert(cmTargets::value_type(exeName,target));
|
m_Targets.insert(cmTargets::value_type(exeName,target));
|
||||||
|
cmTarget::LinkLibraries::iterator i;
|
||||||
|
for(i = m_LinkLibraries.begin(); i != m_LinkLibraries.end(); ++i)
|
||||||
|
{
|
||||||
|
this->AddLinkLibraryForTarget(exeName, i->first.c_str(), i->second);
|
||||||
|
}
|
||||||
|
|
||||||
// Add an entry into the cache
|
// Add an entry into the cache
|
||||||
cmCacheManager::GetInstance()->
|
cmCacheManager::GetInstance()->
|
||||||
|
|
|
@ -155,22 +155,6 @@ public:
|
||||||
const std::vector<std::string> &depends,
|
const std::vector<std::string> &depends,
|
||||||
const std::vector<std::string> &outputs);
|
const std::vector<std::string> &outputs);
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Get a list of link libraries in the build.
|
|
||||||
// */
|
|
||||||
// cmTarget::LinkLibraries& GetLinkLibraries()
|
|
||||||
// {
|
|
||||||
// return m_LinkLibraries;
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a list of link libraries in the build.
|
|
||||||
*/
|
|
||||||
const cmTarget::LinkLibraries& GetLinkLibraries() const
|
|
||||||
{
|
|
||||||
return m_LinkLibraries;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a link library to the build.
|
* Add a link library to the build.
|
||||||
*/
|
*/
|
||||||
|
@ -178,6 +162,7 @@ public:
|
||||||
void AddLinkLibrary(const char*, cmTarget::LinkLibraryType type);
|
void AddLinkLibrary(const char*, cmTarget::LinkLibraryType type);
|
||||||
void AddLinkLibraryForTarget(const char *tgt, const char*,
|
void AddLinkLibraryForTarget(const char *tgt, const char*,
|
||||||
cmTarget::LinkLibraryType type);
|
cmTarget::LinkLibraryType type);
|
||||||
|
void AddLinkDirectoryForTarget(const char *tgt, const char* d);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a link directory to the build.
|
* Add a link directory to the build.
|
||||||
|
|
|
@ -67,16 +67,6 @@ void cmTarget::GenerateSourceFilesFromSourceLists( cmMakefile &mf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmTarget::MergeLibraries(const LinkLibraries &ll)
|
|
||||||
{
|
|
||||||
m_LinkLibraries.insert( m_LinkLibraries.end(), ll.begin(), ll.end() );
|
|
||||||
}
|
|
||||||
|
|
||||||
void cmTarget::MergeDirectories(const std::vector<std::string> &ld)
|
|
||||||
{
|
|
||||||
m_LinkDirectories.insert( m_LinkDirectories.end(), ld.begin(), ld.end() );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void cmTarget::AddLinkLibrary(const std::string& lib,
|
void cmTarget::AddLinkLibrary(const std::string& lib,
|
||||||
LinkLibraryType llt)
|
LinkLibraryType llt)
|
||||||
|
@ -276,7 +266,9 @@ void cmTarget::Emit( const std::string& lib,
|
||||||
{
|
{
|
||||||
// It's already been emitted
|
// It's already been emitted
|
||||||
if( emitted.find(lib) != emitted.end() )
|
if( emitted.find(lib) != emitted.end() )
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// If this library hasn't been visited before, then emit all its
|
// If this library hasn't been visited before, then emit all its
|
||||||
// dependencies before emitting the library itself. If it has been
|
// dependencies before emitting the library itself. If it has been
|
||||||
|
|
|
@ -81,6 +81,7 @@ public:
|
||||||
const LinkLibraries &GetLinkLibraries() const {return m_LinkLibraries;}
|
const LinkLibraries &GetLinkLibraries() const {return m_LinkLibraries;}
|
||||||
|
|
||||||
const std::vector<std::string>& GetLinkDirectories() const {return m_LinkDirectories;}
|
const std::vector<std::string>& GetLinkDirectories() const {return m_LinkDirectories;}
|
||||||
|
void AddLinkDirectory(const char* d) { m_LinkDirectories.push_back(d);}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the path where this target should be installed. This is relative to
|
* Set the path where this target should be installed. This is relative to
|
||||||
|
@ -96,16 +97,6 @@ public:
|
||||||
void AddLinkLibrary(const std::string& lib,
|
void AddLinkLibrary(const std::string& lib,
|
||||||
LinkLibraryType llt);
|
LinkLibraryType llt);
|
||||||
|
|
||||||
/**
|
|
||||||
* Merge Link Libraries into this targets current list
|
|
||||||
*/
|
|
||||||
void MergeLibraries(const LinkLibraries &ll);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Merge Link Directories into this targets current list
|
|
||||||
*/
|
|
||||||
void MergeDirectories(const std::vector<std::string> &ld);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate the SourceFilesList from the SourceLists. This should only be
|
* Generate the SourceFilesList from the SourceLists. This should only be
|
||||||
* done once to be safe.
|
* done once to be safe.
|
||||||
|
|
|
@ -57,12 +57,12 @@ bool cmTargetLinkLibrariesCommand::InitialPass(std::vector<std::string> const& a
|
||||||
const char* dir = m_Makefile->GetDefinition(i->c_str());
|
const char* dir = m_Makefile->GetDefinition(i->c_str());
|
||||||
if( dir )
|
if( dir )
|
||||||
{
|
{
|
||||||
m_Makefile->AddLinkDirectory( dir );
|
m_Makefile->AddLinkDirectoryForTarget(args[0].c_str(), dir );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_Makefile->AddLinkDirectory( ldir );
|
m_Makefile->AddLinkDirectoryForTarget(args[0].c_str(), ldir );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -890,22 +890,6 @@ void cmUnixMakefileGenerator::OutputDependLibs(std::ostream& fout)
|
||||||
// A library should not depend on itself!
|
// A library should not depend on itself!
|
||||||
emitted.insert(l->first);
|
emitted.insert(l->first);
|
||||||
|
|
||||||
// First look at all makefile level link libraries.
|
|
||||||
const cmTarget::LinkLibraries& libs = m_Makefile->GetLinkLibraries();
|
|
||||||
for(cmTarget::LinkLibraries::const_iterator lib = libs.begin();
|
|
||||||
lib != libs.end(); ++lib)
|
|
||||||
{
|
|
||||||
// Record that this library was used.
|
|
||||||
used.insert(lib->first);
|
|
||||||
|
|
||||||
// Don't emit the same library twice for this target.
|
|
||||||
if(emitted.insert(lib->first).second)
|
|
||||||
{
|
|
||||||
// Output this dependency.
|
|
||||||
this->OutputLibDepend(fout, lib->first.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now, look at all link libraries specific to this target.
|
// Now, look at all link libraries specific to this target.
|
||||||
const cmTarget::LinkLibraries& tlibs = l->second.GetLinkLibraries();
|
const cmTarget::LinkLibraries& tlibs = l->second.GetLinkLibraries();
|
||||||
for(cmTarget::LinkLibraries::const_iterator lib = tlibs.begin();
|
for(cmTarget::LinkLibraries::const_iterator lib = tlibs.begin();
|
||||||
|
|
|
@ -5,22 +5,16 @@ CMAKE_MINIMUM_REQUIRED(VERSION 1.3)
|
||||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTEST_CXX_FLAGS")
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTEST_CXX_FLAGS")
|
||||||
SET_SOURCE_FILES_PROPERTIES(complex COMPILE_FLAGS
|
SET_SOURCE_FILES_PROPERTIES(complex COMPILE_FLAGS
|
||||||
"-DFILE_HAS_EXTRA_COMPILE_FLAGS")
|
"-DFILE_HAS_EXTRA_COMPILE_FLAGS")
|
||||||
ADD_EXECUTABLE(complex complex)
|
# Link to CMake lib
|
||||||
SET(COMPLEX_LIBS CMakeTestLibrary;CMakeTestLibraryShared;CMakeTestCLibraryShared)
|
LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Source)
|
||||||
|
|
||||||
# Use LINK_LIBRARIES instead of TARGET_LINK_LIBRARIES to
|
# Use LINK_LIBRARIES instead of TARGET_LINK_LIBRARIES to
|
||||||
|
SET(COMPLEX_LIBS CMakeTestLibrary;CMakeTestLibraryShared;CMakeTestCLibraryShared)
|
||||||
LINK_LIBRARIES(${COMPLEX_LIBS})
|
LINK_LIBRARIES(${COMPLEX_LIBS})
|
||||||
|
|
||||||
#
|
|
||||||
# Link to CMake lib
|
|
||||||
# Specify the same one for debug/optimized to increase coverage
|
|
||||||
#
|
|
||||||
LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Source)
|
|
||||||
|
|
||||||
|
ADD_EXECUTABLE(complex complex)
|
||||||
TARGET_LINK_LIBRARIES(complex
|
TARGET_LINK_LIBRARIES(complex
|
||||||
CMakeLib
|
CMakeLib)
|
||||||
debug CMakeLib
|
|
||||||
optimized CMakeLib)
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Output the files required by 'complex' to a file.
|
# Output the files required by 'complex' to a file.
|
||||||
|
|
|
@ -5,22 +5,16 @@ CMAKE_MINIMUM_REQUIRED(VERSION 1.3)
|
||||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTEST_CXX_FLAGS")
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTEST_CXX_FLAGS")
|
||||||
SET_SOURCE_FILES_PROPERTIES(complex COMPILE_FLAGS
|
SET_SOURCE_FILES_PROPERTIES(complex COMPILE_FLAGS
|
||||||
"-DFILE_HAS_EXTRA_COMPILE_FLAGS")
|
"-DFILE_HAS_EXTRA_COMPILE_FLAGS")
|
||||||
ADD_EXECUTABLE(complex complex)
|
# Link to CMake lib
|
||||||
SET(COMPLEX_LIBS CMakeTestLibrary;CMakeTestLibraryShared;CMakeTestCLibraryShared)
|
LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Source)
|
||||||
|
|
||||||
# Use LINK_LIBRARIES instead of TARGET_LINK_LIBRARIES to
|
# Use LINK_LIBRARIES instead of TARGET_LINK_LIBRARIES to
|
||||||
|
SET(COMPLEX_LIBS CMakeTestLibrary;CMakeTestLibraryShared;CMakeTestCLibraryShared)
|
||||||
LINK_LIBRARIES(${COMPLEX_LIBS})
|
LINK_LIBRARIES(${COMPLEX_LIBS})
|
||||||
|
|
||||||
#
|
|
||||||
# Link to CMake lib
|
|
||||||
# Specify the same one for debug/optimized to increase coverage
|
|
||||||
#
|
|
||||||
LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Source)
|
|
||||||
|
|
||||||
|
ADD_EXECUTABLE(complex complex)
|
||||||
TARGET_LINK_LIBRARIES(complex
|
TARGET_LINK_LIBRARIES(complex
|
||||||
CMakeLib
|
CMakeLib)
|
||||||
debug CMakeLib
|
|
||||||
optimized CMakeLib)
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Output the files required by 'complex' to a file.
|
# Output the files required by 'complex' to a file.
|
||||||
|
|
|
@ -5,22 +5,16 @@ CMAKE_MINIMUM_REQUIRED(VERSION 1.3)
|
||||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTEST_CXX_FLAGS")
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTEST_CXX_FLAGS")
|
||||||
SET_SOURCE_FILES_PROPERTIES(complex COMPILE_FLAGS
|
SET_SOURCE_FILES_PROPERTIES(complex COMPILE_FLAGS
|
||||||
"-DFILE_HAS_EXTRA_COMPILE_FLAGS")
|
"-DFILE_HAS_EXTRA_COMPILE_FLAGS")
|
||||||
ADD_EXECUTABLE(complex complex)
|
# Link to CMake lib
|
||||||
SET(COMPLEX_LIBS CMakeTestLibrary;CMakeTestLibraryShared;CMakeTestCLibraryShared)
|
LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Source)
|
||||||
|
|
||||||
# Use LINK_LIBRARIES instead of TARGET_LINK_LIBRARIES to
|
# Use LINK_LIBRARIES instead of TARGET_LINK_LIBRARIES to
|
||||||
|
SET(COMPLEX_LIBS CMakeTestLibrary;CMakeTestLibraryShared;CMakeTestCLibraryShared)
|
||||||
LINK_LIBRARIES(${COMPLEX_LIBS})
|
LINK_LIBRARIES(${COMPLEX_LIBS})
|
||||||
|
|
||||||
#
|
|
||||||
# Link to CMake lib
|
|
||||||
# Specify the same one for debug/optimized to increase coverage
|
|
||||||
#
|
|
||||||
LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Source)
|
|
||||||
|
|
||||||
|
ADD_EXECUTABLE(complex complex)
|
||||||
TARGET_LINK_LIBRARIES(complex
|
TARGET_LINK_LIBRARIES(complex
|
||||||
CMakeLib
|
CMakeLib)
|
||||||
debug CMakeLib
|
|
||||||
optimized CMakeLib)
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Output the files required by 'complex' to a file.
|
# Output the files required by 'complex' to a file.
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
ADD_EXECUTABLE( exec ExecMain.c )
|
|
||||||
|
|
||||||
# This executable directly depends on NoDepB, NoDepC, SixA and SixB. However,
|
# This executable directly depends on NoDepB, NoDepC, SixA and SixB. However,
|
||||||
# since NoDepB and NoDepC do not have explicit dependency information,
|
# since NoDepB and NoDepC do not have explicit dependency information,
|
||||||
# and they depend on NoDepA, we have to manually specify that dependency.
|
# and they depend on NoDepA, we have to manually specify that dependency.
|
||||||
LINK_LIBRARIES( NoDepB NoDepC NoDepA SixB SixA )
|
LINK_LIBRARIES( NoDepB NoDepC NoDepA SixB SixA )
|
||||||
|
|
||||||
|
ADD_EXECUTABLE( exec ExecMain.c )
|
||||||
|
|
||||||
|
|
|
@ -3,10 +3,10 @@
|
||||||
# specify them in the correct order.
|
# specify them in the correct order.
|
||||||
|
|
||||||
LINK_LIBRARIES( Two )
|
LINK_LIBRARIES( Two )
|
||||||
|
LINK_LIBRARIES( Five )
|
||||||
|
|
||||||
ADD_LIBRARY( SixA SixASrc.c )
|
ADD_LIBRARY( SixA SixASrc.c )
|
||||||
|
|
||||||
ADD_LIBRARY( SixB SixBSrc.c )
|
ADD_LIBRARY( SixB SixBSrc.c )
|
||||||
TARGET_LINK_LIBRARIES( SixB Four )
|
TARGET_LINK_LIBRARIES( SixB Four )
|
||||||
|
|
||||||
LINK_LIBRARIES( Five )
|
|
||||||
|
|
Loading…
Reference in New Issue