ExternalProject.cmake 106 KB

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