Browse Source

Merge topic 'file-GetRuntimeDependencies_support_cross_compilation'

f867423aa2 file: GetRuntimeDependencies use CMAKE_OBJDUMP when applicable

Acked-by: Kitware Robot <[email protected]>
Merge-request: !4538
Brad King 5 years ago
parent
commit
b8b804e2ed

+ 2 - 2
Help/command/file.rst

@@ -402,8 +402,8 @@ dependency resolution:
   Determines the path to the tool to use for dependency resolution. This is the
   Determines the path to the tool to use for dependency resolution. This is the
   actual path to ``objdump``, ``dumpbin``, or ``otool``.
   actual path to ``objdump``, ``dumpbin``, or ``otool``.
 
 
-  If this variable is not specified, it is determined automatically by system
-  introspection.
+  If this variable is not specified, it is determined by the value of
+  ``CMAKE_OBJDUMP`` if set, else by system introspection.
 
 
 Writing
 Writing
 ^^^^^^^
 ^^^^^^^

+ 65 - 0
Source/cmLocalGenerator.cxx

@@ -557,6 +557,71 @@ void cmLocalGenerator::GenerateInstallRules()
     /* clang-format on */
     /* clang-format on */
   }
   }
 
 
+  // Write out CMAKE_GET_RUNTIME_DEPENDENCIES_PLATFORM so that
+  // installed code that uses `file(GET_RUNTIME_DEPENDENCIES)`
+  // has same platform variable as when running cmake
+  if (const char* platform = this->Makefile->GetDefinition(
+        "CMAKE_GET_RUNTIME_DEPENDENCIES_PLATFORM")) {
+    /* clang-format off */
+    fout <<
+      "# Set default install directory permissions.\n"
+      "if(NOT DEFINED CMAKE_GET_RUNTIME_DEPENDENCIES_PLATFORM)\n"
+      "  set(CMAKE_GET_RUNTIME_DEPENDENCIES_PLATFORM \""
+         << platform << "\")\n"
+      "endif()\n"
+      "\n";
+    /* clang-format on */
+  }
+
+  // Write out CMAKE_GET_RUNTIME_DEPENDENCIES_TOOL so that
+  // installed code that uses `file(GET_RUNTIME_DEPENDENCIES)`
+  // has same tool selected as when running cmake
+  if (const char* command =
+        this->Makefile->GetDefinition("CMAKE_GET_RUNTIME_DEPENDENCIES_TOOL")) {
+    /* clang-format off */
+    fout <<
+      "# Set default install directory permissions.\n"
+      "if(NOT DEFINED CMAKE_GET_RUNTIME_DEPENDENCIES_TOOL)\n"
+      "  set(CMAKE_GET_RUNTIME_DEPENDENCIES_TOOL \""
+         << command << "\")\n"
+      "endif()\n"
+      "\n";
+    /* clang-format on */
+  }
+
+  // Write out CMAKE_GET_RUNTIME_DEPENDENCIES_COMMAND so that
+  // installed code that uses `file(GET_RUNTIME_DEPENDENCIES)`
+  // has same path to the tool as when running cmake
+  if (const char* command = this->Makefile->GetDefinition(
+        "CMAKE_GET_RUNTIME_DEPENDENCIES_COMMAND")) {
+    /* clang-format off */
+    fout <<
+      "# Set default install directory permissions.\n"
+      "if(NOT DEFINED CMAKE_GET_RUNTIME_DEPENDENCIES_COMMAND)\n"
+      "  set(CMAKE_GET_RUNTIME_DEPENDENCIES_COMMAND \""
+         << command << "\")\n"
+      "endif()\n"
+      "\n";
+    /* clang-format on */
+  }
+
+  // Write out CMAKE_OBJDUMP so that installed code that uses
+  // `file(GET_RUNTIME_DEPENDENCIES)` and hasn't specified
+  // CMAKE_GET_RUNTIME_DEPENDENCIES_COMMAND has consistent
+  // logic to fallback to CMAKE_OBJDUMP when `objdump` is
+  // not on the path
+  if (const char* command = this->Makefile->GetDefinition("CMAKE_OBJDUMP")) {
+    /* clang-format off */
+    fout <<
+      "# Set default install directory permissions.\n"
+      "if(NOT DEFINED CMAKE_OBJDUMP)\n"
+      "  set(CMAKE_OBJDUMP \""
+         << command << "\")\n"
+      "endif()\n"
+      "\n";
+    /* clang-format on */
+  }
+
   // Ask each install generator to write its code.
   // Ask each install generator to write its code.
   cmPolicies::PolicyStatus status = this->GetPolicyStatus(cmPolicies::CMP0082);
   cmPolicies::PolicyStatus status = this->GetPolicyStatus(cmPolicies::CMP0082);
   auto const& installers = this->Makefile->GetInstallGenerators();
   auto const& installers = this->Makefile->GetInstallGenerators();

