summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2013-01-12 11:11:29 (GMT)
committerBrad King <brad.king@kitware.com>2013-01-15 19:36:22 (GMT)
commit4ee872cb99f49ac5a95768da454f3313ba87182f (patch)
treecaa573a00cb61a298e5c8345be5c9a962753291e
parent1d47cd94f3748d287f676f3847d42f3674062dcd (diff)
downloadCMake-4ee872cb99f49ac5a95768da454f3313ba87182f.zip
CMake-4ee872cb99f49ac5a95768da454f3313ba87182f.tar.gz
CMake-4ee872cb99f49ac5a95768da454f3313ba87182f.tar.bz2
Make the BUILD_INTERFACE of export()ed targets work.
The existing BUILD_INTERFACE code is executed at generate time, which is too late for export().
-rw-r--r--Source/cmExportBuildFileGenerator.cxx2
-rw-r--r--Source/cmGlobalGenerator.cxx14
-rw-r--r--Source/cmTarget.cxx25
-rw-r--r--Source/cmTarget.h3
-rw-r--r--Tests/ExportImport/Export/CMakeLists.txt4
-rw-r--r--Tests/ExportImport/Export/sublib/CMakeLists.txt6
-rw-r--r--Tests/ExportImport/Export/sublib/subdir.cpp7
-rw-r--r--Tests/ExportImport/Export/sublib/subdir.h12
-rw-r--r--Tests/ExportImport/Import/A/CMakeLists.txt8
-rw-r--r--Tests/ExportImport/Import/A/deps_shared_iface.cpp14
10 files changed, 77 insertions, 18 deletions
diff --git a/Source/cmExportBuildFileGenerator.cxx b/Source/cmExportBuildFileGenerator.cxx
index ad61803..36c53dc 100644
--- a/Source/cmExportBuildFileGenerator.cxx
+++ b/Source/cmExportBuildFileGenerator.cxx
@@ -62,6 +62,8 @@ bool cmExportBuildFileGenerator::GenerateMainFile(std::ostream& os)
cmTarget* te = *tei;
this->GenerateImportTargetCode(os, te);
+ te->AppendBuildInterfaceIncludes();
+
ImportPropertyMap properties;
this->PopulateInterfaceProperty("INTERFACE_INCLUDE_DIRECTORIES", te,
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index d030aa7..d2baf53 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -941,19 +941,7 @@ void cmGlobalGenerator::Generate()
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());
- }
- }
+ tit->second.AppendBuildInterfaceIncludes();
}
}
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index 9b50b8e..cf01f9f 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -150,6 +150,7 @@ cmTarget::cmTarget()
this->DLLPlatform = false;
this->IsApple = false;
this->IsImportedTarget = false;
+ this->BuildInterfaceIncludesAppended = false;
}
//----------------------------------------------------------------------------
@@ -2655,6 +2656,30 @@ void cmTarget::AppendProperty(const char* prop, const char* value,
}
//----------------------------------------------------------------------------
+void cmTarget::AppendBuildInterfaceIncludes()
+{
+ if (this->BuildInterfaceIncludesAppended)
+ {
+ return;
+ }
+ this->BuildInterfaceIncludesAppended = true;
+
+ if (this->Makefile->IsOn("CMAKE_BUILD_INTERFACE_INCLUDES"))
+ {
+ const char *binDir = this->Makefile->GetStartOutputDirectory();
+ const char *srcDir = this->Makefile->GetStartDirectory();
+ const std::string dirs = std::string(binDir ? binDir : "")
+ + std::string(binDir ? ";" : "")
+ + std::string(srcDir ? srcDir : "");
+ if (!dirs.empty())
+ {
+ this->AppendProperty("INTERFACE_INCLUDE_DIRECTORIES",
+ ("$<BUILD_INTERFACE:" + dirs + ">").c_str());
+ }
+ }
+}
+
+//----------------------------------------------------------------------------
void cmTarget::InsertInclude(const cmMakefileIncludeDirectoriesEntry &entry,
bool before)
{
diff --git a/Source/cmTarget.h b/Source/cmTarget.h
index b4d053d..48dde0a 100644
--- a/Source/cmTarget.h
+++ b/Source/cmTarget.h
@@ -490,6 +490,8 @@ public:
void InsertInclude(const cmMakefileIncludeDirectoriesEntry &entry,
bool before = false);
+ void AppendBuildInterfaceIncludes();
+
void GetLinkDependentTargetsForProperty(const std::string &p,
std::set<std::string> &targets);
bool IsNullImpliedByLinkLibraries(const std::string &p);
@@ -611,6 +613,7 @@ private:
mutable std::map<cmStdString, std::set<std::string> >
LinkDependentProperties;
mutable std::set<std::string> LinkImplicitNullProperties;
+ bool BuildInterfaceIncludesAppended;
// Cache target output paths for each configuration.
struct OutputInfo;
diff --git a/Tests/ExportImport/Export/CMakeLists.txt b/Tests/ExportImport/Export/CMakeLists.txt
index 4f6ccd6..e92dcd8 100644
--- a/Tests/ExportImport/Export/CMakeLists.txt
+++ b/Tests/ExportImport/Export/CMakeLists.txt
@@ -247,9 +247,11 @@ if(WIN32)
install(TARGETS testLib5 RUNTIME DESTINATION bin)
endif()
+add_subdirectory(sublib) # For CMAKE_BUILD_INTERFACE_INCLUDES test.
+
# Export from build tree.
export(TARGETS testExe1 testLib1 testLib2 testLib3
- testExe2libImp testLib3Imp testLib3ImpDep
+ testExe2libImp testLib3Imp testLib3ImpDep subdirlib
testSharedLibRequired testSharedLibDepends
NAMESPACE bld_
FILE ExportBuildTree.cmake
diff --git a/Tests/ExportImport/Export/sublib/CMakeLists.txt b/Tests/ExportImport/Export/sublib/CMakeLists.txt
new file mode 100644
index 0000000..2d11040
--- /dev/null
+++ b/Tests/ExportImport/Export/sublib/CMakeLists.txt
@@ -0,0 +1,6 @@
+
+set(CMAKE_BUILD_INTERFACE_INCLUDES ON)
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+add_library(subdirlib SHARED subdir.cpp)
+generate_export_header(subdirlib)
diff --git a/Tests/ExportImport/Export/sublib/subdir.cpp b/Tests/ExportImport/Export/sublib/subdir.cpp
new file mode 100644
index 0000000..35b0743
--- /dev/null
+++ b/Tests/ExportImport/Export/sublib/subdir.cpp
@@ -0,0 +1,7 @@
+
+#include "subdir.h"
+
+int SubDirObject::foo()
+{
+ return 0;
+}
diff --git a/Tests/ExportImport/Export/sublib/subdir.h b/Tests/ExportImport/Export/sublib/subdir.h
new file mode 100644
index 0000000..3a4b73d
--- /dev/null
+++ b/Tests/ExportImport/Export/sublib/subdir.h
@@ -0,0 +1,12 @@
+
+#ifndef SUBDIR_H
+#define SUBDIR_H
+
+#include "subdirlib_export.h"
+
+struct SUBDIRLIB_EXPORT SubDirObject
+{
+ int foo();
+};
+
+#endif
diff --git a/Tests/ExportImport/Import/A/CMakeLists.txt b/Tests/ExportImport/Import/A/CMakeLists.txt
index 6a2e54c..72d11b6 100644
--- a/Tests/ExportImport/Import/A/CMakeLists.txt
+++ b/Tests/ExportImport/Import/A/CMakeLists.txt
@@ -172,6 +172,8 @@ target_compile_definitions(deps_shared_iface PRIVATE testSharedLibDepends)
# evaluated correctly. The above already tests the same for the install tree.
add_executable(deps_shared_iface2 deps_shared_iface.cpp)
-target_link_libraries(deps_shared_iface2 bld_testSharedLibDepends)
-target_include_directories(deps_shared_iface2 PRIVATE bld_testSharedLibDepends)
-target_compile_definitions(deps_shared_iface2 PRIVATE bld_testSharedLibDepends)
+target_link_libraries(deps_shared_iface2 bld_testSharedLibDepends bld_subdirlib)
+target_include_directories(deps_shared_iface2 PRIVATE bld_testSharedLibDepends bld_subdirlib)
+target_compile_definitions(deps_shared_iface2
+ PRIVATE bld_testSharedLibDepends TEST_SUBDIR_LIB
+)
diff --git a/Tests/ExportImport/Import/A/deps_shared_iface.cpp b/Tests/ExportImport/Import/A/deps_shared_iface.cpp
index 4f7eb23..14aac0a 100644
--- a/Tests/ExportImport/Import/A/deps_shared_iface.cpp
+++ b/Tests/ExportImport/Import/A/deps_shared_iface.cpp
@@ -2,10 +2,22 @@
#include "testSharedLibDepends.h"
+#ifdef TEST_SUBDIR_LIB
+#include "subdir.h"
+#endif
+
int main(int,char **)
{
TestSharedLibDepends dep;
TestSharedLibRequired req;
- return dep.foo() + req.foo();
+#ifdef TEST_SUBDIR_LIB
+ SubDirObject sdo;
+#endif
+
+ return dep.foo() + req.foo()
+#ifdef TEST_SUBDIR_LIB
+ + sdo.foo()
+#endif
+ ;
}