CPackComponent.cmake 19 KB

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