ExternalProject.cmake 104 KB

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