Prechádzať zdrojové kódy

ENH: Added INSTALL command as a placeholder for a future generic install specification interface. Currently it supports only a SCRIPT option specifying a script to run during the install stage.

Brad King 20 rokov pred
rodič
commit
b8a33fb424

Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 0 - 0
Docs/cmake-mode.el


+ 2 - 0
Source/cmCommands.cxx

@@ -26,6 +26,7 @@
 #include "cmGetDirectoryPropertyCommand.cxx"
 #include "cmGetTestPropertyCommand.cxx"
 #include "cmIncludeExternalMSProjectCommand.cxx"
+#include "cmInstallCommand.cxx"
 #include "cmLinkLibrariesCommand.cxx"
 #include "cmLoadCacheCommand.cxx"
 #include "cmMathCommand.cxx"
@@ -68,6 +69,7 @@ void GetPredefinedCommands(std::list<cmCommand*>&
   commands.push_back(new cmGetDirectoryPropertyCommand);
   commands.push_back(new cmGetTestPropertyCommand);
   commands.push_back(new cmIncludeExternalMSProjectCommand);
+  commands.push_back(new cmInstallCommand);
   commands.push_back(new cmLinkLibrariesCommand);
   commands.push_back(new cmLoadCacheCommand);
   commands.push_back(new cmLoadCommandCommand);

+ 54 - 0
Source/cmInstallCommand.cxx

@@ -0,0 +1,54 @@
+/*=========================================================================
+
+  Program:   CMake - Cross-Platform Makefile Generator
+  Module:    $RCSfile$
+  Language:  C++
+  Date:      $Date$
+  Version:   $Revision$
+
+  Copyright (c) 2002 Kitware, Inc., Insight Consortium.  All rights reserved.
+  See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
+
+     This software is distributed WITHOUT ANY WARRANTY; without even
+     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+     PURPOSE.  See the above copyright notices for more information.
+
+=========================================================================*/
+#include "cmInstallCommand.h"
+
+// cmInstallCommand
+bool cmInstallCommand::InitialPass(std::vector<std::string> const& args)
+{
+  bool doing_script = false;
+  for(size_t i=0; i < args.size(); ++i)
+    {
+    if(args[i] == "SCRIPT")
+      {
+      doing_script = true;
+      }
+    else if(doing_script)
+      {
+      doing_script = false;
+      std::string script = args[i];
+      if(!cmSystemTools::FileIsFullPath(script.c_str()))
+        {
+        script = m_Makefile->GetCurrentDirectory();
+        script += "/";
+        script += args[i];
+        }
+      if(cmSystemTools::FileIsDirectory(script.c_str()))
+        {
+        this->SetError("given a directory as value of SCRIPT argument.");
+        return false;
+        }
+      m_Makefile->AddInstallScript(script.c_str());
+      }
+    }
+  if(doing_script)
+    {
+    this->SetError("given no value for SCRIPT argument.");
+    return false;
+    }
+
+  return true;
+}

+ 80 - 0
Source/cmInstallCommand.h

@@ -0,0 +1,80 @@
+/*=========================================================================
+
+  Program:   CMake - Cross-Platform Makefile Generator
+  Module:    $RCSfile$
+  Language:  C++
+  Date:      $Date$
+  Version:   $Revision$
+
+  Copyright (c) 2002 Kitware, Inc., Insight Consortium.  All rights reserved.
+  See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
+
+     This software is distributed WITHOUT ANY WARRANTY; without even
+     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+     PURPOSE.  See the above copyright notices for more information.
+
+=========================================================================*/
+#ifndef cmInstallCommand_h
+#define cmInstallCommand_h
+
+#include "cmCommand.h"
+
+/** \class cmInstallCommand
+ * \brief Specifies where to install some files
+ *
+ * cmInstallCommand is a general-purpose interface command for
+ * specifying install rules.
+ */
+class cmInstallCommand : public cmCommand
+{
+public:
+  /**
+   * This is a virtual constructor for the command.
+   */
+  virtual cmCommand* Clone()
+    {
+    return new cmInstallCommand;
+    }
+
+  /**
+   * This is called when the command is first encountered in
+   * the CMakeLists.txt file.
+   */
+  virtual bool InitialPass(std::vector<std::string> const& args);
+
+  /**
+   * The name of the command as specified in CMakeList.txt.
+   */
+  virtual const char* GetName() { return "INSTALL";}
+
+  /**
+   * Succinct documentation.
+   */
+  virtual const char* GetTerseDocumentation()
+    {
+    return "Install rule specification interface command.";
+    }
+
+  /**
+   * More documentation.
+   */
+  virtual const char* GetFullDocumentation()
+    {
+    return
+      "  INSTALL(SCRIPT <script1> [SCRIPT <script2> [...]])\n"
+      "Specify rules to run at install time.  If SCRIPT is given the "
+      "file named after it will be included in the install scripts.  "
+      "Multiple SCRIPTs may be given within a single source directory "
+      "and the scripts will be run in the order given.  "
+      "The processing order of these scripts relative to install rules "
+      "generated by INSTALL_TARGETS, INSTALL_FILES, and INSTALL_PROGRAMS "
+      "commands is not specified.\n"
+      "This command is a placeholder for a future larger interface."
+      ;
+    }
+
+  cmTypeMacro(cmInstallCommand, cmCommand);
+};
+
+
+#endif

+ 9 - 0
Source/cmLocalGenerator.cxx

@@ -354,6 +354,15 @@ void cmLocalGenerator::GenerateInstallRules()
     exeOutPath = currdir + "/";
     }
 
