ExternalProject.cmake 119 KB

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