Explorar o código

CMP0034: Remove support for OLD utility_source command

Brad King hai 1 ano
pai
achega
84c3943873

+ 4 - 3
Help/policy/CMP0034.rst

@@ -1,6 +1,9 @@
 CMP0034
 -------
 
+.. |REMOVED_IN_CMAKE_VERSION| replace:: 4.0
+.. include:: REMOVED_PROLOGUE.txt
+
 The :command:`utility_source` command should not be called.
 
 This command was introduced in March 2001 to help build executables used to
@@ -8,6 +11,4 @@ generate other files.  This approach has long been replaced by
 :command:`add_executable` combined with :command:`add_custom_command`.
 
 .. |disallowed_version| replace:: 3.0
-.. include:: DISALLOWED_COMMAND.txt
-
-.. include:: DEPRECATED.txt
+.. include:: REMOVED_COMMAND.txt

+ 0 - 2
Source/CMakeLists.txt

@@ -752,8 +752,6 @@ add_library(
   cmTryRunCommand.h
   cmUnsetCommand.cxx
   cmUnsetCommand.h
-  cmUtilitySourceCommand.cxx
-  cmUtilitySourceCommand.h
   cmVariableRequiresCommand.cxx
   cmVariableRequiresCommand.h
   cmVariableWatchCommand.cxx

+ 3 - 4
Source/cmCommands.cxx

@@ -109,7 +109,6 @@
 #  include "cmRemoveDefinitionsCommand.h"
 #  include "cmSourceGroupCommand.h"
 #  include "cmTargetLinkDirectoriesCommand.h"
-#  include "cmUtilitySourceCommand.h"
 #  include "cmVariableRequiresCommand.h"
 #  include "cmVariableWatchCommand.h"
 #  include "cmWriteFileCommand.h"
@@ -310,9 +309,9 @@ void GetProjectCommands(cmState* state)
   state->AddRemovedCommand(
     "subdir_depends",
     "The subdir_depends command has been removed; see CMP0029.");
-  state->AddDisallowedCommand(
-    "utility_source", cmUtilitySourceCommand, cmPolicies::CMP0034,
-    "The utility_source command should not be called; see CMP0034.");
+  state->AddRemovedCommand(
+    "utility_source",
+    "The utility_source command has been removed; see CMP0034.");
   state->AddDisallowedCommand(
     "variable_requires", cmVariableRequiresCommand, cmPolicies::CMP0035,
     "The variable_requires command should not be called; see CMP0035.");

+ 1 - 1
Source/cmPolicies.h

@@ -109,7 +109,7 @@ class cmMakefile;
          "The export_library_dependencies command should not be called.", 3,  \
          0, 0, NEW)                                                           \
   SELECT(POLICY, CMP0034, "The utility_source command should not be called.", \
-         3, 0, 0, WARN)                                                       \
+         3, 0, 0, NEW)                                                        \
   SELECT(POLICY, CMP0035,                                                     \
          "The variable_requires command should not be called.", 3, 0, 0,      \
          WARN)                                                                \

+ 0 - 118
Source/cmUtilitySourceCommand.cxx

