ExternalProject.cmake 139 KB

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