CPackComponent.cmake 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. # - Build binary and source package installers
  2. #
  3. # The CPackComponent module is the module which handles
  4. # the component part of CPack. See CPack module for
  5. # general information about CPack.
  6. #
  7. # For certain kinds of binary installers (including the graphical
  8. # installers on Mac OS X and Windows), CPack generates installers that
  9. # allow users to select individual application components to
  10. # install. The contents of each of the components are identified by
  11. # the COMPONENT argument of CMake's INSTALL command. These components
  12. # can be annotated with user-friendly names and descriptions,
  13. # inter-component dependencies, etc., and grouped in various ways to
  14. # customize the resulting installer. See the cpack_add_* commands,
  15. # described below, for more information about component-specific
  16. # installations.
  17. #
  18. # Component-specific installation allows users to select specific sets
  19. # of components to install during the install process. Installation
  20. # components are identified by the COMPONENT argument of CMake's
  21. # INSTALL commands, and should be further described by the following
  22. # CPack commands:
  23. #
  24. # cpack_add_component - Describes a CPack installation component
  25. # named by the COMPONENT argument to a CMake INSTALL command.
  26. #
  27. # cpack_add_component(compname
  28. # [DISPLAY_NAME name]
  29. # [DESCRIPTION description]
  30. # [HIDDEN | REQUIRED | DISABLED ]
  31. # [GROUP group]
  32. # [DEPENDS comp1 comp2 ... ]
  33. # [INSTALL_TYPES type1 type2 ... ]
  34. # [DOWNLOADED]
  35. # [ARCHIVE_FILE filename])
  36. #
  37. # The cmake_add_component command describes an installation
  38. # component, which the user can opt to install or remove as part of
  39. # the graphical installation process. compname is the name of the
  40. # component, as provided to the COMPONENT argument of one or more
  41. # CMake INSTALL commands.
  42. #
  43. # DISPLAY_NAME is the displayed name of the component, used in
  44. # graphical installers to display the component name. This value can
  45. # be any string.
  46. #
  47. # DESCRIPTION is an extended description of the component, used in
  48. # graphical installers to give the user additional information about
  49. # the component. Descriptions can span multiple lines using "\n" as
  50. # the line separator. Typically, these descriptions should be no
  51. # more than a few lines long.
  52. #
  53. # HIDDEN indicates that this component will be hidden in the
  54. # graphical installer, so that the user cannot directly change
  55. # whether it is installed or not.
  56. #
  57. # REQUIRED indicates that this component is required, and therefore
  58. # will always be installed. It will be visible in the graphical
  59. # installer, but it cannot be unselected. (Typically, required
  60. # components are shown greyed out).
  61. #
  62. # DISABLED indicates that this component should be disabled
  63. # (unselected) by default. The user is free to select this component
  64. # for installation, unless it is also HIDDEN.
  65. #
  66. # DEPENDS lists the components on which this component depends. If
  67. # this component is selected, then each of the components listed
  68. # must also be selected. The dependency information is encoded
  69. # within the installer itself, so that users cannot install
  70. # inconsitent sets of components.
  71. #
  72. # GROUP names the component group of which this component is a
  73. # part. If not provided, the component will be a standalone
  74. # component, not part of any component group. Component groups are
  75. # described with the cpack_add_component_group command, detailed
  76. # below.
  77. #
  78. # INSTALL_TYPES lists the installation types of which this component
  79. # is a part. When one of these installations types is selected, this
  80. # component will automatically be selected. Installation types are
  81. # described with the cpack_add_install_type command, detailed below.
  82. #
  83. # DOWNLOADED indicates that this component should be downloaded
  84. # on-the-fly by the installer, rather than packaged in with the
  85. # installer itself. For more information, see the cpack_configure_downloads
  86. # command.
  87. #
  88. # ARCHIVE_FILE provides a name for the archive file created by CPack
  89. # to be used for downloaded components. If not supplied, CPack will
  90. # create a file with some name based on CPACK_PACKAGE_FILE_NAME and
  91. # the name of the component. See cpack_configure_downloads for more
  92. # information.
  93. #
  94. # cpack_add_component_group - Describes a group of related CPack
  95. # installation components.
  96. #
  97. # cpack_add_component_group(groupname
  98. # [DISPLAY_NAME name]
  99. # [DESCRIPTION description]
  100. # [PARENT_GROUP parent]
  101. # [EXPANDED]
  102. # [BOLD_TITLE])
  103. #
  104. # The cpack_add_component_group describes a group of installation
  105. # components, which will be placed together within the listing of
  106. # options. Typically, component groups allow the user to
  107. # select/deselect all of the components within a single group via a
  108. # single group-level option. Use component groups to reduce the
  109. # complexity of installers with many options. groupname is an
  110. # arbitrary name used to identify the group in the GROUP argument of
  111. # the cpack_add_component command, which is used to place a
  112. # component in a group. The name of the group must not conflict with
  113. # the name of any component.
  114. #
  115. # DISPLAY_NAME is the displayed name of the component group, used in
  116. # graphical installers to display the component group name. This
  117. # value can be any string.
  118. #
  119. # DESCRIPTION is an extended description of the component group,
  120. # used in graphical installers to give the user additional
  121. # information about the components within that group. Descriptions
  122. # can span multiple lines using "\n" as the line
  123. # separator. Typically, these descriptions should be no more than a
  124. # few lines long.
  125. #
  126. # PARENT_GROUP, if supplied, names the parent group of this group.
  127. # Parent groups are used to establish a hierarchy of groups,
  128. # providing an arbitrary hierarchy of groups.
  129. #
  130. # EXPANDED indicates that, by default, the group should show up as
  131. # "expanded", so that the user immediately sees all of the
  132. # components within the group. Otherwise, the group will initially
  133. # show up as a single entry.
  134. #
  135. # BOLD_TITLE indicates that the group title should appear in bold,
  136. # to call the user's attention to the group.
  137. #
  138. # cpack_add_install_type - Add a new installation type containing a
  139. # set of predefined component selections to the graphical installer.
  140. #
  141. # cpack_add_install_type(typename
  142. # [DISPLAY_NAME name])
  143. #
  144. # The cpack_add_install_type command identifies a set of preselected
  145. # components that represents a common use case for an
  146. # application. For example, a "Developer" install type might include
  147. # an application along with its header and library files, while an
  148. # "End user" install type might just include the application's
  149. # executable. Each component identifies itself with one or more
  150. # install types via the INSTALL_TYPES argument to
  151. # cpack_add_component.
  152. #
  153. # DISPLAY_NAME is the displayed name of the install type, which will
  154. # typically show up in a drop-down box within a graphical
  155. # installer. This value can be any string.
  156. #
  157. # cpack_configure_downloads - Configure CPack to download selected
  158. # components on-the-fly as part of the installation process.
  159. #
  160. # cpack_configure_downloads(site
  161. # [UPLOAD_DIRECTORY dirname]
  162. # [ALL]
  163. # [ADD_REMOVE|NO_ADD_REMOVE])
  164. #
  165. # The cpack_configure_downloads command configures installation-time
  166. # downloads of selected components. For each downloadable component,
  167. # CPack will create an archive containing the contents of that
  168. # component, which should be uploaded to the given site. When the
  169. # user selects that component for installation, the installer will
  170. # download and extract the component in place. This feature is
  171. # useful for creating small installers that only download the
  172. # requested components, saving bandwidth. Additionally, the
  173. # installers are small enough that they will be installed as part of
  174. # the normal installation process, and the "Change" button in
  175. # Windows Add/Remove Programs control panel will allow one to add or
  176. # remove parts of the application after the original
  177. # installation. On Windows, the downloaded-components functionality
  178. # requires the ZipDLL plug-in for NSIS, available at:
  179. #
  180. # http://nsis.sourceforge.net/ZipDLL_plug-in
  181. #
  182. # On Mac OS X, installers that download components on-the-fly can
  183. # only be built and installed on system using Mac OS X 10.5 or
  184. # later.
  185. #
  186. # The site argument is a URL where the archives for downloadable
  187. # components will reside, e.g., http://www.cmake.org/files/2.6.1/installer/
  188. # All of the archives produced by CPack should be uploaded to that location.
  189. #
  190. # UPLOAD_DIRECTORY is the local directory where CPack will create the
  191. # various archives for each of the components. The contents of this
  192. # directory should be uploaded to a location accessible by the URL given
  193. # in the site argument. If omitted, CPack will use the directory
  194. # CPackUploads inside the CMake binary directory to store the generated
  195. # archives.
  196. #
  197. # The ALL flag indicates that all components be downloaded. Otherwise, only
  198. # those components explicitly marked as DOWNLOADED or that have a specified
  199. # ARCHIVE_FILE will be downloaded. Additionally, the ALL option implies
  200. # ADD_REMOVE (unless NO_ADD_REMOVE is specified).
  201. #
  202. # ADD_REMOVE indicates that CPack should install a copy of the installer
  203. # that can be called from Windows' Add/Remove Programs dialog (via the
  204. # "Modify" button) to change the set of installed components. NO_ADD_REMOVE
  205. # turns off this behavior. This option is ignored on Mac OS X.
  206. #=============================================================================
  207. # Copyright 2006-2009 Kitware, Inc.
  208. #
  209. # Distributed under the OSI-approved BSD License (the "License");
  210. # see accompanying file Copyright.txt for details.
  211. #
  212. # This software is distributed WITHOUT ANY WARRANTY; without even the
  213. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  214. # See the License for more information.
  215. #=============================================================================
  216. # (To distribute this file outside of CMake, substitute the full
  217. # License text for the above reference.)
  218. # Define var in order to avoid multiple inclusion
  219. IF(NOT CPackComponent_CMake_INCLUDED)
  220. SET(CPackComponent_CMake_INCLUDED 1)
  221. # Argument-parsing macro from http://www.cmake.org/Wiki/CMakeMacroParseArguments
  222. MACRO(cpack_parse_arguments prefix arg_names option_names)
  223. SET(${prefix}_DEFAULT_ARGS)
  224. FOREACH(arg_name ${arg_names})
  225. SET(${prefix}_${arg_name})
  226. ENDFOREACH(arg_name)
  227. FOREACH(option ${option_names})
  228. SET(${prefix}_${option} FALSE)
  229. ENDFOREACH(option)
  230. SET(current_arg_name DEFAULT_ARGS)
  231. SET(current_arg_list)
  232. FOREACH(arg ${ARGN})
  233. SET(larg_names ${arg_names})
  234. LIST(FIND larg_names "${arg}" is_arg_name)
  235. IF (is_arg_name GREATER -1)
  236. SET(${prefix}_${current_arg_name} ${current_arg_list})
  237. SET(current_arg_name ${arg})
  238. SET(current_arg_list)
  239. ELSE (is_arg_name GREATER -1)
  240. SET(loption_names ${option_names})
  241. LIST(FIND loption_names "${arg}" is_option)
  242. IF (is_option GREATER -1)
  243. SET(${prefix}_${arg} TRUE)
  244. ELSE (is_option GREATER -1)
  245. SET(current_arg_list ${current_arg_list} ${arg})
  246. ENDIF (is_option GREATER -1)
  247. ENDIF (is_arg_name GREATER -1)
  248. ENDFOREACH(arg)
  249. SET(${prefix}_${current_arg_name} ${current_arg_list})
  250. ENDMACRO(cpack_parse_arguments)
  251. # Macro that appends a SET command for the given variable name (var)
  252. # to the macro named strvar, but only if the variable named "var"
  253. # has been defined. The string will eventually be appended to a CPack
  254. # configuration file.
  255. MACRO(cpack_append_variable_set_command var strvar)
  256. IF (DEFINED ${var})
  257. SET(${strvar} "${${strvar}}SET(${var}")
  258. FOREACH(APPENDVAL ${${var}})
  259. SET(${strvar} "${${strvar}} ${APPENDVAL}")
  260. ENDFOREACH(APPENDVAL)
  261. SET(${strvar} "${${strvar}})\n")
  262. ENDIF (DEFINED ${var})
  263. ENDMACRO(cpack_append_variable_set_command)
  264. # Macro that appends a SET command for the given variable name (var)
  265. # to the macro named strvar, but only if the variable named "var"
  266. # has been defined and is a string. The string will eventually be
  267. # appended to a CPack configuration file.
  268. MACRO(cpack_append_string_variable_set_command var strvar)
  269. IF (DEFINED ${var})
  270. LIST(LENGTH ${var} CPACK_APP_VALUE_LEN)
  271. IF(${CPACK_APP_VALUE_LEN} EQUAL 1)
  272. SET(${strvar} "${${strvar}}SET(${var} \"${${var}}\")\n")
  273. ENDIF(${CPACK_APP_VALUE_LEN} EQUAL 1)
  274. ENDIF (DEFINED ${var})
  275. ENDMACRO(cpack_append_string_variable_set_command)
  276. # Macro that appends a SET command for the given variable name (var)
  277. # to the macro named strvar, but only if the variable named "var"
  278. # has been set to true. The string will eventually be
  279. # appended to a CPack configuration file.
  280. MACRO(cpack_append_option_set_command var strvar)
  281. IF (${var})
  282. LIST(LENGTH ${var} CPACK_APP_VALUE_LEN)
  283. IF(${CPACK_APP_VALUE_LEN} EQUAL 1)
  284. SET(${strvar} "${${strvar}}SET(${var} TRUE)\n")
  285. ENDIF(${CPACK_APP_VALUE_LEN} EQUAL 1)
  286. ENDIF (${var})
  287. ENDMACRO(cpack_append_option_set_command)
  288. # Macro that adds a component to the CPack installer
  289. MACRO(cpack_add_component compname)
  290. STRING(TOUPPER ${compname} CPACK_ADDCOMP_UNAME)
  291. cpack_parse_arguments(CPACK_COMPONENT_${CPACK_ADDCOMP_UNAME}
  292. "DISPLAY_NAME;DESCRIPTION;GROUP;DEPENDS;INSTALL_TYPES;ARCHIVE_FILE"
  293. "HIDDEN;REQUIRED;DISABLED;DOWNLOADED"
  294. ${ARGN}
  295. )
  296. if (CPACK_COMPONENT_${CPACK_ADDCOMP_UNAME}_DOWNLOADED)
  297. SET(CPACK_ADDCOMP_STR "\n# Configuration for downloaded component \"${compname}\"\n")
  298. else ()
  299. SET(CPACK_ADDCOMP_STR "\n# Configuration for component \"${compname}\"\n")
  300. endif ()
  301. IF(NOT CPACK_MONOLITHIC_INSTALL)
  302. # If the user didn't set CPACK_COMPONENTS_ALL explicitly, update the
  303. # value of CPACK_COMPONENTS_ALL in the configuration file. This will
  304. # take care of any components that have been added after the CPack
  305. # moduled was included.
  306. IF(NOT CPACK_COMPONENTS_ALL_SET_BY_USER)
  307. GET_CMAKE_PROPERTY(CPACK_ADDCOMP_COMPONENTS COMPONENTS)
  308. SET(CPACK_ADDCOMP_STR "${CPACK_ADDCOMP_STR}\nSET(CPACK_COMPONENTS_ALL")
  309. FOREACH(COMP ${CPACK_ADDCOMP_COMPONENTS})
  310. SET(CPACK_ADDCOMP_STR "${CPACK_ADDCOMP_STR} ${COMP}")
  311. ENDFOREACH(COMP)
  312. SET(CPACK_ADDCOMP_STR "${CPACK_ADDCOMP_STR})\n")
  313. ENDIF(NOT CPACK_COMPONENTS_ALL_SET_BY_USER)
  314. ENDIF(NOT CPACK_MONOLITHIC_INSTALL)
  315. cpack_append_string_variable_set_command(
  316. CPACK_COMPONENT_${CPACK_ADDCOMP_UNAME}_DISPLAY_NAME
  317. CPACK_ADDCOMP_STR)
  318. cpack_append_string_variable_set_command(
  319. CPACK_COMPONENT_${CPACK_ADDCOMP_UNAME}_DESCRIPTION
  320. CPACK_ADDCOMP_STR)
  321. cpack_append_variable_set_command(
  322. CPACK_COMPONENT_${CPACK_ADDCOMP_UNAME}_GROUP
  323. CPACK_ADDCOMP_STR)
  324. cpack_append_variable_set_command(
  325. CPACK_COMPONENT_${CPACK_ADDCOMP_UNAME}_DEPENDS
  326. CPACK_ADDCOMP_STR)
  327. cpack_append_variable_set_command(
  328. CPACK_COMPONENT_${CPACK_ADDCOMP_UNAME}_INSTALL_TYPES
  329. CPACK_ADDCOMP_STR)
  330. cpack_append_string_variable_set_command(
  331. CPACK_COMPONENT_${CPACK_ADDCOMP_UNAME}_ARCHIVE_FILE
  332. CPACK_ADDCOMP_STR)
  333. cpack_append_option_set_command(
  334. CPACK_COMPONENT_${CPACK_ADDCOMP_UNAME}_HIDDEN
  335. CPACK_ADDCOMP_STR)
  336. cpack_append_option_set_command(
  337. CPACK_COMPONENT_${CPACK_ADDCOMP_UNAME}_REQUIRED
  338. CPACK_ADDCOMP_STR)
  339. cpack_append_option_set_command(
  340. CPACK_COMPONENT_${CPACK_ADDCOMP_UNAME}_DISABLED
  341. CPACK_ADDCOMP_STR)
  342. cpack_append_option_set_command(
  343. CPACK_COMPONENT_${CPACK_ADDCOMP_UNAME}_DOWNLOADED
  344. CPACK_ADDCOMP_STR)
  345. # Backward compatibility issue.
  346. # Write to config iff the macros is used after CPack.cmake has been
  347. # included, other it's not necessary because the variables
  348. # will be encoded by cpack_encode_variables.
  349. IF(CPack_CMake_INCLUDED)
  350. FILE(APPEND "${CPACK_OUTPUT_CONFIG_FILE}" "${CPACK_ADDCOMP_STR}")
  351. ENDIF(CPack_CMake_INCLUDED)
  352. ENDMACRO(cpack_add_component)
  353. # Macro that adds a component group to the CPack installer
  354. MACRO(cpack_add_component_group grpname)
  355. STRING(TOUPPER ${grpname} CPACK_ADDGRP_UNAME)
  356. cpack_parse_arguments(CPACK_COMPONENT_GROUP_${CPACK_ADDGRP_UNAME}
  357. "DISPLAY_NAME;DESCRIPTION"
  358. "EXPANDED;BOLD_TITLE"
  359. ${ARGN}
  360. )
  361. SET(CPACK_ADDGRP_STR "\n# Configuration for component group \"${grpname}\"\n")
  362. cpack_append_string_variable_set_command(
  363. CPACK_COMPONENT_GROUP_${CPACK_ADDGRP_UNAME}_DISPLAY_NAME
  364. CPACK_ADDGRP_STR)
  365. cpack_append_string_variable_set_command(
  366. CPACK_COMPONENT_GROUP_${CPACK_ADDGRP_UNAME}_DESCRIPTION
  367. CPACK_ADDGRP_STR)
  368. cpack_append_option_set_command(
  369. CPACK_COMPONENT_GROUP_${CPACK_ADDGRP_UNAME}_EXPANDED
  370. CPACK_ADDGRP_STR)
  371. cpack_append_option_set_command(
  372. CPACK_COMPONENT_GROUP_${CPACK_ADDGRP_UNAME}_BOLD_TITLE
  373. CPACK_ADDGRP_STR)
  374. # Backward compatibility issue.
  375. # Write to config iff the macros is used after CPack.cmake has been
  376. # included, other it's not necessary because the variables
  377. # will be encoded by cpack_encode_variables.
  378. IF(CPack_CMake_INCLUDED)
  379. FILE(APPEND "${CPACK_OUTPUT_CONFIG_FILE}" "${CPACK_ADDGRP_STR}")
  380. ENDIF(CPack_CMake_INCLUDED)
  381. ENDMACRO(cpack_add_component_group)
  382. # Macro that adds an installation type to the CPack installer
  383. MACRO(cpack_add_install_type insttype)
  384. STRING(TOUPPER ${insttype} CPACK_INSTTYPE_UNAME)
  385. cpack_parse_arguments(CPACK_INSTALL_TYPE_${CPACK_INSTTYPE_UNAME}
  386. "DISPLAY_NAME"
  387. ""
  388. ${ARGN}
  389. )
  390. SET(CPACK_INSTTYPE_STR
  391. "\n# Configuration for installation type \"${insttype}\"\n")
  392. SET(CPACK_INSTTYPE_STR
  393. "${CPACK_INSTTYPE_STR}LIST(APPEND CPACK_ALL_INSTALL_TYPES ${insttype})\n")
  394. cpack_append_string_variable_set_command(
  395. CPACK_INSTALL_TYPE_${CPACK_INSTTYPE_UNAME}_DISPLAY_NAME
  396. CPACK_INSTTYPE_STR)
  397. # Backward compatibility issue.
  398. # Write to config iff the macros is used after CPack.cmake has been
  399. # included, other it's not necessary because the variables
  400. # will be encoded by cpack_encode_variables.
  401. IF(CPack_CMake_INCLUDED)
  402. FILE(APPEND "${CPACK_OUTPUT_CONFIG_FILE}" "${CPACK_INSTTYPE_STR}")
  403. ENDIF(CPack_CMake_INCLUDED)
  404. ENDMACRO(cpack_add_install_type)
  405. MACRO(cpack_configure_downloads site)
  406. cpack_parse_arguments(CPACK_DOWNLOAD
  407. "UPLOAD_DIRECTORY"
  408. "ALL;ADD_REMOVE;NO_ADD_REMOVE"
  409. ${ARGN}
  410. )
  411. SET(CPACK_CONFIG_DL_STR
  412. "\n# Downloaded components configuration\n")
  413. SET(CPACK_UPLOAD_DIRECTORY ${CPACK_DOWNLOAD_UPLOAD_DIRECTORY})
  414. SET(CPACK_DOWNLOAD_SITE ${site})
  415. cpack_append_string_variable_set_command(
  416. CPACK_DOWNLOAD_SITE
  417. CPACK_CONFIG_DL_STR)
  418. cpack_append_string_variable_set_command(
  419. CPACK_UPLOAD_DIRECTORY
  420. CPACK_CONFIG_DL_STR)
  421. cpack_append_option_set_command(
  422. CPACK_DOWNLOAD_ALL
  423. CPACK_CONFIG_DL_STR)
  424. IF (${CPACK_DOWNLOAD_ALL} AND NOT ${CPACK_DOWNLOAD_NO_ADD_REMOVE})
  425. SET(CPACK_DOWNLOAD_ADD_REMOVE ON)
  426. ENDIF (${CPACK_DOWNLOAD_ALL} AND NOT ${CPACK_DOWNLOAD_NO_ADD_REMOVE})
  427. SET(CPACK_ADD_REMOVE ${CPACK_DOWNLOAD_ADD_REMOVE})
  428. cpack_append_option_set_command(
  429. CPACK_ADD_REMOVE
  430. CPACK_CONFIG_DL_STR)
  431. # Backward compatibility issue.
  432. # Write to config iff the macros is used after CPack.cmake has been
  433. # included, other it's not necessary because the variables
  434. # will be encoded by cpack_encode_variables.
  435. IF(CPack_CMake_INCLUDED)
  436. FILE(APPEND "${CPACK_OUTPUT_CONFIG_FILE}" "${CPACK_CONFIG_DL_STR}")
  437. ENDIF(CPack_CMake_INCLUDED)
  438. ENDMACRO(cpack_configure_downloads)
  439. ENDIF(NOT CPackComponent_CMake_INCLUDED)