@@ -1,118 +0,0 @@
-/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
-   file Copyright.txt or https://cmake.org/licensing for details.  */
-#include "cmUtilitySourceCommand.h"
-
-#include <cstring>
-
-#include "cmExecutionStatus.h"
-#include "cmMakefile.h"
-#include "cmState.h"
-#include "cmStateTypes.h"
-#include "cmStringAlgorithms.h"
-#include "cmSystemTools.h"
-#include "cmValue.h"
-
-// cmUtilitySourceCommand
-bool cmUtilitySourceCommand(std::vector<std::string> const& args,
-                            cmExecutionStatus& status)
-{
-  if (args.size() < 3) {
-    status.SetError("called with incorrect number of arguments");
-    return false;
-  }
-
-  auto arg = args.begin();
-
-  // The first argument is the cache entry name.
-  std::string const& cacheEntry = *arg++;
-  cmValue cacheValue = status.GetMakefile().GetDefinition(cacheEntry);
-  // If it exists already and appears up to date then we are done.  If
-  // the string contains "(IntDir)" but that is not the
-  // CMAKE_CFG_INTDIR setting then the value is out of date.
-  std::string const& intDir =
-    status.GetMakefile().GetRequiredDefinition("CMAKE_CFG_INTDIR");
-
-  bool haveCacheValue = false;
-  if (status.GetMakefile().IsOn("CMAKE_CROSSCOMPILING")) {
-    haveCacheValue = (cacheValue != nullptr);
-    if (!haveCacheValue) {
-      std::string msg = cmStrCat(
-        "UTILITY_SOURCE is used in cross compiling mode for ", cacheEntry,
-        ". If your intention is to run this executable, you need to "
-        "preload the cache with the full path to a version of that "
-        "program, which runs on this build machine.");
-      cmSystemTools::Message(msg, "Warning");
-    }
-  } else {
-    cmState* state = status.GetMakefile().GetState();
-    haveCacheValue = (cacheValue &&
-                      (strstr(cacheValue->c_str(), "(IntDir)") == nullptr ||
-                       (intDir == "$(IntDir)")) &&
-                      (state->GetCacheMajorVersion() != 0 &&
-                       state->GetCacheMinorVersion() != 0));
-  }
-
-  if (haveCacheValue) {
-    return true;
-  }
-
-  // The second argument is the utility's executable name, which will be
-  // needed later.
-  std::string const& utilityName = *arg++;
-
-  // The third argument specifies the relative directory of the source
-  // of the utility.
-  std::string const& relativeSource = *arg++;
-  std::string utilitySource = status.GetMakefile().GetCurrentSourceDirectory();
-  utilitySource = utilitySource + "/" + relativeSource;
-
-  // If the directory doesn't exist, the source has not been included.
-  if (!cmSystemTools::FileExists(utilitySource)) {
-    return true;
-  }
-
-  // Make sure all the files exist in the source directory.
-  while (arg != args.end()) {
-    std::string file = utilitySource + "/" + *arg++;
-    if (!cmSystemTools::FileExists(file)) {
-      return true;
-    }
-  }
-
-  // The source exists.
-  const std::string& cmakeCFGout =
-    status.GetMakefile().GetRequiredDefinition("CMAKE_CFG_INTDIR");
-  std::string utilityDirectory =
-    status.GetMakefile().GetCurrentBinaryDirectory();
-  std::string exePath;
-  if (cmValue d =
-        status.GetMakefile().GetDefinition("EXECUTABLE_OUTPUT_PATH")) {
-    exePath = *d;
-  }
-  if (!exePath.empty()) {
-    utilityDirectory = exePath;
-  } else {
-    utilityDirectory += "/" + relativeSource;
-  }
-
-  // Construct the cache entry for the executable's location.
-  std::string utilityExecutable = utilityDirectory + "/" + cmakeCFGout + "/" +
-    utilityName +
-    *status.GetMakefile().GetDefinition("CMAKE_EXECUTABLE_SUFFIX");
-
-  // make sure we remove any /./ in the name
-  cmSystemTools::ReplaceString(utilityExecutable, "/./", "/");
-
-  // Enter the value into the cache.
-  status.GetMakefile().AddCacheDefinition(cacheEntry, utilityExecutable,
-                                          "Path to an internal program.",
-                                          cmStateEnums::FILEPATH);
-  // add a value into the cache that maps from the
-  // full path to the name of the project
-  cmSystemTools::ConvertToUnixSlashes(utilityExecutable);
-  status.GetMakefile().AddCacheDefinition(utilityExecutable, utilityName,
-                                          "Executable to project name.",
-                                          cmStateEnums::INTERNAL);
-
-  return true;
-}

+ 0 - 13
Source/cmUtilitySourceCommand.h

@@ -1,13 +0,0 @@
-/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
-   file Copyright.txt or https://cmake.org/licensing for details.  */
-#pragma once
-
-#include "cmConfigure.h" // IWYU pragma: keep
-
-#include <string>
-#include <vector>
-
-class cmExecutionStatus;
-
-bool cmUtilitySourceCommand(std::vector<std::string> const& args,
-                            cmExecutionStatus& status);

+ 0 - 1
Tests/Complex/CMakeLists.txt

@@ -22,7 +22,6 @@ message("message")
 # It is not recommended to set a policy to OLD, but this test
 # covers the OLD behavior of some policies.
 foreach(p
-    CMP0034
     CMP0043
     CMP0050
     )

+ 1 - 6
Tests/Complex/Library/CMakeLists.txt

@@ -1,11 +1,6 @@
 remove_definitions(-DCMAKE_IS_REALLY_FUN)
 
