ExternalProject.cmake 137 KB

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