+  // Include user-specified install scripts.
+  std::vector<std::string> const& installScripts =
+    m_Makefile->GetInstallScripts();
+  for(std::vector<std::string>::const_iterator s = installScripts.begin();
+      s != installScripts.end(); ++s)
+    {
+    fout << "INCLUDE(\"" << s->c_str() << "\")" << std::endl;
+    }
+
   std::string destination;
   for(cmTargets::iterator l = tgts.begin(); 
     l != tgts.end(); l++)

+ 9 - 1
Source/cmMakefile.h

@@ -671,7 +671,12 @@ public:
   ///! Set/Get the preorder flag
   void SetPreOrder(bool p) { this->PreOrder = p; }
   bool GetPreOrder() { return this->PreOrder; }
-    
+
+  /** Add a script file to be invoked during installation.  */
+  void AddInstallScript(const char* script)
+    { m_InstallScripts.push_back(script); }
+  std::vector<std::string> const& GetInstallScripts()
+    { return m_InstallScripts; }
 protected:
   // add link libraries and directories to the target
   void AddGlobalLinkInformation(const char* name, cmTarget& target);
@@ -704,6 +709,9 @@ protected:
   
   cmTarget::LinkLibraries m_LinkLibraries;
 
+  // List of install-time scripts.  This should not be inherited.
+  std::vector<std::string> m_InstallScripts;
+
   std::string m_IncludeFileRegularExpression;
   std::string m_ComplainFileRegularExpression;
   std::vector<std::string> m_SourceFileExtensions;

+ 17 - 0
Tests/SimpleInstall/CMakeLists.txt

@@ -19,6 +19,15 @@ IF(STAGE2)
   SET(t2NAMES test2 test2${CMAKE_DEBUG_POSTFIX})
   SET(t4NAMES test4 test4${CMAKE_DEBUG_POSTFIX})
 
+  # Make sure the install script ran.
+  SET(CMAKE_INSTALL_SCRIPT_DID_RUN 0)
+  INCLUDE(${CMAKE_INSTALL_PREFIX}/InstallScriptOut.cmake OPTIONAL)
+  IF(CMAKE_INSTALL_SCRIPT_DID_RUN)
+    MESSAGE(STATUS "Stage 1 did run install script 2.")
+  ELSE(CMAKE_INSTALL_SCRIPT_DID_RUN)
+    MESSAGE(SEND_ERROR "Stage 1 did not run install script 2.")
+  ENDIF(CMAKE_INSTALL_SCRIPT_DID_RUN)
+
   IF(CYGWIN OR MINGW)
     SET(LIBPATHS ${LIBPATHS} "${CMAKE_INSTALL_PREFIX}/bin")
   ENDIF(CYGWIN OR MINGW)
@@ -70,6 +79,14 @@ ELSE(STAGE2)
   INSTALL_TARGETS(/lib test1 test2 test3 test4)
   INSTALL_FILES(/include FILES lib1.h lib2.h lib3.h)
 
+  # Test user-specified install scripts.
+  INSTALL(
+    SCRIPT InstallScript1.cmake
+    SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/InstallScript2.cmake
+    )
+  SET_DIRECTORY_PROPERTIES(PROPERTIES
+    ADDITIONAL_MAKE_CLEAN_FILES ${CMAKE_INSTALL_PREFIX}/InstallScriptOut.cmake)
+
   SET_TARGET_PROPERTIES(SimpleInstall PROPERTIES OUTPUT_NAME SimpleInstallExe)
   # Disable VERSION test until it is implemented in the XCode generator.
   #SET_TARGET_PROPERTIES(SimpleInstall PROPERTIES VERSION 1.2)

