summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2012-11-25 00:15:44 (GMT)
committerBrad King <brad.king@kitware.com>2013-01-08 19:14:27 (GMT)
commit9ce1b9ef2946ead0605e766c7dcf1302fe122f3a (patch)
treedc757e71d66b28948a587c16e2a8b965ccffde01
parentc2cde7f1047b2f11e7d4a466000a20d8c42394be (diff)
downloadCMake-9ce1b9ef2946ead0605e766c7dcf1302fe122f3a.zip
CMake-9ce1b9ef2946ead0605e766c7dcf1302fe122f3a.tar.gz
CMake-9ce1b9ef2946ead0605e766c7dcf1302fe122f3a.tar.bz2
Add CMAKE_BUILD_INTERFACE_INCLUDES build-variable.
This makes set(CMAKE_BUILD_INTERFACE_INCLUDES ON) add the equivalent of set_property(TARGET tgt APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_BINARY_DIR}> ) to every target. If the headers are in CMAKE_CURRENT_SOURCE_DIR, and the generated headers are in CMAKE_CURRENT_BINARY_DIR, this is a convenient way to build a target bar, which depends on foo, just by using target_link_libraries() and adding the INTERFACE_INCLUDE_DIRECTORIES to the INCLUDE_DIRECTORIES of the target being linked. There will be more-convenient porcelain API to consume the property in the future.
-rw-r--r--Source/cmDocumentVariables.cxx11
-rw-r--r--Source/cmGlobalGenerator.cxx17
-rw-r--r--Tests/CMakeCommands/target_link_libraries/CMakeLists.txt7
-rw-r--r--Tests/CMakeCommands/target_link_libraries/subdir/CMakeLists.txt5
-rw-r--r--Tests/CMakeCommands/target_link_libraries/subdir/subdirlib.cpp7
-rw-r--r--Tests/CMakeCommands/target_link_libraries/subdir/subdirlib.h12
-rw-r--r--Tests/CMakeCommands/target_link_libraries/targetA.cpp6
7 files changed, 64 insertions, 1 deletions
diff --git a/Source/cmDocumentVariables.cxx b/Source/cmDocumentVariables.cxx
index be45e2d..08b3ef1 100644
--- a/Source/cmDocumentVariables.cxx
+++ b/Source/cmDocumentVariables.cxx
@@ -1147,6 +1147,17 @@ void cmDocumentVariables::DefineVariables(cmake* cm)
"Variables that Control the Build");
cm->DefineProperty
+ ("CMAKE_BUILD_INTERFACE_INCLUDES", cmProperty::VARIABLE,
+ "Automatically add the current source- and build directories "
+ "to the INTERFACE_INCLUDE_DIRECTORIES.",
+ "If this variable is enabled, CMake automatically adds for each "
+ "target ${CMAKE_CURRENT_SOURCE_DIR} and ${CMAKE_CURRENT_BINARY_DIR} "
+ "to the INTERFACE_INCLUDE_DIRECTORIES."
+ "By default CMAKE_BUILD_INTERFACE_INCLUDES is OFF.",
+ false,
+ "Variables that Control the Build");
+
+ cm->DefineProperty
("CMAKE_INSTALL_RPATH", cmProperty::VARIABLE,
"The rpath to use for installed targets.",
"A semicolon-separated list specifying the rpath "
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index 0f439e9..d030aa7 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -938,6 +938,23 @@ void cmGlobalGenerator::Generate()
(*targets)[tit->first] = tit->second;
(*targets)[tit->first].SetMakefile(mf);
}
+
+ for ( tit = targets->begin(); tit != targets->end(); ++ tit )
+ {
+ if (mf->IsOn("CMAKE_BUILD_INTERFACE_INCLUDES"))
+ {
+ const char *binDir = mf->GetStartOutputDirectory();
+ const char *srcDir = mf->GetStartDirectory();
+ const std::string dirs = std::string(binDir ? binDir : "")
+ + std::string(binDir ? ";" : "")
+ + std::string(srcDir ? srcDir : "");
+ if (!dirs.empty())
+ {
+ tit->second.AppendProperty("INTERFACE_INCLUDE_DIRECTORIES",
+ ("$<BUILD_INTERFACE:" + dirs + ">").c_str());
+ }
+ }
+ }
}
// Add generator specific helper commands
diff --git a/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt b/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt
index 60b36fc..29b69d9 100644
--- a/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt
+++ b/Tests/CMakeCommands/target_link_libraries/CMakeLists.txt
@@ -53,6 +53,13 @@ set_target_properties(targetA PROPERTIES LINK_INTERFACE_LIBRARIES "")
assert_property(targetA LINK_INTERFACE_LIBRARIES "")
+add_subdirectory(subdir)
+target_link_libraries(targetA subdirlib)
+set_property(TARGET targetA APPEND PROPERTY
+ INCLUDE_DIRECTORIES
+ $<TARGET_PROPERTY:subdirlib,INTERFACE_INCLUDE_DIRECTORIES>
+)
+
target_link_libraries(targetA depB depC)
assert_property(targetA LINK_INTERFACE_LIBRARIES "")
diff --git a/Tests/CMakeCommands/target_link_libraries/subdir/CMakeLists.txt b/Tests/CMakeCommands/target_link_libraries/subdir/CMakeLists.txt
new file mode 100644
index 0000000..61a1a59
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/subdir/CMakeLists.txt
@@ -0,0 +1,5 @@
+
+set(CMAKE_BUILD_INTERFACE_INCLUDES ON)
+
+add_library(subdirlib SHARED subdirlib.cpp)
+generate_export_header(subdirlib)
diff --git a/Tests/CMakeCommands/target_link_libraries/subdir/subdirlib.cpp b/Tests/CMakeCommands/target_link_libraries/subdir/subdirlib.cpp
new file mode 100644
index 0000000..cd2f1a2
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/subdir/subdirlib.cpp
@@ -0,0 +1,7 @@
+
+#include "subdirlib.h"
+
+int SubDirLibObject::foo() const
+{
+ return 0;
+}
diff --git a/Tests/CMakeCommands/target_link_libraries/subdir/subdirlib.h b/Tests/CMakeCommands/target_link_libraries/subdir/subdirlib.h
new file mode 100644
index 0000000..e386f87
--- /dev/null
+++ b/Tests/CMakeCommands/target_link_libraries/subdir/subdirlib.h
@@ -0,0 +1,12 @@
+
+#ifndef SUBDIRLIB_H
+#define SUBDIRLIB_H
+
+#include "subdirlib_export.h"
+
+struct SUBDIRLIB_EXPORT SubDirLibObject
+{
+ int foo() const;
+};
+
+#endif
diff --git a/Tests/CMakeCommands/target_link_libraries/targetA.cpp b/Tests/CMakeCommands/target_link_libraries/targetA.cpp
index 6ff65b1..559aef7 100644
--- a/Tests/CMakeCommands/target_link_libraries/targetA.cpp
+++ b/Tests/CMakeCommands/target_link_libraries/targetA.cpp
@@ -3,6 +3,8 @@
#include "depC.h"
#include "depIfaceOnly.h"
+#include "subdirlib.h"
+
int main(int argc, char **argv)
{
DepA a;
@@ -11,5 +13,7 @@ int main(int argc, char **argv)
DepIfaceOnly iface_only;
- return a.foo() + b.foo() + c.foo() + iface_only.foo();
+ SubDirLibObject sd;
+
+ return a.foo() + b.foo() + c.foo() + iface_only.foo() + sd.foo();
}