-#
-# Small utility used to create file
-# UTILITY_SOURCE is used for coverage and for getting the exact name
-# of the executable.
-#
-utility_source(CREATE_FILE_EXE create_file "." create_file.cxx)
+set(CREATE_FILE_EXE create_file CACHE INTERNAL "") # make globally visible
 add_executable(create_file create_file.cxx)
 set_target_properties(create_file PROPERTIES RUNTIME_OUTPUT_DIRECTORY ".")
 

+ 0 - 1
Tests/ComplexOneConfig/CMakeLists.txt

@@ -15,7 +15,6 @@ string(APPEND CMAKE_CXX_FLAGS_MINSIZEREL " -DCOMPLEX_NDEBUG")
 # It is not recommended to set a policy to OLD, but this test
 # covers the OLD behavior of some policies.
 foreach(p
-    CMP0034
     CMP0043
     CMP0050
     )

+ 1 - 6
Tests/ComplexOneConfig/Library/CMakeLists.txt

@@ -1,11 +1,6 @@
 remove_definitions(-DCMAKE_IS_REALLY_FUN)
 
-#
-# Small utility used to create file
-# UTILITY_SOURCE is used for coverage and for getting the exact name
-# of the executable.
-#
-utility_source(CREATE_FILE_EXE create_file "." create_file.cxx)
+set(CREATE_FILE_EXE create_file CACHE INTERNAL "") # make globally visible
 add_executable(create_file create_file.cxx)
 set_target_properties(create_file PROPERTIES RUNTIME_OUTPUT_DIRECTORY ".")
 

+ 2 - 2
Tests/RunCMake/DisallowedCommands/CMP0034-NEW-stderr.txt

@@ -1,4 +1,4 @@
-CMake Error at CMP0034-NEW.cmake:2 \(utility_source\):
-  The utility_source command should not be called; see CMP0034.
+CMake Error at CMP0034-NEW.cmake:1 \(utility_source\):
+  The utility_source command has been removed; see CMP0034.
 Call Stack \(most recent call first\):
   CMakeLists.txt:3 \(include\)

+ 0 - 1
Tests/RunCMake/DisallowedCommands/CMP0034-NEW.cmake

@@ -1,2 +1 @@
-cmake_policy(SET CMP0034 NEW)
 utility_source()

+ 0 - 1
Tests/RunCMake/DisallowedCommands/CMP0034-OLD-result.txt

@@ -1 +0,0 @@
-1

+ 0 - 4
Tests/RunCMake/DisallowedCommands/CMP0034-OLD-stderr.txt

@@ -1,4 +0,0 @@
-CMake Error at CMP0034-OLD.cmake:2 \(utility_source\):
-  utility_source called with incorrect number of arguments
-Call Stack \(most recent call first\):
-  CMakeLists.txt:3 \(include\)

+ 0 - 2
Tests/RunCMake/DisallowedCommands/CMP0034-OLD.cmake

@@ -1,2 +0,0 @@
-cmake_policy(SET CMP0034 OLD)
-utility_source()

+ 0 - 1
Tests/RunCMake/DisallowedCommands/CMP0034-WARN-result.txt

@@ -1 +0,0 @@
-1

+ 0 - 12
Tests/RunCMake/DisallowedCommands/CMP0034-WARN-stderr.txt

@@ -1,12 +0,0 @@
-CMake Warning \(dev\) at CMP0034-WARN.cmake:1 \(utility_source\):
-  Policy CMP0034 is not set: The utility_source command should not be called.
-  Run "cmake --help-policy CMP0034" for policy details.  Use the cmake_policy
-  command to set the policy and suppress this warning.
-Call Stack \(most recent call first\):
-  CMakeLists.txt:3 \(include\)
-This warning is for project developers.  Use -Wno-dev to suppress it.
-
-CMake Error at CMP0034-WARN.cmake:1 \(utility_source\):
-  utility_source called with incorrect number of arguments
-Call Stack \(most recent call first\):
-  CMakeLists.txt:3 \(include\)

+ 0 - 1
Tests/RunCMake/DisallowedCommands/CMP0034-WARN.cmake

@@ -1 +0,0 @@
-utility_source()

+ 1 - 1
Tests/RunCMake/DisallowedCommands/RunCMakeTest.cmake

@@ -6,6 +6,7 @@ foreach(p
     CMP0031
     CMP0032
     CMP0033
+    CMP0034
     )
   run_cmake(${p}-NEW)
 endforeach()
@@ -13,7 +14,6 @@ endforeach()
 return()
 
 foreach(p
-    CMP0034
     CMP0035
     CMP0036
     )