summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2014-12-01 08:55:45 -0500
committerBrad King <brad.king@kitware.com>2014-12-01 08:55:45 -0500
commit58d3898083e1bf66f4ecf2e82a556e81f67ce5bc (patch)
tree582d63921aab0ef0e91ebbb6913999418476fed2
parentbaa283f9226a8c599523e9265cb85b809740ab31 (diff)
parent8a75c7ef32af391cb45af889d266e2a77daa61d6 (diff)
downloadcmake-58d3898083e1bf66f4ecf2e82a556e81f67ce5bc.tar.gz
Merge branch 'target-sources-error-conditions' into release
-rw-r--r--Help/command/target_sources.rst4
-rw-r--r--Help/prop_tgt/INTERFACE_SOURCES.rst4
-rw-r--r--Source/cmExportBuildFileGenerator.cxx10
-rw-r--r--Source/cmExportInstallFileGenerator.cxx11
-rw-r--r--Source/cmTarget.cxx26
-rw-r--r--Tests/ConfigSources/CMakeLists.txt6
-rw-r--r--Tests/RunCMake/TargetSources/ExportBuild-result.txt1
-rw-r--r--Tests/RunCMake/TargetSources/ExportBuild-stderr.txt1
-rw-r--r--Tests/RunCMake/TargetSources/ExportBuild.cmake5
-rw-r--r--Tests/RunCMake/TargetSources/ExportInstall-result.txt1
-rw-r--r--Tests/RunCMake/TargetSources/ExportInstall-stderr.txt1
-rw-r--r--Tests/RunCMake/TargetSources/ExportInstall.cmake6
-rw-r--r--Tests/RunCMake/TargetSources/OriginDebug.cmake2
-rw-r--r--Tests/RunCMake/TargetSources/RelativePathInInterface-result.txt1
-rw-r--r--Tests/RunCMake/TargetSources/RelativePathInInterface-stderr.txt4
-rw-r--r--Tests/RunCMake/TargetSources/RelativePathInInterface.cmake6
-rw-r--r--Tests/RunCMake/TargetSources/RunCMakeTest.cmake3
-rw-r--r--Tests/RunCMake/TargetSources/main.cpp5
-rw-r--r--Tests/SourcesProperty/CMakeLists.txt4
19 files changed, 93 insertions, 8 deletions
diff --git a/Help/command/target_sources.rst b/Help/command/target_sources.rst
index d6f148d237..832240ade3 100644
--- a/Help/command/target_sources.rst
+++ b/Help/command/target_sources.rst
@@ -22,6 +22,10 @@ items will populate the :prop_tgt:`SOURCES` property of
following arguments specify sources. Repeated calls for the same
``<target>`` append items in the order called.
+Targets with :prop_tgt:`INTERFACE_SOURCES` may not be exported with the
+:command:`export` or :command:`install(EXPORT)` commands. This limitation may be
+lifted in a future version of CMake.
+
Arguments to ``target_sources`` may use "generator expressions"
with the syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)`
manual for available expressions. See the :manual:`cmake-buildsystem(7)`
diff --git a/Help/prop_tgt/INTERFACE_SOURCES.rst b/Help/prop_tgt/INTERFACE_SOURCES.rst
index fb28231a31..c8ca2e83ae 100644
--- a/Help/prop_tgt/INTERFACE_SOURCES.rst
+++ b/Help/prop_tgt/INTERFACE_SOURCES.rst
@@ -9,6 +9,10 @@ targets can add entries to their own :prop_tgt:`SOURCES` property
such as ``$<TARGET_PROPERTY:foo,INTERFACE_SOURCES>`` to use the
sources specified in the interface of ``foo``.
+Targets with ``INTERFACE_SOURCES`` may not be exported with the
+:command:`export` or :command:`install(EXPORT)` commands. This limitation may be
+lifted in a future version of CMake.
+
Contents of ``INTERFACE_SOURCES`` may use "generator expressions"
with the syntax ``$<...>``. See the :manual:`cmake-generator-expressions(7)`
manual for available expressions. See the :manual:`cmake-buildsystem(7)`
diff --git a/Source/cmExportBuildFileGenerator.cxx b/Source/cmExportBuildFileGenerator.cxx
index 30a52d4764..134ee98aab 100644
--- a/Source/cmExportBuildFileGenerator.cxx
+++ b/Source/cmExportBuildFileGenerator.cxx
@@ -68,6 +68,16 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os)
tei != this->Exports.end(); ++tei)
{
cmTarget* te = *tei;
+ if (te->GetProperty("INTERFACE_SOURCES"))
+ {
+ cmOStringStream e;
+ e << "Target \""
+ << te->GetName()
+ << "\" has a populated INTERFACE_SOURCES property. This is not "
+ "currently supported.";
+ cmSystemTools::Error(e.str().c_str());
+ return false;
+ }
this->GenerateImportTargetCode(os, te);
te->AppendBuildInterfaceIncludes();
diff --git a/Source/cmExportInstallFileGenerator.cxx b/Source/cmExportInstallFileGenerator.cxx
index 89071c052c..23180f1bfb 100644
--- a/Source/cmExportInstallFileGenerator.cxx
+++ b/Source/cmExportInstallFileGenerator.cxx
@@ -123,6 +123,17 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os)
{
cmTarget* te = (*tei)->Target;
+ if (te->GetProperty("INTERFACE_SOURCES"))
+ {
+ cmOStringStream e;
+ e << "Target \""
+ << te->GetName()
+ << "\" has a populated INTERFACE_SOURCES property. This is not "
+ "currently supported.";
+ cmSystemTools::Error(e.str().c_str());
+ return false;
+ }
+
requiresConfigFiles = requiresConfigFiles
|| te->GetType() != cmTarget::INTERFACE_LIBRARY;
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index b476a2776e..ad1c83e573 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -649,6 +649,8 @@ static bool processSources(cmTarget const* tgt,
for (std::vector<cmTargetInternals::TargetPropertyEntry*>::const_iterator
it = entries.begin(), end = entries.end(); it != end; ++it)
{
+ cmLinkImplItem const& item = (*it)->LinkImplItem;
+ std::string const& targetName = item;
std::vector<std::string> entrySources;
cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf,
config,
@@ -667,11 +669,10 @@ static bool processSources(cmTarget const* tgt,
i != entrySources.end(); ++i)
{
std::string& src = *i;
-
cmSourceFile* sf = mf->GetOrCreateSource(src);
std::string e;
- src = sf->GetFullPath(&e);
- if(src.empty())
+ std::string fullPath = sf->GetFullPath(&e);
+ if(fullPath.empty())
{
if(!e.empty())
{
@@ -681,6 +682,25 @@ static bool processSources(cmTarget const* tgt,
}
return contextDependent;
}
+
+ if (!targetName.empty() && !cmSystemTools::FileIsFullPath(src.c_str()))
+ {
+ cmOStringStream err;
+ if (!targetName.empty())
+ {
+ err << "Target \"" << targetName << "\" contains relative "
+ "path in its INTERFACE_SOURCES:\n"
+ " \"" << src << "\"";
+ }
+ else
+ {
+ err << "Found relative path while evaluating sources of "
+ "\"" << tgt->GetName() << "\":\n \"" << src << "\"\n";
+ }
+ tgt->GetMakefile()->IssueMessage(cmake::FATAL_ERROR, err.str());
+ return contextDependent;
+ }
+ src = fullPath;
}
std::string usedSources;
for(std::vector<std::string>::iterator
diff --git a/Tests/ConfigSources/CMakeLists.txt b/Tests/ConfigSources/CMakeLists.txt
index c272257ca3..748aad8878 100644
--- a/Tests/ConfigSources/CMakeLists.txt
+++ b/Tests/ConfigSources/CMakeLists.txt
@@ -5,9 +5,9 @@ project(ConfigSources)
add_library(iface INTERFACE)
set_property(TARGET iface PROPERTY INTERFACE_SOURCES
- iface_src.cpp
- $<$<CONFIG:Debug>:iface_debug_src.cpp>
- $<$<CONFIG:Release>:does_not_exist.cpp>
+ "${CMAKE_CURRENT_SOURCE_DIR}/iface_src.cpp"
+ "$<$<CONFIG:Debug>:${CMAKE_CURRENT_SOURCE_DIR}/iface_debug_src.cpp>"
+ "$<$<CONFIG:Release>:${CMAKE_CURRENT_SOURCE_DIR}/does_not_exist.cpp>"
)
add_executable(ConfigSources
diff --git a/Tests/RunCMake/TargetSources/ExportBuild-result.txt b/Tests/RunCMake/TargetSources/ExportBuild-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/TargetSources/ExportBuild-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/TargetSources/ExportBuild-stderr.txt b/Tests/RunCMake/TargetSources/ExportBuild-stderr.txt
new file mode 100644
index 0000000000..0d65a558b2
--- /dev/null
+++ b/Tests/RunCMake/TargetSources/ExportBuild-stderr.txt
@@ -0,0 +1 @@
+CMake Error: Target "iface" has a populated INTERFACE_SOURCES property. This is not currently supported.
diff --git a/Tests/RunCMake/TargetSources/ExportBuild.cmake b/Tests/RunCMake/TargetSources/ExportBuild.cmake
new file mode 100644
index 0000000000..b626aa6cd1
--- /dev/null
+++ b/Tests/RunCMake/TargetSources/ExportBuild.cmake
@@ -0,0 +1,5 @@
+
+add_library(iface INTERFACE)
+target_sources(iface INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/empty_1.cpp")
+
+export(TARGETS iface FILE ${CMAKE_CURRENT_BINARY_DIR}/targets.cmake)
diff --git a/Tests/RunCMake/TargetSources/ExportInstall-result.txt b/Tests/RunCMake/TargetSources/ExportInstall-result.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/Tests/RunCMake/TargetSources/ExportInstall-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/TargetSources/ExportInstall-stderr.txt b/Tests/RunCMake/TargetSources/ExportInstall-stderr.txt
new file mode 100644
index 0000000000..0d65a558b2
--- /dev/null
+++ b/Tests/RunCMake/TargetSources/ExportInstall-stderr.txt
@@ -0,0 +1 @@
+CMake Error: Target "iface" has a populated INTERFACE_SOURCES property. This is not currently supported.
diff --git a/Tests/RunCMake/TargetSources/ExportInstall.cmake b/Tests/RunCMake/TargetSources/ExportInstall.cmake
new file mode 100644
index 0000000000..8e7c9f93f8
--- /dev/null
+++ b/Tests/RunCMake/TargetSources/ExportInstall.cmake
@@ -0,0 +1,6 @@
+
+add_library(iface INTERFACE)
+target_sources(iface INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/empty_1.cpp")
+
+install(TARGETS iface EXPORT exp)
+install(EXPORT exp DESTINATION cmake)
diff --git a/Tests/RunCMake/TargetSources/OriginDebug.cmake b/Tests/RunCMake/TargetSources/OriginDebug.cmake
index 5fe9ba75b2..d40a1d82a9 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 0000000000..d00491fd7e
--- /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 0000000000..d47dd4de30
--- /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 0000000000..8bb6149d9c
--- /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 1d2eaec669..1b4ef0bc1d 100644
--- a/Tests/RunCMake/TargetSources/RunCMakeTest.cmake
+++ b/Tests/RunCMake/TargetSources/RunCMakeTest.cmake
@@ -8,3 +8,6 @@ else()
endif()
run_cmake(CMP0026-LOCATION)
+run_cmake(RelativePathInInterface)
+run_cmake(ExportBuild)
+run_cmake(ExportInstall)
diff --git a/Tests/RunCMake/TargetSources/main.cpp b/Tests/RunCMake/TargetSources/main.cpp
new file mode 100644
index 0000000000..766b7751bf
--- /dev/null
+++ b/Tests/RunCMake/TargetSources/main.cpp
@@ -0,0 +1,5 @@
+
+int main()
+{
+ return 0;
+}
diff --git a/Tests/SourcesProperty/CMakeLists.txt b/Tests/SourcesProperty/CMakeLists.txt
index 6c99e00745..d1c35d8011 100644
--- a/Tests/SourcesProperty/CMakeLists.txt
+++ b/Tests/SourcesProperty/CMakeLists.txt
@@ -4,7 +4,9 @@ cmake_minimum_required(VERSION 3.0)
project(SourcesProperty)
add_library(iface INTERFACE)
-set_property(TARGET iface PROPERTY INTERFACE_SOURCES iface.cpp)
+set_property(TARGET iface PROPERTY INTERFACE_SOURCES
+ "${CMAKE_CURRENT_SOURCE_DIR}/iface.cpp"
+)
add_executable(SourcesProperty main.cpp)
target_link_libraries(SourcesProperty iface)