ExternalProject.cmake 136 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731
  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 script_filename source_dir git_EXECUTABLE git_repository git_tag git_remote_name init_submodules git_submodules_recurse git_submodules git_shallow git_progress git_config src_name work_dir gitclone_infofile gitclone_stampfile tls_verify)
  1002. if(NOT GIT_VERSION_STRING VERSION_LESS 1.8.5)
  1003. # Use `git checkout <tree-ish> --` to avoid ambiguity with a local path.
  1004. set(git_checkout_explicit-- "--")
  1005. else()
  1006. # Use `git checkout <branch>` even though this risks ambiguity with a
  1007. # local path. Unfortunately we cannot use `git checkout <tree-ish> --`
  1008. # because that will not search for remote branch names, a common use case.
  1009. set(git_checkout_explicit-- "")
  1010. endif()
  1011. if("${git_tag}" STREQUAL "")
  1012. message(FATAL_ERROR "Tag for git checkout should not be empty.")
  1013. endif()
  1014. if(GIT_VERSION_STRING VERSION_LESS 2.20 OR 2.21 VERSION_LESS_EQUAL GIT_VERSION_STRING)
  1015. set(git_clone_options "--no-checkout")
  1016. else()
  1017. set(git_clone_options)
  1018. endif()
  1019. if(git_shallow)
  1020. if(NOT GIT_VERSION_STRING VERSION_LESS 1.7.10)
  1021. list(APPEND git_clone_options "--depth 1 --no-single-branch")
  1022. else()
  1023. list(APPEND git_clone_options "--depth 1")
  1024. endif()
  1025. endif()
  1026. if(git_progress)
  1027. list(APPEND git_clone_options --progress)
  1028. endif()
  1029. foreach(config IN LISTS git_config)
  1030. list(APPEND git_clone_options --config \"${config}\")
  1031. endforeach()
  1032. if(NOT ${git_remote_name} STREQUAL "origin")
  1033. list(APPEND git_clone_options --origin \"${git_remote_name}\")
  1034. endif()
  1035. string (REPLACE ";" " " git_clone_options "${git_clone_options}")
  1036. set(git_options)
  1037. # disable cert checking if explicitly told not to do it
  1038. if(NOT "x${tls_verify}" STREQUAL "x" AND NOT tls_verify)
  1039. set(git_options
  1040. -c http.sslVerify=false)
  1041. endif()
  1042. string (REPLACE ";" " " git_options "${git_options}")
  1043. file(WRITE ${script_filename}
  1044. "
  1045. if(EXISTS \"${gitclone_stampfile}\" AND EXISTS \"${gitclone_infofile}\" AND
  1046. \"${gitclone_stampfile}\" IS_NEWER_THAN \"${gitclone_infofile}\")
  1047. message(STATUS \"Avoiding repeated git clone, stamp file is up to date: '${gitclone_stampfile}'\")
  1048. return()
  1049. endif()
  1050. execute_process(
  1051. COMMAND \${CMAKE_COMMAND} -E rm -rf \"${source_dir}\"
  1052. RESULT_VARIABLE error_code
  1053. )
  1054. if(error_code)
  1055. message(FATAL_ERROR \"Failed to remove directory: '${source_dir}'\")
  1056. endif()
  1057. # try the clone 3 times in case there is an odd git clone issue
  1058. set(error_code 1)
  1059. set(number_of_tries 0)
  1060. while(error_code AND number_of_tries LESS 3)
  1061. execute_process(
  1062. COMMAND \"${git_EXECUTABLE}\" ${git_options} clone ${git_clone_options} \"${git_repository}\" \"${src_name}\"
  1063. WORKING_DIRECTORY \"${work_dir}\"
  1064. RESULT_VARIABLE error_code
  1065. )
  1066. math(EXPR number_of_tries \"\${number_of_tries} + 1\")
  1067. endwhile()
  1068. if(number_of_tries GREATER 1)
  1069. message(STATUS \"Had to git clone more than once:
  1070. \${number_of_tries} times.\")
  1071. endif()
  1072. if(error_code)
  1073. message(FATAL_ERROR \"Failed to clone repository: '${git_repository}'\")
  1074. endif()
  1075. execute_process(
  1076. COMMAND \"${git_EXECUTABLE}\" ${git_options} checkout ${git_tag} ${git_checkout_explicit--}
  1077. WORKING_DIRECTORY \"${work_dir}/${src_name}\"
  1078. RESULT_VARIABLE error_code
  1079. )
  1080. if(error_code)
  1081. message(FATAL_ERROR \"Failed to checkout tag: '${git_tag}'\")
  1082. endif()
  1083. set(init_submodules ${init_submodules})
  1084. if(init_submodules)
  1085. execute_process(
  1086. COMMAND \"${git_EXECUTABLE}\" ${git_options} submodule update ${git_submodules_recurse} --init ${git_submodules}
  1087. WORKING_DIRECTORY \"${work_dir}/${src_name}\"
  1088. RESULT_VARIABLE error_code
  1089. )
  1090. endif()
  1091. if(error_code)
  1092. message(FATAL_ERROR \"Failed to update submodules in: '${work_dir}/${src_name}'\")
  1093. endif()
  1094. # Complete success, update the script-last-run stamp file:
  1095. #
  1096. execute_process(
  1097. COMMAND \${CMAKE_COMMAND} -E copy
  1098. \"${gitclone_infofile}\"
  1099. \"${gitclone_stampfile}\"
  1100. RESULT_VARIABLE error_code
  1101. )
  1102. if(error_code)
  1103. message(FATAL_ERROR \"Failed to copy script-last-run stamp file: '${gitclone_stampfile}'\")
  1104. endif()
  1105. "
  1106. )
  1107. endfunction()
  1108. function(_ep_write_hgclone_script script_filename source_dir hg_EXECUTABLE hg_repository hg_tag src_name work_dir hgclone_infofile hgclone_stampfile)
  1109. if("${hg_tag}" STREQUAL "")
  1110. message(FATAL_ERROR "Tag for hg checkout should not be empty.")
  1111. endif()
  1112. file(WRITE ${script_filename}
  1113. "
  1114. if(EXISTS \"${hgclone_stampfile}\" AND EXISTS \"${hgclone_infofile}\" AND
  1115. \"${hgclone_stampfile}\" IS_NEWER_THAN \"${hgclone_infofile}\")
  1116. message(STATUS \"Avoiding repeated hg clone, stamp file is up to date: '${hgclone_stampfile}'\")
  1117. return()
  1118. endif()
  1119. execute_process(
  1120. COMMAND \${CMAKE_COMMAND} -E rm -rf \"${source_dir}\"
  1121. RESULT_VARIABLE error_code
  1122. )
  1123. if(error_code)
  1124. message(FATAL_ERROR \"Failed to remove directory: '${source_dir}'\")
  1125. endif()
  1126. execute_process(
  1127. COMMAND \"${hg_EXECUTABLE}\" clone -U \"${hg_repository}\" \"${src_name}\"
  1128. WORKING_DIRECTORY \"${work_dir}\"
  1129. RESULT_VARIABLE error_code
  1130. )
  1131. if(error_code)
  1132. message(FATAL_ERROR \"Failed to clone repository: '${hg_repository}'\")
  1133. endif()
  1134. execute_process(
  1135. COMMAND \"${hg_EXECUTABLE}\" update ${hg_tag}
  1136. WORKING_DIRECTORY \"${work_dir}/${src_name}\"
  1137. RESULT_VARIABLE error_code
  1138. )
  1139. if(error_code)
  1140. message(FATAL_ERROR \"Failed to checkout tag: '${hg_tag}'\")
  1141. endif()
  1142. # Complete success, update the script-last-run stamp file:
  1143. #
  1144. execute_process(
  1145. COMMAND \${CMAKE_COMMAND} -E copy
  1146. \"${hgclone_infofile}\"
  1147. \"${hgclone_stampfile}\"
  1148. RESULT_VARIABLE error_code
  1149. )
  1150. if(error_code)
  1151. message(FATAL_ERROR \"Failed to copy script-last-run stamp file: '${hgclone_stampfile}'\")
  1152. endif()
  1153. "
  1154. )
  1155. endfunction()
  1156. function(_ep_write_gitupdate_script script_filename git_EXECUTABLE git_tag git_remote_name init_submodules git_submodules_recurse git_submodules git_repository work_dir git_update_strategy)
  1157. if("${git_tag}" STREQUAL "")
  1158. message(FATAL_ERROR "Tag for git checkout should not be empty.")
  1159. endif()
  1160. set(git_stash_save_options --quiet)
  1161. if(GIT_VERSION_STRING VERSION_GREATER_EQUAL 1.7.7)
  1162. # This avoids stashing files covered by .gitignore
  1163. list(APPEND git_stash_save_options --include-untracked)
  1164. elseif(GIT_VERSION_STRING VERSION_GREATER_EQUAL 1.7.6)
  1165. # Untracked files, but also ignored files, so potentially slower
  1166. list(APPEND git_stash_save_options --all)
  1167. endif()
  1168. configure_file(
  1169. "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/ExternalProject-gitupdate.cmake.in"
  1170. "${script_filename}"
  1171. @ONLY
  1172. )
  1173. endfunction()
  1174. function(_ep_write_downloadfile_script script_filename REMOTE LOCAL timeout inactivity_timeout no_progress hash tls_verify tls_cainfo userpwd http_headers netrc netrc_file)
  1175. if(timeout)
  1176. set(TIMEOUT_ARGS TIMEOUT ${timeout})
  1177. set(TIMEOUT_MSG "${timeout} seconds")
  1178. else()
  1179. set(TIMEOUT_ARGS "# no TIMEOUT")
  1180. set(TIMEOUT_MSG "none")
  1181. endif()
  1182. if(inactivity_timeout)
  1183. set(INACTIVITY_TIMEOUT_ARGS INACTIVITY_TIMEOUT ${inactivity_timeout})
  1184. set(INACTIVITY_TIMEOUT_MSG "${inactivity_timeout} seconds")
  1185. else()
  1186. set(INACTIVITY_TIMEOUT_ARGS "# no INACTIVITY_TIMEOUT")
  1187. set(INACTIVITY_TIMEOUT_MSG "none")
  1188. endif()
  1189. if(no_progress)
  1190. set(SHOW_PROGRESS "")
  1191. else()
  1192. set(SHOW_PROGRESS "SHOW_PROGRESS")
  1193. endif()
  1194. _ep_get_hash_regex(_ep_hash_regex)
  1195. if("${hash}" MATCHES "${_ep_hash_regex}")
  1196. set(ALGO "${CMAKE_MATCH_1}")
  1197. string(TOLOWER "${CMAKE_MATCH_2}" EXPECT_VALUE)
  1198. else()
  1199. set(ALGO "")
  1200. set(EXPECT_VALUE "")
  1201. endif()
  1202. set(TLS_VERIFY_CODE "")
  1203. set(TLS_CAINFO_CODE "")
  1204. set(NETRC_CODE "")
  1205. set(NETRC_FILE_CODE "")
  1206. # check for curl globals in the project
  1207. if(DEFINED CMAKE_TLS_VERIFY)
  1208. set(TLS_VERIFY_CODE "set(CMAKE_TLS_VERIFY ${CMAKE_TLS_VERIFY})")
  1209. endif()
  1210. if(DEFINED CMAKE_TLS_CAINFO)
  1211. set(TLS_CAINFO_CODE "set(CMAKE_TLS_CAINFO \"${CMAKE_TLS_CAINFO}\")")
  1212. endif()
  1213. if(DEFINED CMAKE_NETRC)
  1214. set(NETRC_CODE "set(CMAKE_NETRC \"${CMAKE_NETRC}\")")
  1215. endif()
  1216. if(DEFINED CMAKE_NETRC_FILE)
  1217. set(NETRC_FILE_CODE "set(CMAKE_NETRC_FILE \"${CMAKE_NETRC_FILE}\")")
  1218. endif()
  1219. # now check for curl locals so that the local values
  1220. # will override the globals
  1221. # check for tls_verify argument
  1222. string(LENGTH "${tls_verify}" tls_verify_len)
  1223. if(tls_verify_len GREATER 0)
  1224. set(TLS_VERIFY_CODE "set(CMAKE_TLS_VERIFY ${tls_verify})")
  1225. endif()
  1226. # check for tls_cainfo argument
  1227. string(LENGTH "${tls_cainfo}" tls_cainfo_len)
  1228. if(tls_cainfo_len GREATER 0)
  1229. set(TLS_CAINFO_CODE "set(CMAKE_TLS_CAINFO \"${tls_cainfo}\")")
  1230. endif()
  1231. # check for netrc argument
  1232. string(LENGTH "${netrc}" netrc_len)
  1233. if(netrc_len GREATER 0)
  1234. set(NETRC_CODE "set(CMAKE_NETRC \"${netrc}\")")
  1235. endif()
  1236. # check for netrc_file argument
  1237. string(LENGTH "${netrc_file}" netrc_file_len)
  1238. if(netrc_file_len GREATER 0)
  1239. set(NETRC_FILE_CODE "set(CMAKE_NETRC_FILE \"${netrc_file}\")")
  1240. endif()
  1241. if(userpwd STREQUAL ":")
  1242. set(USERPWD_ARGS)
  1243. else()
  1244. set(USERPWD_ARGS USERPWD "${userpwd}")
  1245. endif()
  1246. set(HTTP_HEADERS_ARGS "")
  1247. if(NOT http_headers STREQUAL "")
  1248. foreach(header ${http_headers})
  1249. set(
  1250. HTTP_HEADERS_ARGS
  1251. "HTTPHEADER \"${header}\"\n ${HTTP_HEADERS_ARGS}"
  1252. )
  1253. endforeach()
  1254. endif()
  1255. # Used variables:
  1256. # * TLS_VERIFY_CODE
  1257. # * TLS_CAINFO_CODE
  1258. # * ALGO
  1259. # * EXPECT_VALUE
  1260. # * REMOTE
  1261. # * LOCAL
  1262. # * SHOW_PROGRESS
  1263. # * TIMEOUT_ARGS
  1264. # * TIMEOUT_MSG
  1265. # * USERPWD_ARGS
  1266. # * HTTP_HEADERS_ARGS
  1267. configure_file(
  1268. "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/ExternalProject-download.cmake.in"
  1269. "${script_filename}"
  1270. @ONLY
  1271. )
  1272. endfunction()
  1273. function(_ep_write_verifyfile_script script_filename LOCAL hash)
  1274. _ep_get_hash_regex(_ep_hash_regex)
  1275. if("${hash}" MATCHES "${_ep_hash_regex}")
  1276. set(ALGO "${CMAKE_MATCH_1}")
  1277. string(TOLOWER "${CMAKE_MATCH_2}" EXPECT_VALUE)
  1278. else()
  1279. set(ALGO "")
  1280. set(EXPECT_VALUE "")
  1281. endif()
  1282. # Used variables:
  1283. # * ALGO
  1284. # * EXPECT_VALUE
  1285. # * LOCAL
  1286. configure_file(
  1287. "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/ExternalProject-verify.cmake.in"
  1288. "${script_filename}"
  1289. @ONLY
  1290. )
  1291. endfunction()
  1292. function(_ep_write_extractfile_script script_filename name filename directory)
  1293. set(args "")
  1294. if(filename MATCHES "(\\.|=)(7z|tar\\.bz2|tar\\.gz|tar\\.xz|tbz2|tgz|txz|zip)$")
  1295. set(args xfz)
  1296. endif()
  1297. if(filename MATCHES "(\\.|=)tar$")
  1298. set(args xf)
  1299. endif()
  1300. if(args STREQUAL "")
  1301. 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")
  1302. return()
  1303. endif()
  1304. file(WRITE ${script_filename}
  1305. "# Make file names absolute:
  1306. #
  1307. get_filename_component(filename \"${filename}\" ABSOLUTE)
  1308. get_filename_component(directory \"${directory}\" ABSOLUTE)
  1309. message(STATUS \"extracting...
  1310. src='\${filename}'
  1311. dst='\${directory}'\")
  1312. if(NOT EXISTS \"\${filename}\")
  1313. message(FATAL_ERROR \"error: file to extract does not exist: '\${filename}'\")
  1314. endif()
  1315. # Prepare a space for extracting:
  1316. #
  1317. set(i 1234)
  1318. while(EXISTS \"\${directory}/../ex-${name}\${i}\")
  1319. math(EXPR i \"\${i} + 1\")
  1320. endwhile()
  1321. set(ut_dir \"\${directory}/../ex-${name}\${i}\")
  1322. file(MAKE_DIRECTORY \"\${ut_dir}\")
  1323. # Extract it:
  1324. #
  1325. message(STATUS \"extracting... [tar ${args}]\")
  1326. execute_process(COMMAND \${CMAKE_COMMAND} -E tar ${args} \${filename}
  1327. WORKING_DIRECTORY \${ut_dir}
  1328. RESULT_VARIABLE rv)
  1329. if(NOT rv EQUAL 0)
  1330. message(STATUS \"extracting... [error clean up]\")
  1331. file(REMOVE_RECURSE \"\${ut_dir}\")
  1332. message(FATAL_ERROR \"error: extract of '\${filename}' failed\")
  1333. endif()
  1334. # Analyze what came out of the tar file:
  1335. #
  1336. message(STATUS \"extracting... [analysis]\")
  1337. file(GLOB contents \"\${ut_dir}/*\")
  1338. list(REMOVE_ITEM contents \"\${ut_dir}/.DS_Store\")
  1339. list(LENGTH contents n)
  1340. if(NOT n EQUAL 1 OR NOT IS_DIRECTORY \"\${contents}\")
  1341. set(contents \"\${ut_dir}\")
  1342. endif()
  1343. # Move \"the one\" directory to the final directory:
  1344. #
  1345. message(STATUS \"extracting... [rename]\")
  1346. file(REMOVE_RECURSE \${directory})
  1347. get_filename_component(contents \${contents} ABSOLUTE)
  1348. file(RENAME \${contents} \${directory})
  1349. # Clean up:
  1350. #
  1351. message(STATUS \"extracting... [clean up]\")
  1352. file(REMOVE_RECURSE \"\${ut_dir}\")
  1353. message(STATUS \"extracting... done\")
  1354. "
  1355. )
  1356. endfunction()
  1357. function(_ep_set_directories name)
  1358. get_property(prefix TARGET ${name} PROPERTY _EP_PREFIX)
  1359. if(NOT prefix)
  1360. get_property(prefix DIRECTORY PROPERTY EP_PREFIX)
  1361. if(NOT prefix)
  1362. get_property(base DIRECTORY PROPERTY EP_BASE)
  1363. if(NOT base)
  1364. set(prefix "${name}-prefix")
  1365. endif()
  1366. endif()
  1367. endif()
  1368. if(prefix)
  1369. set(tmp_default "${prefix}/tmp")
  1370. set(download_default "${prefix}/src")
  1371. set(source_default "${prefix}/src/${name}")
  1372. set(binary_default "${prefix}/src/${name}-build")
  1373. set(stamp_default "${prefix}/src/${name}-stamp")
  1374. set(install_default "${prefix}")
  1375. else()
  1376. set(tmp_default "${base}/tmp/${name}")
  1377. set(download_default "${base}/Download/${name}")
  1378. set(source_default "${base}/Source/${name}")
  1379. set(binary_default "${base}/Build/${name}")
  1380. set(stamp_default "${base}/Stamp/${name}")
  1381. set(install_default "${base}/Install/${name}")
  1382. endif()
  1383. get_property(build_in_source TARGET ${name} PROPERTY _EP_BUILD_IN_SOURCE)
  1384. if(build_in_source)
  1385. get_property(have_binary_dir TARGET ${name} PROPERTY _EP_BINARY_DIR SET)
  1386. if(have_binary_dir)
  1387. message(FATAL_ERROR
  1388. "External project ${name} has both BINARY_DIR and BUILD_IN_SOURCE!")
  1389. endif()
  1390. endif()
  1391. set(top "${CMAKE_CURRENT_BINARY_DIR}")
  1392. # Apply defaults and convert to absolute paths.
  1393. set(places stamp download source binary install tmp)
  1394. foreach(var ${places})
  1395. string(TOUPPER "${var}" VAR)
  1396. get_property(${var}_dir TARGET ${name} PROPERTY _EP_${VAR}_DIR)
  1397. if(NOT ${var}_dir)
  1398. set(${var}_dir "${${var}_default}")
  1399. endif()
  1400. if(NOT IS_ABSOLUTE "${${var}_dir}")
  1401. get_filename_component(${var}_dir "${top}/${${var}_dir}" ABSOLUTE)
  1402. endif()
  1403. set_property(TARGET ${name} PROPERTY _EP_${VAR}_DIR "${${var}_dir}")
  1404. endforeach()
  1405. # Special case for default log directory based on stamp directory.
  1406. get_property(log_dir TARGET ${name} PROPERTY _EP_LOG_DIR)
  1407. if(NOT log_dir)
  1408. get_property(log_dir TARGET ${name} PROPERTY _EP_STAMP_DIR)
  1409. endif()
  1410. if(NOT IS_ABSOLUTE "${log_dir}")
  1411. get_filename_component(log_dir "${top}/${log_dir}" ABSOLUTE)
  1412. endif()
  1413. set_property(TARGET ${name} PROPERTY _EP_LOG_DIR "${log_dir}")
  1414. get_property(source_subdir TARGET ${name} PROPERTY _EP_SOURCE_SUBDIR)
  1415. if(NOT source_subdir)
  1416. set_property(TARGET ${name} PROPERTY _EP_SOURCE_SUBDIR "")
  1417. elseif(IS_ABSOLUTE "${source_subdir}")
  1418. message(FATAL_ERROR
  1419. "External project ${name} has non-relative SOURCE_SUBDIR!")
  1420. else()
  1421. # Prefix with a slash so that when appended to the source directory, it
  1422. # behaves as expected.
  1423. set_property(TARGET ${name} PROPERTY _EP_SOURCE_SUBDIR "/${source_subdir}")
  1424. endif()
  1425. if(build_in_source)
  1426. get_property(source_dir TARGET ${name} PROPERTY _EP_SOURCE_DIR)
  1427. if(source_subdir)
  1428. set_property(TARGET ${name} PROPERTY _EP_BINARY_DIR "${source_dir}/${source_subdir}")
  1429. else()
  1430. set_property(TARGET ${name} PROPERTY _EP_BINARY_DIR "${source_dir}")
  1431. endif()
  1432. endif()
  1433. # Make the directories at CMake configure time *and* add a custom command
  1434. # to make them at build time. They need to exist at makefile generation
  1435. # time for Borland make and wmake so that CMake may generate makefiles
  1436. # with "cd C:\short\paths\with\no\spaces" commands in them.
  1437. #
  1438. # Additionally, the add_custom_command is still used in case somebody
  1439. # removes one of the necessary directories and tries to rebuild without
  1440. # re-running cmake.
  1441. foreach(var ${places})
  1442. string(TOUPPER "${var}" VAR)
  1443. get_property(dir TARGET ${name} PROPERTY _EP_${VAR}_DIR)
  1444. file(MAKE_DIRECTORY "${dir}")
  1445. if(NOT EXISTS "${dir}")
  1446. message(FATAL_ERROR "dir '${dir}' does not exist after file(MAKE_DIRECTORY)")
  1447. endif()
  1448. endforeach()
  1449. endfunction()
  1450. # IMPORTANT: this MUST be a macro and not a function because of the
  1451. # in-place replacements that occur in each ${var}
  1452. #
  1453. macro(_ep_replace_location_tags target_name)
  1454. set(vars ${ARGN})
  1455. foreach(var ${vars})
  1456. if(${var})
  1457. foreach(dir SOURCE_DIR SOURCE_SUBDIR BINARY_DIR INSTALL_DIR TMP_DIR DOWNLOAD_DIR DOWNLOADED_FILE LOG_DIR)
  1458. get_property(val TARGET ${target_name} PROPERTY _EP_${dir})
  1459. string(REPLACE "<${dir}>" "${val}" ${var} "${${var}}")
  1460. endforeach()
  1461. endif()
  1462. endforeach()
  1463. endmacro()
  1464. function(_ep_command_line_to_initial_cache var args force)
  1465. set(script_initial_cache "")
  1466. set(regex "^([^:]+):([^=]+)=(.*)$")
  1467. set(setArg "")
  1468. set(forceArg "")
  1469. if(force)
  1470. set(forceArg "FORCE")
  1471. endif()
  1472. foreach(line ${args})
  1473. if("${line}" MATCHES "^-D(.*)")
  1474. set(line "${CMAKE_MATCH_1}")
  1475. if(NOT "${setArg}" STREQUAL "")
  1476. # This is required to build up lists in variables, or complete an entry
  1477. string(APPEND setArg "${accumulator}\" CACHE ${type} \"Initial cache\" ${forceArg})")
  1478. string(APPEND script_initial_cache "\n${setArg}")
  1479. set(accumulator "")
  1480. set(setArg "")
  1481. endif()
  1482. if("${line}" MATCHES "${regex}")
  1483. set(name "${CMAKE_MATCH_1}")
  1484. set(type "${CMAKE_MATCH_2}")
  1485. set(value "${CMAKE_MATCH_3}")
  1486. set(setArg "set(${name} \"${value}")
  1487. else()
  1488. message(WARNING "Line '${line}' does not match regex. Ignoring.")
  1489. endif()
  1490. else()
  1491. # Assume this is a list to append to the last var
  1492. string(APPEND accumulator ";${line}")
  1493. endif()
  1494. endforeach()
  1495. # Catch the final line of the args
  1496. if(NOT "${setArg}" STREQUAL "")
  1497. string(APPEND setArg "${accumulator}\" CACHE ${type} \"Initial cache\" ${forceArg})")
  1498. string(APPEND script_initial_cache "\n${setArg}")
  1499. endif()
  1500. set(${var} ${script_initial_cache} PARENT_SCOPE)
  1501. endfunction()
  1502. function(_ep_write_initial_cache target_name script_filename script_initial_cache)
  1503. # Write out values into an initial cache, that will be passed to CMake with -C
  1504. # Replace location tags.
  1505. _ep_replace_location_tags(${target_name} script_initial_cache)
  1506. _ep_replace_location_tags(${target_name} script_filename)
  1507. # Replace list separators.
  1508. get_property(sep TARGET ${target_name} PROPERTY _EP_LIST_SEPARATOR)
  1509. if(sep AND script_initial_cache)
  1510. string(REPLACE "${sep}" ";" script_initial_cache "${script_initial_cache}")
  1511. endif()
  1512. # Write out the initial cache file to the location specified.
  1513. file(GENERATE OUTPUT "${script_filename}" CONTENT "${script_initial_cache}")
  1514. endfunction()
  1515. function(ExternalProject_Get_Property name)
  1516. foreach(var ${ARGN})
  1517. string(TOUPPER "${var}" VAR)
  1518. get_property(is_set TARGET ${name} PROPERTY _EP_${VAR} SET)
  1519. if(NOT is_set)
  1520. message(FATAL_ERROR "External project \"${name}\" has no ${var}")
  1521. endif()
  1522. get_property(${var} TARGET ${name} PROPERTY _EP_${VAR})
  1523. set(${var} "${${var}}" PARENT_SCOPE)
  1524. endforeach()
  1525. endfunction()
  1526. function(_ep_get_configure_command_id name cfg_cmd_id_var)
  1527. get_target_property(cmd ${name} _EP_CONFIGURE_COMMAND)
  1528. if(cmd STREQUAL "")
  1529. # Explicit empty string means no configure step for this project
  1530. set(${cfg_cmd_id_var} "none" PARENT_SCOPE)
  1531. else()
  1532. if(NOT cmd)
  1533. # Default is "use cmake":
  1534. set(${cfg_cmd_id_var} "cmake" PARENT_SCOPE)
  1535. else()
  1536. # Otherwise we have to analyze the value:
  1537. if(cmd MATCHES "^[^;]*/configure")
  1538. set(${cfg_cmd_id_var} "configure" PARENT_SCOPE)
  1539. elseif(cmd MATCHES "^[^;]*/cmake" AND NOT cmd MATCHES ";-[PE];")
  1540. set(${cfg_cmd_id_var} "cmake" PARENT_SCOPE)
  1541. elseif(cmd MATCHES "config")
  1542. set(${cfg_cmd_id_var} "configure" PARENT_SCOPE)
  1543. else()
  1544. set(${cfg_cmd_id_var} "unknown:${cmd}" PARENT_SCOPE)
  1545. endif()
  1546. endif()
  1547. endif()
  1548. endfunction()
  1549. function(_ep_get_build_command name step cmd_var)
  1550. set(cmd "")
  1551. set(args)
  1552. _ep_get_configure_command_id(${name} cfg_cmd_id)
  1553. if(cfg_cmd_id STREQUAL "cmake")
  1554. # CMake project. Select build command based on generator.
  1555. get_target_property(cmake_generator ${name} _EP_CMAKE_GENERATOR)
  1556. if("${CMAKE_GENERATOR}" MATCHES "Make" AND
  1557. ("${cmake_generator}" MATCHES "Make" OR NOT cmake_generator))
  1558. # The project uses the same Makefile generator. Use recursive make.
  1559. set(cmd "$(MAKE)")
  1560. if(step STREQUAL "INSTALL")
  1561. set(args install)
  1562. endif()
  1563. if("x${step}x" STREQUAL "xTESTx")
  1564. set(args test)
  1565. endif()
  1566. else()
  1567. # Drive the project with "cmake --build".
  1568. get_target_property(cmake_command ${name} _EP_CMAKE_COMMAND)
  1569. if(cmake_command)
  1570. set(cmd "${cmake_command}")
  1571. else()
  1572. set(cmd "${CMAKE_COMMAND}")
  1573. endif()
  1574. set(args --build ".")
  1575. get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
  1576. if(_isMultiConfig)
  1577. if (CMAKE_CFG_INTDIR AND
  1578. NOT CMAKE_CFG_INTDIR STREQUAL "." AND
  1579. NOT CMAKE_CFG_INTDIR MATCHES "\\$")
  1580. # CMake 3.4 and below used the CMAKE_CFG_INTDIR placeholder value
  1581. # provided by multi-configuration generators. Some projects were
  1582. # taking advantage of that undocumented implementation detail to
  1583. # specify a specific configuration here. They should use
  1584. # BUILD_COMMAND to change the default command instead, but for
  1585. # compatibility honor the value.
  1586. set(config ${CMAKE_CFG_INTDIR})
  1587. message(AUTHOR_WARNING "CMAKE_CFG_INTDIR should not be set by project code.\n"
  1588. "To get a non-default build command, use the BUILD_COMMAND option.")
  1589. else()
  1590. set(config $<CONFIG>)
  1591. endif()
  1592. list(APPEND args --config ${config})
  1593. endif()
  1594. if(step STREQUAL "INSTALL")
  1595. list(APPEND args --target install)
  1596. endif()
  1597. # But for "TEST" drive the project with corresponding "ctest".
  1598. if("x${step}x" STREQUAL "xTESTx")
  1599. string(REGEX REPLACE "^(.*/)cmake([^/]*)$" "\\1ctest\\2" cmd "${cmd}")
  1600. set(args "")
  1601. if(_isMultiConfig)
  1602. list(APPEND args -C ${config})
  1603. endif()
  1604. endif()
  1605. endif()
  1606. else()
  1607. # Non-CMake project. Guess "make" and "make install" and "make test".
  1608. if("${CMAKE_GENERATOR}" MATCHES "Makefiles")
  1609. # Try to get the parallel arguments
  1610. set(cmd "$(MAKE)")
  1611. else()
  1612. set(cmd "make")
  1613. endif()
  1614. if(step STREQUAL "INSTALL")
  1615. set(args install)
  1616. endif()
  1617. if("x${step}x" STREQUAL "xTESTx")
  1618. set(args test)
  1619. endif()
  1620. endif()
  1621. # Use user-specified arguments instead of default arguments, if any.
  1622. get_property(have_args TARGET ${name} PROPERTY _EP_${step}_ARGS SET)
  1623. if(have_args)
  1624. get_target_property(args ${name} _EP_${step}_ARGS)
  1625. endif()
  1626. if(NOT "${args}" STREQUAL "")
  1627. # args could have empty items, so we must quote it to prevent them
  1628. # from being silently removed
  1629. list(APPEND cmd "${args}")
  1630. endif()
  1631. set(${cmd_var} "${cmd}" PARENT_SCOPE)
  1632. endfunction()
  1633. function(_ep_write_log_script name step cmd_var)
  1634. ExternalProject_Get_Property(${name} log_dir)
  1635. ExternalProject_Get_Property(${name} stamp_dir)
  1636. set(command "${${cmd_var}}")
  1637. set(make "")
  1638. set(code_cygpath_make "")
  1639. if(command MATCHES "^\\$\\(MAKE\\)")
  1640. # GNU make recognizes the string "$(MAKE)" as recursive make, so
  1641. # ensure that it appears directly in the makefile.
  1642. string(REGEX REPLACE "^\\$\\(MAKE\\)" "\${make}" command "${command}")
  1643. set(make "-Dmake=$(MAKE)")
  1644. if(WIN32 AND NOT CYGWIN)
  1645. set(code_cygpath_make "
  1646. if(\${make} MATCHES \"^/\")
  1647. execute_process(
  1648. COMMAND cygpath -w \${make}
  1649. OUTPUT_VARIABLE cygpath_make
  1650. ERROR_VARIABLE cygpath_make
  1651. RESULT_VARIABLE cygpath_error
  1652. OUTPUT_STRIP_TRAILING_WHITESPACE
  1653. )
  1654. if(NOT cygpath_error)
  1655. set(make \${cygpath_make})
  1656. endif()
  1657. endif()
  1658. ")
  1659. endif()
  1660. endif()
  1661. set(config "")
  1662. if("${CMAKE_CFG_INTDIR}" MATCHES "^\\$")
  1663. string(REPLACE "${CMAKE_CFG_INTDIR}" "\${config}" command "${command}")
  1664. set(config "-Dconfig=${CMAKE_CFG_INTDIR}")
  1665. endif()
  1666. # Wrap multiple 'COMMAND' lines up into a second-level wrapper
  1667. # script so all output can be sent to one log file.
  1668. if(command MATCHES "(^|;)COMMAND;")
  1669. set(code_execute_process "
  1670. ${code_cygpath_make}
  1671. execute_process(COMMAND \${command} RESULT_VARIABLE result)
  1672. if(result)
  1673. set(msg \"Command failed (\${result}):\\n\")
  1674. foreach(arg IN LISTS command)
  1675. set(msg \"\${msg} '\${arg}'\")
  1676. endforeach()
  1677. message(FATAL_ERROR \"\${msg}\")
  1678. endif()
  1679. ")
  1680. set(code "")
  1681. set(cmd "")
  1682. set(sep "")
  1683. foreach(arg IN LISTS command)
  1684. if("x${arg}" STREQUAL "xCOMMAND")
  1685. if(NOT "x${cmd}" STREQUAL "x")
  1686. string(APPEND code "set(command \"${cmd}\")${code_execute_process}")
  1687. endif()
  1688. set(cmd "")
  1689. set(sep "")
  1690. else()
  1691. string(APPEND cmd "${sep}${arg}")
  1692. set(sep ";")
  1693. endif()
  1694. endforeach()
  1695. string(APPEND code "set(command \"${cmd}\")${code_execute_process}")
  1696. file(GENERATE OUTPUT "${stamp_dir}/${name}-${step}-$<CONFIG>-impl.cmake" CONTENT "${code}")
  1697. set(command ${CMAKE_COMMAND} "-Dmake=\${make}" "-Dconfig=\${config}" -P ${stamp_dir}/${name}-${step}-$<CONFIG>-impl.cmake)
  1698. endif()
  1699. # Wrap the command in a script to log output to files.
  1700. set(script ${stamp_dir}/${name}-${step}-$<CONFIG>.cmake)
  1701. set(logbase ${log_dir}/${name}-${step})
  1702. get_property(log_merged TARGET ${name} PROPERTY _EP_LOG_MERGED_STDOUTERR)
  1703. get_property(log_output_on_failure TARGET ${name} PROPERTY _EP_LOG_OUTPUT_ON_FAILURE)
  1704. if (log_merged)
  1705. set(stdout_log "${logbase}.log")
  1706. set(stderr_log "${logbase}.log")
  1707. else()
  1708. set(stdout_log "${logbase}-out.log")
  1709. set(stderr_log "${logbase}-err.log")
  1710. endif()
  1711. set(code "
  1712. cmake_minimum_required(VERSION 3.15)
  1713. ${code_cygpath_make}
  1714. set(command \"${command}\")
  1715. set(log_merged \"${log_merged}\")
  1716. set(log_output_on_failure \"${log_output_on_failure}\")
  1717. set(stdout_log \"${stdout_log}\")
  1718. set(stderr_log \"${stderr_log}\")
  1719. execute_process(
  1720. COMMAND \${command}
  1721. RESULT_VARIABLE result
  1722. OUTPUT_FILE \"\${stdout_log}\"
  1723. ERROR_FILE \"\${stderr_log}\"
  1724. )
  1725. macro(read_up_to_max_size log_file output_var)
  1726. file(SIZE \${log_file} determined_size)
  1727. set(max_size 10240)
  1728. if (determined_size GREATER max_size)
  1729. math(EXPR seek_position \"\${determined_size} - \${max_size}\")
  1730. file(READ \${log_file} \${output_var} OFFSET \${seek_position})
  1731. set(\${output_var} \"...skipping to end...\\n\${\${output_var}}\")
  1732. else()
  1733. file(READ \${log_file} \${output_var})
  1734. endif()
  1735. endmacro()
  1736. if(result)
  1737. set(msg \"Command failed: \${result}\\n\")
  1738. foreach(arg IN LISTS command)
  1739. set(msg \"\${msg} '\${arg}'\")
  1740. endforeach()
  1741. if (\${log_merged})
  1742. set(msg \"\${msg}\\nSee also\\n \${stderr_log}\")
  1743. else()
  1744. set(msg \"\${msg}\\nSee also\\n ${logbase}-*.log\")
  1745. endif()
  1746. if (\${log_output_on_failure})
  1747. message(SEND_ERROR \"\${msg}\")
  1748. if (\${log_merged})
  1749. read_up_to_max_size(\"\${stderr_log}\" error_log_contents)
  1750. message(STATUS \"Log output is:\\n\${error_log_contents}\")
  1751. else()
  1752. read_up_to_max_size(\"\${stdout_log}\" out_log_contents)
  1753. read_up_to_max_size(\"\${stderr_log}\" err_log_contents)
  1754. message(STATUS \"stdout output is:\\n\${out_log_contents}\")
  1755. message(STATUS \"stderr output is:\\n\${err_log_contents}\")
  1756. endif()
  1757. message(FATAL_ERROR \"Stopping after outputting logs.\")
  1758. else()
  1759. message(FATAL_ERROR \"\${msg}\")
  1760. endif()
  1761. else()
  1762. if(NOT \"${CMAKE_GENERATOR}\" MATCHES \"Ninja\")
  1763. set(msg \"${name} ${step} command succeeded. See also ${logbase}-*.log\")
  1764. message(STATUS \"\${msg}\")
  1765. endif()
  1766. endif()
  1767. ")
  1768. file(GENERATE OUTPUT "${script}" CONTENT "${code}")
  1769. set(command ${CMAKE_COMMAND} ${make} ${config} -P ${script})
  1770. set(${cmd_var} "${command}" PARENT_SCOPE)
  1771. endfunction()
  1772. # This module used to use "/${CMAKE_CFG_INTDIR}" directly and produced
  1773. # makefiles with "/./" in paths for custom command dependencies. Which
  1774. # resulted in problems with parallel make -j invocations.
  1775. #
  1776. # This function was added so that the suffix (search below for ${cfgdir}) is
  1777. # only set to "/${CMAKE_CFG_INTDIR}" when ${CMAKE_CFG_INTDIR} is not going to
  1778. # be "." (multi-configuration build systems like Visual Studio and Xcode...)
  1779. #
  1780. function(_ep_get_configuration_subdir_suffix suffix_var)
  1781. set(suffix "")
  1782. get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
  1783. if(_isMultiConfig)
  1784. set(suffix "/${CMAKE_CFG_INTDIR}")
  1785. endif()
  1786. set(${suffix_var} "${suffix}" PARENT_SCOPE)
  1787. endfunction()
  1788. function(_ep_get_step_stampfile name step stampfile_var)
  1789. ExternalProject_Get_Property(${name} stamp_dir)
  1790. _ep_get_configuration_subdir_suffix(cfgdir)
  1791. set(stampfile "${stamp_dir}${cfgdir}/${name}-${step}")
  1792. set(${stampfile_var} "${stampfile}" PARENT_SCOPE)
  1793. endfunction()
  1794. function(_ep_get_complete_stampfile name stampfile_var)
  1795. set(cmf_dir ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles)
  1796. _ep_get_configuration_subdir_suffix(cfgdir)
  1797. set(stampfile "${cmf_dir}${cfgdir}/${name}-complete")
  1798. set(${stampfile_var} ${stampfile} PARENT_SCOPE)
  1799. endfunction()
  1800. function(_ep_step_add_target name step no_deps)
  1801. if(TARGET ${name}-${step})
  1802. return()
  1803. endif()
  1804. get_property(cmp0114 TARGET ${name} PROPERTY _EP_CMP0114)
  1805. _ep_get_step_stampfile(${name} ${step} stamp_file)
  1806. cmake_policy(PUSH)
  1807. if(cmp0114 STREQUAL "NEW")
  1808. # To implement CMP0114 NEW behavior with Makefile generators,
  1809. # we need CMP0113 NEW behavior.
  1810. cmake_policy(SET CMP0113 NEW)
  1811. endif()
  1812. add_custom_target(${name}-${step}
  1813. DEPENDS ${stamp_file})
  1814. cmake_policy(POP)
  1815. set_property(TARGET ${name}-${step} PROPERTY _EP_IS_EXTERNAL_PROJECT_STEP 1)
  1816. set_property(TARGET ${name}-${step} PROPERTY LABELS ${name})
  1817. set_property(TARGET ${name}-${step} PROPERTY FOLDER "ExternalProjectTargets/${name}")
  1818. if(cmp0114 STREQUAL "NEW")
  1819. # Add target-level dependencies for the step.
  1820. get_property(exclude_from_main TARGET ${name} PROPERTY _EP_${step}_EXCLUDE_FROM_MAIN)
  1821. if(NOT exclude_from_main)
  1822. add_dependencies(${name} ${name}-${step})
  1823. endif()
  1824. _ep_step_add_target_dependencies(${name} ${step} ${step})
  1825. _ep_step_add_target_dependents(${name} ${step} ${step})
  1826. get_property(independent TARGET ${name} PROPERTY _EP_${step}_INDEPENDENT)
  1827. else()
  1828. if(no_deps AND "${step}" MATCHES "^(configure|build|install|test)$")
  1829. message(AUTHOR_WARNING "Using NO_DEPENDS for \"${step}\" step might break parallel builds")
  1830. endif()
  1831. set(independent ${no_deps})
  1832. endif()
  1833. # Depend on other external projects (target-level).
  1834. if(NOT independent)
  1835. get_property(deps TARGET ${name} PROPERTY _EP_DEPENDS)
  1836. foreach(arg IN LISTS deps)
  1837. add_dependencies(${name}-${step} ${arg})
  1838. endforeach()
  1839. endif()
  1840. endfunction()
  1841. function(_ep_step_add_target_dependencies name step node)
  1842. get_property(dependees TARGET ${name} PROPERTY _EP_${node}_INTERNAL_DEPENDEES)
  1843. list(REMOVE_DUPLICATES dependees)
  1844. foreach(dependee IN LISTS dependees)
  1845. get_property(exclude_from_main TARGET ${name} PROPERTY _EP_${step}_EXCLUDE_FROM_MAIN)
  1846. get_property(dependee_dependers TARGET ${name} PROPERTY _EP_${dependee}_INTERNAL_DEPENDERS)
  1847. if(exclude_from_main OR dependee_dependers MATCHES ";")
  1848. # The step on which our step target depends itself has
  1849. # dependents in multiple targes. It needs a step target too
  1850. # so that there is a unique place for its custom command.
  1851. _ep_step_add_target("${name}" "${dependee}" "FALSE")
  1852. endif()
  1853. if(TARGET ${name}-${dependee})
  1854. add_dependencies(${name}-${step} ${name}-${dependee})
  1855. else()
  1856. _ep_step_add_target_dependencies(${name} ${step} ${dependee})
  1857. endif()
  1858. endforeach()
  1859. endfunction()
  1860. function(_ep_step_add_target_dependents name step node)
  1861. get_property(dependers TARGET ${name} PROPERTY _EP_${node}_INTERNAL_DEPENDERS)
  1862. list(REMOVE_DUPLICATES dependers)
  1863. foreach(depender IN LISTS dependers)
  1864. if(TARGET ${name}-${depender})
  1865. add_dependencies(${name}-${depender} ${name}-${step})
  1866. else()
  1867. _ep_step_add_target_dependents(${name} ${step} ${depender})
  1868. endif()
  1869. endforeach()
  1870. endfunction()
  1871. function(ExternalProject_Add_StepTargets name)
  1872. get_property(cmp0114 TARGET ${name} PROPERTY _EP_CMP0114)
  1873. set(steps ${ARGN})
  1874. if(ARGC GREATER 1 AND "${ARGV1}" STREQUAL "NO_DEPENDS")
  1875. set(no_deps 1)
  1876. list(REMOVE_AT steps 0)
  1877. else()
  1878. set(no_deps 0)
  1879. endif()
  1880. if(cmp0114 STREQUAL "NEW")
  1881. if(no_deps)
  1882. message(FATAL_ERROR
  1883. "The 'NO_DEPENDS' option is no longer allowed. "
  1884. "It has been superseded by the per-step 'INDEPENDENT' option. "
  1885. "See policy CMP0114."
  1886. )
  1887. endif()
  1888. elseif(cmp0114 STREQUAL "")
  1889. cmake_policy(GET_WARNING CMP0114 _cmp0114_warning)
  1890. string(APPEND _cmp0114_warning "\n"
  1891. "ExternalProject target '${name}' would depend on the targets for "
  1892. "step(s) '${steps}' under policy CMP0114, but this is being left out "
  1893. "for compatibility since the policy is not set."
  1894. )
  1895. if(no_deps)
  1896. string(APPEND _cmp0114_warning
  1897. " Also, the NO_DEPENDS option is deprecated in favor of policy CMP0114."
  1898. )
  1899. endif()
  1900. message(AUTHOR_WARNING "${_cmp0114_warning}")
  1901. endif()
  1902. foreach(step ${steps})
  1903. _ep_step_add_target("${name}" "${step}" "${no_deps}")
  1904. endforeach()
  1905. endfunction()
  1906. function(ExternalProject_Add_Step name step)
  1907. get_property(cmp0114 TARGET ${name} PROPERTY _EP_CMP0114)
  1908. _ep_get_complete_stampfile(${name} complete_stamp_file)
  1909. _ep_get_step_stampfile(${name} ${step} stamp_file)
  1910. set(keywords
  1911. COMMAND
  1912. COMMENT
  1913. DEPENDEES
  1914. DEPENDERS
  1915. DEPENDS
  1916. INDEPENDENT
  1917. BYPRODUCTS
  1918. ALWAYS
  1919. EXCLUDE_FROM_MAIN
  1920. WORKING_DIRECTORY
  1921. LOG
  1922. USES_TERMINAL
  1923. )
  1924. _ep_parse_arguments(ExternalProject_Add_Step "${keywords}"
  1925. ${name} _EP_${step}_ "${ARGN}")
  1926. get_property(independent TARGET ${name} PROPERTY _EP_${step}_INDEPENDENT)
  1927. if(independent STREQUAL "")
  1928. set(independent FALSE)
  1929. set_property(TARGET ${name} PROPERTY _EP_${step}_INDEPENDENT "${independent}")
  1930. endif()
  1931. get_property(exclude_from_main TARGET ${name} PROPERTY _EP_${step}_EXCLUDE_FROM_MAIN)
  1932. if(NOT exclude_from_main)
  1933. add_custom_command(APPEND
  1934. OUTPUT ${complete_stamp_file}
  1935. DEPENDS ${stamp_file}
  1936. )
  1937. endif()
  1938. # Steps depending on this step.
  1939. get_property(dependers TARGET ${name} PROPERTY _EP_${step}_DEPENDERS)
  1940. set_property(TARGET ${name} APPEND PROPERTY _EP_${step}_INTERNAL_DEPENDERS ${dependers})
  1941. foreach(depender IN LISTS dependers)
  1942. set_property(TARGET ${name} APPEND PROPERTY _EP_${depender}_INTERNAL_DEPENDEES ${step})
  1943. _ep_get_step_stampfile(${name} ${depender} depender_stamp_file)
  1944. add_custom_command(APPEND
  1945. OUTPUT ${depender_stamp_file}
  1946. DEPENDS ${stamp_file}
  1947. )
  1948. if(cmp0114 STREQUAL "NEW" AND NOT independent)
  1949. get_property(dep_independent TARGET ${name} PROPERTY _EP_${depender}_INDEPENDENT)
  1950. if(dep_independent)
  1951. message(FATAL_ERROR "ExternalProject '${name}' step '${depender}' is marked INDEPENDENT "
  1952. "but depends on step '${step}' that is not marked INDEPENDENT.")
  1953. endif()
  1954. endif()
  1955. endforeach()
  1956. # Dependencies on files.
  1957. get_property(depends TARGET ${name} PROPERTY _EP_${step}_DEPENDS)
  1958. # Byproducts of the step.
  1959. get_property(byproducts TARGET ${name} PROPERTY _EP_${step}_BYPRODUCTS)
  1960. # Dependencies on steps.
  1961. get_property(dependees TARGET ${name} PROPERTY _EP_${step}_DEPENDEES)
  1962. set_property(TARGET ${name} APPEND PROPERTY _EP_${step}_INTERNAL_DEPENDEES ${dependees})
  1963. foreach(dependee IN LISTS dependees)
  1964. set_property(TARGET ${name} APPEND PROPERTY _EP_${dependee}_INTERNAL_DEPENDERS ${step})
  1965. _ep_get_step_stampfile(${name} ${dependee} dependee_stamp_file)
  1966. list(APPEND depends ${dependee_stamp_file})
  1967. if(cmp0114 STREQUAL "NEW" AND independent)
  1968. get_property(dep_independent TARGET ${name} PROPERTY _EP_${dependee}_INDEPENDENT)
  1969. if(NOT dep_independent)
  1970. message(FATAL_ERROR "ExternalProject '${name}' step '${step}' is marked INDEPENDENT "
  1971. "but depends on step '${dependee}' that is not marked INDEPENDENT.")
  1972. endif()
  1973. endif()
  1974. endforeach()
  1975. # The command to run.
  1976. get_property(command TARGET ${name} PROPERTY _EP_${step}_COMMAND)
  1977. if(command)
  1978. set(comment "Performing ${step} step for '${name}'")
  1979. else()
  1980. set(comment "No ${step} step for '${name}'")
  1981. endif()
  1982. get_property(work_dir TARGET ${name} PROPERTY _EP_${step}_WORKING_DIRECTORY)
  1983. # Replace list separators.
  1984. get_property(sep TARGET ${name} PROPERTY _EP_LIST_SEPARATOR)
  1985. if(sep AND command)
  1986. string(REPLACE "${sep}" "\\;" command "${command}")
  1987. endif()
  1988. # Replace location tags.
  1989. _ep_replace_location_tags(${name} comment command work_dir byproducts)
  1990. # Custom comment?
  1991. get_property(comment_set TARGET ${name} PROPERTY _EP_${step}_COMMENT SET)
  1992. if(comment_set)
  1993. get_property(comment TARGET ${name} PROPERTY _EP_${step}_COMMENT)
  1994. endif()
  1995. # Uses terminal?
  1996. get_property(uses_terminal TARGET ${name} PROPERTY _EP_${step}_USES_TERMINAL)
  1997. if(uses_terminal)
  1998. set(uses_terminal USES_TERMINAL)
  1999. else()
  2000. set(uses_terminal "")
  2001. endif()
  2002. # Run every time?
  2003. get_property(always TARGET ${name} PROPERTY _EP_${step}_ALWAYS)
  2004. if(always)
  2005. set_property(SOURCE ${stamp_file} PROPERTY SYMBOLIC 1)
  2006. set(touch)
  2007. # Remove any existing stamp in case the option changed in an existing tree.
  2008. get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
  2009. if(_isMultiConfig)
  2010. foreach(cfg ${CMAKE_CONFIGURATION_TYPES})
  2011. string(REPLACE "/${CMAKE_CFG_INTDIR}" "/${cfg}" stamp_file_config "${stamp_file}")
  2012. file(REMOVE ${stamp_file_config})
  2013. endforeach()
  2014. else()
  2015. file(REMOVE ${stamp_file})
  2016. endif()
  2017. else()
  2018. set(touch ${CMAKE_COMMAND} -E touch ${stamp_file})
  2019. endif()
  2020. # Wrap with log script?
  2021. get_property(log TARGET ${name} PROPERTY _EP_${step}_LOG)
  2022. if(command AND log)
  2023. _ep_write_log_script(${name} ${step} command)
  2024. endif()
  2025. if("${command}" STREQUAL "")
  2026. # Some generators (i.e. Xcode) will not generate a file level target
  2027. # if no command is set, and therefore the dependencies on this
  2028. # target will be broken.
  2029. # The empty command is replaced by an echo command here in order to
  2030. # avoid this issue.
  2031. set(command ${CMAKE_COMMAND} -E echo_append)
  2032. endif()
  2033. set(__cmdQuoted)
  2034. foreach(__item IN LISTS command)
  2035. string(APPEND __cmdQuoted " [==[${__item}]==]")
  2036. endforeach()
  2037. cmake_language(EVAL CODE "
  2038. add_custom_command(
  2039. OUTPUT \${stamp_file}
  2040. BYPRODUCTS \${byproducts}
  2041. COMMENT \${comment}
  2042. COMMAND ${__cmdQuoted}
  2043. COMMAND \${touch}
  2044. DEPENDS \${depends}
  2045. WORKING_DIRECTORY \${work_dir}
  2046. VERBATIM
  2047. ${uses_terminal}
  2048. )"
  2049. )
  2050. set_property(TARGET ${name} APPEND PROPERTY _EP_STEPS ${step})
  2051. # Add custom "step target"?
  2052. get_property(step_targets TARGET ${name} PROPERTY _EP_STEP_TARGETS)
  2053. if(NOT step_targets)
  2054. get_property(step_targets DIRECTORY PROPERTY EP_STEP_TARGETS)
  2055. endif()
  2056. foreach(st ${step_targets})
  2057. if("${st}" STREQUAL "${step}")
  2058. _ep_step_add_target("${name}" "${step}" "FALSE")
  2059. break()
  2060. endif()
  2061. endforeach()
  2062. get_property(independent_step_targets TARGET ${name} PROPERTY _EP_INDEPENDENT_STEP_TARGETS)
  2063. if(NOT independent_step_targets)
  2064. get_property(independent_step_targets DIRECTORY PROPERTY EP_INDEPENDENT_STEP_TARGETS)
  2065. endif()
  2066. if(cmp0114 STREQUAL "NEW")
  2067. if(independent_step_targets)
  2068. message(FATAL_ERROR
  2069. "ExternalProject '${name}' option 'INDEPENDENT_STEP_TARGETS' is set to\n"
  2070. " ${independent_step_targets}\n"
  2071. "but the option is no longer allowed. "
  2072. "It has been superseded by the per-step 'INDEPENDENT' option. "
  2073. "See policy CMP0114."
  2074. )
  2075. endif()
  2076. else()
  2077. if(independent_step_targets AND cmp0114 STREQUAL "")
  2078. get_property(warned TARGET ${name} PROPERTY _EP_CMP0114_WARNED_INDEPENDENT_STEP_TARGETS)
  2079. if(NOT warned)
  2080. set_property(TARGET ${name} PROPERTY _EP_CMP0114_WARNED_INDEPENDENT_STEP_TARGETS 1)
  2081. cmake_policy(GET_WARNING CMP0114 _cmp0114_warning)
  2082. string(APPEND _cmp0114_warning "\n"
  2083. "ExternalProject '${name}' option INDEPENDENT_STEP_TARGETS is set to\n"
  2084. " ${independent_step_targets}\n"
  2085. "but the option is deprecated in favor of policy CMP0114."
  2086. )
  2087. message(AUTHOR_WARNING "${_cmp0114_warning}")
  2088. endif()
  2089. endif()
  2090. foreach(st ${independent_step_targets})
  2091. if("${st}" STREQUAL "${step}")
  2092. _ep_step_add_target("${name}" "${step}" "TRUE")
  2093. break()
  2094. endif()
  2095. endforeach()
  2096. endif()
  2097. endfunction()
  2098. function(ExternalProject_Add_StepDependencies name step)
  2099. set(dependencies ${ARGN})
  2100. # Sanity checks on "name" and "step".
  2101. if(NOT TARGET ${name})
  2102. message(FATAL_ERROR "Cannot find target \"${name}\". Perhaps it has not yet been created using ExternalProject_Add.")
  2103. endif()
  2104. get_property(type TARGET ${name} PROPERTY TYPE)
  2105. if(NOT type STREQUAL "UTILITY")
  2106. message(FATAL_ERROR "Target \"${name}\" was not generated by ExternalProject_Add.")
  2107. endif()
  2108. get_property(is_ep TARGET ${name} PROPERTY _EP_IS_EXTERNAL_PROJECT)
  2109. if(NOT is_ep)
  2110. message(FATAL_ERROR "Target \"${name}\" was not generated by ExternalProject_Add.")
  2111. endif()
  2112. get_property(steps TARGET ${name} PROPERTY _EP_STEPS)
  2113. list(FIND steps ${step} is_step)
  2114. if(is_step LESS 0)
  2115. message(FATAL_ERROR "External project \"${name}\" does not have a step \"${step}\".")
  2116. endif()
  2117. if(TARGET ${name}-${step})
  2118. get_property(type TARGET ${name}-${step} PROPERTY TYPE)
  2119. if(NOT type STREQUAL "UTILITY")
  2120. message(FATAL_ERROR "Target \"${name}-${step}\" was not generated by ExternalProject_Add_StepTargets.")
  2121. endif()
  2122. get_property(is_ep_step TARGET ${name}-${step} PROPERTY _EP_IS_EXTERNAL_PROJECT_STEP)
  2123. if(NOT is_ep_step)
  2124. message(FATAL_ERROR "Target \"${name}-${step}\" was not generated by ExternalProject_Add_StepTargets.")
  2125. endif()
  2126. endif()
  2127. # Always add file-level dependency, but add target-level dependency
  2128. # only if the target exists for that step.
  2129. _ep_get_step_stampfile(${name} ${step} stamp_file)
  2130. foreach(dep ${dependencies})
  2131. add_custom_command(APPEND
  2132. OUTPUT ${stamp_file}
  2133. DEPENDS ${dep})
  2134. if(TARGET ${name}-${step})
  2135. foreach(dep ${dependencies})
  2136. add_dependencies(${name}-${step} ${dep})
  2137. endforeach()
  2138. endif()
  2139. endforeach()
  2140. endfunction()
  2141. function(_ep_add_mkdir_command name)
  2142. ExternalProject_Get_Property(${name}
  2143. source_dir binary_dir install_dir stamp_dir download_dir tmp_dir log_dir)
  2144. _ep_get_configuration_subdir_suffix(cfgdir)
  2145. ExternalProject_Add_Step(${name} mkdir
  2146. INDEPENDENT TRUE
  2147. COMMENT "Creating directories for '${name}'"
  2148. COMMAND ${CMAKE_COMMAND} -E make_directory ${source_dir}
  2149. COMMAND ${CMAKE_COMMAND} -E make_directory ${binary_dir}
  2150. COMMAND ${CMAKE_COMMAND} -E make_directory ${install_dir}
  2151. COMMAND ${CMAKE_COMMAND} -E make_directory ${tmp_dir}
  2152. COMMAND ${CMAKE_COMMAND} -E make_directory ${stamp_dir}${cfgdir}
  2153. COMMAND ${CMAKE_COMMAND} -E make_directory ${download_dir}
  2154. COMMAND ${CMAKE_COMMAND} -E make_directory ${log_dir}
  2155. )
  2156. endfunction()
  2157. function(_ep_is_dir_empty dir empty_var)
  2158. file(GLOB gr "${dir}/*")
  2159. if("${gr}" STREQUAL "")
  2160. set(${empty_var} 1 PARENT_SCOPE)
  2161. else()
  2162. set(${empty_var} 0 PARENT_SCOPE)
  2163. endif()
  2164. endfunction()
  2165. function(_ep_get_git_submodules_recurse git_submodules_recurse)
  2166. # Checks for GIT_SUBMODULES_RECURSE property
  2167. # Default is ON, which sets git_submodules_recurse output variable to "--recursive"
  2168. # Otherwise, the output variable is set to an empty value ""
  2169. get_property(git_submodules_recurse_set TARGET ${name} PROPERTY _EP_GIT_SUBMODULES_RECURSE SET)
  2170. if(NOT git_submodules_recurse_set)
  2171. set(recurseFlag "--recursive")
  2172. else()
  2173. get_property(git_submodules_recurse_value TARGET ${name} PROPERTY _EP_GIT_SUBMODULES_RECURSE)
  2174. if(git_submodules_recurse_value)
  2175. set(recurseFlag "--recursive")
  2176. else()
  2177. set(recurseFlag "")
  2178. endif()
  2179. endif()
  2180. set(${git_submodules_recurse} "${recurseFlag}" PARENT_SCOPE)
  2181. # The git submodule update '--recursive' flag requires git >= v1.6.5
  2182. if(recurseFlag AND GIT_VERSION_STRING VERSION_LESS 1.6.5)
  2183. message(FATAL_ERROR "error: git version 1.6.5 or later required for --recursive flag with 'git submodule ...': GIT_VERSION_STRING='${GIT_VERSION_STRING}'")
  2184. endif()
  2185. endfunction()
  2186. function(_ep_add_download_command name)
  2187. ExternalProject_Get_Property(${name} source_dir stamp_dir download_dir tmp_dir)
  2188. get_property(cmd_set TARGET ${name} PROPERTY _EP_DOWNLOAD_COMMAND SET)
  2189. get_property(cmd TARGET ${name} PROPERTY _EP_DOWNLOAD_COMMAND)
  2190. get_property(cvs_repository TARGET ${name} PROPERTY _EP_CVS_REPOSITORY)
  2191. get_property(svn_repository TARGET ${name} PROPERTY _EP_SVN_REPOSITORY)
  2192. get_property(git_repository TARGET ${name} PROPERTY _EP_GIT_REPOSITORY)
  2193. get_property(hg_repository TARGET ${name} PROPERTY _EP_HG_REPOSITORY )
  2194. get_property(url TARGET ${name} PROPERTY _EP_URL)
  2195. get_property(fname TARGET ${name} PROPERTY _EP_DOWNLOAD_NAME)
  2196. # TODO: Perhaps file:// should be copied to download dir before extraction.
  2197. string(REGEX REPLACE "file://" "" url "${url}")
  2198. set(depends)
  2199. set(comment)
  2200. set(work_dir)
  2201. if(cmd_set)
  2202. set(work_dir ${download_dir})
  2203. elseif(cvs_repository)
  2204. find_package(CVS QUIET)
  2205. if(NOT CVS_EXECUTABLE)
  2206. message(FATAL_ERROR "error: could not find cvs for checkout of ${name}")
  2207. endif()
  2208. get_target_property(cvs_module ${name} _EP_CVS_MODULE)
  2209. if(NOT cvs_module)
  2210. message(FATAL_ERROR "error: no CVS_MODULE")
  2211. endif()
  2212. get_property(cvs_tag TARGET ${name} PROPERTY _EP_CVS_TAG)
  2213. set(repository ${cvs_repository})
  2214. set(module ${cvs_module})
  2215. set(tag ${cvs_tag})
  2216. configure_file(
  2217. "${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in"
  2218. "${stamp_dir}/${name}-cvsinfo.txt"
  2219. @ONLY
  2220. )
  2221. get_filename_component(src_name "${source_dir}" NAME)
  2222. get_filename_component(work_dir "${source_dir}" PATH)
  2223. set(comment "Performing download step (CVS checkout) for '${name}'")
  2224. set(cmd ${CVS_EXECUTABLE} -d ${cvs_repository} -q co ${cvs_tag} -d ${src_name} ${cvs_module})
  2225. list(APPEND depends ${stamp_dir}/${name}-cvsinfo.txt)
  2226. elseif(svn_repository)
  2227. find_package(Subversion QUIET)
  2228. if(NOT Subversion_SVN_EXECUTABLE)
  2229. message(FATAL_ERROR "error: could not find svn for checkout of ${name}")
  2230. endif()
  2231. get_property(svn_revision TARGET ${name} PROPERTY _EP_SVN_REVISION)
  2232. get_property(svn_username TARGET ${name} PROPERTY _EP_SVN_USERNAME)
  2233. get_property(svn_password TARGET ${name} PROPERTY _EP_SVN_PASSWORD)
  2234. get_property(svn_trust_cert TARGET ${name} PROPERTY _EP_SVN_TRUST_CERT)
  2235. set(repository "${svn_repository} user=${svn_username} password=${svn_password}")
  2236. set(module)
  2237. set(tag ${svn_revision})
  2238. configure_file(
  2239. "${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in"
  2240. "${stamp_dir}/${name}-svninfo.txt"
  2241. @ONLY
  2242. )
  2243. get_filename_component(src_name "${source_dir}" NAME)
  2244. get_filename_component(work_dir "${source_dir}" PATH)
  2245. set(comment "Performing download step (SVN checkout) for '${name}'")
  2246. set(svn_user_pw_args "")
  2247. if(DEFINED svn_username)
  2248. set(svn_user_pw_args ${svn_user_pw_args} "--username=${svn_username}")
  2249. endif()
  2250. if(DEFINED svn_password)
  2251. set(svn_user_pw_args ${svn_user_pw_args} "--password=${svn_password}")
  2252. endif()
  2253. if(svn_trust_cert)
  2254. set(svn_trust_cert_args --trust-server-cert)
  2255. endif()
  2256. set(cmd ${Subversion_SVN_EXECUTABLE} co ${svn_repository} ${svn_revision}
  2257. --non-interactive ${svn_trust_cert_args} ${svn_user_pw_args} ${src_name})
  2258. list(APPEND depends ${stamp_dir}/${name}-svninfo.txt)
  2259. elseif(git_repository)
  2260. # FetchContent gives us these directly, so don't try to recompute them
  2261. if(NOT GIT_EXECUTABLE OR NOT GIT_VERSION_STRING)
  2262. unset(CMAKE_MODULE_PATH) # Use CMake builtin find module
  2263. find_package(Git QUIET)
  2264. if(NOT GIT_EXECUTABLE)
  2265. message(FATAL_ERROR "error: could not find git for clone of ${name}")
  2266. endif()
  2267. endif()
  2268. _ep_get_git_submodules_recurse(git_submodules_recurse)
  2269. get_property(git_tag TARGET ${name} PROPERTY _EP_GIT_TAG)
  2270. if(NOT git_tag)
  2271. set(git_tag "master")
  2272. endif()
  2273. set(git_init_submodules TRUE)
  2274. get_property(git_submodules_set TARGET ${name} PROPERTY _EP_GIT_SUBMODULES SET)
  2275. if(git_submodules_set)
  2276. get_property(git_submodules TARGET ${name} PROPERTY _EP_GIT_SUBMODULES)
  2277. if(git_submodules STREQUAL "" AND _EP_CMP0097 STREQUAL "NEW")
  2278. set(git_init_submodules FALSE)
  2279. endif()
  2280. endif()
  2281. get_property(git_remote_name TARGET ${name} PROPERTY _EP_GIT_REMOTE_NAME)
  2282. if(NOT git_remote_name)
  2283. set(git_remote_name "origin")
  2284. endif()
  2285. get_property(tls_verify TARGET ${name} PROPERTY _EP_TLS_VERIFY)
  2286. if("x${tls_verify}" STREQUAL "x" AND DEFINED CMAKE_TLS_VERIFY)
  2287. set(tls_verify "${CMAKE_TLS_VERIFY}")
  2288. endif()
  2289. get_property(git_shallow TARGET ${name} PROPERTY _EP_GIT_SHALLOW)
  2290. get_property(git_progress TARGET ${name} PROPERTY _EP_GIT_PROGRESS)
  2291. get_property(git_config TARGET ${name} PROPERTY _EP_GIT_CONFIG)
  2292. # If git supports it, make checkouts quiet when checking out a git hash.
  2293. # This avoids the very noisy detached head message.
  2294. if(GIT_VERSION_STRING VERSION_GREATER_EQUAL 1.7.7)
  2295. list(PREPEND git_config advice.detachedHead=false)
  2296. endif()
  2297. # For the download step, and the git clone operation, only the repository
  2298. # should be recorded in a configured RepositoryInfo file. If the repo
  2299. # changes, the clone script should be run again. But if only the tag
  2300. # changes, avoid running the clone script again. Let the 'always' running
  2301. # update step checkout the new tag.
  2302. #
  2303. set(repository ${git_repository})
  2304. set(module)
  2305. set(tag ${git_remote_name})
  2306. configure_file(
  2307. "${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in"
  2308. "${stamp_dir}/${name}-gitinfo.txt"
  2309. @ONLY
  2310. )
  2311. get_filename_component(src_name "${source_dir}" NAME)
  2312. get_filename_component(work_dir "${source_dir}" PATH)
  2313. # Since git clone doesn't succeed if the non-empty source_dir exists,
  2314. # create a cmake script to invoke as download command.
  2315. # The script will delete the source directory and then call git clone.
  2316. #
  2317. _ep_write_gitclone_script(${tmp_dir}/${name}-gitclone.cmake ${source_dir}
  2318. ${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}
  2319. ${stamp_dir}/${name}-gitinfo.txt ${stamp_dir}/${name}-gitclone-lastrun.txt "${tls_verify}"
  2320. )
  2321. set(comment "Performing download step (git clone) for '${name}'")
  2322. set(cmd ${CMAKE_COMMAND} -P ${tmp_dir}/${name}-gitclone.cmake)
  2323. list(APPEND depends ${stamp_dir}/${name}-gitinfo.txt)
  2324. elseif(hg_repository)
  2325. find_package(Hg QUIET)
  2326. if(NOT HG_EXECUTABLE)
  2327. message(FATAL_ERROR "error: could not find hg for clone of ${name}")
  2328. endif()
  2329. get_property(hg_tag TARGET ${name} PROPERTY _EP_HG_TAG)
  2330. if(NOT hg_tag)
  2331. set(hg_tag "tip")
  2332. endif()
  2333. # For the download step, and the hg clone operation, only the repository
  2334. # should be recorded in a configured RepositoryInfo file. If the repo
  2335. # changes, the clone script should be run again. But if only the tag
  2336. # changes, avoid running the clone script again. Let the 'always' running
  2337. # update step checkout the new tag.
  2338. #
  2339. set(repository ${hg_repository})
  2340. set(module)
  2341. set(tag)
  2342. configure_file(
  2343. "${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in"
  2344. "${stamp_dir}/${name}-hginfo.txt"
  2345. @ONLY
  2346. )
  2347. get_filename_component(src_name "${source_dir}" NAME)
  2348. get_filename_component(work_dir "${source_dir}" PATH)
  2349. # Since hg clone doesn't succeed if the non-empty source_dir exists,
  2350. # create a cmake script to invoke as download command.
  2351. # The script will delete the source directory and then call hg clone.
  2352. #
  2353. _ep_write_hgclone_script(${tmp_dir}/${name}-hgclone.cmake ${source_dir}
  2354. ${HG_EXECUTABLE} ${hg_repository} ${hg_tag} ${src_name} ${work_dir}
  2355. ${stamp_dir}/${name}-hginfo.txt ${stamp_dir}/${name}-hgclone-lastrun.txt
  2356. )
  2357. set(comment "Performing download step (hg clone) for '${name}'")
  2358. set(cmd ${CMAKE_COMMAND} -P ${tmp_dir}/${name}-hgclone.cmake)
  2359. list(APPEND depends ${stamp_dir}/${name}-hginfo.txt)
  2360. elseif(url)
  2361. get_filename_component(work_dir "${source_dir}" PATH)
  2362. get_property(hash TARGET ${name} PROPERTY _EP_URL_HASH)
  2363. _ep_get_hash_regex(_ep_hash_regex)
  2364. if(hash AND NOT "${hash}" MATCHES "${_ep_hash_regex}")
  2365. _ep_get_hash_algos(_ep_hash_algos)
  2366. list(JOIN _ep_hash_algos "|" _ep_hash_algos)
  2367. message(FATAL_ERROR "URL_HASH is set to\n ${hash}\n"
  2368. "but must be ALGO=value where ALGO is\n ${_ep_hash_algos}\n"
  2369. "and value is a hex string.")
  2370. endif()
  2371. get_property(md5 TARGET ${name} PROPERTY _EP_URL_MD5)
  2372. if(md5 AND NOT "MD5=${md5}" MATCHES "${_ep_hash_regex}")
  2373. message(FATAL_ERROR "URL_MD5 is set to\n ${md5}\nbut must be a hex string.")
  2374. endif()
  2375. if(md5 AND NOT hash)
  2376. set(hash "MD5=${md5}")
  2377. endif()
  2378. set(repository "external project URL")
  2379. set(module "${url}")
  2380. set(tag "${hash}")
  2381. configure_file(
  2382. "${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in"
  2383. "${stamp_dir}/${name}-urlinfo.txt"
  2384. @ONLY
  2385. )
  2386. list(APPEND depends ${stamp_dir}/${name}-urlinfo.txt)
  2387. list(LENGTH url url_list_length)
  2388. if(NOT "${url_list_length}" STREQUAL "1")
  2389. foreach(entry ${url})
  2390. if(NOT "${entry}" MATCHES "^[a-z]+://")
  2391. message(FATAL_ERROR "At least one entry of URL is a path (invalid in a list)")
  2392. endif()
  2393. endforeach()
  2394. if("x${fname}" STREQUAL "x")
  2395. list(GET url 0 fname)
  2396. endif()
  2397. endif()
  2398. if(IS_DIRECTORY "${url}")
  2399. get_filename_component(abs_dir "${url}" ABSOLUTE)
  2400. set(comment "Performing download step (DIR copy) for '${name}'")
  2401. set(cmd ${CMAKE_COMMAND} -E rm -rf ${source_dir}
  2402. COMMAND ${CMAKE_COMMAND} -E copy_directory ${abs_dir} ${source_dir})
  2403. else()
  2404. get_property(no_extract TARGET "${name}" PROPERTY _EP_DOWNLOAD_NO_EXTRACT)
  2405. if("${url}" MATCHES "^[a-z]+://")
  2406. # TODO: Should download and extraction be different steps?
  2407. if("x${fname}" STREQUAL "x")
  2408. set(fname "${url}")
  2409. endif()
  2410. if("${fname}" MATCHES [[([^/\?#]+(\.|=)(7z|tar|tar\.bz2|tar\.gz|tar\.xz|tbz2|tgz|txz|zip))([/?#].*)?$]])
  2411. set(fname "${CMAKE_MATCH_1}")
  2412. elseif(no_extract)
  2413. get_filename_component(fname "${fname}" NAME)
  2414. else()
  2415. # Fall back to a default file name. The actual file name does not
  2416. # matter because it is used only internally and our extraction tool
  2417. # inspects the file content directly. If it turns out the wrong URL
  2418. # was given that will be revealed during the build which is an easier
  2419. # place for users to diagnose than an error here anyway.
  2420. set(fname "archive.tar")
  2421. endif()
  2422. string(REPLACE ";" "-" fname "${fname}")
  2423. set(file ${download_dir}/${fname})
  2424. get_property(timeout TARGET ${name} PROPERTY _EP_TIMEOUT)
  2425. get_property(inactivity_timeout TARGET ${name} PROPERTY _EP_INACTIVITY_TIMEOUT)
  2426. get_property(no_progress TARGET ${name} PROPERTY _EP_DOWNLOAD_NO_PROGRESS)
  2427. get_property(tls_verify TARGET ${name} PROPERTY _EP_TLS_VERIFY)
  2428. get_property(tls_cainfo TARGET ${name} PROPERTY _EP_TLS_CAINFO)
  2429. get_property(netrc TARGET ${name} PROPERTY _EP_NETRC)
  2430. get_property(netrc_file TARGET ${name} PROPERTY _EP_NETRC_FILE)
  2431. get_property(http_username TARGET ${name} PROPERTY _EP_HTTP_USERNAME)
  2432. get_property(http_password TARGET ${name} PROPERTY _EP_HTTP_PASSWORD)
  2433. get_property(http_headers TARGET ${name} PROPERTY _EP_HTTP_HEADER)
  2434. set(download_script "${stamp_dir}/download-${name}.cmake")
  2435. _ep_write_downloadfile_script("${download_script}" "${url}" "${file}" "${timeout}" "${inactivity_timeout}" "${no_progress}" "${hash}" "${tls_verify}" "${tls_cainfo}" "${http_username}:${http_password}" "${http_headers}" "${netrc}" "${netrc_file}")
  2436. set(cmd ${CMAKE_COMMAND} -P "${download_script}"
  2437. COMMAND)
  2438. if (no_extract)
  2439. set(steps "download and verify")
  2440. else ()
  2441. set(steps "download, verify and extract")
  2442. endif ()
  2443. set(comment "Performing download step (${steps}) for '${name}'")
  2444. file(WRITE "${stamp_dir}/verify-${name}.cmake" "") # already verified by 'download_script'
  2445. else()
  2446. set(file "${url}")
  2447. if (no_extract)
  2448. set(steps "verify")
  2449. else ()
  2450. set(steps "verify and extract")
  2451. endif ()
  2452. set(comment "Performing download step (${steps}) for '${name}'")
  2453. _ep_write_verifyfile_script("${stamp_dir}/verify-${name}.cmake" "${file}" "${hash}")
  2454. endif()
  2455. list(APPEND cmd ${CMAKE_COMMAND} -P ${stamp_dir}/verify-${name}.cmake)
  2456. if (NOT no_extract)
  2457. _ep_write_extractfile_script("${stamp_dir}/extract-${name}.cmake" "${name}" "${file}" "${source_dir}")
  2458. list(APPEND cmd COMMAND ${CMAKE_COMMAND} -P ${stamp_dir}/extract-${name}.cmake)
  2459. else ()
  2460. set_property(TARGET ${name} PROPERTY _EP_DOWNLOADED_FILE ${file})
  2461. endif ()
  2462. endif()
  2463. else()
  2464. _ep_is_dir_empty("${source_dir}" empty)
  2465. if(${empty})
  2466. message(SEND_ERROR
  2467. "No download info given for '${name}' and its source directory:\n"
  2468. " ${source_dir}\n"
  2469. "is not an existing non-empty directory. Please specify one of:\n"
  2470. " * SOURCE_DIR with an existing non-empty directory\n"
  2471. " * DOWNLOAD_COMMAND\n"
  2472. " * URL\n"
  2473. " * GIT_REPOSITORY\n"
  2474. " * SVN_REPOSITORY\n"
  2475. " * HG_REPOSITORY\n"
  2476. " * CVS_REPOSITORY and CVS_MODULE"
  2477. )
  2478. endif()
  2479. endif()
  2480. get_property(log TARGET ${name} PROPERTY _EP_LOG_DOWNLOAD)
  2481. if(log)
  2482. set(log LOG 1)
  2483. else()
  2484. set(log "")
  2485. endif()
  2486. get_property(uses_terminal TARGET ${name} PROPERTY
  2487. _EP_USES_TERMINAL_DOWNLOAD)
  2488. if(uses_terminal)
  2489. set(uses_terminal USES_TERMINAL 1)
  2490. else()
  2491. set(uses_terminal "")
  2492. endif()
  2493. set(__cmdQuoted)
  2494. foreach(__item IN LISTS cmd)
  2495. string(APPEND __cmdQuoted " [==[${__item}]==]")
  2496. endforeach()
  2497. cmake_language(EVAL CODE "
  2498. ExternalProject_Add_Step(\${name} download
  2499. INDEPENDENT TRUE
  2500. COMMENT \${comment}
  2501. COMMAND ${__cmdQuoted}
  2502. WORKING_DIRECTORY \${work_dir}
  2503. DEPENDS \${depends}
  2504. DEPENDEES mkdir
  2505. ${log}
  2506. ${uses_terminal}
  2507. )"
  2508. )
  2509. endfunction()
  2510. function(_ep_get_update_disconnected var name)
  2511. get_property(update_disconnected_set TARGET ${name} PROPERTY _EP_UPDATE_DISCONNECTED SET)
  2512. if(update_disconnected_set)
  2513. get_property(update_disconnected TARGET ${name} PROPERTY _EP_UPDATE_DISCONNECTED)
  2514. else()
  2515. get_property(update_disconnected DIRECTORY PROPERTY EP_UPDATE_DISCONNECTED)
  2516. endif()
  2517. set(${var} "${update_disconnected}" PARENT_SCOPE)
  2518. endfunction()
  2519. function(_ep_add_update_command name)
  2520. ExternalProject_Get_Property(${name} source_dir tmp_dir)
  2521. get_property(cmd_set TARGET ${name} PROPERTY _EP_UPDATE_COMMAND SET)
  2522. get_property(cmd TARGET ${name} PROPERTY _EP_UPDATE_COMMAND)
  2523. get_property(cvs_repository TARGET ${name} PROPERTY _EP_CVS_REPOSITORY)
  2524. get_property(svn_repository TARGET ${name} PROPERTY _EP_SVN_REPOSITORY)
  2525. get_property(git_repository TARGET ${name} PROPERTY _EP_GIT_REPOSITORY)
  2526. get_property(hg_repository TARGET ${name} PROPERTY _EP_HG_REPOSITORY )
  2527. _ep_get_update_disconnected(update_disconnected ${name})
  2528. set(work_dir)
  2529. set(comment)
  2530. set(always)
  2531. if(cmd_set)
  2532. set(work_dir ${source_dir})
  2533. if(NOT "x${cmd}" STREQUAL "x")
  2534. set(always 1)
  2535. endif()
  2536. elseif(cvs_repository)
  2537. if(NOT CVS_EXECUTABLE)
  2538. message(FATAL_ERROR "error: could not find cvs for update of ${name}")
  2539. endif()
  2540. set(work_dir ${source_dir})
  2541. set(comment "Performing update step (CVS update) for '${name}'")
  2542. get_property(cvs_tag TARGET ${name} PROPERTY _EP_CVS_TAG)
  2543. set(cmd ${CVS_EXECUTABLE} -d ${cvs_repository} -q up -dP ${cvs_tag})
  2544. set(always 1)
  2545. elseif(svn_repository)
  2546. if(NOT Subversion_SVN_EXECUTABLE)
  2547. message(FATAL_ERROR "error: could not find svn for update of ${name}")
  2548. endif()
  2549. set(work_dir ${source_dir})
  2550. set(comment "Performing update step (SVN update) for '${name}'")
  2551. get_property(svn_revision TARGET ${name} PROPERTY _EP_SVN_REVISION)
  2552. get_property(svn_username TARGET ${name} PROPERTY _EP_SVN_USERNAME)
  2553. get_property(svn_password TARGET ${name} PROPERTY _EP_SVN_PASSWORD)
  2554. get_property(svn_trust_cert TARGET ${name} PROPERTY _EP_SVN_TRUST_CERT)
  2555. set(svn_user_pw_args "")
  2556. if(DEFINED svn_username)
  2557. set(svn_user_pw_args ${svn_user_pw_args} "--username=${svn_username}")
  2558. endif()
  2559. if(DEFINED svn_password)
  2560. set(svn_user_pw_args ${svn_user_pw_args} "--password=${svn_password}")
  2561. endif()
  2562. if(svn_trust_cert)
  2563. set(svn_trust_cert_args --trust-server-cert)
  2564. endif()
  2565. set(cmd ${Subversion_SVN_EXECUTABLE} up ${svn_revision}
  2566. --non-interactive ${svn_trust_cert_args} ${svn_user_pw_args})
  2567. set(always 1)
  2568. elseif(git_repository)
  2569. # FetchContent gives us these directly, so don't try to recompute them
  2570. if(NOT GIT_EXECUTABLE OR NOT GIT_VERSION_STRING)
  2571. unset(CMAKE_MODULE_PATH) # Use CMake builtin find module
  2572. find_package(Git QUIET)
  2573. if(NOT GIT_EXECUTABLE)
  2574. message(FATAL_ERROR "error: could not find git for fetch of ${name}")
  2575. endif()
  2576. endif()
  2577. set(work_dir ${source_dir})
  2578. set(comment "Performing update step for '${name}'")
  2579. get_property(git_tag TARGET ${name} PROPERTY _EP_GIT_TAG)
  2580. if(NOT git_tag)
  2581. set(git_tag "master")
  2582. endif()
  2583. get_property(git_remote_name TARGET ${name} PROPERTY _EP_GIT_REMOTE_NAME)
  2584. if(NOT git_remote_name)
  2585. set(git_remote_name "origin")
  2586. endif()
  2587. set(git_init_submodules TRUE)
  2588. get_property(git_submodules_set TARGET ${name} PROPERTY _EP_GIT_SUBMODULES SET)
  2589. if(git_submodules_set)
  2590. get_property(git_submodules TARGET ${name} PROPERTY _EP_GIT_SUBMODULES)
  2591. if(git_submodules STREQUAL "" AND _EP_CMP0097 STREQUAL "NEW")
  2592. set(git_init_submodules FALSE)
  2593. endif()
  2594. endif()
  2595. get_property(git_update_strategy TARGET ${name} PROPERTY _EP_GIT_REMOTE_UPDATE_STRATEGY)
  2596. if(NOT git_update_strategy)
  2597. set(git_update_strategy "${CMAKE_EP_GIT_REMOTE_UPDATE_STRATEGY}")
  2598. endif()
  2599. if(NOT git_update_strategy)
  2600. set(git_update_strategy REBASE)
  2601. endif()
  2602. set(strategies CHECKOUT REBASE REBASE_CHECKOUT)
  2603. if(NOT git_update_strategy IN_LIST strategies)
  2604. message(FATAL_ERROR "'${git_update_strategy}' is not one of the supported strategies: ${strategies}")
  2605. endif()
  2606. _ep_get_git_submodules_recurse(git_submodules_recurse)
  2607. _ep_write_gitupdate_script(${tmp_dir}/${name}-gitupdate.cmake
  2608. ${GIT_EXECUTABLE} ${git_tag} ${git_remote_name} ${git_init_submodules} "${git_submodules_recurse}" "${git_submodules}" ${git_repository} ${work_dir} ${git_update_strategy}
  2609. )
  2610. set(cmd ${CMAKE_COMMAND} -P ${tmp_dir}/${name}-gitupdate.cmake)
  2611. set(always 1)
  2612. elseif(hg_repository)
  2613. if(NOT HG_EXECUTABLE)
  2614. message(FATAL_ERROR "error: could not find hg for pull of ${name}")
  2615. endif()
  2616. set(work_dir ${source_dir})
  2617. set(comment "Performing update step (hg pull) for '${name}'")
  2618. get_property(hg_tag TARGET ${name} PROPERTY _EP_HG_TAG)
  2619. if(NOT hg_tag)
  2620. set(hg_tag "tip")
  2621. endif()
  2622. if("${HG_VERSION_STRING}" STREQUAL "2.1")
  2623. message(WARNING "Mercurial 2.1 does not distinguish an empty pull from a failed pull:
  2624. http://mercurial.selenic.com/wiki/UpgradeNotes#A2.1.1:_revert_pull_return_code_change.2C_compile_issue_on_OS_X
  2625. http://thread.gmane.org/gmane.comp.version-control.mercurial.devel/47656
  2626. Update to Mercurial >= 2.1.1.
  2627. ")
  2628. endif()
  2629. set(cmd ${HG_EXECUTABLE} pull
  2630. COMMAND ${HG_EXECUTABLE} update ${hg_tag}
  2631. )
  2632. set(always 1)
  2633. endif()
  2634. get_property(log TARGET ${name} PROPERTY _EP_LOG_UPDATE)
  2635. if(log)
  2636. set(log LOG 1)
  2637. else()
  2638. set(log "")
  2639. endif()
  2640. get_property(uses_terminal TARGET ${name} PROPERTY
  2641. _EP_USES_TERMINAL_UPDATE)
  2642. if(uses_terminal)
  2643. set(uses_terminal USES_TERMINAL 1)
  2644. else()
  2645. set(uses_terminal "")
  2646. endif()
  2647. set(__cmdQuoted)
  2648. foreach(__item IN LISTS cmd)
  2649. string(APPEND __cmdQuoted " [==[${__item}]==]")
  2650. endforeach()
  2651. cmake_language(EVAL CODE "
  2652. ExternalProject_Add_Step(${name} update
  2653. INDEPENDENT TRUE
  2654. COMMENT \${comment}
  2655. COMMAND ${__cmdQuoted}
  2656. ALWAYS \${always}
  2657. EXCLUDE_FROM_MAIN \${update_disconnected}
  2658. WORKING_DIRECTORY \${work_dir}
  2659. DEPENDEES download
  2660. ${log}
  2661. ${uses_terminal}
  2662. )"
  2663. )
  2664. endfunction()
  2665. function(_ep_add_patch_command name)
  2666. ExternalProject_Get_Property(${name} source_dir)
  2667. get_property(cmd_set TARGET ${name} PROPERTY _EP_PATCH_COMMAND SET)
  2668. get_property(cmd TARGET ${name} PROPERTY _EP_PATCH_COMMAND)
  2669. set(work_dir)
  2670. if(cmd_set)
  2671. set(work_dir ${source_dir})
  2672. endif()
  2673. get_property(log TARGET ${name} PROPERTY _EP_LOG_PATCH)
  2674. if(log)
  2675. set(log LOG 1)
  2676. else()
  2677. set(log "")
  2678. endif()
  2679. _ep_get_update_disconnected(update_disconnected ${name})
  2680. if(update_disconnected)
  2681. set(patch_dep download)
  2682. else()
  2683. set(patch_dep update)
  2684. endif()
  2685. set(__cmdQuoted)
  2686. foreach(__item IN LISTS cmd)
  2687. string(APPEND __cmdQuoted " [==[${__item}]==]")
  2688. endforeach()
  2689. cmake_language(EVAL CODE "
  2690. ExternalProject_Add_Step(${name} patch
  2691. INDEPENDENT TRUE
  2692. COMMAND ${__cmdQuoted}
  2693. WORKING_DIRECTORY \${work_dir}
  2694. DEPENDEES \${patch_dep}
  2695. ${log}
  2696. )"
  2697. )
  2698. endfunction()
  2699. function(_ep_get_file_deps var name)
  2700. set(file_deps)
  2701. get_property(deps TARGET ${name} PROPERTY _EP_DEPENDS)
  2702. foreach(dep IN LISTS deps)
  2703. get_property(dep_type TARGET ${dep} PROPERTY TYPE)
  2704. if(dep_type STREQUAL "UTILITY")
  2705. get_property(is_ep TARGET ${dep} PROPERTY _EP_IS_EXTERNAL_PROJECT)
  2706. if(is_ep)
  2707. _ep_get_step_stampfile(${dep} "done" done_stamp_file)
  2708. list(APPEND file_deps ${done_stamp_file})
  2709. endif()
  2710. endif()
  2711. endforeach()
  2712. set("${var}" "${file_deps}" PARENT_SCOPE)
  2713. endfunction()
  2714. function(_ep_extract_configure_command var name)
  2715. get_property(cmd_set TARGET ${name} PROPERTY _EP_CONFIGURE_COMMAND SET)
  2716. if(cmd_set)
  2717. get_property(cmd TARGET ${name} PROPERTY _EP_CONFIGURE_COMMAND)
  2718. else()
  2719. get_target_property(cmake_command ${name} _EP_CMAKE_COMMAND)
  2720. if(cmake_command)
  2721. set(cmd "${cmake_command}")
  2722. else()
  2723. set(cmd "${CMAKE_COMMAND}")
  2724. endif()
  2725. get_property(cmake_args TARGET ${name} PROPERTY _EP_CMAKE_ARGS)
  2726. list(APPEND cmd ${cmake_args})
  2727. # If there are any CMAKE_CACHE_ARGS or CMAKE_CACHE_DEFAULT_ARGS,
  2728. # write an initial cache and use it
  2729. get_property(cmake_cache_args TARGET ${name} PROPERTY _EP_CMAKE_CACHE_ARGS)
  2730. get_property(cmake_cache_default_args TARGET ${name} PROPERTY _EP_CMAKE_CACHE_DEFAULT_ARGS)
  2731. set(has_cmake_cache_args 0)
  2732. if(NOT "${cmake_cache_args}" STREQUAL "")
  2733. set(has_cmake_cache_args 1)
  2734. endif()
  2735. set(has_cmake_cache_default_args 0)
  2736. if(NOT "${cmake_cache_default_args}" STREQUAL "")
  2737. set(has_cmake_cache_default_args 1)
  2738. endif()
  2739. get_target_property(cmake_generator ${name} _EP_CMAKE_GENERATOR)
  2740. get_target_property(cmake_generator_instance ${name} _EP_CMAKE_GENERATOR_INSTANCE)
  2741. get_target_property(cmake_generator_platform ${name} _EP_CMAKE_GENERATOR_PLATFORM)
  2742. get_target_property(cmake_generator_toolset ${name} _EP_CMAKE_GENERATOR_TOOLSET)
  2743. if(cmake_generator)
  2744. list(APPEND cmd "-G${cmake_generator}")
  2745. if(cmake_generator_platform)
  2746. list(APPEND cmd "-A${cmake_generator_platform}")
  2747. endif()
  2748. if(cmake_generator_toolset)
  2749. list(APPEND cmd "-T${cmake_generator_toolset}")
  2750. endif()
  2751. if(cmake_generator_instance)
  2752. list(APPEND cmd "-DCMAKE_GENERATOR_INSTANCE:INTERNAL=${cmake_generator_instance}")
  2753. endif()
  2754. else()
  2755. if(CMAKE_EXTRA_GENERATOR)
  2756. list(APPEND cmd "-G${CMAKE_EXTRA_GENERATOR} - ${CMAKE_GENERATOR}")
  2757. else()
  2758. list(APPEND cmd "-G${CMAKE_GENERATOR}")
  2759. if("${CMAKE_GENERATOR}" MATCHES "Green Hills MULTI")
  2760. set(has_cmake_cache_default_args 1)
  2761. set(cmake_cache_default_args ${cmake_cache_default_args}
  2762. "-DGHS_TARGET_PLATFORM:STRING=${GHS_TARGET_PLATFORM}"
  2763. "-DGHS_PRIMARY_TARGET:STRING=${GHS_PRIMARY_TARGET}"
  2764. "-DGHS_TOOLSET_ROOT:STRING=${GHS_TOOLSET_ROOT}"
  2765. "-DGHS_OS_ROOT:STRING=${GHS_OS_ROOT}"
  2766. "-DGHS_OS_DIR:STRING=${GHS_OS_DIR}"
  2767. "-DGHS_BSP_NAME:STRING=${GHS_BSP_NAME}")
  2768. endif()
  2769. endif()
  2770. if(cmake_generator_platform)
  2771. message(FATAL_ERROR "Option CMAKE_GENERATOR_PLATFORM not allowed without CMAKE_GENERATOR.")
  2772. endif()
  2773. if(CMAKE_GENERATOR_PLATFORM)
  2774. list(APPEND cmd "-A${CMAKE_GENERATOR_PLATFORM}")
  2775. endif()
  2776. if(cmake_generator_toolset)
  2777. message(FATAL_ERROR "Option CMAKE_GENERATOR_TOOLSET not allowed without CMAKE_GENERATOR.")
  2778. endif()
  2779. if(CMAKE_GENERATOR_TOOLSET)
  2780. list(APPEND cmd "-T${CMAKE_GENERATOR_TOOLSET}")
  2781. endif()
  2782. if(cmake_generator_instance)
  2783. message(FATAL_ERROR "Option CMAKE_GENERATOR_INSTANCE not allowed without CMAKE_GENERATOR.")
  2784. endif()
  2785. if(CMAKE_GENERATOR_INSTANCE)
  2786. list(APPEND cmd "-DCMAKE_GENERATOR_INSTANCE:INTERNAL=${CMAKE_GENERATOR_INSTANCE}")
  2787. endif()
  2788. endif()
  2789. if(has_cmake_cache_args OR has_cmake_cache_default_args)
  2790. set(_ep_cache_args_script "<TMP_DIR>/${name}-cache-$<CONFIG>.cmake")
  2791. if(has_cmake_cache_args)
  2792. _ep_command_line_to_initial_cache(script_initial_cache_force "${cmake_cache_args}" 1)
  2793. endif()
  2794. if(has_cmake_cache_default_args)
  2795. _ep_command_line_to_initial_cache(script_initial_cache_default "${cmake_cache_default_args}" 0)
  2796. endif()
  2797. _ep_write_initial_cache(${name} "${_ep_cache_args_script}" "${script_initial_cache_force}${script_initial_cache_default}")
  2798. list(APPEND cmd "-C${_ep_cache_args_script}")
  2799. _ep_replace_location_tags(${name} _ep_cache_args_script)
  2800. set(_ep_cache_args_script
  2801. "${_ep_cache_args_script}"
  2802. PARENT_SCOPE)
  2803. endif()
  2804. list(APPEND cmd "<SOURCE_DIR><SOURCE_SUBDIR>")
  2805. endif()
  2806. set("${var}" "${cmd}" PARENT_SCOPE)
  2807. endfunction()
  2808. # TODO: Make sure external projects use the proper compiler
  2809. function(_ep_add_configure_command name)
  2810. ExternalProject_Get_Property(${name} binary_dir tmp_dir)
  2811. set(file_deps)
  2812. get_property(configure_handled_by_build TARGET ${name}
  2813. PROPERTY _EP_CONFIGURE_HANDLED_BY_BUILD)
  2814. if(NOT configure_handled_by_build)
  2815. # Depend on other external projects (file-level)
  2816. _ep_get_file_deps(file_deps ${name})
  2817. endif()
  2818. _ep_extract_configure_command(cmd ${name})
  2819. # If anything about the configure command changes, (command itself, cmake
  2820. # used, cmake args or cmake generator) then re-run the configure step.
  2821. # Fixes issue https://gitlab.kitware.com/cmake/cmake/-/issues/10258
  2822. #
  2823. if(NOT EXISTS ${tmp_dir}/${name}-cfgcmd.txt.in)
  2824. file(WRITE ${tmp_dir}/${name}-cfgcmd.txt.in "cmd='\@cmd\@'\n")
  2825. endif()
  2826. configure_file(${tmp_dir}/${name}-cfgcmd.txt.in ${tmp_dir}/${name}-cfgcmd.txt)
  2827. list(APPEND file_deps ${tmp_dir}/${name}-cfgcmd.txt)
  2828. list(APPEND file_deps ${_ep_cache_args_script})
  2829. get_property(log TARGET ${name} PROPERTY _EP_LOG_CONFIGURE)
  2830. if(log)
  2831. set(log LOG 1)
  2832. else()
  2833. set(log "")
  2834. endif()
  2835. get_property(uses_terminal TARGET ${name} PROPERTY
  2836. _EP_USES_TERMINAL_CONFIGURE)
  2837. if(uses_terminal)
  2838. set(uses_terminal USES_TERMINAL 1)
  2839. else()
  2840. set(uses_terminal "")
  2841. endif()
  2842. set(__cmdQuoted)
  2843. foreach(__item IN LISTS cmd)
  2844. string(APPEND __cmdQuoted " [==[${__item}]==]")
  2845. endforeach()
  2846. cmake_language(EVAL CODE "
  2847. ExternalProject_Add_Step(${name} configure
  2848. INDEPENDENT FALSE
  2849. COMMAND ${__cmdQuoted}
  2850. WORKING_DIRECTORY \${binary_dir}
  2851. DEPENDEES patch
  2852. DEPENDS \${file_deps}
  2853. ${log}
  2854. ${uses_terminal}
  2855. )"
  2856. )
  2857. endfunction()
  2858. function(_ep_add_build_command name)
  2859. ExternalProject_Get_Property(${name} binary_dir)
  2860. set(file_deps)
  2861. get_property(configure_handled_by_build TARGET ${name}
  2862. PROPERTY _EP_CONFIGURE_HANDLED_BY_BUILD)
  2863. if(configure_handled_by_build)
  2864. # Depend on other external projects (file-level)
  2865. _ep_get_file_deps(file_deps ${name})
  2866. endif()
  2867. get_property(cmd_set TARGET ${name} PROPERTY _EP_BUILD_COMMAND SET)
  2868. if(cmd_set)
  2869. get_property(cmd TARGET ${name} PROPERTY _EP_BUILD_COMMAND)
  2870. else()
  2871. _ep_get_build_command(${name} BUILD cmd)
  2872. endif()
  2873. get_property(log TARGET ${name} PROPERTY _EP_LOG_BUILD)
  2874. if(log)
  2875. set(log LOG 1)
  2876. else()
  2877. set(log "")
  2878. endif()
  2879. get_property(uses_terminal TARGET ${name} PROPERTY
  2880. _EP_USES_TERMINAL_BUILD)
  2881. if(uses_terminal)
  2882. set(uses_terminal USES_TERMINAL 1)
  2883. else()
  2884. set(uses_terminal "")
  2885. endif()
  2886. get_property(build_always TARGET ${name} PROPERTY _EP_BUILD_ALWAYS)
  2887. if(build_always)
  2888. set(always 1)
  2889. else()
  2890. set(always 0)
  2891. endif()
  2892. get_property(build_byproducts TARGET ${name} PROPERTY _EP_BUILD_BYPRODUCTS)
  2893. set(__cmdQuoted)
  2894. foreach(__item IN LISTS cmd)
  2895. string(APPEND __cmdQuoted " [==[${__item}]==]")
  2896. endforeach()
  2897. cmake_language(EVAL CODE "
  2898. ExternalProject_Add_Step(${name} build
  2899. INDEPENDENT FALSE
  2900. COMMAND ${__cmdQuoted}
  2901. BYPRODUCTS \${build_byproducts}
  2902. WORKING_DIRECTORY \${binary_dir}
  2903. DEPENDEES configure
  2904. DEPENDS \${file_deps}
  2905. ALWAYS \${always}
  2906. ${log}
  2907. ${uses_terminal}
  2908. )"
  2909. )
  2910. endfunction()
  2911. function(_ep_add_install_command name)
  2912. ExternalProject_Get_Property(${name} binary_dir)
  2913. get_property(cmd_set TARGET ${name} PROPERTY _EP_INSTALL_COMMAND SET)
  2914. if(cmd_set)
  2915. get_property(cmd TARGET ${name} PROPERTY _EP_INSTALL_COMMAND)
  2916. else()
  2917. _ep_get_build_command(${name} INSTALL cmd)
  2918. endif()
  2919. get_property(log TARGET ${name} PROPERTY _EP_LOG_INSTALL)
  2920. if(log)
  2921. set(log LOG 1)
  2922. else()
  2923. set(log "")
  2924. endif()
  2925. get_property(uses_terminal TARGET ${name} PROPERTY
  2926. _EP_USES_TERMINAL_INSTALL)
  2927. if(uses_terminal)
  2928. set(uses_terminal USES_TERMINAL 1)
  2929. else()
  2930. set(uses_terminal "")
  2931. endif()
  2932. set(__cmdQuoted)
  2933. foreach(__item IN LISTS cmd)
  2934. string(APPEND __cmdQuoted " [==[${__item}]==]")
  2935. endforeach()
  2936. cmake_language(EVAL CODE "
  2937. ExternalProject_Add_Step(${name} install
  2938. INDEPENDENT FALSE
  2939. COMMAND ${__cmdQuoted}
  2940. WORKING_DIRECTORY \${binary_dir}
  2941. DEPENDEES build
  2942. ${log}
  2943. ${uses_terminal}
  2944. )"
  2945. )
  2946. endfunction()
  2947. function(_ep_add_test_command name)
  2948. ExternalProject_Get_Property(${name} binary_dir)
  2949. get_property(before TARGET ${name} PROPERTY _EP_TEST_BEFORE_INSTALL)
  2950. get_property(after TARGET ${name} PROPERTY _EP_TEST_AFTER_INSTALL)
  2951. get_property(exclude TARGET ${name} PROPERTY _EP_TEST_EXCLUDE_FROM_MAIN)
  2952. get_property(cmd_set TARGET ${name} PROPERTY _EP_TEST_COMMAND SET)
  2953. # Only actually add the test step if one of the test related properties is
  2954. # explicitly set. (i.e. the test step is omitted unless requested...)
  2955. #
  2956. if(cmd_set OR before OR after OR exclude)
  2957. if(cmd_set)
  2958. get_property(cmd TARGET ${name} PROPERTY _EP_TEST_COMMAND)
  2959. else()
  2960. _ep_get_build_command(${name} TEST cmd)
  2961. endif()
  2962. if(before)
  2963. set(dependees_args DEPENDEES build)
  2964. else()
  2965. set(dependees_args DEPENDEES install)
  2966. endif()
  2967. if(exclude)
  2968. set(dependers_args "")
  2969. set(exclude_args EXCLUDE_FROM_MAIN 1)
  2970. else()
  2971. if(before)
  2972. set(dependers_args DEPENDERS install)
  2973. else()
  2974. set(dependers_args "")
  2975. endif()
  2976. set(exclude_args "")
  2977. endif()
  2978. get_property(log TARGET ${name} PROPERTY _EP_LOG_TEST)
  2979. if(log)
  2980. set(log LOG 1)
  2981. else()
  2982. set(log "")
  2983. endif()
  2984. get_property(uses_terminal TARGET ${name} PROPERTY
  2985. _EP_USES_TERMINAL_TEST)
  2986. if(uses_terminal)
  2987. set(uses_terminal USES_TERMINAL 1)
  2988. else()
  2989. set(uses_terminal "")
  2990. endif()
  2991. set(__cmdQuoted)
  2992. foreach(__item IN LISTS cmd)
  2993. string(APPEND __cmdQuoted " [==[${__item}]==]")
  2994. endforeach()
  2995. cmake_language(EVAL CODE "
  2996. ExternalProject_Add_Step(${name} test
  2997. INDEPENDENT FALSE
  2998. COMMAND ${__cmdQuoted}
  2999. WORKING_DIRECTORY \${binary_dir}
  3000. ${dependees_args}
  3001. ${dependers_args}
  3002. ${exclude_args}
  3003. ${log}
  3004. ${uses_terminal}
  3005. )"
  3006. )
  3007. endif()
  3008. endfunction()
  3009. function(ExternalProject_Add name)
  3010. cmake_policy(GET CMP0097 _EP_CMP0097
  3011. PARENT_SCOPE # undocumented, do not use outside of CMake
  3012. )
  3013. cmake_policy(GET CMP0114 cmp0114
  3014. PARENT_SCOPE # undocumented, do not use outside of CMake
  3015. )
  3016. if(CMAKE_XCODE_BUILD_SYSTEM VERSION_GREATER_EQUAL 12 AND NOT cmp0114 STREQUAL "NEW")
  3017. message(AUTHOR_WARNING
  3018. "Policy CMP0114 is not set to NEW. "
  3019. "In order to support the Xcode \"new build system\", "
  3020. "this project must be updated to set policy CMP0114 to NEW."
  3021. "\n"
  3022. "Since CMake is generating for the Xcode \"new build system\", "
  3023. "ExternalProject_Add will use policy CMP0114's NEW behavior anyway, "
  3024. "but the generated build system may not match what the project intends."
  3025. )
  3026. set(cmp0114 "NEW")
  3027. endif()
  3028. _ep_get_configuration_subdir_suffix(cfgdir)
  3029. # Add a custom target for the external project.
  3030. set(cmf_dir ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles)
  3031. _ep_get_complete_stampfile(${name} complete_stamp_file)
  3032. cmake_policy(PUSH)
  3033. if(cmp0114 STREQUAL "NEW")
  3034. # To implement CMP0114 NEW behavior with Makefile generators,
  3035. # we need CMP0113 NEW behavior.
  3036. cmake_policy(SET CMP0113 NEW)
  3037. endif()
  3038. # The "ALL" option to add_custom_target just tells it to not set the
  3039. # EXCLUDE_FROM_ALL target property. Later, if the EXCLUDE_FROM_ALL
  3040. # argument was passed, we explicitly set it for the target.
  3041. add_custom_target(${name} ALL DEPENDS ${complete_stamp_file})
  3042. cmake_policy(POP)
  3043. set_property(TARGET ${name} PROPERTY _EP_IS_EXTERNAL_PROJECT 1)
  3044. set_property(TARGET ${name} PROPERTY LABELS ${name})
  3045. set_property(TARGET ${name} PROPERTY FOLDER "ExternalProjectTargets/${name}")
  3046. set_property(TARGET ${name} PROPERTY _EP_CMP0114 "${cmp0114}")
  3047. set(keywords
  3048. #
  3049. # Directory options
  3050. #
  3051. PREFIX
  3052. TMP_DIR
  3053. STAMP_DIR
  3054. LOG_DIR
  3055. DOWNLOAD_DIR
  3056. SOURCE_DIR
  3057. BINARY_DIR
  3058. INSTALL_DIR
  3059. #
  3060. # Download step options
  3061. #
  3062. DOWNLOAD_COMMAND
  3063. #
  3064. URL
  3065. URL_HASH
  3066. URL_MD5
  3067. DOWNLOAD_NAME
  3068. DOWNLOAD_NO_EXTRACT
  3069. DOWNLOAD_NO_PROGRESS
  3070. TIMEOUT
  3071. INACTIVITY_TIMEOUT
  3072. HTTP_USERNAME
  3073. HTTP_PASSWORD
  3074. HTTP_HEADER
  3075. TLS_VERIFY # Also used for git clone operations
  3076. TLS_CAINFO
  3077. NETRC
  3078. NETRC_FILE
  3079. #
  3080. GIT_REPOSITORY
  3081. GIT_TAG
  3082. GIT_REMOTE_NAME
  3083. GIT_SUBMODULES
  3084. GIT_SUBMODULES_RECURSE
  3085. GIT_SHALLOW
  3086. GIT_PROGRESS
  3087. GIT_CONFIG
  3088. GIT_REMOTE_UPDATE_STRATEGY
  3089. #
  3090. SVN_REPOSITORY
  3091. SVN_REVISION
  3092. SVN_USERNAME
  3093. SVN_PASSWORD
  3094. SVN_TRUST_CERT
  3095. #
  3096. HG_REPOSITORY
  3097. HG_TAG
  3098. #
  3099. CVS_REPOSITORY
  3100. CVS_MODULE
  3101. CVS_TAG
  3102. #
  3103. # Update step options
  3104. #
  3105. UPDATE_COMMAND
  3106. UPDATE_DISCONNECTED
  3107. #
  3108. # Patch step options
  3109. #
  3110. PATCH_COMMAND
  3111. #
  3112. # Configure step options
  3113. #
  3114. CONFIGURE_COMMAND
  3115. CMAKE_COMMAND
  3116. CMAKE_GENERATOR
  3117. CMAKE_GENERATOR_PLATFORM
  3118. CMAKE_GENERATOR_TOOLSET
  3119. CMAKE_GENERATOR_INSTANCE
  3120. CMAKE_ARGS
  3121. CMAKE_CACHE_ARGS
  3122. CMAKE_CACHE_DEFAULT_ARGS
  3123. SOURCE_SUBDIR
  3124. CONFIGURE_HANDLED_BY_BUILD
  3125. #
  3126. # Build step options
  3127. #
  3128. BUILD_COMMAND
  3129. BUILD_IN_SOURCE
  3130. BUILD_ALWAYS
  3131. BUILD_BYPRODUCTS
  3132. #
  3133. # Install step options
  3134. #
  3135. INSTALL_COMMAND
  3136. #
  3137. # Test step options
  3138. #
  3139. TEST_COMMAND
  3140. TEST_BEFORE_INSTALL
  3141. TEST_AFTER_INSTALL
  3142. TEST_EXCLUDE_FROM_MAIN
  3143. #
  3144. # Logging options
  3145. #
  3146. LOG_DOWNLOAD
  3147. LOG_UPDATE
  3148. LOG_PATCH
  3149. LOG_CONFIGURE
  3150. LOG_BUILD
  3151. LOG_INSTALL
  3152. LOG_TEST
  3153. LOG_MERGED_STDOUTERR
  3154. LOG_OUTPUT_ON_FAILURE
  3155. #
  3156. # Terminal access options
  3157. #
  3158. USES_TERMINAL_DOWNLOAD
  3159. USES_TERMINAL_UPDATE
  3160. USES_TERMINAL_CONFIGURE
  3161. USES_TERMINAL_BUILD
  3162. USES_TERMINAL_INSTALL
  3163. USES_TERMINAL_TEST
  3164. #
  3165. # Target options
  3166. #
  3167. DEPENDS
  3168. EXCLUDE_FROM_ALL
  3169. STEP_TARGETS
  3170. INDEPENDENT_STEP_TARGETS
  3171. #
  3172. # Miscellaneous options
  3173. #
  3174. LIST_SEPARATOR
  3175. )
  3176. _ep_parse_arguments(ExternalProject_Add "${keywords}" ${name} _EP_ "${ARGN}")
  3177. _ep_set_directories(${name})
  3178. _ep_get_step_stampfile(${name} "done" done_stamp_file)
  3179. _ep_get_step_stampfile(${name} "install" install_stamp_file)
  3180. # Set the EXCLUDE_FROM_ALL target property if required.
  3181. get_property(exclude_from_all TARGET ${name} PROPERTY _EP_EXCLUDE_FROM_ALL)
  3182. if(exclude_from_all)
  3183. set_property(TARGET ${name} PROPERTY EXCLUDE_FROM_ALL TRUE)
  3184. endif()
  3185. # The 'complete' step depends on all other steps and creates a
  3186. # 'done' mark. A dependent external project's 'configure' step
  3187. # depends on the 'done' mark so that it rebuilds when this project
  3188. # rebuilds. It is important that 'done' is not the output of any
  3189. # custom command so that CMake does not propagate build rules to
  3190. # other external project targets, which may cause problems during
  3191. # parallel builds. However, the Ninja generator needs to see the entire
  3192. # dependency graph, and can cope with custom commands belonging to
  3193. # multiple targets, so we add the 'done' mark as an output for Ninja only.
  3194. set(complete_outputs ${complete_stamp_file})
  3195. if(${CMAKE_GENERATOR} MATCHES "Ninja")
  3196. set(complete_outputs ${complete_outputs} ${done_stamp_file})
  3197. endif()
  3198. add_custom_command(
  3199. OUTPUT ${complete_outputs}
  3200. COMMENT "Completed '${name}'"
  3201. COMMAND ${CMAKE_COMMAND} -E make_directory ${cmf_dir}${cfgdir}
  3202. COMMAND ${CMAKE_COMMAND} -E touch ${complete_stamp_file}
  3203. COMMAND ${CMAKE_COMMAND} -E touch ${done_stamp_file}
  3204. DEPENDS ${install_stamp_file}
  3205. VERBATIM
  3206. )
  3207. # Depend on other external projects (target-level).
  3208. get_property(deps TARGET ${name} PROPERTY _EP_DEPENDS)
  3209. foreach(arg IN LISTS deps)
  3210. add_dependencies(${name} ${arg})
  3211. endforeach()
  3212. # Set up custom build steps based on the target properties.
  3213. # Each step depends on the previous one.
  3214. #
  3215. # The target depends on the output of the final step.
  3216. # (Already set up above in the DEPENDS of the add_custom_target command.)
  3217. #
  3218. _ep_add_mkdir_command(${name})
  3219. _ep_add_download_command(${name})
  3220. _ep_add_update_command(${name})
  3221. _ep_add_patch_command(${name})
  3222. _ep_add_configure_command(${name})
  3223. _ep_add_build_command(${name})
  3224. _ep_add_install_command(${name})
  3225. # Test is special in that it might depend on build, or it might depend
  3226. # on install.
  3227. #
  3228. _ep_add_test_command(${name})
  3229. endfunction()
  3230. cmake_policy(POP)