ExternalProject.cmake 137 KB

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