ExternalProject.cmake 144 KB

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