[Cmake-commits] CMake branch, next, updated. v3.1.0-rc3-1097-g52fe999

Stephen Kelly steveire at gmail.com
Mon Dec 8 14:53:01 EST 2014


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".

The branch, next has been updated
       via  52fe99979c62f63a26c836d2419d40a072710b44 (commit)
       via  9c32070ac60538282982236ec4c85c4dfab6b3c2 (commit)
       via  29f92485f1792cccd84077a0c5f5d452ba2a85aa (commit)
      from  9a6d37950af7a360578102c7d26d93c827e32d4d (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=52fe99979c62f63a26c836d2419d40a072710b44
commit 52fe99979c62f63a26c836d2419d40a072710b44
Merge: 9a6d379 9c32070
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Mon Dec 8 14:52:59 2014 -0500
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Mon Dec 8 14:52:59 2014 -0500

    Merge topic 'diagnose-invalid-_IMPORT_PREFIX-generation' into next
    
    9c32070a Export: Issue error if generating unusable export file (#15258).
    29f92485 Export: Diagnose issues in INCLUDES DESTINATION while generating (#15258).


http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=9c32070ac60538282982236ec4c85c4dfab6b3c2
commit 9c32070ac60538282982236ec4c85c4dfab6b3c2
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Mon Dec 8 19:29:56 2014 +0100
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Mon Dec 8 20:50:11 2014 +0100

    Export: Issue error if generating unusable export file (#15258).
    
    Diagnose presence of $<INSTALL_PREFIX> in exported target properties,
    as can appear in user code, or generated for relative paths inside
    a $<INSTALL_INTERFACE> generator expression.
    
    The case of use of install(TARGETS) with a relative path in
    INCLUDES DESTINATION would also be caught by this diagnostic, but
    that is handled separately because in that case the $<INSTALL_PREFIX>
    is generated by cmake internally, so a more-specific diagnostic is
    desired.
    
    Extend policy CMP0057 to cover this diagnostic.

diff --git a/Help/policy/CMP0057.rst b/Help/policy/CMP0057.rst
index 79da0b9..ddd2bf1 100644
--- a/Help/policy/CMP0057.rst
+++ b/Help/policy/CMP0057.rst
@@ -6,8 +6,12 @@ Error on absolute export with relative usage requirements.
 CMake 3.1 and lower generated unusable files with the
 :command:`install(EXPORT)` command if an absolute ``DESTINATION`` was used
 with it, and a relative path was passed to the ``INCLUDES DESTINATION`` of a
-target in the specified export set.  In such cases, a use of an internal
-variable was generated, although the internal variable was unset.
+target in the specified export set.  Unusable files could also be generated
+if the ``$<INSTALL_PREFIX>`` generator expression was used, despite an
+export with an absolute ``DESTINATION``, or if the ``$<INSTALL_INTERFACE>``
+generator expression was used containing a relative path.  In such cases,
+a use of an internal variable was generated, although the internal
+variable was unset.
 
 The ``OLD`` behavior for this policy is to issue a warning if a the
 :command:`install(EXPORT)` command generates such an unusable file.  The
diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx
index 1f39d7a..37956dc 100644
--- a/Source/cmExportFileGenerator.cxx
+++ b/Source/cmExportFileGenerator.cxx
@@ -171,7 +171,7 @@ void cmExportFileGenerator::PopulateInterfaceProperty(
                                                            preprocessRule);
     if (!prepro.empty())
       {
-      this->ResolveTargetsInGeneratorExpressions(prepro, target,
+      this->ResolveTargetsInGeneratorExpressions(propName, prepro, target,
                                                  missingTargets);
       properties[outputName] = prepro;
       }
@@ -205,7 +205,8 @@ bool cmExportFileGenerator::PopulateInterfaceLinkLibrariesProperty(
                                                            preprocessRule);
     if (!prepro.empty())
       {
-      this->ResolveTargetsInGeneratorExpressions(prepro, target,
+      this->ResolveTargetsInGeneratorExpressions("INTERFACE_LINK_LIBRARIES",
+                                                 prepro, target,
                                                  missingTargets,
                                                  ReplaceFreeTargets);
       properties["INTERFACE_LINK_LIBRARIES"] = prepro;
@@ -383,7 +384,8 @@ void cmExportFileGenerator::PopulateIncludeDirectoriesInterface(
                                             tei->InterfaceIncludeDirectories,
                                             preprocessRule,
                                             true);
-  this->ReplaceInstallPrefix(dirs);
+  this->ReplaceInstallPrefix(tei->Target, "INTERFACE_INCLUDE_DIRECTORIES",
+                             dirs);
   cmsys::auto_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(dirs);
   std::string exportDirs = cge->Evaluate(target->GetMakefile(), "",
                                          false, target);
@@ -421,8 +423,9 @@ void cmExportFileGenerator::PopulateIncludeDirectoriesInterface(
                                                          true);
   if (!prepro.empty())
     {
-    this->ResolveTargetsInGeneratorExpressions(prepro, target,
-                                                missingTargets);
+    this->ResolveTargetsInGeneratorExpressions("INTERFACE_INCLUDE_DIRECTORIES",
+                                               prepro, target,
+                                               missingTargets);
 
     if (!checkInterfaceDirs(prepro, target))
       {
@@ -607,6 +610,7 @@ cmExportFileGenerator::AddTargetNamespace(std::string &input,
 //----------------------------------------------------------------------------
 void
 cmExportFileGenerator::ResolveTargetsInGeneratorExpressions(
+                                    std::string const& propName,
                                     std::string &input,
                                     cmTarget* target,
                                     std::vector<std::string> &missingTargets,
@@ -614,7 +618,8 @@ cmExportFileGenerator::ResolveTargetsInGeneratorExpressions(
 {
   if (replace == NoReplaceFreeTargets)
     {
-    this->ResolveTargetsInGeneratorExpression(input, target, missingTargets);
+    this->ResolveTargetsInGeneratorExpression(propName, input,
+                                              target, missingTargets);
     return;
     }
   std::vector<std::string> parts;
@@ -631,7 +636,7 @@ cmExportFileGenerator::ResolveTargetsInGeneratorExpressions(
       }
     else
       {
-      this->ResolveTargetsInGeneratorExpression(
+      this->ResolveTargetsInGeneratorExpression(propName,
                                     *li,
                                     target,
                                     missingTargets);
@@ -644,6 +649,7 @@ cmExportFileGenerator::ResolveTargetsInGeneratorExpressions(
 //----------------------------------------------------------------------------
 void
 cmExportFileGenerator::ResolveTargetsInGeneratorExpression(
+                                    std::string const& propName,
                                     std::string &input,
                                     cmTarget* target,
                                     std::vector<std::string> &missingTargets)
@@ -709,7 +715,7 @@ cmExportFileGenerator::ResolveTargetsInGeneratorExpression(
     lastPos = endPos;
     }
 
-  this->ReplaceInstallPrefix(input);
+  this->ReplaceInstallPrefix(target, propName, input);
 
   if (!errorString.empty())
     {
@@ -719,7 +725,8 @@ cmExportFileGenerator::ResolveTargetsInGeneratorExpression(
 
 //----------------------------------------------------------------------------
 void
-cmExportFileGenerator::ReplaceInstallPrefix(std::string &)
+cmExportFileGenerator::ReplaceInstallPrefix(cmTarget*,
+                                            std::string const&, std::string &)
 {
   // Do nothing
 }
@@ -792,9 +799,11 @@ cmExportFileGenerator
                                                          preprocessRule);
   if (!prepro.empty())
     {
-    this->ResolveTargetsInGeneratorExpressions(prepro, target,
-                                               missingTargets,
-                                               ReplaceFreeTargets);
+    this->ResolveTargetsInGeneratorExpressions(
+                                          "LINK_INTERFACE_LIBRARIES" + suffix,
+                                          prepro, target,
+                                          missingTargets,
+                                          ReplaceFreeTargets);
     properties["IMPORTED_LINK_INTERFACE_LIBRARIES" + suffix] = prepro;
     }
 }
diff --git a/Source/cmExportFileGenerator.h b/Source/cmExportFileGenerator.h
index 919924e..d3b9fee 100644
--- a/Source/cmExportFileGenerator.h
+++ b/Source/cmExportFileGenerator.h
@@ -151,7 +151,9 @@ protected:
     NoReplaceFreeTargets
   };
 
-  void ResolveTargetsInGeneratorExpressions(std::string &input,
+  void ResolveTargetsInGeneratorExpressions(
+                          std::string const& propName,
+                          std::string &input,
                           cmTarget* target,
                           std::vector<std::string> &missingTargets,
                           FreeTargetsReplace replace = NoReplaceFreeTargets);
@@ -187,11 +189,15 @@ private:
   bool AddTargetNamespace(std::string &input, cmTarget* target,
                           std::vector<std::string> &missingTargets);
 
-  void ResolveTargetsInGeneratorExpression(std::string &input,
+  void ResolveTargetsInGeneratorExpression(
+                                    std::string const& propName,
+                                    std::string &input,
                                     cmTarget* target,
                                     std::vector<std::string> &missingTargets);
 
-  virtual void ReplaceInstallPrefix(std::string &input);
+  virtual void ReplaceInstallPrefix(cmTarget* target,
+                                    std::string const& propName,
+                                    std::string &input);
 
   virtual std::string InstallNameDir(cmTarget* target,
                                      const std::string& config) = 0;
diff --git a/Source/cmExportInstallFileGenerator.cxx b/Source/cmExportInstallFileGenerator.cxx
index 5bc36a5..9b1754f 100644
--- a/Source/cmExportInstallFileGenerator.cxx
+++ b/Source/cmExportInstallFileGenerator.cxx
@@ -299,14 +299,80 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os)
 }
 
 //----------------------------------------------------------------------------
+static bool checkCMP0057(cmTarget* target, std::string const& propName,
+                         std::string const& input, cmExportSet* exportSet)
+{
+  cmOStringStream e;
+  cmake::MessageType messageType = cmake::FATAL_ERROR;
+  cmMakefile* mf = target->GetMakefile();
+  switch(target->GetPolicyStatusCMP0057())
+    {
+    case cmPolicies::WARN:
+      e << (mf->GetPolicies()
+            ->GetPolicyWarning(cmPolicies::CMP0057)) << "\n";
+    case cmPolicies::OLD:
+      messageType = cmake::AUTHOR_WARNING;
+      break;
+    case cmPolicies::REQUIRED_ALWAYS:
+    case cmPolicies::REQUIRED_IF_USED:
+    case cmPolicies::NEW:
+      break;
+    }
+  e << "Target \""
+    << target->GetName()
+    << "\" is installed with a path relative to the installation "
+      "prefix\n  \"" << input << "\"\nin its " << propName
+    << " property.  The target is part of export set \""
+    << exportSet->GetName() << "\" which is installed "
+      "with an absolute path as its DESTINATION.  This mixing of "
+      "absolute and relative paths creates unusable target export files.";
+  mf->IssueMessage(messageType, e.str());
+  if (messageType == cmake::FATAL_ERROR)
+    {
+    return false;
+    }
+  return true;
+}
+
+//----------------------------------------------------------------------------
 void
-cmExportInstallFileGenerator::ReplaceInstallPrefix(std::string &input)
+cmExportInstallFileGenerator::ReplaceInstallPrefix(cmTarget* target,
+                                                   std::string const& propName,
+                                                   std::string &input)
 {
   std::string::size_type pos = 0;
   std::string::size_type lastPos = pos;
 
+  if (input.find("${_IMPORT_PREFIX}") != std::string::npos
+      && this->ImportPrefix.empty())
+    {
+    std::string userFacingInput = input;
+    while((pos = userFacingInput.find("${_IMPORT_PREFIX}/", lastPos))
+        != userFacingInput.npos)
+      {
+      std::string::size_type endPos = pos + sizeof("${_IMPORT_PREFIX}/") - 1;
+      userFacingInput.erase(pos, endPos - pos);
+      lastPos = endPos;
+      }
+
+    if (!checkCMP0057(target, propName, userFacingInput, this->IEGen->GetExportSet()))
+      {
+      return;
+      }
+    }
+
+  pos = 0;
+  lastPos = pos;
+
   while((pos = input.find("$<INSTALL_PREFIX>", lastPos)) != input.npos)
     {
+    if (this->ImportPrefix.empty())
+      {
+      if (!checkCMP0057(target, propName, input, this->IEGen->GetExportSet()))
+        {
+        return;
+        }
+      }
     std::string::size_type endPos = pos + sizeof("$<INSTALL_PREFIX>") - 1;
     input.replace(pos, endPos - pos, "${_IMPORT_PREFIX}");
     lastPos = endPos;
diff --git a/Source/cmExportInstallFileGenerator.h b/Source/cmExportInstallFileGenerator.h
index 3d7b0c6..0723085 100644
--- a/Source/cmExportInstallFileGenerator.h
+++ b/Source/cmExportInstallFileGenerator.h
@@ -62,7 +62,9 @@ protected:
                                    cmTarget* depender,
                                    cmTarget* dependee);
 
-  virtual void ReplaceInstallPrefix(std::string &input);
+  virtual void ReplaceInstallPrefix(cmTarget* target,
+                                    std::string const& propName,
+                                    std::string &input);
 
   void ComplainAboutMissingTarget(cmTarget* depender,
                                   cmTarget* dependee,
diff --git a/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-INSTALL_PREFIX-NEW-result.txt b/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-INSTALL_PREFIX-NEW-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-INSTALL_PREFIX-NEW-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-INSTALL_PREFIX-NEW-stderr.txt b/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-INSTALL_PREFIX-NEW-stderr.txt
new file mode 100644
index 0000000..2968b91
--- /dev/null
+++ b/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-INSTALL_PREFIX-NEW-stderr.txt
@@ -0,0 +1,10 @@
+CMake Error in CMakeLists.txt:
+  Target "somelib" is installed with a path relative to the installation
+  prefix
+
+    "\$<INSTALL_PREFIX>/include"
+
+  in its INTERFACE_INCLUDE_DIRECTORIES property.  The target is part of
+  export set "exp" which is installed with an absolute path as its
+  DESTINATION.  This mixing of absolute and relative paths creates unusable
+  target export files.
diff --git a/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-INSTALL_PREFIX-NEW.cmake b/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-INSTALL_PREFIX-NEW.cmake
new file mode 100644
index 0000000..c7255db
--- /dev/null
+++ b/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-INSTALL_PREFIX-NEW.cmake
@@ -0,0 +1,13 @@
+
+cmake_policy(SET CMP0057 NEW)
+
+add_library(somelib SHARED empty.cpp)
+target_include_directories(somelib INTERFACE $<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>)
+
+install(TARGETS somelib EXPORT exp
+  LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
+  ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
+  RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
+)
+
+install(EXPORT exp DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake)
diff --git a/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-INSTALL_PREFIX-OLD-result.txt b/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-INSTALL_PREFIX-OLD-result.txt
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-INSTALL_PREFIX-OLD-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-INSTALL_PREFIX-OLD-stderr.txt b/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-INSTALL_PREFIX-OLD-stderr.txt
new file mode 100644
index 0000000..860f62f
--- /dev/null
+++ b/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-INSTALL_PREFIX-OLD-stderr.txt
@@ -0,0 +1,11 @@
+CMake Warning \(dev\) in CMakeLists.txt:
+  Target "somelib" is installed with a path relative to the installation
+  prefix
+
+    "\$<INSTALL_PREFIX>/include"
+
+  in its INTERFACE_INCLUDE_DIRECTORIES property.  The target is part of
+  export set "exp" which is installed with an absolute path as its
+  DESTINATION.  This mixing of absolute and relative paths creates unusable
+  target export files.
+This warning is for project developers.  Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-INSTALL_PREFIX-OLD.cmake b/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-INSTALL_PREFIX-OLD.cmake
new file mode 100644
index 0000000..1c27fd7
--- /dev/null
+++ b/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-INSTALL_PREFIX-OLD.cmake
@@ -0,0 +1,13 @@
+
+cmake_policy(SET CMP0057 OLD)
+
+add_library(somelib SHARED empty.cpp)
+target_include_directories(somelib INTERFACE $<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>)
+
+install(TARGETS somelib EXPORT exp
+  LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
+  ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
+  RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
+)
+
+install(EXPORT exp DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake)
diff --git a/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-INSTALL_PREFIX-WARN-result.txt b/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-INSTALL_PREFIX-WARN-result.txt
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-INSTALL_PREFIX-WARN-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-INSTALL_PREFIX-WARN-stderr.txt b/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-INSTALL_PREFIX-WARN-stderr.txt
new file mode 100644
index 0000000..a5ece0d
--- /dev/null
+++ b/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-INSTALL_PREFIX-WARN-stderr.txt
@@ -0,0 +1,15 @@
+CMake Warning \(dev\) in CMakeLists.txt:
+  Policy CMP0057 is not set: Error on absolute export with relative usage
+  requirements.  Run "cmake --help-policy CMP0057" for policy details.  Use
+  the cmake_policy command to set the policy and suppress this warning.
+
+  Target "somelib" is installed with a path relative to the installation
+  prefix
+
+    "\$<INSTALL_PREFIX>/include"
+
+  in its INTERFACE_INCLUDE_DIRECTORIES property.  The target is part of
+  export set "exp" which is installed with an absolute path as its
+  DESTINATION.  This mixing of absolute and relative paths creates unusable
+  target export files.
+This warning is for project developers.  Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-INSTALL_PREFIX-WARN.cmake b/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-INSTALL_PREFIX-WARN.cmake
new file mode 100644
index 0000000..06e793e
--- /dev/null
+++ b/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-INSTALL_PREFIX-WARN.cmake
@@ -0,0 +1,11 @@
+
+add_library(somelib SHARED empty.cpp)
+target_include_directories(somelib INTERFACE $<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>)
+
+install(TARGETS somelib EXPORT exp
+  LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
+  ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
+  RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
+)
+
+install(EXPORT exp DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake)
diff --git a/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-NEW-result.txt b/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-NEW-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-NEW-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-NEW-stderr.txt b/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-NEW-stderr.txt
new file mode 100644
index 0000000..a11f06a
--- /dev/null
+++ b/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-NEW-stderr.txt
@@ -0,0 +1,10 @@
+CMake Error in CMakeLists.txt:
+  Target "somelib" is installed with a path relative to the installation
+  prefix
+
+    "include"
+
+  in its INTERFACE_INCLUDE_DIRECTORIES property.  The target is part of
+  export set "exp" which is installed with an absolute path as its
+  DESTINATION.  This mixing of absolute and relative paths creates unusable
+  target export files.
diff --git a/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-NEW.cmake b/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-NEW.cmake
new file mode 100644
index 0000000..912aaef
--- /dev/null
+++ b/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-NEW.cmake
@@ -0,0 +1,13 @@
+
+cmake_policy(SET CMP0057 NEW)
+
+add_library(somelib SHARED empty.cpp)
+target_include_directories(somelib INTERFACE $<INSTALL_INTERFACE:include>)
+
+install(TARGETS somelib EXPORT exp
+  LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
+  ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
+  RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
+)
+
+install(EXPORT exp DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake)
diff --git a/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-OLD-result.txt b/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-OLD-result.txt
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-OLD-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-OLD-stderr.txt b/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-OLD-stderr.txt
new file mode 100644
index 0000000..32cc756
--- /dev/null
+++ b/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-OLD-stderr.txt
@@ -0,0 +1,11 @@
+CMake Warning \(dev\) in CMakeLists.txt:
+  Target "somelib" is installed with a path relative to the installation
+  prefix
+
+    "include"
+
+  in its INTERFACE_INCLUDE_DIRECTORIES property.  The target is part of
+  export set "exp" which is installed with an absolute path as its
+  DESTINATION.  This mixing of absolute and relative paths creates unusable
+  target export files.
+This warning is for project developers.  Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-OLD.cmake b/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-OLD.cmake
new file mode 100644
index 0000000..e6f5b96
--- /dev/null
+++ b/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-OLD.cmake
@@ -0,0 +1,13 @@
+
+cmake_policy(SET CMP0057 OLD)
+
+add_library(somelib SHARED empty.cpp)
+target_include_directories(somelib INTERFACE $<INSTALL_INTERFACE:include>)
+
+install(TARGETS somelib EXPORT exp
+  LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
+  ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
+  RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
+)
+
+install(EXPORT exp DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake)
diff --git a/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-WARN-result.txt b/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-WARN-result.txt
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-WARN-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-WARN-stderr.txt b/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-WARN-stderr.txt
new file mode 100644
index 0000000..1c2acb5
--- /dev/null
+++ b/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-WARN-stderr.txt
@@ -0,0 +1,15 @@
+CMake Warning \(dev\) in CMakeLists.txt:
+  Policy CMP0057 is not set: Error on absolute export with relative usage
+  requirements.  Run "cmake --help-policy CMP0057" for policy details.  Use
+  the cmake_policy command to set the policy and suppress this warning.
+
+  Target "somelib" is installed with a path relative to the installation
+  prefix
+
+    "include"
+
+  in its INTERFACE_INCLUDE_DIRECTORIES property.  The target is part of
+  export set "exp" which is installed with an absolute path as its
+  DESTINATION.  This mixing of absolute and relative paths creates unusable
+  target export files.
+This warning is for project developers.  Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-WARN.cmake b/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-WARN.cmake
new file mode 100644
index 0000000..6d112b2
--- /dev/null
+++ b/Tests/RunCMake/export/RelativeIncludeDirectory-CMP0057-WARN.cmake
@@ -0,0 +1,11 @@
+
+add_library(somelib SHARED empty.cpp)
+target_include_directories(somelib INTERFACE $<INSTALL_INTERFACE:include>)
+
+install(TARGETS somelib EXPORT exp
+  LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
+  ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
+  RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
+)
+
+install(EXPORT exp DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake)
diff --git a/Tests/RunCMake/export/RunCMakeTest.cmake b/Tests/RunCMake/export/RunCMakeTest.cmake
index 296d440..2ebe8c0 100644
--- a/Tests/RunCMake/export/RunCMakeTest.cmake
+++ b/Tests/RunCMake/export/RunCMakeTest.cmake
@@ -8,3 +8,9 @@ run_cmake(RelativeLibDir)
 run_cmake(RelativeIncludeDestination-CMP0057-NEW)
 run_cmake(RelativeIncludeDestination-CMP0057-OLD)
 run_cmake(RelativeIncludeDestination-CMP0057-WARN)
+run_cmake(RelativeIncludeDirectory-CMP0057-NEW)
+run_cmake(RelativeIncludeDirectory-CMP0057-OLD)
+run_cmake(RelativeIncludeDirectory-CMP0057-WARN)
+run_cmake(RelativeIncludeDirectory-CMP0057-INSTALL_PREFIX-NEW)
+run_cmake(RelativeIncludeDirectory-CMP0057-INSTALL_PREFIX-OLD)
+run_cmake(RelativeIncludeDirectory-CMP0057-INSTALL_PREFIX-WARN)

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=29f92485f1792cccd84077a0c5f5d452ba2a85aa
commit 29f92485f1792cccd84077a0c5f5d452ba2a85aa
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun Dec 7 22:34:44 2014 +0100
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Mon Dec 8 20:50:10 2014 +0100

    Export: Diagnose issues in INCLUDES DESTINATION while generating (#15258).
    
    The _IMPORT_PREFIX variable is generated in export files only if the
    installation destination is relative.  If packagers set the path to
    an absolute destination, the generated file must not have any
    references to the _IMPORT_PREFIX as it is undefined.
    
    A use of _IMPORT_PREFIX is generated for content passed to
    install(TARGETS) in the INCLUDES DESTINATION component, if the
    content is a relative path.  Issue a message to notify the user that
    that the generated file is unusable, and introduce policy CMP0057 to
    control the severity of the message.

diff --git a/Help/manual/cmake-policies.7.rst b/Help/manual/cmake-policies.7.rst
index 96f39e6..76ca5d4 100644
--- a/Help/manual/cmake-policies.7.rst
+++ b/Help/manual/cmake-policies.7.rst
@@ -114,3 +114,4 @@ All Policies
    /policy/CMP0054
    /policy/CMP0055
    /policy/CMP0056
+   /policy/CMP0057
diff --git a/Help/policy/CMP0057.rst b/Help/policy/CMP0057.rst
new file mode 100644
index 0000000..79da0b9
--- /dev/null
+++ b/Help/policy/CMP0057.rst
@@ -0,0 +1,20 @@
+CMP0057
+-------
+
+Error on absolute export with relative usage requirements.
+
+CMake 3.1 and lower generated unusable files with the
+:command:`install(EXPORT)` command if an absolute ``DESTINATION`` was used
+with it, and a relative path was passed to the ``INCLUDES DESTINATION`` of a
+target in the specified export set.  In such cases, a use of an internal
+variable was generated, although the internal variable was unset.
+
+The ``OLD`` behavior for this policy is to issue a warning if a the
+:command:`install(EXPORT)` command generates such an unusable file.  The
+``NEW`` behavior for this policy is to issue an error instead of generating
+the file.
+
+This policy was introduced in CMake version 3.2.
+CMake version |release| warns when the policy is not set and uses
+``OLD`` behavior.  Use the :command:`cmake_policy` command to set it to
+``OLD`` or ``NEW`` explicitly.
diff --git a/Source/cmExportInstallFileGenerator.cxx b/Source/cmExportInstallFileGenerator.cxx
index 23180f1..5bc36a5 100644
--- a/Source/cmExportInstallFileGenerator.cxx
+++ b/Source/cmExportInstallFileGenerator.cxx
@@ -37,15 +37,70 @@ std::string cmExportInstallFileGenerator::GetConfigImportFileGlob()
 }
 
 //----------------------------------------------------------------------------
+bool cmExportInstallFileGenerator
+::CheckIncludesDestinationContent(cmTargetExport* tei,
+                                  cmExportSet* exportSet)
+{
+  std::vector<std::string> parts;
+  cmGeneratorExpression::Split(tei->InterfaceIncludeDirectories, parts);
+  for (std::vector<std::string>::const_iterator it = parts.begin();
+       it != parts.end(); ++it)
+    {
+    if (!cmSystemTools::FileIsFullPath(*it))
+      {
+      if (cmGeneratorExpression::Find(*it) != 0)
+        {
+        if (this->ImportPrefix.empty())
+          {
+          cmOStringStream e;
+          cmake::MessageType messageType = cmake::FATAL_ERROR;
+          cmMakefile* mf = tei->Target->GetMakefile();
+          switch(tei->Target->GetPolicyStatusCMP0057())
+            {
+            case cmPolicies::WARN:
+              e << (mf->GetPolicies()
+                    ->GetPolicyWarning(cmPolicies::CMP0057)) << "\n";
+            case cmPolicies::OLD:
+              messageType = cmake::AUTHOR_WARNING;
+              break;
+            case cmPolicies::REQUIRED_ALWAYS:
+            case cmPolicies::REQUIRED_IF_USED:
+            case cmPolicies::NEW:
+              break;
+            }
+          e << "Target \""
+            << tei->Target->GetName()
+            << "\" is installed as part of export set \""
+            << exportSet->GetName() << "\" with an INCLUDES DESTINATION "
+              "containing relative path\n  \"" << *it
+            << "\"\nThe export set \""
+            << exportSet->GetName()
+            << "\" is installed with an absolute path as its DESTINATION.  "
+              "This mixing of absolute and relative paths creates unusable "
+              "target export files.";
+          mf->IssueMessage(messageType, e.str());
+          if (messageType == cmake::FATAL_ERROR)
+            {
+            return false;
+            }
+          }
+        }
+      }
+    }
+  return true;
+}
+
+//----------------------------------------------------------------------------
 bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os)
 {
   std::vector<cmTargetExport*> allTargets;
+  cmExportSet* exportSet = this->IEGen->GetExportSet();
   {
   std::string expectedTargets;
   std::string sep;
   for(std::vector<cmTargetExport*>::const_iterator
-        tei = this->IEGen->GetExportSet()->GetTargetExports()->begin();
-      tei != this->IEGen->GetExportSet()->GetTargetExports()->end(); ++tei)
+        tei = exportSet->GetTargetExports()->begin();
+      tei != exportSet->GetTargetExports()->end(); ++tei)
     {
     expectedTargets += sep + this->Namespace + (*tei)->Target->GetExportName();
     sep = " ";
@@ -58,7 +113,7 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os)
       {
       cmOStringStream e;
       e << "install(EXPORT \""
-        << this->IEGen->GetExportSet()->GetName()
+        << exportSet->GetName()
         << "\" ...) " << "includes target \"" << te->Target->GetName()
         << "\" more than once in the export set.";
       cmSystemTools::Error(e.str().c_str());
@@ -141,6 +196,11 @@ bool cmExportInstallFileGenerator::GenerateMainFile(std::ostream& os)
 
     ImportPropertyMap properties;
 
+    if (!this->CheckIncludesDestinationContent(*tei, exportSet))
+      {
+      return false;
+      }
+
     this->PopulateIncludeDirectoriesInterface(*tei,
                                   cmGeneratorExpression::InstallInterface,
                                   properties, missingTargets);
diff --git a/Source/cmExportInstallFileGenerator.h b/Source/cmExportInstallFileGenerator.h
index b851ad5..3d7b0c6 100644
--- a/Source/cmExportInstallFileGenerator.h
+++ b/Source/cmExportInstallFileGenerator.h
@@ -16,6 +16,7 @@
 
 class cmInstallExportGenerator;
 class cmInstallTargetGenerator;
+class cmExportSet;
 
 /** \class cmExportInstallFileGenerator
  * \brief Generate a file exporting targets from an install tree.
@@ -87,6 +88,9 @@ protected:
 
   std::string InstallNameDir(cmTarget* target, const std::string& config);
 
+  bool CheckIncludesDestinationContent(cmTargetExport* tei,
+                                       cmExportSet* exportSet);
+
   cmInstallExportGenerator* IEGen;
 
   std::string ImportPrefix;
diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx
index 1a27a25..d3061f3 100644
--- a/Source/cmPolicies.cxx
+++ b/Source/cmPolicies.cxx
@@ -374,6 +374,11 @@ cmPolicies::cmPolicies()
     CMP0056, "CMP0056",
     "Honor link flags in try_compile() source-file signature.",
     3,2,0, cmPolicies::WARN);
+
+  this->DefinePolicy(
+    CMP0057, "CMP0057",
+    "Error on absolute export with relative usage requirements.",
+    3,2,0, cmPolicies::WARN);
 }
 
 cmPolicies::~cmPolicies()
diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h
index 2ad4890..c3866bd 100644
--- a/Source/cmPolicies.h
+++ b/Source/cmPolicies.h
@@ -112,6 +112,7 @@ public:
     /// or keywords when unquoted.
     CMP0055, ///< Strict checking for break() command.
     CMP0056, ///< Honor link flags in try_compile() source-file signature.
+    CMP0057, ///< Error on absolute export with relative usage requirements.
 
     /** \brief Always the last entry.
      *
diff --git a/Source/cmTarget.h b/Source/cmTarget.h
index a3ecca0..dc4e6c6 100644
--- a/Source/cmTarget.h
+++ b/Source/cmTarget.h
@@ -34,7 +34,8 @@
   F(CMP0041) \
   F(CMP0042) \
   F(CMP0046) \
-  F(CMP0052)
+  F(CMP0052) \
+  F(CMP0057)
 
 class cmake;
 class cmMakefile;
diff --git a/Tests/RunCMake/TargetPolicies/PolicyList-stderr.txt b/Tests/RunCMake/TargetPolicies/PolicyList-stderr.txt
index f4b744b..7a59902 100644
--- a/Tests/RunCMake/TargetPolicies/PolicyList-stderr.txt
+++ b/Tests/RunCMake/TargetPolicies/PolicyList-stderr.txt
@@ -17,6 +17,7 @@
    \* CMP0042
    \* CMP0046
    \* CMP0052
+   \* CMP0057
 
 Call Stack \(most recent call first\):
   CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/export/RelativeIncludeDestination-CMP0057-NEW-result.txt b/Tests/RunCMake/export/RelativeIncludeDestination-CMP0057-NEW-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/export/RelativeIncludeDestination-CMP0057-NEW-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/export/RelativeIncludeDestination-CMP0057-NEW-stderr.txt b/Tests/RunCMake/export/RelativeIncludeDestination-CMP0057-NEW-stderr.txt
new file mode 100644
index 0000000..8cd27c2
--- /dev/null
+++ b/Tests/RunCMake/export/RelativeIncludeDestination-CMP0057-NEW-stderr.txt
@@ -0,0 +1,9 @@
+CMake Error in CMakeLists.txt:
+  Target "somelib" is installed as part of export set "exp" with an INCLUDES
+  DESTINATION containing relative path
+
+    "include"
+
+  The export set "exp" is installed with an absolute path as its DESTINATION.
+  This mixing of absolute and relative paths creates unusable target export
+  files.
diff --git a/Tests/RunCMake/export/RelativeIncludeDestination-CMP0057-NEW.cmake b/Tests/RunCMake/export/RelativeIncludeDestination-CMP0057-NEW.cmake
new file mode 100644
index 0000000..cab9ac6
--- /dev/null
+++ b/Tests/RunCMake/export/RelativeIncludeDestination-CMP0057-NEW.cmake
@@ -0,0 +1,13 @@
+
+cmake_policy(SET CMP0057 NEW)
+
+add_library(somelib SHARED empty.cpp)
+
+install(TARGETS somelib EXPORT exp
+  LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
+  ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
+  RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
+  INCLUDES DESTINATION include
+)
+
+install(EXPORT exp DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake)
diff --git a/Tests/RunCMake/export/RelativeIncludeDestination-CMP0057-OLD-result.txt b/Tests/RunCMake/export/RelativeIncludeDestination-CMP0057-OLD-result.txt
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/Tests/RunCMake/export/RelativeIncludeDestination-CMP0057-OLD-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/export/RelativeIncludeDestination-CMP0057-OLD-stderr.txt b/Tests/RunCMake/export/RelativeIncludeDestination-CMP0057-OLD-stderr.txt
new file mode 100644
index 0000000..79c92a1
--- /dev/null
+++ b/Tests/RunCMake/export/RelativeIncludeDestination-CMP0057-OLD-stderr.txt
@@ -0,0 +1,10 @@
+CMake Warning \(dev\) in CMakeLists.txt:
+  Target "somelib" is installed as part of export set "exp" with an INCLUDES
+  DESTINATION containing relative path
+
+    "include"
+
+  The export set "exp" is installed with an absolute path as its DESTINATION.
+  This mixing of absolute and relative paths creates unusable target export
+  files.
+This warning is for project developers.  Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/export/RelativeIncludeDestination-CMP0057-OLD.cmake b/Tests/RunCMake/export/RelativeIncludeDestination-CMP0057-OLD.cmake
new file mode 100644
index 0000000..58bcbb7
--- /dev/null
+++ b/Tests/RunCMake/export/RelativeIncludeDestination-CMP0057-OLD.cmake
@@ -0,0 +1,13 @@
+
+cmake_policy(SET CMP0057 OLD)
+
+add_library(somelib SHARED empty.cpp)
+
+install(TARGETS somelib EXPORT exp
+  LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
+  ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
+  RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
+  INCLUDES DESTINATION include
+)
+
+install(EXPORT exp DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake)
diff --git a/Tests/RunCMake/export/RelativeIncludeDestination-CMP0057-WARN-result.txt b/Tests/RunCMake/export/RelativeIncludeDestination-CMP0057-WARN-result.txt
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/Tests/RunCMake/export/RelativeIncludeDestination-CMP0057-WARN-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/export/RelativeIncludeDestination-CMP0057-WARN-stderr.txt b/Tests/RunCMake/export/RelativeIncludeDestination-CMP0057-WARN-stderr.txt
new file mode 100644
index 0000000..c8e413c
--- /dev/null
+++ b/Tests/RunCMake/export/RelativeIncludeDestination-CMP0057-WARN-stderr.txt
@@ -0,0 +1,14 @@
+CMake Warning \(dev\) in CMakeLists.txt:
+  Policy CMP0057 is not set: Error on absolute export with relative usage
+  requirements.  Run "cmake --help-policy CMP0057" for policy details.  Use
+  the cmake_policy command to set the policy and suppress this warning.
+
+  Target "somelib" is installed as part of export set "exp" with an INCLUDES
+  DESTINATION containing relative path
+
+    "include"
+
+  The export set "exp" is installed with an absolute path as its DESTINATION.
+  This mixing of absolute and relative paths creates unusable target export
+  files.
+This warning is for project developers.  Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/export/RelativeIncludeDestination-CMP0057-WARN.cmake b/Tests/RunCMake/export/RelativeIncludeDestination-CMP0057-WARN.cmake
new file mode 100644
index 0000000..82bde5d
--- /dev/null
+++ b/Tests/RunCMake/export/RelativeIncludeDestination-CMP0057-WARN.cmake
@@ -0,0 +1,11 @@
+
+add_library(somelib SHARED empty.cpp)
+
+install(TARGETS somelib EXPORT exp
+  LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
+  ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
+  RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
+  INCLUDES DESTINATION include
+)
+
+install(EXPORT exp DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake)
diff --git a/Tests/RunCMake/export/RunCMakeTest.cmake b/Tests/RunCMake/export/RunCMakeTest.cmake
index 32cf30c..296d440 100644
--- a/Tests/RunCMake/export/RunCMakeTest.cmake
+++ b/Tests/RunCMake/export/RunCMakeTest.cmake
@@ -5,3 +5,6 @@ run_cmake(AppendExport)
 run_cmake(OldIface)
 run_cmake(NoExportSet)
 run_cmake(RelativeLibDir)
+run_cmake(RelativeIncludeDestination-CMP0057-NEW)
+run_cmake(RelativeIncludeDestination-CMP0057-OLD)
+run_cmake(RelativeIncludeDestination-CMP0057-WARN)

-----------------------------------------------------------------------

Summary of changes:


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list