ExternalProject.cmake 115 KB

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