ENH: Report an error when ADD_LIBRARY and TARGET_LINK_LIBRARIES are in the wrong order and fix CMakeLists files to actually work
This commit is contained in:
parent
7e54a53a3d
commit
6c65c77d35
|
@ -57,6 +57,9 @@ SET(KWSYS_USE_Process 1)
|
|||
SET(KWSYS_HEADER_ROOT ${CMake_BINARY_DIR}/Source)
|
||||
SUBDIRS(Source/kwsys)
|
||||
|
||||
SET(CMAKE_BUILD_WITH_CURL 1)
|
||||
SUBDIRS(Source/CTest/Curl)
|
||||
|
||||
SUBDIRS(Source Modules Templates Utilities)
|
||||
ENABLE_TESTING()
|
||||
|
||||
|
|
|
@ -81,6 +81,19 @@ IF (WIN32)
|
|||
cmWin32ProcessExecution.cxx
|
||||
cmWin32ProcessExecution.h
|
||||
)
|
||||
ENDIF(NOT UNIX)
|
||||
ENDIF (WIN32)
|
||||
|
||||
# create a library used by the command line and the GUI
|
||||
ADD_LIBRARY(CMakeLib ${SRCS})
|
||||
TARGET_LINK_LIBRARIES(CMakeLib cmsys)
|
||||
|
||||
# always link in the library
|
||||
# the library is found here
|
||||
LINK_DIRECTORIES(${CMake_BINARY_DIR}/Source)
|
||||
|
||||
IF (WIN32)
|
||||
IF(NOT UNIX)
|
||||
IF( NOT BORLAND )
|
||||
LINK_LIBRARIES( rpcrt4.lib )
|
||||
ADD_EXECUTABLE(cmw9xcom cmw9xcom.cxx)
|
||||
|
@ -90,15 +103,6 @@ IF (WIN32)
|
|||
ENDIF(NOT UNIX)
|
||||
ENDIF (WIN32)
|
||||
|
||||
# create a library used by the command line and the GUI
|
||||
ADD_LIBRARY(CMakeLib ${SRCS})
|
||||
|
||||
TARGET_LINK_LIBRARIES(CMakeLib cmsys)
|
||||
|
||||
# always link in the library
|
||||
# the library is found here
|
||||
LINK_DIRECTORIES(${CMake_BINARY_DIR}/Source)
|
||||
|
||||
ADD_EXECUTABLE(cmake cmakemain.cxx)
|
||||
ADD_EXECUTABLE(DumpDocumentation cmDumpDocumentation)
|
||||
|
||||
|
@ -111,7 +115,6 @@ ENDIF (UNIX)
|
|||
TARGET_LINK_LIBRARIES(cmake CMakeLib)
|
||||
TARGET_LINK_LIBRARIES(DumpDocumentation CMakeLib)
|
||||
|
||||
SET(CMAKE_BUILD_WITH_CURL 1)
|
||||
IF(CMAKE_BUILD_WITH_CURL)
|
||||
SUBDIRS(CTest)
|
||||
SET(CMTEST_SRCS ${CMTEST_SRCS} CTest/cmCTestSubmit.cxx)
|
||||
|
|
|
@ -8,11 +8,11 @@ IF(CMAKE_SYSTEM MATCHES "AIX.*")
|
|||
ENDIF(NOT CMAKE_COMPILER_IS_GNUCXX)
|
||||
ENDIF(CMAKE_SYSTEM MATCHES "AIX.*")
|
||||
|
||||
SUBDIRS(Curl)
|
||||
|
||||
IF(CMAKE_BUILD_WITH_CURL)
|
||||
SET(CMAKE_LIBRARY CMakeLib)
|
||||
ELSE(CMAKE_BUILD_WITH_CURL)
|
||||
SUBDIRS(Curl)
|
||||
FIND_LIBRARY(CMAKE_LIBRARY NAMES CMakeLib PATHS
|
||||
${CTEST_BINARY_DIR}/..
|
||||
${CTEST_BINARY_DIR}/../Source
|
||||
|
|
|
@ -25,6 +25,9 @@ bool cmTargetLinkLibrariesCommand::InitialPass(std::vector<std::string> const& a
|
|||
this->SetError("called with incorrect number of arguments");
|
||||
return false;
|
||||
}
|
||||
|
||||
m_TargetName = args[0];
|
||||
|
||||
// but we might not have any libs after variable expansion
|
||||
if(args.size() < 2)
|
||||
{
|
||||
|
@ -59,11 +62,16 @@ bool cmTargetLinkLibrariesCommand::InitialPass(std::vector<std::string> const& a
|
|||
if (cmSystemTools::IsOff(ldir))
|
||||
{
|
||||
std::string libPath = *i + "_CMAKE_PATH";
|
||||
|
||||
const char* dir = m_Makefile->GetDefinition(libPath.c_str());
|
||||
if( dir )
|
||||
{
|
||||
m_Makefile->AddLinkDirectoryForTarget(args[0].c_str(), dir );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_HasLocation.push_back(*i);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -73,3 +81,23 @@ bool cmTargetLinkLibrariesCommand::InitialPass(std::vector<std::string> const& a
|
|||
return true;
|
||||
}
|
||||
|
||||
void cmTargetLinkLibrariesCommand::FinalPass()
|
||||
{
|
||||
std::vector<std::string>::size_type cc;
|
||||
std::string libPath;
|
||||
for ( cc = 0; cc < m_HasLocation.size(); cc ++ )
|
||||
{
|
||||
libPath = m_HasLocation[cc] + "_CMAKE_PATH";
|
||||
const char* dir = m_Makefile->GetDefinition(libPath.c_str());
|
||||
if ( dir )
|
||||
{
|
||||
std::string str = "Library " + m_HasLocation[cc] +
|
||||
" is defined using ADD_LIBRARY after the library is used "
|
||||
"using TARGET_LINK_LIBRARIES for the target " + m_TargetName +
|
||||
". This breaks CMake's dependency "
|
||||
"handling. Please fix the CMakeLists.txt file.";
|
||||
this->SetError(str.c_str());
|
||||
cmSystemTools::Message(str.c_str(), "CMake Error");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,6 +44,11 @@ public:
|
|||
*/
|
||||
virtual bool InitialPass(std::vector<std::string> const& args);
|
||||
|
||||
/**
|
||||
* Verify that the ordering in CMake is correct.
|
||||
*/
|
||||
virtual void FinalPass();
|
||||
|
||||
/**
|
||||
* The name of the command as specified in CMakeList.txt.
|
||||
*/
|
||||
|
@ -74,6 +79,9 @@ public:
|
|||
}
|
||||
|
||||
cmTypeMacro(cmTargetLinkLibrariesCommand, cmCommand);
|
||||
private:
|
||||
std::vector<std::string> m_HasLocation;
|
||||
std::string m_TargetName;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue