1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmInstallGenerator.cxx,v $
6 Date: $Date: 2009-03-16 14:39:48 $
7 Version: $Revision: 1.17 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmInstallGenerator.h"
19 #include "cmSystemTools.h"
22 //----------------------------------------------------------------------------
24 ::cmInstallGenerator(const char* destination
,
25 std::vector
<std::string
> const& configurations
,
26 const char* component
):
27 cmScriptGenerator("CMAKE_INSTALL_CONFIG_NAME", configurations
),
28 Destination(destination
? destination
:""),
29 Component(component
? component
:"")
33 //----------------------------------------------------------------------------
35 ::~cmInstallGenerator()
39 //----------------------------------------------------------------------------
40 void cmInstallGenerator
44 std::vector
<std::string
> const& files
,
45 bool optional
/* = false */,
46 const char* properties
/* = 0 */,
47 const char* permissions_file
/* = 0 */,
48 const char* permissions_dir
/* = 0 */,
49 const char* rename
/* = 0 */,
50 const char* literal_args
/* = 0 */,
54 // Use the FILE command to install the file.
58 case cmTarget::INSTALL_DIRECTORY
:stype
= "DIRECTORY"; break;
59 case cmTarget::INSTALL_PROGRAMS
: stype
= "PROGRAM"; break;
60 case cmTarget::EXECUTABLE
: stype
= "EXECUTABLE"; break;
61 case cmTarget::STATIC_LIBRARY
: stype
= "STATIC_LIBRARY"; break;
62 case cmTarget::SHARED_LIBRARY
: stype
= "SHARED_LIBRARY"; break;
63 case cmTarget::MODULE_LIBRARY
: stype
= "MODULE"; break;
64 case cmTarget::INSTALL_FILES
:
65 default: stype
= "FILE"; break;
68 std::string dest
= this->GetInstallDestination();
69 os
<< "FILE(INSTALL DESTINATION \"" << dest
<< "\" TYPE " << stype
.c_str();
74 if(properties
&& *properties
)
76 os
<< " PROPERTIES" << properties
;
78 if(permissions_file
&& *permissions_file
)
80 os
<< " PERMISSIONS" << permissions_file
;
82 if(permissions_dir
&& *permissions_dir
)
84 os
<< " DIR_PERMISSIONS" << permissions_dir
;
88 os
<< " RENAME \"" << rename
<< "\"";
93 os
<< " \"" << files
[0] << "\"";
97 for(std::vector
<std::string
>::const_iterator fi
= files
.begin();
98 fi
!= files
.end(); ++fi
)
100 os
<< "\n" << indent
<< " \"" << *fi
<< "\"";
102 os
<< "\n" << indent
<< " ";
103 if(!(literal_args
&& *literal_args
))
108 if(literal_args
&& *literal_args
)
115 //----------------------------------------------------------------------------
117 cmInstallGenerator::CreateComponentTest(const char* component
)
119 std::string result
= "NOT CMAKE_INSTALL_COMPONENT OR "
120 "\"${CMAKE_INSTALL_COMPONENT}\" STREQUAL \"";
126 //----------------------------------------------------------------------------
127 void cmInstallGenerator::GenerateScript(std::ostream
& os
)
129 // Track indentation.
132 // Begin this block of installation.
133 std::string component_test
=
134 this->CreateComponentTest(this->Component
.c_str());
135 os
<< indent
<< "IF(" << component_test
<< ")\n";
137 // Generate the script possibly with per-configuration code.
138 this->GenerateScriptConfigs(os
, indent
.Next());
140 // End this block of installation.
141 os
<< indent
<< "ENDIF(" << component_test
<< ")\n\n";
144 //----------------------------------------------------------------------------
145 bool cmInstallGenerator::InstallsForConfig(const char* config
)
147 return this->GeneratesForConfig(config
);
150 //----------------------------------------------------------------------------
151 std::string
cmInstallGenerator::GetInstallDestination() const
154 if(!this->Destination
.empty() &&
155 !cmSystemTools::FileIsFullPath(this->Destination
.c_str()))
157 result
= "${CMAKE_INSTALL_PREFIX}/";
159 result
+= this->Destination
;