diff --git a/Source/cmAddLibraryCommand.cxx b/Source/cmAddLibraryCommand.cxx index 13957b0877..baecbe374f 100644 --- a/Source/cmAddLibraryCommand.cxx +++ b/Source/cmAddLibraryCommand.cxx @@ -72,13 +72,4 @@ bool cmAddLibraryCommand::InitialPass(std::vector const& argsIn) 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 ); - } -} diff --git a/Source/cmAddLibraryCommand.h b/Source/cmAddLibraryCommand.h index cb41cccd39..9f01004f43 100644 --- a/Source/cmAddLibraryCommand.h +++ b/Source/cmAddLibraryCommand.h @@ -43,13 +43,6 @@ public: */ virtual bool InitialPass(std::vector 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. */ diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 9280cf2357..4c31efa88f 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -428,8 +428,6 @@ void cmMakefile::GenerateMakefile() l != m_Targets.end(); l++) { l->second.GenerateSourceFilesFromSourceLists(*this); - l->second.MergeLibraries(m_LinkLibraries); - l->second.MergeDirectories(m_LinkDirectories); l->second.AnalyzeLibDependencies(*this); } // now do the generation @@ -520,10 +518,11 @@ void cmMakefile::AddLinkLibrary(const char* lib, cmTarget::LinkLibraryType llt) void cmMakefile::AddLinkLibraryForTarget(const char *target, const char* lib, 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 { @@ -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) { this->AddLinkLibrary(lib,cmTarget::GENERAL); @@ -654,7 +668,20 @@ void cmMakefile::AddLibrary(const char* lname, int shared, target.SetInAll(true); target.GetSourceLists() = srcs; + std::vector::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)); + 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 cmCacheManager::GetInstance()-> @@ -727,7 +754,18 @@ void cmMakefile::AddExecutable(const char *exeName, } target.SetInAll(true); target.GetSourceLists() = srcs; + std::vector::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)); + 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 cmCacheManager::GetInstance()-> diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 742e622c63..1914dc0891 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -155,22 +155,6 @@ public: const std::vector &depends, const std::vector &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. */ @@ -178,6 +162,7 @@ public: void AddLinkLibrary(const char*, cmTarget::LinkLibraryType type); void AddLinkLibraryForTarget(const char *tgt, const char*, cmTarget::LinkLibraryType type); + void AddLinkDirectoryForTarget(const char *tgt, const char* d); /** * Add a link directory to the build. diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 2c27c9cfa9..8b12ab0cb6 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -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 &ld) -{ - m_LinkDirectories.insert( m_LinkDirectories.end(), ld.begin(), ld.end() ); -} - void cmTarget::AddLinkLibrary(const std::string& lib, LinkLibraryType llt) @@ -276,7 +266,9 @@ void cmTarget::Emit( const std::string& lib, { // It's already been emitted if( emitted.find(lib) != emitted.end() ) + { return; + } // If this library hasn't been visited before, then emit all its // dependencies before emitting the library itself. If it has been diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 6abdab2074..124c04c8a0 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -81,6 +81,7 @@ public: const LinkLibraries &GetLinkLibraries() const {return m_LinkLibraries;} const std::vector& 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 @@ -96,16 +97,6 @@ public: void AddLinkLibrary(const std::string& lib, 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 &ld); - /** * Generate the SourceFilesList from the SourceLists. This should only be * done once to be safe. diff --git a/Source/cmTargetLinkLibrariesCommand.cxx b/Source/cmTargetLinkLibrariesCommand.cxx index 34c57a30e6..143cf86397 100644 --- a/Source/cmTargetLinkLibrariesCommand.cxx +++ b/Source/cmTargetLinkLibrariesCommand.cxx @@ -57,12 +57,12 @@ bool cmTargetLinkLibrariesCommand::InitialPass(std::vector const& a const char* dir = m_Makefile->GetDefinition(i->c_str()); if( dir ) { - m_Makefile->AddLinkDirectory( dir ); + m_Makefile->AddLinkDirectoryForTarget(args[0].c_str(), dir ); } } else { - m_Makefile->AddLinkDirectory( ldir ); + m_Makefile->AddLinkDirectoryForTarget(args[0].c_str(), ldir ); } } return true; diff --git a/Source/cmUnixMakefileGenerator.cxx b/Source/cmUnixMakefileGenerator.cxx index 9a31a20844..5609bda1e0 100644 --- a/Source/cmUnixMakefileGenerator.cxx +++ b/Source/cmUnixMakefileGenerator.cxx @@ -890,22 +890,6 @@ void cmUnixMakefileGenerator::OutputDependLibs(std::ostream& fout) // A library should not depend on itself! 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. const cmTarget::LinkLibraries& tlibs = l->second.GetLinkLibraries(); for(cmTarget::LinkLibraries::const_iterator lib = tlibs.begin(); diff --git a/Tests/Complex/Executable/CMakeLists.txt b/Tests/Complex/Executable/CMakeLists.txt index 30c60fe6da..72b77fa549 100644 --- a/Tests/Complex/Executable/CMakeLists.txt +++ b/Tests/Complex/Executable/CMakeLists.txt @@ -5,22 +5,16 @@ CMAKE_MINIMUM_REQUIRED(VERSION 1.3) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTEST_CXX_FLAGS") SET_SOURCE_FILES_PROPERTIES(complex COMPILE_FLAGS "-DFILE_HAS_EXTRA_COMPILE_FLAGS") -ADD_EXECUTABLE(complex complex) -SET(COMPLEX_LIBS CMakeTestLibrary;CMakeTestLibraryShared;CMakeTestCLibraryShared) - +# Link to CMake lib +LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Source) # Use LINK_LIBRARIES instead of TARGET_LINK_LIBRARIES to +SET(COMPLEX_LIBS CMakeTestLibrary;CMakeTestLibraryShared;CMakeTestCLibraryShared) 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 - CMakeLib - debug CMakeLib - optimized CMakeLib) + CMakeLib) # # Output the files required by 'complex' to a file. diff --git a/Tests/ComplexOneConfig/Executable/CMakeLists.txt b/Tests/ComplexOneConfig/Executable/CMakeLists.txt index 30c60fe6da..72b77fa549 100644 --- a/Tests/ComplexOneConfig/Executable/CMakeLists.txt +++ b/Tests/ComplexOneConfig/Executable/CMakeLists.txt @@ -5,22 +5,16 @@ CMAKE_MINIMUM_REQUIRED(VERSION 1.3) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTEST_CXX_FLAGS") SET_SOURCE_FILES_PROPERTIES(complex COMPILE_FLAGS "-DFILE_HAS_EXTRA_COMPILE_FLAGS") -ADD_EXECUTABLE(complex complex) -SET(COMPLEX_LIBS CMakeTestLibrary;CMakeTestLibraryShared;CMakeTestCLibraryShared) - +# Link to CMake lib +LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Source) # Use LINK_LIBRARIES instead of TARGET_LINK_LIBRARIES to +SET(COMPLEX_LIBS CMakeTestLibrary;CMakeTestLibraryShared;CMakeTestCLibraryShared) 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 - CMakeLib - debug CMakeLib - optimized CMakeLib) + CMakeLib) # # Output the files required by 'complex' to a file. diff --git a/Tests/ComplexRelativePaths/Executable/CMakeLists.txt b/Tests/ComplexRelativePaths/Executable/CMakeLists.txt index 30c60fe6da..72b77fa549 100644 --- a/Tests/ComplexRelativePaths/Executable/CMakeLists.txt +++ b/Tests/ComplexRelativePaths/Executable/CMakeLists.txt @@ -5,22 +5,16 @@ CMAKE_MINIMUM_REQUIRED(VERSION 1.3) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DTEST_CXX_FLAGS") SET_SOURCE_FILES_PROPERTIES(complex COMPILE_FLAGS "-DFILE_HAS_EXTRA_COMPILE_FLAGS") -ADD_EXECUTABLE(complex complex) -SET(COMPLEX_LIBS CMakeTestLibrary;CMakeTestLibraryShared;CMakeTestCLibraryShared) - +# Link to CMake lib +LINK_DIRECTORIES(${Complex_BINARY_DIR}/../../Source) # Use LINK_LIBRARIES instead of TARGET_LINK_LIBRARIES to +SET(COMPLEX_LIBS CMakeTestLibrary;CMakeTestLibraryShared;CMakeTestCLibraryShared) 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 - CMakeLib - debug CMakeLib - optimized CMakeLib) + CMakeLib) # # Output the files required by 'complex' to a file. diff --git a/Tests/Dependency/Exec/CMakeLists.txt b/Tests/Dependency/Exec/CMakeLists.txt index 1867b1d9d5..97fffe706d 100644 --- a/Tests/Dependency/Exec/CMakeLists.txt +++ b/Tests/Dependency/Exec/CMakeLists.txt @@ -1,6 +1,7 @@ -ADD_EXECUTABLE( exec ExecMain.c ) - # This executable directly depends on NoDepB, NoDepC, SixA and SixB. However, # since NoDepB and NoDepC do not have explicit dependency information, # and they depend on NoDepA, we have to manually specify that dependency. LINK_LIBRARIES( NoDepB NoDepC NoDepA SixB SixA ) + +ADD_EXECUTABLE( exec ExecMain.c ) + diff --git a/Tests/Dependency/Six/CMakeLists.txt b/Tests/Dependency/Six/CMakeLists.txt index 2cb15864a1..d0abdd6957 100644 --- a/Tests/Dependency/Six/CMakeLists.txt +++ b/Tests/Dependency/Six/CMakeLists.txt @@ -3,10 +3,10 @@ # specify them in the correct order. LINK_LIBRARIES( Two ) +LINK_LIBRARIES( Five ) ADD_LIBRARY( SixA SixASrc.c ) ADD_LIBRARY( SixB SixBSrc.c ) TARGET_LINK_LIBRARIES( SixB Four ) -LINK_LIBRARIES( Five )