Honor custom command dependencies on imported targets (#10395)

Imported targets do not themselves build, but we can follow dependencies
through them to find real targets.  This allows imported targets to
depend on custom targets that provide the underlying files at build
time.
This commit is contained in:
Brad King 2010-12-08 12:22:13 -05:00
parent e01cce2869
commit a765c491ad
2 changed files with 52 additions and 12 deletions

View File

@ -1357,8 +1357,8 @@ bool cmTargetTraceDependencies::IsUtility(std::string const& dep)
util = cmSystemTools::GetFilenameWithoutLastExtension(util);
}
// Check for a non-imported target with this name.
if(cmTarget* t = this->GlobalGenerator->FindTarget(0, util.c_str()))
// Check for a target with this name.
if(cmTarget* t = this->Makefile->FindTargetToUse(util.c_str()))
{
// If we find the target and the dep was given as a full path,
// then make sure it was not a full path to something else, and
@ -1406,8 +1406,8 @@ cmTargetTraceDependencies
cit != cc.GetCommandLines().end(); ++cit)
{
std::string const& command = *cit->begin();
// Look for a non-imported target with this name.
if(cmTarget* t = this->GlobalGenerator->FindTarget(0, command.c_str()))
// Check for a target with this name.
if(cmTarget* t = this->Makefile->FindTargetToUse(command.c_str()))
{
if(t->GetType() == cmTarget::EXECUTABLE)
{

View File

@ -75,24 +75,64 @@ foreach(c DEBUG RELWITHDEBINFO)
set_property(TARGET imp_testExe1b PROPERTY COMPILE_DEFINITIONS_${c} EXE_DBG)
endforeach(c)
#-----------------------------------------------------------------------------
# Create a custom target to generate a header for the libraries below.
include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_custom_command(
OUTPUT testLib2.h
VERBATIM COMMAND
${CMAKE_COMMAND} -E echo "extern int testLib2(void);" > testLib2.h
)
add_custom_target(hdr_testLib2 DEPENDS testLib2.h)
# Drive the header generation through an indirect chain of imported
# target dependencies.
# testLib2tmp1.h
add_custom_command(
OUTPUT testLib2tmp1.h
VERBATIM COMMAND
${CMAKE_COMMAND} -E echo "extern int testLib2(void);" > testLib2tmp1.h
)
# hdr_testLib2tmp1 needs testLib2tmp1.h
add_custom_target(hdr_testLib2tmp1 DEPENDS testLib2tmp1.h)
# exp_testExe2 needs hdr_testLib2tmp1
add_dependencies(exp_testExe2 hdr_testLib2tmp1)
# testLib2tmp.h needs exp_testExe2
add_custom_command(
OUTPUT testLib2tmp.h
VERBATIM COMMAND exp_testExe2
COMMAND ${CMAKE_COMMAND} -E copy testLib2tmp1.h testLib2tmp.h
)
# hdr_testLib2tmp needs testLib2tmp.h
add_custom_target(hdr_testLib2tmp DEPENDS testLib2tmp.h)
add_library(dep_testLib2tmp UNKNOWN IMPORTED)
set_property(TARGET dep_testLib2tmp PROPERTY
IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/testLib2tmp.h)
# dep_testLib2tmp needs hdr_testLib2tmp
add_dependencies(dep_testLib2tmp hdr_testLib2tmp)
# testLib2.h needs dep_testLib2tmp
add_custom_command(
OUTPUT testLib2.h
VERBATIM COMMAND ${CMAKE_COMMAND} -E copy testLib2tmp.h testLib2.h
DEPENDS dep_testLib2tmp
)
# hdr_testLib2 needs testLib2.h
add_custom_target(hdr_testLib2 DEPENDS testLib2.h)
add_library(dep_testLib2 UNKNOWN IMPORTED)
# dep_testLib2 needs hdr_testLib2
add_dependencies(dep_testLib2 hdr_testLib2)
# exp_testLib2 and bld_testLib2 both need dep_testLib2
add_dependencies(bld_testLib2 dep_testLib2)
add_dependencies(exp_testLib2 dep_testLib2)
#-----------------------------------------------------------------------------
# Create a library to be linked by another directory in this project
# to test transitive linking to otherwise invisible imported targets.
include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_library(imp_lib1 STATIC imp_lib1.c)
target_link_libraries(imp_lib1 exp_testLib2)
add_library(imp_lib1b STATIC imp_lib1.c)