FetchContent.cmake 98 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #[=======================================================================[.rst:
  4. FetchContent
  5. ------------------
  6. .. versionadded:: 3.11
  7. .. only:: html
  8. .. contents::
  9. .. note:: The :guide:`Using Dependencies Guide` provides a high-level
  10. introduction to this general topic. It provides a broader overview of
  11. where the ``FetchContent`` module fits into the bigger picture,
  12. including its relationship to the :command:`find_package` command.
  13. The guide is recommended pre-reading before moving on to the details below.
  14. Overview
  15. ^^^^^^^^
  16. This module enables populating content at configure time via any method
  17. supported by the :module:`ExternalProject` module. Whereas
  18. :command:`ExternalProject_Add` downloads at build time, the
  19. ``FetchContent`` module makes content available immediately, allowing the
  20. configure step to use the content in commands like :command:`add_subdirectory`,
  21. :command:`include` or :command:`file` operations.
  22. Content population details should be defined separately from the command that
  23. performs the actual population. This separation ensures that all the
  24. dependency details are defined before anything might try to use them to
  25. populate content. This is particularly important in more complex project
  26. hierarchies where dependencies may be shared between multiple projects.
  27. The following shows a typical example of declaring content details for some
  28. dependencies and then ensuring they are populated with a separate call:
  29. .. code-block:: cmake
  30. FetchContent_Declare(
  31. googletest
  32. GIT_REPOSITORY https://github.com/google/googletest.git
  33. GIT_TAG 703bd9caab50b139428cea1aaff9974ebee5742e # release-1.10.0
  34. )
  35. FetchContent_Declare(
  36. myCompanyIcons
  37. URL https://intranet.mycompany.com/assets/iconset_1.12.tar.gz
  38. URL_HASH MD5=5588a7b18261c20068beabfb4f530b87
  39. )
  40. FetchContent_MakeAvailable(googletest myCompanyIcons)
  41. The :command:`FetchContent_MakeAvailable` command ensures the named
  42. dependencies have been populated, either by an earlier call, or by populating
  43. them itself. When performing the population, it will also add them to the
  44. main build, if possible, so that the main build can use the populated
  45. projects' targets, etc. See the command's documentation for how these steps
  46. are performed.
  47. When using a hierarchical project arrangement, projects at higher levels in
  48. the hierarchy are able to override the declared details of content specified
  49. anywhere lower in the project hierarchy. The first details to be declared
  50. for a given dependency take precedence, regardless of where in the project
  51. hierarchy that occurs. Similarly, the first call that tries to populate a
  52. dependency "wins", with subsequent populations reusing the result of the
  53. first instead of repeating the population again.
  54. See the :ref:`Examples <fetch-content-examples>` which demonstrate
  55. this scenario.
  56. The ``FetchContent`` module also supports defining and populating
  57. content in a single call, with no check for whether the content has been
  58. populated elsewhere already. This should not be done in projects, but may
  59. be appropriate for populating content in
  60. :ref:`CMake script mode <Script Processing Mode>`.
  61. See :command:`FetchContent_Populate` for details.
  62. Commands
  63. ^^^^^^^^
  64. .. command:: FetchContent_Declare
  65. .. code-block:: cmake
  66. FetchContent_Declare(
  67. <name>
  68. <contentOptions>...
  69. [EXCLUDE_FROM_ALL]
  70. [SYSTEM]
  71. [OVERRIDE_FIND_PACKAGE |
  72. FIND_PACKAGE_ARGS args...]
  73. )
  74. The ``FetchContent_Declare()`` function records the options that describe
  75. how to populate the specified content. If such details have already
  76. been recorded earlier in this project (regardless of where in the project
  77. hierarchy), this and all later calls for the same content ``<name>`` are
  78. ignored. This "first to record, wins" approach is what allows hierarchical
  79. projects to have parent projects override content details of child projects.
  80. The content ``<name>`` can be any string without spaces, but good practice
  81. would be to use only letters, numbers, and underscores. The name will be
  82. treated case-insensitively, and it should be obvious for the content it
  83. represents. It is often the name of the child project, or the value given
  84. to its top level :command:`project` command (if it is a CMake project).
  85. For well-known public projects, the name should generally be the official
  86. name of the project. Choosing an unusual name makes it unlikely that other
  87. projects needing that same content will use the same name, leading to
  88. the content being populated multiple times.
  89. The ``<contentOptions>`` can be any of the download, update, or patch options
  90. that the :command:`ExternalProject_Add` command understands. The configure,
  91. build, install, and test steps are explicitly disabled, so options related
  92. to those steps will be ignored. The ``SOURCE_SUBDIR`` option is an
  93. exception, see :command:`FetchContent_MakeAvailable` for details on how that
  94. affects behavior.
  95. .. versionchanged:: 3.30
  96. When policy :policy:`CMP0168` is set to ``NEW``, some output-related and
  97. directory-related options are ignored. See the policy documentation for
  98. details.
  99. In most cases, ``<contentOptions>`` will just be a couple of options defining
  100. the download method and method-specific details like a commit tag or archive
  101. hash. For example:
  102. .. code-block:: cmake
  103. FetchContent_Declare(
  104. googletest
  105. GIT_REPOSITORY https://github.com/google/googletest.git
  106. GIT_TAG 703bd9caab50b139428cea1aaff9974ebee5742e # release-1.10.0
  107. )
  108. FetchContent_Declare(
  109. myCompanyIcons
  110. URL https://intranet.mycompany.com/assets/iconset_1.12.tar.gz
  111. URL_HASH MD5=5588a7b18261c20068beabfb4f530b87
  112. )
  113. FetchContent_Declare(
  114. myCompanyCertificates
  115. SVN_REPOSITORY svn+ssh://svn.mycompany.com/srv/svn/trunk/certs
  116. SVN_REVISION -r12345
  117. )
  118. Where contents are being fetched from a remote location and you do not
  119. control that server, it is advisable to use a hash for ``GIT_TAG`` rather
  120. than a branch or tag name. A commit hash is more secure and helps to
  121. confirm that the downloaded contents are what you expected.
  122. .. versionchanged:: 3.14
  123. Commands for the download, update, or patch steps can access the terminal.
  124. This may be needed for things like password prompts or real-time display
  125. of command progress.
  126. .. versionadded:: 3.22
  127. The :variable:`CMAKE_TLS_VERIFY`, :variable:`CMAKE_TLS_CAINFO`,
  128. :variable:`CMAKE_NETRC`, and :variable:`CMAKE_NETRC_FILE` variables now
  129. provide the defaults for their corresponding content options, just like
  130. they do for :command:`ExternalProject_Add`. Previously, these variables
  131. were ignored by the ``FetchContent`` module.
  132. .. versionadded:: 3.24
  133. ``FIND_PACKAGE_ARGS``
  134. This option is for scenarios where the
  135. :command:`FetchContent_MakeAvailable` command may first try a call to
  136. :command:`find_package` to satisfy the dependency for ``<name>``.
  137. By default, such a call would be simply ``find_package(<name>)``, but
  138. ``FIND_PACKAGE_ARGS`` can be used to provide additional arguments to be
  139. appended after the ``<name>``. ``FIND_PACKAGE_ARGS`` can also be given
  140. with nothing after it, which indicates that :command:`find_package` can
  141. still be called if :variable:`FETCHCONTENT_TRY_FIND_PACKAGE_MODE` is
  142. set to ``OPT_IN``, or is not set.
  143. It would not normally be appropriate to specify ``REQUIRED`` as one of
  144. the additional arguments after ``FIND_PACKAGE_ARGS``. Doing so would
  145. mean the :command:`find_package` call must succeed, so none of the other
  146. details specified in the ``FetchContent_Declare()`` call would get a
  147. chance to be used as a fall-back.
  148. Everything after the ``FIND_PACKAGE_ARGS`` keyword is appended to the
  149. :command:`find_package` call, so all other ``<contentOptions>`` must
  150. come before the ``FIND_PACKAGE_ARGS`` keyword. If the
  151. :variable:`CMAKE_FIND_PACKAGE_TARGETS_GLOBAL` variable is set to true
  152. at the time ``FetchContent_Declare()`` is called, a ``GLOBAL`` keyword
  153. will be appended to the :command:`find_package` arguments if it was
  154. not already specified. It will also be appended if
  155. ``FIND_PACKAGE_ARGS`` was not given, but
  156. :variable:`FETCHCONTENT_TRY_FIND_PACKAGE_MODE` was set to ``ALWAYS``.
  157. ``OVERRIDE_FIND_PACKAGE`` cannot be used when ``FIND_PACKAGE_ARGS`` is
  158. given.
  159. :ref:`dependency_providers` discusses another way that
  160. :command:`FetchContent_MakeAvailable` calls can be redirected.
  161. ``FIND_PACKAGE_ARGS`` is intended for project control, whereas
  162. dependency providers allow users to override project behavior.
  163. ``OVERRIDE_FIND_PACKAGE``
  164. When a ``FetchContent_Declare(<name> ...)`` call includes this option,
  165. subsequent calls to ``find_package(<name> ...)`` will ensure that
  166. ``FetchContent_MakeAvailable(<name>)`` has been called, then use the
  167. config package files in the :variable:`CMAKE_FIND_PACKAGE_REDIRECTS_DIR`
  168. directory (which are usually created by ``FetchContent_MakeAvailable()``).
  169. This effectively makes :command:`FetchContent_MakeAvailable` override
  170. :command:`find_package` for the named dependency, allowing the former to
  171. satisfy the package requirements of the latter. ``FIND_PACKAGE_ARGS``
  172. cannot be used when ``OVERRIDE_FIND_PACKAGE`` is given.
  173. If a :ref:`dependency provider <dependency_providers>` has been set
  174. and the project calls :command:`find_package` for the ``<name>``
  175. dependency, ``OVERRIDE_FIND_PACKAGE`` will not prevent the provider
  176. from seeing that call. Dependency providers always have the opportunity
  177. to intercept any direct call to :command:`find_package`, except if that
  178. call contains the ``BYPASS_PROVIDER`` option.
  179. .. versionadded:: 3.25
  180. ``SYSTEM``
  181. If the ``SYSTEM`` argument is provided, the :prop_dir:`SYSTEM` directory
  182. property of a subdirectory added by
  183. :command:`FetchContent_MakeAvailable` will be set to true. This will
  184. affect non-imported targets created as part of that command.
  185. See the :prop_tgt:`SYSTEM` target property documentation for a more
  186. detailed discussion of the effects.
  187. .. versionadded:: 3.28
  188. ``EXCLUDE_FROM_ALL``
  189. If the ``EXCLUDE_FROM_ALL`` argument is provided, then targets in the
  190. subdirectory added by :command:`FetchContent_MakeAvailable` will not be
  191. included in the ``ALL`` target by default, and may be excluded from IDE
  192. project files. See the :command:`add_subdirectory` ``EXCLUDE_FROM_ALL``
  193. argument documentation for a more detailed discussion of the effects.
  194. .. command:: FetchContent_MakeAvailable
  195. .. versionadded:: 3.14
  196. .. code-block:: cmake
  197. FetchContent_MakeAvailable(<name1> [<name2>...])
  198. This command ensures that each of the named dependencies are made available
  199. to the project by the time it returns. There must have been a call to
  200. :command:`FetchContent_Declare` for each dependency, and the first such call
  201. will control how that dependency will be made available, as described below.
  202. If ``<lowercaseName>_SOURCE_DIR`` is not set:
  203. * .. versionadded:: 3.24
  204. If a :ref:`dependency provider <dependency_providers>` is set, call the
  205. provider's command with ``FETCHCONTENT_MAKEAVAILABLE_SERIAL`` as the
  206. first argument, followed by the arguments of the first call to
  207. :command:`FetchContent_Declare` for ``<name>``. If ``SOURCE_DIR`` or
  208. ``BINARY_DIR`` were not part of the original declared arguments, they
  209. will be added with their default values.
  210. If :variable:`FETCHCONTENT_TRY_FIND_PACKAGE_MODE` was set to ``NEVER``
  211. when the details were declared, any ``FIND_PACKAGE_ARGS`` will be
  212. omitted. The ``OVERRIDE_FIND_PACKAGE`` keyword is also always omitted.
  213. If the provider fulfilled the request, ``FetchContent_MakeAvailable()``
  214. will consider that dependency handled, skip the remaining steps below,
  215. and move on to the next dependency in the list.
  216. * .. versionadded:: 3.24
  217. If permitted, :command:`find_package(<name> [<args>...]) <find_package>`
  218. will be called, where ``<args>...`` may be provided by the
  219. ``FIND_PACKAGE_ARGS`` option in :command:`FetchContent_Declare`.
  220. The value of the :variable:`FETCHCONTENT_TRY_FIND_PACKAGE_MODE` variable
  221. at the time :command:`FetchContent_Declare` was called determines whether
  222. ``FetchContent_MakeAvailable()`` can call :command:`find_package`.
  223. If the :variable:`CMAKE_FIND_PACKAGE_TARGETS_GLOBAL` variable is set to
  224. true when ``FetchContent_MakeAvailable()`` is called, it still affects
  225. any imported targets created when that in turn calls
  226. :command:`find_package`, even if that variable was false when the
  227. corresponding details were declared.
  228. If the dependency was not satisfied by a provider or a
  229. :command:`find_package` call, ``FetchContent_MakeAvailable()`` then uses
  230. the following logic to make the dependency available:
  231. * If the dependency has already been populated earlier in this run, set
  232. the ``<lowercaseName>_POPULATED``, ``<lowercaseName>_SOURCE_DIR``, and
  233. ``<lowercaseName>_BINARY_DIR`` variables in the same way as a call to
  234. :command:`FetchContent_GetProperties`, then skip the remaining steps
  235. below and move on to the next dependency in the list.
  236. * Populate the dependency using the details recorded by an earlier call
  237. to :command:`FetchContent_Declare`.
  238. Halt with a fatal error if no such details have been recorded.
  239. :variable:`FETCHCONTENT_SOURCE_DIR_<uppercaseName>` can be used to override
  240. the declared details and use content provided at the specified location
  241. instead.
  242. * .. versionadded:: 3.24
  243. Ensure the :variable:`CMAKE_FIND_PACKAGE_REDIRECTS_DIR` directory
  244. contains a ``<lowercaseName>-config.cmake`` and a
  245. ``<lowercaseName>-config-version.cmake`` file (or equivalently,
  246. ``<name>Config.cmake`` and ``<name>ConfigVersion.cmake``).
  247. The directory that the :variable:`CMAKE_FIND_PACKAGE_REDIRECTS_DIR`
  248. variable points to is cleared at the start of every CMake run.
  249. If no config file exists after populating the dependency in the previous
  250. step, a minimal one will be written which :command:`includes <include>`
  251. any ``<lowercaseName>-extra.cmake`` or ``<name>Extra.cmake`` file with
  252. the ``OPTIONAL`` flag (so the files can be missing and won't generate a
  253. warning). Similarly, if no config version file exists, a very simple
  254. one will be written which sets ``PACKAGE_VERSION_COMPATIBLE`` and
  255. ``PACKAGE_VERSION_EXACT`` to true. This ensures all future calls to
  256. :command:`find_package()` for the dependency will use the redirected
  257. config file, regardless of any version requirements.
  258. CMake cannot automatically determine an arbitrary dependency's version,
  259. so it cannot set ``PACKAGE_VERSION``.
  260. When a dependency is pulled in via :command:`add_subdirectory` in the
  261. next step, it may choose to overwrite the generated config version file
  262. in :variable:`CMAKE_FIND_PACKAGE_REDIRECTS_DIR` with one that also sets
  263. ``PACKAGE_VERSION``.
  264. The dependency may also write a ``<lowercaseName>-extra.cmake`` or
  265. ``<name>Extra.cmake`` file to perform custom processing, or define any
  266. variables that their normal (installed) package config file would
  267. otherwise usually define (many projects don't do any custom processing
  268. or set any variables and therefore have no need to do this).
  269. If required, the main project can write these files instead if the
  270. dependency project doesn't do so. This allows the main project to
  271. add missing details from older dependencies that haven't or can't be
  272. updated to support this functionality.
  273. See `Integrating With find_package()`_ for examples.
  274. * If the top directory of the populated content contains a ``CMakeLists.txt``
  275. file, call :command:`add_subdirectory` to add it to the main build.
  276. It is not an error for there to be no ``CMakeLists.txt`` file, which
  277. allows the command to be used for dependencies that make downloaded
  278. content available at a known location, but which do not need or support
  279. being added directly to the build.
  280. .. versionadded:: 3.18
  281. The ``SOURCE_SUBDIR`` option can be given in the declared details to
  282. look somewhere below the top directory instead (i.e. the same way that
  283. ``SOURCE_SUBDIR`` is used by the :command:`ExternalProject_Add`
  284. command). The path provided with ``SOURCE_SUBDIR`` must be relative,
  285. and it will be treated as relative to the top directory. It can also
  286. point to a directory that does not contain a ``CMakeLists.txt`` file,
  287. or even to a directory that doesn't exist. This can be used to avoid
  288. adding a project that contains a ``CMakeLists.txt`` file in its top
  289. directory.
  290. .. versionadded:: 3.25
  291. If the ``SYSTEM`` keyword was included in the call to
  292. :command:`FetchContent_Declare`, the ``SYSTEM`` keyword will be
  293. added to the :command:`add_subdirectory` command.
  294. .. versionadded:: 3.28
  295. If the ``EXCLUDE_FROM_ALL`` keyword was included in the call to
  296. :command:`FetchContent_Declare`, the ``EXCLUDE_FROM_ALL`` keyword will
  297. be added to the :command:`add_subdirectory` command.
  298. .. versionadded:: 3.29
  299. :variable:`CMAKE_EXPORT_FIND_PACKAGE_NAME` is set to the dependency name
  300. before calling :command:`add_subdirectory`.
  301. Projects should aim to declare the details of all dependencies they might
  302. use before they call ``FetchContent_MakeAvailable()`` for any of them.
  303. This ensures that if any of the dependencies are also sub-dependencies of
  304. one or more of the others, the main project still controls the details
  305. that will be used (because it will declare them first before the
  306. dependencies get a chance to). In the following code samples, assume that
  307. the ``uses_other`` dependency also uses ``FetchContent`` to add the ``other``
  308. dependency internally:
  309. .. code-block:: cmake
  310. # WRONG: Should declare all details first
  311. FetchContent_Declare(uses_other ...)
  312. FetchContent_MakeAvailable(uses_other)
  313. FetchContent_Declare(other ...) # Will be ignored, uses_other beat us to it
  314. FetchContent_MakeAvailable(other) # Would use details declared by uses_other
  315. .. code-block:: cmake
  316. # CORRECT: All details declared first, so they will take priority
  317. FetchContent_Declare(uses_other ...)
  318. FetchContent_Declare(other ...)
  319. FetchContent_MakeAvailable(uses_other other)
  320. Note that :variable:`CMAKE_VERIFY_INTERFACE_HEADER_SETS` is explicitly set
  321. to false upon entry to ``FetchContent_MakeAvailable()``, and is restored to
  322. its original value before the command returns. Developers typically only
  323. want to verify header sets from the main project, not those from any
  324. dependencies. This local manipulation of the
  325. :variable:`CMAKE_VERIFY_INTERFACE_HEADER_SETS` variable provides that
  326. intuitive behavior. You can use variables like
  327. :variable:`CMAKE_PROJECT_INCLUDE` or
  328. :variable:`CMAKE_PROJECT_<PROJECT-NAME>_INCLUDE` to turn verification back
  329. on for all or some dependencies. You can also set the
  330. :prop_tgt:`VERIFY_INTERFACE_HEADER_SETS` property of individual targets.
  331. .. command:: FetchContent_Populate
  332. The ``FetchContent_Populate()`` command is a self-contained call which can
  333. be used to perform content population as an isolated operation.
  334. It is rarely the right command to use, projects should almost always use
  335. :command:`FetchContent_Declare` and :command:`FetchContent_MakeAvailable`
  336. instead. The main use case for ``FetchContent_Populate()`` is in
  337. :ref:`CMake script mode <Script Processing Mode>` as part of implementing
  338. some other higher level custom feature.
  339. .. code-block:: cmake
  340. FetchContent_Populate(
  341. <name>
  342. [QUIET]
  343. [SUBBUILD_DIR <subBuildDir>]
  344. [SOURCE_DIR <srcDir>]
  345. [BINARY_DIR <binDir>]
  346. ...
  347. )
  348. At least one option must be specified after `<name>`, otherwise the call
  349. is interpreted differently (see :ref:`below <FetchContent_Populate-depName>`).
  350. The supported options for ``FetchContent_Populate()`` are the same as those
  351. for :command:`FetchContent_Declare()`, with a few exceptions. The following
  352. do not relate to populating content with ``FetchContent_Populate()`` and
  353. therefore are not supported:
  354. * ``EXCLUDE_FROM_ALL``
  355. * ``SYSTEM``
  356. * ``OVERRIDE_FIND_PACKAGE``
  357. * ``FIND_PACKAGE_ARGS``
  358. The few options shown in the signature above are either specific to
  359. ``FetchContent_Populate()``, or their behavior is slightly modified from how
  360. :command:`ExternalProject_Add` treats them:
  361. ``QUIET``
  362. The ``QUIET`` option can be given to hide the output associated with
  363. populating the specified content. If the population fails, the output will
  364. be shown regardless of whether this option was given or not so that the
  365. cause of the failure can be diagnosed. The :variable:`FETCHCONTENT_QUIET`
  366. variable has no effect on ``FetchContent_Populate()`` calls of this form
  367. where the content details are provided directly.
  368. .. versionchanged:: 3.30
  369. The ``QUIET`` option and :variable:`FETCHCONTENT_QUIET` variable have no
  370. effect when policy :policy:`CMP0168` is set to ``NEW``. The output is
  371. still quiet by default in that case, but verbosity is controlled by the
  372. message logging level (see :variable:`CMAKE_MESSAGE_LOG_LEVEL` and
  373. :option:`--log-level <cmake --log-level>`).
  374. ``SUBBUILD_DIR``
  375. The ``SUBBUILD_DIR`` argument can be provided to change the location of the
  376. sub-build created to perform the population. The default value is
  377. ``${CMAKE_CURRENT_BINARY_DIR}/<lowercaseName>-subbuild``, and it would be
  378. unusual to need to override this default. If a relative path is specified,
  379. it will be interpreted as relative to :variable:`CMAKE_CURRENT_BINARY_DIR`.
  380. This option should not be confused with the ``SOURCE_SUBDIR`` option, which
  381. only affects the :command:`FetchContent_MakeAvailable` command.
  382. .. versionchanged:: 3.30
  383. ``SUBBUILD_DIR`` is ignored when policy :policy:`CMP0168` is set to
  384. ``NEW``, since there is no sub-build in that case.
  385. ``SOURCE_DIR``, ``BINARY_DIR``
  386. The ``SOURCE_DIR`` and ``BINARY_DIR`` arguments are supported by
  387. :command:`ExternalProject_Add`, but different default values are used by
  388. ``FetchContent_Populate()``. ``SOURCE_DIR`` defaults to
  389. ``${CMAKE_CURRENT_BINARY_DIR}/<lowercaseName>-src``, and ``BINARY_DIR``
  390. defaults to ``${CMAKE_CURRENT_BINARY_DIR}/<lowercaseName>-build``.
  391. If a relative path is specified, it will be interpreted as relative to
  392. :variable:`CMAKE_CURRENT_BINARY_DIR`.
  393. In addition to the above explicit options, any other unrecognized options are
  394. passed through unmodified to :command:`ExternalProject_Add` to set up the
  395. download, patch, and update steps. The following options are explicitly
  396. prohibited (they are disabled by the ``FetchContent_Populate()`` command):
  397. - ``CONFIGURE_COMMAND``
  398. - ``BUILD_COMMAND``
  399. - ``INSTALL_COMMAND``
  400. - ``TEST_COMMAND``
  401. With this form, the :variable:`FETCHCONTENT_FULLY_DISCONNECTED` and
  402. :variable:`FETCHCONTENT_UPDATES_DISCONNECTED` variables are ignored.
  403. When this form of ``FetchContent_Populate()`` returns, the following
  404. variables will be set in the scope of the caller:
  405. ``<lowercaseName>_SOURCE_DIR``
  406. The location where the populated content can be found upon return.
  407. ``<lowercaseName>_BINARY_DIR``
  408. A directory originally intended for use as a corresponding build directory,
  409. but is unlikely to be relevant when using this form of the command.
  410. If using ``FetchContent_Populate()`` within
  411. :ref:`CMake script mode <Script Processing Mode>`, be aware that the
  412. implementation sets up a sub-build which therefore requires a CMake
  413. generator and build tool to be available. If these cannot be found by
  414. default, then the :variable:`CMAKE_GENERATOR` and potentially the
  415. :variable:`CMAKE_MAKE_PROGRAM` variables will need to be set appropriately
  416. on the command line invoking the script.
  417. .. versionchanged:: 3.30
  418. If policy :policy:`CMP0168` is set to ``NEW``, no sub-build is used.
  419. Within :ref:`CMake script mode <Script Processing Mode>`, that allows
  420. ``FetchContent_Populate()`` to be called without any build tool or
  421. CMake generator.
  422. .. versionadded:: 3.18
  423. Added support for the ``DOWNLOAD_NO_EXTRACT`` option.
  424. .. _`FetchContent_Populate-depName`:
  425. The command supports another form, although it should no longer be used:
  426. .. code-block:: cmake
  427. FetchContent_Populate(<name>)
  428. .. versionchanged:: 3.30
  429. This form is deprecated. Policy :policy:`CMP0169` provides backward
  430. compatibility for projects that still need to use this form, but projects
  431. should be updated to use :command:`FetchContent_MakeAvailable` instead.
  432. In this form, the only argument given to ``FetchContent_Populate()`` is the
  433. ``<name>``. When used this way, the command assumes the content details have
  434. been recorded by an earlier call to :command:`FetchContent_Declare`. The
  435. details are stored in a global property, so they are unaffected by things
  436. like variable or directory scope. Therefore, it doesn't matter where in the
  437. project the details were previously declared, as long as they have been
  438. declared before the call to ``FetchContent_Populate()``. Those saved details
  439. are then used to populate the content using a method based on
  440. :command:`ExternalProject_Add` (see policy :policy:`CMP0168` for important
  441. behavioral aspects of how that is done).
  442. When this form of ``FetchContent_Populate()`` returns, the following
  443. variables will be set in the scope of the caller:
  444. ``<lowercaseName>_POPULATED``
  445. This will always be set to ``TRUE`` by the call.
  446. ``<lowercaseName>_SOURCE_DIR``
  447. The location where the populated content can be found upon return.
  448. ``<lowercaseName>_BINARY_DIR``
  449. A directory intended for use as a corresponding build directory.
  450. The values of the three variables can also be retrieved from anywhere in the
  451. project hierarchy using the :command:`FetchContent_GetProperties` command.
  452. The implementation ensures that if the content has already been populated
  453. in a previous CMake run, that content will be reused rather than repopulating
  454. again. For the common case where population involves downloading content,
  455. the cost of the download is only paid once. But note that it is an error to
  456. call ``FetchContent_Populate(<name>)`` with the same ``<name>`` more than
  457. once within a single CMake run. See :command:`FetchContent_GetProperties`
  458. for how to determine if population of a ``<name>`` has already been
  459. performed in the current run.
  460. .. command:: FetchContent_GetProperties
  461. When using saved content details, a call to
  462. :command:`FetchContent_MakeAvailable` or :command:`FetchContent_Populate`
  463. records information in global properties which can be queried at any time.
  464. This information may include the source and binary directories associated with
  465. the content, and also whether or not the content population has been processed
  466. during the current configure run.
  467. .. code-block:: cmake
  468. FetchContent_GetProperties(
  469. <name>
  470. [SOURCE_DIR <srcDirVar>]
  471. [BINARY_DIR <binDirVar>]
  472. [POPULATED <doneVar>]
  473. )
  474. The ``SOURCE_DIR``, ``BINARY_DIR``, and ``POPULATED`` options can be used to
  475. specify which properties should be retrieved. Each option accepts a value
  476. which is the name of the variable in which to store that property. Most of
  477. the time though, only ``<name>`` is given, in which case the call will then
  478. set the same variables as a call to
  479. :command:`FetchContent_MakeAvailable(name) <FetchContent_MakeAvailable>` or
  480. :command:`FetchContent_Populate(name) <FetchContent_Populate>`.
  481. Note that the ``SOURCE_DIR`` and ``BINARY_DIR`` values can be empty if the
  482. call is fulfilled by a :ref:`dependency provider <dependency_providers>`.
  483. This command is rarely needed when using
  484. :command:`FetchContent_MakeAvailable`. It is more commonly used as part of
  485. implementing the deprecated pattern with :command:`FetchContent_Populate`,
  486. which ensures that the relevant variables will always be defined regardless
  487. of whether or not the population has been performed elsewhere in the project
  488. already:
  489. .. code-block:: cmake
  490. # WARNING: This pattern is deprecated, don't use it!
  491. #
  492. # Check if population has already been performed
  493. FetchContent_GetProperties(depname)
  494. if(NOT depname_POPULATED)
  495. # Fetch the content using previously declared details
  496. FetchContent_Populate(depname)
  497. # Set custom variables, policies, etc.
  498. # ...
  499. # Bring the populated content into the build
  500. add_subdirectory(${depname_SOURCE_DIR} ${depname_BINARY_DIR})
  501. endif()
  502. .. command:: FetchContent_SetPopulated
  503. .. versionadded:: 3.24
  504. .. note::
  505. This command should only be called by
  506. :ref:`dependency providers <dependency_providers>`. Calling it in any
  507. other context is unsupported and future CMake versions may halt with a
  508. fatal error in such cases.
  509. .. code-block:: cmake
  510. FetchContent_SetPopulated(
  511. <name>
  512. [SOURCE_DIR <srcDir>]
  513. [BINARY_DIR <binDir>]
  514. )
  515. If a provider command fulfills a ``FETCHCONTENT_MAKEAVAILABLE_SERIAL``
  516. request, it must call this function before returning. The ``SOURCE_DIR``
  517. and ``BINARY_DIR`` arguments can be used to specify the values that
  518. :command:`FetchContent_GetProperties` should return for its corresponding
  519. arguments. Only provide ``SOURCE_DIR`` and ``BINARY_DIR`` if they have
  520. the same meaning as if they had been populated by the built-in
  521. :command:`FetchContent_MakeAvailable` implementation.
  522. Variables
  523. ^^^^^^^^^
  524. A number of cache variables can influence the behavior where details from a
  525. :command:`FetchContent_Declare` call are used to populate content.
  526. .. note::
  527. All of these variables are intended for the developer to customize behavior.
  528. They should not normally be set by the project.
  529. .. variable:: FETCHCONTENT_BASE_DIR
  530. In most cases, the saved details do not specify any options relating to the
  531. directories to use for the internal sub-build, final source, and build areas.
  532. It is generally best to leave these decisions up to the ``FetchContent``
  533. module to handle on the project's behalf. The ``FETCHCONTENT_BASE_DIR``
  534. cache variable controls the point under which all content population
  535. directories are collected, but in most cases, developers would not need to
  536. change this. The default location is ``${CMAKE_BINARY_DIR}/_deps``, but if
  537. developers change this value, they should aim to keep the path short and
  538. just below the top level of the build tree to avoid running into path
  539. length problems on Windows.
  540. .. variable:: FETCHCONTENT_QUIET
  541. The logging output during population can be quite verbose, making the
  542. configure stage quite noisy. This cache option (``ON`` by default) hides
  543. all population output unless an error is encountered. If experiencing
  544. problems with hung downloads, temporarily switching this option off may
  545. help diagnose which content population is causing the issue.
  546. .. versionchanged:: 3.30
  547. ``FETCHCONTENT_QUIET`` is ignored if policy :policy:`CMP0168` is set to
  548. ``NEW``. The output is still quiet by default in that case, but verbosity
  549. is controlled by the message logging level (see
  550. :variable:`CMAKE_MESSAGE_LOG_LEVEL` and
  551. :option:`--log-level <cmake --log-level>`).
  552. .. variable:: FETCHCONTENT_FULLY_DISCONNECTED
  553. When this option is enabled, no attempt is made to download or update
  554. any content. It is assumed that all content has already been populated in
  555. a previous run, or the source directories have been pointed at existing
  556. contents the developer has provided manually (using options described
  557. further below). When the developer knows that no changes have been made to
  558. any content details, turning this option ``ON`` can speed up
  559. the configure stage. It is ``OFF`` by default.
  560. .. note::
  561. The ``FETCHCONTENT_FULLY_DISCONNECTED`` variable is not an appropriate way
  562. to prevent any network access on the first run in a build directory.
  563. Doing so can break projects, lead to misleading error messages, and hide
  564. subtle population failures. This variable is specifically intended to
  565. only be turned on *after* the first time CMake has been run.
  566. If you want to prevent network access even on the first run, use a
  567. :ref:`dependency provider <dependency_providers>` and populate the
  568. dependency from local content instead.
  569. .. variable:: FETCHCONTENT_UPDATES_DISCONNECTED
  570. This is a less severe download/update control compared to
  571. :variable:`FETCHCONTENT_FULLY_DISCONNECTED`. Instead of bypassing all
  572. download and update logic, ``FETCHCONTENT_UPDATES_DISCONNECTED`` only
  573. prevents the update step from making connections to remote servers
  574. when using the git or hg download methods. Updates still occur if details
  575. about the update step change, but the update is attempted with only the
  576. information already available locally (so switching to a different tag or
  577. commit that is already fetched locally will succeed, but switching to an
  578. unknown commit hash will fail). The download step is not affected, so if
  579. content has not been downloaded previously, it will still be downloaded
  580. when this option is enabled. This can speed up the configure step, but
  581. not as much as :variable:`FETCHCONTENT_FULLY_DISCONNECTED`.
  582. ``FETCHCONTENT_UPDATES_DISCONNECTED`` is ``OFF`` by default.
  583. .. variable:: FETCHCONTENT_TRY_FIND_PACKAGE_MODE
  584. .. versionadded:: 3.24
  585. This variable modifies the details that :command:`FetchContent_Declare`
  586. records for a given dependency. While it ultimately controls the behavior
  587. of :command:`FetchContent_MakeAvailable`, it is the variable's value when
  588. :command:`FetchContent_Declare` is called that gets used. It makes no
  589. difference what the variable is set to when
  590. :command:`FetchContent_MakeAvailable` is called. Since the variable should
  591. only be set by the user and not by projects directly, it will typically have
  592. the same value throughout anyway, so this distinction is not usually
  593. noticeable.
  594. ``FETCHCONTENT_TRY_FIND_PACKAGE_MODE`` ultimately controls whether
  595. :command:`FetchContent_MakeAvailable` is allowed to call
  596. :command:`find_package` to satisfy a dependency. The variable can be set
  597. to one of the following values:
  598. ``OPT_IN``
  599. :command:`FetchContent_MakeAvailable` will only call
  600. :command:`find_package` if the :command:`FetchContent_Declare` call
  601. included a ``FIND_PACKAGE_ARGS`` keyword. This is also the default
  602. behavior if ``FETCHCONTENT_TRY_FIND_PACKAGE_MODE`` is not set.
  603. ``ALWAYS``
  604. :command:`find_package` can be called by
  605. :command:`FetchContent_MakeAvailable` regardless of whether the
  606. :command:`FetchContent_Declare` call included a ``FIND_PACKAGE_ARGS``
  607. keyword or not. If no ``FIND_PACKAGE_ARGS`` keyword was given, the
  608. behavior will be as though ``FIND_PACKAGE_ARGS`` had been provided,
  609. with no additional arguments after it.
  610. ``NEVER``
  611. :command:`FetchContent_MakeAvailable` will not call
  612. :command:`find_package`. Any ``FIND_PACKAGE_ARGS`` given to the
  613. :command:`FetchContent_Declare` call will be ignored.
  614. As a special case, if the :variable:`FETCHCONTENT_SOURCE_DIR_<uppercaseName>`
  615. variable has a non-empty value for a dependency, it is assumed that the
  616. user is overriding all other methods of making that dependency available.
  617. ``FETCHCONTENT_TRY_FIND_PACKAGE_MODE`` will have no effect on that
  618. dependency and :command:`FetchContent_MakeAvailable` will not try to call
  619. :command:`find_package` for it.
  620. In addition to the above, the following variables are also defined for each
  621. content name:
  622. .. variable:: FETCHCONTENT_SOURCE_DIR_<uppercaseName>
  623. If this is set, no download or update steps are performed for the specified
  624. content and the ``<lowercaseName>_SOURCE_DIR`` variable returned to the
  625. caller is pointed at this location. This gives developers a way to have a
  626. separate checkout of the content that they can modify freely without
  627. interference from the build. The build simply uses that existing source,
  628. but it still defines ``<lowercaseName>_BINARY_DIR`` to point inside its own
  629. build area. Developers are strongly encouraged to use this mechanism rather
  630. than editing the sources populated in the default location, as changes to
  631. sources in the default location can be lost when content population details
  632. are changed by the project.
  633. .. variable:: FETCHCONTENT_UPDATES_DISCONNECTED_<uppercaseName>
  634. This is the per-content equivalent of
  635. :variable:`FETCHCONTENT_UPDATES_DISCONNECTED`. If the global option or
  636. this option is ``ON``, then updates for the git and hg methods will not
  637. contact any remote for the named content. They will only use information
  638. already available locally. Disabling updates for individual content can
  639. be useful for content whose details rarely change, while still leaving
  640. other frequently changing content with updates enabled.
  641. .. _`fetch-content-examples`:
  642. Examples
  643. ^^^^^^^^
  644. Typical Case
  645. """"""""""""
  646. This first fairly straightforward example ensures that some popular testing
  647. frameworks are available to the main build:
  648. .. code-block:: cmake
  649. include(FetchContent)
  650. FetchContent_Declare(
  651. googletest
  652. GIT_REPOSITORY https://github.com/google/googletest.git
  653. GIT_TAG 703bd9caab50b139428cea1aaff9974ebee5742e # release-1.10.0
  654. )
  655. FetchContent_Declare(
  656. Catch2
  657. GIT_REPOSITORY https://github.com/catchorg/Catch2.git
  658. GIT_TAG 605a34765aa5d5ecbf476b4598a862ada971b0cc # v3.0.1
  659. )
  660. # After the following call, the CMake targets defined by googletest and
  661. # Catch2 will be available to the rest of the build
  662. FetchContent_MakeAvailable(googletest Catch2)
  663. .. _FetchContent-find_package-integration-examples:
  664. Integrating With find_package()
  665. """""""""""""""""""""""""""""""
  666. For the previous example, if the user wanted to try to find ``googletest``
  667. and ``Catch2`` via :command:`find_package` first before trying to download
  668. and build them from source, they could set the
  669. :variable:`FETCHCONTENT_TRY_FIND_PACKAGE_MODE` variable to ``ALWAYS``.
  670. This would also affect any other calls to :command:`FetchContent_Declare`
  671. throughout the project, which might not be acceptable. The behavior can be
  672. enabled for just these two dependencies instead by adding ``FIND_PACKAGE_ARGS``
  673. to the declared details and leaving
  674. :variable:`FETCHCONTENT_TRY_FIND_PACKAGE_MODE` unset, or set to ``OPT_IN``:
  675. .. code-block:: cmake
  676. include(FetchContent)
  677. FetchContent_Declare(
  678. googletest
  679. GIT_REPOSITORY https://github.com/google/googletest.git
  680. GIT_TAG 703bd9caab50b139428cea1aaff9974ebee5742e # release-1.10.0
  681. FIND_PACKAGE_ARGS NAMES GTest
  682. )
  683. FetchContent_Declare(
  684. Catch2
  685. GIT_REPOSITORY https://github.com/catchorg/Catch2.git
  686. GIT_TAG 605a34765aa5d5ecbf476b4598a862ada971b0cc # v3.0.1
  687. FIND_PACKAGE_ARGS
  688. )
  689. # This will try calling find_package() first for both dependencies
  690. FetchContent_MakeAvailable(googletest Catch2)
  691. For ``Catch2``, no additional arguments to :command:`find_package` are needed,
  692. so no additional arguments are provided after the ``FIND_PACKAGE_ARGS``
  693. keyword. For ``googletest``, its package is more commonly called ``GTest``,
  694. so arguments are added to support it being found by that name.
  695. If the user wanted to disable :command:`FetchContent_MakeAvailable` from
  696. calling :command:`find_package` for any dependency, even if it provided
  697. ``FIND_PACKAGE_ARGS`` in its declared details, they could set
  698. :variable:`FETCHCONTENT_TRY_FIND_PACKAGE_MODE` to ``NEVER``.
  699. If the project wanted to indicate that these two dependencies should be
  700. downloaded and built from source and that :command:`find_package` calls
  701. should be redirected to use the built dependencies, the
  702. ``OVERRIDE_FIND_PACKAGE`` option should be used when declaring the content
  703. details:
  704. .. code-block:: cmake
  705. include(FetchContent)
  706. FetchContent_Declare(
  707. googletest
  708. GIT_REPOSITORY https://github.com/google/googletest.git
  709. GIT_TAG 703bd9caab50b139428cea1aaff9974ebee5742e # release-1.10.0
  710. OVERRIDE_FIND_PACKAGE
  711. )
  712. FetchContent_Declare(
  713. Catch2
  714. GIT_REPOSITORY https://github.com/catchorg/Catch2.git
  715. GIT_TAG 605a34765aa5d5ecbf476b4598a862ada971b0cc # v3.0.1
  716. OVERRIDE_FIND_PACKAGE
  717. )
  718. # The following will automatically forward through to FetchContent_MakeAvailable()
  719. find_package(googletest)
  720. find_package(Catch2)
  721. CMake provides a FindGTest module which defines some variables that older
  722. projects may use instead of linking to the imported targets. To support
  723. those cases, we can provide an extra file. In keeping with the
  724. "first to define, wins" philosophy of ``FetchContent``, we only write out
  725. that file if something else hasn't already done so.
  726. .. code-block:: cmake
  727. FetchContent_MakeAvailable(googletest)
  728. if(NOT EXISTS ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/googletest-extra.cmake AND
  729. NOT EXISTS ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/googletestExtra.cmake)
  730. file(WRITE ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/googletest-extra.cmake
  731. [=[
  732. if("${GTEST_LIBRARIES}" STREQUAL "" AND TARGET GTest::gtest)
  733. set(GTEST_LIBRARIES GTest::gtest)
  734. endif()
  735. if("${GTEST_MAIN_LIBRARIES}" STREQUAL "" AND TARGET GTest::gtest_main)
  736. set(GTEST_MAIN_LIBRARIES GTest::gtest_main)
  737. endif()
  738. if("${GTEST_BOTH_LIBRARIES}" STREQUAL "")
  739. set(GTEST_BOTH_LIBRARIES ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES})
  740. endif()
  741. ]=])
  742. endif()
  743. Projects will also likely be using ``find_package(GTest)`` rather than
  744. ``find_package(googletest)``, but it is possible to make use of the
  745. :variable:`CMAKE_FIND_PACKAGE_REDIRECTS_DIR` area to pull in the latter as
  746. a dependency of the former. This is likely to be sufficient to satisfy
  747. a typical ``find_package(GTest)`` call.
  748. .. code-block:: cmake
  749. FetchContent_MakeAvailable(googletest)
  750. if(NOT EXISTS ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/gtest-config.cmake AND
  751. NOT EXISTS ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/GTestConfig.cmake)
  752. file(WRITE ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/gtest-config.cmake
  753. [=[
  754. include(CMakeFindDependencyMacro)
  755. find_dependency(googletest)
  756. ]=])
  757. endif()
  758. if(NOT EXISTS ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/gtest-config-version.cmake AND
  759. NOT EXISTS ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/GTestConfigVersion.cmake)
  760. file(WRITE ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/gtest-config-version.cmake
  761. [=[
  762. include(${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/googletest-config-version.cmake OPTIONAL)
  763. if(NOT PACKAGE_VERSION_COMPATIBLE)
  764. include(${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/googletestConfigVersion.cmake OPTIONAL)
  765. endif()
  766. ]=])
  767. endif()
  768. Overriding Where To Find CMakeLists.txt
  769. """""""""""""""""""""""""""""""""""""""
  770. If the sub-project's ``CMakeLists.txt`` file is not at the top level of its
  771. source tree, the ``SOURCE_SUBDIR`` option can be used to tell ``FetchContent``
  772. where to find it. The following example shows how to use that option, and
  773. it also sets a variable which is meaningful to the subproject before pulling
  774. it into the main build (set as an ``INTERNAL`` cache variable to avoid
  775. problems with policy :policy:`CMP0077`):
  776. .. code-block:: cmake
  777. include(FetchContent)
  778. FetchContent_Declare(
  779. protobuf
  780. GIT_REPOSITORY https://github.com/protocolbuffers/protobuf.git
  781. GIT_TAG ae50d9b9902526efd6c7a1907d09739f959c6297 # v3.15.0
  782. SOURCE_SUBDIR cmake
  783. )
  784. set(protobuf_BUILD_TESTS OFF CACHE INTERNAL "")
  785. FetchContent_MakeAvailable(protobuf)
  786. Complex Dependency Hierarchies
  787. """"""""""""""""""""""""""""""
  788. In more complex project hierarchies, the dependency relationships can be more
  789. complicated. Consider a hierarchy where ``projA`` is the top level project and
  790. it depends directly on projects ``projB`` and ``projC``. Both ``projB`` and
  791. ``projC`` can be built standalone and they also both depend on another project
  792. ``projD``. ``projB`` additionally depends on ``projE``. This example assumes
  793. that all five projects are available on a company git server. The
  794. ``CMakeLists.txt`` of each project might have sections like the following:
  795. .. code-block:: cmake
  796. :caption: *projA*
  797. include(FetchContent)
  798. FetchContent_Declare(
  799. projB
  800. GIT_REPOSITORY [email protected]:git/projB.git
  801. GIT_TAG 4a89dc7e24ff212a7b5167bef7ab079d
  802. )
  803. FetchContent_Declare(
  804. projC
  805. GIT_REPOSITORY [email protected]:git/projC.git
  806. GIT_TAG 4ad4016bd1d8d5412d135cf8ceea1bb9
  807. )
  808. FetchContent_Declare(
  809. projD
  810. GIT_REPOSITORY [email protected]:git/projD.git
  811. GIT_TAG origin/integrationBranch
  812. )
  813. FetchContent_Declare(
  814. projE
  815. GIT_REPOSITORY [email protected]:git/projE.git
  816. GIT_TAG v2.3-rc1
  817. )
  818. # Order is important, see notes in the discussion further below
  819. FetchContent_MakeAvailable(projD projB projC)
  820. .. code-block:: cmake
  821. :caption: *projB*
  822. include(FetchContent)
  823. FetchContent_Declare(
  824. projD
  825. GIT_REPOSITORY [email protected]:git/projD.git
  826. GIT_TAG 20b415f9034bbd2a2e8216e9a5c9e632
  827. )
  828. FetchContent_Declare(
  829. projE
  830. GIT_REPOSITORY [email protected]:git/projE.git
  831. GIT_TAG 68e20f674a48be38d60e129f600faf7d
  832. )
  833. FetchContent_MakeAvailable(projD projE)
  834. .. code-block:: cmake
  835. :caption: *projC*
  836. include(FetchContent)
  837. FetchContent_Declare(
  838. projD
  839. GIT_REPOSITORY [email protected]:git/projD.git
  840. GIT_TAG 7d9a17ad2c962aa13e2fbb8043fb6b8a
  841. )
  842. FetchContent_MakeAvailable(projD)
  843. A few key points should be noted in the above:
  844. - ``projB`` and ``projC`` define different content details for ``projD``,
  845. but ``projA`` also defines a set of content details for ``projD``.
  846. Because ``projA`` will define them first, the details from ``projB`` and
  847. ``projC`` will not be used. The override details defined by ``projA``
  848. are not required to match either of those from ``projB`` or ``projC``, but
  849. it is up to the higher level project to ensure that the details it does
  850. define still make sense for the child projects.
  851. - In the ``projA`` call to :command:`FetchContent_MakeAvailable`, ``projD``
  852. is listed ahead of ``projB`` and ``projC``, so it will be populated before
  853. either ``projB`` or ``projC``. It isn't required for ``projA`` to do this,
  854. doing so ensures that ``projA`` fully controls the environment in which
  855. ``projD`` is brought into the build (directory properties are particularly
  856. relevant).
  857. - While ``projA`` defines content details for ``projE``, it does not need
  858. to explicitly call ``FetchContent_MakeAvailable(projE)`` or
  859. ``FetchContent_Populate(projD)`` itself. Instead, it leaves that to the
  860. child ``projB``. For higher level projects, it is often enough to just
  861. define the override content details and leave the actual population to the
  862. child projects. This saves repeating the same thing at each level of the
  863. project hierarchy unnecessarily, but it should only be done if directory
  864. properties set by dependencies are not expected to influence the population
  865. of the shared dependency (``projE`` in this case).
  866. Populating Content Without Adding It To The Build
  867. """""""""""""""""""""""""""""""""""""""""""""""""
  868. Projects don't always need to add the populated content to the build.
  869. Sometimes the project just wants to make the downloaded content available at
  870. a predictable location. The next example ensures that a set of standard
  871. company toolchain files (and potentially even the toolchain binaries
  872. themselves) is available early enough to be used for that same build.
  873. .. code-block:: cmake
  874. cmake_minimum_required(VERSION 3.14)
  875. include(FetchContent)
  876. FetchContent_Declare(
  877. mycom_toolchains
  878. URL https://intranet.mycompany.com//toolchains_1.3.2.tar.gz
  879. )
  880. FetchContent_MakeAvailable(mycom_toolchains)
  881. project(CrossCompileExample)
  882. The project could be configured to use one of the downloaded toolchains like
  883. so:
  884. .. code-block:: shell
  885. cmake -DCMAKE_TOOLCHAIN_FILE=_deps/mycom_toolchains-src/toolchain_arm.cmake /path/to/src
  886. When CMake processes the ``CMakeLists.txt`` file, it will download and unpack
  887. the tarball into ``_deps/mycompany_toolchains-src`` relative to the build
  888. directory. The :variable:`CMAKE_TOOLCHAIN_FILE` variable is not used until
  889. the :command:`project` command is reached, at which point CMake looks for the
  890. named toolchain file relative to the build directory. Because the tarball has
  891. already been downloaded and unpacked by then, the toolchain file will be in
  892. place, even the very first time that :program:`cmake` is run in the build directory.
  893. Populating Content In CMake Script Mode
  894. """""""""""""""""""""""""""""""""""""""
  895. This last example demonstrates how one might download and unpack a
  896. firmware tarball using CMake's :ref:`script mode <Script Processing Mode>`.
  897. The call to :command:`FetchContent_Populate` specifies all the content details
  898. and the unpacked firmware will be placed in a ``firmware`` directory below the
  899. current working directory.
  900. .. code-block:: cmake
  901. :caption: :file:`getFirmware.cmake`
  902. # NOTE: Intended to be run in script mode with cmake -P
  903. include(FetchContent)
  904. FetchContent_Populate(
  905. firmware
  906. URL https://mycompany.com/assets/firmware-1.23-arm.tar.gz
  907. URL_HASH MD5=68247684da89b608d466253762b0ff11
  908. SOURCE_DIR firmware
  909. )
  910. #]=======================================================================]
  911. # Control policies for most of the things defined by this module. Only a few
  912. # FetchContent_MakeAvailable() implementation details are excluded for
  913. # backward compatibility reasons (see just after the endblock()).
  914. block(SCOPE_FOR POLICIES)
  915. cmake_policy(VERSION 3.29)
  916. include(${CMAKE_CURRENT_LIST_DIR}/ExternalProject/shared_internal_commands.cmake)
  917. #=======================================================================
  918. # Recording and retrieving content details for later population
  919. #=======================================================================
  920. # Internal use, projects must not call this directly. It is
  921. # intended for use by FetchContent_Declare() only.
  922. #
  923. # Sets a content-specific global property (not meant for use
  924. # outside of functions defined here in this file) which can later
  925. # be retrieved using __FetchContent_getSavedDetails() with just the
  926. # same content name. If there is already a value stored in the
  927. # property, it is left unchanged and this call has no effect.
  928. # This allows parent projects to define the content details,
  929. # overriding anything a child project may try to set (properties
  930. # are not cached between runs, so the first thing to set it in a
  931. # build will be in control).
  932. function(__FetchContent_declareDetails contentName)
  933. string(TOLOWER ${contentName} contentNameLower)
  934. set(savedDetailsPropertyName "_FetchContent_${contentNameLower}_savedDetails")
  935. get_property(alreadyDefined GLOBAL PROPERTY ${savedDetailsPropertyName} DEFINED)
  936. if(alreadyDefined)
  937. return()
  938. endif()
  939. if("${FETCHCONTENT_TRY_FIND_PACKAGE_MODE}" STREQUAL "ALWAYS")
  940. set(__tryFindPackage TRUE)
  941. set(__tryFindPackageAllowed TRUE)
  942. elseif("${FETCHCONTENT_TRY_FIND_PACKAGE_MODE}" STREQUAL "NEVER")
  943. set(__tryFindPackage FALSE)
  944. set(__tryFindPackageAllowed FALSE)
  945. elseif("${FETCHCONTENT_TRY_FIND_PACKAGE_MODE}" STREQUAL "OPT_IN" OR
  946. NOT DEFINED FETCHCONTENT_TRY_FIND_PACKAGE_MODE)
  947. set(__tryFindPackage FALSE)
  948. set(__tryFindPackageAllowed TRUE)
  949. else()
  950. message(FATAL_ERROR
  951. "Unsupported value for FETCHCONTENT_TRY_FIND_PACKAGE_MODE: "
  952. "${FETCHCONTENT_TRY_FIND_PACKAGE_MODE}"
  953. )
  954. endif()
  955. set(__cmdArgs)
  956. set(__findPackageArgs)
  957. set(__sawQuietKeyword NO)
  958. set(__sawGlobalKeyword NO)
  959. set(__direct_population NO)
  960. foreach(__item IN LISTS ARGN)
  961. if(__item STREQUAL "__DIRECT_POPULATION")
  962. set(__direct_population YES)
  963. continue()
  964. endif()
  965. if(DEFINED __findPackageArgs)
  966. # All remaining args are for find_package()
  967. string(APPEND __findPackageArgs " [==[${__item}]==]")
  968. if(__item STREQUAL "QUIET")
  969. set(__sawQuietKeyword YES)
  970. elseif(__item STREQUAL "GLOBAL")
  971. set(__sawGlobalKeyword YES)
  972. endif()
  973. continue()
  974. endif()
  975. # Still processing non-find_package() args
  976. if(__item STREQUAL "FIND_PACKAGE_ARGS")
  977. if(__tryFindPackageAllowed)
  978. set(__tryFindPackage TRUE)
  979. endif()
  980. # All arguments after this keyword are for find_package(). Define the
  981. # variable but with an empty value initially. This allows us to check
  982. # at the start of the loop whether to store remaining items in this
  983. # variable or not. Note that there could be no more args, which is still
  984. # a valid case because we automatically provide ${contentName} as the
  985. # package name and there may not need to be any further arguments.
  986. set(__findPackageArgs "")
  987. continue() # Don't store this item
  988. elseif(__item STREQUAL "OVERRIDE_FIND_PACKAGE")
  989. set(__tryFindPackageAllowed FALSE)
  990. # Define a separate dedicated property for find_package() to check
  991. # in its implementation. This will be a placeholder until FetchContent
  992. # actually does the population. After that, we will have created a
  993. # stand-in config file that find_package() will pick up instead.
  994. set(propertyName "_FetchContent_${contentNameLower}_override_find_package")
  995. define_property(GLOBAL PROPERTY ${propertyName})
  996. set_property(GLOBAL PROPERTY ${propertyName} TRUE)
  997. endif()
  998. string(APPEND __cmdArgs " [==[${__item}]==]")
  999. endforeach()
  1000. set_property(GLOBAL PROPERTY
  1001. "_FetchContent_${contentNameLower}_direct_population" ${__direct_population}
  1002. )
  1003. define_property(GLOBAL PROPERTY ${savedDetailsPropertyName})
  1004. cmake_language(EVAL CODE
  1005. "set_property(GLOBAL PROPERTY ${savedDetailsPropertyName} ${__cmdArgs})"
  1006. )
  1007. if(__tryFindPackage AND __tryFindPackageAllowed)
  1008. set(propertyName "_FetchContent_${contentNameLower}_find_package_args")
  1009. define_property(GLOBAL PROPERTY ${propertyName})
  1010. if(NOT __sawQuietKeyword)
  1011. string(PREPEND __findPackageArgs "QUIET ")
  1012. endif()
  1013. if(CMAKE_FIND_PACKAGE_TARGETS_GLOBAL AND NOT __sawGlobalKeyword)
  1014. string(APPEND __findPackageArgs " GLOBAL")
  1015. endif()
  1016. cmake_language(EVAL CODE
  1017. "set_property(GLOBAL PROPERTY ${propertyName} ${__findPackageArgs})"
  1018. )
  1019. endif()
  1020. endfunction()
  1021. # Internal use, projects must not call this directly. It is
  1022. # intended for use by the FetchContent_Declare() function.
  1023. #
  1024. # Retrieves details saved for the specified content in an
  1025. # earlier call to __FetchContent_declareDetails().
  1026. function(__FetchContent_getSavedDetails contentName outVar)
  1027. string(TOLOWER ${contentName} contentNameLower)
  1028. set(propertyName "_FetchContent_${contentNameLower}_savedDetails")
  1029. get_property(alreadyDefined GLOBAL PROPERTY ${propertyName} DEFINED)
  1030. if(NOT alreadyDefined)
  1031. message(FATAL_ERROR "No content details recorded for ${contentName}")
  1032. endif()
  1033. get_property(propertyValue GLOBAL PROPERTY ${propertyName})
  1034. set(${outVar} "${propertyValue}" PARENT_SCOPE)
  1035. endfunction()
  1036. # Saves population details of the content, sets defaults for the
  1037. # SOURCE_DIR and BUILD_DIR.
  1038. function(FetchContent_Declare contentName)
  1039. # Always check this even if we won't save these details.
  1040. # This helps projects catch errors earlier.
  1041. # Avoid using if(... IN_LIST ...) so we don't have to alter policy settings
  1042. list(FIND ARGN OVERRIDE_FIND_PACKAGE index_OVERRIDE_FIND_PACKAGE)
  1043. list(FIND ARGN FIND_PACKAGE_ARGS index_FIND_PACKAGE_ARGS)
  1044. if(index_OVERRIDE_FIND_PACKAGE GREATER_EQUAL 0 AND
  1045. index_FIND_PACKAGE_ARGS GREATER_EQUAL 0)
  1046. message(FATAL_ERROR
  1047. "Cannot specify both OVERRIDE_FIND_PACKAGE and FIND_PACKAGE_ARGS "
  1048. "when declaring details for ${contentName}"
  1049. )
  1050. endif()
  1051. # Because we are only looking for a subset of the supported keywords, we
  1052. # cannot check for multi-value arguments with this method. We will have to
  1053. # handle the URL keyword differently.
  1054. set(oneValueArgs
  1055. GIT_REPOSITORY
  1056. SVN_REPOSITORY
  1057. DOWNLOAD_NO_EXTRACT
  1058. DOWNLOAD_EXTRACT_TIMESTAMP
  1059. BINARY_DIR
  1060. SOURCE_DIR
  1061. )
  1062. cmake_parse_arguments(PARSE_ARGV 1 ARG "" "${oneValueArgs}" "")
  1063. string(TOLOWER ${contentName} contentNameLower)
  1064. if(NOT ARG_BINARY_DIR)
  1065. set(ARG_BINARY_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-build")
  1066. endif()
  1067. if(NOT ARG_SOURCE_DIR)
  1068. set(ARG_SOURCE_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-src")
  1069. endif()
  1070. if(ARG_GIT_REPOSITORY)
  1071. # We resolve the GIT_REPOSITORY here so that we get the right parent in the
  1072. # remote selection logic. In the sub-build, ExternalProject_Add() would see
  1073. # the private sub-build directory as the parent project, but the parent
  1074. # project should be the one that called FetchContent_Declare(). We resolve
  1075. # a relative repo here so that the sub-build's ExternalProject_Add() only
  1076. # ever sees a non-relative repo.
  1077. # Since these checks may be non-trivial on some platforms (notably Windows),
  1078. # don't perform them if we won't be using these details. This also allows
  1079. # projects to override calls with relative URLs when they have checked out
  1080. # the parent project in an unexpected way, such as from a mirror or fork.
  1081. set(savedDetailsPropertyName "_FetchContent_${contentNameLower}_savedDetails")
  1082. get_property(alreadyDefined GLOBAL PROPERTY ${savedDetailsPropertyName} DEFINED)
  1083. if(NOT alreadyDefined)
  1084. cmake_policy(GET CMP0150 cmp0150
  1085. PARENT_SCOPE # undocumented, do not use outside of CMake
  1086. )
  1087. _ep_resolve_git_remote(_resolved_git_repository
  1088. "${ARG_GIT_REPOSITORY}" "${cmp0150}" "${FETCHCONTENT_BASE_DIR}"
  1089. )
  1090. set(ARG_GIT_REPOSITORY "${_resolved_git_repository}")
  1091. endif()
  1092. endif()
  1093. if(ARG_SVN_REPOSITORY)
  1094. # Add a hash of the svn repository URL to the source dir. This works
  1095. # around the problem where if the URL changes, the download would
  1096. # fail because it tries to checkout/update rather than switch the
  1097. # old URL to the new one. We limit the hash to the first 7 characters
  1098. # so that the source path doesn't get overly long (which can be a
  1099. # problem on windows due to path length limits).
  1100. string(SHA1 urlSHA ${ARG_SVN_REPOSITORY})
  1101. string(SUBSTRING ${urlSHA} 0 7 urlSHA)
  1102. string(APPEND ARG_SOURCE_DIR "-${urlSHA}")
  1103. endif()
  1104. # The ExternalProject_Add() call in the sub-build won't see the CMP0135
  1105. # policy setting of our caller. Work out if that policy will be needed and
  1106. # explicitly set the relevant option if not already provided. The condition
  1107. # here is essentially an abbreviated version of the logic in
  1108. # ExternalProject's _ep_add_download_command() function.
  1109. if(NOT ARG_DOWNLOAD_NO_EXTRACT AND
  1110. NOT DEFINED ARG_DOWNLOAD_EXTRACT_TIMESTAMP)
  1111. list(FIND ARGN URL urlIndex)
  1112. if(urlIndex GREATER_EQUAL 0)
  1113. math(EXPR urlIndex "${urlIndex} + 1")
  1114. list(LENGTH ARGN numArgs)
  1115. if(urlIndex GREATER_EQUAL numArgs)
  1116. message(FATAL_ERROR
  1117. "URL keyword needs to be followed by at least one URL"
  1118. )
  1119. endif()
  1120. # If we have multiple URLs, none of them are allowed to be local paths.
  1121. # Therefore, we can test just the first URL, and if it is non-local, so
  1122. # will be the others if there are more.
  1123. list(GET ARGN ${urlIndex} firstUrl)
  1124. if(NOT IS_DIRECTORY "${firstUrl}")
  1125. cmake_policy(GET CMP0135 _FETCHCONTENT_CMP0135
  1126. PARENT_SCOPE # undocumented, do not use outside of CMake
  1127. )
  1128. if(_FETCHCONTENT_CMP0135 STREQUAL "")
  1129. message(AUTHOR_WARNING
  1130. "The DOWNLOAD_EXTRACT_TIMESTAMP option was not given and policy "
  1131. "CMP0135 is not set. The policy's OLD behavior will be used. "
  1132. "When using a URL download, the timestamps of extracted files "
  1133. "should preferably be that of the time of extraction, otherwise "
  1134. "code that depends on the extracted contents might not be "
  1135. "rebuilt if the URL changes. The OLD behavior preserves the "
  1136. "timestamps from the archive instead, but this is usually not "
  1137. "what you want. Update your project to the NEW behavior or "
  1138. "specify the DOWNLOAD_EXTRACT_TIMESTAMP option with a value of "
  1139. "true to avoid this robustness issue."
  1140. )
  1141. set(ARG_DOWNLOAD_EXTRACT_TIMESTAMP TRUE)
  1142. elseif(_FETCHCONTENT_CMP0135 STREQUAL "NEW")
  1143. set(ARG_DOWNLOAD_EXTRACT_TIMESTAMP FALSE)
  1144. else()
  1145. set(ARG_DOWNLOAD_EXTRACT_TIMESTAMP TRUE)
  1146. endif()
  1147. endif()
  1148. endif()
  1149. endif()
  1150. # Add back in the keyword args we pulled out and potentially tweaked/added
  1151. set(forward_args "${ARG_UNPARSED_ARGUMENTS}")
  1152. set(sep EXTERNALPROJECT_INTERNAL_ARGUMENT_SEPARATOR)
  1153. foreach(key IN LISTS oneValueArgs)
  1154. if(DEFINED ARG_${key})
  1155. list(PREPEND forward_args ${key} "${ARG_${key}}" ${sep})
  1156. set(sep "")
  1157. endif()
  1158. endforeach()
  1159. cmake_policy(GET CMP0168 cmp0168
  1160. PARENT_SCOPE # undocumented, do not use outside of CMake
  1161. )
  1162. if(cmp0168 STREQUAL "NEW")
  1163. list(PREPEND forward_args __DIRECT_POPULATION ${sep})
  1164. endif()
  1165. set(__argsQuoted)
  1166. foreach(__item IN LISTS forward_args)
  1167. string(APPEND __argsQuoted " [==[${__item}]==]")
  1168. endforeach()
  1169. cmake_language(EVAL CODE
  1170. "__FetchContent_declareDetails(${contentNameLower} ${__argsQuoted})"
  1171. )
  1172. endfunction()
  1173. #=======================================================================
  1174. # Set/get whether the specified content has been populated yet.
  1175. # The setter also records the source and binary dirs used.
  1176. #=======================================================================
  1177. # Semi-internal use. Projects must not call this directly. Dependency
  1178. # providers must call it if they satisfy a request made with the
  1179. # FETCHCONTENT_MAKEAVAILABLE_SERIAL method (that is the only permitted
  1180. # place to call it outside of the FetchContent module).
  1181. function(FetchContent_SetPopulated contentName)
  1182. cmake_parse_arguments(PARSE_ARGV 1 arg
  1183. ""
  1184. "SOURCE_DIR;BINARY_DIR"
  1185. ""
  1186. )
  1187. if(NOT "${arg_UNPARSED_ARGUMENTS}" STREQUAL "")
  1188. message(FATAL_ERROR "Unsupported arguments: ${arg_UNPARSED_ARGUMENTS}")
  1189. endif()
  1190. string(TOLOWER ${contentName} contentNameLower)
  1191. set(prefix "_FetchContent_${contentNameLower}")
  1192. set(propertyName "${prefix}_sourceDir")
  1193. define_property(GLOBAL PROPERTY ${propertyName})
  1194. if("${arg_SOURCE_DIR}" STREQUAL "")
  1195. # Don't discard a previously provided SOURCE_DIR
  1196. get_property(arg_SOURCE_DIR GLOBAL PROPERTY ${propertyName})
  1197. endif()
  1198. set_property(GLOBAL PROPERTY ${propertyName} "${arg_SOURCE_DIR}")
  1199. set(propertyName "${prefix}_binaryDir")
  1200. define_property(GLOBAL PROPERTY ${propertyName})
  1201. if("${arg_BINARY_DIR}" STREQUAL "")
  1202. # Don't discard a previously provided BINARY_DIR
  1203. get_property(arg_BINARY_DIR GLOBAL PROPERTY ${propertyName})
  1204. endif()
  1205. set_property(GLOBAL PROPERTY ${propertyName} "${arg_BINARY_DIR}")
  1206. set(propertyName "${prefix}_populated")
  1207. define_property(GLOBAL PROPERTY ${propertyName})
  1208. set_property(GLOBAL PROPERTY ${propertyName} TRUE)
  1209. endfunction()
  1210. # Set variables in the calling scope for any of the retrievable
  1211. # properties. If no specific properties are requested, variables
  1212. # will be set for all retrievable properties.
  1213. #
  1214. # This function is intended to also be used by projects as the canonical
  1215. # way to detect whether they should call FetchContent_Populate()
  1216. # and pull the populated source into the build with add_subdirectory(),
  1217. # if they are using the populated content in that way.
  1218. function(FetchContent_GetProperties contentName)
  1219. string(TOLOWER ${contentName} contentNameLower)
  1220. set(options "")
  1221. set(oneValueArgs SOURCE_DIR BINARY_DIR POPULATED)
  1222. set(multiValueArgs "")
  1223. cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
  1224. if(NOT ARG_SOURCE_DIR AND
  1225. NOT ARG_BINARY_DIR AND
  1226. NOT ARG_POPULATED)
  1227. # No specific properties requested, provide them all
  1228. set(ARG_SOURCE_DIR ${contentNameLower}_SOURCE_DIR)
  1229. set(ARG_BINARY_DIR ${contentNameLower}_BINARY_DIR)
  1230. set(ARG_POPULATED ${contentNameLower}_POPULATED)
  1231. endif()
  1232. set(prefix "_FetchContent_${contentNameLower}")
  1233. if(ARG_SOURCE_DIR)
  1234. set(propertyName "${prefix}_sourceDir")
  1235. get_property(value GLOBAL PROPERTY ${propertyName})
  1236. if(value)
  1237. set(${ARG_SOURCE_DIR} ${value} PARENT_SCOPE)
  1238. endif()
  1239. endif()
  1240. if(ARG_BINARY_DIR)
  1241. set(propertyName "${prefix}_binaryDir")
  1242. get_property(value GLOBAL PROPERTY ${propertyName})
  1243. if(value)
  1244. set(${ARG_BINARY_DIR} ${value} PARENT_SCOPE)
  1245. endif()
  1246. endif()
  1247. if(ARG_POPULATED)
  1248. set(propertyName "${prefix}_populated")
  1249. get_property(value GLOBAL PROPERTY ${propertyName} DEFINED)
  1250. set(${ARG_POPULATED} ${value} PARENT_SCOPE)
  1251. endif()
  1252. endfunction()
  1253. #=======================================================================
  1254. # Performing the population
  1255. #=======================================================================
  1256. # The value of contentName will always have been lowercased by the caller.
  1257. # All other arguments are assumed to be options that are understood by
  1258. # ExternalProject_Add(), except for QUIET and SUBBUILD_DIR.
  1259. function(__FetchContent_doPopulation contentName)
  1260. set(options
  1261. QUIET
  1262. # EXCLUDE_FROM_ALL and SYSTEM have no meaning for ExternalProject, they
  1263. # are only used by us in FetchContent_MakeAvailable(). We need to parse
  1264. # and discard them here.
  1265. EXCLUDE_FROM_ALL
  1266. SYSTEM
  1267. )
  1268. set(oneValueArgs
  1269. SUBBUILD_DIR
  1270. SOURCE_DIR
  1271. BINARY_DIR
  1272. # We need special processing if DOWNLOAD_NO_EXTRACT is true
  1273. DOWNLOAD_NO_EXTRACT
  1274. # Prevent the following from being passed through
  1275. CONFIGURE_COMMAND
  1276. BUILD_COMMAND
  1277. INSTALL_COMMAND
  1278. TEST_COMMAND
  1279. # We force these to be ON since we are always executing serially
  1280. # and we want all steps to have access to the terminal in case they
  1281. # need input from the command line (e.g. ask for a private key password)
  1282. # or they want to provide timely progress. We silently absorb and
  1283. # discard these if they are set by the caller.
  1284. USES_TERMINAL_DOWNLOAD
  1285. USES_TERMINAL_UPDATE
  1286. USES_TERMINAL_PATCH
  1287. # Internal options, may change at any time
  1288. __DIRECT_POPULATION
  1289. )
  1290. set(multiValueArgs "")
  1291. cmake_parse_arguments(PARSE_ARGV 1 ARG
  1292. "${options}" "${oneValueArgs}" "${multiValueArgs}")
  1293. if(DEFINED ARG___DIRECT_POPULATION)
  1294. # Direct call to FetchContent_Populate() with full details. The policy
  1295. # setting of its caller is included in the function arguments.
  1296. set(direct_population ${ARG___DIRECT_POPULATION})
  1297. else()
  1298. # FetchContent_Populate() called with only the name of a dependency.
  1299. # We need the policy setting of the corresponding FetchContent_Declare().
  1300. get_property(direct_population GLOBAL PROPERTY
  1301. "_FetchContent_${contentNameLower}_direct_population"
  1302. )
  1303. endif()
  1304. if(NOT ARG_SUBBUILD_DIR)
  1305. if(NOT direct_population)
  1306. message(FATAL_ERROR "Internal error: SUBBUILD_DIR not set")
  1307. endif()
  1308. elseif(NOT IS_ABSOLUTE "${ARG_SUBBUILD_DIR}")
  1309. set(ARG_SUBBUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/${ARG_SUBBUILD_DIR}")
  1310. endif()
  1311. if(NOT ARG_SOURCE_DIR)
  1312. message(FATAL_ERROR "Internal error: SOURCE_DIR not set")
  1313. elseif(NOT IS_ABSOLUTE "${ARG_SOURCE_DIR}")
  1314. set(ARG_SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/${ARG_SOURCE_DIR}")
  1315. endif()
  1316. if(NOT ARG_BINARY_DIR)
  1317. message(FATAL_ERROR "Internal error: BINARY_DIR not set")
  1318. elseif(NOT IS_ABSOLUTE "${ARG_BINARY_DIR}")
  1319. set(ARG_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/${ARG_BINARY_DIR}")
  1320. endif()
  1321. # Ensure the caller can know where to find the source and build directories
  1322. # with some convenient variables. Doing this here ensures the caller sees
  1323. # the correct result in the case where the default values are overridden by
  1324. # the content details set by the project.
  1325. set(${contentName}_SOURCE_DIR "${ARG_SOURCE_DIR}" PARENT_SCOPE)
  1326. set(${contentName}_BINARY_DIR "${ARG_BINARY_DIR}" PARENT_SCOPE)
  1327. if(direct_population)
  1328. __FetchContent_populateDirect()
  1329. else()
  1330. __FetchContent_populateSubbuild()
  1331. endif()
  1332. endfunction()
  1333. function(__FetchContent_populateDirect)
  1334. # Policies CMP0097, CMP0135 and CMP0150 are handled in FetchContent_Declare()
  1335. # and the stored arguments already account for them.
  1336. # For CMP0097, the arguments will always assume NEW behavior by the time
  1337. # we get to here, so ensure ExternalProject sees that.
  1338. set(_EP_CMP0097 NEW)
  1339. set(args_to_parse
  1340. "${ARG_UNPARSED_ARGUMENTS}"
  1341. SOURCE_DIR "${ARG_SOURCE_DIR}"
  1342. BINARY_DIR "${ARG_BINARY_DIR}"
  1343. )
  1344. if(ARG_DOWNLOAD_NO_EXTRACT)
  1345. list(APPEND args_to_parse DOWNLOAD_NO_EXTRACT YES)
  1346. endif()
  1347. get_property(cmake_role GLOBAL PROPERTY CMAKE_ROLE)
  1348. if(cmake_role STREQUAL "PROJECT")
  1349. # We don't support direct population where a project makes a direct call
  1350. # to FetchContent_Populate(). That always goes through ExternalProject and
  1351. # will soon be deprecated anyway.
  1352. set(function_for_args FetchContent_Declare)
  1353. elseif(cmake_role STREQUAL "SCRIPT")
  1354. set(function_for_args FetchContent_Populate)
  1355. else()
  1356. message(FATAL_ERROR "Unsupported context for direct population")
  1357. endif()
  1358. _ep_get_add_keywords(keywords)
  1359. _ep_parse_arguments_to_vars(
  1360. ${function_for_args}
  1361. "${keywords}"
  1362. ${contentName}
  1363. _EP_
  1364. "${args_to_parse}"
  1365. )
  1366. # We use a simplified set of directories here. We do not need the full set
  1367. # of directories that ExternalProject supports, and we don't need the
  1368. # extensive customization options it supports either. Note that
  1369. # _EP_SOURCE_DIR and _EP_BINARY_DIR are always included in the saved args,
  1370. # so we must not set them here.
  1371. set(_EP_STAMP_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-stamp")
  1372. set(_EP_TMP_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-tmp")
  1373. set(_EP_DOWNLOAD_DIR "${_EP_TMP_DIR}")
  1374. file(MAKE_DIRECTORY
  1375. "${_EP_SOURCE_DIR}"
  1376. "${_EP_BINARY_DIR}"
  1377. "${_EP_STAMP_DIR}"
  1378. "${_EP_TMP_DIR}"
  1379. )
  1380. # We take over the stamp files and use our own for detecting whether each
  1381. # step is up-to-date. The method used by ExternalProject is specific to
  1382. # using a sub-build and is not appropriate for us here.
  1383. set(download_script ${_EP_TMP_DIR}/download.cmake)
  1384. set(update_script ${_EP_TMP_DIR}/upload.cmake)
  1385. set(patch_script ${_EP_TMP_DIR}/patch.cmake)
  1386. _ep_add_download_command(${contentName}
  1387. SCRIPT_FILE ${download_script}
  1388. DEPENDS_VARIABLE download_depends
  1389. )
  1390. _ep_add_update_command(${contentName}
  1391. SCRIPT_FILE ${update_script}
  1392. DEPENDS_VARIABLE update_depends
  1393. )
  1394. _ep_add_patch_command(${contentName}
  1395. SCRIPT_FILE ${patch_script}
  1396. # No additional dependencies for the patch step
  1397. )
  1398. set(download_stamp ${_EP_STAMP_DIR}/download.stamp)
  1399. set(update_stamp ${_EP_STAMP_DIR}/upload.stamp)
  1400. set(patch_stamp ${_EP_STAMP_DIR}/patch.stamp)
  1401. __FetchContent_doStepDirect(
  1402. SCRIPT_FILE ${download_script}
  1403. STAMP_FILE ${download_stamp}
  1404. DEPENDS ${download_depends}
  1405. )
  1406. __FetchContent_doStepDirect(
  1407. SCRIPT_FILE ${update_script}
  1408. STAMP_FILE ${update_stamp}
  1409. DEPENDS ${update_depends} ${download_stamp}
  1410. )
  1411. __FetchContent_doStepDirect(
  1412. SCRIPT_FILE ${patch_script}
  1413. STAMP_FILE ${patch_stamp}
  1414. DEPENDS ${update_stamp}
  1415. )
  1416. endfunction()
  1417. function(__FetchContent_doStepDirect)
  1418. set(noValueOptions )
  1419. set(singleValueOptions
  1420. SCRIPT_FILE
  1421. STAMP_FILE
  1422. )
  1423. set(multiValueOptions
  1424. DEPENDS
  1425. )
  1426. cmake_parse_arguments(PARSE_ARGV 0 arg
  1427. "${noValueOptions}" "${singleValueOptions}" "${multiValueOptions}"
  1428. )
  1429. if(NOT EXISTS ${arg_STAMP_FILE})
  1430. set(do_step YES)
  1431. else()
  1432. set(do_step NO)
  1433. foreach(dep_file IN LISTS arg_DEPENDS arg_SCRIPT_FILE)
  1434. if(NOT EXISTS "${arg_STAMP_FILE}" OR
  1435. NOT EXISTS "${dep_file}" OR
  1436. NOT "${arg_STAMP_FILE}" IS_NEWER_THAN "${dep_file}")
  1437. set(do_step YES)
  1438. break()
  1439. endif()
  1440. endforeach()
  1441. endif()
  1442. if(do_step)
  1443. include(${arg_SCRIPT_FILE})
  1444. file(TOUCH "${arg_STAMP_FILE}")
  1445. endif()
  1446. endfunction()
  1447. function(__FetchContent_populateSubbuild)
  1448. # All argument parsing is done in __FetchContent_doPopulate(), since it is
  1449. # common to both the subbuild and direct population strategies.
  1450. # Parsed arguments are in ARG_... variables.
  1451. # The unparsed arguments may contain spaces, so build up ARG_EXTRA
  1452. # in such a way that it correctly substitutes into the generated
  1453. # CMakeLists.txt file with each argument quoted.
  1454. unset(ARG_EXTRA)
  1455. foreach(arg IN LISTS ARG_UNPARSED_ARGUMENTS)
  1456. set(ARG_EXTRA "${ARG_EXTRA} \"${arg}\"")
  1457. endforeach()
  1458. if(ARG_DOWNLOAD_NO_EXTRACT)
  1459. set(ARG_EXTRA "${ARG_EXTRA} DOWNLOAD_NO_EXTRACT YES")
  1460. set(__FETCHCONTENT_COPY_FILE
  1461. "
  1462. ExternalProject_Get_Property(${contentName}-populate DOWNLOADED_FILE)
  1463. get_filename_component(dlFileName \"\${DOWNLOADED_FILE}\" NAME)
  1464. ExternalProject_Add_Step(${contentName}-populate copyfile
  1465. COMMAND \"${CMAKE_COMMAND}\" -E copy_if_different
  1466. \"<DOWNLOADED_FILE>\" \"${ARG_SOURCE_DIR}\"
  1467. DEPENDEES patch
  1468. DEPENDERS configure
  1469. BYPRODUCTS \"${ARG_SOURCE_DIR}/\${dlFileName}\"
  1470. COMMENT \"Copying file to SOURCE_DIR\"
  1471. )
  1472. ")
  1473. else()
  1474. unset(__FETCHCONTENT_COPY_FILE)
  1475. endif()
  1476. # Hide output if requested, but save it to a variable in case there's an
  1477. # error so we can show the output upon failure. When not quiet, don't
  1478. # capture the output to a variable because the user may want to see the
  1479. # output as it happens (e.g. progress during long downloads). Combine both
  1480. # stdout and stderr in the one capture variable so the output stays in order.
  1481. if (ARG_QUIET)
  1482. set(outputOptions
  1483. OUTPUT_VARIABLE capturedOutput
  1484. ERROR_VARIABLE capturedOutput
  1485. )
  1486. else()
  1487. set(capturedOutput)
  1488. set(outputOptions)
  1489. message(STATUS "Populating ${contentName}")
  1490. endif()
  1491. if(CMAKE_GENERATOR)
  1492. set(subCMakeOpts "-G${CMAKE_GENERATOR}")
  1493. if(CMAKE_GENERATOR_PLATFORM)
  1494. list(APPEND subCMakeOpts "-A${CMAKE_GENERATOR_PLATFORM}")
  1495. endif()
  1496. if(CMAKE_GENERATOR_TOOLSET)
  1497. list(APPEND subCMakeOpts "-T${CMAKE_GENERATOR_TOOLSET}")
  1498. endif()
  1499. if(CMAKE_GENERATOR_INSTANCE)
  1500. list(APPEND subCMakeOpts "-DCMAKE_GENERATOR_INSTANCE:INTERNAL=${CMAKE_GENERATOR_INSTANCE}")
  1501. endif()
  1502. if(CMAKE_MAKE_PROGRAM)
  1503. list(APPEND subCMakeOpts "-DCMAKE_MAKE_PROGRAM:FILEPATH=${CMAKE_MAKE_PROGRAM}")
  1504. endif()
  1505. # GreenHills needs to know about the compiler and toolset to run the
  1506. # subbuild commands. Be sure to update the similar section in
  1507. # ExternalProject.cmake:_ep_extract_configure_command()
  1508. if(CMAKE_GENERATOR MATCHES "Green Hills MULTI")
  1509. list(APPEND subCMakeOpts
  1510. "-DGHS_TARGET_PLATFORM:STRING=${GHS_TARGET_PLATFORM}"
  1511. "-DGHS_PRIMARY_TARGET:STRING=${GHS_PRIMARY_TARGET}"
  1512. "-DGHS_TOOLSET_ROOT:STRING=${GHS_TOOLSET_ROOT}"
  1513. "-DGHS_OS_ROOT:STRING=${GHS_OS_ROOT}"
  1514. "-DGHS_OS_DIR:STRING=${GHS_OS_DIR}"
  1515. "-DGHS_BSP_NAME:STRING=${GHS_BSP_NAME}"
  1516. )
  1517. endif()
  1518. # Override the sub-build's configuration types for multi-config generators.
  1519. # This ensures we are not affected by any custom setting from the project
  1520. # and can always request a known configuration further below.
  1521. get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
  1522. if(is_multi_config)
  1523. list(APPEND subCMakeOpts "-DCMAKE_CONFIGURATION_TYPES:STRING=Debug")
  1524. endif()
  1525. else()
  1526. # Likely we've been invoked via CMake's script mode where no
  1527. # generator is set (and hence CMAKE_MAKE_PROGRAM could not be
  1528. # trusted even if provided). We will have to rely on being
  1529. # able to find the default generator and build tool.
  1530. unset(subCMakeOpts)
  1531. endif()
  1532. set(__FETCHCONTENT_CACHED_INFO "")
  1533. set(__passthrough_vars
  1534. CMAKE_EP_GIT_REMOTE_UPDATE_STRATEGY
  1535. CMAKE_TLS_VERSION
  1536. CMAKE_TLS_VERIFY
  1537. CMAKE_TLS_CAINFO
  1538. CMAKE_NETRC
  1539. CMAKE_NETRC_FILE
  1540. )
  1541. foreach(var IN LISTS __passthrough_vars)
  1542. if(DEFINED ${var})
  1543. # Embed directly in the generated CMakeLists.txt file to avoid making
  1544. # the cmake command line excessively long. It also makes debugging and
  1545. # testing easier.
  1546. string(APPEND __FETCHCONTENT_CACHED_INFO "set(${var} [==[${${var}}]==])\n")
  1547. endif()
  1548. endforeach()
  1549. # Avoid using if(... IN_LIST ...) so we don't have to alter policy settings
  1550. list(FIND ARG_UNPARSED_ARGUMENTS GIT_REPOSITORY indexResult)
  1551. if(indexResult GREATER_EQUAL 0)
  1552. find_package(Git QUIET)
  1553. string(APPEND __FETCHCONTENT_CACHED_INFO "
  1554. # Pass through things we've already detected in the main project to avoid
  1555. # paying the cost of redetecting them again in ExternalProject_Add()
  1556. set(GIT_EXECUTABLE [==[${GIT_EXECUTABLE}]==])
  1557. set(GIT_VERSION_STRING [==[${GIT_VERSION_STRING}]==])
  1558. set_property(GLOBAL PROPERTY _CMAKE_FindGit_GIT_EXECUTABLE_VERSION
  1559. [==[${GIT_EXECUTABLE};${GIT_VERSION_STRING}]==]
  1560. )
  1561. ")
  1562. endif()
  1563. # Create and build a separate CMake project to carry out the population.
  1564. # If we've already previously done these steps, they will not cause
  1565. # anything to be updated, so extra rebuilds of the project won't occur.
  1566. # Make sure to pass through CMAKE_MAKE_PROGRAM in case the main project
  1567. # has this set to something not findable on the PATH. We also ensured above
  1568. # that the Debug config will be defined for multi-config generators.
  1569. configure_file("${CMAKE_CURRENT_FUNCTION_LIST_DIR}/FetchContent/CMakeLists.cmake.in"
  1570. "${ARG_SUBBUILD_DIR}/CMakeLists.txt"
  1571. @ONLY
  1572. )
  1573. execute_process(
  1574. COMMAND ${CMAKE_COMMAND} ${subCMakeOpts} .
  1575. RESULT_VARIABLE result
  1576. ${outputOptions}
  1577. WORKING_DIRECTORY "${ARG_SUBBUILD_DIR}"
  1578. )
  1579. if(result)
  1580. if(capturedOutput)
  1581. message("${capturedOutput}")
  1582. endif()
  1583. message(FATAL_ERROR "CMake step for ${contentName} failed: ${result}")
  1584. endif()
  1585. execute_process(
  1586. COMMAND ${CMAKE_COMMAND} --build . --config Debug
  1587. RESULT_VARIABLE result
  1588. ${outputOptions}
  1589. WORKING_DIRECTORY "${ARG_SUBBUILD_DIR}"
  1590. )
  1591. if(result)
  1592. if(capturedOutput)
  1593. message("${capturedOutput}")
  1594. endif()
  1595. message(FATAL_ERROR "Build step for ${contentName} failed: ${result}")
  1596. endif()
  1597. endfunction()
  1598. option(FETCHCONTENT_FULLY_DISCONNECTED "Disables all attempts to download or update content and assumes source dirs already exist")
  1599. option(FETCHCONTENT_UPDATES_DISCONNECTED "Enables UPDATE_DISCONNECTED behavior for all content population")
  1600. option(FETCHCONTENT_QUIET "Enables QUIET option for all content population" ON)
  1601. set(FETCHCONTENT_BASE_DIR "${CMAKE_BINARY_DIR}/_deps" CACHE PATH "Directory under which to collect all populated content")
  1602. # Populate the specified content using details stored from
  1603. # an earlier call to FetchContent_Declare().
  1604. function(FetchContent_Populate contentName)
  1605. if(NOT contentName)
  1606. message(FATAL_ERROR "Empty contentName not allowed for FetchContent_Populate()")
  1607. endif()
  1608. if(ARGC EQUAL 1)
  1609. cmake_policy(GET CMP0169 cmp0169
  1610. PARENT_SCOPE # undocumented, do not use outside of CMake
  1611. )
  1612. if(NOT cmp0169 STREQUAL "OLD")
  1613. string(CONCAT msg
  1614. "Calling FetchContent_Populate(${contentName}) is deprecated, call "
  1615. "FetchContent_MakeAvailable(${contentName}) instead. "
  1616. "Policy CMP0169 can be set to OLD to allow "
  1617. "FetchContent_Populate(${contentName}) to be called directly for now, "
  1618. "but the ability to call it with declared details will be removed "
  1619. "completely in a future version."
  1620. )
  1621. if(cmp0169 STREQUAL "NEW")
  1622. message(FATAL_ERROR "${msg}")
  1623. else()
  1624. message(AUTHOR_WARNING "${msg}")
  1625. endif()
  1626. endif()
  1627. set(__doDirectArgs)
  1628. else()
  1629. cmake_policy(GET CMP0168 cmp0168
  1630. PARENT_SCOPE # undocumented, do not use outside of CMake
  1631. )
  1632. if(cmp0168 STREQUAL "NEW")
  1633. set(__doDirectArgs __DIRECT_POPULATION YES)
  1634. else()
  1635. set(__doDirectArgs __DIRECT_POPULATION NO)
  1636. endif()
  1637. endif()
  1638. cmake_parse_arguments(PARSE_ARGV 0 __arg "" "" "")
  1639. set(__argsQuoted)
  1640. foreach(__item IN LISTS __arg_UNPARSED_ARGUMENTS __doDirectArgs)
  1641. string(APPEND __argsQuoted " [==[${__item}]==]")
  1642. endforeach()
  1643. cmake_language(EVAL CODE "__FetchContent_Populate(${__argsQuoted})")
  1644. string(TOLOWER ${contentName} contentNameLower)
  1645. foreach(var IN ITEMS SOURCE_DIR BINARY_DIR POPULATED)
  1646. set(var "${contentNameLower}_${var}")
  1647. if(DEFINED ${var})
  1648. set(${var} "${${var}}" PARENT_SCOPE)
  1649. endif()
  1650. endforeach()
  1651. endfunction()
  1652. function(__FetchContent_Populate contentName)
  1653. string(TOLOWER ${contentName} contentNameLower)
  1654. if(ARGN)
  1655. # This is the direct population form with details fully specified
  1656. # as part of the call, so we already have everything we need
  1657. __FetchContent_doPopulation(
  1658. ${contentNameLower}
  1659. SUBBUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/${contentNameLower}-subbuild"
  1660. SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/${contentNameLower}-src"
  1661. BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/${contentNameLower}-build"
  1662. ${ARGN} # Could override any of the above ..._DIR variables
  1663. )
  1664. # Pass source and binary dir variables back to the caller
  1665. set(${contentNameLower}_SOURCE_DIR "${${contentNameLower}_SOURCE_DIR}" PARENT_SCOPE)
  1666. set(${contentNameLower}_BINARY_DIR "${${contentNameLower}_BINARY_DIR}" PARENT_SCOPE)
  1667. # Don't set global properties, or record that we did this population, since
  1668. # this was a direct call outside of the normal declared details form.
  1669. # We only want to save values in the global properties for content that
  1670. # honors the hierarchical details mechanism so that projects are not
  1671. # robbed of the ability to override details set in nested projects.
  1672. return()
  1673. endif()
  1674. # No details provided, so assume they were saved from an earlier call
  1675. # to FetchContent_Declare(). Do a check that we haven't already
  1676. # populated this content before in case the caller forgot to check.
  1677. FetchContent_GetProperties(${contentName})
  1678. if(${contentNameLower}_POPULATED)
  1679. if("${${contentNameLower}_SOURCE_DIR}" STREQUAL "")
  1680. message(FATAL_ERROR
  1681. "Content ${contentName} already populated by find_package() or a "
  1682. "dependency provider"
  1683. )
  1684. else()
  1685. message(FATAL_ERROR
  1686. "Content ${contentName} already populated in ${${contentNameLower}_SOURCE_DIR}"
  1687. )
  1688. endif()
  1689. endif()
  1690. __FetchContent_getSavedDetails(${contentName} contentDetails)
  1691. if("${contentDetails}" STREQUAL "")
  1692. message(FATAL_ERROR "No details have been set for content: ${contentName}")
  1693. endif()
  1694. string(TOUPPER ${contentName} contentNameUpper)
  1695. set(FETCHCONTENT_SOURCE_DIR_${contentNameUpper}
  1696. "${FETCHCONTENT_SOURCE_DIR_${contentNameUpper}}"
  1697. CACHE PATH "When not empty, overrides where to find pre-populated content for ${contentName}")
  1698. if(FETCHCONTENT_SOURCE_DIR_${contentNameUpper})
  1699. # The source directory has been explicitly provided in the cache,
  1700. # so no population is required. The build directory may still be specified
  1701. # by the declared details though.
  1702. if(NOT IS_ABSOLUTE "${FETCHCONTENT_SOURCE_DIR_${contentNameUpper}}")
  1703. # Don't check this directory because we don't know what location it is
  1704. # expected to be relative to. We can't make this a hard error for backward
  1705. # compatibility reasons.
  1706. message(WARNING "Relative source directory specified. This is not safe, "
  1707. "as it depends on the calling directory scope.\n"
  1708. " FETCHCONTENT_SOURCE_DIR_${contentNameUpper} --> ${FETCHCONTENT_SOURCE_DIR_${contentNameUpper}}")
  1709. elseif(NOT EXISTS "${FETCHCONTENT_SOURCE_DIR_${contentNameUpper}}")
  1710. message(FATAL_ERROR "Manually specified source directory is missing:\n"
  1711. " FETCHCONTENT_SOURCE_DIR_${contentNameUpper} --> ${FETCHCONTENT_SOURCE_DIR_${contentNameUpper}}")
  1712. endif()
  1713. set(${contentNameLower}_SOURCE_DIR "${FETCHCONTENT_SOURCE_DIR_${contentNameUpper}}")
  1714. cmake_parse_arguments(savedDetails "" "BINARY_DIR" "" ${contentDetails})
  1715. if(savedDetails_BINARY_DIR)
  1716. set(${contentNameLower}_BINARY_DIR ${savedDetails_BINARY_DIR})
  1717. else()
  1718. set(${contentNameLower}_BINARY_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-build")
  1719. endif()
  1720. elseif(FETCHCONTENT_FULLY_DISCONNECTED)
  1721. # Bypass population and assume source is already there from a previous run.
  1722. # Declared details may override the default source or build directories.
  1723. cmake_parse_arguments(savedDetails "" "SOURCE_DIR;BINARY_DIR" "" ${contentDetails})
  1724. if(savedDetails_SOURCE_DIR)
  1725. set(${contentNameLower}_SOURCE_DIR ${savedDetails_SOURCE_DIR})
  1726. else()
  1727. set(${contentNameLower}_SOURCE_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-src")
  1728. endif()
  1729. if(savedDetails_BINARY_DIR)
  1730. set(${contentNameLower}_BINARY_DIR ${savedDetails_BINARY_DIR})
  1731. else()
  1732. set(${contentNameLower}_BINARY_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-build")
  1733. endif()
  1734. else()
  1735. # Support both a global "disconnect all updates" and a per-content
  1736. # update test (either one being set disables updates for this content).
  1737. option(FETCHCONTENT_UPDATES_DISCONNECTED_${contentNameUpper}
  1738. "Enables UPDATE_DISCONNECTED behavior just for population of ${contentName}")
  1739. if(FETCHCONTENT_UPDATES_DISCONNECTED OR
  1740. FETCHCONTENT_UPDATES_DISCONNECTED_${contentNameUpper})
  1741. set(disconnectUpdates True)
  1742. else()
  1743. set(disconnectUpdates False)
  1744. endif()
  1745. if(FETCHCONTENT_QUIET)
  1746. set(quietFlag QUIET)
  1747. else()
  1748. unset(quietFlag)
  1749. endif()
  1750. set(__detailsQuoted)
  1751. foreach(__item IN LISTS contentDetails)
  1752. if(NOT __item STREQUAL "OVERRIDE_FIND_PACKAGE")
  1753. string(APPEND __detailsQuoted " [==[${__item}]==]")
  1754. endif()
  1755. endforeach()
  1756. cmake_language(EVAL CODE "
  1757. __FetchContent_doPopulation(
  1758. ${contentNameLower}
  1759. ${quietFlag}
  1760. UPDATE_DISCONNECTED ${disconnectUpdates}
  1761. SUBBUILD_DIR \"${FETCHCONTENT_BASE_DIR}/${contentNameLower}-subbuild\"
  1762. SOURCE_DIR \"${FETCHCONTENT_BASE_DIR}/${contentNameLower}-src\"
  1763. BINARY_DIR \"${FETCHCONTENT_BASE_DIR}/${contentNameLower}-build\"
  1764. # Put the saved details last so they can override any of the
  1765. # the options we set above (this can include SOURCE_DIR or
  1766. # BUILD_DIR)
  1767. ${__detailsQuoted}
  1768. )"
  1769. )
  1770. endif()
  1771. FetchContent_SetPopulated(
  1772. ${contentName}
  1773. SOURCE_DIR "${${contentNameLower}_SOURCE_DIR}"
  1774. BINARY_DIR "${${contentNameLower}_BINARY_DIR}"
  1775. )
  1776. # Pass variables back to the caller. The variables passed back here
  1777. # must match what FetchContent_GetProperties() sets when it is called
  1778. # with just the content name.
  1779. set(${contentNameLower}_SOURCE_DIR "${${contentNameLower}_SOURCE_DIR}" PARENT_SCOPE)
  1780. set(${contentNameLower}_BINARY_DIR "${${contentNameLower}_BINARY_DIR}" PARENT_SCOPE)
  1781. set(${contentNameLower}_POPULATED True PARENT_SCOPE)
  1782. endfunction()
  1783. function(__FetchContent_setupFindPackageRedirection contentName)
  1784. __FetchContent_getSavedDetails(${contentName} contentDetails)
  1785. string(TOLOWER ${contentName} contentNameLower)
  1786. get_property(wantFindPackage GLOBAL PROPERTY
  1787. _FetchContent_${contentNameLower}_find_package_args
  1788. DEFINED
  1789. )
  1790. # Avoid using if(... IN_LIST ...) so we don't have to alter policy settings
  1791. list(FIND contentDetails OVERRIDE_FIND_PACKAGE indexResult)
  1792. if(NOT wantFindPackage AND indexResult EQUAL -1)
  1793. # No find_package() redirection allowed
  1794. return()
  1795. endif()
  1796. # We write out dep-config.cmake and dep-config-version.cmake file name
  1797. # forms here because they are forced to lowercase. FetchContent
  1798. # dependency names are case-insensitive, but find_package() config files
  1799. # are only case-insensitive for the -config and -config-version forms,
  1800. # not the Config and ConfigVersion forms.
  1801. set(inFileDir ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/FetchContent)
  1802. set(configFilePrefix1 "${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/${contentName}Config")
  1803. set(configFilePrefix2 "${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/${contentNameLower}-config")
  1804. if(NOT EXISTS "${configFilePrefix1}.cmake" AND
  1805. NOT EXISTS "${configFilePrefix2}.cmake")
  1806. configure_file(${inFileDir}/package-config.cmake.in
  1807. "${configFilePrefix2}.cmake" @ONLY
  1808. )
  1809. endif()
  1810. if(NOT EXISTS "${configFilePrefix1}Version.cmake" AND
  1811. NOT EXISTS "${configFilePrefix2}-version.cmake")
  1812. configure_file(${inFileDir}/package-config-version.cmake.in
  1813. "${configFilePrefix2}-version.cmake" @ONLY
  1814. )
  1815. endif()
  1816. # Now that we've created the redirected package config files, prevent
  1817. # find_package() from delegating to FetchContent and let it find these
  1818. # config files through its normal processing.
  1819. set(propertyName "${prefix}_override_find_package")
  1820. set(GLOBAL PROPERTY ${propertyName} FALSE)
  1821. set(${contentName}_DIR "${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}"
  1822. CACHE INTERNAL "Redirected by FetchContent"
  1823. )
  1824. endfunction()
  1825. # Arguments are assumed to be the names of dependencies that have been
  1826. # declared previously and should be populated. It is not an error if
  1827. # any of them have already been populated (they will just be skipped in
  1828. # that case). The command is implemented as a macro so that the variables
  1829. # defined by the FetchContent_GetProperties() and FetchContent_Populate()
  1830. # calls will be available to the caller.
  1831. macro(FetchContent_MakeAvailable)
  1832. # We must append an item, even if the variable is unset, so prefix its value.
  1833. # We will strip that prefix when we pop the value at the end of the macro.
  1834. list(APPEND __cmake_fcCurrentVarsStack
  1835. "__fcprefix__${CMAKE_VERIFY_INTERFACE_HEADER_SETS}"
  1836. )
  1837. set(CMAKE_VERIFY_INTERFACE_HEADER_SETS FALSE)
  1838. get_property(__cmake_providerCommand GLOBAL PROPERTY
  1839. __FETCHCONTENT_MAKEAVAILABLE_SERIAL_PROVIDER
  1840. )
  1841. foreach(__cmake_contentName IN ITEMS ${ARGV})
  1842. string(TOLOWER ${__cmake_contentName} __cmake_contentNameLower)
  1843. # If user specified FETCHCONTENT_SOURCE_DIR_... for this dependency, that
  1844. # overrides everything else and we shouldn't try to use find_package() or
  1845. # a dependency provider.
  1846. string(TOUPPER ${__cmake_contentName} __cmake_contentNameUpper)
  1847. if("${FETCHCONTENT_SOURCE_DIR_${__cmake_contentNameUpper}}" STREQUAL "")
  1848. # Dependency provider gets first opportunity, but prevent infinite
  1849. # recursion if we are called again for the same thing
  1850. if(NOT "${__cmake_providerCommand}" STREQUAL "" AND
  1851. NOT DEFINED __cmake_fcProvider_${__cmake_contentNameLower})
  1852. message(VERBOSE
  1853. "Trying FETCHCONTENT_MAKEAVAILABLE_SERIAL dependency provider for "
  1854. "${__cmake_contentName}"
  1855. )
  1856. if(DEFINED CMAKE_EXPORT_FIND_PACKAGE_NAME)
  1857. list(APPEND __cmake_fcCurrentVarsStack "${CMAKE_EXPORT_FIND_PACKAGE_NAME}")
  1858. else()
  1859. # This just needs to be something that can't be a real package name
  1860. list(APPEND __cmake_fcCurrentVarsStack "<<::VAR_NOT_SET::>>")
  1861. endif()
  1862. set(CMAKE_EXPORT_FIND_PACKAGE_NAME "${__cmake_contentName}")
  1863. # It's still valid if there are no saved details. The project may have
  1864. # been written to assume a dependency provider is always set and will
  1865. # provide dependencies without having any declared details for them.
  1866. __FetchContent_getSavedDetails(${__cmake_contentName} __cmake_contentDetails)
  1867. set(__cmake_providerArgs
  1868. "FETCHCONTENT_MAKEAVAILABLE_SERIAL"
  1869. "${__cmake_contentName}"
  1870. )
  1871. # Empty arguments must be preserved because of things like
  1872. # GIT_SUBMODULES (see CMP0097)
  1873. foreach(__cmake_item IN LISTS __cmake_contentDetails)
  1874. string(APPEND __cmake_providerArgs " [==[${__cmake_item}]==]")
  1875. endforeach()
  1876. # This property might be defined but empty. As long as it is defined,
  1877. # find_package() can be called.
  1878. get_property(__cmake_addfpargs GLOBAL PROPERTY
  1879. _FetchContent_${__cmake_contentNameLower}_find_package_args
  1880. DEFINED
  1881. )
  1882. if(__cmake_addfpargs)
  1883. get_property(__cmake_fpargs GLOBAL PROPERTY
  1884. _FetchContent_${__cmake_contentNameLower}_find_package_args
  1885. )
  1886. string(APPEND __cmake_providerArgs " FIND_PACKAGE_ARGS")
  1887. foreach(__cmake_item IN LISTS __cmake_fpargs)
  1888. string(APPEND __cmake_providerArgs " [==[${__cmake_item}]==]")
  1889. endforeach()
  1890. endif()
  1891. # Calling the provider could lead to FetchContent_MakeAvailable() being
  1892. # called for a nested dependency. That nested call may occur in the
  1893. # current variable scope. We have to save and restore the variables we
  1894. # need preserved.
  1895. list(APPEND __cmake_fcCurrentVarsStack
  1896. ${__cmake_contentName}
  1897. ${__cmake_contentNameLower}
  1898. )
  1899. set(__cmake_fcProvider_${__cmake_contentNameLower} YES)
  1900. # The provider needs to see policies from our caller, so we need a
  1901. # helper macro defined outside our policy block. We pass through a
  1902. # variable name rather than variable contents to avoid any potential
  1903. # problems with parsing macro arguments.
  1904. set(__cmake_fcCode "${__cmake_providerCommand}(${__cmake_providerArgs})")
  1905. __FetchContent_MakeAvailable_eval_code(__cmake_fcCode)
  1906. list(POP_BACK __cmake_fcCurrentVarsStack
  1907. __cmake_contentNameLower
  1908. __cmake_contentName
  1909. CMAKE_EXPORT_FIND_PACKAGE_NAME
  1910. )
  1911. if(CMAKE_EXPORT_FIND_PACKAGE_NAME STREQUAL "<<::VAR_NOT_SET::>>")
  1912. unset(CMAKE_EXPORT_FIND_PACKAGE_NAME)
  1913. endif()
  1914. unset(__cmake_fcCode)
  1915. unset(__cmake_fcProvider_${__cmake_contentNameLower})
  1916. unset(__cmake_providerArgs)
  1917. unset(__cmake_addfpargs)
  1918. unset(__cmake_fpargs)
  1919. unset(__cmake_item)
  1920. unset(__cmake_contentDetails)
  1921. FetchContent_GetProperties(${__cmake_contentName})
  1922. if(${__cmake_contentNameLower}_POPULATED)
  1923. continue()
  1924. endif()
  1925. endif()
  1926. # Check if we've been asked to try find_package() first, even if we
  1927. # have already populated this dependency. If we previously tried to
  1928. # use find_package() for this and it succeeded, those things might
  1929. # no longer be in scope, so we have to do it again.
  1930. get_property(__cmake_haveFpArgs GLOBAL PROPERTY
  1931. _FetchContent_${__cmake_contentNameLower}_find_package_args DEFINED
  1932. )
  1933. if(__cmake_haveFpArgs)
  1934. unset(__cmake_haveFpArgs)
  1935. message(VERBOSE "Trying find_package(${__cmake_contentName} ...) before FetchContent")
  1936. get_property(__cmake_fpArgs GLOBAL PROPERTY
  1937. _FetchContent_${__cmake_contentNameLower}_find_package_args
  1938. )
  1939. # This call could lead to FetchContent_MakeAvailable() being called for
  1940. # a nested dependency and it may occur in the current variable scope.
  1941. # We have to save/restore the variables we need to preserve.
  1942. list(APPEND __cmake_fcCurrentNameStack
  1943. ${__cmake_contentName}
  1944. ${__cmake_contentNameLower}
  1945. )
  1946. # We pass variable names rather than their contents so as to avoid any
  1947. # potential problems with macro argument parsing
  1948. __FetchContent_MakeAvailable_find_package(__cmake_contentName __cmake_fpArgs)
  1949. list(POP_BACK __cmake_fcCurrentNameStack
  1950. __cmake_contentNameLower
  1951. __cmake_contentName
  1952. )
  1953. unset(__cmake_fpArgs)
  1954. if(${__cmake_contentName}_FOUND)
  1955. FetchContent_SetPopulated(${__cmake_contentName})
  1956. FetchContent_GetProperties(${__cmake_contentName})
  1957. continue()
  1958. endif()
  1959. endif()
  1960. else()
  1961. unset(__cmake_haveFpArgs)
  1962. endif()
  1963. FetchContent_GetProperties(${__cmake_contentName})
  1964. if(NOT ${__cmake_contentNameLower}_POPULATED)
  1965. __FetchContent_Populate(${__cmake_contentName})
  1966. __FetchContent_setupFindPackageRedirection(${__cmake_contentName})
  1967. # Only try to call add_subdirectory() if the populated content
  1968. # can be treated that way. Protecting the call with the check
  1969. # allows this function to be used for projects that just want
  1970. # to ensure the content exists, such as to provide content at
  1971. # a known location. We check the saved details for an optional
  1972. # SOURCE_SUBDIR which can be used in the same way as its meaning
  1973. # for ExternalProject. It won't matter if it was passed through
  1974. # to the ExternalProject sub-build, since it would have been
  1975. # ignored there.
  1976. set(__cmake_srcdir "${${__cmake_contentNameLower}_SOURCE_DIR}")
  1977. __FetchContent_getSavedDetails(${__cmake_contentName} __cmake_contentDetails)
  1978. if("${__cmake_contentDetails}" STREQUAL "")
  1979. message(FATAL_ERROR "No details have been set for content: ${__cmake_contentName}")
  1980. endif()
  1981. cmake_parse_arguments(__cmake_arg "EXCLUDE_FROM_ALL;SYSTEM" "SOURCE_SUBDIR" "" ${__cmake_contentDetails})
  1982. if(NOT "${__cmake_arg_SOURCE_SUBDIR}" STREQUAL "")
  1983. string(APPEND __cmake_srcdir "/${__cmake_arg_SOURCE_SUBDIR}")
  1984. endif()
  1985. if(EXISTS ${__cmake_srcdir}/CMakeLists.txt)
  1986. if(DEFINED CMAKE_EXPORT_FIND_PACKAGE_NAME)
  1987. list(APPEND __cmake_fcCurrentVarsStack "${CMAKE_EXPORT_FIND_PACKAGE_NAME}")
  1988. else()
  1989. # This just needs to be something that can't be a real package name
  1990. list(APPEND __cmake_fcCurrentVarsStack "<<::VAR_NOT_SET::>>")
  1991. endif()
  1992. set(CMAKE_EXPORT_FIND_PACKAGE_NAME "${__cmake_contentName}")
  1993. set(__cmake_add_subdirectory_args ${__cmake_srcdir} ${${__cmake_contentNameLower}_BINARY_DIR})
  1994. if(__cmake_arg_EXCLUDE_FROM_ALL)
  1995. list(APPEND __cmake_add_subdirectory_args EXCLUDE_FROM_ALL)
  1996. endif()
  1997. if(__cmake_arg_SYSTEM)
  1998. list(APPEND __cmake_add_subdirectory_args SYSTEM)
  1999. endif()
  2000. # We pass a variable name rather than its contents so as to avoid any
  2001. # potential problems with macro argument parsing. It's highly unlikely
  2002. # in this case, but still theoretically possible someone might try to
  2003. # use a directory name that looks like a CMake variable evaluation.
  2004. __FetchContent_MakeAvailable_add_subdirectory(__cmake_add_subdirectory_args)
  2005. list(POP_BACK __cmake_fcCurrentVarsStack CMAKE_EXPORT_FIND_PACKAGE_NAME)
  2006. if(CMAKE_EXPORT_FIND_PACKAGE_NAME STREQUAL "<<::VAR_NOT_SET::>>")
  2007. unset(CMAKE_EXPORT_FIND_PACKAGE_NAME)
  2008. endif()
  2009. endif()
  2010. unset(__cmake_srcdir)
  2011. unset(__cmake_contentDetails)
  2012. unset(__cmake_arg_EXCLUDE_FROM_ALL)
  2013. unset(__cmake_arg_SYSTEM)
  2014. unset(__cmake_arg_SOURCE_SUBDIR)
  2015. unset(__cmake_add_subdirectory_args)
  2016. endif()
  2017. endforeach()
  2018. # Prefix will be "__fcprefix__"
  2019. list(POP_BACK __cmake_fcCurrentVarsStack __cmake_original_verify_setting)
  2020. string(SUBSTRING "${__cmake_original_verify_setting}"
  2021. 12 -1 __cmake_original_verify_setting
  2022. )
  2023. set(CMAKE_VERIFY_INTERFACE_HEADER_SETS ${__cmake_original_verify_setting})
  2024. # clear local variables to prevent leaking into the caller's scope
  2025. unset(__cmake_contentName)
  2026. unset(__cmake_contentNameLower)
  2027. unset(__cmake_contentNameUpper)
  2028. unset(__cmake_providerCommand)
  2029. unset(__cmake_original_verify_setting)
  2030. endmacro()
  2031. endblock() # End of FetchContent module's policy scope
  2032. # These are factored out here outside our policies block to preserve policy
  2033. # settings of the scope from which FetchContent was included. Any project or
  2034. # user code that actually relies on this is fragile and should enforce its own
  2035. # policies instead, but we keep these here to preserve backward compatibility.
  2036. macro(__FetchContent_MakeAvailable_eval_code code_var)
  2037. cmake_language(EVAL CODE "${${code_var}}")
  2038. endmacro()
  2039. macro(__FetchContent_MakeAvailable_find_package first_arg_var remaining_args_var)
  2040. find_package(${${first_arg_var}} ${${remaining_args_var}})
  2041. endmacro()
  2042. macro(__FetchContent_MakeAvailable_add_subdirectory args_var)
  2043. add_subdirectory(${${args_var}})
  2044. endmacro()