ExternalProject.cmake 134 KB

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