+ 3 - 0
Source/cmRuntimeDependencyArchive.cxx

@@ -218,6 +218,9 @@ bool cmRuntimeDependencyArchive::GetGetRuntimeDependenciesCommand(
   // First see if it was supplied by the user
   // First see if it was supplied by the user
   std::string toolCommand = this->GetMakefile()->GetSafeDefinition(
   std::string toolCommand = this->GetMakefile()->GetSafeDefinition(
     "CMAKE_GET_RUNTIME_DEPENDENCIES_COMMAND");
     "CMAKE_GET_RUNTIME_DEPENDENCIES_COMMAND");
+  if (toolCommand.empty() && search == "objdump") {
+    toolCommand = this->GetMakefile()->GetSafeDefinition("CMAKE_OBJDUMP");
+  }
   if (!toolCommand.empty()) {
   if (!toolCommand.empty()) {
     cmExpandList(toolCommand, command);
     cmExpandList(toolCommand, command);
     return true;
     return true;

+ 1 - 0
Tests/RunCMake/install/RunCMakeTest.cmake

@@ -188,6 +188,7 @@ else()
 endif()
 endif()
 
 
 set(run_install_test_components 1)
 set(run_install_test_components 1)
+run_install_test(file-GET_RUNTIME_DEPENDENCIES-variable-propagation)
 run_install_test(FILES-EXCLUDE_FROM_ALL)
 run_install_test(FILES-EXCLUDE_FROM_ALL)
 run_install_test(TARGETS-EXCLUDE_FROM_ALL)
 run_install_test(TARGETS-EXCLUDE_FROM_ALL)
 run_install_test(TARGETS-NAMELINK_COMPONENT)
 run_install_test(TARGETS-NAMELINK_COMPONENT)

+ 1 - 0
Tests/RunCMake/install/file-GET_RUNTIME_DEPENDENCIES-variable-propagation-all-result.txt

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

+ 6 - 0
Tests/RunCMake/install/file-GET_RUNTIME_DEPENDENCIES-variable-propagation-all-stderr.txt

@@ -0,0 +1,6 @@
+^CMake Error at cmake_install\.cmake:[0-9]+ \(message\):
+.*
+.*CMAKE_GET_RUNTIME_DEPENDENCIES_PLATFORM: custom-platform.*
+.*CMAKE_GET_RUNTIME_DEPENDENCIES_TOOL: custom-platform-objdump.*
+.*CMAKE_GET_RUNTIME_DEPENDENCIES_COMMAND: path/to/custom-objdump.*
+.*CMAKE_OBJDUMP: custom-objdump.*

+ 1 - 0
Tests/RunCMake/install/file-GET_RUNTIME_DEPENDENCIES-variable-propagation-dev-result.txt

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

+ 6 - 0
Tests/RunCMake/install/file-GET_RUNTIME_DEPENDENCIES-variable-propagation-dev-stderr.txt

@@ -0,0 +1,6 @@
+^CMake Error at cmake_install\.cmake:[0-9]+ \(message\):
+.*
+.*CMAKE_GET_RUNTIME_DEPENDENCIES_PLATFORM: custom-platform.*
+.*CMAKE_GET_RUNTIME_DEPENDENCIES_TOOL: custom-platform-objdump.*
+.*CMAKE_GET_RUNTIME_DEPENDENCIES_COMMAND: path/to/custom-objdump.*
+.*CMAKE_OBJDUMP: custom-objdump.*

+ 17 - 0
Tests/RunCMake/install/file-GET_RUNTIME_DEPENDENCIES-variable-propagation.cmake

@@ -0,0 +1,17 @@
+enable_language(C)
+
+set(CMAKE_GET_RUNTIME_DEPENDENCIES_PLATFORM "custom-platform")
+set(CMAKE_GET_RUNTIME_DEPENDENCIES_TOOL "custom-platform-objdump")
+set(CMAKE_GET_RUNTIME_DEPENDENCIES_COMMAND "path/to/custom-objdump")
+set(CMAKE_OBJDUMP "custom-objdump")
+
+install(CODE [[
+message(FATAL_ERROR "
+  CMAKE_GET_RUNTIME_DEPENDENCIES_PLATFORM: ${CMAKE_GET_RUNTIME_DEPENDENCIES_PLATFORM}
+  CMAKE_GET_RUNTIME_DEPENDENCIES_TOOL: ${CMAKE_GET_RUNTIME_DEPENDENCIES_TOOL}
+  CMAKE_GET_RUNTIME_DEPENDENCIES_COMMAND: ${CMAKE_GET_RUNTIME_DEPENDENCIES_COMMAND}
+  CMAKE_OBJDUMP: ${CMAKE_OBJDUMP}
+")
+]]
+COMPONENT dev
+)