ExternalProject.cmake 130 KB

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