[Cmake-commits] CMake branch, next, updated. v2.8.12.1-4890-ga569509

Stephen Kelly steveire at gmail.com
Wed Nov 6 16:27:37 EST 2013


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  a569509e7c870d38c91f5762e804f90e49445f37 (commit)
       via  3c43e52a54c58f868d62f171f87f4096d0a0cf65 (commit)
       via  2ef0f2fe9a0b5a40c036807ee6e2d3e2f4e9cab4 (commit)
       via  47ad632bb96bb00af79124c4e6d3e8342ef7032f (commit)
      from  ae6de0eaaa1e0e67881f06d75bcf4bc87707faab (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=a569509e7c870d38c91f5762e804f90e49445f37
commit a569509e7c870d38c91f5762e804f90e49445f37
Merge: ae6de0e 3c43e52
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Wed Nov 6 16:27:33 2013 -0500
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Wed Nov 6 16:27:33 2013 -0500

    Merge topic 'tll-target-policies' into next
    
    3c43e52 Disallow linking to utility targets (#13902).
    2ef0f2f Disallow link-to-self (#13947).
    47ad632 Disallow invalid target names (#13140)


http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=3c43e52a54c58f868d62f171f87f4096d0a0cf65
commit 3c43e52a54c58f868d62f171f87f4096d0a0cf65
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Tue Nov 5 19:15:53 2013 +0100
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Wed Nov 6 22:26:58 2013 +0100

    Disallow linking to utility targets (#13902).

diff --git a/Help/manual/cmake-policies.7.rst b/Help/manual/cmake-policies.7.rst
index f77a21c..2430ee9 100644
--- a/Help/manual/cmake-policies.7.rst
+++ b/Help/manual/cmake-policies.7.rst
@@ -72,3 +72,4 @@ All Policies
    /policy/CMP0036
    /policy/CMP0037
    /policy/CMP0038
+   /policy/CMP0039
diff --git a/Help/policy/CMP0039.rst b/Help/policy/CMP0039.rst
new file mode 100644
index 0000000..1d20f0c
--- /dev/null
+++ b/Help/policy/CMP0039.rst
@@ -0,0 +1,17 @@
+CMP0039
+-------
+
+Utility targets may not have link dependencies
+
+CMake 2.8.12 and lower allowed using utility targets in the left hand side
+position of the :command:`target_link_libraries` command. This is an indicator
+of a bug in user code.
+
+The OLD behavior for this policy is to ignore attempts to set the link
+libraries of utility targets.  The NEW behavior for this policy is to
+report an error if an attempt is made to set the link libraries of a
+utility target.
+
+This policy was introduced in CMake version 3.0.0.  CMake version
+|release| warns when the policy is not set and uses OLD behavior.  Use
+the cmake_policy command to set it to OLD or NEW explicitly.
diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx
index af33d0b..3881c54 100644
--- a/Source/cmPolicies.cxx
+++ b/Source/cmPolicies.cxx
@@ -296,6 +296,11 @@ cmPolicies::cmPolicies()
     CMP0038, "CMP0038",
     "Targets may not link directly to themselves.",
     3,0,0,0, cmPolicies::WARN);
+
+  this->DefinePolicy(
+    CMP0039, "CMP0039",
+    "Utility targets may not have link dependencies",
+    3,0,0,0, cmPolicies::WARN);
 }
 
 cmPolicies::~cmPolicies()
diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h
index 2ea9973..fc239d4 100644
--- a/Source/cmPolicies.h
+++ b/Source/cmPolicies.h
@@ -90,6 +90,7 @@ public:
     CMP0036, ///< Disallow command: build_name
     CMP0037, ///< Target names should match a validity pattern.
     CMP0038, ///< Targets may not link directly to themselves
+    CMP0039, ///< Utility targets may not have link dependencies
 
     /** \brief Always the last entry.
      *
diff --git a/Source/cmTargetLinkLibrariesCommand.cxx b/Source/cmTargetLinkLibrariesCommand.cxx
index c289459..209609d 100644
--- a/Source/cmTargetLinkLibrariesCommand.cxx
+++ b/Source/cmTargetLinkLibrariesCommand.cxx
@@ -101,6 +101,37 @@ bool cmTargetLinkLibrariesCommand
     return true;
     }
 
+  if (this->Target->GetType() == cmTarget::UTILITY)
+    {
+    const char *modal = 0;
+    cmake::MessageType messageType = cmake::AUTHOR_WARNING;
+    switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0039))
+      {
+      case cmPolicies::WARN:
+        modal = "should";
+      case cmPolicies::OLD:
+        break;
+      case cmPolicies::REQUIRED_ALWAYS:
+      case cmPolicies::REQUIRED_IF_USED:
+      case cmPolicies::NEW:
+        modal = "must";
+        messageType = cmake::FATAL_ERROR;
+      }
+    if (modal)
+      {
+      cmOStringStream e;
+      e << this->Makefile->GetPolicies()
+                            ->GetPolicyWarning(cmPolicies::CMP0039) << "\n"
+        "Utility target \"" << this->Target->GetName() << "\" " << modal
+        << " not be used as the target of a target_link_libraries call.";
+      this->Makefile->IssueMessage(messageType, e.str().c_str());
+      if(messageType == cmake::FATAL_ERROR)
+        {
+        return false;
+        }
+      }
+    }
+
   // but we might not have any libs after variable expansion
   if(args.size() < 2)
     {
diff --git a/Tests/RunCMake/CMP0039/CMP0039-NEW-result.txt b/Tests/RunCMake/CMP0039/CMP0039-NEW-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/CMP0039/CMP0039-NEW-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CMP0039/CMP0039-NEW-stderr.txt b/Tests/RunCMake/CMP0039/CMP0039-NEW-stderr.txt
new file mode 100644
index 0000000..1496c05
--- /dev/null
+++ b/Tests/RunCMake/CMP0039/CMP0039-NEW-stderr.txt
@@ -0,0 +1,9 @@
+CMake Error at CMP0039-NEW.cmake:7 \(target_link_libraries\):
+  Policy CMP0039 is not set: Utility targets may not have link dependencies
+  Run "cmake --help-policy CMP0039" for policy details.  Use the cmake_policy
+  command to set the policy and suppress this warning.
+
+  Utility target "utility" must not be used as the target of a
+  target_link_libraries call.
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/CMP0039/CMP0039-NEW.cmake b/Tests/RunCMake/CMP0039/CMP0039-NEW.cmake
new file mode 100644
index 0000000..2032d64
--- /dev/null
+++ b/Tests/RunCMake/CMP0039/CMP0039-NEW.cmake
@@ -0,0 +1,7 @@
+
+cmake_policy(SET CMP0039 NEW)
+
+add_custom_target(utility
+  COMMAND ${CMAKE_COMMAND} -E echo test
+)
+target_link_libraries(utility m)
diff --git a/Tests/RunCMake/CMP0039/CMP0039-OLD-result.txt b/Tests/RunCMake/CMP0039/CMP0039-OLD-result.txt
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/Tests/RunCMake/CMP0039/CMP0039-OLD-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0039/CMP0039-OLD-stderr.txt b/Tests/RunCMake/CMP0039/CMP0039-OLD-stderr.txt
new file mode 100644
index 0000000..10f3293
--- /dev/null
+++ b/Tests/RunCMake/CMP0039/CMP0039-OLD-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/CMP0039/CMP0039-OLD.cmake b/Tests/RunCMake/CMP0039/CMP0039-OLD.cmake
new file mode 100644
index 0000000..9a513f4
--- /dev/null
+++ b/Tests/RunCMake/CMP0039/CMP0039-OLD.cmake
@@ -0,0 +1,7 @@
+
+cmake_policy(SET CMP0039 OLD)
+
+add_custom_target(utility
+  COMMAND ${CMAKE_COMMAND} -E echo test
+)
+target_link_libraries(utility m)
diff --git a/Tests/RunCMake/CMP0039/CMP0039-WARN-result.txt b/Tests/RunCMake/CMP0039/CMP0039-WARN-result.txt
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/Tests/RunCMake/CMP0039/CMP0039-WARN-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0039/CMP0039-WARN-stderr.txt b/Tests/RunCMake/CMP0039/CMP0039-WARN-stderr.txt
new file mode 100644
index 0000000..9387f8c
--- /dev/null
+++ b/Tests/RunCMake/CMP0039/CMP0039-WARN-stderr.txt
@@ -0,0 +1,10 @@
+CMake Warning \(dev\) at CMP0039-WARN.cmake:5 \(target_link_libraries\):
+  Policy CMP0039 is not set: Utility targets may not have link dependencies
+  Run "cmake --help-policy CMP0039" for policy details.  Use the cmake_policy
+  command to set the policy and suppress this warning.
+
+  Utility target "utility" should not be used as the target of a
+  target_link_libraries call.
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)
+This warning is for project developers.  Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/CMP0039/CMP0039-WARN.cmake b/Tests/RunCMake/CMP0039/CMP0039-WARN.cmake
new file mode 100644
index 0000000..6249993
--- /dev/null
+++ b/Tests/RunCMake/CMP0039/CMP0039-WARN.cmake
@@ -0,0 +1,5 @@
+
+add_custom_target(utility
+  COMMAND ${CMAKE_COMMAND} -E echo test
+)
+target_link_libraries(utility m)
diff --git a/Tests/RunCMake/CMP0039/CMakeLists.txt b/Tests/RunCMake/CMP0039/CMakeLists.txt
new file mode 100644
index 0000000..2f10cb0
--- /dev/null
+++ b/Tests/RunCMake/CMP0039/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.12)
+project(${RunCMake_TEST} CXX)
+include(${RunCMake_TEST}.cmake NO_POLICY_SCOPE)
diff --git a/Tests/RunCMake/CMP0039/RunCMakeTest.cmake b/Tests/RunCMake/CMP0039/RunCMakeTest.cmake
new file mode 100644
index 0000000..58e8ea9
--- /dev/null
+++ b/Tests/RunCMake/CMP0039/RunCMakeTest.cmake
@@ -0,0 +1,5 @@
+include(RunCMake)
+
+run_cmake(CMP0039-WARN)
+run_cmake(CMP0039-NEW)
+run_cmake(CMP0039-OLD)
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt
index d703892..ed06745 100644
--- a/Tests/RunCMake/CMakeLists.txt
+++ b/Tests/RunCMake/CMakeLists.txt
@@ -61,6 +61,7 @@ if (NOT "${CMAKE_TEST_GENERATOR}" MATCHES "Borland"
   add_RunCMake_test(CMP0037)
 endif()
 add_RunCMake_test(CMP0038)
+add_RunCMake_test(CMP0039)
 add_RunCMake_test(CTest)
 if(UNIX AND "${CMAKE_TEST_GENERATOR}" MATCHES "Unix Makefiles")
   add_RunCMake_test(CompilerChange)

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=2ef0f2fe9a0b5a40c036807ee6e2d3e2f4e9cab4
commit 2ef0f2fe9a0b5a40c036807ee6e2d3e2f4e9cab4
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Tue Nov 5 18:01:09 2013 +0100
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Wed Nov 6 22:26:57 2013 +0100

    Disallow link-to-self (#13947).

diff --git a/Help/manual/cmake-policies.7.rst b/Help/manual/cmake-policies.7.rst
index addd2a7..f77a21c 100644
--- a/Help/manual/cmake-policies.7.rst
+++ b/Help/manual/cmake-policies.7.rst
@@ -71,3 +71,4 @@ All Policies
    /policy/CMP0035
    /policy/CMP0036
    /policy/CMP0037
+   /policy/CMP0038
diff --git a/Help/policy/CMP0038.rst b/Help/policy/CMP0038.rst
new file mode 100644
index 0000000..c448ed6
--- /dev/null
+++ b/Help/policy/CMP0038.rst
@@ -0,0 +1,16 @@
+CMP0038
+-------
+
+Targets may not link directly to themselves
+
+CMake 2.8.12 and lower allowed a build target to link to itself directly with
+a :command:`target_link_libraries` call. This is an indicator of a bug in
+user code.
+
+The OLD behavior for this policy is to ignore targets which list themselves
+in their own link implementation.  The NEW behavior for this policy is to
+report an error if a target attempts to link to itself.
+
+This policy was introduced in CMake version 3.0.0.  CMake version
+|release| warns when the policy is not set and uses OLD behavior.  Use
+the cmake_policy command to set it to OLD or NEW explicitly.
diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx
index db23f1e..af33d0b 100644
--- a/Source/cmPolicies.cxx
+++ b/Source/cmPolicies.cxx
@@ -291,6 +291,11 @@ cmPolicies::cmPolicies()
     CMP0037, "CMP0037",
     "Target names should match a validity pattern.",
     3,0,0,0, cmPolicies::WARN);
+
+  this->DefinePolicy(
+    CMP0038, "CMP0038",
+    "Targets may not link directly to themselves.",
+    3,0,0,0, cmPolicies::WARN);
 }
 
 cmPolicies::~cmPolicies()
diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h
index 821c58d..2ea9973 100644
--- a/Source/cmPolicies.h
+++ b/Source/cmPolicies.h
@@ -89,6 +89,7 @@ public:
     CMP0035, ///< Disallow command: variable_requires
     CMP0036, ///< Disallow command: build_name
     CMP0037, ///< Target names should match a validity pattern.
+    CMP0038, ///< Targets may not link directly to themselves
 
     /** \brief Always the last entry.
      *
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index d0390f7..d5e8420 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -932,12 +932,6 @@ void cmTarget::AddLinkLibrary(cmMakefile& mf,
                               const char *target, const char* lib,
                               LinkLibraryType llt)
 {
-  // Never add a self dependency, even if the user asks for it.
-  if(strcmp( target, lib ) == 0)
-    {
-    return;
-    }
-
   cmTarget *tgt = this->Makefile->FindTargetToUse(lib);
   {
   const bool isNonImportedTarget = tgt && !tgt->IsImported();
@@ -951,7 +945,8 @@ void cmTarget::AddLinkLibrary(cmMakefile& mf,
   }
 
   if (cmGeneratorExpression::Find(lib) != std::string::npos
-      || (tgt && tgt->GetType() == INTERFACE_LIBRARY))
+      || (tgt && tgt->GetType() == INTERFACE_LIBRARY)
+      || (strcmp( target, lib ) == 0))
     {
     return;
     }
@@ -5293,6 +5288,41 @@ void cmTarget::ComputeLinkImplementation(const char* config,
     std::string item = this->CheckCMP0004(*li);
     if(item == this->GetName() || item.empty())
       {
+      if(item == this->GetName())
+        {
+        bool noMessage = false;
+        cmake::MessageType messageType = cmake::FATAL_ERROR;
+        cmOStringStream e;
+        switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0038))
+          {
+          case cmPolicies::WARN:
+            {
+            e << (this->Makefile->GetPolicies()
+                  ->GetPolicyWarning(cmPolicies::CMP0038)) << "\n";
+            messageType = cmake::AUTHOR_WARNING;
+            }
+            break;
+          case cmPolicies::OLD:
+            noMessage = true;
+          case cmPolicies::REQUIRED_IF_USED:
+          case cmPolicies::REQUIRED_ALWAYS:
+          case cmPolicies::NEW:
+            // Issue the fatal message.
+            break;
+          }
+
+        if(!noMessage)
+          {
+          e << "Target \"" << this->GetName() << "\" links to itself.";
+          this->Makefile->GetCMakeInstance()->IssueMessage(messageType,
+                                                        e.str(),
+                                                        this->GetBacktrace());
+          if (messageType == cmake::FATAL_ERROR)
+            {
+            return;
+            }
+          }
+        }
       continue;
       }
     cmTarget *tgt = this->Makefile->FindTargetToUse(li->c_str());
@@ -5335,6 +5365,7 @@ void cmTarget::ComputeLinkImplementation(const char* config,
           }
         }
       }
+
     // The entry is meant for this configuration.
     impl.Libraries.push_back(item);
     }
diff --git a/Tests/RunCMake/CMP0038/CMP0038-NEW-result.txt b/Tests/RunCMake/CMP0038/CMP0038-NEW-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/CMP0038/CMP0038-NEW-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CMP0038/CMP0038-NEW-stderr.txt b/Tests/RunCMake/CMP0038/CMP0038-NEW-stderr.txt
new file mode 100644
index 0000000..3d0a428
--- /dev/null
+++ b/Tests/RunCMake/CMP0038/CMP0038-NEW-stderr.txt
@@ -0,0 +1,4 @@
+CMake Error at CMP0038-NEW.cmake:3 \(add_library\):
+  Target "self_link" links to itself.
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/CMP0038/CMP0038-NEW.cmake b/Tests/RunCMake/CMP0038/CMP0038-NEW.cmake
new file mode 100644
index 0000000..6296b83
--- /dev/null
+++ b/Tests/RunCMake/CMP0038/CMP0038-NEW.cmake
@@ -0,0 +1,4 @@
+
+cmake_policy(SET CMP0038 NEW)
+add_library(self_link empty.cpp)
+target_link_libraries(self_link self_link)
diff --git a/Tests/RunCMake/CMP0038/CMP0038-OLD-result.txt b/Tests/RunCMake/CMP0038/CMP0038-OLD-result.txt
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/Tests/RunCMake/CMP0038/CMP0038-OLD-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0038/CMP0038-OLD-stderr.txt b/Tests/RunCMake/CMP0038/CMP0038-OLD-stderr.txt
new file mode 100644
index 0000000..10f3293
--- /dev/null
+++ b/Tests/RunCMake/CMP0038/CMP0038-OLD-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/CMP0038/CMP0038-OLD.cmake b/Tests/RunCMake/CMP0038/CMP0038-OLD.cmake
new file mode 100644
index 0000000..3752821
--- /dev/null
+++ b/Tests/RunCMake/CMP0038/CMP0038-OLD.cmake
@@ -0,0 +1,4 @@
+
+cmake_policy(SET CMP0038 OLD)
+add_library(self_link empty.cpp)
+target_link_libraries(self_link self_link)
diff --git a/Tests/RunCMake/CMP0038/CMP0038-WARN-result.txt b/Tests/RunCMake/CMP0038/CMP0038-WARN-result.txt
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/Tests/RunCMake/CMP0038/CMP0038-WARN-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0038/CMP0038-WARN-stderr.txt b/Tests/RunCMake/CMP0038/CMP0038-WARN-stderr.txt
new file mode 100644
index 0000000..64631e7
--- /dev/null
+++ b/Tests/RunCMake/CMP0038/CMP0038-WARN-stderr.txt
@@ -0,0 +1,9 @@
+CMake Warning \(dev\) at CMP0038-WARN.cmake:2 \(add_library\):
+  Policy CMP0038 is not set: Targets may not link directly to themselves.
+  Run "cmake --help-policy CMP0038" for policy details.  Use the cmake_policy
+  command to set the policy and suppress this warning.
+
+  Target "self_link" links to itself.
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)
+This warning is for project developers.  Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/CMP0038/CMP0038-WARN.cmake b/Tests/RunCMake/CMP0038/CMP0038-WARN.cmake
new file mode 100644
index 0000000..5b92d09
--- /dev/null
+++ b/Tests/RunCMake/CMP0038/CMP0038-WARN.cmake
@@ -0,0 +1,3 @@
+
+add_library(self_link empty.cpp)
+target_link_libraries(self_link self_link)
diff --git a/Tests/RunCMake/CMP0038/CMakeLists.txt b/Tests/RunCMake/CMP0038/CMakeLists.txt
new file mode 100644
index 0000000..2f10cb0
--- /dev/null
+++ b/Tests/RunCMake/CMP0038/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.12)
+project(${RunCMake_TEST} CXX)
+include(${RunCMake_TEST}.cmake NO_POLICY_SCOPE)
diff --git a/Tests/RunCMake/CMP0038/RunCMakeTest.cmake b/Tests/RunCMake/CMP0038/RunCMakeTest.cmake
new file mode 100644
index 0000000..fc3500a
--- /dev/null
+++ b/Tests/RunCMake/CMP0038/RunCMakeTest.cmake
@@ -0,0 +1,5 @@
+include(RunCMake)
+
+run_cmake(CMP0038-WARN)
+run_cmake(CMP0038-NEW)
+run_cmake(CMP0038-OLD)
diff --git a/Tests/RunCMake/CMP0038/empty.cpp b/Tests/RunCMake/CMP0038/empty.cpp
new file mode 100644
index 0000000..bfbbdde
--- /dev/null
+++ b/Tests/RunCMake/CMP0038/empty.cpp
@@ -0,0 +1,7 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int empty()
+{
+  return 0;
+}
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt
index 3395bd3..d703892 100644
--- a/Tests/RunCMake/CMakeLists.txt
+++ b/Tests/RunCMake/CMakeLists.txt
@@ -60,6 +60,7 @@ if (NOT "${CMAKE_TEST_GENERATOR}" MATCHES "Borland"
     AND NOT "${CMAKE_TEST_GENERATOR}" MATCHES "NMake")
   add_RunCMake_test(CMP0037)
 endif()
+add_RunCMake_test(CMP0038)
 add_RunCMake_test(CTest)
 if(UNIX AND "${CMAKE_TEST_GENERATOR}" MATCHES "Unix Makefiles")
   add_RunCMake_test(CompilerChange)

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=47ad632bb96bb00af79124c4e6d3e8342ef7032f
commit 47ad632bb96bb00af79124c4e6d3e8342ef7032f
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Tue Nov 5 17:32:30 2013 +0100
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Wed Nov 6 22:26:28 2013 +0100

    Disallow invalid target names (#13140)
    
    Exclude Borland and NMake from the CMP0037 test. They do not accept
    the colon in a target name.

diff --git a/Help/manual/cmake-policies.7.rst b/Help/manual/cmake-policies.7.rst
index 5879a30..addd2a7 100644
--- a/Help/manual/cmake-policies.7.rst
+++ b/Help/manual/cmake-policies.7.rst
@@ -70,3 +70,4 @@ All Policies
    /policy/CMP0034
    /policy/CMP0035
    /policy/CMP0036
+   /policy/CMP0037
diff --git a/Help/policy/CMP0037.rst b/Help/policy/CMP0037.rst
new file mode 100644
index 0000000..5df3c00
--- /dev/null
+++ b/Help/policy/CMP0037.rst
@@ -0,0 +1,21 @@
+CMP0037
+-------
+
+Target names should match a validity pattern.
+
+CMake 2.8.12 and lower allowed creating targets using :command:`add_library` and
+:command:`add_executable` with unrestricted choice for the target name.  Newer
+cmake features such as :manual:`cmake-generator-expressions(7)` and some
+diagnostics expect target names to match a restricted pattern.
+
+Target names may contain upper and lower case letters, numbers, the underscore
+character (_), dot(.), plus(+) and minus(-).  As a special case, ALIAS
+targets and INTERFACE library targets may contain two consequtive colons.
+
+The OLD behavior for this policy is to allow creating targets which do not match
+the validity pattern.  The NEW behavior for this policy is to report an error
+if an add_* command is used with an invalid target name.
+
+This policy was introduced in CMake version 3.0.0.  CMake version
+|release| warns when the policy is not set and uses OLD behavior.  Use
+the cmake_policy command to set it to OLD or NEW explicitly.
diff --git a/Source/cmAddExecutableCommand.cxx b/Source/cmAddExecutableCommand.cxx
index 5785259..a93e834 100644
--- a/Source/cmAddExecutableCommand.cxx
+++ b/Source/cmAddExecutableCommand.cxx
@@ -69,6 +69,44 @@ bool cmAddExecutableCommand
       }
     }
 
+  bool nameOk = cmGeneratorExpression::IsValidTargetName(exename);
+  if (nameOk && !importTarget && !isAlias)
+    {
+    nameOk = exename.find(":") == std::string::npos;
+    }
+  if (!nameOk)
+    {
+    cmake::MessageType messageType = cmake::AUTHOR_WARNING;
+    bool issueMessage = false;
+    switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0037))
+      {
+      case cmPolicies::WARN:
+        issueMessage = true;
+      case cmPolicies::OLD:
+        break;
+      case cmPolicies::NEW:
+      case cmPolicies::REQUIRED_IF_USED:
+      case cmPolicies::REQUIRED_ALWAYS:
+        issueMessage = true;
+        messageType = cmake::FATAL_ERROR;
+      }
+    if (issueMessage)
+      {
+      cmOStringStream e;
+      e << (this->Makefile->GetPolicies()
+            ->GetPolicyWarning(cmPolicies::CMP0037)) << "\n";
+      e << "The target name \"" << exename << "\" is not valid for certain "
+          "CMake features, such as generator expressions, and may result "
+          "in undefined behavior.";
+      this->Makefile->IssueMessage(messageType, e.str().c_str());
+
+      if (messageType == cmake::FATAL_ERROR)
+        {
+        return false;
+        }
+      }
+    }
+
   // Special modifiers are not allowed with IMPORTED signature.
   if(importTarget
       && (use_win32 || use_macbundle || excludeFromAll))
diff --git a/Source/cmAddLibraryCommand.cxx b/Source/cmAddLibraryCommand.cxx
index 0e61c99..4c591b6 100644
--- a/Source/cmAddLibraryCommand.cxx
+++ b/Source/cmAddLibraryCommand.cxx
@@ -108,6 +108,45 @@ bool cmAddLibraryCommand
       break;
       }
     }
+
+  bool nameOk = cmGeneratorExpression::IsValidTargetName(libName);
+  if (nameOk && !importTarget && !isAlias)
+    {
+    nameOk = libName.find(":") == std::string::npos;
+    }
+  if (!nameOk)
+    {
+    cmake::MessageType messageType = cmake::AUTHOR_WARNING;
+    bool issueMessage = false;
+    switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0037))
+      {
+      case cmPolicies::WARN:
+        issueMessage = type != cmTarget::INTERFACE_LIBRARY;
+      case cmPolicies::OLD:
+        break;
+      case cmPolicies::NEW:
+      case cmPolicies::REQUIRED_IF_USED:
+      case cmPolicies::REQUIRED_ALWAYS:
+        issueMessage = true;
+        messageType = cmake::FATAL_ERROR;
+      }
+    if (issueMessage)
+      {
+      cmOStringStream e;
+      e << (this->Makefile->GetPolicies()
+            ->GetPolicyWarning(cmPolicies::CMP0037)) << "\n";
+      e << "The target name \"" << libName << "\" is not valid for certain "
+          "CMake features, such as generator expressions, and may result "
+          "in undefined behavior.";
+      this->Makefile->IssueMessage(messageType, e.str().c_str());
+
+      if (messageType == cmake::FATAL_ERROR)
+        {
+        return false;
+        }
+      }
+    }
+
   if (isAlias)
     {
     if(!cmGeneratorExpression::IsValidTargetName(libName.c_str()))
diff --git a/Source/cmPolicies.cxx b/Source/cmPolicies.cxx
index ab822d3..db23f1e 100644
--- a/Source/cmPolicies.cxx
+++ b/Source/cmPolicies.cxx
@@ -286,6 +286,11 @@ cmPolicies::cmPolicies()
     CMP0036, "CMP0036",
     "The build_name command should not be called.",
     3,0,0,0, cmPolicies::WARN);
+
+  this->DefinePolicy(
+    CMP0037, "CMP0037",
+    "Target names should match a validity pattern.",
+    3,0,0,0, cmPolicies::WARN);
 }
 
 cmPolicies::~cmPolicies()
diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h
index 9e72bdc..821c58d 100644
--- a/Source/cmPolicies.h
+++ b/Source/cmPolicies.h
@@ -88,6 +88,7 @@ public:
     CMP0034, ///< Disallow command: utility_source
     CMP0035, ///< Disallow command: variable_requires
     CMP0036, ///< Disallow command: build_name
+    CMP0037, ///< Target names should match a validity pattern.
 
     /** \brief Always the last entry.
      *
diff --git a/Tests/RunCMake/CMP0037/CMP0037-NEW-result.txt b/Tests/RunCMake/CMP0037/CMP0037-NEW-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/CMP0037-NEW-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CMP0037/CMP0037-NEW-stderr.txt b/Tests/RunCMake/CMP0037/CMP0037-NEW-stderr.txt
new file mode 100644
index 0000000..6de96b1
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/CMP0037-NEW-stderr.txt
@@ -0,0 +1,39 @@
+CMake Error at CMP0037-NEW.cmake:4 \(add_library\):
+  Policy CMP0037 is not set: Target names should match a validity pattern.
+  Run "cmake --help-policy CMP0037" for policy details.  Use the cmake_policy
+  command to set the policy and suppress this warning.
+
+  The target name "lib with spaces" is not valid for certain CMake features,
+  such as generator expressions, and may result in undefined behavior.
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)
++
+CMake Error at CMP0037-NEW.cmake:5 \(add_executable\):
+  Policy CMP0037 is not set: Target names should match a validity pattern.
+  Run "cmake --help-policy CMP0037" for policy details.  Use the cmake_policy
+  command to set the policy and suppress this warning.
+
+  The target name "exe with spaces" is not valid for certain CMake features,
+  such as generator expressions, and may result in undefined behavior.
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)
++
+CMake Error at CMP0037-NEW.cmake:6 \(add_library\):
+  Policy CMP0037 is not set: Target names should match a validity pattern.
+  Run "cmake --help-policy CMP0037" for policy details.  Use the cmake_policy
+  command to set the policy and suppress this warning.
+
+  The target name "lib:colon" is not valid for certain CMake features, such
+  as generator expressions, and may result in undefined behavior.
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)
++
+CMake Error at CMP0037-NEW.cmake:7 \(add_executable\):
+  Policy CMP0037 is not set: Target names should match a validity pattern.
+  Run "cmake --help-policy CMP0037" for policy details.  Use the cmake_policy
+  command to set the policy and suppress this warning.
+
+  The target name "exe:colon" is not valid for certain CMake features, such
+  as generator expressions, and may result in undefined behavior.
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)
diff --git a/Tests/RunCMake/CMP0037/CMP0037-NEW.cmake b/Tests/RunCMake/CMP0037/CMP0037-NEW.cmake
new file mode 100644
index 0000000..a6ffc59
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/CMP0037-NEW.cmake
@@ -0,0 +1,7 @@
+
+cmake_policy(SET CMP0037 NEW)
+
+add_library("lib with spaces" empty.cpp)
+add_executable("exe with spaces" empty.cpp)
+add_library("lib:colon" empty.cpp)
+add_executable("exe:colon" empty.cpp)
diff --git a/Tests/RunCMake/CMP0037/CMP0037-OLD-result.txt b/Tests/RunCMake/CMP0037/CMP0037-OLD-result.txt
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/CMP0037-OLD-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0037/CMP0037-OLD-stderr.txt b/Tests/RunCMake/CMP0037/CMP0037-OLD-stderr.txt
new file mode 100644
index 0000000..10f3293
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/CMP0037-OLD-stderr.txt
@@ -0,0 +1 @@
+^$
diff --git a/Tests/RunCMake/CMP0037/CMP0037-OLD.cmake b/Tests/RunCMake/CMP0037/CMP0037-OLD.cmake
new file mode 100644
index 0000000..af98f12
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/CMP0037-OLD.cmake
@@ -0,0 +1,5 @@
+
+cmake_policy(SET CMP0037 OLD)
+
+add_library("lib with spaces" empty.cpp)
+add_executable("exe with spaces" empty.cpp)
diff --git a/Tests/RunCMake/CMP0037/CMP0037-WARN-result.txt b/Tests/RunCMake/CMP0037/CMP0037-WARN-result.txt
new file mode 100644
index 0000000..573541a
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/CMP0037-WARN-result.txt
@@ -0,0 +1 @@
+0
diff --git a/Tests/RunCMake/CMP0037/CMP0037-WARN-stderr.txt b/Tests/RunCMake/CMP0037/CMP0037-WARN-stderr.txt
new file mode 100644
index 0000000..e7a9e1d
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/CMP0037-WARN-stderr.txt
@@ -0,0 +1,43 @@
+CMake Warning \(dev\) at CMP0037-WARN.cmake:2 \(add_library\):
+  Policy CMP0037 is not set: Target names should match a validity pattern.
+  Run "cmake --help-policy CMP0037" for policy details.  Use the cmake_policy
+  command to set the policy and suppress this warning.
+
+  The target name "lib with spaces" is not valid for certain CMake features,
+  such as generator expressions, and may result in undefined behavior.
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)
+This warning is for project developers.  Use -Wno-dev to suppress it.
++
+CMake Warning \(dev\) at CMP0037-WARN.cmake:3 \(add_executable\):
+  Policy CMP0037 is not set: Target names should match a validity pattern.
+  Run "cmake --help-policy CMP0037" for policy details.  Use the cmake_policy
+  command to set the policy and suppress this warning.
+
+  The target name "exe with spaces" is not valid for certain CMake features,
+  such as generator expressions, and may result in undefined behavior.
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)
+This warning is for project developers.  Use -Wno-dev to suppress it.
++
+CMake Warning \(dev\) at CMP0037-WARN.cmake:4 \(add_library\):
+  Policy CMP0037 is not set: Target names should match a validity pattern.
+  Run "cmake --help-policy CMP0037" for policy details.  Use the cmake_policy
+  command to set the policy and suppress this warning.
+
+  The target name "lib:colon" is not valid for certain CMake features, such
+  as generator expressions, and may result in undefined behavior.
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)
+This warning is for project developers.  Use -Wno-dev to suppress it.
++
+CMake Warning \(dev\) at CMP0037-WARN.cmake:5 \(add_executable\):
+  Policy CMP0037 is not set: Target names should match a validity pattern.
+  Run "cmake --help-policy CMP0037" for policy details.  Use the cmake_policy
+  command to set the policy and suppress this warning.
+
+  The target name "exe:colon" is not valid for certain CMake features, such
+  as generator expressions, and may result in undefined behavior.
+Call Stack \(most recent call first\):
+  CMakeLists.txt:3 \(include\)
+This warning is for project developers.  Use -Wno-dev to suppress it.
diff --git a/Tests/RunCMake/CMP0037/CMP0037-WARN.cmake b/Tests/RunCMake/CMP0037/CMP0037-WARN.cmake
new file mode 100644
index 0000000..2beaad0
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/CMP0037-WARN.cmake
@@ -0,0 +1,5 @@
+
+add_library("lib with spaces" empty.cpp)
+add_executable("exe with spaces" empty.cpp)
+add_library("lib:colon" empty.cpp)
+add_executable("exe:colon" empty.cpp)
diff --git a/Tests/RunCMake/CMP0037/CMakeLists.txt b/Tests/RunCMake/CMP0037/CMakeLists.txt
new file mode 100644
index 0000000..f1d9cae
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.4)
+project(${RunCMake_TEST} CXX)
+include(${RunCMake_TEST}.cmake NO_POLICY_SCOPE)
diff --git a/Tests/RunCMake/CMP0037/RunCMakeTest.cmake b/Tests/RunCMake/CMP0037/RunCMakeTest.cmake
new file mode 100644
index 0000000..e983526
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/RunCMakeTest.cmake
@@ -0,0 +1,5 @@
+include(RunCMake)
+
+run_cmake(CMP0037-NEW)
+run_cmake(CMP0037-OLD)
+run_cmake(CMP0037-WARN)
diff --git a/Tests/RunCMake/CMP0037/empty.cpp b/Tests/RunCMake/CMP0037/empty.cpp
new file mode 100644
index 0000000..bfbbdde
--- /dev/null
+++ b/Tests/RunCMake/CMP0037/empty.cpp
@@ -0,0 +1,7 @@
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int empty()
+{
+  return 0;
+}
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt
index 99a0fb3..3395bd3 100644
--- a/Tests/RunCMake/CMakeLists.txt
+++ b/Tests/RunCMake/CMakeLists.txt
@@ -56,6 +56,10 @@ add_RunCMake_test(CMP0022)
 add_RunCMake_test(CMP0026)
 add_RunCMake_test(CMP0027)
 add_RunCMake_test(CMP0028)
+if (NOT "${CMAKE_TEST_GENERATOR}" MATCHES "Borland"
+    AND NOT "${CMAKE_TEST_GENERATOR}" MATCHES "NMake")
+  add_RunCMake_test(CMP0037)
+endif()
 add_RunCMake_test(CTest)
 if(UNIX AND "${CMAKE_TEST_GENERATOR}" MATCHES "Unix Makefiles")
   add_RunCMake_test(CompilerChange)

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

Summary of changes:


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list