ExternalProject.cmake 118 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. ExternalProject
  5. ---------------
  6. .. only:: html
  7. .. contents::
  8. External Project Definition
  9. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  10. .. command:: ExternalProject_Add
  11. The ``ExternalProject_Add()`` function creates a custom target to drive
  12. download, update/patch, configure, build, install and test steps of an
  13. external project:
  14. .. code-block:: cmake
  15. ExternalProject_Add(<name> [<option>...])
  16. The individual steps within the process can be driven independently if
  17. required (e.g. for CDash submission) and extra custom steps can be defined,
  18. along with the ability to control the step dependencies. The directory
  19. structure used for the management of the external project can also be
  20. customized. The function supports a large number of options which can be used
  21. to tailor the external project behavior.
  22. **Directory Options:**
  23. Most of the time, the default directory layout is sufficient. It is largely
  24. an implementation detail that the main project usually doesn't need to
  25. change. In some circumstances, however, control over the directory layout
  26. can be useful or necessary. The directory options are potentially more
  27. useful from the point of view that the main build can use the
  28. :command:`ExternalProject_Get_Property` command to retrieve their values,
  29. thereby allowing the main project to refer to build artifacts of the
  30. external project.
  31. ``PREFIX <dir>``
  32. Root directory for the external project. Unless otherwise noted below,
  33. all other directories associated with the external project will be
  34. created under here.
  35. ``TMP_DIR <dir>``
  36. Directory in which to store temporary files.
  37. ``STAMP_DIR <dir>``
  38. Directory in which to store the timestamps of each step. Log files from
  39. individual steps are also created in here unless overriden by LOG_DIR
  40. (see *Logging Options* below).
  41. ``LOG_DIR <dir>``
  42. Directory in which to store the logs of each step.
  43. ``DOWNLOAD_DIR <dir>``
  44. Directory in which to store downloaded files before unpacking them. This
  45. directory is only used by the URL download method, all other download
  46. methods use ``SOURCE_DIR`` directly instead.
  47. ``SOURCE_DIR <dir>``
  48. Source directory into which downloaded contents will be unpacked, or for
  49. non-URL download methods, the directory in which the repository should be
  50. checked out, cloned, etc. If no download method is specified, this must
  51. point to an existing directory where the external project has already
  52. been unpacked or cloned/checked out.
  53. .. note::
  54. If a download method is specified, any existing contents of the source
  55. directory may be deleted. Only the URL download method checks whether
  56. this directory is either missing or empty before initiating the
  57. download, stopping with an error if it is not empty. All other
  58. download methods silently discard any previous contents of the source
  59. directory.
  60. ``BINARY_DIR <dir>``
  61. Specify the build directory location. This option is ignored if
  62. ``BUILD_IN_SOURCE`` is enabled.
  63. ``INSTALL_DIR <dir>``
  64. Installation prefix to be placed in the ``<INSTALL_DIR>`` placeholder.
  65. This does not actually configure the external project to install to
  66. the given prefix. That must be done by passing appropriate arguments
  67. to the external project configuration step, e.g. using ``<INSTALL_DIR>``.
  68. If any of the above ``..._DIR`` options are not specified, their defaults
  69. are computed as follows. If the ``PREFIX`` option is given or the
  70. ``EP_PREFIX`` directory property is set, then an external project is built
  71. and installed under the specified prefix::
  72. TMP_DIR = <prefix>/tmp
  73. STAMP_DIR = <prefix>/src/<name>-stamp
  74. DOWNLOAD_DIR = <prefix>/src
  75. SOURCE_DIR = <prefix>/src/<name>
  76. BINARY_DIR = <prefix>/src/<name>-build
  77. INSTALL_DIR = <prefix>
  78. LOG_DIR = <STAMP_DIR>
  79. Otherwise, if the ``EP_BASE`` directory property is set then components
  80. of an external project are stored under the specified base::
  81. TMP_DIR = <base>/tmp/<name>
  82. STAMP_DIR = <base>/Stamp/<name>
  83. DOWNLOAD_DIR = <base>/Download/<name>
  84. SOURCE_DIR = <base>/Source/<name>
  85. BINARY_DIR = <base>/Build/<name>
  86. INSTALL_DIR = <base>/Install/<name>
  87. LOG_DIR = <STAMP_DIR>
  88. If no ``PREFIX``, ``EP_PREFIX``, or ``EP_BASE`` is specified, then the
  89. default is to set ``PREFIX`` to ``<name>-prefix``. Relative paths are
  90. interpreted with respect to :variable:`CMAKE_CURRENT_BINARY_DIR` at the
  91. point where ``ExternalProject_Add()`` is called.
  92. **Download Step Options:**
  93. A download method can be omitted if the ``SOURCE_DIR`` option is used to
  94. point to an existing non-empty directory. Otherwise, one of the download
  95. methods below must be specified (multiple download methods should not be
  96. given) or a custom ``DOWNLOAD_COMMAND`` provided.
  97. ``DOWNLOAD_COMMAND <cmd>...``
  98. Overrides the command used for the download step
  99. (:manual:`generator expressions <cmake-generator-expressions(7)>` are
  100. supported). If this option is specified, all other download options will
  101. be ignored. Providing an empty string for ``<cmd>`` effectively disables
  102. the download step.
  103. *URL Download*
  104. ``URL <url1> [<url2>...]``
  105. List of paths and/or URL(s) of the external project's source. When more
  106. than one URL is given, they are tried in turn until one succeeds. A URL
  107. may be an ordinary path in the local file system (in which case it
  108. must be the only URL provided) or any downloadable URL supported by the
  109. :command:`file(DOWNLOAD)` command. A local filesystem path may refer to
  110. either an existing directory or to an archive file, whereas a URL is
  111. expected to point to a file which can be treated as an archive. When an
  112. archive is used, it will be unpacked automatically unless the
  113. ``DOWNLOAD_NO_EXTRACT`` option is set to prevent it. The archive type
  114. is determined by inspecting the actual content rather than using logic
  115. based on the file extension.
  116. ``URL_HASH <algo>=<hashValue>``
  117. Hash of the archive file to be downloaded. The argument should be of
  118. the form ``<algo>=<hashValue>`` where ``algo`` can be any of the hashing
  119. algorithms supported by the :command:`file()` command. Specifying this
  120. option is strongly recommended for URL downloads, as it ensures the
  121. integrity of the downloaded content. It is also used as a check for a
  122. previously downloaded file, allowing connection to the remote location
  123. to be avoided altogether if the local directory already has a file from
  124. an earlier download that matches the specified hash.
  125. ``URL_MD5 <md5>``
  126. Equivalent to ``URL_HASH MD5=<md5>``.
  127. ``DOWNLOAD_NAME <fname>``
  128. File name to use for the downloaded file. If not given, the end of the
  129. URL is used to determine the file name. This option is rarely needed,
  130. the default name is generally suitable and is not normally used outside
  131. of code internal to the ``ExternalProject`` module.
  132. ``DOWNLOAD_NO_EXTRACT <bool>``
  133. Allows the extraction part of the download step to be disabled by
  134. passing a boolean true value for this option. If this option is not
  135. given, the downloaded contents will be unpacked automatically if
  136. required. If extraction has been disabled, the full path to the
  137. downloaded file is available as ``<DOWNLOADED_FILE>`` in subsequent
  138. steps or as the property ``DOWNLOADED_FILE`` with the
  139. :command:`ExternalProject_Get_Property` command.
  140. ``DOWNLOAD_NO_PROGRESS <bool>``
  141. Can be used to disable logging the download progress. If this option is
  142. not given, download progress messages will be logged.
  143. ``TIMEOUT <seconds>``
  144. Maximum time allowed for file download operations.
  145. ``HTTP_USERNAME <username>``
  146. Username for the download operation if authentication is required.
  147. ``HTTP_PASSWORD <password>``
  148. Password for the download operation if authentication is required.
  149. ``HTTP_HEADER <header1> [<header2>...]``
  150. Provides an arbitrary list of HTTP headers for the download operation.
  151. This can be useful for accessing content in systems like AWS, etc.
  152. ``TLS_VERIFY <bool>``
  153. Specifies whether certificate verification should be performed for
  154. https URLs. If this option is not provided, the default behavior is
  155. determined by the ``CMAKE_TLS_VERIFY`` variable (see
  156. :command:`file(DOWNLOAD)`). If that is also not set, certificate
  157. verification will not be performed. In situations where ``URL_HASH``
  158. cannot be provided, this option can be an alternative verification
  159. measure.
  160. ``TLS_CAINFO <file>``
  161. Specify a custom certificate authority file to use if ``TLS_VERIFY``
  162. is enabled. If this option is not specified, the value of the
  163. ``CMAKE_TLS_CAINFO`` variable will be used instead (see
  164. :command:`file(DOWNLOAD)`)
  165. ``NETRC <level>``
  166. Specify whether the .netrc file is to be used for operation. If this
  167. option is not specified, the value of the ``CMAKE_NETRC`` variable
  168. will be used instead (see :command:`file(DOWNLOAD)`)
  169. Valid levels are:
  170. ``IGNORED``
  171. The .netrc file is ignored.
  172. This is the default.
  173. ``OPTIONAL``
  174. The .netrc file is optional, and information in the URL is preferred.
  175. The file will be scanned to find which ever information is not specified
  176. in the URL.
  177. ``REQUIRED``
  178. The .netrc file is required, and information in the URL is ignored.
  179. ``NETRC_FILE <file>``
  180. Specify an alternative .netrc file to the one in your home directory
  181. if the ``NETRC`` level is ``OPTIONAL`` or ``REQUIRED``. If this option
  182. is not specified, the value of the ``CMAKE_NETRC_FILE`` variable will
  183. be used instead (see :command:`file(DOWNLOAD)`)
  184. *Git*
  185. NOTE: A git version of 1.6.5 or later is required if this download method
  186. is used.
  187. ``GIT_REPOSITORY <url>``
  188. URL of the git repository. Any URL understood by the ``git`` command
  189. may be used.
  190. ``GIT_TAG <tag>``
  191. Git branch name, tag or commit hash. Note that branch names and tags
  192. should generally be specified as remote names (i.e. ``origin/myBranch``
  193. rather than simply ``myBranch``). This ensures that if the remote end
  194. has its tag moved or branch rebased or history rewritten, the local
  195. clone will still be updated correctly. In general, however, specifying
  196. a commit hash should be preferred for a number of reasons:
  197. - If the local clone already has the commit corresponding to the hash,
  198. no ``git fetch`` needs to be performed to check for changes each time
  199. CMake is re-run. This can result in a significant speed up if many
  200. external projects are being used.
  201. - Using a specific git hash ensures that the main project's own history
  202. is fully traceable to a specific point in the external project's
  203. evolution. If a branch or tag name is used instead, then checking out
  204. a specific commit of the main project doesn't necessarily pin the
  205. whole build to a specific point in the life of the external project.
  206. The lack of such deterministic behavior makes the main project lose
  207. traceability and repeatability.
  208. If ``GIT_SHALLOW`` is enabled then ``GIT_TAG`` works only with
  209. branch names and tags. A commit hash is not allowed.
  210. ``GIT_REMOTE_NAME <name>``
  211. The optional name of the remote. If this option is not specified, it
  212. defaults to ``origin``.
  213. ``GIT_SUBMODULES <module>...``
  214. Specific git submodules that should also be updated. If this option is
  215. not provided, all git submodules will be updated.
  216. ``GIT_SHALLOW <bool>``
  217. When this option is enabled, the ``git clone`` operation will be given
  218. the ``--depth 1`` option. This performs a shallow clone, which avoids
  219. downloading the whole history and instead retrieves just the commit
  220. denoted by the ``GIT_TAG`` option.
  221. ``GIT_PROGRESS <bool>``
  222. When enabled, this option instructs the ``git clone`` operation to
  223. report its progress by passing it the ``--progress`` option. Without
  224. this option, the clone step for large projects may appear to make the
  225. build stall, since nothing will be logged until the clone operation
  226. finishes. While this option can be used to provide progress to prevent
  227. the appearance of the build having stalled, it may also make the build
  228. overly noisy if lots of external projects are used.
  229. ``GIT_CONFIG <option1> [<option2>...]``
  230. Specify a list of config options to pass to ``git clone``. Each option
  231. listed will be transformed into its own ``--config <option>`` on the
  232. ``git clone`` command line, with each option required to be in the
  233. form ``key=value``.
  234. *Subversion*
  235. ``SVN_REPOSITORY <url>``
  236. URL of the Subversion repository.
  237. ``SVN_REVISION -r<rev>``
  238. Revision to checkout from the Subversion repository.
  239. ``SVN_USERNAME <username>``
  240. Username for the Subversion checkout and update.
  241. ``SVN_PASSWORD <password>``
  242. Password for the Subversion checkout and update.
  243. ``SVN_TRUST_CERT <bool>``
  244. Specifies whether to trust the Subversion server site certificate. If
  245. enabled, the ``--trust-server-cert`` option is passed to the ``svn``
  246. checkout and update commands.
  247. *Mercurial*
  248. ``HG_REPOSITORY <url>``
  249. URL of the mercurial repository.
  250. ``HG_TAG <tag>``
  251. Mercurial branch name, tag or commit id.
  252. *CVS*
  253. ``CVS_REPOSITORY <cvsroot>``
  254. CVSROOT of the CVS repository.
  255. ``CVS_MODULE <mod>``
  256. Module to checkout from the CVS repository.
  257. ``CVS_TAG <tag>``
  258. Tag to checkout from the CVS repository.
  259. **Update/Patch Step Options:**
  260. Whenever CMake is re-run, by default the external project's sources will be
  261. updated if the download method supports updates (e.g. a git repository
  262. would be checked if the ``GIT_TAG`` does not refer to a specific commit).
  263. ``UPDATE_COMMAND <cmd>...``
  264. Overrides the download method's update step with a custom command.
  265. The command may use
  266. :manual:`generator expressions <cmake-generator-expressions(7)>`.
  267. ``UPDATE_DISCONNECTED <bool>``
  268. When enabled, this option causes the update step to be skipped. It does
  269. not, however, prevent the download step. The update step can still be
  270. added as a step target (see :command:`ExternalProject_Add_StepTargets`)
  271. and called manually. This is useful if you want to allow developers to
  272. build the project when disconnected from the network (the network may
  273. still be needed for the download step though).
  274. When this option is present, it is generally advisable to make the value
  275. a cache variable under the developer's control rather than hard-coding
  276. it. If this option is not present, the default value is taken from the
  277. ``EP_UPDATE_DISCONNECTED`` directory property. If that is also not
  278. defined, updates are performed as normal. The ``EP_UPDATE_DISCONNECTED``
  279. directory property is intended as a convenience for controlling the
  280. ``UPDATE_DISCONNECTED`` behavior for an entire section of a project's
  281. directory hierarchy and may be a more convenient method of giving
  282. developers control over whether or not to perform updates (assuming the
  283. project also provides a cache variable or some other convenient method
  284. for setting the directory property).
  285. ``PATCH_COMMAND <cmd>...``
  286. Specifies a custom command to patch the sources after an update. By
  287. default, no patch command is defined. Note that it can be quite difficult
  288. to define an appropriate patch command that performs robustly, especially
  289. for download methods such as git where changing the ``GIT_TAG`` will not
  290. discard changes from a previous patch, but the patch command will be
  291. called again after updating to the new tag.
  292. **Configure Step Options:**
  293. The configure step is run after the download and update steps. By default,
  294. the external project is assumed to be a CMake project, but this can be
  295. overridden if required.
  296. ``CONFIGURE_COMMAND <cmd>...``
  297. The default configure command runs CMake with options based on the main
  298. project. For non-CMake external projects, the ``CONFIGURE_COMMAND``
  299. option must be used to override this behavior
  300. (:manual:`generator expressions <cmake-generator-expressions(7)>` are
  301. supported). For projects that require no configure step, specify this
  302. option with an empty string as the command to execute.
  303. ``CMAKE_COMMAND /.../cmake``
  304. Specify an alternative cmake executable for the configure step (use an
  305. absolute path). This is generally not recommended, since it is
  306. usually desirable to use the same CMake version throughout the whole
  307. build. This option is ignored if a custom configure command has been
  308. specified with ``CONFIGURE_COMMAND``.
  309. ``CMAKE_GENERATOR <gen>``
  310. Override the CMake generator used for the configure step. Without this
  311. option, the same generator as the main build will be used. This option is
  312. ignored if a custom configure command has been specified with the
  313. ``CONFIGURE_COMMAND`` option.
  314. ``CMAKE_GENERATOR_PLATFORM <platform>``
  315. Pass a generator-specific platform name to the CMake command (see
  316. :variable:`CMAKE_GENERATOR_PLATFORM`). It is an error to provide this
  317. option without the ``CMAKE_GENERATOR`` option.
  318. ``CMAKE_GENERATOR_TOOLSET <toolset>``
  319. Pass a generator-specific toolset name to the CMake command (see
  320. :variable:`CMAKE_GENERATOR_TOOLSET`). It is an error to provide this
  321. option without the ``CMAKE_GENERATOR`` option.
  322. ``CMAKE_GENERATOR_INSTANCE <instance>``
  323. Pass a generator-specific instance selection to the CMake command (see
  324. :variable:`CMAKE_GENERATOR_INSTANCE`). It is an error to provide this
  325. option without the ``CMAKE_GENERATOR`` option.
  326. ``CMAKE_ARGS <arg>...``
  327. The specified arguments are passed to the ``cmake`` command line. They
  328. can be any argument the ``cmake`` command understands, not just cache
  329. values defined by ``-D...`` arguments (see also
  330. :manual:`CMake Options <cmake(1)>`). In addition, arguments may use
  331. :manual:`generator expressions <cmake-generator-expressions(7)>`.
  332. ``CMAKE_CACHE_ARGS <arg>...``
  333. This is an alternate way of specifying cache variables where command line
  334. length issues may become a problem. The arguments are expected to be in
  335. the form ``-Dvar:STRING=value``, which are then transformed into
  336. CMake :command:`set` commands with the ``FORCE`` option used. These
  337. ``set()`` commands are written to a pre-load script which is then applied
  338. using the :manual:`cmake -C <cmake(1)>` command line option. Arguments
  339. may use :manual:`generator expressions <cmake-generator-expressions(7)>`.
  340. ``CMAKE_CACHE_DEFAULT_ARGS <arg>...``
  341. This is the same as the ``CMAKE_CACHE_ARGS`` option except the ``set()``
  342. commands do not include the ``FORCE`` keyword. This means the values act
  343. as initial defaults only and will not override any variables already set
  344. from a previous run. Use this option with care, as it can lead to
  345. different behavior depending on whether the build starts from a fresh
  346. build directory or re-uses previous build contents.
  347. ``SOURCE_SUBDIR <dir>``
  348. When no ``CONFIGURE_COMMAND`` option is specified, the configure step
  349. assumes the external project has a ``CMakeLists.txt`` file at the top of
  350. its source tree (i.e. in ``SOURCE_DIR``). The ``SOURCE_SUBDIR`` option
  351. can be used to point to an alternative directory within the source tree
  352. to use as the top of the CMake source tree instead. This must be a
  353. relative path and it will be interpreted as being relative to
  354. ``SOURCE_DIR``. When ``BUILD_IN_SOURCE 1`` is specified, the
  355. ``BUILD_COMMAND`` is used to point to an alternative directory within the
  356. source tree.
  357. **Build Step Options:**
  358. If the configure step assumed the external project uses CMake as its build
  359. system, the build step will also. Otherwise, the build step will assume a
  360. Makefile-based build and simply run ``make`` with no arguments as the
  361. default build step. This can be overridden with custom build commands if
  362. required.
  363. ``BUILD_COMMAND <cmd>...``
  364. Overrides the default build command
  365. (:manual:`generator expressions <cmake-generator-expressions(7)>` are
  366. supported). If this option is not given, the default build command will
  367. be chosen to integrate with the main build in the most appropriate way
  368. (e.g. using recursive ``make`` for Makefile generators or
  369. ``cmake --build`` if the project uses a CMake build). This option can be
  370. specified with an empty string as the command to make the build step do
  371. nothing.
  372. ``BUILD_IN_SOURCE <bool>``
  373. When this option is enabled, the build will be done directly within the
  374. external project's source tree. This should generally be avoided, the use
  375. of a separate build directory is usually preferred, but it can be useful
  376. when the external project assumes an in-source build. The ``BINARY_DIR``
  377. option should not be specified if building in-source.
  378. ``BUILD_ALWAYS <bool>``
  379. Enabling this option forces the build step to always be run. This can be
  380. the easiest way to robustly ensure that the external project's own build
  381. dependencies are evaluated rather than relying on the default
  382. success timestamp-based method. This option is not normally needed unless
  383. developers are expected to modify something the external project's build
  384. depends on in a way that is not detectable via the step target
  385. dependencies (e.g. ``SOURCE_DIR`` is used without a download method and
  386. developers might modify the sources in ``SOURCE_DIR``).
  387. ``BUILD_BYPRODUCTS <file>...``
  388. Specifies files that will be generated by the build command but which
  389. might or might not have their modification time updated by subsequent
  390. builds. These ultimately get passed through as ``BYPRODUCTS`` to the
  391. build step's own underlying call to :command:`add_custom_command`.
  392. **Install Step Options:**
  393. If the configure step assumed the external project uses CMake as its build
  394. system, the install step will also. Otherwise, the install step will assume
  395. a Makefile-based build and simply run ``make install`` as the default build
  396. step. This can be overridden with custom install commands if required.
  397. ``INSTALL_COMMAND <cmd>...``
  398. The external project's own install step is invoked as part of the main
  399. project's *build*. It is done after the external project's build step
  400. and may be before or after the external project's test step (see the
  401. ``TEST_BEFORE_INSTALL`` option below). The external project's install
  402. rules are not part of the main project's install rules, so if anything
  403. from the external project should be installed as part of the main build,
  404. these need to be specified in the main build as additional
  405. :command:`install` commands. The default install step builds the
  406. ``install`` target of the external project, but this can be overridden
  407. with a custom command using this option
  408. (:manual:`generator expressions <cmake-generator-expressions(7)>` are
  409. supported). Passing an empty string as the ``<cmd>`` makes the install
  410. step do nothing.
  411. **Test Step Options:**
  412. The test step is only defined if at least one of the following ``TEST_...``
  413. options are provided.
  414. ``TEST_COMMAND <cmd>...``
  415. Overrides the default test command
  416. (:manual:`generator expressions <cmake-generator-expressions(7)>` are
  417. supported). If this option is not given, the default behavior of the test
  418. step is to build the external project's own ``test`` target. This option
  419. can be specified with ``<cmd>`` as an empty string, which allows the test
  420. step to still be defined, but it will do nothing. Do not specify any of
  421. the other ``TEST_...`` options if providing an empty string as the test
  422. command, but prefer to omit all ``TEST_...`` options altogether if the
  423. test step target is not needed.
  424. ``TEST_BEFORE_INSTALL <bool>``
  425. When this option is enabled, the test step will be executed before the
  426. install step. The default behavior is for the test step to run after the
  427. install step.
  428. ``TEST_AFTER_INSTALL <bool>``
  429. This option is mainly useful as a way to indicate that the test step is
  430. desired but all default behavior is sufficient. Specifying this option
  431. with a boolean true value ensures the test step is defined and that it
  432. comes after the install step. If both ``TEST_BEFORE_INSTALL`` and
  433. ``TEST_AFTER_INSTALL`` are enabled, the latter is silently ignored.
  434. ``TEST_EXCLUDE_FROM_MAIN <bool>``
  435. If enabled, the main build's default ALL target will not depend on the
  436. test step. This can be a useful way of ensuring the test step is defined
  437. but only gets invoked when manually requested.
  438. **Output Logging Options:**
  439. Each of the following ``LOG_...`` options can be used to wrap the relevant
  440. step in a script to capture its output to files. The log files will be
  441. created in ``LOG_DIR`` if supplied or otherwise the ``STAMP_DIR``
  442. directory with step-specific file names.
  443. ``LOG_DOWNLOAD <bool>``
  444. When enabled, the output of the download step is logged to files.
  445. ``LOG_UPDATE <bool>``
  446. When enabled, the output of the update step is logged to files.
  447. ``LOG_PATCH <bool>``
  448. When enabled, the output of the patch step is logged to files.
  449. ``LOG_CONFIGURE <bool>``
  450. When enabled, the output of the configure step is logged to files.
  451. ``LOG_BUILD <bool>``
  452. When enabled, the output of the build step is logged to files.
  453. ``LOG_INSTALL <bool>``
  454. When enabled, the output of the install step is logged to files.
  455. ``LOG_TEST <bool>``
  456. When enabled, the output of the test step is logged to files.
  457. ``LOG_MERGED_STDOUTERR <bool>``
  458. When enabled, stdout and stderr will be merged for any step whose
  459. output is being logged to files.
  460. ``LOG_OUTPUT_ON_FAILURE <bool>``
  461. This option only has an effect if at least one of the other ``LOG_<step>``
  462. options is enabled. If an error occurs for a step which has logging to
  463. file enabled, that step's output will be printed to the console if
  464. ``LOG_OUTPUT_ON_FAILURE`` is set to true. For cases where a large amount
  465. of output is recorded, just the end of that output may be printed to the
  466. console.
  467. **Terminal Access Options:**
  468. Steps can be given direct access to the terminal in some cases. Giving a
  469. step access to the terminal may allow it to receive terminal input if
  470. required, such as for authentication details not provided by other options.
  471. With the :generator:`Ninja` generator, these options place the steps in the
  472. ``console`` :prop_gbl:`job pool <JOB_POOLS>`. Each step can be given access
  473. to the terminal individually via the following options:
  474. ``USES_TERMINAL_DOWNLOAD <bool>``
  475. Give the download step access to the terminal.
  476. ``USES_TERMINAL_UPDATE <bool>``
  477. Give the update step access to the terminal.
  478. ``USES_TERMINAL_CONFIGURE <bool>``
  479. Give the configure step access to the terminal.
  480. ``USES_TERMINAL_BUILD <bool>``
  481. Give the build step access to the terminal.
  482. ``USES_TERMINAL_INSTALL <bool>``
  483. Give the install step access to the terminal.
  484. ``USES_TERMINAL_TEST <bool>``
  485. Give the test step access to the terminal.
  486. **Target Options:**
  487. ``DEPENDS <targets>...``
  488. Specify other targets on which the external project depends. The other
  489. targets will be brought up to date before any of the external project's
  490. steps are executed. Because the external project uses additional custom
  491. targets internally for each step, the ``DEPENDS`` option is the most
  492. convenient way to ensure all of those steps depend on the other targets.
  493. Simply doing
  494. :command:`add_dependencies(\<name\> \<targets\>) <add_dependencies>` will
  495. not make any of the steps dependent on ``<targets>``.
  496. ``EXCLUDE_FROM_ALL <bool>``
  497. When enabled, this option excludes the external project from the default
  498. ALL target of the main build.
  499. ``STEP_TARGETS <step-target>...``
  500. Generate custom targets for the specified steps. This is required if the
  501. steps need to be triggered manually or if they need to be used as
  502. dependencies of other targets. If this option is not specified, the
  503. default value is taken from the ``EP_STEP_TARGETS`` directory property.
  504. See :command:`ExternalProject_Add_Step` below for further discussion of
  505. the effects of this option.
  506. ``INDEPENDENT_STEP_TARGETS <step-target>...``
  507. Generate custom targets for the specified steps and prevent these targets
  508. from having the usual dependencies applied to them. If this option is not
  509. specified, the default value is taken from the
  510. ``EP_INDEPENDENT_STEP_TARGETS`` directory property. This option is mostly
  511. useful for allowing individual steps to be driven independently, such as
  512. for a CDash setup where each step should be initiated and reported
  513. individually rather than as one whole build. See
  514. :command:`ExternalProject_Add_Step` below for further discussion of the
  515. effects of this option.
  516. **Miscellaneous Options:**
  517. ``LIST_SEPARATOR <sep>``
  518. For any of the various ``..._COMMAND`` options, replace ``;`` with
  519. ``<sep>`` in the specified command lines. This can be useful where list
  520. variables may be given in commands where they should end up as
  521. space-separated arguments (``<sep>`` would be a single space character
  522. string in this case).
  523. ``COMMAND <cmd>...``
  524. Any of the other ``..._COMMAND`` options can have additional commands
  525. appended to them by following them with as many ``COMMAND ...`` options
  526. as needed
  527. (:manual:`generator expressions <cmake-generator-expressions(7)>` are
  528. supported). For example:
  529. .. code-block:: cmake
  530. ExternalProject_Add(example
  531. ... # Download options, etc.
  532. BUILD_COMMAND ${CMAKE_COMMAND} -E echo "Starting $<CONFIG> build"
  533. COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --config $<CONFIG>
  534. COMMAND ${CMAKE_COMMAND} -E echo "$<CONFIG> build complete"
  535. )
  536. It should also be noted that each build step is created via a call to
  537. :command:`ExternalProject_Add_Step`. See that command's documentation for the
  538. automatic substitutions that are supported for some options.
  539. Obtaining Project Properties
  540. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  541. .. command:: ExternalProject_Get_Property
  542. The ``ExternalProject_Get_Property()`` function retrieves external project
  543. target properties:
  544. .. code-block:: cmake
  545. ExternalProject_Get_Property(<name> <prop1> [<prop2>...])
  546. The function stores property values in variables of the same name. Property
  547. names correspond to the keyword argument names of ``ExternalProject_Add()``.
  548. For example, the source directory might be retrieved like so:
  549. .. code-block:: cmake
  550. ExternalProject_Get_property(myExtProj SOURCE_DIR)
  551. message("Source dir of myExtProj = ${SOURCE_DIR}")
  552. Explicit Step Management
  553. ^^^^^^^^^^^^^^^^^^^^^^^^
  554. The ``ExternalProject_Add()`` function on its own is often sufficient for
  555. incorporating an external project into the main build. Certain scenarios
  556. require additional work to implement desired behavior, such as adding in a
  557. custom step or making steps available as manually triggerable targets. The
  558. ``ExternalProject_Add_Step()``, ``ExternalProject_Add_StepTargets()`` and
  559. ``ExternalProject_Add_StepDependencies`` functions provide the lower level
  560. control needed to implement such step-level capabilities.
  561. .. command:: ExternalProject_Add_Step
  562. The ``ExternalProject_Add_Step()`` function specifies an additional custom
  563. step for an external project defined by an earlier call to
  564. :command:`ExternalProject_Add`:
  565. .. code-block:: cmake
  566. ExternalProject_Add_Step(<name> <step> [<option>...])
  567. ``<name>`` is the same as the name passed to the original call to
  568. :command:`ExternalProject_Add`. The specified ``<step>`` must not be one of
  569. the pre-defined steps (``mkdir``, ``download``, ``update``, ``skip-update``,
  570. ``patch``, ``configure``, ``build``, ``install`` or ``test``). The supported
  571. options are:
  572. ``COMMAND <cmd>...``
  573. The command line to be executed by this custom step
  574. (:manual:`generator expressions <cmake-generator-expressions(7)>` are
  575. supported). This option can be repeated multiple times to specify multiple
  576. commands to be executed in order.
  577. ``COMMENT "<text>..."``
  578. Text to be printed when the custom step executes.
  579. ``DEPENDEES <step>...``
  580. Other steps (custom or pre-defined) on which this step depends.
  581. ``DEPENDERS <step>...``
  582. Other steps (custom or pre-defined) that depend on this new custom step.
  583. ``DEPENDS <file>...``
  584. Files on which this custom step depends.
  585. ``BYPRODUCTS <file>...``
  586. Files that will be generated by this custom step but which might or might
  587. not have their modification time updated by subsequent builds. This list of
  588. files will ultimately be passed through as the ``BYPRODUCTS`` option to the
  589. :command:`add_custom_command` used to implement the custom step internally.
  590. ``ALWAYS <bool>``
  591. When enabled, this option specifies that the custom step should always be
  592. run (i.e. that it is always considered out of date).
  593. ``EXCLUDE_FROM_MAIN <bool>``
  594. When enabled, this option specifies that the external project's main target
  595. does not depend on the custom step.
  596. ``WORKING_DIRECTORY <dir>``
  597. Specifies the working directory to set before running the custom step's
  598. command. If this option is not specified, the directory will be the value
  599. of the :variable:`CMAKE_CURRENT_BINARY_DIR` at the point where
  600. ``ExternalProject_Add_Step()`` was called.
  601. ``LOG <bool>``
  602. If set, this causes the output from the custom step to be captured to files
  603. in the external project's ``LOG_DIR`` if supplied or ``STAMP_DIR``.
  604. ``USES_TERMINAL <bool>``
  605. If enabled, this gives the custom step direct access to the terminal if
  606. possible.
  607. The command line, comment, working directory and byproducts of every
  608. standard and custom step are processed to replace the tokens
  609. ``<SOURCE_DIR>``, ``<SOURCE_SUBDIR>``, ``<BINARY_DIR>``, ``<INSTALL_DIR>``
  610. ``<TMP_DIR>``, ``<DOWNLOAD_DIR>`` and ``<DOWNLOADED_FILE>`` with their
  611. corresponding property values defined in the original call to
  612. :command:`ExternalProject_Add`.
  613. .. command:: ExternalProject_Add_StepTargets
  614. The ``ExternalProject_Add_StepTargets()`` function generates targets for the
  615. steps listed. The name of each created target will be of the form
  616. ``<name>-<step>``:
  617. .. code-block:: cmake
  618. ExternalProject_Add_StepTargets(<name> [NO_DEPENDS] <step1> [<step2>...])
  619. Creating a target for a step allows it to be used as a dependency of another
  620. target or to be triggered manually. Having targets for specific steps also
  621. allows them to be driven independently of each other by specifying targets on
  622. build command lines. For example, you may be submitting to a sub-project
  623. based dashboard where you want to drive the configure portion of the build,
  624. then submit to the dashboard, followed by the build portion, followed
  625. by tests. If you invoke a custom target that depends on a step halfway
  626. through the step dependency chain, then all the previous steps will also run
  627. to ensure everything is up to date.
  628. If the ``NO_DEPENDS`` option is specified, the step target will not depend on
  629. the dependencies of the external project (i.e. on any dependencies of the
  630. ``<name>`` custom target created by :command:`ExternalProject_Add`). This is
  631. usually safe for the ``download``, ``update`` and ``patch`` steps, since they
  632. do not typically require that the dependencies are updated and built. Using
  633. ``NO_DEPENDS`` for any of the other pre-defined steps, however, may break
  634. parallel builds. Only use ``NO_DEPENDS`` where it is certain that the named
  635. steps genuinely do not have dependencies. For custom steps, consider whether
  636. or not the custom commands require the dependencies to be configured, built
  637. and installed.
  638. Internally, :command:`ExternalProject_Add` calls
  639. :command:`ExternalProject_Add_Step` to create each step. If any
  640. ``STEP_TARGETS`` or ``INDEPENDENT_STEP_TARGETS`` were specified, then
  641. ``ExternalProject_Add_StepTargets()`` will also be called after
  642. :command:`ExternalProject_Add_Step`. ``INDEPENDENT_STEP_TARGETS`` have the
  643. ``NO_DEPENDS`` option set, whereas ``STEP_TARGETS`` do not. Other than that,
  644. the two options result in ``ExternalProject_Add_StepTargets()`` being called
  645. in the same way. Even if a step is not mentioned in either of those two
  646. options, ``ExternalProject_Add_StepTargets()`` can still be called later to
  647. manually define a target for the step.
  648. The ``STEP_TARGETS`` and ``INDEPENDENT_STEP_TARGETS`` options for
  649. :command:`ExternalProject_Add` are generally the easiest way to ensure
  650. targets are created for specific steps of interest. For custom steps,
  651. ``ExternalProject_Add_StepTargets()`` must be called explicitly if a target
  652. should also be created for that custom step. An alternative to these two
  653. options is to populate the ``EP_STEP_TARGETS`` and
  654. ``EP_INDEPENDENT_STEP_TARGETS`` directory properties. These act as defaults
  655. for the step target options and can save having to repeatedly specify the
  656. same set of step targets when multiple external projects are being defined.
  657. .. command:: ExternalProject_Add_StepDependencies
  658. The ``ExternalProject_Add_StepDependencies()`` function can be used to add
  659. dependencies to a step. The dependencies added must be targets CMake already
  660. knows about (these can be ordinary executable or library targets, custom
  661. targets or even step targets of another external project):
  662. .. code-block:: cmake
  663. ExternalProject_Add_StepDependencies(<name> <step> <target1> [<target2>...])
  664. This function takes care to set both target and file level dependencies and
  665. will ensure that parallel builds will not break. It should be used instead of
  666. :command:`add_dependencies` whenever adding a dependency for some of the step
  667. targets generated by the ``ExternalProject`` module.
  668. Examples
  669. ^^^^^^^^
  670. The following example shows how to download and build a hypothetical project
  671. called *FooBar* from github:
  672. .. code-block:: cmake
  673. include(ExternalProject)
  674. ExternalProject_Add(foobar
  675. GIT_REPOSITORY [email protected]:FooCo/FooBar.git
  676. GIT_TAG origin/release/1.2.3
  677. )
  678. For the sake of the example, also define a second hypothetical external project
  679. called *SecretSauce*, which is downloaded from a web server. Two URLs are given
  680. to take advantage of a faster internal network if available, with a fallback to
  681. a slower external server. The project is a typical ``Makefile`` project with no
  682. configure step, so some of the default commands are overridden. The build is
  683. only required to build the *sauce* target:
  684. .. code-block:: cmake
  685. find_program(MAKE_EXE NAMES gmake nmake make)
  686. ExternalProject_Add(secretsauce
  687. URL http://intranet.somecompany.com/artifacts/sauce-2.7.tgz
  688. https://www.somecompany.com/downloads/sauce-2.7.zip
  689. URL_HASH MD5=d41d8cd98f00b204e9800998ecf8427e
  690. CONFIGURE_COMMAND ""
  691. BUILD_COMMAND ${MAKE_EXE} sauce
  692. )
  693. Suppose the build step of ``secretsauce`` requires that ``foobar`` must already
  694. be built. This could be enforced like so:
  695. .. code-block:: cmake
  696. ExternalProject_Add_StepDependencies(secretsauce build foobar)
  697. Another alternative would be to create a custom target for ``foobar``'s build
  698. step and make ``secretsauce`` depend on that rather than the whole ``foobar``
  699. project. This would mean ``foobar`` only needs to be built, it doesn't need to
  700. run its install or test steps before ``secretsauce`` can be built. The
  701. dependency can also be defined along with the ``secretsauce`` project:
  702. .. code-block:: cmake
  703. ExternalProject_Add_StepTargets(foobar build)
  704. ExternalProject_Add(secretsauce
  705. URL http://intranet.somecompany.com/artifacts/sauce-2.7.tgz
  706. https://www.somecompany.com/downloads/sauce-2.7.zip
  707. URL_HASH MD5=d41d8cd98f00b204e9800998ecf8427e
  708. CONFIGURE_COMMAND ""
  709. BUILD_COMMAND ${MAKE_EXE} sauce
  710. DEPENDS foobar-build
  711. )
  712. Instead of calling :command:`ExternalProject_Add_StepTargets`, the target could
  713. be defined along with the ``foobar`` project itself:
  714. .. code-block:: cmake
  715. ExternalProject_Add(foobar
  716. GIT_REPOSITORY [email protected]:FooCo/FooBar.git
  717. GIT_TAG origin/release/1.2.3
  718. STEP_TARGETS build
  719. )
  720. If many external projects should have the same set of step targets, setting a
  721. directory property may be more convenient. The ``build`` step target could be
  722. created automatically by setting the ``EP_STEP_TARGETS`` directory property
  723. before creating the external projects with :command:`ExternalProject_Add`:
  724. .. code-block:: cmake
  725. set_property(DIRECTORY PROPERTY EP_STEP_TARGETS build)
  726. Lastly, suppose that ``secretsauce`` provides a script called ``makedoc`` which
  727. can be used to generate its own documentation. Further suppose that the script
  728. expects the output directory to be provided as the only parameter and that it
  729. should be run from the ``secretsauce`` source directory. A custom step and a
  730. custom target to trigger the script can be defined like so:
  731. .. code-block:: cmake
  732. ExternalProject_Add_Step(secretsauce docs
  733. COMMAND <SOURCE_DIR>/makedoc <BINARY_DIR>
  734. WORKING_DIRECTORY <SOURCE_DIR>
  735. COMMENT "Building secretsauce docs"
  736. ALWAYS TRUE
  737. EXCLUDE_FROM_MAIN TRUE
  738. )
  739. ExternalProject_Add_StepTargets(secretsauce docs)
  740. The custom step could then be triggered from the main build like so::
  741. cmake --build . --target secretsauce-docs
  742. #]=======================================================================]
  743. cmake_policy(PUSH)
  744. cmake_policy(SET CMP0054 NEW) # if() quoted variables not dereferenced
  745. # Pre-compute a regex to match documented keywords for each command.
  746. math(EXPR _ep_documentation_line_count "${CMAKE_CURRENT_LIST_LINE} - 4")
  747. file(STRINGS "${CMAKE_CURRENT_LIST_FILE}" lines
  748. LIMIT_COUNT ${_ep_documentation_line_count}
  749. REGEX "^\\.\\. command:: [A-Za-z0-9_]+|^ +``[A-Z0-9_]+ [^`]*``$")
  750. foreach(line IN LISTS lines)
  751. if("${line}" MATCHES "^\\.\\. command:: ([A-Za-z0-9_]+)")
  752. if(_ep_func)
  753. string(APPEND _ep_keywords_${_ep_func} ")$")
  754. endif()
  755. set(_ep_func "${CMAKE_MATCH_1}")
  756. #message("function [${_ep_func}]")
  757. set(_ep_keywords_${_ep_func} "^(")
  758. set(_ep_keyword_sep)
  759. elseif("${line}" MATCHES "^ +``([A-Z0-9_]+) [^`]*``$")
  760. set(_ep_key "${CMAKE_MATCH_1}")
  761. # COMMAND should never be included as a keyword,
  762. # for ExternalProject_Add(), as it is treated as a
  763. # special case by argument parsing as an extension
  764. # of a previous ..._COMMAND
  765. if("x${_ep_key}x" STREQUAL "xCOMMANDx" AND
  766. "x${_ep_func}x" STREQUAL "xExternalProject_Addx")
  767. continue()
  768. endif()
  769. #message(" keyword [${_ep_key}]")
  770. string(APPEND _ep_keywords_${_ep_func}
  771. "${_ep_keyword_sep}${_ep_key}")
  772. set(_ep_keyword_sep "|")
  773. endif()
  774. endforeach()
  775. if(_ep_func)
  776. string(APPEND _ep_keywords_${_ep_func} ")$")
  777. endif()
  778. # Save regex matching supported hash algorithm names.
  779. set(_ep_hash_algos "MD5|SHA1|SHA224|SHA256|SHA384|SHA512|SHA3_224|SHA3_256|SHA3_384|SHA3_512")
  780. set(_ep_hash_regex "^(${_ep_hash_algos})=([0-9A-Fa-f]+)$")
  781. set(_ExternalProject_SELF "${CMAKE_CURRENT_LIST_FILE}")
  782. get_filename_component(_ExternalProject_SELF_DIR "${_ExternalProject_SELF}" PATH)
  783. function(_ep_parse_arguments f name ns args)
  784. # Transfer the arguments to this function into target properties for the
  785. # new custom target we just added so that we can set up all the build steps
  786. # correctly based on target properties.
  787. #
  788. # We loop through ARGN and consider the namespace starting with an
  789. # upper-case letter followed by at least two more upper-case letters,
  790. # numbers or underscores to be keywords.
  791. if(NOT DEFINED _ExternalProject_SELF)
  792. message(FATAL_ERROR "error: ExternalProject module must be explicitly included before using ${f} function")
  793. endif()
  794. set(key)
  795. foreach(arg IN LISTS args)
  796. set(is_value 1)
  797. if(arg MATCHES "^[A-Z][A-Z0-9_][A-Z0-9_]+$" AND
  798. NOT (("x${arg}x" STREQUAL "x${key}x") AND ("x${key}x" STREQUAL "xCOMMANDx")) AND
  799. NOT arg MATCHES "^(TRUE|FALSE)$")
  800. if(_ep_keywords_${f} AND arg MATCHES "${_ep_keywords_${f}}")
  801. set(is_value 0)
  802. endif()
  803. endif()
  804. if(is_value)
  805. if(key)
  806. # Value
  807. if(NOT arg STREQUAL "")
  808. set_property(TARGET ${name} APPEND PROPERTY ${ns}${key} "${arg}")
  809. else()
  810. get_property(have_key TARGET ${name} PROPERTY ${ns}${key} SET)
  811. if(have_key)
  812. get_property(value TARGET ${name} PROPERTY ${ns}${key})
  813. set_property(TARGET ${name} PROPERTY ${ns}${key} "${value};${arg}")
  814. else()
  815. set_property(TARGET ${name} PROPERTY ${ns}${key} "${arg}")
  816. endif()
  817. endif()
  818. else()
  819. # Missing Keyword
  820. message(AUTHOR_WARNING "value '${arg}' with no previous keyword in ${f}")
  821. endif()
  822. else()
  823. set(key "${arg}")
  824. endif()
  825. endforeach()
  826. endfunction()
  827. define_property(DIRECTORY PROPERTY "EP_BASE" INHERITED
  828. BRIEF_DOCS "Base directory for External Project storage."
  829. FULL_DOCS
  830. "See documentation of the ExternalProject_Add() function in the "
  831. "ExternalProject module."
  832. )
  833. define_property(DIRECTORY PROPERTY "EP_PREFIX" INHERITED
  834. BRIEF_DOCS "Top prefix for External Project storage."
  835. FULL_DOCS
  836. "See documentation of the ExternalProject_Add() function in the "
  837. "ExternalProject module."
  838. )
  839. define_property(DIRECTORY PROPERTY "EP_STEP_TARGETS" INHERITED
  840. BRIEF_DOCS
  841. "List of ExternalProject steps that automatically get corresponding targets"
  842. FULL_DOCS
  843. "These targets will be dependent on the main target dependencies. "
  844. "See documentation of the ExternalProject_Add_StepTargets() function in the "
  845. "ExternalProject module."
  846. )
  847. define_property(DIRECTORY PROPERTY "EP_INDEPENDENT_STEP_TARGETS" INHERITED
  848. BRIEF_DOCS
  849. "List of ExternalProject steps that automatically get corresponding targets"
  850. FULL_DOCS
  851. "These targets will not be dependent on the main target dependencies. "
  852. "See documentation of the ExternalProject_Add_StepTargets() function in the "
  853. "ExternalProject module."
  854. )
  855. define_property(DIRECTORY PROPERTY "EP_UPDATE_DISCONNECTED" INHERITED
  856. BRIEF_DOCS "Never update automatically from the remote repo."
  857. FULL_DOCS
  858. "See documentation of the ExternalProject_Add() function in the "
  859. "ExternalProject module."
  860. )
  861. function(_ep_write_gitclone_script script_filename source_dir git_EXECUTABLE git_repository git_tag git_remote_name git_submodules git_shallow git_progress git_config src_name work_dir gitclone_infofile gitclone_stampfile tls_verify)
  862. if(NOT GIT_VERSION_STRING VERSION_LESS 1.8.5)
  863. # Use `git checkout <tree-ish> --` to avoid ambiguity with a local path.
  864. set(git_checkout_explicit-- "--")
  865. else()
  866. # Use `git checkout <branch>` even though this risks ambiguity with a
  867. # local path. Unfortunately we cannot use `git checkout <tree-ish> --`
  868. # because that will not search for remote branch names, a common use case.
  869. set(git_checkout_explicit-- "")
  870. endif()
  871. if("${git_tag}" STREQUAL "")
  872. message(FATAL_ERROR "Tag for git checkout should not be empty.")
  873. endif()
  874. set(git_clone_options)
  875. if(git_shallow)
  876. if(NOT GIT_VERSION_STRING VERSION_LESS 1.7.10)
  877. list(APPEND git_clone_options "--depth 1 --no-single-branch")
  878. else()
  879. list(APPEND git_clone_options "--depth 1")
  880. endif()
  881. endif()
  882. if(git_progress)
  883. list(APPEND git_clone_options --progress)
  884. endif()
  885. foreach(config IN LISTS git_config)
  886. list(APPEND git_clone_options --config ${config})
  887. endforeach()
  888. if(NOT ${git_remote_name} STREQUAL "origin")
  889. list(APPEND git_clone_options --origin \"${git_remote_name}\")
  890. endif()
  891. string (REPLACE ";" " " git_clone_options "${git_clone_options}")
  892. set(git_options)
  893. # disable cert checking if explicitly told not to do it
  894. if(NOT "x${tls_verify}" STREQUAL "x" AND NOT tls_verify)
  895. set(git_options
  896. -c http.sslVerify=false)
  897. endif()
  898. string (REPLACE ";" " " git_options "${git_options}")
  899. file(WRITE ${script_filename}
  900. "
  901. if(NOT \"${gitclone_infofile}\" IS_NEWER_THAN \"${gitclone_stampfile}\")
  902. message(STATUS \"Avoiding repeated git clone, stamp file is up to date: '${gitclone_stampfile}'\")
  903. return()
  904. endif()
  905. execute_process(
  906. COMMAND \${CMAKE_COMMAND} -E remove_directory \"${source_dir}\"
  907. RESULT_VARIABLE error_code
  908. )
  909. if(error_code)
  910. message(FATAL_ERROR \"Failed to remove directory: '${source_dir}'\")
  911. endif()
  912. # try the clone 3 times in case there is an odd git clone issue
  913. set(error_code 1)
  914. set(number_of_tries 0)
  915. while(error_code AND number_of_tries LESS 3)
  916. execute_process(
  917. COMMAND \"${git_EXECUTABLE}\" ${git_options} clone ${git_clone_options} \"${git_repository}\" \"${src_name}\"
  918. WORKING_DIRECTORY \"${work_dir}\"
  919. RESULT_VARIABLE error_code
  920. )
  921. math(EXPR number_of_tries \"\${number_of_tries} + 1\")
  922. endwhile()
  923. if(number_of_tries GREATER 1)
  924. message(STATUS \"Had to git clone more than once:
  925. \${number_of_tries} times.\")
  926. endif()
  927. if(error_code)
  928. message(FATAL_ERROR \"Failed to clone repository: '${git_repository}'\")
  929. endif()
  930. execute_process(
  931. COMMAND \"${git_EXECUTABLE}\" ${git_options} checkout ${git_tag} ${git_checkout_explicit--}
  932. WORKING_DIRECTORY \"${work_dir}/${src_name}\"
  933. RESULT_VARIABLE error_code
  934. )
  935. if(error_code)
  936. message(FATAL_ERROR \"Failed to checkout tag: '${git_tag}'\")
  937. endif()
  938. execute_process(
  939. COMMAND \"${git_EXECUTABLE}\" ${git_options} submodule update --recursive --init ${git_submodules}
  940. WORKING_DIRECTORY \"${work_dir}/${src_name}\"
  941. RESULT_VARIABLE error_code
  942. )
  943. if(error_code)
  944. message(FATAL_ERROR \"Failed to update submodules in: '${work_dir}/${src_name}'\")
  945. endif()
  946. # Complete success, update the script-last-run stamp file:
  947. #
  948. execute_process(
  949. COMMAND \${CMAKE_COMMAND} -E copy
  950. \"${gitclone_infofile}\"
  951. \"${gitclone_stampfile}\"
  952. RESULT_VARIABLE error_code
  953. )
  954. if(error_code)
  955. message(FATAL_ERROR \"Failed to copy script-last-run stamp file: '${gitclone_stampfile}'\")
  956. endif()
  957. "
  958. )
  959. endfunction()
  960. function(_ep_write_hgclone_script script_filename source_dir hg_EXECUTABLE hg_repository hg_tag src_name work_dir hgclone_infofile hgclone_stampfile)
  961. if("${hg_tag}" STREQUAL "")
  962. message(FATAL_ERROR "Tag for hg checkout should not be empty.")
  963. endif()
  964. file(WRITE ${script_filename}
  965. "
  966. if(NOT \"${hgclone_infofile}\" IS_NEWER_THAN \"${hgclone_stampfile}\")
  967. message(STATUS \"Avoiding repeated hg clone, stamp file is up to date: '${hgclone_stampfile}'\")
  968. return()
  969. endif()
  970. execute_process(
  971. COMMAND \${CMAKE_COMMAND} -E remove_directory \"${source_dir}\"
  972. RESULT_VARIABLE error_code
  973. )
  974. if(error_code)
  975. message(FATAL_ERROR \"Failed to remove directory: '${source_dir}'\")
  976. endif()
  977. execute_process(
  978. COMMAND \"${hg_EXECUTABLE}\" clone -U \"${hg_repository}\" \"${src_name}\"
  979. WORKING_DIRECTORY \"${work_dir}\"
  980. RESULT_VARIABLE error_code
  981. )
  982. if(error_code)
  983. message(FATAL_ERROR \"Failed to clone repository: '${hg_repository}'\")
  984. endif()
  985. execute_process(
  986. COMMAND \"${hg_EXECUTABLE}\" update ${hg_tag}
  987. WORKING_DIRECTORY \"${work_dir}/${src_name}\"
  988. RESULT_VARIABLE error_code
  989. )
  990. if(error_code)
  991. message(FATAL_ERROR \"Failed to checkout tag: '${hg_tag}'\")
  992. endif()
  993. # Complete success, update the script-last-run stamp file:
  994. #
  995. execute_process(
  996. COMMAND \${CMAKE_COMMAND} -E copy
  997. \"${hgclone_infofile}\"
  998. \"${hgclone_stampfile}\"
  999. RESULT_VARIABLE error_code
  1000. )
  1001. if(error_code)
  1002. message(FATAL_ERROR \"Failed to copy script-last-run stamp file: '${hgclone_stampfile}'\")
  1003. endif()
  1004. "
  1005. )
  1006. endfunction()
  1007. function(_ep_write_gitupdate_script script_filename git_EXECUTABLE git_tag git_remote_name git_submodules git_repository work_dir)
  1008. if("${git_tag}" STREQUAL "")
  1009. message(FATAL_ERROR "Tag for git checkout should not be empty.")
  1010. endif()
  1011. if(NOT GIT_VERSION_STRING VERSION_LESS 1.7.6)
  1012. set(git_stash_save_options --all --quiet)
  1013. else()
  1014. set(git_stash_save_options --quiet)
  1015. endif()
  1016. file(WRITE ${script_filename}
  1017. "
  1018. execute_process(
  1019. COMMAND \"${git_EXECUTABLE}\" rev-list --max-count=1 HEAD
  1020. WORKING_DIRECTORY \"${work_dir}\"
  1021. RESULT_VARIABLE error_code
  1022. OUTPUT_VARIABLE head_sha
  1023. OUTPUT_STRIP_TRAILING_WHITESPACE
  1024. )
  1025. if(error_code)
  1026. message(FATAL_ERROR \"Failed to get the hash for HEAD\")
  1027. endif()
  1028. execute_process(
  1029. COMMAND \"${git_EXECUTABLE}\" show-ref ${git_tag}
  1030. WORKING_DIRECTORY \"${work_dir}\"
  1031. OUTPUT_VARIABLE show_ref_output
  1032. )
  1033. # If a remote ref is asked for, which can possibly move around,
  1034. # we must always do a fetch and checkout.
  1035. if(\"\${show_ref_output}\" MATCHES \"remotes\")
  1036. set(is_remote_ref 1)
  1037. else()
  1038. set(is_remote_ref 0)
  1039. endif()
  1040. # Tag is in the form <remote>/<tag> (i.e. origin/master) we must strip
  1041. # the remote from the tag.
  1042. if(\"\${show_ref_output}\" MATCHES \"refs/remotes/${git_tag}\")
  1043. string(REGEX MATCH \"^([^/]+)/(.+)$\" _unused \"${git_tag}\")
  1044. set(git_remote \"\${CMAKE_MATCH_1}\")
  1045. set(git_tag \"\${CMAKE_MATCH_2}\")
  1046. else()
  1047. set(git_remote \"${git_remote_name}\")
  1048. set(git_tag \"${git_tag}\")
  1049. endif()
  1050. # This will fail if the tag does not exist (it probably has not been fetched
  1051. # yet).
  1052. execute_process(
  1053. COMMAND \"${git_EXECUTABLE}\" rev-list --max-count=1 ${git_tag}
  1054. WORKING_DIRECTORY \"${work_dir}\"
  1055. RESULT_VARIABLE error_code
  1056. OUTPUT_VARIABLE tag_sha
  1057. OUTPUT_STRIP_TRAILING_WHITESPACE
  1058. )
  1059. # Is the hash checkout out that we want?
  1060. if(error_code OR is_remote_ref OR NOT (\"\${tag_sha}\" STREQUAL \"\${head_sha}\"))
  1061. execute_process(
  1062. COMMAND \"${git_EXECUTABLE}\" fetch
  1063. WORKING_DIRECTORY \"${work_dir}\"
  1064. RESULT_VARIABLE error_code
  1065. )
  1066. if(error_code)
  1067. message(FATAL_ERROR \"Failed to fetch repository '${git_repository}'\")
  1068. endif()
  1069. if(is_remote_ref)
  1070. # Check if stash is needed
  1071. execute_process(
  1072. COMMAND \"${git_EXECUTABLE}\" status --porcelain
  1073. WORKING_DIRECTORY \"${work_dir}\"
  1074. RESULT_VARIABLE error_code
  1075. OUTPUT_VARIABLE repo_status
  1076. )
  1077. if(error_code)
  1078. message(FATAL_ERROR \"Failed to get the status\")
  1079. endif()
  1080. string(LENGTH \"\${repo_status}\" need_stash)
  1081. # If not in clean state, stash changes in order to be able to be able to
  1082. # perform git pull --rebase
  1083. if(need_stash)
  1084. execute_process(
  1085. COMMAND \"${git_EXECUTABLE}\" stash save ${git_stash_save_options}
  1086. WORKING_DIRECTORY \"${work_dir}\"
  1087. RESULT_VARIABLE error_code
  1088. )
  1089. if(error_code)
  1090. message(FATAL_ERROR \"Failed to stash changes\")
  1091. endif()
  1092. endif()
  1093. # Pull changes from the remote branch
  1094. execute_process(
  1095. COMMAND \"${git_EXECUTABLE}\" rebase \${git_remote}/\${git_tag}
  1096. WORKING_DIRECTORY \"${work_dir}\"
  1097. RESULT_VARIABLE error_code
  1098. )
  1099. if(error_code)
  1100. # Rebase failed: Restore previous state.
  1101. execute_process(
  1102. COMMAND \"${git_EXECUTABLE}\" rebase --abort
  1103. WORKING_DIRECTORY \"${work_dir}\"
  1104. )
  1105. if(need_stash)
  1106. execute_process(
  1107. COMMAND \"${git_EXECUTABLE}\" stash pop --index --quiet
  1108. WORKING_DIRECTORY \"${work_dir}\"
  1109. )
  1110. endif()
  1111. message(FATAL_ERROR \"\\nFailed to rebase in: '${work_dir}/${src_name}'.\\nYou will have to resolve the conflicts manually\")
  1112. endif()
  1113. if(need_stash)
  1114. execute_process(
  1115. COMMAND \"${git_EXECUTABLE}\" stash pop --index --quiet
  1116. WORKING_DIRECTORY \"${work_dir}\"
  1117. RESULT_VARIABLE error_code
  1118. )
  1119. if(error_code)
  1120. # Stash pop --index failed: Try again dropping the index
  1121. execute_process(
  1122. COMMAND \"${git_EXECUTABLE}\" reset --hard --quiet
  1123. WORKING_DIRECTORY \"${work_dir}\"
  1124. RESULT_VARIABLE error_code
  1125. )
  1126. execute_process(
  1127. COMMAND \"${git_EXECUTABLE}\" stash pop --quiet
  1128. WORKING_DIRECTORY \"${work_dir}\"
  1129. RESULT_VARIABLE error_code
  1130. )
  1131. if(error_code)
  1132. # Stash pop failed: Restore previous state.
  1133. execute_process(
  1134. COMMAND \"${git_EXECUTABLE}\" reset --hard --quiet \${head_sha}
  1135. WORKING_DIRECTORY \"${work_dir}\"
  1136. )
  1137. execute_process(
  1138. COMMAND \"${git_EXECUTABLE}\" stash pop --index --quiet
  1139. WORKING_DIRECTORY \"${work_dir}\"
  1140. )
  1141. message(FATAL_ERROR \"\\nFailed to unstash changes in: '${work_dir}/${src_name}'.\\nYou will have to resolve the conflicts manually\")
  1142. endif()
  1143. endif()
  1144. endif()
  1145. else()
  1146. execute_process(
  1147. COMMAND \"${git_EXECUTABLE}\" checkout ${git_tag}
  1148. WORKING_DIRECTORY \"${work_dir}\"
  1149. RESULT_VARIABLE error_code
  1150. )
  1151. if(error_code)
  1152. message(FATAL_ERROR \"Failed to checkout tag: '${git_tag}'\")
  1153. endif()
  1154. endif()
  1155. execute_process(
  1156. COMMAND \"${git_EXECUTABLE}\" submodule update --recursive --init ${git_submodules}
  1157. WORKING_DIRECTORY \"${work_dir}/${src_name}\"
  1158. RESULT_VARIABLE error_code
  1159. )
  1160. if(error_code)
  1161. message(FATAL_ERROR \"Failed to update submodules in: '${work_dir}/${src_name}'\")
  1162. endif()
  1163. endif()
  1164. "
  1165. )
  1166. endfunction(_ep_write_gitupdate_script)
  1167. function(_ep_write_downloadfile_script script_filename REMOTE LOCAL timeout no_progress hash tls_verify tls_cainfo userpwd http_headers netrc netrc_file)
  1168. if(timeout)
  1169. set(TIMEOUT_ARGS TIMEOUT ${timeout})
  1170. set(TIMEOUT_MSG "${timeout} seconds")
  1171. else()
  1172. set(TIMEOUT_ARGS "# no TIMEOUT")
  1173. set(TIMEOUT_MSG "none")
  1174. endif()
  1175. if(no_progress)
  1176. set(SHOW_PROGRESS "")
  1177. else()
  1178. set(SHOW_PROGRESS "SHOW_PROGRESS")
  1179. endif()
  1180. if("${hash}" MATCHES "${_ep_hash_regex}")
  1181. set(ALGO "${CMAKE_MATCH_1}")
  1182. string(TOLOWER "${CMAKE_MATCH_2}" EXPECT_VALUE)
  1183. else()
  1184. set(ALGO "")
  1185. set(EXPECT_VALUE "")
  1186. endif()
  1187. set(TLS_VERIFY_CODE "")
  1188. set(TLS_CAINFO_CODE "")
  1189. set(NETRC_CODE "")
  1190. set(NETRC_FILE_CODE "")
  1191. # check for curl globals in the project
  1192. if(DEFINED CMAKE_TLS_VERIFY)
  1193. set(TLS_VERIFY_CODE "set(CMAKE_TLS_VERIFY ${CMAKE_TLS_VERIFY})")
  1194. endif()
  1195. if(DEFINED CMAKE_TLS_CAINFO)
  1196. set(TLS_CAINFO_CODE "set(CMAKE_TLS_CAINFO \"${CMAKE_TLS_CAINFO}\")")
  1197. endif()
  1198. if(DEFINED CMAKE_NETRC)
  1199. set(NETRC_CODE "set(CMAKE_NETRC \"${CMAKE_NETRC}\")")
  1200. endif()
  1201. if(DEFINED CMAKE_NETRC_FILE)
  1202. set(NETRC_FILE_CODE "set(CMAKE_NETRC_FILE \"${CMAKE_NETRC_FILE}\")")
  1203. endif()
  1204. # now check for curl locals so that the local values
  1205. # will override the globals
  1206. # check for tls_verify argument
  1207. string(LENGTH "${tls_verify}" tls_verify_len)
  1208. if(tls_verify_len GREATER 0)
  1209. set(TLS_VERIFY_CODE "set(CMAKE_TLS_VERIFY ${tls_verify})")
  1210. endif()
  1211. # check for tls_cainfo argument
  1212. string(LENGTH "${tls_cainfo}" tls_cainfo_len)
  1213. if(tls_cainfo_len GREATER 0)
  1214. set(TLS_CAINFO_CODE "set(CMAKE_TLS_CAINFO \"${tls_cainfo}\")")
  1215. endif()
  1216. # check for netrc argument
  1217. string(LENGTH "${netrc}" netrc_len)
  1218. if(netrc_len GREATER 0)
  1219. set(NETRC_CODE "set(CMAKE_NETRC \"${netrc}\")")
  1220. endif()
  1221. # check for netrc_file argument
  1222. string(LENGTH "${netrc_file}" netrc_file_len)
  1223. if(netrc_file_len GREATER 0)
  1224. set(NETRC_FILE_CODE "set(CMAKE_NETRC_FILE \"${netrc_file}\")")
  1225. endif()
  1226. if(userpwd STREQUAL ":")
  1227. set(USERPWD_ARGS)
  1228. else()
  1229. set(USERPWD_ARGS USERPWD "${userpwd}")
  1230. endif()
  1231. set(HTTP_HEADERS_ARGS "")
  1232. if(NOT http_headers STREQUAL "")
  1233. foreach(header ${http_headers})
  1234. set(
  1235. HTTP_HEADERS_ARGS
  1236. "HTTPHEADER \"${header}\"\n ${HTTP_HEADERS_ARGS}"
  1237. )
  1238. endforeach()
  1239. endif()
  1240. # Used variables:
  1241. # * TLS_VERIFY_CODE
  1242. # * TLS_CAINFO_CODE
  1243. # * ALGO
  1244. # * EXPECT_VALUE
  1245. # * REMOTE
  1246. # * LOCAL
  1247. # * SHOW_PROGRESS
  1248. # * TIMEOUT_ARGS
  1249. # * TIMEOUT_MSG
  1250. # * USERPWD_ARGS
  1251. # * HTTP_HEADERS_ARGS
  1252. configure_file(
  1253. "${_ExternalProject_SELF_DIR}/ExternalProject-download.cmake.in"
  1254. "${script_filename}"
  1255. @ONLY
  1256. )
  1257. endfunction()
  1258. function(_ep_write_verifyfile_script script_filename LOCAL hash)
  1259. if("${hash}" MATCHES "${_ep_hash_regex}")
  1260. set(ALGO "${CMAKE_MATCH_1}")
  1261. string(TOLOWER "${CMAKE_MATCH_2}" EXPECT_VALUE)
  1262. else()
  1263. set(ALGO "")
  1264. set(EXPECT_VALUE "")
  1265. endif()
  1266. # Used variables:
  1267. # * ALGO
  1268. # * EXPECT_VALUE
  1269. # * LOCAL
  1270. configure_file(
  1271. "${_ExternalProject_SELF_DIR}/ExternalProject-verify.cmake.in"
  1272. "${script_filename}"
  1273. @ONLY
  1274. )
  1275. endfunction()
  1276. function(_ep_write_extractfile_script script_filename name filename directory)
  1277. set(args "")
  1278. if(filename MATCHES "(\\.|=)(7z|tar\\.bz2|tar\\.gz|tar\\.xz|tbz2|tgz|txz|zip)$")
  1279. set(args xfz)
  1280. endif()
  1281. if(filename MATCHES "(\\.|=)tar$")
  1282. set(args xf)
  1283. endif()
  1284. if(args STREQUAL "")
  1285. message(SEND_ERROR "error: do not know how to extract '${filename}' -- known types are .7z, .tar, .tar.bz2, .tar.gz, .tar.xz, .tbz2, .tgz, .txz and .zip")
  1286. return()
  1287. endif()
  1288. file(WRITE ${script_filename}
  1289. "# Make file names absolute:
  1290. #
  1291. get_filename_component(filename \"${filename}\" ABSOLUTE)
  1292. get_filename_component(directory \"${directory}\" ABSOLUTE)
  1293. message(STATUS \"extracting...
  1294. src='\${filename}'
  1295. dst='\${directory}'\")
  1296. if(NOT EXISTS \"\${filename}\")
  1297. message(FATAL_ERROR \"error: file to extract does not exist: '\${filename}'\")
  1298. endif()
  1299. # Prepare a space for extracting:
  1300. #
  1301. set(i 1234)
  1302. while(EXISTS \"\${directory}/../ex-${name}\${i}\")
  1303. math(EXPR i \"\${i} + 1\")
  1304. endwhile()
  1305. set(ut_dir \"\${directory}/../ex-${name}\${i}\")
  1306. file(MAKE_DIRECTORY \"\${ut_dir}\")
  1307. # Extract it:
  1308. #
  1309. message(STATUS \"extracting... [tar ${args}]\")
  1310. execute_process(COMMAND \${CMAKE_COMMAND} -E tar ${args} \${filename}
  1311. WORKING_DIRECTORY \${ut_dir}
  1312. RESULT_VARIABLE rv)
  1313. if(NOT rv EQUAL 0)
  1314. message(STATUS \"extracting... [error clean up]\")
  1315. file(REMOVE_RECURSE \"\${ut_dir}\")
  1316. message(FATAL_ERROR \"error: extract of '\${filename}' failed\")
  1317. endif()
  1318. # Analyze what came out of the tar file:
  1319. #
  1320. message(STATUS \"extracting... [analysis]\")
  1321. file(GLOB contents \"\${ut_dir}/*\")
  1322. list(REMOVE_ITEM contents \"\${ut_dir}/.DS_Store\")
  1323. list(LENGTH contents n)
  1324. if(NOT n EQUAL 1 OR NOT IS_DIRECTORY \"\${contents}\")
  1325. set(contents \"\${ut_dir}\")
  1326. endif()
  1327. # Move \"the one\" directory to the final directory:
  1328. #
  1329. message(STATUS \"extracting... [rename]\")
  1330. file(REMOVE_RECURSE \${directory})
  1331. get_filename_component(contents \${contents} ABSOLUTE)
  1332. file(RENAME \${contents} \${directory})
  1333. # Clean up:
  1334. #
  1335. message(STATUS \"extracting... [clean up]\")
  1336. file(REMOVE_RECURSE \"\${ut_dir}\")
  1337. message(STATUS \"extracting... done\")
  1338. "
  1339. )
  1340. endfunction()
  1341. function(_ep_set_directories name)
  1342. get_property(prefix TARGET ${name} PROPERTY _EP_PREFIX)
  1343. if(NOT prefix)
  1344. get_property(prefix DIRECTORY PROPERTY EP_PREFIX)
  1345. if(NOT prefix)
  1346. get_property(base DIRECTORY PROPERTY EP_BASE)
  1347. if(NOT base)
  1348. set(prefix "${name}-prefix")
  1349. endif()
  1350. endif()
  1351. endif()
  1352. if(prefix)
  1353. set(tmp_default "${prefix}/tmp")
  1354. set(download_default "${prefix}/src")
  1355. set(source_default "${prefix}/src/${name}")
  1356. set(binary_default "${prefix}/src/${name}-build")
  1357. set(stamp_default "${prefix}/src/${name}-stamp")
  1358. set(install_default "${prefix}")
  1359. else()
  1360. set(tmp_default "${base}/tmp/${name}")
  1361. set(download_default "${base}/Download/${name}")
  1362. set(source_default "${base}/Source/${name}")
  1363. set(binary_default "${base}/Build/${name}")
  1364. set(stamp_default "${base}/Stamp/${name}")
  1365. set(install_default "${base}/Install/${name}")
  1366. endif()
  1367. get_property(build_in_source TARGET ${name} PROPERTY _EP_BUILD_IN_SOURCE)
  1368. if(build_in_source)
  1369. get_property(have_binary_dir TARGET ${name} PROPERTY _EP_BINARY_DIR SET)
  1370. if(have_binary_dir)
  1371. message(FATAL_ERROR
  1372. "External project ${name} has both BINARY_DIR and BUILD_IN_SOURCE!")
  1373. endif()
  1374. endif()
  1375. set(top "${CMAKE_CURRENT_BINARY_DIR}")
  1376. # Apply defaults and convert to absolute paths.
  1377. set(places stamp download source binary install tmp)
  1378. foreach(var ${places})
  1379. string(TOUPPER "${var}" VAR)
  1380. get_property(${var}_dir TARGET ${name} PROPERTY _EP_${VAR}_DIR)
  1381. if(NOT ${var}_dir)
  1382. set(${var}_dir "${${var}_default}")
  1383. endif()
  1384. if(NOT IS_ABSOLUTE "${${var}_dir}")
  1385. get_filename_component(${var}_dir "${top}/${${var}_dir}" ABSOLUTE)
  1386. endif()
  1387. set_property(TARGET ${name} PROPERTY _EP_${VAR}_DIR "${${var}_dir}")
  1388. endforeach()
  1389. # Special case for default log directory based on stamp directory.
  1390. get_property(log_dir TARGET ${name} PROPERTY _EP_LOG_DIR)
  1391. if(NOT log_dir)
  1392. get_property(log_dir TARGET ${name} PROPERTY _EP_STAMP_DIR)
  1393. endif()
  1394. if(NOT IS_ABSOLUTE "${log_dir}")
  1395. get_filename_component(log_dir "${top}/${log_dir}" ABSOLUTE)
  1396. endif()
  1397. set_property(TARGET ${name} PROPERTY _EP_LOG_DIR "${log_dir}")
  1398. get_property(source_subdir TARGET ${name} PROPERTY _EP_SOURCE_SUBDIR)
  1399. if(NOT source_subdir)
  1400. set_property(TARGET ${name} PROPERTY _EP_SOURCE_SUBDIR "")
  1401. elseif(IS_ABSOLUTE "${source_subdir}")
  1402. message(FATAL_ERROR
  1403. "External project ${name} has non-relative SOURCE_SUBDIR!")
  1404. else()
  1405. # Prefix with a slash so that when appended to the source directory, it
  1406. # behaves as expected.
  1407. set_property(TARGET ${name} PROPERTY _EP_SOURCE_SUBDIR "/${source_subdir}")
  1408. endif()
  1409. if(build_in_source)
  1410. get_property(source_dir TARGET ${name} PROPERTY _EP_SOURCE_DIR)
  1411. if(source_subdir)
  1412. set_property(TARGET ${name} PROPERTY _EP_BINARY_DIR "${source_dir}/${source_subdir}")
  1413. else()
  1414. set_property(TARGET ${name} PROPERTY _EP_BINARY_DIR "${source_dir}")
  1415. endif()
  1416. endif()
  1417. # Make the directories at CMake configure time *and* add a custom command
  1418. # to make them at build time. They need to exist at makefile generation
  1419. # time for Borland make and wmake so that CMake may generate makefiles
  1420. # with "cd C:\short\paths\with\no\spaces" commands in them.
  1421. #
  1422. # Additionally, the add_custom_command is still used in case somebody
  1423. # removes one of the necessary directories and tries to rebuild without
  1424. # re-running cmake.
  1425. foreach(var ${places})
  1426. string(TOUPPER "${var}" VAR)
  1427. get_property(dir TARGET ${name} PROPERTY _EP_${VAR}_DIR)
  1428. file(MAKE_DIRECTORY "${dir}")
  1429. if(NOT EXISTS "${dir}")
  1430. message(FATAL_ERROR "dir '${dir}' does not exist after file(MAKE_DIRECTORY)")
  1431. endif()
  1432. endforeach()
  1433. endfunction()
  1434. # IMPORTANT: this MUST be a macro and not a function because of the
  1435. # in-place replacements that occur in each ${var}
  1436. #
  1437. macro(_ep_replace_location_tags target_name)
  1438. set(vars ${ARGN})
  1439. foreach(var ${vars})
  1440. if(${var})
  1441. foreach(dir SOURCE_DIR SOURCE_SUBDIR BINARY_DIR INSTALL_DIR TMP_DIR DOWNLOAD_DIR DOWNLOADED_FILE LOG_DIR)
  1442. get_property(val TARGET ${target_name} PROPERTY _EP_${dir})
  1443. string(REPLACE "<${dir}>" "${val}" ${var} "${${var}}")
  1444. endforeach()
  1445. endif()
  1446. endforeach()
  1447. endmacro()
  1448. function(_ep_command_line_to_initial_cache var args force)
  1449. set(script_initial_cache "")
  1450. set(regex "^([^:]+):([^=]+)=(.*)$")
  1451. set(setArg "")
  1452. set(forceArg "")
  1453. if(force)
  1454. set(forceArg "FORCE")
  1455. endif()
  1456. foreach(line ${args})
  1457. if("${line}" MATCHES "^-D(.*)")
  1458. set(line "${CMAKE_MATCH_1}")
  1459. if(NOT "${setArg}" STREQUAL "")
  1460. # This is required to build up lists in variables, or complete an entry
  1461. string(APPEND setArg "${accumulator}\" CACHE ${type} \"Initial cache\" ${forceArg})")
  1462. string(APPEND script_initial_cache "\n${setArg}")
  1463. set(accumulator "")
  1464. set(setArg "")
  1465. endif()
  1466. if("${line}" MATCHES "${regex}")
  1467. set(name "${CMAKE_MATCH_1}")
  1468. set(type "${CMAKE_MATCH_2}")
  1469. set(value "${CMAKE_MATCH_3}")
  1470. set(setArg "set(${name} \"${value}")
  1471. else()
  1472. message(WARNING "Line '${line}' does not match regex. Ignoring.")
  1473. endif()
  1474. else()
  1475. # Assume this is a list to append to the last var
  1476. string(APPEND accumulator ";${line}")
  1477. endif()
  1478. endforeach()
  1479. # Catch the final line of the args
  1480. if(NOT "${setArg}" STREQUAL "")
  1481. string(APPEND setArg "${accumulator}\" CACHE ${type} \"Initial cache\" ${forceArg})")
  1482. string(APPEND script_initial_cache "\n${setArg}")
  1483. endif()
  1484. set(${var} ${script_initial_cache} PARENT_SCOPE)
  1485. endfunction()
  1486. function(_ep_write_initial_cache target_name script_filename script_initial_cache)
  1487. # Write out values into an initial cache, that will be passed to CMake with -C
  1488. # Replace location tags.
  1489. _ep_replace_location_tags(${target_name} script_initial_cache)
  1490. _ep_replace_location_tags(${target_name} script_filename)
  1491. # Write out the initial cache file to the location specified.
  1492. file(GENERATE OUTPUT "${script_filename}" CONTENT "${script_initial_cache}")
  1493. endfunction()
  1494. function(ExternalProject_Get_Property name)
  1495. foreach(var ${ARGN})
  1496. string(TOUPPER "${var}" VAR)
  1497. get_property(is_set TARGET ${name} PROPERTY _EP_${VAR} SET)
  1498. if(NOT is_set)
  1499. message(FATAL_ERROR "External project \"${name}\" has no ${var}")
  1500. endif()
  1501. get_property(${var} TARGET ${name} PROPERTY _EP_${VAR})
  1502. set(${var} "${${var}}" PARENT_SCOPE)
  1503. endforeach()
  1504. endfunction()
  1505. function(_ep_get_configure_command_id name cfg_cmd_id_var)
  1506. get_target_property(cmd ${name} _EP_CONFIGURE_COMMAND)
  1507. if(cmd STREQUAL "")
  1508. # Explicit empty string means no configure step for this project
  1509. set(${cfg_cmd_id_var} "none" PARENT_SCOPE)
  1510. else()
  1511. if(NOT cmd)
  1512. # Default is "use cmake":
  1513. set(${cfg_cmd_id_var} "cmake" PARENT_SCOPE)
  1514. else()
  1515. # Otherwise we have to analyze the value:
  1516. if(cmd MATCHES "^[^;]*/configure")
  1517. set(${cfg_cmd_id_var} "configure" PARENT_SCOPE)
  1518. elseif(cmd MATCHES "^[^;]*/cmake" AND NOT cmd MATCHES ";-[PE];")
  1519. set(${cfg_cmd_id_var} "cmake" PARENT_SCOPE)
  1520. elseif(cmd MATCHES "config")
  1521. set(${cfg_cmd_id_var} "configure" PARENT_SCOPE)
  1522. else()
  1523. set(${cfg_cmd_id_var} "unknown:${cmd}" PARENT_SCOPE)
  1524. endif()
  1525. endif()
  1526. endif()
  1527. endfunction()
  1528. function(_ep_get_build_command name step cmd_var)
  1529. set(cmd "")
  1530. set(args)
  1531. _ep_get_configure_command_id(${name} cfg_cmd_id)
  1532. if(cfg_cmd_id STREQUAL "cmake")
  1533. # CMake project. Select build command based on generator.
  1534. get_target_property(cmake_generator ${name} _EP_CMAKE_GENERATOR)
  1535. if("${CMAKE_GENERATOR}" MATCHES "Make" AND
  1536. ("${cmake_generator}" MATCHES "Make" OR NOT cmake_generator))
  1537. # The project uses the same Makefile generator. Use recursive make.
  1538. set(cmd "$(MAKE)")
  1539. if(step STREQUAL "INSTALL")
  1540. set(args install)
  1541. endif()
  1542. if("x${step}x" STREQUAL "xTESTx")
  1543. set(args test)
  1544. endif()
  1545. else()
  1546. # Drive the project with "cmake --build".
  1547. get_target_property(cmake_command ${name} _EP_CMAKE_COMMAND)
  1548. if(cmake_command)
  1549. set(cmd "${cmake_command}")
  1550. else()
  1551. set(cmd "${CMAKE_COMMAND}")
  1552. endif()
  1553. set(args --build ".")
  1554. get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
  1555. if(_isMultiConfig)
  1556. if (CMAKE_CFG_INTDIR AND
  1557. NOT CMAKE_CFG_INTDIR STREQUAL "." AND
  1558. NOT CMAKE_CFG_INTDIR MATCHES "\\$")
  1559. # CMake 3.4 and below used the CMAKE_CFG_INTDIR placeholder value
  1560. # provided by multi-configuration generators. Some projects were
  1561. # taking advantage of that undocumented implementation detail to
  1562. # specify a specific configuration here. They should use
  1563. # BUILD_COMMAND to change the default command instead, but for
  1564. # compatibility honor the value.
  1565. set(config ${CMAKE_CFG_INTDIR})
  1566. message(AUTHOR_WARNING "CMAKE_CFG_INTDIR should not be set by project code.\n"
  1567. "To get a non-default build command, use the BUILD_COMMAND option.")
  1568. else()
  1569. set(config $<CONFIG>)
  1570. endif()
  1571. list(APPEND args --config ${config})
  1572. endif()
  1573. if(step STREQUAL "INSTALL")
  1574. list(APPEND args --target install)
  1575. endif()
  1576. # But for "TEST" drive the project with corresponding "ctest".
  1577. if("x${step}x" STREQUAL "xTESTx")
  1578. string(REGEX REPLACE "^(.*/)cmake([^/]*)$" "\\1ctest\\2" cmd "${cmd}")
  1579. set(args "")
  1580. if(_isMultiConfig)
  1581. list(APPEND args -C ${config})
  1582. endif()
  1583. endif()
  1584. endif()
  1585. else()
  1586. # Non-CMake project. Guess "make" and "make install" and "make test".
  1587. if("${CMAKE_GENERATOR}" MATCHES "Makefiles")
  1588. # Try to get the parallel arguments
  1589. set(cmd "$(MAKE)")
  1590. else()
  1591. set(cmd "make")
  1592. endif()
  1593. if(step STREQUAL "INSTALL")
  1594. set(args install)
  1595. endif()
  1596. if("x${step}x" STREQUAL "xTESTx")
  1597. set(args test)
  1598. endif()
  1599. endif()
  1600. # Use user-specified arguments instead of default arguments, if any.
  1601. get_property(have_args TARGET ${name} PROPERTY _EP_${step}_ARGS SET)
  1602. if(have_args)
  1603. get_target_property(args ${name} _EP_${step}_ARGS)
  1604. endif()
  1605. list(APPEND cmd ${args})
  1606. set(${cmd_var} "${cmd}" PARENT_SCOPE)
  1607. endfunction()
  1608. function(_ep_write_log_script name step cmd_var)
  1609. ExternalProject_Get_Property(${name} log_dir)
  1610. ExternalProject_Get_Property(${name} stamp_dir)
  1611. set(command "${${cmd_var}}")
  1612. set(make "")
  1613. set(code_cygpath_make "")
  1614. if(command MATCHES "^\\$\\(MAKE\\)")
  1615. # GNU make recognizes the string "$(MAKE)" as recursive make, so
  1616. # ensure that it appears directly in the makefile.
  1617. string(REGEX REPLACE "^\\$\\(MAKE\\)" "\${make}" command "${command}")
  1618. set(make "-Dmake=$(MAKE)")
  1619. if(WIN32 AND NOT CYGWIN)
  1620. set(code_cygpath_make "
  1621. if(\${make} MATCHES \"^/\")
  1622. execute_process(
  1623. COMMAND cygpath -w \${make}
  1624. OUTPUT_VARIABLE cygpath_make
  1625. ERROR_VARIABLE cygpath_make
  1626. RESULT_VARIABLE cygpath_error
  1627. OUTPUT_STRIP_TRAILING_WHITESPACE
  1628. )
  1629. if(NOT cygpath_error)
  1630. set(make \${cygpath_make})
  1631. endif()
  1632. endif()
  1633. ")
  1634. endif()
  1635. endif()
  1636. set(config "")
  1637. if("${CMAKE_CFG_INTDIR}" MATCHES "^\\$")
  1638. string(REPLACE "${CMAKE_CFG_INTDIR}" "\${config}" command "${command}")
  1639. set(config "-Dconfig=${CMAKE_CFG_INTDIR}")
  1640. endif()
  1641. # Wrap multiple 'COMMAND' lines up into a second-level wrapper
  1642. # script so all output can be sent to one log file.
  1643. if(command MATCHES "(^|;)COMMAND;")
  1644. set(code_execute_process "
  1645. ${code_cygpath_make}
  1646. execute_process(COMMAND \${command} RESULT_VARIABLE result)
  1647. if(result)
  1648. set(msg \"Command failed (\${result}):\\n\")
  1649. foreach(arg IN LISTS command)
  1650. set(msg \"\${msg} '\${arg}'\")
  1651. endforeach()
  1652. message(FATAL_ERROR \"\${msg}\")
  1653. endif()
  1654. ")
  1655. set(code "")
  1656. set(cmd "")
  1657. set(sep "")
  1658. foreach(arg IN LISTS command)
  1659. if("x${arg}" STREQUAL "xCOMMAND")
  1660. if(NOT "x${cmd}" STREQUAL "x")
  1661. string(APPEND code "set(command \"${cmd}\")${code_execute_process}")
  1662. endif()
  1663. set(cmd "")
  1664. set(sep "")
  1665. else()
  1666. string(APPEND cmd "${sep}${arg}")
  1667. set(sep ";")
  1668. endif()
  1669. endforeach()
  1670. string(APPEND code "set(command \"${cmd}\")${code_execute_process}")
  1671. file(GENERATE OUTPUT "${stamp_dir}/${name}-${step}-$<CONFIG>-impl.cmake" CONTENT "${code}")
  1672. set(command ${CMAKE_COMMAND} "-Dmake=\${make}" "-Dconfig=\${config}" -P ${stamp_dir}/${name}-${step}-$<CONFIG>-impl.cmake)
  1673. endif()
  1674. # Wrap the command in a script to log output to files.
  1675. set(script ${stamp_dir}/${name}-${step}-$<CONFIG>.cmake)
  1676. set(logbase ${log_dir}/${name}-${step})
  1677. get_property(log_merged TARGET ${name} PROPERTY _EP_LOG_MERGED_STDOUTERR)
  1678. get_property(log_output_on_failure TARGET ${name} PROPERTY _EP_LOG_OUTPUT_ON_FAILURE)
  1679. if (log_merged)
  1680. set(stdout_log "${logbase}.log")
  1681. set(stderr_log "${logbase}.log")
  1682. else()
  1683. set(stdout_log "${logbase}-out.log")
  1684. set(stderr_log "${logbase}-err.log")
  1685. endif()
  1686. set(code "
  1687. cmake_minimum_required(VERSION 3.13)
  1688. ${code_cygpath_make}
  1689. set(command \"${command}\")
  1690. set(log_merged \"${log_merged}\")
  1691. set(log_output_on_failure \"${log_output_on_failure}\")
  1692. set(stdout_log \"${stdout_log}\")
  1693. set(stderr_log \"${stderr_log}\")
  1694. execute_process(
  1695. COMMAND \${command}
  1696. RESULT_VARIABLE result
  1697. OUTPUT_FILE \"\${stdout_log}\"
  1698. ERROR_FILE \"\${stderr_log}\"
  1699. )
  1700. macro(read_up_to_max_size log_file output_var)
  1701. file(SIZE \${log_file} determined_size)
  1702. set(max_size 10240)
  1703. if (determined_size GREATER max_size)
  1704. math(EXPR seek_position \"\${determined_size} - \${max_size}\")
  1705. file(READ \${log_file} \${output_var} OFFSET \${seek_position})
  1706. set(\${output_var} \"...skipping to end...\\n\${\${output_var}}\")
  1707. else()
  1708. file(READ \${log_file} \${output_var})
  1709. endif()
  1710. endmacro()
  1711. if(result)
  1712. set(msg \"Command failed: \${result}\\n\")
  1713. foreach(arg IN LISTS command)
  1714. set(msg \"\${msg} '\${arg}'\")
  1715. endforeach()
  1716. if (\${log_merged})
  1717. set(msg \"\${msg}\\nSee also\\n \${stderr_log}\")
  1718. else()
  1719. set(msg \"\${msg}\\nSee also\\n ${logbase}-*.log\")
  1720. endif()
  1721. if (\${log_output_on_failure})
  1722. message(SEND_ERROR \"\${msg}\")
  1723. if (\${log_merged})
  1724. read_up_to_max_size(\"\${stderr_log}\" error_log_contents)
  1725. message(STATUS \"Log output is:\\n\${error_log_contents}\")
  1726. else()
  1727. read_up_to_max_size(\"\${stdout_log}\" out_log_contents)
  1728. read_up_to_max_size(\"\${stderr_log}\" err_log_contents)
  1729. message(STATUS \"stdout output is:\\n\${out_log_contents}\")
  1730. message(STATUS \"stderr output is:\\n\${err_log_contents}\")
  1731. endif()
  1732. message(FATAL_ERROR \"Stopping after outputting logs.\")
  1733. else()
  1734. message(FATAL_ERROR \"\${msg}\")
  1735. endif()
  1736. else()
  1737. set(msg \"${name} ${step} command succeeded. See also ${logbase}-*.log\")
  1738. message(STATUS \"\${msg}\")
  1739. endif()
  1740. ")
  1741. file(GENERATE OUTPUT "${script}" CONTENT "${code}")
  1742. set(command ${CMAKE_COMMAND} ${make} ${config} -P ${script})
  1743. set(${cmd_var} "${command}" PARENT_SCOPE)
  1744. endfunction()
  1745. # This module used to use "/${CMAKE_CFG_INTDIR}" directly and produced
  1746. # makefiles with "/./" in paths for custom command dependencies. Which
  1747. # resulted in problems with parallel make -j invocations.
  1748. #
  1749. # This function was added so that the suffix (search below for ${cfgdir}) is
  1750. # only set to "/${CMAKE_CFG_INTDIR}" when ${CMAKE_CFG_INTDIR} is not going to
  1751. # be "." (multi-configuration build systems like Visual Studio and Xcode...)
  1752. #
  1753. function(_ep_get_configuration_subdir_suffix suffix_var)
  1754. set(suffix "")
  1755. get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
  1756. if(_isMultiConfig)
  1757. set(suffix "/${CMAKE_CFG_INTDIR}")
  1758. endif()
  1759. set(${suffix_var} "${suffix}" PARENT_SCOPE)
  1760. endfunction()
  1761. function(_ep_get_step_stampfile name step stampfile_var)
  1762. ExternalProject_Get_Property(${name} stamp_dir)
  1763. _ep_get_configuration_subdir_suffix(cfgdir)
  1764. set(stampfile "${stamp_dir}${cfgdir}/${name}-${step}")
  1765. set(${stampfile_var} "${stampfile}" PARENT_SCOPE)
  1766. endfunction()
  1767. function(_ep_get_complete_stampfile name stampfile_var)
  1768. set(cmf_dir ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles)
  1769. _ep_get_configuration_subdir_suffix(cfgdir)
  1770. set(stampfile "${cmf_dir}${cfgdir}/${name}-complete")
  1771. set(${stampfile_var} ${stampfile} PARENT_SCOPE)
  1772. endfunction()
  1773. function(ExternalProject_Add_StepTargets name)
  1774. set(steps ${ARGN})
  1775. if(ARGC GREATER 1 AND "${ARGV1}" STREQUAL "NO_DEPENDS")
  1776. set(no_deps 1)
  1777. list(REMOVE_AT steps 0)
  1778. endif()
  1779. foreach(step ${steps})
  1780. if(no_deps AND "${step}" MATCHES "^(configure|build|install|test)$")
  1781. message(AUTHOR_WARNING "Using NO_DEPENDS for \"${step}\" step might break parallel builds")
  1782. endif()
  1783. _ep_get_step_stampfile(${name} ${step} stamp_file)
  1784. add_custom_target(${name}-${step}
  1785. DEPENDS ${stamp_file})
  1786. set_property(TARGET ${name}-${step} PROPERTY _EP_IS_EXTERNAL_PROJECT_STEP 1)
  1787. set_property(TARGET ${name}-${step} PROPERTY LABELS ${name})
  1788. set_property(TARGET ${name}-${step} PROPERTY FOLDER "ExternalProjectTargets/${name}")
  1789. # Depend on other external projects (target-level).
  1790. if(NOT no_deps)
  1791. get_property(deps TARGET ${name} PROPERTY _EP_DEPENDS)
  1792. foreach(arg IN LISTS deps)
  1793. add_dependencies(${name}-${step} ${arg})
  1794. endforeach()
  1795. endif()
  1796. endforeach()
  1797. endfunction()
  1798. function(ExternalProject_Add_Step name step)
  1799. _ep_get_complete_stampfile(${name} complete_stamp_file)
  1800. _ep_get_step_stampfile(${name} ${step} stamp_file)
  1801. _ep_parse_arguments(ExternalProject_Add_Step
  1802. ${name} _EP_${step}_ "${ARGN}")
  1803. get_property(exclude_from_main TARGET ${name} PROPERTY _EP_${step}_EXCLUDE_FROM_MAIN)
  1804. if(NOT exclude_from_main)
  1805. add_custom_command(APPEND
  1806. OUTPUT ${complete_stamp_file}
  1807. DEPENDS ${stamp_file}
  1808. )
  1809. endif()
  1810. # Steps depending on this step.
  1811. get_property(dependers TARGET ${name} PROPERTY _EP_${step}_DEPENDERS)
  1812. foreach(depender IN LISTS dependers)
  1813. _ep_get_step_stampfile(${name} ${depender} depender_stamp_file)
  1814. add_custom_command(APPEND
  1815. OUTPUT ${depender_stamp_file}
  1816. DEPENDS ${stamp_file}
  1817. )
  1818. endforeach()
  1819. # Dependencies on files.
  1820. get_property(depends TARGET ${name} PROPERTY _EP_${step}_DEPENDS)
  1821. # Byproducts of the step.
  1822. get_property(byproducts TARGET ${name} PROPERTY _EP_${step}_BYPRODUCTS)
  1823. # Dependencies on steps.
  1824. get_property(dependees TARGET ${name} PROPERTY _EP_${step}_DEPENDEES)
  1825. foreach(dependee IN LISTS dependees)
  1826. _ep_get_step_stampfile(${name} ${dependee} dependee_stamp_file)
  1827. list(APPEND depends ${dependee_stamp_file})
  1828. endforeach()
  1829. # The command to run.
  1830. get_property(command TARGET ${name} PROPERTY _EP_${step}_COMMAND)
  1831. if(command)
  1832. set(comment "Performing ${step} step for '${name}'")
  1833. else()
  1834. set(comment "No ${step} step for '${name}'")
  1835. endif()
  1836. get_property(work_dir TARGET ${name} PROPERTY _EP_${step}_WORKING_DIRECTORY)
  1837. # Replace list separators.
  1838. get_property(sep TARGET ${name} PROPERTY _EP_LIST_SEPARATOR)
  1839. if(sep AND command)
  1840. string(REPLACE "${sep}" "\\;" command "${command}")
  1841. endif()
  1842. # Replace location tags.
  1843. _ep_replace_location_tags(${name} comment command work_dir byproducts)
  1844. # Custom comment?
  1845. get_property(comment_set TARGET ${name} PROPERTY _EP_${step}_COMMENT SET)
  1846. if(comment_set)
  1847. get_property(comment TARGET ${name} PROPERTY _EP_${step}_COMMENT)
  1848. endif()
  1849. # Uses terminal?
  1850. get_property(uses_terminal TARGET ${name} PROPERTY _EP_${step}_USES_TERMINAL)
  1851. if(uses_terminal)
  1852. set(uses_terminal USES_TERMINAL)
  1853. else()
  1854. set(uses_terminal "")
  1855. endif()
  1856. # Run every time?
  1857. get_property(always TARGET ${name} PROPERTY _EP_${step}_ALWAYS)
  1858. if(always)
  1859. set_property(SOURCE ${stamp_file} PROPERTY SYMBOLIC 1)
  1860. set(touch)
  1861. # Remove any existing stamp in case the option changed in an existing tree.
  1862. get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
  1863. if(_isMultiConfig)
  1864. foreach(cfg ${CMAKE_CONFIGURATION_TYPES})
  1865. string(REPLACE "/${CMAKE_CFG_INTDIR}" "/${cfg}" stamp_file_config "${stamp_file}")
  1866. file(REMOVE ${stamp_file_config})
  1867. endforeach()
  1868. else()
  1869. file(REMOVE ${stamp_file})
  1870. endif()
  1871. else()
  1872. set(touch ${CMAKE_COMMAND} -E touch ${stamp_file})
  1873. endif()
  1874. # Wrap with log script?
  1875. get_property(log TARGET ${name} PROPERTY _EP_${step}_LOG)
  1876. if(command AND log)
  1877. _ep_write_log_script(${name} ${step} command)
  1878. endif()
  1879. if("${command}" STREQUAL "")
  1880. # Some generators (i.e. Xcode) will not generate a file level target
  1881. # if no command is set, and therefore the dependencies on this
  1882. # target will be broken.
  1883. # The empty command is replaced by an echo command here in order to
  1884. # avoid this issue.
  1885. set(command ${CMAKE_COMMAND} -E echo_append)
  1886. endif()
  1887. add_custom_command(
  1888. OUTPUT ${stamp_file}
  1889. BYPRODUCTS ${byproducts}
  1890. COMMENT ${comment}
  1891. COMMAND ${command}
  1892. COMMAND ${touch}
  1893. DEPENDS ${depends}
  1894. WORKING_DIRECTORY ${work_dir}
  1895. VERBATIM
  1896. ${uses_terminal}
  1897. )
  1898. set_property(TARGET ${name} APPEND PROPERTY _EP_STEPS ${step})
  1899. # Add custom "step target"?
  1900. get_property(step_targets TARGET ${name} PROPERTY _EP_STEP_TARGETS)
  1901. if(NOT step_targets)
  1902. get_property(step_targets DIRECTORY PROPERTY EP_STEP_TARGETS)
  1903. endif()
  1904. foreach(st ${step_targets})
  1905. if("${st}" STREQUAL "${step}")
  1906. ExternalProject_Add_StepTargets(${name} ${step})
  1907. break()
  1908. endif()
  1909. endforeach()
  1910. get_property(independent_step_targets TARGET ${name} PROPERTY _EP_INDEPENDENT_STEP_TARGETS)
  1911. if(NOT independent_step_targets)
  1912. get_property(independent_step_targets DIRECTORY PROPERTY EP_INDEPENDENT_STEP_TARGETS)
  1913. endif()
  1914. foreach(st ${independent_step_targets})
  1915. if("${st}" STREQUAL "${step}")
  1916. ExternalProject_Add_StepTargets(${name} NO_DEPENDS ${step})
  1917. break()
  1918. endif()
  1919. endforeach()
  1920. endfunction()
  1921. function(ExternalProject_Add_StepDependencies name step)
  1922. set(dependencies ${ARGN})
  1923. # Sanity checks on "name" and "step".
  1924. if(NOT TARGET ${name})
  1925. message(FATAL_ERROR "Cannot find target \"${name}\". Perhaps it has not yet been created using ExternalProject_Add.")
  1926. endif()
  1927. get_property(type TARGET ${name} PROPERTY TYPE)
  1928. if(NOT type STREQUAL "UTILITY")
  1929. message(FATAL_ERROR "Target \"${name}\" was not generated by ExternalProject_Add.")
  1930. endif()
  1931. get_property(is_ep TARGET ${name} PROPERTY _EP_IS_EXTERNAL_PROJECT)
  1932. if(NOT is_ep)
  1933. message(FATAL_ERROR "Target \"${name}\" was not generated by ExternalProject_Add.")
  1934. endif()
  1935. get_property(steps TARGET ${name} PROPERTY _EP_STEPS)
  1936. list(FIND steps ${step} is_step)
  1937. if(NOT is_step)
  1938. message(FATAL_ERROR "External project \"${name}\" does not have a step \"${step}\".")
  1939. endif()
  1940. if(TARGET ${name}-${step})
  1941. get_property(type TARGET ${name}-${step} PROPERTY TYPE)
  1942. if(NOT type STREQUAL "UTILITY")
  1943. message(FATAL_ERROR "Target \"${name}-${step}\" was not generated by ExternalProject_Add_StepTargets.")
  1944. endif()
  1945. get_property(is_ep_step TARGET ${name}-${step} PROPERTY _EP_IS_EXTERNAL_PROJECT_STEP)
  1946. if(NOT is_ep_step)
  1947. message(FATAL_ERROR "Target \"${name}-${step}\" was not generated by ExternalProject_Add_StepTargets.")
  1948. endif()
  1949. endif()
  1950. # Always add file-level dependency, but add target-level dependency
  1951. # only if the target exists for that step.
  1952. _ep_get_step_stampfile(${name} ${step} stamp_file)
  1953. foreach(dep ${dependencies})
  1954. add_custom_command(APPEND
  1955. OUTPUT ${stamp_file}
  1956. DEPENDS ${dep})
  1957. if(TARGET ${name}-${step})
  1958. foreach(dep ${dependencies})
  1959. add_dependencies(${name}-${step} ${dep})
  1960. endforeach()
  1961. endif()
  1962. endforeach()
  1963. endfunction()
  1964. function(_ep_add_mkdir_command name)
  1965. ExternalProject_Get_Property(${name}
  1966. source_dir binary_dir install_dir stamp_dir download_dir tmp_dir log_dir)
  1967. _ep_get_configuration_subdir_suffix(cfgdir)
  1968. ExternalProject_Add_Step(${name} mkdir
  1969. COMMENT "Creating directories for '${name}'"
  1970. COMMAND ${CMAKE_COMMAND} -E make_directory ${source_dir}
  1971. COMMAND ${CMAKE_COMMAND} -E make_directory ${binary_dir}
  1972. COMMAND ${CMAKE_COMMAND} -E make_directory ${install_dir}
  1973. COMMAND ${CMAKE_COMMAND} -E make_directory ${tmp_dir}
  1974. COMMAND ${CMAKE_COMMAND} -E make_directory ${stamp_dir}${cfgdir}
  1975. COMMAND ${CMAKE_COMMAND} -E make_directory ${download_dir}
  1976. COMMAND ${CMAKE_COMMAND} -E make_directory ${log_dir}
  1977. )
  1978. endfunction()
  1979. function(_ep_is_dir_empty dir empty_var)
  1980. file(GLOB gr "${dir}/*")
  1981. if("${gr}" STREQUAL "")
  1982. set(${empty_var} 1 PARENT_SCOPE)
  1983. else()
  1984. set(${empty_var} 0 PARENT_SCOPE)
  1985. endif()
  1986. endfunction()
  1987. function(_ep_add_download_command name)
  1988. ExternalProject_Get_Property(${name} source_dir stamp_dir download_dir tmp_dir)
  1989. get_property(cmd_set TARGET ${name} PROPERTY _EP_DOWNLOAD_COMMAND SET)
  1990. get_property(cmd TARGET ${name} PROPERTY _EP_DOWNLOAD_COMMAND)
  1991. get_property(cvs_repository TARGET ${name} PROPERTY _EP_CVS_REPOSITORY)
  1992. get_property(svn_repository TARGET ${name} PROPERTY _EP_SVN_REPOSITORY)
  1993. get_property(git_repository TARGET ${name} PROPERTY _EP_GIT_REPOSITORY)
  1994. get_property(hg_repository TARGET ${name} PROPERTY _EP_HG_REPOSITORY )
  1995. get_property(url TARGET ${name} PROPERTY _EP_URL)
  1996. get_property(fname TARGET ${name} PROPERTY _EP_DOWNLOAD_NAME)
  1997. # TODO: Perhaps file:// should be copied to download dir before extraction.
  1998. string(REGEX REPLACE "file://" "" url "${url}")
  1999. set(depends)
  2000. set(comment)
  2001. set(work_dir)
  2002. if(cmd_set)
  2003. set(work_dir ${download_dir})
  2004. elseif(cvs_repository)
  2005. find_package(CVS QUIET)
  2006. if(NOT CVS_EXECUTABLE)
  2007. message(FATAL_ERROR "error: could not find cvs for checkout of ${name}")
  2008. endif()
  2009. get_target_property(cvs_module ${name} _EP_CVS_MODULE)
  2010. if(NOT cvs_module)
  2011. message(FATAL_ERROR "error: no CVS_MODULE")
  2012. endif()
  2013. get_property(cvs_tag TARGET ${name} PROPERTY _EP_CVS_TAG)
  2014. set(repository ${cvs_repository})
  2015. set(module ${cvs_module})
  2016. set(tag ${cvs_tag})
  2017. configure_file(
  2018. "${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in"
  2019. "${stamp_dir}/${name}-cvsinfo.txt"
  2020. @ONLY
  2021. )
  2022. get_filename_component(src_name "${source_dir}" NAME)
  2023. get_filename_component(work_dir "${source_dir}" PATH)
  2024. set(comment "Performing download step (CVS checkout) for '${name}'")
  2025. set(cmd ${CVS_EXECUTABLE} -d ${cvs_repository} -q co ${cvs_tag} -d ${src_name} ${cvs_module})
  2026. list(APPEND depends ${stamp_dir}/${name}-cvsinfo.txt)
  2027. elseif(svn_repository)
  2028. find_package(Subversion QUIET)
  2029. if(NOT Subversion_SVN_EXECUTABLE)
  2030. message(FATAL_ERROR "error: could not find svn for checkout of ${name}")
  2031. endif()
  2032. get_property(svn_revision TARGET ${name} PROPERTY _EP_SVN_REVISION)
  2033. get_property(svn_username TARGET ${name} PROPERTY _EP_SVN_USERNAME)
  2034. get_property(svn_password TARGET ${name} PROPERTY _EP_SVN_PASSWORD)
  2035. get_property(svn_trust_cert TARGET ${name} PROPERTY _EP_SVN_TRUST_CERT)
  2036. set(repository "${svn_repository} user=${svn_username} password=${svn_password}")
  2037. set(module)
  2038. set(tag ${svn_revision})
  2039. configure_file(
  2040. "${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in"
  2041. "${stamp_dir}/${name}-svninfo.txt"
  2042. @ONLY
  2043. )
  2044. get_filename_component(src_name "${source_dir}" NAME)
  2045. get_filename_component(work_dir "${source_dir}" PATH)
  2046. set(comment "Performing download step (SVN checkout) for '${name}'")
  2047. set(svn_user_pw_args "")
  2048. if(DEFINED svn_username)
  2049. set(svn_user_pw_args ${svn_user_pw_args} "--username=${svn_username}")
  2050. endif()
  2051. if(DEFINED svn_password)
  2052. set(svn_user_pw_args ${svn_user_pw_args} "--password=${svn_password}")
  2053. endif()
  2054. if(svn_trust_cert)
  2055. set(svn_trust_cert_args --trust-server-cert)
  2056. endif()
  2057. set(cmd ${Subversion_SVN_EXECUTABLE} co ${svn_repository} ${svn_revision}
  2058. --non-interactive ${svn_trust_cert_args} ${svn_user_pw_args} ${src_name})
  2059. list(APPEND depends ${stamp_dir}/${name}-svninfo.txt)
  2060. elseif(git_repository)
  2061. unset(CMAKE_MODULE_PATH) # Use CMake builtin find module
  2062. find_package(Git QUIET)
  2063. if(NOT GIT_EXECUTABLE)
  2064. message(FATAL_ERROR "error: could not find git for clone of ${name}")
  2065. endif()
  2066. # The git submodule update '--recursive' flag requires git >= v1.6.5
  2067. #
  2068. if(GIT_VERSION_STRING VERSION_LESS 1.6.5)
  2069. message(FATAL_ERROR "error: git version 1.6.5 or later required for 'git submodule update --recursive': GIT_VERSION_STRING='${GIT_VERSION_STRING}'")
  2070. endif()
  2071. get_property(git_tag TARGET ${name} PROPERTY _EP_GIT_TAG)
  2072. if(NOT git_tag)
  2073. set(git_tag "master")
  2074. endif()
  2075. get_property(git_submodules TARGET ${name} PROPERTY _EP_GIT_SUBMODULES)
  2076. get_property(git_remote_name TARGET ${name} PROPERTY _EP_GIT_REMOTE_NAME)
  2077. if(NOT git_remote_name)
  2078. set(git_remote_name "origin")
  2079. endif()
  2080. get_property(tls_verify TARGET ${name} PROPERTY _EP_TLS_VERIFY)
  2081. if("x${tls_verify}" STREQUAL "x" AND DEFINED CMAKE_TLS_VERIFY)
  2082. set(tls_verify "${CMAKE_TLS_VERIFY}")
  2083. endif()
  2084. get_property(git_shallow TARGET ${name} PROPERTY _EP_GIT_SHALLOW)
  2085. get_property(git_progress TARGET ${name} PROPERTY _EP_GIT_PROGRESS)
  2086. get_property(git_config TARGET ${name} PROPERTY _EP_GIT_CONFIG)
  2087. # For the download step, and the git clone operation, only the repository
  2088. # should be recorded in a configured RepositoryInfo file. If the repo
  2089. # changes, the clone script should be run again. But if only the tag
  2090. # changes, avoid running the clone script again. Let the 'always' running
  2091. # update step checkout the new tag.
  2092. #
  2093. set(repository ${git_repository})
  2094. set(module)
  2095. set(tag ${git_remote_name})
  2096. configure_file(
  2097. "${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in"
  2098. "${stamp_dir}/${name}-gitinfo.txt"
  2099. @ONLY
  2100. )
  2101. get_filename_component(src_name "${source_dir}" NAME)
  2102. get_filename_component(work_dir "${source_dir}" PATH)
  2103. # Since git clone doesn't succeed if the non-empty source_dir exists,
  2104. # create a cmake script to invoke as download command.
  2105. # The script will delete the source directory and then call git clone.
  2106. #
  2107. _ep_write_gitclone_script(${tmp_dir}/${name}-gitclone.cmake ${source_dir}
  2108. ${GIT_EXECUTABLE} ${git_repository} ${git_tag} ${git_remote_name} "${git_submodules}" "${git_shallow}" "${git_progress}" "${git_config}" ${src_name} ${work_dir}
  2109. ${stamp_dir}/${name}-gitinfo.txt ${stamp_dir}/${name}-gitclone-lastrun.txt "${tls_verify}"
  2110. )
  2111. set(comment "Performing download step (git clone) for '${name}'")
  2112. set(cmd ${CMAKE_COMMAND} -P ${tmp_dir}/${name}-gitclone.cmake)
  2113. list(APPEND depends ${stamp_dir}/${name}-gitinfo.txt)
  2114. elseif(hg_repository)
  2115. find_package(Hg QUIET)
  2116. if(NOT HG_EXECUTABLE)
  2117. message(FATAL_ERROR "error: could not find hg for clone of ${name}")
  2118. endif()
  2119. get_property(hg_tag TARGET ${name} PROPERTY _EP_HG_TAG)
  2120. if(NOT hg_tag)
  2121. set(hg_tag "tip")
  2122. endif()
  2123. # For the download step, and the hg clone operation, only the repository
  2124. # should be recorded in a configured RepositoryInfo file. If the repo
  2125. # changes, the clone script should be run again. But if only the tag
  2126. # changes, avoid running the clone script again. Let the 'always' running
  2127. # update step checkout the new tag.
  2128. #
  2129. set(repository ${hg_repository})
  2130. set(module)
  2131. set(tag)
  2132. configure_file(
  2133. "${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in"
  2134. "${stamp_dir}/${name}-hginfo.txt"
  2135. @ONLY
  2136. )
  2137. get_filename_component(src_name "${source_dir}" NAME)
  2138. get_filename_component(work_dir "${source_dir}" PATH)
  2139. # Since hg clone doesn't succeed if the non-empty source_dir exists,
  2140. # create a cmake script to invoke as download command.
  2141. # The script will delete the source directory and then call hg clone.
  2142. #
  2143. _ep_write_hgclone_script(${tmp_dir}/${name}-hgclone.cmake ${source_dir}
  2144. ${HG_EXECUTABLE} ${hg_repository} ${hg_tag} ${src_name} ${work_dir}
  2145. ${stamp_dir}/${name}-hginfo.txt ${stamp_dir}/${name}-hgclone-lastrun.txt
  2146. )
  2147. set(comment "Performing download step (hg clone) for '${name}'")
  2148. set(cmd ${CMAKE_COMMAND} -P ${tmp_dir}/${name}-hgclone.cmake)
  2149. list(APPEND depends ${stamp_dir}/${name}-hginfo.txt)
  2150. elseif(url)
  2151. get_filename_component(work_dir "${source_dir}" PATH)
  2152. get_property(hash TARGET ${name} PROPERTY _EP_URL_HASH)
  2153. if(hash AND NOT "${hash}" MATCHES "${_ep_hash_regex}")
  2154. message(FATAL_ERROR "URL_HASH is set to\n ${hash}\n"
  2155. "but must be ALGO=value where ALGO is\n ${_ep_hash_algos}\n"
  2156. "and value is a hex string.")
  2157. endif()
  2158. get_property(md5 TARGET ${name} PROPERTY _EP_URL_MD5)
  2159. if(md5 AND NOT "MD5=${md5}" MATCHES "${_ep_hash_regex}")
  2160. message(FATAL_ERROR "URL_MD5 is set to\n ${md5}\nbut must be a hex string.")
  2161. endif()
  2162. if(md5 AND NOT hash)
  2163. set(hash "MD5=${md5}")
  2164. endif()
  2165. set(repository "external project URL")
  2166. set(module "${url}")
  2167. set(tag "${hash}")
  2168. configure_file(
  2169. "${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in"
  2170. "${stamp_dir}/${name}-urlinfo.txt"
  2171. @ONLY
  2172. )
  2173. list(APPEND depends ${stamp_dir}/${name}-urlinfo.txt)
  2174. list(LENGTH url url_list_length)
  2175. if(NOT "${url_list_length}" STREQUAL "1")
  2176. foreach(entry ${url})
  2177. if(NOT "${entry}" MATCHES "^[a-z]+://")
  2178. message(FATAL_ERROR "At least one entry of URL is a path (invalid in a list)")
  2179. endif()
  2180. endforeach()
  2181. if("x${fname}" STREQUAL "x")
  2182. list(GET url 0 fname)
  2183. endif()
  2184. endif()
  2185. if(IS_DIRECTORY "${url}")
  2186. get_filename_component(abs_dir "${url}" ABSOLUTE)
  2187. set(comment "Performing download step (DIR copy) for '${name}'")
  2188. set(cmd ${CMAKE_COMMAND} -E remove_directory ${source_dir}
  2189. COMMAND ${CMAKE_COMMAND} -E copy_directory ${abs_dir} ${source_dir})
  2190. else()
  2191. get_property(no_extract TARGET "${name}" PROPERTY _EP_DOWNLOAD_NO_EXTRACT SET)
  2192. if("${url}" MATCHES "^[a-z]+://")
  2193. # TODO: Should download and extraction be different steps?
  2194. if("x${fname}" STREQUAL "x")
  2195. set(fname "${url}")
  2196. endif()
  2197. if("${fname}" MATCHES [[([^/\?#]+(\.|=)(7z|tar|tar\.bz2|tar\.gz|tar\.xz|tbz2|tgz|txz|zip))([/?#].*)?$]])
  2198. set(fname "${CMAKE_MATCH_1}")
  2199. elseif(no_extract)
  2200. get_filename_component(fname "${fname}" NAME)
  2201. else()
  2202. # Fall back to a default file name. The actual file name does not
  2203. # matter because it is used only internally and our extraction tool
  2204. # inspects the file content directly. If it turns out the wrong URL
  2205. # was given that will be revealed during the build which is an easier
  2206. # place for users to diagnose than an error here anyway.
  2207. set(fname "archive.tar")
  2208. endif()
  2209. string(REPLACE ";" "-" fname "${fname}")
  2210. set(file ${download_dir}/${fname})
  2211. get_property(timeout TARGET ${name} PROPERTY _EP_TIMEOUT)
  2212. get_property(no_progress TARGET ${name} PROPERTY _EP_DOWNLOAD_NO_PROGRESS)
  2213. get_property(tls_verify TARGET ${name} PROPERTY _EP_TLS_VERIFY)
  2214. get_property(tls_cainfo TARGET ${name} PROPERTY _EP_TLS_CAINFO)
  2215. get_property(netrc TARGET ${name} PROPERTY _EP_NETRC)
  2216. get_property(netrc_file TARGET ${name} PROPERTY _EP_NETRC_FILE)
  2217. get_property(http_username TARGET ${name} PROPERTY _EP_HTTP_USERNAME)
  2218. get_property(http_password TARGET ${name} PROPERTY _EP_HTTP_PASSWORD)
  2219. get_property(http_headers TARGET ${name} PROPERTY _EP_HTTP_HEADER)
  2220. set(download_script "${stamp_dir}/download-${name}.cmake")
  2221. _ep_write_downloadfile_script("${download_script}" "${url}" "${file}" "${timeout}" "${no_progress}" "${hash}" "${tls_verify}" "${tls_cainfo}" "${http_username}:${http_password}" "${http_headers}" "${netrc}" "${netrc_file}")
  2222. set(cmd ${CMAKE_COMMAND} -P "${download_script}"
  2223. COMMAND)
  2224. if (no_extract)
  2225. set(steps "download and verify")
  2226. else ()
  2227. set(steps "download, verify and extract")
  2228. endif ()
  2229. set(comment "Performing download step (${steps}) for '${name}'")
  2230. file(WRITE "${stamp_dir}/verify-${name}.cmake" "") # already verified by 'download_script'
  2231. else()
  2232. set(file "${url}")
  2233. if (no_extract)
  2234. set(steps "verify")
  2235. else ()
  2236. set(steps "verify and extract")
  2237. endif ()
  2238. set(comment "Performing download step (${steps}) for '${name}'")
  2239. _ep_write_verifyfile_script("${stamp_dir}/verify-${name}.cmake" "${file}" "${hash}")
  2240. endif()
  2241. list(APPEND cmd ${CMAKE_COMMAND} -P ${stamp_dir}/verify-${name}.cmake)
  2242. if (NOT no_extract)
  2243. _ep_write_extractfile_script("${stamp_dir}/extract-${name}.cmake" "${name}" "${file}" "${source_dir}")
  2244. list(APPEND cmd COMMAND ${CMAKE_COMMAND} -P ${stamp_dir}/extract-${name}.cmake)
  2245. else ()
  2246. set_property(TARGET ${name} PROPERTY _EP_DOWNLOADED_FILE ${file})
  2247. endif ()
  2248. endif()
  2249. else()
  2250. _ep_is_dir_empty("${source_dir}" empty)
  2251. if(${empty})
  2252. message(SEND_ERROR
  2253. "No download info given for '${name}' and its source directory:\n"
  2254. " ${source_dir}\n"
  2255. "is not an existing non-empty directory. Please specify one of:\n"
  2256. " * SOURCE_DIR with an existing non-empty directory\n"
  2257. " * DOWNLOAD_COMMAND\n"
  2258. " * URL\n"
  2259. " * GIT_REPOSITORY\n"
  2260. " * SVN_REPOSITORY\n"
  2261. " * HG_REPOSITORY\n"
  2262. " * CVS_REPOSITORY and CVS_MODULE"
  2263. )
  2264. endif()
  2265. endif()
  2266. get_property(log TARGET ${name} PROPERTY _EP_LOG_DOWNLOAD)
  2267. if(log)
  2268. set(log LOG 1)
  2269. else()
  2270. set(log "")
  2271. endif()
  2272. get_property(uses_terminal TARGET ${name} PROPERTY
  2273. _EP_USES_TERMINAL_DOWNLOAD)
  2274. if(uses_terminal)
  2275. set(uses_terminal USES_TERMINAL 1)
  2276. else()
  2277. set(uses_terminal "")
  2278. endif()
  2279. ExternalProject_Add_Step(${name} download
  2280. COMMENT ${comment}
  2281. COMMAND ${cmd}
  2282. WORKING_DIRECTORY ${work_dir}
  2283. DEPENDS ${depends}
  2284. DEPENDEES mkdir
  2285. ${log}
  2286. ${uses_terminal}
  2287. )
  2288. endfunction()
  2289. function(_ep_add_update_command name)
  2290. ExternalProject_Get_Property(${name} source_dir tmp_dir)
  2291. get_property(cmd_set TARGET ${name} PROPERTY _EP_UPDATE_COMMAND SET)
  2292. get_property(cmd TARGET ${name} PROPERTY _EP_UPDATE_COMMAND)
  2293. get_property(cvs_repository TARGET ${name} PROPERTY _EP_CVS_REPOSITORY)
  2294. get_property(svn_repository TARGET ${name} PROPERTY _EP_SVN_REPOSITORY)
  2295. get_property(git_repository TARGET ${name} PROPERTY _EP_GIT_REPOSITORY)
  2296. get_property(hg_repository TARGET ${name} PROPERTY _EP_HG_REPOSITORY )
  2297. get_property(update_disconnected_set TARGET ${name} PROPERTY _EP_UPDATE_DISCONNECTED SET)
  2298. if(update_disconnected_set)
  2299. get_property(update_disconnected TARGET ${name} PROPERTY _EP_UPDATE_DISCONNECTED)
  2300. else()
  2301. get_property(update_disconnected DIRECTORY PROPERTY EP_UPDATE_DISCONNECTED)
  2302. endif()
  2303. set(work_dir)
  2304. set(comment)
  2305. set(always)
  2306. if(cmd_set)
  2307. set(work_dir ${source_dir})
  2308. if(NOT "x${cmd}" STREQUAL "x")
  2309. set(always 1)
  2310. endif()
  2311. elseif(cvs_repository)
  2312. if(NOT CVS_EXECUTABLE)
  2313. message(FATAL_ERROR "error: could not find cvs for update of ${name}")
  2314. endif()
  2315. set(work_dir ${source_dir})
  2316. set(comment "Performing update step (CVS update) for '${name}'")
  2317. get_property(cvs_tag TARGET ${name} PROPERTY _EP_CVS_TAG)
  2318. set(cmd ${CVS_EXECUTABLE} -d ${cvs_repository} -q up -dP ${cvs_tag})
  2319. set(always 1)
  2320. elseif(svn_repository)
  2321. if(NOT Subversion_SVN_EXECUTABLE)
  2322. message(FATAL_ERROR "error: could not find svn for update of ${name}")
  2323. endif()
  2324. set(work_dir ${source_dir})
  2325. set(comment "Performing update step (SVN update) for '${name}'")
  2326. get_property(svn_revision TARGET ${name} PROPERTY _EP_SVN_REVISION)
  2327. get_property(svn_username TARGET ${name} PROPERTY _EP_SVN_USERNAME)
  2328. get_property(svn_password TARGET ${name} PROPERTY _EP_SVN_PASSWORD)
  2329. get_property(svn_trust_cert TARGET ${name} PROPERTY _EP_SVN_TRUST_CERT)
  2330. set(svn_user_pw_args "")
  2331. if(DEFINED svn_username)
  2332. set(svn_user_pw_args ${svn_user_pw_args} "--username=${svn_username}")
  2333. endif()
  2334. if(DEFINED svn_password)
  2335. set(svn_user_pw_args ${svn_user_pw_args} "--password=${svn_password}")
  2336. endif()
  2337. if(svn_trust_cert)
  2338. set(svn_trust_cert_args --trust-server-cert)
  2339. endif()
  2340. set(cmd ${Subversion_SVN_EXECUTABLE} up ${svn_revision}
  2341. --non-interactive ${svn_trust_cert_args} ${svn_user_pw_args})
  2342. set(always 1)
  2343. elseif(git_repository)
  2344. unset(CMAKE_MODULE_PATH) # Use CMake builtin find module
  2345. find_package(Git QUIET)
  2346. if(NOT GIT_EXECUTABLE)
  2347. message(FATAL_ERROR "error: could not find git for fetch of ${name}")
  2348. endif()
  2349. set(work_dir ${source_dir})
  2350. set(comment "Performing update step for '${name}'")
  2351. get_property(git_tag TARGET ${name} PROPERTY _EP_GIT_TAG)
  2352. if(NOT git_tag)
  2353. set(git_tag "master")
  2354. endif()
  2355. get_property(git_remote_name TARGET ${name} PROPERTY _EP_GIT_REMOTE_NAME)
  2356. if(NOT git_remote_name)
  2357. set(git_remote_name "origin")
  2358. endif()
  2359. get_property(git_submodules TARGET ${name} PROPERTY _EP_GIT_SUBMODULES)
  2360. _ep_write_gitupdate_script(${tmp_dir}/${name}-gitupdate.cmake
  2361. ${GIT_EXECUTABLE} ${git_tag} ${git_remote_name} "${git_submodules}" ${git_repository} ${work_dir}
  2362. )
  2363. set(cmd ${CMAKE_COMMAND} -P ${tmp_dir}/${name}-gitupdate.cmake)
  2364. set(always 1)
  2365. elseif(hg_repository)
  2366. if(NOT HG_EXECUTABLE)
  2367. message(FATAL_ERROR "error: could not find hg for pull of ${name}")
  2368. endif()
  2369. set(work_dir ${source_dir})
  2370. set(comment "Performing update step (hg pull) for '${name}'")
  2371. get_property(hg_tag TARGET ${name} PROPERTY _EP_HG_TAG)
  2372. if(NOT hg_tag)
  2373. set(hg_tag "tip")
  2374. endif()
  2375. if("${HG_VERSION_STRING}" STREQUAL "2.1")
  2376. message(WARNING "Mercurial 2.1 does not distinguish an empty pull from a failed pull:
  2377. http://mercurial.selenic.com/wiki/UpgradeNotes#A2.1.1:_revert_pull_return_code_change.2C_compile_issue_on_OS_X
  2378. http://thread.gmane.org/gmane.comp.version-control.mercurial.devel/47656
  2379. Update to Mercurial >= 2.1.1.
  2380. ")
  2381. endif()
  2382. set(cmd ${HG_EXECUTABLE} pull
  2383. COMMAND ${HG_EXECUTABLE} update ${hg_tag}
  2384. )
  2385. set(always 1)
  2386. endif()
  2387. get_property(log TARGET ${name} PROPERTY _EP_LOG_UPDATE)
  2388. if(log)
  2389. set(log LOG 1)
  2390. else()
  2391. set(log "")
  2392. endif()
  2393. get_property(uses_terminal TARGET ${name} PROPERTY
  2394. _EP_USES_TERMINAL_UPDATE)
  2395. if(uses_terminal)
  2396. set(uses_terminal USES_TERMINAL 1)
  2397. else()
  2398. set(uses_terminal "")
  2399. endif()
  2400. ExternalProject_Add_Step(${name} update
  2401. COMMENT ${comment}
  2402. COMMAND ${cmd}
  2403. ALWAYS ${always}
  2404. EXCLUDE_FROM_MAIN ${update_disconnected}
  2405. WORKING_DIRECTORY ${work_dir}
  2406. DEPENDEES download
  2407. ${log}
  2408. ${uses_terminal}
  2409. )
  2410. if(update_disconnected)
  2411. _ep_get_step_stampfile(${name} skip-update skip-update_stamp_file)
  2412. string(REPLACE "Performing" "Skipping" comment "${comment}")
  2413. ExternalProject_Add_Step(${name} skip-update
  2414. COMMENT ${comment}
  2415. ALWAYS ${always}
  2416. EXCLUDE_FROM_MAIN 1
  2417. WORKING_DIRECTORY ${work_dir}
  2418. DEPENDEES download
  2419. ${log}
  2420. ${uses_terminal}
  2421. )
  2422. set_property(SOURCE ${skip-update_stamp_file} PROPERTY SYMBOLIC 1)
  2423. endif()
  2424. endfunction()
  2425. function(_ep_add_patch_command name)
  2426. ExternalProject_Get_Property(${name} source_dir)
  2427. get_property(cmd_set TARGET ${name} PROPERTY _EP_PATCH_COMMAND SET)
  2428. get_property(cmd TARGET ${name} PROPERTY _EP_PATCH_COMMAND)
  2429. set(work_dir)
  2430. if(cmd_set)
  2431. set(work_dir ${source_dir})
  2432. endif()
  2433. get_property(log TARGET ${name} PROPERTY _EP_LOG_PATCH)
  2434. if(log)
  2435. set(log LOG 1)
  2436. else()
  2437. set(log "")
  2438. endif()
  2439. ExternalProject_Add_Step(${name} patch
  2440. COMMAND ${cmd}
  2441. WORKING_DIRECTORY ${work_dir}
  2442. DEPENDEES download
  2443. ${log}
  2444. )
  2445. endfunction()
  2446. function(_ep_extract_configure_command var name)
  2447. get_property(cmd_set TARGET ${name} PROPERTY _EP_CONFIGURE_COMMAND SET)
  2448. if(cmd_set)
  2449. get_property(cmd TARGET ${name} PROPERTY _EP_CONFIGURE_COMMAND)
  2450. else()
  2451. get_target_property(cmake_command ${name} _EP_CMAKE_COMMAND)
  2452. if(cmake_command)
  2453. set(cmd "${cmake_command}")
  2454. else()
  2455. set(cmd "${CMAKE_COMMAND}")
  2456. endif()
  2457. get_property(cmake_args TARGET ${name} PROPERTY _EP_CMAKE_ARGS)
  2458. list(APPEND cmd ${cmake_args})
  2459. # If there are any CMAKE_CACHE_ARGS or CMAKE_CACHE_DEFAULT_ARGS,
  2460. # write an initial cache and use it
  2461. get_property(cmake_cache_args TARGET ${name} PROPERTY _EP_CMAKE_CACHE_ARGS)
  2462. get_property(cmake_cache_default_args TARGET ${name} PROPERTY _EP_CMAKE_CACHE_DEFAULT_ARGS)
  2463. set(has_cmake_cache_args 0)
  2464. if(NOT "${cmake_cache_args}" STREQUAL "")
  2465. set(has_cmake_cache_args 1)
  2466. endif()
  2467. set(has_cmake_cache_default_args 0)
  2468. if(NOT "${cmake_cache_default_args}" STREQUAL "")
  2469. set(has_cmake_cache_default_args 1)
  2470. endif()
  2471. if(has_cmake_cache_args OR has_cmake_cache_default_args)
  2472. set(_ep_cache_args_script "<TMP_DIR>/${name}-cache-$<CONFIG>.cmake")
  2473. if(has_cmake_cache_args)
  2474. _ep_command_line_to_initial_cache(script_initial_cache_force "${cmake_cache_args}" 1)
  2475. endif()
  2476. if(has_cmake_cache_default_args)
  2477. _ep_command_line_to_initial_cache(script_initial_cache_default "${cmake_cache_default_args}" 0)
  2478. endif()
  2479. _ep_write_initial_cache(${name} "${_ep_cache_args_script}" "${script_initial_cache_force}${script_initial_cache_default}")
  2480. list(APPEND cmd "-C${_ep_cache_args_script}")
  2481. endif()
  2482. get_target_property(cmake_generator ${name} _EP_CMAKE_GENERATOR)
  2483. get_target_property(cmake_generator_instance ${name} _EP_CMAKE_GENERATOR_INSTANCE)
  2484. get_target_property(cmake_generator_platform ${name} _EP_CMAKE_GENERATOR_PLATFORM)
  2485. get_target_property(cmake_generator_toolset ${name} _EP_CMAKE_GENERATOR_TOOLSET)
  2486. if(cmake_generator)
  2487. list(APPEND cmd "-G${cmake_generator}")
  2488. if(cmake_generator_platform)
  2489. list(APPEND cmd "-A${cmake_generator_platform}")
  2490. endif()
  2491. if(cmake_generator_toolset)
  2492. list(APPEND cmd "-T${cmake_generator_toolset}")
  2493. endif()
  2494. if(cmake_generator_instance)
  2495. list(APPEND cmd "-DCMAKE_GENERATOR_INSTANCE:INTERNAL=${cmake_generator_instance}")
  2496. endif()
  2497. else()
  2498. if(CMAKE_EXTRA_GENERATOR)
  2499. list(APPEND cmd "-G${CMAKE_EXTRA_GENERATOR} - ${CMAKE_GENERATOR}")
  2500. else()
  2501. list(APPEND cmd "-G${CMAKE_GENERATOR}")
  2502. endif()
  2503. if(cmake_generator_platform)
  2504. message(FATAL_ERROR "Option CMAKE_GENERATOR_PLATFORM not allowed without CMAKE_GENERATOR.")
  2505. endif()
  2506. if(CMAKE_GENERATOR_PLATFORM)
  2507. list(APPEND cmd "-A${CMAKE_GENERATOR_PLATFORM}")
  2508. endif()
  2509. if(cmake_generator_toolset)
  2510. message(FATAL_ERROR "Option CMAKE_GENERATOR_TOOLSET not allowed without CMAKE_GENERATOR.")
  2511. endif()
  2512. if(CMAKE_GENERATOR_TOOLSET)
  2513. list(APPEND cmd "-T${CMAKE_GENERATOR_TOOLSET}")
  2514. endif()
  2515. if(cmake_generator_instance)
  2516. message(FATAL_ERROR "Option CMAKE_GENERATOR_INSTANCE not allowed without CMAKE_GENERATOR.")
  2517. endif()
  2518. if(CMAKE_GENERATOR_INSTANCE)
  2519. list(APPEND cmd "-DCMAKE_GENERATOR_INSTANCE:INTERNAL=${CMAKE_GENERATOR_INSTANCE}")
  2520. endif()
  2521. endif()
  2522. list(APPEND cmd "<SOURCE_DIR><SOURCE_SUBDIR>")
  2523. endif()
  2524. set("${var}" "${cmd}" PARENT_SCOPE)
  2525. endfunction()
  2526. # TODO: Make sure external projects use the proper compiler
  2527. function(_ep_add_configure_command name)
  2528. ExternalProject_Get_Property(${name} binary_dir tmp_dir)
  2529. # Depend on other external projects (file-level).
  2530. set(file_deps)
  2531. get_property(deps TARGET ${name} PROPERTY _EP_DEPENDS)
  2532. foreach(dep IN LISTS deps)
  2533. get_property(dep_type TARGET ${dep} PROPERTY TYPE)
  2534. if(dep_type STREQUAL "UTILITY")
  2535. get_property(is_ep TARGET ${dep} PROPERTY _EP_IS_EXTERNAL_PROJECT)
  2536. if(is_ep)
  2537. _ep_get_step_stampfile(${dep} "done" done_stamp_file)
  2538. list(APPEND file_deps ${done_stamp_file})
  2539. endif()
  2540. endif()
  2541. endforeach()
  2542. _ep_extract_configure_command(cmd ${name})
  2543. # If anything about the configure command changes, (command itself, cmake
  2544. # used, cmake args or cmake generator) then re-run the configure step.
  2545. # Fixes issue https://gitlab.kitware.com/cmake/cmake/issues/10258
  2546. #
  2547. if(NOT EXISTS ${tmp_dir}/${name}-cfgcmd.txt.in)
  2548. file(WRITE ${tmp_dir}/${name}-cfgcmd.txt.in "cmd='\@cmd\@'\n")
  2549. endif()
  2550. configure_file(${tmp_dir}/${name}-cfgcmd.txt.in ${tmp_dir}/${name}-cfgcmd.txt)
  2551. list(APPEND file_deps ${tmp_dir}/${name}-cfgcmd.txt)
  2552. list(APPEND file_deps ${_ep_cache_args_script})
  2553. get_property(log TARGET ${name} PROPERTY _EP_LOG_CONFIGURE)
  2554. if(log)
  2555. set(log LOG 1)
  2556. else()
  2557. set(log "")
  2558. endif()
  2559. get_property(uses_terminal TARGET ${name} PROPERTY
  2560. _EP_USES_TERMINAL_CONFIGURE)
  2561. if(uses_terminal)
  2562. set(uses_terminal USES_TERMINAL 1)
  2563. else()
  2564. set(uses_terminal "")
  2565. endif()
  2566. get_property(update_disconnected_set TARGET ${name} PROPERTY _EP_UPDATE_DISCONNECTED SET)
  2567. if(update_disconnected_set)
  2568. get_property(update_disconnected TARGET ${name} PROPERTY _EP_UPDATE_DISCONNECTED)
  2569. else()
  2570. get_property(update_disconnected DIRECTORY PROPERTY EP_UPDATE_DISCONNECTED)
  2571. endif()
  2572. if(update_disconnected)
  2573. set(update_dep skip-update)
  2574. else()
  2575. set(update_dep update)
  2576. endif()
  2577. ExternalProject_Add_Step(${name} configure
  2578. COMMAND ${cmd}
  2579. WORKING_DIRECTORY ${binary_dir}
  2580. DEPENDEES ${update_dep} patch
  2581. DEPENDS ${file_deps}
  2582. ${log}
  2583. ${uses_terminal}
  2584. )
  2585. endfunction()
  2586. function(_ep_add_build_command name)
  2587. ExternalProject_Get_Property(${name} binary_dir)
  2588. get_property(cmd_set TARGET ${name} PROPERTY _EP_BUILD_COMMAND SET)
  2589. if(cmd_set)
  2590. get_property(cmd TARGET ${name} PROPERTY _EP_BUILD_COMMAND)
  2591. else()
  2592. _ep_get_build_command(${name} BUILD cmd)
  2593. endif()
  2594. get_property(log TARGET ${name} PROPERTY _EP_LOG_BUILD)
  2595. if(log)
  2596. set(log LOG 1)
  2597. else()
  2598. set(log "")
  2599. endif()
  2600. get_property(uses_terminal TARGET ${name} PROPERTY
  2601. _EP_USES_TERMINAL_BUILD)
  2602. if(uses_terminal)
  2603. set(uses_terminal USES_TERMINAL 1)
  2604. else()
  2605. set(uses_terminal "")
  2606. endif()
  2607. get_property(build_always TARGET ${name} PROPERTY _EP_BUILD_ALWAYS)
  2608. if(build_always)
  2609. set(always 1)
  2610. else()
  2611. set(always 0)
  2612. endif()
  2613. get_property(build_byproducts TARGET ${name} PROPERTY _EP_BUILD_BYPRODUCTS)
  2614. ExternalProject_Add_Step(${name} build
  2615. COMMAND ${cmd}
  2616. BYPRODUCTS ${build_byproducts}
  2617. WORKING_DIRECTORY ${binary_dir}
  2618. DEPENDEES configure
  2619. ALWAYS ${always}
  2620. ${log}
  2621. ${uses_terminal}
  2622. )
  2623. endfunction()
  2624. function(_ep_add_install_command name)
  2625. ExternalProject_Get_Property(${name} binary_dir)
  2626. get_property(cmd_set TARGET ${name} PROPERTY _EP_INSTALL_COMMAND SET)
  2627. if(cmd_set)
  2628. get_property(cmd TARGET ${name} PROPERTY _EP_INSTALL_COMMAND)
  2629. else()
  2630. _ep_get_build_command(${name} INSTALL cmd)
  2631. endif()
  2632. get_property(log TARGET ${name} PROPERTY _EP_LOG_INSTALL)
  2633. if(log)
  2634. set(log LOG 1)
  2635. else()
  2636. set(log "")
  2637. endif()
  2638. get_property(uses_terminal TARGET ${name} PROPERTY
  2639. _EP_USES_TERMINAL_INSTALL)
  2640. if(uses_terminal)
  2641. set(uses_terminal USES_TERMINAL 1)
  2642. else()
  2643. set(uses_terminal "")
  2644. endif()
  2645. ExternalProject_Add_Step(${name} install
  2646. COMMAND ${cmd}
  2647. WORKING_DIRECTORY ${binary_dir}
  2648. DEPENDEES build
  2649. ${log}
  2650. ${uses_terminal}
  2651. )
  2652. endfunction()
  2653. function(_ep_add_test_command name)
  2654. ExternalProject_Get_Property(${name} binary_dir)
  2655. get_property(before TARGET ${name} PROPERTY _EP_TEST_BEFORE_INSTALL)
  2656. get_property(after TARGET ${name} PROPERTY _EP_TEST_AFTER_INSTALL)
  2657. get_property(exclude TARGET ${name} PROPERTY _EP_TEST_EXCLUDE_FROM_MAIN)
  2658. get_property(cmd_set TARGET ${name} PROPERTY _EP_TEST_COMMAND SET)
  2659. # Only actually add the test step if one of the test related properties is
  2660. # explicitly set. (i.e. the test step is omitted unless requested...)
  2661. #
  2662. if(cmd_set OR before OR after OR exclude)
  2663. if(cmd_set)
  2664. get_property(cmd TARGET ${name} PROPERTY _EP_TEST_COMMAND)
  2665. else()
  2666. _ep_get_build_command(${name} TEST cmd)
  2667. endif()
  2668. if(before)
  2669. set(dependees_args DEPENDEES build)
  2670. else()
  2671. set(dependees_args DEPENDEES install)
  2672. endif()
  2673. if(exclude)
  2674. set(dependers_args "")
  2675. set(exclude_args EXCLUDE_FROM_MAIN 1)
  2676. else()
  2677. if(before)
  2678. set(dependers_args DEPENDERS install)
  2679. else()
  2680. set(dependers_args "")
  2681. endif()
  2682. set(exclude_args "")
  2683. endif()
  2684. get_property(log TARGET ${name} PROPERTY _EP_LOG_TEST)
  2685. if(log)
  2686. set(log LOG 1)
  2687. else()
  2688. set(log "")
  2689. endif()
  2690. get_property(uses_terminal TARGET ${name} PROPERTY
  2691. _EP_USES_TERMINAL_TEST)
  2692. if(uses_terminal)
  2693. set(uses_terminal USES_TERMINAL 1)
  2694. else()
  2695. set(uses_terminal "")
  2696. endif()
  2697. ExternalProject_Add_Step(${name} test
  2698. COMMAND ${cmd}
  2699. WORKING_DIRECTORY ${binary_dir}
  2700. ${dependees_args}
  2701. ${dependers_args}
  2702. ${exclude_args}
  2703. ${log}
  2704. ${uses_terminal}
  2705. )
  2706. endif()
  2707. endfunction()
  2708. function(ExternalProject_Add name)
  2709. _ep_get_configuration_subdir_suffix(cfgdir)
  2710. # Add a custom target for the external project.
  2711. set(cmf_dir ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles)
  2712. _ep_get_complete_stampfile(${name} complete_stamp_file)
  2713. # The "ALL" option to add_custom_target just tells it to not set the
  2714. # EXCLUDE_FROM_ALL target property. Later, if the EXCLUDE_FROM_ALL
  2715. # argument was passed, we explicitly set it for the target.
  2716. add_custom_target(${name} ALL DEPENDS ${complete_stamp_file})
  2717. set_property(TARGET ${name} PROPERTY _EP_IS_EXTERNAL_PROJECT 1)
  2718. set_property(TARGET ${name} PROPERTY LABELS ${name})
  2719. set_property(TARGET ${name} PROPERTY FOLDER "ExternalProjectTargets/${name}")
  2720. _ep_parse_arguments(ExternalProject_Add ${name} _EP_ "${ARGN}")
  2721. _ep_set_directories(${name})
  2722. _ep_get_step_stampfile(${name} "done" done_stamp_file)
  2723. _ep_get_step_stampfile(${name} "install" install_stamp_file)
  2724. # Set the EXCLUDE_FROM_ALL target property if required.
  2725. get_property(exclude_from_all TARGET ${name} PROPERTY _EP_EXCLUDE_FROM_ALL)
  2726. if(exclude_from_all)
  2727. set_property(TARGET ${name} PROPERTY EXCLUDE_FROM_ALL TRUE)
  2728. endif()
  2729. # The 'complete' step depends on all other steps and creates a
  2730. # 'done' mark. A dependent external project's 'configure' step
  2731. # depends on the 'done' mark so that it rebuilds when this project
  2732. # rebuilds. It is important that 'done' is not the output of any
  2733. # custom command so that CMake does not propagate build rules to
  2734. # other external project targets, which may cause problems during
  2735. # parallel builds. However, the Ninja generator needs to see the entire
  2736. # dependency graph, and can cope with custom commands belonging to
  2737. # multiple targets, so we add the 'done' mark as an output for Ninja only.
  2738. set(complete_outputs ${complete_stamp_file})
  2739. if(${CMAKE_GENERATOR} MATCHES "Ninja")
  2740. set(complete_outputs ${complete_outputs} ${done_stamp_file})
  2741. endif()
  2742. add_custom_command(
  2743. OUTPUT ${complete_outputs}
  2744. COMMENT "Completed '${name}'"
  2745. COMMAND ${CMAKE_COMMAND} -E make_directory ${cmf_dir}${cfgdir}
  2746. COMMAND ${CMAKE_COMMAND} -E touch ${complete_stamp_file}
  2747. COMMAND ${CMAKE_COMMAND} -E touch ${done_stamp_file}
  2748. DEPENDS ${install_stamp_file}
  2749. VERBATIM
  2750. )
  2751. # Depend on other external projects (target-level).
  2752. get_property(deps TARGET ${name} PROPERTY _EP_DEPENDS)
  2753. foreach(arg IN LISTS deps)
  2754. add_dependencies(${name} ${arg})
  2755. endforeach()
  2756. # Set up custom build steps based on the target properties.
  2757. # Each step depends on the previous one.
  2758. #
  2759. # The target depends on the output of the final step.
  2760. # (Already set up above in the DEPENDS of the add_custom_target command.)
  2761. #
  2762. _ep_add_mkdir_command(${name})
  2763. _ep_add_download_command(${name})
  2764. _ep_add_update_command(${name})
  2765. _ep_add_patch_command(${name})
  2766. _ep_add_configure_command(${name})
  2767. _ep_add_build_command(${name})
  2768. _ep_add_install_command(${name})
  2769. # Test is special in that it might depend on build, or it might depend
  2770. # on install.
  2771. #
  2772. _ep_add_test_command(${name})
  2773. endfunction()
  2774. cmake_policy(POP)