Whitelist target types in target_{include_directories,compile_definitions}

Setting include directories or compile definitions on a target created
with add_custom_target does not make sense.
This commit is contained in:
Stephen Kelly 2013-02-08 19:12:45 +01:00
parent 4de71786e8
commit 510fdcb188
6 changed files with 22 additions and 1 deletions

View File

@ -38,6 +38,15 @@ bool cmTargetPropCommandBase
this->HandleMissingTarget(args[0]); this->HandleMissingTarget(args[0]);
return false; return false;
} }
if ((this->Target->GetType() != cmTarget::SHARED_LIBRARY)
&& (this->Target->GetType() != cmTarget::STATIC_LIBRARY)
&& (this->Target->GetType() != cmTarget::OBJECT_LIBRARY)
&& (this->Target->GetType() != cmTarget::MODULE_LIBRARY)
&& (this->Target->GetType() != cmTarget::EXECUTABLE))
{
this->SetError("called with non-compilable target type");
return false;
}
unsigned int argIndex = 1; unsigned int argIndex = 1;

View File

@ -13,6 +13,6 @@ add_custom_command(
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/a1.c.in COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/a1.c.in
${CMAKE_CURRENT_BINARY_DIR}/a1.c ${CMAKE_CURRENT_BINARY_DIR}/a1.c
) )
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
add_library(A OBJECT a1.c a2.c) add_library(A OBJECT a1.c a2.c)
target_include_directories(A PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

View File

@ -2,3 +2,4 @@ include(RunCMake)
run_cmake(NotFoundContent) run_cmake(NotFoundContent)
run_cmake(DebugIncludes) run_cmake(DebugIncludes)
run_cmake(TID-bad-target)

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,4 @@
CMake Error at TID-bad-target.cmake:6 \(target_include_directories\):
target_include_directories called with non-compilable target type
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)

View File

@ -0,0 +1,6 @@
add_custom_target(check ALL
COMMAND ${CMAKE_COMMAND} -E echo check
)
target_include_directories(check PRIVATE somedir)