ExternalProject.cmake 133 KB

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