ExternalProject.cmake 142 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431
  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. re-use 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 re-uses 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(timeout)
  1225. set(TIMEOUT_ARGS TIMEOUT ${timeout})
  1226. set(TIMEOUT_MSG "${timeout} seconds")
  1227. else()
  1228. set(TIMEOUT_ARGS "# no TIMEOUT")
  1229. set(TIMEOUT_MSG "none")
  1230. endif()
  1231. if(inactivity_timeout)
  1232. set(INACTIVITY_TIMEOUT_ARGS INACTIVITY_TIMEOUT ${inactivity_timeout})
  1233. set(INACTIVITY_TIMEOUT_MSG "${inactivity_timeout} seconds")
  1234. else()
  1235. set(INACTIVITY_TIMEOUT_ARGS "# no INACTIVITY_TIMEOUT")
  1236. set(INACTIVITY_TIMEOUT_MSG "none")
  1237. endif()
  1238. if(no_progress)
  1239. set(SHOW_PROGRESS "")
  1240. else()
  1241. set(SHOW_PROGRESS "SHOW_PROGRESS")
  1242. endif()
  1243. _ep_get_hash_regex(_ep_hash_regex)
  1244. if("${hash}" MATCHES "${_ep_hash_regex}")
  1245. set(ALGO "${CMAKE_MATCH_1}")
  1246. string(TOLOWER "${CMAKE_MATCH_2}" EXPECT_VALUE)
  1247. else()
  1248. set(ALGO "")
  1249. set(EXPECT_VALUE "")
  1250. endif()
  1251. set(TLS_VERIFY_CODE "")
  1252. set(TLS_CAINFO_CODE "")
  1253. set(NETRC_CODE "")
  1254. set(NETRC_FILE_CODE "")
  1255. # check for curl globals in the project
  1256. if(DEFINED CMAKE_TLS_VERIFY)
  1257. set(TLS_VERIFY_CODE "set(CMAKE_TLS_VERIFY ${CMAKE_TLS_VERIFY})")
  1258. endif()
  1259. if(DEFINED CMAKE_TLS_CAINFO)
  1260. set(TLS_CAINFO_CODE "set(CMAKE_TLS_CAINFO \"${CMAKE_TLS_CAINFO}\")")
  1261. endif()
  1262. if(DEFINED CMAKE_NETRC)
  1263. set(NETRC_CODE "set(CMAKE_NETRC \"${CMAKE_NETRC}\")")
  1264. endif()
  1265. if(DEFINED CMAKE_NETRC_FILE)
  1266. set(NETRC_FILE_CODE "set(CMAKE_NETRC_FILE \"${CMAKE_NETRC_FILE}\")")
  1267. endif()
  1268. # now check for curl locals so that the local values
  1269. # will override the globals
  1270. # check for tls_verify argument
  1271. string(LENGTH "${tls_verify}" tls_verify_len)
  1272. if(tls_verify_len GREATER 0)
  1273. set(TLS_VERIFY_CODE "set(CMAKE_TLS_VERIFY ${tls_verify})")
  1274. endif()
  1275. # check for tls_cainfo argument
  1276. string(LENGTH "${tls_cainfo}" tls_cainfo_len)
  1277. if(tls_cainfo_len GREATER 0)
  1278. set(TLS_CAINFO_CODE "set(CMAKE_TLS_CAINFO \"${tls_cainfo}\")")
  1279. endif()
  1280. # check for netrc argument
  1281. string(LENGTH "${netrc}" netrc_len)
  1282. if(netrc_len GREATER 0)
  1283. set(NETRC_CODE "set(CMAKE_NETRC \"${netrc}\")")
  1284. endif()
  1285. # check for netrc_file argument
  1286. string(LENGTH "${netrc_file}" netrc_file_len)
  1287. if(netrc_file_len GREATER 0)
  1288. set(NETRC_FILE_CODE "set(CMAKE_NETRC_FILE \"${netrc_file}\")")
  1289. endif()
  1290. if(userpwd STREQUAL ":")
  1291. set(USERPWD_ARGS)
  1292. else()
  1293. set(USERPWD_ARGS USERPWD "${userpwd}")
  1294. endif()
  1295. set(HTTP_HEADERS_ARGS "")
  1296. if(NOT http_headers STREQUAL "")
  1297. foreach(header ${http_headers})
  1298. string(PREPEND HTTP_HEADERS_ARGS
  1299. "HTTPHEADER \"${header}\"\n "
  1300. )
  1301. endforeach()
  1302. endif()
  1303. # Used variables:
  1304. # * TLS_VERIFY_CODE
  1305. # * TLS_CAINFO_CODE
  1306. # * ALGO
  1307. # * EXPECT_VALUE
  1308. # * REMOTE
  1309. # * LOCAL
  1310. # * SHOW_PROGRESS
  1311. # * TIMEOUT_ARGS
  1312. # * TIMEOUT_MSG
  1313. # * USERPWD_ARGS
  1314. # * HTTP_HEADERS_ARGS
  1315. configure_file(
  1316. "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/ExternalProject/download.cmake.in"
  1317. "${script_filename}"
  1318. @ONLY
  1319. )
  1320. endfunction()
  1321. function(_ep_write_verifyfile_script
  1322. script_filename
  1323. LOCAL
  1324. hash
  1325. )
  1326. _ep_get_hash_regex(_ep_hash_regex)
  1327. if("${hash}" MATCHES "${_ep_hash_regex}")
  1328. set(ALGO "${CMAKE_MATCH_1}")
  1329. string(TOLOWER "${CMAKE_MATCH_2}" EXPECT_VALUE)
  1330. else()
  1331. set(ALGO "")
  1332. set(EXPECT_VALUE "")
  1333. endif()
  1334. # Used variables:
  1335. # * ALGO
  1336. # * EXPECT_VALUE
  1337. # * LOCAL
  1338. configure_file(
  1339. "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/ExternalProject/verify.cmake.in"
  1340. "${script_filename}"
  1341. @ONLY
  1342. )
  1343. endfunction()
  1344. function(_ep_write_extractfile_script
  1345. script_filename
  1346. name
  1347. filename
  1348. directory options
  1349. )
  1350. set(args "")
  1351. if(filename MATCHES
  1352. "(\\.|=)(7z|tar\\.bz2|tar\\.gz|tar\\.xz|tbz2|tgz|txz|zip)$")
  1353. set(args xfz)
  1354. endif()
  1355. if(filename MATCHES "(\\.|=)tar$")
  1356. set(args xf)
  1357. endif()
  1358. if(args STREQUAL "")
  1359. message(FATAL_ERROR
  1360. "Do not know how to extract '${filename}' -- known types are: "
  1361. ".7z, .tar, .tar.bz2, .tar.gz, .tar.xz, .tbz2, .tgz, .txz and .zip"
  1362. )
  1363. endif()
  1364. configure_file(
  1365. "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/ExternalProject/extractfile.cmake.in"
  1366. "${script_filename}"
  1367. @ONLY
  1368. )
  1369. endfunction()
  1370. function(_ep_set_directories name)
  1371. get_property(prefix TARGET ${name} PROPERTY _EP_PREFIX)
  1372. if(NOT prefix)
  1373. get_property(prefix DIRECTORY PROPERTY EP_PREFIX)
  1374. if(NOT prefix)
  1375. get_property(base DIRECTORY PROPERTY EP_BASE)
  1376. if(NOT base)
  1377. set(prefix "${name}-prefix")
  1378. endif()
  1379. endif()
  1380. endif()
  1381. if(prefix)
  1382. file(TO_CMAKE_PATH "${prefix}" prefix)
  1383. set(tmp_default "${prefix}/tmp")
  1384. set(download_default "${prefix}/src")
  1385. set(source_default "${prefix}/src/${name}")
  1386. set(binary_default "${prefix}/src/${name}-build")
  1387. set(stamp_default "${prefix}/src/${name}-stamp")
  1388. set(install_default "${prefix}")
  1389. else()
  1390. file(TO_CMAKE_PATH "${base}" base)
  1391. set(tmp_default "${base}/tmp/${name}")
  1392. set(download_default "${base}/Download/${name}")
  1393. set(source_default "${base}/Source/${name}")
  1394. set(binary_default "${base}/Build/${name}")
  1395. set(stamp_default "${base}/Stamp/${name}")
  1396. set(install_default "${base}/Install/${name}")
  1397. endif()
  1398. get_property(build_in_source TARGET ${name} PROPERTY _EP_BUILD_IN_SOURCE)
  1399. if(build_in_source)
  1400. get_property(have_binary_dir TARGET ${name} PROPERTY _EP_BINARY_DIR SET)
  1401. if(have_binary_dir)
  1402. message(FATAL_ERROR
  1403. "External project ${name} has both BINARY_DIR and BUILD_IN_SOURCE!"
  1404. )
  1405. endif()
  1406. endif()
  1407. set(top "${CMAKE_CURRENT_BINARY_DIR}")
  1408. # Apply defaults and convert to absolute paths.
  1409. set(places stamp download source binary install tmp)
  1410. foreach(var ${places})
  1411. string(TOUPPER "${var}" VAR)
  1412. get_property(${var}_dir TARGET ${name} PROPERTY _EP_${VAR}_DIR)
  1413. if(NOT ${var}_dir)
  1414. set(${var}_dir "${${var}_default}")
  1415. endif()
  1416. if(NOT IS_ABSOLUTE "${${var}_dir}")
  1417. get_filename_component(${var}_dir "${top}/${${var}_dir}" ABSOLUTE)
  1418. endif()
  1419. file(TO_CMAKE_PATH "${${var}_dir}" ${var}_dir)
  1420. set_property(TARGET ${name} PROPERTY _EP_${VAR}_DIR "${${var}_dir}")
  1421. endforeach()
  1422. # Special case for default log directory based on stamp directory.
  1423. get_property(log_dir TARGET ${name} PROPERTY _EP_LOG_DIR)
  1424. if(NOT log_dir)
  1425. get_property(log_dir TARGET ${name} PROPERTY _EP_STAMP_DIR)
  1426. endif()
  1427. if(NOT IS_ABSOLUTE "${log_dir}")
  1428. get_filename_component(log_dir "${top}/${log_dir}" ABSOLUTE)
  1429. endif()
  1430. file(TO_CMAKE_PATH "${log_dir}" log_dir)
  1431. set_property(TARGET ${name} PROPERTY _EP_LOG_DIR "${log_dir}")
  1432. get_property(source_subdir TARGET ${name} PROPERTY _EP_SOURCE_SUBDIR)
  1433. if(NOT source_subdir)
  1434. set_property(TARGET ${name} PROPERTY _EP_SOURCE_SUBDIR "")
  1435. elseif(IS_ABSOLUTE "${source_subdir}")
  1436. message(FATAL_ERROR
  1437. "External project ${name} has non-relative SOURCE_SUBDIR!"
  1438. )
  1439. else()
  1440. # Prefix with a slash so that when appended to the source directory, it
  1441. # behaves as expected.
  1442. file(TO_CMAKE_PATH "${source_subdir}" source_subdir)
  1443. set_property(TARGET ${name} PROPERTY _EP_SOURCE_SUBDIR "/${source_subdir}")
  1444. endif()
  1445. if(build_in_source)
  1446. get_property(source_dir TARGET ${name} PROPERTY _EP_SOURCE_DIR)
  1447. if(source_subdir)
  1448. set_property(TARGET ${name} PROPERTY
  1449. _EP_BINARY_DIR "${source_dir}/${source_subdir}"
  1450. )
  1451. else()
  1452. set_property(TARGET ${name} PROPERTY
  1453. _EP_BINARY_DIR "${source_dir}"
  1454. )
  1455. endif()
  1456. endif()
  1457. # This script will be used both here and by the mkdir step. We create the
  1458. # directories now at configure time and ensure they exist again at build
  1459. # time (since somebody might remove one of the required directories and try
  1460. # to rebuild without re-running cmake). They need to exist now at makefile
  1461. # generation time for Borland make and wmake so that CMake may generate
  1462. # makefiles with "cd C:\short\paths\with\no\spaces" commands in them.
  1463. set(script_filename "${tmp_dir}/${name}-mkdirs.cmake")
  1464. configure_file(
  1465. ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/ExternalProject/mkdirs.cmake.in
  1466. ${script_filename}
  1467. @ONLY
  1468. )
  1469. unset(cfgdir) # do not leak into mkdirs.cmake script
  1470. include(${script_filename})
  1471. endfunction()
  1472. # IMPORTANT: this MUST be a macro and not a function because of the
  1473. # in-place replacements that occur in each ${var}
  1474. #
  1475. macro(_ep_replace_location_tags target_name)
  1476. set(vars ${ARGN})
  1477. foreach(var ${vars})
  1478. if(${var})
  1479. foreach(dir
  1480. SOURCE_DIR
  1481. SOURCE_SUBDIR
  1482. BINARY_DIR
  1483. INSTALL_DIR
  1484. TMP_DIR
  1485. DOWNLOAD_DIR
  1486. DOWNLOADED_FILE
  1487. LOG_DIR
  1488. )
  1489. get_property(val TARGET ${target_name} PROPERTY _EP_${dir})
  1490. string(REPLACE "<${dir}>" "${val}" ${var} "${${var}}")
  1491. endforeach()
  1492. endif()
  1493. endforeach()
  1494. endmacro()
  1495. function(_ep_command_line_to_initial_cache
  1496. var
  1497. args
  1498. force
  1499. )
  1500. set(script_initial_cache "")
  1501. set(regex "^([^:]+):([^=]+)=(.*)$")
  1502. set(setArg "")
  1503. set(forceArg "")
  1504. if(force)
  1505. set(forceArg "FORCE")
  1506. endif()
  1507. foreach(line ${args})
  1508. if("${line}" MATCHES "^-D(.*)")
  1509. set(line "${CMAKE_MATCH_1}")
  1510. if(NOT "${setArg}" STREQUAL "")
  1511. # This is required to build up lists in variables, or complete an entry
  1512. string(APPEND setArg
  1513. "${accumulator}\" CACHE ${type} \"Initial cache\" ${forceArg})"
  1514. )
  1515. string(APPEND script_initial_cache "\n${setArg}")
  1516. set(accumulator "")
  1517. set(setArg "")
  1518. endif()
  1519. if("${line}" MATCHES "${regex}")
  1520. set(name "${CMAKE_MATCH_1}")
  1521. set(type "${CMAKE_MATCH_2}")
  1522. set(value "${CMAKE_MATCH_3}")
  1523. set(setArg "set(${name} \"${value}")
  1524. else()
  1525. message(WARNING "Line '${line}' does not match regex. Ignoring.")
  1526. endif()
  1527. else()
  1528. # Assume this is a list to append to the last var
  1529. string(APPEND accumulator ";${line}")
  1530. endif()
  1531. endforeach()
  1532. # Catch the final line of the args
  1533. if(NOT "${setArg}" STREQUAL "")
  1534. string(APPEND setArg
  1535. "${accumulator}\" CACHE ${type} \"Initial cache\" ${forceArg})"
  1536. )
  1537. string(APPEND script_initial_cache "\n${setArg}")
  1538. endif()
  1539. set(${var} ${script_initial_cache} PARENT_SCOPE)
  1540. endfunction()
  1541. function(_ep_write_initial_cache
  1542. target_name
  1543. script_filename
  1544. script_initial_cache
  1545. )
  1546. # Write out values into an initial cache, that will be passed to CMake with -C
  1547. # Replace location tags.
  1548. _ep_replace_location_tags(${target_name} script_initial_cache)
  1549. _ep_replace_location_tags(${target_name} script_filename)
  1550. # Replace list separators.
  1551. get_property(sep TARGET ${target_name} PROPERTY _EP_LIST_SEPARATOR)
  1552. if(sep AND script_initial_cache)
  1553. string(REPLACE "${sep}" ";" script_initial_cache "${script_initial_cache}")
  1554. endif()
  1555. # Write out the initial cache file to the location specified.
  1556. file(GENERATE OUTPUT "${script_filename}" CONTENT "${script_initial_cache}")
  1557. endfunction()
  1558. function(ExternalProject_Get_Property name)
  1559. foreach(var ${ARGN})
  1560. string(TOUPPER "${var}" VAR)
  1561. get_property(is_set TARGET ${name} PROPERTY _EP_${VAR} SET)
  1562. if(NOT is_set)
  1563. message(FATAL_ERROR "External project \"${name}\" has no ${var}")
  1564. endif()
  1565. get_property(${var} TARGET ${name} PROPERTY _EP_${VAR})
  1566. set(${var} "${${var}}" PARENT_SCOPE)
  1567. endforeach()
  1568. endfunction()
  1569. function(_ep_get_configure_command_id
  1570. name
  1571. cfg_cmd_id_var
  1572. )
  1573. get_target_property(cmd ${name} _EP_CONFIGURE_COMMAND)
  1574. if(cmd STREQUAL "")
  1575. # Explicit empty string means no configure step for this project
  1576. set(${cfg_cmd_id_var} "none" PARENT_SCOPE)
  1577. else()
  1578. if(NOT cmd)
  1579. # Default is "use cmake":
  1580. set(${cfg_cmd_id_var} "cmake" PARENT_SCOPE)
  1581. else()
  1582. # Otherwise we have to analyze the value:
  1583. if(cmd MATCHES "^[^;]*/configure")
  1584. set(${cfg_cmd_id_var} "configure" PARENT_SCOPE)
  1585. elseif(cmd MATCHES "^[^;]*/cmake" AND NOT cmd MATCHES ";-[PE];")
  1586. set(${cfg_cmd_id_var} "cmake" PARENT_SCOPE)
  1587. elseif(cmd MATCHES "config")
  1588. set(${cfg_cmd_id_var} "configure" PARENT_SCOPE)
  1589. else()
  1590. set(${cfg_cmd_id_var} "unknown:${cmd}" PARENT_SCOPE)
  1591. endif()
  1592. endif()
  1593. endif()
  1594. endfunction()
  1595. function(_ep_get_build_command
  1596. name
  1597. step
  1598. cmd_var
  1599. )
  1600. set(cmd "")
  1601. set(args)
  1602. _ep_get_configure_command_id(${name} cfg_cmd_id)
  1603. if(cfg_cmd_id STREQUAL "cmake")
  1604. # CMake project. Select build command based on generator.
  1605. get_target_property(cmake_generator ${name} _EP_CMAKE_GENERATOR)
  1606. if("${CMAKE_GENERATOR}" MATCHES "Make" AND
  1607. ("${cmake_generator}" MATCHES "Make" OR NOT cmake_generator))
  1608. # The project uses the same Makefile generator. Use recursive make.
  1609. set(cmd "$(MAKE)")
  1610. if(step STREQUAL "INSTALL")
  1611. set(args install)
  1612. endif()
  1613. if("x${step}x" STREQUAL "xTESTx")
  1614. set(args test)
  1615. endif()
  1616. else()
  1617. # Drive the project with "cmake --build".
  1618. get_target_property(cmake_command ${name} _EP_CMAKE_COMMAND)
  1619. if(cmake_command)
  1620. set(cmd "${cmake_command}")
  1621. else()
  1622. set(cmd "${CMAKE_COMMAND}")
  1623. endif()
  1624. set(args --build ".")
  1625. get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
  1626. if(_isMultiConfig)
  1627. if (CMAKE_CFG_INTDIR AND
  1628. NOT CMAKE_CFG_INTDIR STREQUAL "." AND
  1629. NOT CMAKE_CFG_INTDIR MATCHES "\\$")
  1630. # CMake 3.4 and below used the CMAKE_CFG_INTDIR placeholder value
  1631. # provided by multi-configuration generators. Some projects were
  1632. # taking advantage of that undocumented implementation detail to
  1633. # specify a specific configuration here. They should use
  1634. # BUILD_COMMAND to change the default command instead, but for
  1635. # compatibility honor the value.
  1636. set(config ${CMAKE_CFG_INTDIR})
  1637. message(AUTHOR_WARNING
  1638. "CMAKE_CFG_INTDIR should not be set by project code.\n"
  1639. "To get a non-default build command, use the BUILD_COMMAND option."
  1640. )
  1641. else()
  1642. set(config $<CONFIG>)
  1643. endif()
  1644. list(APPEND args --config ${config})
  1645. endif()
  1646. if(step STREQUAL "INSTALL")
  1647. list(APPEND args --target install)
  1648. endif()
  1649. # But for "TEST" drive the project with corresponding "ctest".
  1650. if("x${step}x" STREQUAL "xTESTx")
  1651. string(REGEX REPLACE "^(.*/)cmake([^/]*)$" "\\1ctest\\2" cmd "${cmd}")
  1652. set(args "")
  1653. if(_isMultiConfig)
  1654. list(APPEND args -C ${config})
  1655. endif()
  1656. endif()
  1657. endif()
  1658. else()
  1659. # Non-CMake project. Guess "make" and "make install" and "make test".
  1660. if("${CMAKE_GENERATOR}" MATCHES "Makefiles")
  1661. # Try to get the parallel arguments
  1662. set(cmd "$(MAKE)")
  1663. else()
  1664. set(cmd "make")
  1665. endif()
  1666. if(step STREQUAL "INSTALL")
  1667. set(args install)
  1668. endif()
  1669. if("x${step}x" STREQUAL "xTESTx")
  1670. set(args test)
  1671. endif()
  1672. endif()
  1673. # Use user-specified arguments instead of default arguments, if any.
  1674. get_property(have_args TARGET ${name} PROPERTY _EP_${step}_ARGS SET)
  1675. if(have_args)
  1676. get_target_property(args ${name} _EP_${step}_ARGS)
  1677. endif()
  1678. if(NOT "${args}" STREQUAL "")
  1679. # args could have empty items, so we must quote it to prevent them
  1680. # from being silently removed
  1681. list(APPEND cmd "${args}")
  1682. endif()
  1683. set(${cmd_var} "${cmd}" PARENT_SCOPE)
  1684. endfunction()
  1685. function(_ep_write_log_script
  1686. name
  1687. step
  1688. cmd_var
  1689. )
  1690. ExternalProject_Get_Property(${name} log_dir)
  1691. ExternalProject_Get_Property(${name} stamp_dir)
  1692. set(command "${${cmd_var}}")
  1693. set(make "")
  1694. set(code_cygpath_make "")
  1695. if(command MATCHES "^\\$\\(MAKE\\)")
  1696. # GNU make recognizes the string "$(MAKE)" as recursive make, so
  1697. # ensure that it appears directly in the makefile.
  1698. string(REGEX REPLACE "^\\$\\(MAKE\\)" "\${make}" command "${command}")
  1699. set(make "-Dmake=$(MAKE)")
  1700. if(WIN32 AND NOT CYGWIN)
  1701. set(code_cygpath_make "
  1702. if(\${make} MATCHES \"^/\")
  1703. execute_process(
  1704. COMMAND cygpath -w \${make}
  1705. OUTPUT_VARIABLE cygpath_make
  1706. ERROR_VARIABLE cygpath_make
  1707. RESULT_VARIABLE cygpath_error
  1708. OUTPUT_STRIP_TRAILING_WHITESPACE
  1709. )
  1710. if(NOT cygpath_error)
  1711. set(make \${cygpath_make})
  1712. endif()
  1713. endif()
  1714. ")
  1715. endif()
  1716. endif()
  1717. set(config "")
  1718. if("${CMAKE_CFG_INTDIR}" MATCHES "^\\$")
  1719. string(REPLACE "${CMAKE_CFG_INTDIR}" "\${config}" command "${command}")
  1720. set(config "-Dconfig=${CMAKE_CFG_INTDIR}")
  1721. endif()
  1722. # Wrap multiple 'COMMAND' lines up into a second-level wrapper
  1723. # script so all output can be sent to one log file.
  1724. if(command MATCHES "(^|;)COMMAND;")
  1725. set(code_execute_process "
  1726. ${code_cygpath_make}
  1727. execute_process(COMMAND \${command} RESULT_VARIABLE result)
  1728. if(result)
  1729. set(msg \"Command failed (\${result}):\\n\")
  1730. foreach(arg IN LISTS command)
  1731. set(msg \"\${msg} '\${arg}'\")
  1732. endforeach()
  1733. message(FATAL_ERROR \"\${msg}\")
  1734. endif()
  1735. ")
  1736. set(code "")
  1737. set(cmd "")
  1738. set(sep "")
  1739. foreach(arg IN LISTS command)
  1740. if("x${arg}" STREQUAL "xCOMMAND")
  1741. if(NOT "x${cmd}" STREQUAL "x")
  1742. string(APPEND code "set(command \"${cmd}\")${code_execute_process}")
  1743. endif()
  1744. set(cmd "")
  1745. set(sep "")
  1746. else()
  1747. string(APPEND cmd "${sep}${arg}")
  1748. set(sep ";")
  1749. endif()
  1750. endforeach()
  1751. string(APPEND code "set(command \"${cmd}\")${code_execute_process}")
  1752. file(GENERATE
  1753. OUTPUT "${stamp_dir}/${name}-${step}-$<CONFIG>-impl.cmake"
  1754. CONTENT "${code}"
  1755. )
  1756. set(command
  1757. ${CMAKE_COMMAND}
  1758. "-Dmake=\${make}"
  1759. "-Dconfig=\${config}"
  1760. -P ${stamp_dir}/${name}-${step}-$<CONFIG>-impl.cmake
  1761. )
  1762. endif()
  1763. # Wrap the command in a script to log output to files.
  1764. set(script ${stamp_dir}/${name}-${step}-$<CONFIG>.cmake)
  1765. set(logbase ${log_dir}/${name}-${step})
  1766. get_property(log_merged
  1767. TARGET ${name}
  1768. PROPERTY _EP_LOG_MERGED_STDOUTERR
  1769. )
  1770. get_property(log_output_on_failure
  1771. TARGET ${name}
  1772. PROPERTY _EP_LOG_OUTPUT_ON_FAILURE
  1773. )
  1774. if (log_merged)
  1775. set(stdout_log "${logbase}.log")
  1776. set(stderr_log "${logbase}.log")
  1777. else()
  1778. set(stdout_log "${logbase}-out.log")
  1779. set(stderr_log "${logbase}-err.log")
  1780. endif()
  1781. set(code "
  1782. cmake_minimum_required(VERSION 3.15)
  1783. ${code_cygpath_make}
  1784. set(command \"${command}\")
  1785. set(log_merged \"${log_merged}\")
  1786. set(log_output_on_failure \"${log_output_on_failure}\")
  1787. set(stdout_log \"${stdout_log}\")
  1788. set(stderr_log \"${stderr_log}\")
  1789. execute_process(
  1790. COMMAND \${command}
  1791. RESULT_VARIABLE result
  1792. OUTPUT_FILE \"\${stdout_log}\"
  1793. ERROR_FILE \"\${stderr_log}\"
  1794. )
  1795. macro(read_up_to_max_size log_file output_var)
  1796. file(SIZE \${log_file} determined_size)
  1797. set(max_size 10240)
  1798. if (determined_size GREATER max_size)
  1799. math(EXPR seek_position \"\${determined_size} - \${max_size}\")
  1800. file(READ \${log_file} \${output_var} OFFSET \${seek_position})
  1801. set(\${output_var} \"...skipping to end...\\n\${\${output_var}}\")
  1802. else()
  1803. file(READ \${log_file} \${output_var})
  1804. endif()
  1805. endmacro()
  1806. if(result)
  1807. set(msg \"Command failed: \${result}\\n\")
  1808. foreach(arg IN LISTS command)
  1809. set(msg \"\${msg} '\${arg}'\")
  1810. endforeach()
  1811. if (\${log_merged})
  1812. set(msg \"\${msg}\\nSee also\\n \${stderr_log}\")
  1813. else()
  1814. set(msg \"\${msg}\\nSee also\\n ${logbase}-*.log\")
  1815. endif()
  1816. if (\${log_output_on_failure})
  1817. message(SEND_ERROR \"\${msg}\")
  1818. if (\${log_merged})
  1819. read_up_to_max_size(\"\${stderr_log}\" error_log_contents)
  1820. message(STATUS \"Log output is:\\n\${error_log_contents}\")
  1821. else()
  1822. read_up_to_max_size(\"\${stdout_log}\" out_log_contents)
  1823. read_up_to_max_size(\"\${stderr_log}\" err_log_contents)
  1824. message(STATUS \"stdout output is:\\n\${out_log_contents}\")
  1825. message(STATUS \"stderr output is:\\n\${err_log_contents}\")
  1826. endif()
  1827. message(FATAL_ERROR \"Stopping after outputting logs.\")
  1828. else()
  1829. message(FATAL_ERROR \"\${msg}\")
  1830. endif()
  1831. else()
  1832. if(NOT \"${CMAKE_GENERATOR}\" MATCHES \"Ninja\")
  1833. set(msg \"${name} ${step} command succeeded. See also ${logbase}-*.log\")
  1834. message(STATUS \"\${msg}\")
  1835. endif()
  1836. endif()
  1837. ")
  1838. file(GENERATE OUTPUT "${script}" CONTENT "${code}")
  1839. set(command ${CMAKE_COMMAND} ${make} ${config} -P ${script})
  1840. set(${cmd_var} "${command}" PARENT_SCOPE)
  1841. endfunction()
  1842. # On multi-config generators, provide a placeholder for a per-config subdir.
  1843. # On single-config generators, this is empty.
  1844. function(_ep_get_configuration_subdir_genex suffix_var)
  1845. set(suffix "")
  1846. get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
  1847. if(_isMultiConfig)
  1848. set(suffix "/$<CONFIG>")
  1849. endif()
  1850. set(${suffix_var} "${suffix}" PARENT_SCOPE)
  1851. endfunction()
  1852. function(_ep_get_step_stampfile
  1853. name
  1854. step
  1855. stampfile_var
  1856. )
  1857. ExternalProject_Get_Property(${name} stamp_dir)
  1858. _ep_get_configuration_subdir_genex(cfgdir)
  1859. set(stampfile "${stamp_dir}${cfgdir}/${name}-${step}")
  1860. set(${stampfile_var} "${stampfile}" PARENT_SCOPE)
  1861. endfunction()
  1862. function(_ep_get_complete_stampfile
  1863. name
  1864. stampfile_var
  1865. )
  1866. set(cmf_dir ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles)
  1867. _ep_get_configuration_subdir_genex(cfgdir)
  1868. set(stampfile "${cmf_dir}${cfgdir}/${name}-complete")
  1869. set(${stampfile_var} ${stampfile} PARENT_SCOPE)
  1870. endfunction()
  1871. function(_ep_step_add_target
  1872. name
  1873. step
  1874. no_deps
  1875. )
  1876. if(TARGET ${name}-${step})
  1877. return()
  1878. endif()
  1879. get_property(cmp0114 TARGET ${name} PROPERTY _EP_CMP0114)
  1880. _ep_get_step_stampfile(${name} ${step} stamp_file)
  1881. cmake_policy(PUSH)
  1882. if(cmp0114 STREQUAL "NEW")
  1883. # To implement CMP0114 NEW behavior with Makefile generators,
  1884. # we need CMP0113 NEW behavior.
  1885. cmake_policy(SET CMP0113 NEW)
  1886. endif()
  1887. add_custom_target(${name}-${step} DEPENDS ${stamp_file})
  1888. cmake_policy(POP)
  1889. set_target_properties(${name}-${step} PROPERTIES
  1890. _EP_IS_EXTERNAL_PROJECT_STEP 1
  1891. LABELS "${name}"
  1892. FOLDER "ExternalProjectTargets/${name}"
  1893. )
  1894. if(cmp0114 STREQUAL "NEW")
  1895. # Add target-level dependencies for the step.
  1896. get_property(exclude_from_main
  1897. TARGET ${name}
  1898. PROPERTY _EP_${step}_EXCLUDE_FROM_MAIN
  1899. )
  1900. if(NOT exclude_from_main)
  1901. add_dependencies(${name} ${name}-${step})
  1902. endif()
  1903. _ep_step_add_target_dependencies(${name} ${step} ${step})
  1904. _ep_step_add_target_dependents(${name} ${step} ${step})
  1905. get_property(independent TARGET ${name} PROPERTY _EP_${step}_INDEPENDENT)
  1906. else()
  1907. if(no_deps AND "${step}" MATCHES "^(configure|build|install|test)$")
  1908. message(AUTHOR_WARNING
  1909. "Using NO_DEPENDS for \"${step}\" step might break parallel builds"
  1910. )
  1911. endif()
  1912. set(independent ${no_deps})
  1913. endif()
  1914. # Depend on other external projects (target-level).
  1915. if(NOT independent)
  1916. get_property(deps TARGET ${name} PROPERTY _EP_DEPENDS)
  1917. foreach(arg IN LISTS deps)
  1918. add_dependencies(${name}-${step} ${arg})
  1919. endforeach()
  1920. endif()
  1921. endfunction()
  1922. function(_ep_step_add_target_dependencies
  1923. name
  1924. step
  1925. node
  1926. )
  1927. get_property(dependees
  1928. TARGET ${name}
  1929. PROPERTY _EP_${node}_INTERNAL_DEPENDEES
  1930. )
  1931. list(REMOVE_DUPLICATES dependees)
  1932. foreach(dependee IN LISTS dependees)
  1933. get_property(exclude_from_main
  1934. TARGET ${name}
  1935. PROPERTY _EP_${step}_EXCLUDE_FROM_MAIN
  1936. )
  1937. get_property(dependee_dependers
  1938. TARGET ${name}
  1939. PROPERTY _EP_${dependee}_INTERNAL_DEPENDERS
  1940. )
  1941. if(exclude_from_main OR dependee_dependers MATCHES ";")
  1942. # The step on which our step target depends itself has
  1943. # dependents in multiple targes. It needs a step target too
  1944. # so that there is a unique place for its custom command.
  1945. _ep_step_add_target("${name}" "${dependee}" "FALSE")
  1946. endif()
  1947. if(TARGET ${name}-${dependee})
  1948. add_dependencies(${name}-${step} ${name}-${dependee})
  1949. else()
  1950. _ep_step_add_target_dependencies(${name} ${step} ${dependee})
  1951. endif()
  1952. endforeach()
  1953. endfunction()
  1954. function(_ep_step_add_target_dependents
  1955. name
  1956. step
  1957. node
  1958. )
  1959. get_property(dependers
  1960. TARGET ${name}
  1961. PROPERTY _EP_${node}_INTERNAL_DEPENDERS
  1962. )
  1963. list(REMOVE_DUPLICATES dependers)
  1964. foreach(depender IN LISTS dependers)
  1965. if(TARGET ${name}-${depender})
  1966. add_dependencies(${name}-${depender} ${name}-${step})
  1967. else()
  1968. _ep_step_add_target_dependents(${name} ${step} ${depender})
  1969. endif()
  1970. endforeach()
  1971. endfunction()
  1972. function(ExternalProject_Add_StepTargets name)
  1973. get_property(cmp0114 TARGET ${name} PROPERTY _EP_CMP0114)
  1974. set(steps ${ARGN})
  1975. if(ARGC GREATER 1 AND "${ARGV1}" STREQUAL "NO_DEPENDS")
  1976. set(no_deps 1)
  1977. list(REMOVE_AT steps 0)
  1978. else()
  1979. set(no_deps 0)
  1980. endif()
  1981. if(cmp0114 STREQUAL "NEW")
  1982. if(no_deps)
  1983. message(FATAL_ERROR
  1984. "The 'NO_DEPENDS' option is no longer allowed. "
  1985. "It has been superseded by the per-step 'INDEPENDENT' option. "
  1986. "See policy CMP0114."
  1987. )
  1988. endif()
  1989. elseif(cmp0114 STREQUAL "")
  1990. cmake_policy(GET_WARNING CMP0114 _cmp0114_warning)
  1991. string(APPEND _cmp0114_warning "\n"
  1992. "ExternalProject target '${name}' would depend on the targets for "
  1993. "step(s) '${steps}' under policy CMP0114, but this is being left out "
  1994. "for compatibility since the policy is not set."
  1995. )
  1996. if(no_deps)
  1997. string(APPEND _cmp0114_warning " "
  1998. "Also, the NO_DEPENDS option is deprecated in favor of policy CMP0114."
  1999. )
  2000. endif()
  2001. message(AUTHOR_WARNING "${_cmp0114_warning}")
  2002. endif()
  2003. foreach(step ${steps})
  2004. _ep_step_add_target("${name}" "${step}" "${no_deps}")
  2005. endforeach()
  2006. endfunction()
  2007. function(ExternalProject_Add_Step name step)
  2008. get_property(cmp0114 TARGET ${name} PROPERTY _EP_CMP0114)
  2009. _ep_get_complete_stampfile(${name} complete_stamp_file)
  2010. _ep_get_step_stampfile(${name} ${step} stamp_file)
  2011. set(keywords
  2012. COMMAND
  2013. COMMENT
  2014. DEPENDEES
  2015. DEPENDERS
  2016. DEPENDS
  2017. INDEPENDENT
  2018. BYPRODUCTS
  2019. ALWAYS
  2020. JOB_SERVER_AWARE
  2021. EXCLUDE_FROM_MAIN
  2022. WORKING_DIRECTORY
  2023. LOG
  2024. USES_TERMINAL
  2025. )
  2026. _ep_parse_arguments(
  2027. ExternalProject_Add_Step
  2028. "${keywords}"
  2029. ${name}
  2030. _EP_${step}_
  2031. "${ARGN}"
  2032. )
  2033. get_property(independent
  2034. TARGET ${name}
  2035. PROPERTY _EP_${step}_INDEPENDENT
  2036. )
  2037. if(independent STREQUAL "")
  2038. set(independent FALSE)
  2039. set_property(TARGET ${name} PROPERTY
  2040. _EP_${step}_INDEPENDENT "${independent}"
  2041. )
  2042. endif()
  2043. get_property(exclude_from_main
  2044. TARGET ${name}
  2045. PROPERTY _EP_${step}_EXCLUDE_FROM_MAIN
  2046. )
  2047. if(NOT exclude_from_main)
  2048. add_custom_command(APPEND
  2049. OUTPUT ${complete_stamp_file}
  2050. DEPENDS ${stamp_file}
  2051. )
  2052. endif()
  2053. # Steps depending on this step.
  2054. get_property(dependers TARGET ${name} PROPERTY _EP_${step}_DEPENDERS)
  2055. set_property(TARGET ${name} APPEND PROPERTY
  2056. _EP_${step}_INTERNAL_DEPENDERS ${dependers}
  2057. )
  2058. foreach(depender IN LISTS dependers)
  2059. set_property(TARGET ${name} APPEND PROPERTY
  2060. _EP_${depender}_INTERNAL_DEPENDEES ${step}
  2061. )
  2062. _ep_get_step_stampfile(${name} ${depender} depender_stamp_file)
  2063. add_custom_command(APPEND
  2064. OUTPUT ${depender_stamp_file}
  2065. DEPENDS ${stamp_file}
  2066. )
  2067. if(cmp0114 STREQUAL "NEW" AND NOT independent)
  2068. get_property(dep_independent
  2069. TARGET ${name}
  2070. PROPERTY _EP_${depender}_INDEPENDENT
  2071. )
  2072. if(dep_independent)
  2073. message(FATAL_ERROR
  2074. "ExternalProject '${name}' step '${depender}' is marked INDEPENDENT "
  2075. "but depends on step '${step}' that is not marked INDEPENDENT."
  2076. )
  2077. endif()
  2078. endif()
  2079. endforeach()
  2080. # Dependencies on files.
  2081. get_property(depends TARGET ${name} PROPERTY _EP_${step}_DEPENDS)
  2082. # Byproducts of the step.
  2083. get_property(byproducts TARGET ${name} PROPERTY _EP_${step}_BYPRODUCTS)
  2084. # Dependencies on steps.
  2085. get_property(dependees TARGET ${name} PROPERTY _EP_${step}_DEPENDEES)
  2086. set_property(TARGET ${name} APPEND PROPERTY
  2087. _EP_${step}_INTERNAL_DEPENDEES ${dependees}
  2088. )
  2089. foreach(dependee IN LISTS dependees)
  2090. set_property(TARGET ${name} APPEND PROPERTY
  2091. _EP_${dependee}_INTERNAL_DEPENDERS ${step}
  2092. )
  2093. _ep_get_step_stampfile(${name} ${dependee} dependee_stamp_file)
  2094. list(APPEND depends ${dependee_stamp_file})
  2095. if(cmp0114 STREQUAL "NEW" AND independent)
  2096. get_property(dep_independent
  2097. TARGET ${name}
  2098. PROPERTY _EP_${dependee}_INDEPENDENT
  2099. )
  2100. if(NOT dep_independent)
  2101. message(FATAL_ERROR
  2102. "ExternalProject '${name}' step '${step}' is marked INDEPENDENT "
  2103. "but depends on step '${dependee}' that is not marked INDEPENDENT."
  2104. )
  2105. endif()
  2106. endif()
  2107. endforeach()
  2108. # The command to run.
  2109. get_property(command TARGET ${name} PROPERTY _EP_${step}_COMMAND)
  2110. if(command)
  2111. set(comment "Performing ${step} step for '${name}'")
  2112. else()
  2113. set(comment "No ${step} step for '${name}'")
  2114. endif()
  2115. get_property(work_dir
  2116. TARGET ${name}
  2117. PROPERTY _EP_${step}_WORKING_DIRECTORY
  2118. )
  2119. # Replace list separators.
  2120. get_property(sep
  2121. TARGET ${name}
  2122. PROPERTY _EP_LIST_SEPARATOR
  2123. )
  2124. if(sep AND command)
  2125. string(REPLACE "${sep}" "\\;" command "${command}")
  2126. endif()
  2127. # Replace location tags.
  2128. _ep_replace_location_tags(
  2129. ${name}
  2130. comment
  2131. command
  2132. work_dir
  2133. byproducts
  2134. )
  2135. # Custom comment?
  2136. get_property(comment_set
  2137. TARGET ${name}
  2138. PROPERTY _EP_${step}_COMMENT
  2139. SET
  2140. )
  2141. if(comment_set)
  2142. get_property(comment
  2143. TARGET ${name}
  2144. PROPERTY _EP_${step}_COMMENT
  2145. )
  2146. endif()
  2147. # Uses terminal?
  2148. get_property(uses_terminal
  2149. TARGET ${name}
  2150. PROPERTY _EP_${step}_USES_TERMINAL
  2151. )
  2152. if(uses_terminal)
  2153. set(uses_terminal USES_TERMINAL)
  2154. else()
  2155. set(uses_terminal "")
  2156. endif()
  2157. # Run every time?
  2158. get_property(always
  2159. TARGET ${name}
  2160. PROPERTY _EP_${step}_ALWAYS
  2161. )
  2162. if(always)
  2163. set(maybe_COMMAND_touch "")
  2164. # Mark stamp files for all configs as SYMBOLIC since we do not create them.
  2165. # Remove any existing stamp in case the option changed in an existing tree.
  2166. get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
  2167. if(_isMultiConfig)
  2168. _ep_get_configuration_subdir_genex(cfgdir)
  2169. foreach(cfg ${CMAKE_CONFIGURATION_TYPES})
  2170. string(REPLACE "${cfgdir}" "/${cfg}"
  2171. stamp_file_config "${stamp_file}"
  2172. )
  2173. set_property(SOURCE ${stamp_file_config} PROPERTY SYMBOLIC 1)
  2174. file(REMOVE ${stamp_file_config})
  2175. endforeach()
  2176. if(CMAKE_GENERATOR STREQUAL "Xcode")
  2177. # See Xcode case in _ep_get_configuration_subdir_genex.
  2178. set_property(SOURCE ${stamp_file} PROPERTY SYMBOLIC 1)
  2179. endif()
  2180. else()
  2181. set_property(SOURCE ${stamp_file} PROPERTY SYMBOLIC 1)
  2182. file(REMOVE ${stamp_file})
  2183. endif()
  2184. else()
  2185. set(maybe_COMMAND_touch "COMMAND \${CMAKE_COMMAND} -E touch \${stamp_file}")
  2186. endif()
  2187. get_property(job_server_aware
  2188. TARGET ${name}
  2189. PROPERTY _EP_${step}_JOB_SERVER_AWARE
  2190. )
  2191. if(job_server_aware)
  2192. set(maybe_JOB_SERVER_AWARE "JOB_SERVER_AWARE 1")
  2193. else()
  2194. set(maybe_JOB_SERVER_AWARE "")
  2195. endif()
  2196. # Wrap with log script?
  2197. get_property(log TARGET ${name} PROPERTY _EP_${step}_LOG)
  2198. if(command AND log)
  2199. _ep_write_log_script(${name} ${step} command)
  2200. endif()
  2201. if("${command}" STREQUAL "")
  2202. # Some generators (i.e. Xcode) will not generate a file level target
  2203. # if no command is set, and therefore the dependencies on this
  2204. # target will be broken.
  2205. # The empty command is replaced by an echo command here in order to
  2206. # avoid this issue.
  2207. set(command ${CMAKE_COMMAND} -E echo_append)
  2208. endif()
  2209. set(__cmdQuoted)
  2210. foreach(__item IN LISTS command)
  2211. string(APPEND __cmdQuoted " [==[${__item}]==]")
  2212. endforeach()
  2213. cmake_language(EVAL CODE "
  2214. add_custom_command(
  2215. OUTPUT \${stamp_file}
  2216. BYPRODUCTS \${byproducts}
  2217. COMMENT \${comment}
  2218. COMMAND ${__cmdQuoted}
  2219. ${maybe_COMMAND_touch}
  2220. ${maybe_JOB_SERVER_AWARE}
  2221. DEPENDS \${depends}
  2222. WORKING_DIRECTORY \${work_dir}
  2223. VERBATIM
  2224. ${uses_terminal}
  2225. )"
  2226. )
  2227. set_property(TARGET ${name} APPEND PROPERTY _EP_STEPS ${step})
  2228. # Add custom "step target"?
  2229. get_property(step_targets
  2230. TARGET ${name}
  2231. PROPERTY _EP_STEP_TARGETS
  2232. )
  2233. if(NOT step_targets)
  2234. get_property(step_targets
  2235. DIRECTORY
  2236. PROPERTY EP_STEP_TARGETS
  2237. )
  2238. endif()
  2239. foreach(st ${step_targets})
  2240. if("${st}" STREQUAL "${step}")
  2241. _ep_step_add_target("${name}" "${step}" "FALSE")
  2242. break()
  2243. endif()
  2244. endforeach()
  2245. get_property(independent_step_targets
  2246. TARGET ${name} PROPERTY
  2247. _EP_INDEPENDENT_STEP_TARGETS
  2248. )
  2249. if(NOT independent_step_targets)
  2250. get_property(independent_step_targets
  2251. DIRECTORY
  2252. PROPERTY EP_INDEPENDENT_STEP_TARGETS
  2253. )
  2254. endif()
  2255. if(cmp0114 STREQUAL "NEW")
  2256. if(independent_step_targets)
  2257. message(FATAL_ERROR
  2258. "ExternalProject '${name}' option 'INDEPENDENT_STEP_TARGETS' is set to"
  2259. "\n ${independent_step_targets}\n"
  2260. "but the option is no longer allowed. "
  2261. "It has been superseded by the per-step 'INDEPENDENT' option. "
  2262. "See policy CMP0114."
  2263. )
  2264. endif()
  2265. else()
  2266. if(independent_step_targets AND cmp0114 STREQUAL "")
  2267. get_property(warned
  2268. TARGET ${name}
  2269. PROPERTY _EP_CMP0114_WARNED_INDEPENDENT_STEP_TARGETS
  2270. )
  2271. if(NOT warned)
  2272. set_property(TARGET ${name} PROPERTY
  2273. _EP_CMP0114_WARNED_INDEPENDENT_STEP_TARGETS 1
  2274. )
  2275. cmake_policy(GET_WARNING CMP0114 _cmp0114_warning)
  2276. string(APPEND _cmp0114_warning
  2277. "\n"
  2278. "ExternalProject '${name}' option INDEPENDENT_STEP_TARGETS is set to"
  2279. "\n ${independent_step_targets}\n"
  2280. "but the option is deprecated in favor of policy CMP0114."
  2281. )
  2282. message(AUTHOR_WARNING "${_cmp0114_warning}")
  2283. endif()
  2284. endif()
  2285. foreach(st ${independent_step_targets})
  2286. if("${st}" STREQUAL "${step}")
  2287. _ep_step_add_target("${name}" "${step}" "TRUE")
  2288. break()
  2289. endif()
  2290. endforeach()
  2291. endif()
  2292. endfunction()
  2293. function(ExternalProject_Add_StepDependencies name step)
  2294. set(dependencies ${ARGN})
  2295. # Sanity checks on "name" and "step".
  2296. if(NOT TARGET ${name})
  2297. message(FATAL_ERROR
  2298. "Cannot find target \"${name}\". Perhaps it has not yet been created "
  2299. "using ExternalProject_Add."
  2300. )
  2301. endif()
  2302. get_property(type TARGET ${name} PROPERTY TYPE)
  2303. if(NOT type STREQUAL "UTILITY")
  2304. message(FATAL_ERROR
  2305. "Target \"${name}\" was not generated by ExternalProject_Add."
  2306. )
  2307. endif()
  2308. get_property(is_ep TARGET ${name} PROPERTY _EP_IS_EXTERNAL_PROJECT)
  2309. if(NOT is_ep)
  2310. message(FATAL_ERROR
  2311. "Target \"${name}\" was not generated by ExternalProject_Add."
  2312. )
  2313. endif()
  2314. get_property(steps TARGET ${name} PROPERTY _EP_STEPS)
  2315. list(FIND steps ${step} is_step)
  2316. if(is_step LESS 0)
  2317. message(FATAL_ERROR
  2318. "External project \"${name}\" does not have a step \"${step}\"."
  2319. )
  2320. endif()
  2321. if(TARGET ${name}-${step})
  2322. get_property(type TARGET ${name}-${step} PROPERTY TYPE)
  2323. if(NOT type STREQUAL "UTILITY")
  2324. message(FATAL_ERROR
  2325. "Target \"${name}-${step}\" was not generated by "
  2326. "ExternalProject_Add_StepTargets."
  2327. )
  2328. endif()
  2329. get_property(is_ep_step
  2330. TARGET ${name}-${step}
  2331. PROPERTY _EP_IS_EXTERNAL_PROJECT_STEP
  2332. )
  2333. if(NOT is_ep_step)
  2334. message(FATAL_ERROR
  2335. "Target \"${name}-${step}\" was not generated by "
  2336. "ExternalProject_Add_StepTargets."
  2337. )
  2338. endif()
  2339. endif()
  2340. # Always add file-level dependency, but add target-level dependency
  2341. # only if the target exists for that step.
  2342. _ep_get_step_stampfile(${name} ${step} stamp_file)
  2343. foreach(dep ${dependencies})
  2344. add_custom_command(APPEND
  2345. OUTPUT ${stamp_file}
  2346. DEPENDS ${dep}
  2347. )
  2348. if(TARGET ${name}-${step})
  2349. foreach(dep ${dependencies})
  2350. add_dependencies(${name}-${step} ${dep})
  2351. endforeach()
  2352. endif()
  2353. endforeach()
  2354. endfunction()
  2355. function(_ep_add_mkdir_command name)
  2356. ExternalProject_Get_Property(${name} tmp_dir)
  2357. set(script_filename "${tmp_dir}/${name}-mkdirs.cmake")
  2358. _ep_get_configuration_subdir_genex(cfgdir)
  2359. ExternalProject_Add_Step(${name} mkdir
  2360. INDEPENDENT TRUE
  2361. COMMENT "Creating directories for '${name}'"
  2362. COMMAND ${CMAKE_COMMAND} -Dcfgdir=${cfgdir} -P ${script_filename}
  2363. )
  2364. endfunction()
  2365. function(_ep_is_dir_empty dir empty_var)
  2366. file(GLOB gr "${dir}/*")
  2367. if("${gr}" STREQUAL "")
  2368. set(${empty_var} 1 PARENT_SCOPE)
  2369. else()
  2370. set(${empty_var} 0 PARENT_SCOPE)
  2371. endif()
  2372. endfunction()
  2373. function(_ep_get_git_submodules_recurse git_submodules_recurse)
  2374. # Checks for GIT_SUBMODULES_RECURSE property. Default is ON, which sets
  2375. # git_submodules_recurse output variable to "--recursive". Otherwise, the
  2376. # output variable is set to an empty value "".
  2377. get_property(git_submodules_recurse_set
  2378. TARGET ${name}
  2379. PROPERTY _EP_GIT_SUBMODULES_RECURSE
  2380. SET
  2381. )
  2382. if(NOT git_submodules_recurse_set)
  2383. set(recurseFlag "--recursive")
  2384. else()
  2385. get_property(git_submodules_recurse_value
  2386. TARGET ${name}
  2387. PROPERTY _EP_GIT_SUBMODULES_RECURSE
  2388. )
  2389. if(git_submodules_recurse_value)
  2390. set(recurseFlag "--recursive")
  2391. else()
  2392. set(recurseFlag "")
  2393. endif()
  2394. endif()
  2395. set(${git_submodules_recurse} "${recurseFlag}" PARENT_SCOPE)
  2396. # The git submodule update '--recursive' flag requires git >= v1.6.5
  2397. if(recurseFlag AND GIT_VERSION_STRING VERSION_LESS 1.6.5)
  2398. message(FATAL_ERROR
  2399. "git version 1.6.5 or later required for --recursive flag with "
  2400. "'git submodule ...': GIT_VERSION_STRING='${GIT_VERSION_STRING}'"
  2401. )
  2402. endif()
  2403. endfunction()
  2404. function(_ep_add_download_command name)
  2405. ExternalProject_Get_Property(${name}
  2406. source_dir
  2407. stamp_dir
  2408. download_dir
  2409. tmp_dir
  2410. )
  2411. get_property(cmd_set TARGET ${name} PROPERTY _EP_DOWNLOAD_COMMAND SET)
  2412. get_property(cmd TARGET ${name} PROPERTY _EP_DOWNLOAD_COMMAND)
  2413. get_property(cvs_repository TARGET ${name} PROPERTY _EP_CVS_REPOSITORY)
  2414. get_property(svn_repository TARGET ${name} PROPERTY _EP_SVN_REPOSITORY)
  2415. get_property(git_repository TARGET ${name} PROPERTY _EP_GIT_REPOSITORY)
  2416. get_property(hg_repository TARGET ${name} PROPERTY _EP_HG_REPOSITORY )
  2417. get_property(url TARGET ${name} PROPERTY _EP_URL)
  2418. get_property(fname TARGET ${name} PROPERTY _EP_DOWNLOAD_NAME)
  2419. # TODO: Perhaps file:// should be copied to download dir before extraction.
  2420. string(REGEX REPLACE "file://" "" url "${url}")
  2421. set(depends)
  2422. set(comment)
  2423. set(work_dir)
  2424. set(extra_repo_info)
  2425. if(cmd_set)
  2426. set(work_dir ${download_dir})
  2427. set(method custom)
  2428. elseif(cvs_repository)
  2429. set(method cvs)
  2430. find_package(CVS QUIET)
  2431. if(NOT CVS_EXECUTABLE)
  2432. message(FATAL_ERROR "error: could not find cvs for checkout of ${name}")
  2433. endif()
  2434. get_target_property(cvs_module ${name} _EP_CVS_MODULE)
  2435. if(NOT cvs_module)
  2436. message(FATAL_ERROR "error: no CVS_MODULE")
  2437. endif()
  2438. get_property(cvs_tag TARGET ${name} PROPERTY _EP_CVS_TAG)
  2439. get_filename_component(src_name "${source_dir}" NAME)
  2440. get_filename_component(work_dir "${source_dir}" PATH)
  2441. set(comment "Performing download step (CVS checkout) for '${name}'")
  2442. set(cmd
  2443. ${CVS_EXECUTABLE}
  2444. -d ${cvs_repository}
  2445. -q
  2446. co ${cvs_tag}
  2447. -d ${src_name}
  2448. ${cvs_module}
  2449. )
  2450. elseif(svn_repository)
  2451. set(method svn)
  2452. find_package(Subversion QUIET)
  2453. if(NOT Subversion_SVN_EXECUTABLE)
  2454. message(FATAL_ERROR "error: could not find svn for checkout of ${name}")
  2455. endif()
  2456. get_property(svn_revision TARGET ${name} PROPERTY _EP_SVN_REVISION)
  2457. get_property(svn_username TARGET ${name} PROPERTY _EP_SVN_USERNAME)
  2458. get_property(svn_password TARGET ${name} PROPERTY _EP_SVN_PASSWORD)
  2459. get_property(svn_trust_cert TARGET ${name} PROPERTY _EP_SVN_TRUST_CERT)
  2460. get_property(uses_terminal
  2461. TARGET ${name}
  2462. PROPERTY _EP_USES_TERMINAL_DOWNLOAD
  2463. )
  2464. # The --trust-server-cert option requires --non-interactive
  2465. if(uses_terminal AND NOT svn_trust_cert)
  2466. set(svn_interactive_args "")
  2467. else()
  2468. set(svn_interactive_args "--non-interactive")
  2469. endif()
  2470. get_filename_component(src_name "${source_dir}" NAME)
  2471. get_filename_component(work_dir "${source_dir}" PATH)
  2472. set(comment "Performing download step (SVN checkout) for '${name}'")
  2473. set(svn_user_pw_args "")
  2474. if(DEFINED svn_username)
  2475. set(svn_user_pw_args ${svn_user_pw_args} "--username=${svn_username}")
  2476. endif()
  2477. if(DEFINED svn_password)
  2478. set(svn_user_pw_args ${svn_user_pw_args} "--password=${svn_password}")
  2479. endif()
  2480. if(svn_trust_cert)
  2481. set(svn_trust_cert_args --trust-server-cert)
  2482. endif()
  2483. set(cmd
  2484. ${Subversion_SVN_EXECUTABLE}
  2485. co
  2486. ${svn_repository}
  2487. ${svn_revision}
  2488. ${svn_interactive_args}
  2489. ${svn_trust_cert_args}
  2490. ${svn_user_pw_args}
  2491. ${src_name}
  2492. )
  2493. elseif(git_repository)
  2494. set(method git)
  2495. # FetchContent gives us these directly, so don't try to recompute them
  2496. if(NOT GIT_EXECUTABLE OR NOT GIT_VERSION_STRING)
  2497. unset(CMAKE_MODULE_PATH) # Use CMake builtin find module
  2498. find_package(Git QUIET)
  2499. if(NOT GIT_EXECUTABLE)
  2500. message(FATAL_ERROR "error: could not find git for clone of ${name}")
  2501. endif()
  2502. endif()
  2503. _ep_get_git_submodules_recurse(git_submodules_recurse)
  2504. get_property(git_tag TARGET ${name} PROPERTY _EP_GIT_TAG)
  2505. if(NOT git_tag)
  2506. set(git_tag "master")
  2507. endif()
  2508. set(git_init_submodules TRUE)
  2509. get_property(git_submodules_set
  2510. TARGET ${name}
  2511. PROPERTY _EP_GIT_SUBMODULES SET
  2512. )
  2513. if(git_submodules_set)
  2514. get_property(git_submodules TARGET ${name} PROPERTY _EP_GIT_SUBMODULES)
  2515. if(git_submodules STREQUAL "" AND _EP_CMP0097 STREQUAL "NEW")
  2516. set(git_init_submodules FALSE)
  2517. endif()
  2518. endif()
  2519. get_property(git_remote_name TARGET ${name} PROPERTY _EP_GIT_REMOTE_NAME)
  2520. if(NOT git_remote_name)
  2521. set(git_remote_name "origin")
  2522. endif()
  2523. get_property(tls_verify TARGET ${name} PROPERTY _EP_TLS_VERIFY)
  2524. if("x${tls_verify}" STREQUAL "x" AND DEFINED CMAKE_TLS_VERIFY)
  2525. set(tls_verify "${CMAKE_TLS_VERIFY}")
  2526. endif()
  2527. get_property(git_shallow TARGET ${name} PROPERTY _EP_GIT_SHALLOW)
  2528. get_property(git_progress TARGET ${name} PROPERTY _EP_GIT_PROGRESS)
  2529. get_property(git_config TARGET ${name} PROPERTY _EP_GIT_CONFIG)
  2530. # If git supports it, make checkouts quiet when checking out a git hash.
  2531. # This avoids the very noisy detached head message.
  2532. if(GIT_VERSION_STRING VERSION_GREATER_EQUAL 1.7.7)
  2533. list(PREPEND git_config advice.detachedHead=false)
  2534. endif()
  2535. # The command doesn't expose any details, so we need to record additional
  2536. # information in the RepositoryInfo.txt file. For the download step, only
  2537. # the things specifically affecting the clone operation should be recorded.
  2538. # If the repo changes, the clone script should be run again.
  2539. # But if only the tag changes, avoid running the clone script again.
  2540. # Let the 'always' running update step checkout the new tag.
  2541. #
  2542. set(extra_repo_info
  2543. "repository=${git_repository}
  2544. remote=${git_remote_name}
  2545. init_submodules=${git_init_submodules}
  2546. recurse_submodules=${git_submodules_recurse}
  2547. submodules=${git_submodules}
  2548. CMP0097=${_EP_CMP0097}
  2549. ")
  2550. get_filename_component(src_name "${source_dir}" NAME)
  2551. get_filename_component(work_dir "${source_dir}" PATH)
  2552. # Since git clone doesn't succeed if the non-empty source_dir exists,
  2553. # create a cmake script to invoke as download command.
  2554. # The script will delete the source directory and then call git clone.
  2555. #
  2556. _ep_write_gitclone_script(
  2557. ${tmp_dir}/${name}-gitclone.cmake
  2558. ${source_dir}
  2559. ${GIT_EXECUTABLE}
  2560. ${git_repository}
  2561. ${git_tag}
  2562. ${git_remote_name}
  2563. ${git_init_submodules}
  2564. "${git_submodules_recurse}"
  2565. "${git_submodules}"
  2566. "${git_shallow}"
  2567. "${git_progress}"
  2568. "${git_config}"
  2569. ${src_name}
  2570. ${work_dir}
  2571. ${stamp_dir}/${name}-gitinfo.txt
  2572. ${stamp_dir}/${name}-gitclone-lastrun.txt
  2573. "${tls_verify}"
  2574. )
  2575. set(comment "Performing download step (git clone) for '${name}'")
  2576. set(cmd ${CMAKE_COMMAND} -P ${tmp_dir}/${name}-gitclone.cmake)
  2577. elseif(hg_repository)
  2578. set(method hg)
  2579. find_package(Hg QUIET)
  2580. if(NOT HG_EXECUTABLE)
  2581. message(FATAL_ERROR "error: could not find hg for clone of ${name}")
  2582. endif()
  2583. get_property(hg_tag TARGET ${name} PROPERTY _EP_HG_TAG)
  2584. if(NOT hg_tag)
  2585. set(hg_tag "tip")
  2586. endif()
  2587. # The command doesn't expose any details, so we need to record additional
  2588. # information in the RepositoryInfo.txt file. For the download step, only
  2589. # the things specifically affecting the clone operation should be recorded.
  2590. # If the repo changes, the clone script should be run again.
  2591. # But if only the tag changes, avoid running the clone script again.
  2592. # Let the 'always' running update step checkout the new tag.
  2593. #
  2594. set(extra_repo_info "repository=${hg_repository}")
  2595. get_filename_component(src_name "${source_dir}" NAME)
  2596. get_filename_component(work_dir "${source_dir}" PATH)
  2597. # Since hg clone doesn't succeed if the non-empty source_dir exists,
  2598. # create a cmake script to invoke as download command.
  2599. # The script will delete the source directory and then call hg clone.
  2600. #
  2601. _ep_write_hgclone_script(
  2602. ${tmp_dir}/${name}-hgclone.cmake
  2603. ${source_dir}
  2604. ${HG_EXECUTABLE}
  2605. ${hg_repository}
  2606. ${hg_tag}
  2607. ${src_name}
  2608. ${work_dir}
  2609. ${stamp_dir}/${name}-hginfo.txt
  2610. ${stamp_dir}/${name}-hgclone-lastrun.txt
  2611. )
  2612. set(comment "Performing download step (hg clone) for '${name}'")
  2613. set(cmd ${CMAKE_COMMAND} -P ${tmp_dir}/${name}-hgclone.cmake)
  2614. elseif(url)
  2615. set(method url)
  2616. get_filename_component(work_dir "${source_dir}" PATH)
  2617. get_property(hash TARGET ${name} PROPERTY _EP_URL_HASH)
  2618. _ep_get_hash_regex(_ep_hash_regex)
  2619. if(hash AND NOT "${hash}" MATCHES "${_ep_hash_regex}")
  2620. _ep_get_hash_algos(_ep_hash_algos)
  2621. list(JOIN _ep_hash_algos "|" _ep_hash_algos)
  2622. message(FATAL_ERROR
  2623. "URL_HASH is set to\n"
  2624. " ${hash}\n"
  2625. "but must be ALGO=value where ALGO is\n"
  2626. " ${_ep_hash_algos}\n"
  2627. "and value is a hex string."
  2628. )
  2629. endif()
  2630. get_property(md5 TARGET ${name} PROPERTY _EP_URL_MD5)
  2631. if(md5 AND NOT "MD5=${md5}" MATCHES "${_ep_hash_regex}")
  2632. message(FATAL_ERROR
  2633. "URL_MD5 is set to\n"
  2634. " ${md5}\n"
  2635. "but must be a hex string."
  2636. )
  2637. endif()
  2638. if(md5 AND NOT hash)
  2639. set(hash "MD5=${md5}")
  2640. endif()
  2641. set(extra_repo_info
  2642. "url(s)=${url}
  2643. hash=${hash}
  2644. ")
  2645. list(LENGTH url url_list_length)
  2646. if(NOT "${url_list_length}" STREQUAL "1")
  2647. foreach(entry ${url})
  2648. if(NOT "${entry}" MATCHES "^[a-z]+://")
  2649. message(FATAL_ERROR
  2650. "At least one entry of URL is a path (invalid in a list)"
  2651. )
  2652. endif()
  2653. endforeach()
  2654. if("x${fname}" STREQUAL "x")
  2655. list(GET url 0 fname)
  2656. endif()
  2657. endif()
  2658. if(IS_DIRECTORY "${url}")
  2659. get_filename_component(abs_dir "${url}" ABSOLUTE)
  2660. set(comment "Performing download step (DIR copy) for '${name}'")
  2661. set(cmd
  2662. ${CMAKE_COMMAND} -E rm -rf ${source_dir}
  2663. COMMAND ${CMAKE_COMMAND} -E copy_directory ${abs_dir} ${source_dir}
  2664. )
  2665. else()
  2666. get_property(no_extract
  2667. TARGET "${name}"
  2668. PROPERTY _EP_DOWNLOAD_NO_EXTRACT
  2669. )
  2670. string(APPEND extra_repo_info "no_extract=${no_extract}\n")
  2671. if("${url}" MATCHES "^[a-z]+://")
  2672. # TODO: Should download and extraction be different steps?
  2673. if("x${fname}" STREQUAL "x")
  2674. set(fname "${url}")
  2675. endif()
  2676. set(ext_regex [[7z|tar|tar\.bz2|tar\.gz|tar\.xz|tbz2|tgz|txz|zip]])
  2677. if("${fname}" MATCHES "([^/\\?#]+(\\.|=)(${ext_regex}))([/?#].*)?$")
  2678. set(fname "${CMAKE_MATCH_1}")
  2679. elseif(no_extract)
  2680. get_filename_component(fname "${fname}" NAME)
  2681. else()
  2682. # Fall back to a default file name. The actual file name does not
  2683. # matter because it is used only internally and our extraction tool
  2684. # inspects the file content directly. If it turns out the wrong URL
  2685. # was given that will be revealed during the build which is an easier
  2686. # place for users to diagnose than an error here anyway.
  2687. set(fname "archive.tar")
  2688. endif()
  2689. string(REPLACE ";" "-" fname "${fname}")
  2690. set(file ${download_dir}/${fname})
  2691. get_property(timeout TARGET ${name} PROPERTY _EP_TIMEOUT)
  2692. get_property(inactivity_timeout
  2693. TARGET ${name}
  2694. PROPERTY _EP_INACTIVITY_TIMEOUT
  2695. )
  2696. get_property(no_progress
  2697. TARGET ${name}
  2698. PROPERTY _EP_DOWNLOAD_NO_PROGRESS
  2699. )
  2700. get_property(tls_verify TARGET ${name} PROPERTY _EP_TLS_VERIFY)
  2701. get_property(tls_cainfo TARGET ${name} PROPERTY _EP_TLS_CAINFO)
  2702. get_property(netrc TARGET ${name} PROPERTY _EP_NETRC)
  2703. get_property(netrc_file TARGET ${name} PROPERTY _EP_NETRC_FILE)
  2704. get_property(http_username TARGET ${name} PROPERTY _EP_HTTP_USERNAME)
  2705. get_property(http_password TARGET ${name} PROPERTY _EP_HTTP_PASSWORD)
  2706. get_property(http_headers TARGET ${name} PROPERTY _EP_HTTP_HEADER)
  2707. set(download_script "${stamp_dir}/download-${name}.cmake")
  2708. _ep_write_downloadfile_script(
  2709. "${download_script}"
  2710. "${url}"
  2711. "${file}"
  2712. "${timeout}"
  2713. "${inactivity_timeout}"
  2714. "${no_progress}"
  2715. "${hash}"
  2716. "${tls_verify}"
  2717. "${tls_cainfo}"
  2718. "${http_username}:${http_password}"
  2719. "${http_headers}"
  2720. "${netrc}"
  2721. "${netrc_file}"
  2722. )
  2723. set(cmd
  2724. ${CMAKE_COMMAND} -P "${download_script}"
  2725. COMMAND
  2726. )
  2727. if (no_extract)
  2728. set(steps "download and verify")
  2729. else ()
  2730. set(steps "download, verify and extract")
  2731. endif ()
  2732. set(comment "Performing download step (${steps}) for '${name}'")
  2733. # already verified by 'download_script'
  2734. file(WRITE "${stamp_dir}/verify-${name}.cmake" "")
  2735. # Rather than adding everything to the RepositoryInfo.txt file, it is
  2736. # more robust to just depend on the download script. That way, we will
  2737. # re-download if any aspect of the download changes.
  2738. list(APPEND depends "${download_script}")
  2739. else()
  2740. set(file "${url}")
  2741. if (no_extract)
  2742. set(steps "verify")
  2743. else ()
  2744. set(steps "verify and extract")
  2745. endif ()
  2746. set(comment "Performing download step (${steps}) for '${name}'")
  2747. _ep_write_verifyfile_script(
  2748. "${stamp_dir}/verify-${name}.cmake"
  2749. "${file}"
  2750. "${hash}"
  2751. )
  2752. endif()
  2753. list(APPEND cmd ${CMAKE_COMMAND} -P ${stamp_dir}/verify-${name}.cmake)
  2754. get_target_property(extract_timestamp ${name}
  2755. _EP_DOWNLOAD_EXTRACT_TIMESTAMP
  2756. )
  2757. if(no_extract)
  2758. if(NOT extract_timestamp STREQUAL "extract_timestamp-NOTFOUND")
  2759. message(FATAL_ERROR
  2760. "Cannot specify DOWNLOAD_EXTRACT_TIMESTAMP when using "
  2761. "DOWNLOAD_NO_EXTRACT TRUE"
  2762. )
  2763. endif()
  2764. set_property(TARGET ${name} PROPERTY _EP_DOWNLOADED_FILE ${file})
  2765. else()
  2766. if(extract_timestamp STREQUAL "extract_timestamp-NOTFOUND")
  2767. # Default depends on policy CMP0135
  2768. if(_EP_CMP0135 STREQUAL "")
  2769. message(AUTHOR_WARNING
  2770. "The DOWNLOAD_EXTRACT_TIMESTAMP option was not given and policy "
  2771. "CMP0135 is not set. The policy's OLD behavior will be used. "
  2772. "When using a URL download, the timestamps of extracted files "
  2773. "should preferably be that of the time of extraction, otherwise "
  2774. "code that depends on the extracted contents might not be "
  2775. "rebuilt if the URL changes. The OLD behavior preserves the "
  2776. "timestamps from the archive instead, but this is usually not "
  2777. "what you want. Update your project to the NEW behavior or "
  2778. "specify the DOWNLOAD_EXTRACT_TIMESTAMP option with a value of "
  2779. "true to avoid this robustness issue."
  2780. )
  2781. set(extract_timestamp TRUE)
  2782. elseif(_EP_CMP0135 STREQUAL "NEW")
  2783. set(extract_timestamp FALSE)
  2784. else()
  2785. set(extract_timestamp TRUE)
  2786. endif()
  2787. endif()
  2788. if(extract_timestamp)
  2789. set(options "")
  2790. else()
  2791. set(options "--touch")
  2792. endif()
  2793. _ep_write_extractfile_script(
  2794. "${stamp_dir}/extract-${name}.cmake"
  2795. "${name}"
  2796. "${file}"
  2797. "${source_dir}"
  2798. "${options}"
  2799. )
  2800. list(APPEND cmd
  2801. COMMAND ${CMAKE_COMMAND} -P ${stamp_dir}/extract-${name}.cmake
  2802. )
  2803. endif ()
  2804. endif()
  2805. else()
  2806. set(method source_dir)
  2807. _ep_is_dir_empty("${source_dir}" empty)
  2808. if(${empty})
  2809. message(FATAL_ERROR
  2810. "No download info given for '${name}' and its source directory:\n"
  2811. " ${source_dir}\n"
  2812. "is not an existing non-empty directory. Please specify one of:\n"
  2813. " * SOURCE_DIR with an existing non-empty directory\n"
  2814. " * DOWNLOAD_COMMAND\n"
  2815. " * URL\n"
  2816. " * GIT_REPOSITORY\n"
  2817. " * SVN_REPOSITORY\n"
  2818. " * HG_REPOSITORY\n"
  2819. " * CVS_REPOSITORY and CVS_MODULE"
  2820. )
  2821. endif()
  2822. endif()
  2823. # We use configure_file() to write the repo_info_file so that the file's
  2824. # timestamp is not updated if we don't change the contents
  2825. set(repo_info_file ${stamp_dir}/${name}-${method}info.txt)
  2826. list(APPEND depends ${repo_info_file})
  2827. configure_file(
  2828. "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/ExternalProject/RepositoryInfo.txt.in"
  2829. "${repo_info_file}"
  2830. @ONLY
  2831. )
  2832. get_property(log
  2833. TARGET ${name}
  2834. PROPERTY _EP_LOG_DOWNLOAD
  2835. )
  2836. if(log)
  2837. set(log LOG 1)
  2838. else()
  2839. set(log "")
  2840. endif()
  2841. get_property(uses_terminal
  2842. TARGET ${name}
  2843. PROPERTY _EP_USES_TERMINAL_DOWNLOAD
  2844. )
  2845. if(uses_terminal)
  2846. set(uses_terminal USES_TERMINAL 1)
  2847. else()
  2848. set(uses_terminal "")
  2849. endif()
  2850. set(__cmdQuoted)
  2851. foreach(__item IN LISTS cmd)
  2852. string(APPEND __cmdQuoted " [==[${__item}]==]")
  2853. endforeach()
  2854. cmake_language(EVAL CODE "
  2855. ExternalProject_Add_Step(\${name} download
  2856. INDEPENDENT TRUE
  2857. COMMENT \${comment}
  2858. COMMAND ${__cmdQuoted}
  2859. WORKING_DIRECTORY \${work_dir}
  2860. DEPENDS \${depends}
  2861. DEPENDEES mkdir
  2862. ${log}
  2863. ${uses_terminal}
  2864. )"
  2865. )
  2866. endfunction()
  2867. function(_ep_get_update_disconnected var name)
  2868. get_property(update_disconnected_set
  2869. TARGET ${name}
  2870. PROPERTY _EP_UPDATE_DISCONNECTED
  2871. SET
  2872. )
  2873. if(update_disconnected_set)
  2874. get_property(update_disconnected
  2875. TARGET ${name}
  2876. PROPERTY _EP_UPDATE_DISCONNECTED
  2877. )
  2878. else()
  2879. get_property(update_disconnected
  2880. DIRECTORY
  2881. PROPERTY EP_UPDATE_DISCONNECTED
  2882. )
  2883. endif()
  2884. set(${var} "${update_disconnected}" PARENT_SCOPE)
  2885. endfunction()
  2886. function(_ep_add_update_command name)
  2887. ExternalProject_Get_Property(${name} source_dir stamp_dir tmp_dir)
  2888. get_property(cmd_set TARGET ${name} PROPERTY _EP_UPDATE_COMMAND SET)
  2889. get_property(cmd TARGET ${name} PROPERTY _EP_UPDATE_COMMAND)
  2890. get_property(cvs_repository TARGET ${name} PROPERTY _EP_CVS_REPOSITORY)
  2891. get_property(svn_repository TARGET ${name} PROPERTY _EP_SVN_REPOSITORY)
  2892. get_property(git_repository TARGET ${name} PROPERTY _EP_GIT_REPOSITORY)
  2893. get_property(hg_repository TARGET ${name} PROPERTY _EP_HG_REPOSITORY )
  2894. _ep_get_update_disconnected(update_disconnected ${name})
  2895. set(work_dir)
  2896. set(comment)
  2897. set(always)
  2898. set(file_deps)
  2899. if(cmd_set)
  2900. set(work_dir ${source_dir})
  2901. if(NOT "x${cmd}" STREQUAL "x")
  2902. set(always 1)
  2903. endif()
  2904. elseif(cvs_repository)
  2905. if(NOT CVS_EXECUTABLE)
  2906. message(FATAL_ERROR "error: could not find cvs for update of ${name}")
  2907. endif()
  2908. set(work_dir ${source_dir})
  2909. set(comment "Performing update step (CVS update) for '${name}'")
  2910. get_property(cvs_tag TARGET ${name} PROPERTY _EP_CVS_TAG)
  2911. set(cmd ${CVS_EXECUTABLE} -d ${cvs_repository} -q up -dP ${cvs_tag})
  2912. set(always 1)
  2913. elseif(svn_repository)
  2914. if(NOT Subversion_SVN_EXECUTABLE)
  2915. message(FATAL_ERROR "error: could not find svn for update of ${name}")
  2916. endif()
  2917. set(work_dir ${source_dir})
  2918. set(comment "Performing update step (SVN update) for '${name}'")
  2919. get_property(svn_revision TARGET ${name} PROPERTY _EP_SVN_REVISION)
  2920. get_property(svn_username TARGET ${name} PROPERTY _EP_SVN_USERNAME)
  2921. get_property(svn_password TARGET ${name} PROPERTY _EP_SVN_PASSWORD)
  2922. get_property(svn_trust_cert TARGET ${name} PROPERTY _EP_SVN_TRUST_CERT)
  2923. get_property(uses_terminal TARGET ${name} PROPERTY _EP_USES_TERMINAL_UPDATE)
  2924. # The --trust-server-cert option requires --non-interactive
  2925. if(uses_terminal AND NOT svn_trust_cert)
  2926. set(svn_interactive_args "")
  2927. else()
  2928. set(svn_interactive_args "--non-interactive")
  2929. endif()
  2930. set(svn_user_pw_args "")
  2931. if(DEFINED svn_username)
  2932. set(svn_user_pw_args ${svn_user_pw_args} "--username=${svn_username}")
  2933. endif()
  2934. if(DEFINED svn_password)
  2935. set(svn_user_pw_args ${svn_user_pw_args} "--password=${svn_password}")
  2936. endif()
  2937. if(svn_trust_cert)
  2938. set(svn_trust_cert_args --trust-server-cert)
  2939. endif()
  2940. set(cmd
  2941. ${Subversion_SVN_EXECUTABLE}
  2942. up
  2943. ${svn_revision}
  2944. ${svn_interactive_args}
  2945. ${svn_trust_cert_args}
  2946. ${svn_user_pw_args}
  2947. )
  2948. set(always 1)
  2949. elseif(git_repository)
  2950. # FetchContent gives us these directly, so don't try to recompute them
  2951. if(NOT GIT_EXECUTABLE OR NOT GIT_VERSION_STRING)
  2952. unset(CMAKE_MODULE_PATH) # Use CMake builtin find module
  2953. find_package(Git QUIET)
  2954. if(NOT GIT_EXECUTABLE)
  2955. message(FATAL_ERROR "error: could not find git for fetch of ${name}")
  2956. endif()
  2957. endif()
  2958. set(work_dir ${source_dir})
  2959. set(comment "Performing update step for '${name}'")
  2960. set(comment_disconnected "Performing disconnected update step for '${name}'")
  2961. get_property(git_tag
  2962. TARGET ${name}
  2963. PROPERTY _EP_GIT_TAG
  2964. )
  2965. if(NOT git_tag)
  2966. set(git_tag "master")
  2967. endif()
  2968. get_property(git_remote_name
  2969. TARGET ${name}
  2970. PROPERTY _EP_GIT_REMOTE_NAME
  2971. )
  2972. if(NOT git_remote_name)
  2973. set(git_remote_name "origin")
  2974. endif()
  2975. set(git_init_submodules TRUE)
  2976. get_property(git_submodules_set
  2977. TARGET ${name}
  2978. PROPERTY _EP_GIT_SUBMODULES
  2979. SET
  2980. )
  2981. if(git_submodules_set)
  2982. get_property(git_submodules
  2983. TARGET ${name}
  2984. PROPERTY _EP_GIT_SUBMODULES
  2985. )
  2986. if(git_submodules STREQUAL "" AND _EP_CMP0097 STREQUAL "NEW")
  2987. set(git_init_submodules FALSE)
  2988. endif()
  2989. endif()
  2990. get_property(git_update_strategy
  2991. TARGET ${name}
  2992. PROPERTY _EP_GIT_REMOTE_UPDATE_STRATEGY
  2993. )
  2994. if(NOT git_update_strategy)
  2995. set(git_update_strategy "${CMAKE_EP_GIT_REMOTE_UPDATE_STRATEGY}")
  2996. endif()
  2997. if(NOT git_update_strategy)
  2998. set(git_update_strategy REBASE)
  2999. endif()
  3000. set(strategies CHECKOUT REBASE REBASE_CHECKOUT)
  3001. if(NOT git_update_strategy IN_LIST strategies)
  3002. message(FATAL_ERROR
  3003. "'${git_update_strategy}' is not one of the supported strategies: "
  3004. "${strategies}"
  3005. )
  3006. endif()
  3007. _ep_get_git_submodules_recurse(git_submodules_recurse)
  3008. get_property(tls_verify TARGET ${name} PROPERTY _EP_TLS_VERIFY)
  3009. if("x${tls_verify}" STREQUAL "x" AND DEFINED CMAKE_TLS_VERIFY)
  3010. set(tls_verify "${CMAKE_TLS_VERIFY}")
  3011. endif()
  3012. set(update_script "${tmp_dir}/${name}-gitupdate.cmake")
  3013. list(APPEND file_deps ${update_script})
  3014. _ep_write_gitupdate_script(
  3015. "${update_script}"
  3016. "${GIT_EXECUTABLE}"
  3017. "${git_tag}"
  3018. "${git_remote_name}"
  3019. "${git_init_submodules}"
  3020. "${git_submodules_recurse}"
  3021. "${git_submodules}"
  3022. "${git_repository}"
  3023. "${work_dir}"
  3024. "${git_update_strategy}"
  3025. "${tls_verify}"
  3026. )
  3027. set(cmd ${CMAKE_COMMAND} -Dcan_fetch=YES -P ${update_script})
  3028. set(cmd_disconnected ${CMAKE_COMMAND} -Dcan_fetch=NO -P ${update_script})
  3029. set(always 1)
  3030. elseif(hg_repository)
  3031. if(NOT HG_EXECUTABLE)
  3032. message(FATAL_ERROR "error: could not find hg for pull of ${name}")
  3033. endif()
  3034. set(work_dir ${source_dir})
  3035. set(comment "Performing update step (hg pull) for '${name}'")
  3036. set(comment_disconnected "Performing disconnected update step for '${name}'")
  3037. get_property(hg_tag
  3038. TARGET ${name}
  3039. PROPERTY _EP_HG_TAG
  3040. )
  3041. if(NOT hg_tag)
  3042. set(hg_tag "tip")
  3043. endif()
  3044. if("${HG_VERSION_STRING}" STREQUAL "2.1")
  3045. set(notesAnchor
  3046. "#A2.1.1:_revert_pull_return_code_change.2C_compile_issue_on_OS_X"
  3047. )
  3048. message(WARNING
  3049. "Mercurial 2.1 does not distinguish an empty pull from a failed pull:
  3050. http://mercurial.selenic.com/wiki/UpgradeNotes${notesAnchor}
  3051. http://thread.gmane.org/gmane.comp.version-control.mercurial.devel/47656
  3052. Update to Mercurial >= 2.1.1.
  3053. ")
  3054. endif()
  3055. set(cmd
  3056. ${HG_EXECUTABLE} pull
  3057. COMMAND ${HG_EXECUTABLE} update ${hg_tag}
  3058. )
  3059. set(cmd_disconnected ${HG_EXECUTABLE} update ${hg_tag})
  3060. set(always 1)
  3061. endif()
  3062. # We use configure_file() to write the update_info_file so that the file's
  3063. # timestamp is not updated if we don't change the contents
  3064. if(NOT DEFINED cmd_disconnected)
  3065. set(cmd_disconnected "${cmd}")
  3066. endif()
  3067. set(update_info_file ${stamp_dir}/${name}-update-info.txt)
  3068. list(APPEND file_deps ${update_info_file})
  3069. configure_file(
  3070. "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/ExternalProject/UpdateInfo.txt.in"
  3071. "${update_info_file}"
  3072. @ONLY
  3073. )
  3074. get_property(log
  3075. TARGET ${name}
  3076. PROPERTY _EP_LOG_UPDATE
  3077. )
  3078. if(log)
  3079. set(log LOG 1)
  3080. else()
  3081. set(log "")
  3082. endif()
  3083. get_property(uses_terminal
  3084. TARGET ${name}
  3085. PROPERTY _EP_USES_TERMINAL_UPDATE
  3086. )
  3087. if(uses_terminal)
  3088. set(uses_terminal USES_TERMINAL 1)
  3089. else()
  3090. set(uses_terminal "")
  3091. endif()
  3092. set(__cmdQuoted)
  3093. foreach(__item IN LISTS cmd)
  3094. string(APPEND __cmdQuoted " [==[${__item}]==]")
  3095. endforeach()
  3096. cmake_language(EVAL CODE "
  3097. ExternalProject_Add_Step(${name} update
  3098. INDEPENDENT TRUE
  3099. COMMENT \${comment}
  3100. COMMAND ${__cmdQuoted}
  3101. ALWAYS \${always}
  3102. EXCLUDE_FROM_MAIN \${update_disconnected}
  3103. WORKING_DIRECTORY \${work_dir}
  3104. DEPENDEES download
  3105. DEPENDS \${file_deps}
  3106. ${log}
  3107. ${uses_terminal}
  3108. )"
  3109. )
  3110. if(update_disconnected)
  3111. if(NOT DEFINED comment_disconnected)
  3112. set(comment_disconnected "${comment}")
  3113. endif()
  3114. set(__cmdQuoted)
  3115. foreach(__item IN LISTS cmd_disconnected)
  3116. string(APPEND __cmdQuoted " [==[${__item}]==]")
  3117. endforeach()
  3118. cmake_language(EVAL CODE "
  3119. ExternalProject_Add_Step(${name} update_disconnected
  3120. INDEPENDENT TRUE
  3121. COMMENT \${comment_disconnected}
  3122. COMMAND ${__cmdQuoted}
  3123. WORKING_DIRECTORY \${work_dir}
  3124. DEPENDEES download
  3125. DEPENDS \${file_deps}
  3126. ${log}
  3127. ${uses_terminal}
  3128. )"
  3129. )
  3130. endif()
  3131. endfunction()
  3132. function(_ep_add_patch_command name)
  3133. ExternalProject_Get_Property(${name} source_dir stamp_dir)
  3134. get_property(cmd_set TARGET ${name} PROPERTY _EP_PATCH_COMMAND SET)
  3135. get_property(cmd TARGET ${name} PROPERTY _EP_PATCH_COMMAND)
  3136. set(work_dir)
  3137. if(cmd_set)
  3138. set(work_dir ${source_dir})
  3139. endif()
  3140. # We use configure_file() to write the patch_info_file so that the file's
  3141. # timestamp is not updated if we don't change the contents
  3142. set(patch_info_file ${stamp_dir}/${name}-patch-info.txt)
  3143. configure_file(
  3144. "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/ExternalProject/PatchInfo.txt.in"
  3145. "${patch_info_file}"
  3146. @ONLY
  3147. )
  3148. get_property(log
  3149. TARGET ${name}
  3150. PROPERTY _EP_LOG_PATCH
  3151. )
  3152. if(log)
  3153. set(log LOG 1)
  3154. else()
  3155. set(log "")
  3156. endif()
  3157. get_property(uses_terminal
  3158. TARGET ${name}
  3159. PROPERTY _EP_USES_TERMINAL_PATCH
  3160. )
  3161. if(uses_terminal)
  3162. set(uses_terminal USES_TERMINAL 1)
  3163. else()
  3164. set(uses_terminal "")
  3165. endif()
  3166. _ep_get_update_disconnected(update_disconnected ${name})
  3167. set(__cmdQuoted)
  3168. foreach(__item IN LISTS cmd)
  3169. string(APPEND __cmdQuoted " [==[${__item}]==]")
  3170. endforeach()
  3171. cmake_language(EVAL CODE "
  3172. ExternalProject_Add_Step(${name} patch
  3173. INDEPENDENT TRUE
  3174. COMMAND ${__cmdQuoted}
  3175. WORKING_DIRECTORY \${work_dir}
  3176. EXCLUDE_FROM_MAIN \${update_disconnected}
  3177. DEPENDEES update
  3178. DEPENDS \${patch_info_file}
  3179. ${log}
  3180. ${uses_terminal}
  3181. )"
  3182. )
  3183. if(update_disconnected)
  3184. cmake_language(EVAL CODE "
  3185. ExternalProject_Add_Step(${name} patch_disconnected
  3186. INDEPENDENT TRUE
  3187. COMMAND ${__cmdQuoted}
  3188. WORKING_DIRECTORY \${work_dir}
  3189. DEPENDEES update_disconnected
  3190. DEPENDS \${patch_info_file}
  3191. ${log}
  3192. ${uses_terminal}
  3193. )"
  3194. )
  3195. endif()
  3196. endfunction()
  3197. function(_ep_get_file_deps var name)
  3198. set(file_deps)
  3199. get_property(deps
  3200. TARGET ${name}
  3201. PROPERTY _EP_DEPENDS
  3202. )
  3203. foreach(dep IN LISTS deps)
  3204. get_property(dep_type
  3205. TARGET ${dep}
  3206. PROPERTY TYPE
  3207. )
  3208. if(dep_type STREQUAL "UTILITY")
  3209. get_property(is_ep
  3210. TARGET ${dep}
  3211. PROPERTY _EP_IS_EXTERNAL_PROJECT
  3212. )
  3213. if(is_ep)
  3214. _ep_get_step_stampfile(${dep} "done" done_stamp_file)
  3215. list(APPEND file_deps ${done_stamp_file})
  3216. endif()
  3217. endif()
  3218. endforeach()
  3219. set("${var}" "${file_deps}" PARENT_SCOPE)
  3220. endfunction()
  3221. function(_ep_extract_configure_command var name)
  3222. get_property(cmd_set
  3223. TARGET ${name}
  3224. PROPERTY _EP_CONFIGURE_COMMAND
  3225. SET
  3226. )
  3227. if(cmd_set)
  3228. get_property(cmd
  3229. TARGET ${name}
  3230. PROPERTY _EP_CONFIGURE_COMMAND
  3231. )
  3232. else()
  3233. get_target_property(cmake_command ${name} _EP_CMAKE_COMMAND)
  3234. if(cmake_command)
  3235. set(cmd "${cmake_command}")
  3236. else()
  3237. set(cmd "${CMAKE_COMMAND}")
  3238. endif()
  3239. get_property(cmake_args
  3240. TARGET ${name}
  3241. PROPERTY _EP_CMAKE_ARGS
  3242. )
  3243. list(APPEND cmd ${cmake_args})
  3244. # If there are any CMAKE_CACHE_ARGS or CMAKE_CACHE_DEFAULT_ARGS,
  3245. # write an initial cache and use it
  3246. get_property(cmake_cache_args
  3247. TARGET ${name}
  3248. PROPERTY _EP_CMAKE_CACHE_ARGS
  3249. )
  3250. get_property(cmake_cache_default_args
  3251. TARGET ${name}
  3252. PROPERTY _EP_CMAKE_CACHE_DEFAULT_ARGS
  3253. )
  3254. set(has_cmake_cache_args 0)
  3255. if(NOT "${cmake_cache_args}" STREQUAL "")
  3256. set(has_cmake_cache_args 1)
  3257. endif()
  3258. set(has_cmake_cache_default_args 0)
  3259. if(NOT "${cmake_cache_default_args}" STREQUAL "")
  3260. set(has_cmake_cache_default_args 1)
  3261. endif()
  3262. get_target_property(cmake_generator ${name}
  3263. _EP_CMAKE_GENERATOR
  3264. )
  3265. get_target_property(cmake_generator_instance ${name}
  3266. _EP_CMAKE_GENERATOR_INSTANCE
  3267. )
  3268. get_target_property(cmake_generator_platform ${name}
  3269. _EP_CMAKE_GENERATOR_PLATFORM
  3270. )
  3271. get_target_property(cmake_generator_toolset ${name}
  3272. _EP_CMAKE_GENERATOR_TOOLSET
  3273. )
  3274. if(cmake_generator)
  3275. list(APPEND cmd "-G${cmake_generator}")
  3276. if(cmake_generator_platform)
  3277. list(APPEND cmd "-A${cmake_generator_platform}")
  3278. endif()
  3279. if(cmake_generator_toolset)
  3280. list(APPEND cmd "-T${cmake_generator_toolset}")
  3281. endif()
  3282. if(cmake_generator_instance)
  3283. list(APPEND cmd
  3284. "-DCMAKE_GENERATOR_INSTANCE:INTERNAL=${cmake_generator_instance}"
  3285. )
  3286. endif()
  3287. else()
  3288. if(CMAKE_EXTRA_GENERATOR)
  3289. list(APPEND cmd "-G${CMAKE_EXTRA_GENERATOR} - ${CMAKE_GENERATOR}")
  3290. else()
  3291. list(APPEND cmd "-G${CMAKE_GENERATOR}")
  3292. if("${CMAKE_GENERATOR}" MATCHES "Green Hills MULTI")
  3293. set(has_cmake_cache_default_args 1)
  3294. list(APPEND cmake_cache_default_args
  3295. "-DGHS_TARGET_PLATFORM:STRING=${GHS_TARGET_PLATFORM}"
  3296. "-DGHS_PRIMARY_TARGET:STRING=${GHS_PRIMARY_TARGET}"
  3297. "-DGHS_TOOLSET_ROOT:STRING=${GHS_TOOLSET_ROOT}"
  3298. "-DGHS_OS_ROOT:STRING=${GHS_OS_ROOT}"
  3299. "-DGHS_OS_DIR:STRING=${GHS_OS_DIR}"
  3300. "-DGHS_BSP_NAME:STRING=${GHS_BSP_NAME}"
  3301. )
  3302. endif()
  3303. endif()
  3304. if(cmake_generator_platform)
  3305. message(FATAL_ERROR
  3306. "Option CMAKE_GENERATOR_PLATFORM not allowed without "
  3307. "CMAKE_GENERATOR."
  3308. )
  3309. endif()
  3310. if(CMAKE_GENERATOR_PLATFORM)
  3311. list(APPEND cmd "-A${CMAKE_GENERATOR_PLATFORM}")
  3312. endif()
  3313. if(cmake_generator_toolset)
  3314. message(FATAL_ERROR
  3315. "Option CMAKE_GENERATOR_TOOLSET not allowed without CMAKE_GENERATOR."
  3316. )
  3317. endif()
  3318. if(CMAKE_GENERATOR_TOOLSET)
  3319. list(APPEND cmd "-T${CMAKE_GENERATOR_TOOLSET}")
  3320. endif()
  3321. if(cmake_generator_instance)
  3322. message(FATAL_ERROR
  3323. "Option CMAKE_GENERATOR_INSTANCE not allowed without CMAKE_GENERATOR."
  3324. )
  3325. endif()
  3326. if(CMAKE_GENERATOR_INSTANCE)
  3327. list(APPEND cmd
  3328. "-DCMAKE_GENERATOR_INSTANCE:INTERNAL=${CMAKE_GENERATOR_INSTANCE}"
  3329. )
  3330. endif()
  3331. endif()
  3332. if(has_cmake_cache_args OR has_cmake_cache_default_args)
  3333. set(_ep_cache_args_script "<TMP_DIR>/${name}-cache-$<CONFIG>.cmake")
  3334. if(has_cmake_cache_args)
  3335. _ep_command_line_to_initial_cache(
  3336. script_initial_cache_force
  3337. "${cmake_cache_args}"
  3338. 1
  3339. )
  3340. endif()
  3341. if(has_cmake_cache_default_args)
  3342. _ep_command_line_to_initial_cache(
  3343. script_initial_cache_default
  3344. "${cmake_cache_default_args}"
  3345. 0
  3346. )
  3347. endif()
  3348. _ep_write_initial_cache(
  3349. ${name}
  3350. "${_ep_cache_args_script}"
  3351. "${script_initial_cache_force}${script_initial_cache_default}"
  3352. )
  3353. list(APPEND cmd "-C${_ep_cache_args_script}")
  3354. _ep_replace_location_tags(${name} _ep_cache_args_script)
  3355. set(_ep_cache_args_script
  3356. "${_ep_cache_args_script}"
  3357. PARENT_SCOPE
  3358. )
  3359. endif()
  3360. list(APPEND cmd -S "<SOURCE_DIR><SOURCE_SUBDIR>" -B "<BINARY_DIR>")
  3361. endif()
  3362. set("${var}" "${cmd}" PARENT_SCOPE)
  3363. endfunction()
  3364. # TODO: Make sure external projects use the proper compiler
  3365. function(_ep_add_configure_command name)
  3366. ExternalProject_Get_Property(${name} binary_dir tmp_dir)
  3367. set(file_deps)
  3368. get_property(configure_handled_by_build
  3369. TARGET ${name}
  3370. PROPERTY _EP_CONFIGURE_HANDLED_BY_BUILD
  3371. )
  3372. if(NOT configure_handled_by_build)
  3373. # Depend on other external projects (file-level)
  3374. _ep_get_file_deps(file_deps ${name})
  3375. endif()
  3376. _ep_extract_configure_command(cmd ${name})
  3377. # If anything about the configure command changes, (command itself, cmake
  3378. # used, cmake args or cmake generator) then re-run the configure step.
  3379. # Fixes issue https://gitlab.kitware.com/cmake/cmake/-/issues/10258
  3380. #
  3381. configure_file(
  3382. ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/ExternalProject/cfgcmd.txt.in
  3383. ${tmp_dir}/${name}-cfgcmd.txt
  3384. @ONLY
  3385. )
  3386. list(APPEND file_deps ${tmp_dir}/${name}-cfgcmd.txt)
  3387. list(APPEND file_deps ${_ep_cache_args_script})
  3388. _ep_get_update_disconnected(update_disconnected ${name})
  3389. if(update_disconnected)
  3390. set(dependees patch_disconnected)
  3391. else()
  3392. set(dependees patch)
  3393. endif()
  3394. get_property(log
  3395. TARGET ${name}
  3396. PROPERTY _EP_LOG_CONFIGURE
  3397. )
  3398. if(log)
  3399. set(log LOG 1)
  3400. else()
  3401. set(log "")
  3402. endif()
  3403. get_property(uses_terminal
  3404. TARGET ${name}
  3405. PROPERTY _EP_USES_TERMINAL_CONFIGURE
  3406. )
  3407. if(uses_terminal)
  3408. set(uses_terminal USES_TERMINAL 1)
  3409. else()
  3410. set(uses_terminal "")
  3411. endif()
  3412. set(__cmdQuoted)
  3413. foreach(__item IN LISTS cmd)
  3414. string(APPEND __cmdQuoted " [==[${__item}]==]")
  3415. endforeach()
  3416. cmake_language(EVAL CODE "
  3417. ExternalProject_Add_Step(${name} configure
  3418. INDEPENDENT FALSE
  3419. COMMAND ${__cmdQuoted}
  3420. WORKING_DIRECTORY \${binary_dir}
  3421. DEPENDEES \${dependees}
  3422. DEPENDS \${file_deps}
  3423. ${log}
  3424. ${uses_terminal}
  3425. )"
  3426. )
  3427. endfunction()
  3428. function(_ep_add_build_command name)
  3429. ExternalProject_Get_Property(${name} binary_dir)
  3430. set(file_deps)
  3431. get_property(configure_handled_by_build
  3432. TARGET ${name}
  3433. PROPERTY _EP_CONFIGURE_HANDLED_BY_BUILD
  3434. )
  3435. if(configure_handled_by_build)
  3436. # Depend on other external projects (file-level)
  3437. _ep_get_file_deps(file_deps ${name})
  3438. endif()
  3439. get_property(cmd_set
  3440. TARGET ${name}
  3441. PROPERTY _EP_BUILD_COMMAND
  3442. SET
  3443. )
  3444. if(cmd_set)
  3445. get_property(cmd
  3446. TARGET ${name}
  3447. PROPERTY _EP_BUILD_COMMAND
  3448. )
  3449. else()
  3450. _ep_get_build_command(${name} BUILD cmd)
  3451. endif()
  3452. get_property(log
  3453. TARGET ${name}
  3454. PROPERTY _EP_LOG_BUILD
  3455. )
  3456. if(log)
  3457. set(log LOG 1)
  3458. else()
  3459. set(log "")
  3460. endif()
  3461. get_property(uses_terminal
  3462. TARGET ${name}
  3463. PROPERTY _EP_USES_TERMINAL_BUILD
  3464. )
  3465. if(uses_terminal)
  3466. set(uses_terminal USES_TERMINAL 1)
  3467. else()
  3468. set(uses_terminal "")
  3469. endif()
  3470. get_property(build_always
  3471. TARGET ${name}
  3472. PROPERTY _EP_BUILD_ALWAYS
  3473. )
  3474. if(build_always)
  3475. set(always 1)
  3476. else()
  3477. set(always 0)
  3478. endif()
  3479. get_property(build_byproducts
  3480. TARGET ${name}
  3481. PROPERTY _EP_BUILD_BYPRODUCTS
  3482. )
  3483. get_property(build_job_server_aware
  3484. TARGET ${name}
  3485. PROPERTY _EP_BUILD_JOB_SERVER_AWARE
  3486. )
  3487. if(build_job_server_aware)
  3488. set(maybe_JOB_SERVER_AWARE "JOB_SERVER_AWARE 1")
  3489. else()
  3490. set(maybe_JOB_SERVER_AWARE "")
  3491. endif()
  3492. set(__cmdQuoted)
  3493. foreach(__item IN LISTS cmd)
  3494. string(APPEND __cmdQuoted " [==[${__item}]==]")
  3495. endforeach()
  3496. cmake_language(EVAL CODE "
  3497. ExternalProject_Add_Step(${name} build
  3498. INDEPENDENT FALSE
  3499. COMMAND ${__cmdQuoted}
  3500. BYPRODUCTS \${build_byproducts}
  3501. WORKING_DIRECTORY \${binary_dir}
  3502. DEPENDEES configure
  3503. DEPENDS \${file_deps}
  3504. ALWAYS \${always}
  3505. ${maybe_JOB_SERVER_AWARE}
  3506. ${log}
  3507. ${uses_terminal}
  3508. )"
  3509. )
  3510. endfunction()
  3511. function(_ep_add_install_command name)
  3512. ExternalProject_Get_Property(${name} binary_dir)
  3513. get_property(cmd_set
  3514. TARGET ${name}
  3515. PROPERTY _EP_INSTALL_COMMAND
  3516. SET
  3517. )
  3518. if(cmd_set)
  3519. get_property(cmd
  3520. TARGET ${name}
  3521. PROPERTY _EP_INSTALL_COMMAND
  3522. )
  3523. else()
  3524. _ep_get_build_command(${name} INSTALL cmd)
  3525. endif()
  3526. get_property(log
  3527. TARGET ${name}
  3528. PROPERTY _EP_LOG_INSTALL
  3529. )
  3530. if(log)
  3531. set(log LOG 1)
  3532. else()
  3533. set(log "")
  3534. endif()
  3535. get_property(uses_terminal
  3536. TARGET ${name}
  3537. PROPERTY _EP_USES_TERMINAL_INSTALL
  3538. )
  3539. if(uses_terminal)
  3540. set(uses_terminal USES_TERMINAL 1)
  3541. else()
  3542. set(uses_terminal "")
  3543. endif()
  3544. # With BUILD_ALWAYS+BUILD_BYPRODUCTS, Ninja restats the
  3545. # build step outputs and may not consider this step to
  3546. # be out-of-date. Explicitly mark it out-of-date too.
  3547. get_property(build_always
  3548. TARGET ${name}
  3549. PROPERTY _EP_BUILD_ALWAYS
  3550. )
  3551. if(build_always)
  3552. set(always 1)
  3553. else()
  3554. set(always 0)
  3555. endif()
  3556. get_property(install_byproducts
  3557. TARGET ${name}
  3558. PROPERTY _EP_INSTALL_BYPRODUCTS
  3559. )
  3560. set(__cmdQuoted)
  3561. foreach(__item IN LISTS cmd)
  3562. string(APPEND __cmdQuoted " [==[${__item}]==]")
  3563. endforeach()
  3564. cmake_language(EVAL CODE "
  3565. ExternalProject_Add_Step(${name} install
  3566. INDEPENDENT FALSE
  3567. COMMAND ${__cmdQuoted}
  3568. BYPRODUCTS \${install_byproducts}
  3569. WORKING_DIRECTORY \${binary_dir}
  3570. DEPENDEES build
  3571. ALWAYS \${always}
  3572. ${log}
  3573. ${uses_terminal}
  3574. )"
  3575. )
  3576. endfunction()
  3577. function(_ep_add_test_command name)
  3578. ExternalProject_Get_Property(${name} binary_dir)
  3579. get_property(before TARGET ${name} PROPERTY _EP_TEST_BEFORE_INSTALL)
  3580. get_property(after TARGET ${name} PROPERTY _EP_TEST_AFTER_INSTALL)
  3581. get_property(exclude TARGET ${name} PROPERTY _EP_TEST_EXCLUDE_FROM_MAIN)
  3582. get_property(cmd_set TARGET ${name} PROPERTY _EP_TEST_COMMAND SET)
  3583. # Only actually add the test step if one of the test related properties is
  3584. # explicitly set. (i.e. the test step is omitted unless requested...)
  3585. #
  3586. if(cmd_set OR before OR after OR exclude)
  3587. if(cmd_set)
  3588. get_property(cmd
  3589. TARGET ${name}
  3590. PROPERTY _EP_TEST_COMMAND
  3591. )
  3592. else()
  3593. _ep_get_build_command(${name} TEST cmd)
  3594. endif()
  3595. if(before)
  3596. set(dependees_args DEPENDEES build)
  3597. else()
  3598. set(dependees_args DEPENDEES install)
  3599. endif()
  3600. if(exclude)
  3601. set(dependers_args "")
  3602. set(exclude_args EXCLUDE_FROM_MAIN 1)
  3603. else()
  3604. if(before)
  3605. set(dependers_args DEPENDERS install)
  3606. else()
  3607. set(dependers_args "")
  3608. endif()
  3609. set(exclude_args "")
  3610. endif()
  3611. get_property(log
  3612. TARGET ${name}
  3613. PROPERTY _EP_LOG_TEST
  3614. )
  3615. if(log)
  3616. set(log LOG 1)
  3617. else()
  3618. set(log "")
  3619. endif()
  3620. get_property(uses_terminal
  3621. TARGET ${name}
  3622. PROPERTY _EP_USES_TERMINAL_TEST
  3623. )
  3624. if(uses_terminal)
  3625. set(uses_terminal USES_TERMINAL 1)
  3626. else()
  3627. set(uses_terminal "")
  3628. endif()
  3629. set(__cmdQuoted)
  3630. foreach(__item IN LISTS cmd)
  3631. string(APPEND __cmdQuoted " [==[${__item}]==]")
  3632. endforeach()
  3633. cmake_language(EVAL CODE "
  3634. ExternalProject_Add_Step(${name} test
  3635. INDEPENDENT FALSE
  3636. COMMAND ${__cmdQuoted}
  3637. WORKING_DIRECTORY \${binary_dir}
  3638. ${dependees_args}
  3639. ${dependers_args}
  3640. ${exclude_args}
  3641. ${log}
  3642. ${uses_terminal}
  3643. )"
  3644. )
  3645. endif()
  3646. endfunction()
  3647. function(ExternalProject_Add name)
  3648. cmake_policy(GET CMP0097 _EP_CMP0097
  3649. PARENT_SCOPE # undocumented, do not use outside of CMake
  3650. )
  3651. cmake_policy(GET CMP0114 cmp0114
  3652. PARENT_SCOPE # undocumented, do not use outside of CMake
  3653. )
  3654. if(CMAKE_XCODE_BUILD_SYSTEM VERSION_GREATER_EQUAL 12 AND
  3655. NOT cmp0114 STREQUAL "NEW")
  3656. message(AUTHOR_WARNING
  3657. "Policy CMP0114 is not set to NEW. "
  3658. "In order to support the Xcode \"new build system\", "
  3659. "this project must be updated to set policy CMP0114 to NEW."
  3660. "\n"
  3661. "Since CMake is generating for the Xcode \"new build system\", "
  3662. "ExternalProject_Add will use policy CMP0114's NEW behavior anyway, "
  3663. "but the generated build system may not match what the project intends."
  3664. )
  3665. set(cmp0114 "NEW")
  3666. endif()
  3667. cmake_policy(GET CMP0135 _EP_CMP0135
  3668. PARENT_SCOPE # undocumented, do not use outside of CMake
  3669. )
  3670. _ep_get_configuration_subdir_genex(cfgdir)
  3671. # Add a custom target for the external project.
  3672. set(cmf_dir ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles)
  3673. _ep_get_complete_stampfile(${name} complete_stamp_file)
  3674. cmake_policy(PUSH)
  3675. if(cmp0114 STREQUAL "NEW")
  3676. # To implement CMP0114 NEW behavior with Makefile generators,
  3677. # we need CMP0113 NEW behavior.
  3678. cmake_policy(SET CMP0113 NEW)
  3679. endif()
  3680. # The "ALL" option to add_custom_target just tells it to not set the
  3681. # EXCLUDE_FROM_ALL target property. Later, if the EXCLUDE_FROM_ALL
  3682. # argument was passed, we explicitly set it for the target.
  3683. add_custom_target(${name} ALL DEPENDS ${complete_stamp_file})
  3684. cmake_policy(POP)
  3685. set_target_properties(${name} PROPERTIES
  3686. _EP_IS_EXTERNAL_PROJECT 1
  3687. LABELS ${name}
  3688. FOLDER "ExternalProjectTargets/${name}"
  3689. _EP_CMP0114 "${cmp0114}"
  3690. )
  3691. set(keywords
  3692. #
  3693. # Directory options
  3694. #
  3695. PREFIX
  3696. TMP_DIR
  3697. STAMP_DIR
  3698. LOG_DIR
  3699. DOWNLOAD_DIR
  3700. SOURCE_DIR
  3701. BINARY_DIR
  3702. INSTALL_DIR
  3703. #
  3704. # Download step options
  3705. #
  3706. DOWNLOAD_COMMAND
  3707. #
  3708. URL
  3709. URL_HASH
  3710. URL_MD5
  3711. DOWNLOAD_NAME
  3712. DOWNLOAD_EXTRACT_TIMESTAMP
  3713. DOWNLOAD_NO_EXTRACT
  3714. DOWNLOAD_NO_PROGRESS
  3715. TIMEOUT
  3716. INACTIVITY_TIMEOUT
  3717. HTTP_USERNAME
  3718. HTTP_PASSWORD
  3719. HTTP_HEADER
  3720. TLS_VERIFY # Also used for git clone operations
  3721. TLS_CAINFO
  3722. NETRC
  3723. NETRC_FILE
  3724. #
  3725. GIT_REPOSITORY
  3726. GIT_TAG
  3727. GIT_REMOTE_NAME
  3728. GIT_SUBMODULES
  3729. GIT_SUBMODULES_RECURSE
  3730. GIT_SHALLOW
  3731. GIT_PROGRESS
  3732. GIT_CONFIG
  3733. GIT_REMOTE_UPDATE_STRATEGY
  3734. #
  3735. SVN_REPOSITORY
  3736. SVN_REVISION
  3737. SVN_USERNAME
  3738. SVN_PASSWORD
  3739. SVN_TRUST_CERT
  3740. #
  3741. HG_REPOSITORY
  3742. HG_TAG
  3743. #
  3744. CVS_REPOSITORY
  3745. CVS_MODULE
  3746. CVS_TAG
  3747. #
  3748. # Update step options
  3749. #
  3750. UPDATE_COMMAND
  3751. UPDATE_DISCONNECTED
  3752. #
  3753. # Patch step options
  3754. #
  3755. PATCH_COMMAND
  3756. #
  3757. # Configure step options
  3758. #
  3759. CONFIGURE_COMMAND
  3760. CMAKE_COMMAND
  3761. CMAKE_GENERATOR
  3762. CMAKE_GENERATOR_PLATFORM
  3763. CMAKE_GENERATOR_TOOLSET
  3764. CMAKE_GENERATOR_INSTANCE
  3765. CMAKE_ARGS
  3766. CMAKE_CACHE_ARGS
  3767. CMAKE_CACHE_DEFAULT_ARGS
  3768. SOURCE_SUBDIR
  3769. CONFIGURE_HANDLED_BY_BUILD
  3770. #
  3771. # Build step options
  3772. #
  3773. BUILD_COMMAND
  3774. BUILD_IN_SOURCE
  3775. BUILD_ALWAYS
  3776. BUILD_BYPRODUCTS
  3777. BUILD_JOB_SERVER_AWARE
  3778. #
  3779. # Install step options
  3780. #
  3781. INSTALL_COMMAND
  3782. INSTALL_BYPRODUCTS
  3783. #
  3784. # Test step options
  3785. #
  3786. TEST_COMMAND
  3787. TEST_BEFORE_INSTALL
  3788. TEST_AFTER_INSTALL
  3789. TEST_EXCLUDE_FROM_MAIN
  3790. #
  3791. # Logging options
  3792. #
  3793. LOG_DOWNLOAD
  3794. LOG_UPDATE
  3795. LOG_PATCH
  3796. LOG_CONFIGURE
  3797. LOG_BUILD
  3798. LOG_INSTALL
  3799. LOG_TEST
  3800. LOG_MERGED_STDOUTERR
  3801. LOG_OUTPUT_ON_FAILURE
  3802. #
  3803. # Terminal access options
  3804. #
  3805. USES_TERMINAL_DOWNLOAD
  3806. USES_TERMINAL_UPDATE
  3807. USES_TERMINAL_PATCH
  3808. USES_TERMINAL_CONFIGURE
  3809. USES_TERMINAL_BUILD
  3810. USES_TERMINAL_INSTALL
  3811. USES_TERMINAL_TEST
  3812. #
  3813. # Target options
  3814. #
  3815. DEPENDS
  3816. EXCLUDE_FROM_ALL
  3817. STEP_TARGETS
  3818. INDEPENDENT_STEP_TARGETS
  3819. #
  3820. # Miscellaneous options
  3821. #
  3822. LIST_SEPARATOR
  3823. #
  3824. # Internal options (undocumented)
  3825. #
  3826. EXTERNALPROJECT_INTERNAL_ARGUMENT_SEPARATOR
  3827. )
  3828. _ep_parse_arguments(
  3829. ExternalProject_Add
  3830. "${keywords}"
  3831. ${name}
  3832. _EP_
  3833. "${ARGN}"
  3834. )
  3835. _ep_set_directories(${name})
  3836. _ep_get_step_stampfile(${name} "done" done_stamp_file)
  3837. _ep_get_step_stampfile(${name} "install" install_stamp_file)
  3838. # Set the EXCLUDE_FROM_ALL target property if required.
  3839. get_property(exclude_from_all
  3840. TARGET ${name}
  3841. PROPERTY _EP_EXCLUDE_FROM_ALL
  3842. )
  3843. if(exclude_from_all)
  3844. set_property(TARGET ${name} PROPERTY EXCLUDE_FROM_ALL TRUE)
  3845. endif()
  3846. get_property(repo TARGET ${name} PROPERTY _EP_GIT_REPOSITORY)
  3847. if(NOT repo STREQUAL "")
  3848. cmake_policy(GET CMP0150 cmp0150
  3849. PARENT_SCOPE # undocumented, do not use outside of CMake
  3850. )
  3851. get_property(source_dir TARGET ${name} PROPERTY _EP_SOURCE_DIR)
  3852. get_filename_component(work_dir "${source_dir}" PATH)
  3853. _ep_resolve_git_remote(resolved_git_repository "${repo}" "${cmp0150}" "${work_dir}")
  3854. set_property(TARGET ${name} PROPERTY _EP_GIT_REPOSITORY ${resolved_git_repository})
  3855. endif()
  3856. # The 'complete' step depends on all other steps and creates a
  3857. # 'done' mark. A dependent external project's 'configure' step
  3858. # depends on the 'done' mark so that it rebuilds when this project
  3859. # rebuilds. It is important that 'done' is not the output of any
  3860. # custom command so that CMake does not propagate build rules to
  3861. # other external project targets, which may cause problems during
  3862. # parallel builds. However, the Ninja generator needs to see the entire
  3863. # dependency graph, and can cope with custom commands belonging to
  3864. # multiple targets, so we add the 'done' mark as an output for Ninja only.
  3865. set(complete_outputs ${complete_stamp_file})
  3866. if(${CMAKE_GENERATOR} MATCHES "Ninja")
  3867. set(complete_outputs ${complete_outputs} ${done_stamp_file})
  3868. endif()
  3869. add_custom_command(
  3870. OUTPUT ${complete_outputs}
  3871. COMMENT "Completed '${name}'"
  3872. COMMAND ${CMAKE_COMMAND} -E make_directory ${cmf_dir}${cfgdir}
  3873. COMMAND ${CMAKE_COMMAND} -E touch ${complete_stamp_file}
  3874. COMMAND ${CMAKE_COMMAND} -E touch ${done_stamp_file}
  3875. DEPENDS ${install_stamp_file}
  3876. VERBATIM
  3877. )
  3878. # Depend on other external projects (target-level).
  3879. get_property(deps
  3880. TARGET ${name}
  3881. PROPERTY _EP_DEPENDS
  3882. )
  3883. foreach(arg IN LISTS deps)
  3884. add_dependencies(${name} ${arg})
  3885. endforeach()
  3886. # Set up custom build steps based on the target properties.
  3887. # Each step depends on the previous one.
  3888. #
  3889. # The target depends on the output of the final step.
  3890. # (Already set up above in the DEPENDS of the add_custom_target command.)
  3891. #
  3892. _ep_add_mkdir_command(${name})
  3893. _ep_add_download_command(${name})
  3894. _ep_add_update_command(${name})
  3895. _ep_add_patch_command(${name})
  3896. _ep_add_configure_command(${name})
  3897. _ep_add_build_command(${name})
  3898. _ep_add_install_command(${name})
  3899. # Test is special in that it might depend on build, or it might depend
  3900. # on install.
  3901. #
  3902. _ep_add_test_command(${name})
  3903. endfunction()
  3904. cmake_policy(POP)