ExternalProject.cmake 144 KB

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