ExternalProject.cmake 146 KB

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