ExternalProject.cmake 146 KB

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