cmCMakePolicyCommand.h 5.21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
/*=========================================================================

  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 cmCMakePolicyCommand_h
#define cmCMakePolicyCommand_h

#include "cmCommand.h"

/** \class cmCMakePolicyCommand
 * \brief Set how CMake should handle policies
 *
 * cmCMakePolicyCommand sets how CMake should deal with backwards 
 * compatibility policies.   
 */
class cmCMakePolicyCommand : public cmCommand
{
public:
  /**
   * This is a virtual constructor for the command.
   */
  virtual cmCommand* Clone() 
    {
    return new cmCMakePolicyCommand;
    }

  /**
   * This is called when the command is first encountered in
   * the CMakeLists.txt file.
   */
  virtual bool InitialPass(std::vector<std::string> const& args,
                           cmExecutionStatus &status);

 /**
   * This determines if the command is invoked when in script mode.
   */
  virtual bool IsScriptable() { return true; }

 /**
   * The name of the command as specified in CMakeList.txt.
   */
  virtual const char* GetName() {return "cmake_policy";}
  
 /**
   * Succinct documentation.
   */
  virtual const char* GetTerseDocumentation() 
    {
61
    return "Manage CMake Policy settings.";
62 63 64 65 66 67 68 69
    }
  
  /**
   * More documentation.
   */
  virtual const char* GetFullDocumentation()
    {
    return
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
      "As CMake evolves it is sometimes necessary to change existing "
      "behavior in order to fix bugs or improve implementations of "
      "existing features.  "
      "The CMake Policy mechanism is designed to help keep existing projects "
      "building as new versions of CMake introduce changes in behavior.  "
      "Each new policy (behavioral change) is given an identifier of "
      "the form \"CMP<NNNN>\" where \"<NNNN>\" is an integer index.  "
      "Documentation associated with each policy describes the OLD and NEW "
      "behavior and the reason the policy was introduced.  "
      "Projects may set each policy to select the desired behavior.  "
      "When CMake needs to know which behavior to use it checks for "
      "a setting specified by the project.  "
      "If no setting is available the OLD behavior is assumed and a warning "
      "is produced requesting that the policy be set.\n"
      "The cmake_policy command is used to set policies to OLD or NEW "
      "behavior.  "
      "While setting policies individually is supported, we encourage "
      "projects to set policies based on CMake versions.\n"
88 89 90 91
      "  cmake_policy(VERSION major.minor[.patch])\n"
      "Specify that the current CMake list file is written for the "
      "given version of CMake.  "
      "All policies introduced in the specified version or earlier "
92 93 94
      "will be set to use NEW behavior.  "
      "All policies introduced after the specified version will be reset "
      "to use OLD behavior with a warning.  "
95 96
      "This effectively requests behavior preferred as of a given CMake "
      "version and tells newer CMake versions to warn about their new "
97 98 99 100
      "policies.  "
      "The policy version specified must be at least 2.4 or the command "
      "will report an error.  "
      "In order to get compatibility features supporting versions earlier "
Ken Martin's avatar
Ken Martin committed
101
      "than 2.4 see documentation of policy CMP0001."
102
      "\n"
103 104
      "  cmake_policy(SET CMP<NNNN> NEW)\n"
      "  cmake_policy(SET CMP<NNNN> OLD)\n"
105 106 107 108 109 110
      "Tell CMake to use the OLD or NEW behavior for a given policy.  "
      "Projects depending on the old behavior of a given policy may "
      "silence a policy warning by setting the policy state to OLD.  "
      "Alternatively one may fix the project to work with the new behavior "
      "and set the policy state to NEW."
      "\n"
111 112 113 114 115
      "  cmake_policy(GET CMP<NNNN> <variable>)\n"
      "Check whether a given policy is set to OLD or NEW behavior.  "
      "The output variable value will be \"OLD\" or \"NEW\" if the "
      "policy is set, and empty otherwise."
      "\n"
116 117 118 119 120 121
      "CMake keeps policy settings on a stack, so changes made by the "
      "cmake_policy command affect only the top of the stack.  "
      "A new entry on the policy stack is managed automatically for each "
      "subdirectory to protect its parents and siblings.  "
      "The cmake_policy command provides an interface to manage custom "
      "entries on the policy stack:\n"
122 123
      "  cmake_policy(PUSH)\n"
      "  cmake_policy(POP)\n"
124 125 126
      "Each PUSH must have a matching POP to erase any changes.  "
      "This is useful to make temporary changes to policy settings."
      ;
127 128 129
    }
  
  cmTypeMacro(cmCMakePolicyCommand, cmCommand);
130 131
private:
  bool HandleSetMode(std::vector<std::string> const& args);
132
  bool HandleGetMode(std::vector<std::string> const& args);
133
  bool HandleVersionMode(std::vector<std::string> const& args);
134 135 136 137 138
};



#endif