+ 2 - 0
Tests/SimpleInstall/InstallScript1.cmake

@@ -0,0 +1,2 @@
+MESSAGE("This is install script 1.")
+SET(INSTALL_SCRIPT_1_DID_RUN 1)

+ 9 - 0
Tests/SimpleInstall/InstallScript2.cmake

@@ -0,0 +1,9 @@
+MESSAGE("This is install script 2.")
+IF(INSTALL_SCRIPT_1_DID_RUN)
+  MESSAGE("Install script ordering works.")
+ELSE(INSTALL_SCRIPT_1_DID_RUN)
+  MESSAGE(FATAL_ERROR "Install script 1 did not run before install script 2.")
+ENDIF(INSTALL_SCRIPT_1_DID_RUN)
+FILE(WRITE "${CMAKE_INSTALL_PREFIX}/InstallScriptOut.cmake"
+  "SET(CMAKE_INSTALL_SCRIPT_DID_RUN 1)\n"
+  )

+ 17 - 0
Tests/SimpleInstallS2/CMakeLists.txt

@@ -19,6 +19,15 @@ IF(STAGE2)
   SET(t2NAMES test2 test2${CMAKE_DEBUG_POSTFIX})
   SET(t4NAMES test4 test4${CMAKE_DEBUG_POSTFIX})
 
+  # Make sure the install script ran.
+  SET(CMAKE_INSTALL_SCRIPT_DID_RUN 0)
+  INCLUDE(${CMAKE_INSTALL_PREFIX}/InstallScriptOut.cmake OPTIONAL)
+  IF(CMAKE_INSTALL_SCRIPT_DID_RUN)
+    MESSAGE(STATUS "Stage 1 did run install script 2.")
+  ELSE(CMAKE_INSTALL_SCRIPT_DID_RUN)
+    MESSAGE(SEND_ERROR "Stage 1 did not run install script 2.")
+  ENDIF(CMAKE_INSTALL_SCRIPT_DID_RUN)
+
   IF(CYGWIN OR MINGW)
     SET(LIBPATHS ${LIBPATHS} "${CMAKE_INSTALL_PREFIX}/bin")
   ENDIF(CYGWIN OR MINGW)
@@ -70,6 +79,14 @@ ELSE(STAGE2)
   INSTALL_TARGETS(/lib test1 test2 test3 test4)
   INSTALL_FILES(/include FILES lib1.h lib2.h lib3.h)
 
+  # Test user-specified install scripts.
+  INSTALL(
+    SCRIPT InstallScript1.cmake
+    SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/InstallScript2.cmake
+    )
+  SET_DIRECTORY_PROPERTIES(PROPERTIES
+    ADDITIONAL_MAKE_CLEAN_FILES ${CMAKE_INSTALL_PREFIX}/InstallScriptOut.cmake)
+
   SET_TARGET_PROPERTIES(SimpleInstall PROPERTIES OUTPUT_NAME SimpleInstallExe)
   # Disable VERSION test until it is implemented in the XCode generator.
   #SET_TARGET_PROPERTIES(SimpleInstall PROPERTIES VERSION 1.2)

+ 2 - 0
Tests/SimpleInstallS2/InstallScript1.cmake

@@ -0,0 +1,2 @@
+MESSAGE("This is install script 1.")
+SET(INSTALL_SCRIPT_1_DID_RUN 1)

+ 9 - 0
Tests/SimpleInstallS2/InstallScript2.cmake

@@ -0,0 +1,9 @@
+MESSAGE("This is install script 2.")
+IF(INSTALL_SCRIPT_1_DID_RUN)
+  MESSAGE("Install script ordering works.")
+ELSE(INSTALL_SCRIPT_1_DID_RUN)
+  MESSAGE(FATAL_ERROR "Install script 1 did not run before install script 2.")
+ENDIF(INSTALL_SCRIPT_1_DID_RUN)
+FILE(WRITE "${CMAKE_INSTALL_PREFIX}/InstallScriptOut.cmake"
+  "SET(CMAKE_INSTALL_SCRIPT_DID_RUN 1)\n"
+  )

Niektoré súbory nie sú zobrazené, pretože je v týchto rozdielových dátach zmenené mnoho súborov