ExternalProject.cmake 147 KB

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