diff options
author | Stephen Kelly <steveire@gmail.com> | 2014-11-27 00:04:33 (GMT) |
---|---|---|
committer | Stephen Kelly <steveire@gmail.com> | 2014-11-29 11:24:59 (GMT) |
commit | bb5905bb1342229c06cecee735322a8a28916b76 (patch) | |
tree | 38549e8a26392cf29f49c87b81229e93dd7e19a2 /Tests/RunCMake/TargetSources | |
parent | d2f2a2e226a8717d6fdb6df0ed4858d1629f557c (diff) | |
download | CMake-bb5905bb1342229c06cecee735322a8a28916b76.zip CMake-bb5905bb1342229c06cecee735322a8a28916b76.tar.gz CMake-bb5905bb1342229c06cecee735322a8a28916b76.tar.bz2 |
cmTarget: Don't allow relative paths in INTERFACE_SOURCES
Follow the pattern of checks that are made for INTERFACE_INCLUDE_DIRECTORIES.
Existence is already checked by cmSourceFile::GetFullPath. Add a check
to disallow relative paths in source directories. Otherwise code such as
target_sources(lib1 INTERFACE foo.cpp)
would fail if consumed by a target in a different directory.
Unlike the INTERFACE_INCLUDE_DIRECTORIES behavior, we don't care whether
the entry comes from an IMPORTED target or not. In the include directories
case, the directory for a non-imported target might not exist yet but
might be created. In the sources case, a file which does not yet
exist in the filesystem must be explicitly marked with the GENERATED
property.
Adjust existing tests and add a new test for the error.
Diffstat (limited to 'Tests/RunCMake/TargetSources')
6 files changed, 18 insertions, 1 deletions
diff --git a/Tests/RunCMake/TargetSources/OriginDebug.cmake b/Tests/RunCMake/TargetSources/OriginDebug.cmake index 5fe9ba7..d40a1d8 100644 --- a/Tests/RunCMake/TargetSources/OriginDebug.cmake +++ b/Tests/RunCMake/TargetSources/OriginDebug.cmake @@ -7,7 +7,7 @@ set(CMAKE_DEBUG_TARGET_PROPERTIES SOURCES) add_library(iface INTERFACE) set_property(TARGET iface PROPERTY INTERFACE_SOURCES - empty_1.cpp + "${CMAKE_CURRENT_SOURCE_DIR}/empty_1.cpp" ) add_library(OriginDebug empty_2.cpp) diff --git a/Tests/RunCMake/TargetSources/RelativePathInInterface-result.txt b/Tests/RunCMake/TargetSources/RelativePathInInterface-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/TargetSources/RelativePathInInterface-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/TargetSources/RelativePathInInterface-stderr.txt b/Tests/RunCMake/TargetSources/RelativePathInInterface-stderr.txt new file mode 100644 index 0000000..d47dd4d --- /dev/null +++ b/Tests/RunCMake/TargetSources/RelativePathInInterface-stderr.txt @@ -0,0 +1,4 @@ +CMake Error in CMakeLists.txt: + Target "iface" contains relative path in its INTERFACE_SOURCES: + + "empty_1.cpp" diff --git a/Tests/RunCMake/TargetSources/RelativePathInInterface.cmake b/Tests/RunCMake/TargetSources/RelativePathInInterface.cmake new file mode 100644 index 0000000..8bb6149 --- /dev/null +++ b/Tests/RunCMake/TargetSources/RelativePathInInterface.cmake @@ -0,0 +1,6 @@ + +add_library(iface INTERFACE) +target_sources(iface INTERFACE empty_1.cpp) + +add_executable(main main.cpp) +target_link_libraries(main iface) diff --git a/Tests/RunCMake/TargetSources/RunCMakeTest.cmake b/Tests/RunCMake/TargetSources/RunCMakeTest.cmake index 1d2eaec..c6d7f43 100644 --- a/Tests/RunCMake/TargetSources/RunCMakeTest.cmake +++ b/Tests/RunCMake/TargetSources/RunCMakeTest.cmake @@ -8,3 +8,4 @@ else() endif() run_cmake(CMP0026-LOCATION) +run_cmake(RelativePathInInterface) diff --git a/Tests/RunCMake/TargetSources/main.cpp b/Tests/RunCMake/TargetSources/main.cpp new file mode 100644 index 0000000..766b775 --- /dev/null +++ b/Tests/RunCMake/TargetSources/main.cpp @@ -0,0 +1,5 @@ + +int main() +{ + return 0; +} |