ExternalProject.cmake 132 KB

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