ExternalProject.cmake 134 KB

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