ExternalProject.cmake 135 KB

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