ExternalProject.cmake 112 KB

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