ExternalProject.cmake 120 KB

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