FetchContent.cmake 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083
  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. .. only:: html
  7. .. contents::
  8. Overview
  9. ^^^^^^^^
  10. This module enables populating content at configure time via any method
  11. supported by the :module:`ExternalProject` module. Whereas
  12. :command:`ExternalProject_Add` downloads at build time, the
  13. ``FetchContent`` module makes content available immediately, allowing the
  14. configure step to use the content in commands like :command:`add_subdirectory`,
  15. :command:`include` or :command:`file` operations.
  16. Content population details would normally be defined separately from the
  17. command that performs the actual population. This separation ensures that
  18. all of the dependency details are defined before anything may try to use those
  19. details to populate content. This is particularly important in more complex
  20. project hierarchies where dependencies may be shared between multiple projects.
  21. The following shows a typical example of declaring content details:
  22. .. code-block:: cmake
  23. FetchContent_Declare(
  24. googletest
  25. GIT_REPOSITORY https://github.com/google/googletest.git
  26. GIT_TAG release-1.8.0
  27. )
  28. For most typical cases, populating the content can then be done with a single
  29. command like so:
  30. .. code-block:: cmake
  31. FetchContent_MakeAvailable(googletest)
  32. The above command not only populates the content, it also adds it to the main
  33. build (if possible) so that the main build can use the populated project's
  34. targets, etc. In some cases, the main project may need to have more precise
  35. control over the population or may be required to explicitly define the
  36. population steps (e.g. if CMake versions earlier than 3.14 need to be
  37. supported). The typical pattern of such custom steps looks like this:
  38. .. code-block:: cmake
  39. FetchContent_GetProperties(googletest)
  40. if(NOT googletest_POPULATED)
  41. FetchContent_Populate(googletest)
  42. add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
  43. endif()
  44. Regardless of which population method is used, when using the
  45. declare-populate pattern with a hierarchical project arrangement, projects at
  46. higher levels in the hierarchy are able to override the population details of
  47. content specified anywhere lower in the project hierarchy. The ability to
  48. detect whether content has already been populated ensures that even if
  49. multiple child projects want certain content to be available, the first one
  50. to populate it wins. The other child project can simply make use of the
  51. already available content instead of repeating the population for itself.
  52. See the :ref:`Examples <fetch-content-examples>` section which demonstrates
  53. this scenario.
  54. The ``FetchContent`` module also supports defining and populating
  55. content in a single call, with no check for whether the content has been
  56. populated elsewhere in the project already. This is a more low level
  57. operation and would not normally be the way the module is used, but it is
  58. sometimes useful as part of implementing some higher level feature or to
  59. populate some content in CMake's script mode.
  60. Commands
  61. ^^^^^^^^
  62. Declaring Content Details
  63. """""""""""""""""""""""""
  64. .. command:: FetchContent_Declare
  65. .. code-block:: cmake
  66. FetchContent_Declare(<name> <contentOptions>...)
  67. The ``FetchContent_Declare()`` function records the options that describe
  68. how to populate the specified content, but if such details have already
  69. been recorded earlier in this project (regardless of where in the project
  70. hierarchy), this and all later calls for the same content ``<name>`` are
  71. ignored. This "first to record, wins" approach is what allows hierarchical
  72. projects to have parent projects override content details of child projects.
  73. The content ``<name>`` can be any string without spaces, but good practice
  74. would be to use only letters, numbers and underscores. The name will be
  75. treated case-insensitively and it should be obvious for the content it
  76. represents, often being the name of the child project or the value given
  77. to its top level :command:`project` command (if it is a CMake project).
  78. For well-known public projects, the name should generally be the official
  79. name of the project. Choosing an unusual name makes it unlikely that other
  80. projects needing that same content will use the same name, leading to
  81. the content being populated multiple times.
  82. The ``<contentOptions>`` can be any of the download or update/patch options
  83. that the :command:`ExternalProject_Add` command understands. The configure,
  84. build, install and test steps are explicitly disabled and therefore options
  85. related to them will be ignored. In most cases, ``<contentOptions>`` will
  86. just be a couple of options defining the download method and method-specific
  87. details like a commit tag or archive hash. For example:
  88. .. code-block:: cmake
  89. FetchContent_Declare(
  90. googletest
  91. GIT_REPOSITORY https://github.com/google/googletest.git
  92. GIT_TAG release-1.8.0
  93. )
  94. FetchContent_Declare(
  95. myCompanyIcons
  96. URL https://intranet.mycompany.com/assets/iconset_1.12.tar.gz
  97. URL_HASH 5588a7b18261c20068beabfb4f530b87
  98. )
  99. FetchContent_Declare(
  100. myCompanyCertificates
  101. SVN_REPOSITORY svn+ssh://svn.mycompany.com/srv/svn/trunk/certs
  102. SVN_REVISION -r12345
  103. )
  104. Populating The Content
  105. """"""""""""""""""""""
  106. For most common scenarios, population means making content available to the
  107. main build according to previously declared details for that dependency.
  108. There are two main patterns for populating content, one based on calling
  109. :command:`FetchContent_GetProperties` and
  110. :command:`FetchContent_Populate` for more precise control and the other on
  111. calling :command:`FetchContent_MakeAvailable` for a simpler, more automated
  112. approach. The former generally follows this canonical pattern:
  113. .. _`fetch-content-canonical-pattern`:
  114. .. code-block:: cmake
  115. # Check if population has already been performed
  116. FetchContent_GetProperties(<name>)
  117. string(TOLOWER "<name>" lcName)
  118. if(NOT ${lcName}_POPULATED)
  119. # Fetch the content using previously declared details
  120. FetchContent_Populate(<name>)
  121. # Set custom variables, policies, etc.
  122. # ...
  123. # Bring the populated content into the build
  124. add_subdirectory(${${lcName}_SOURCE_DIR} ${${lcName}_BINARY_DIR})
  125. endif()
  126. The above is such a common pattern that, where no custom steps are needed
  127. between the calls to :command:`FetchContent_Populate` and
  128. :command:`add_subdirectory`, equivalent logic can be obtained by calling
  129. :command:`FetchContent_MakeAvailable` instead (and should be preferred where
  130. it meets the needs of the project).
  131. .. command:: FetchContent_Populate
  132. .. code-block:: cmake
  133. FetchContent_Populate( <name> )
  134. In most cases, the only argument given to ``FetchContent_Populate()`` is the
  135. ``<name>``. When used this way, the command assumes the content details have
  136. been recorded by an earlier call to :command:`FetchContent_Declare`. The
  137. details are stored in a global property, so they are unaffected by things
  138. like variable or directory scope. Therefore, it doesn't matter where in the
  139. project the details were previously declared, as long as they have been
  140. declared before the call to ``FetchContent_Populate()``. Those saved details
  141. are then used to construct a call to :command:`ExternalProject_Add` in a
  142. private sub-build to perform the content population immediately. The
  143. implementation of ``ExternalProject_Add()`` ensures that if the content has
  144. already been populated in a previous CMake run, that content will be reused
  145. rather than repopulating them again. For the common case where population
  146. involves downloading content, the cost of the download is only paid once.
  147. An internal global property records when a particular content population
  148. request has been processed. If ``FetchContent_Populate()`` is called more
  149. than once for the same content name within a configure run, the second call
  150. will halt with an error. Projects can and should check whether content
  151. population has already been processed with the
  152. :command:`FetchContent_GetProperties` command before calling
  153. ``FetchContent_Populate()``.
  154. ``FetchContent_Populate()`` will set three variables in the scope of the
  155. caller; ``<lcName>_POPULATED``, ``<lcName>_SOURCE_DIR`` and
  156. ``<lcName>_BINARY_DIR``, where ``<lcName>`` is the lowercased ``<name>``.
  157. ``<lcName>_POPULATED`` will always be set to ``True`` by the call.
  158. ``<lcName>_SOURCE_DIR`` is the location where the
  159. content can be found upon return (it will have already been populated), while
  160. ``<lcName>_BINARY_DIR`` is a directory intended for use as a corresponding
  161. build directory. The main use case for the two directory variables is to
  162. call :command:`add_subdirectory` immediately after population, i.e.:
  163. .. code-block:: cmake
  164. FetchContent_Populate(FooBar ...)
  165. add_subdirectory(${foobar_SOURCE_DIR} ${foobar_BINARY_DIR})
  166. The values of the three variables can also be retrieved from anywhere in the
  167. project hierarchy using the :command:`FetchContent_GetProperties` command.
  168. A number of cache variables influence the behavior of all content population
  169. performed using details saved from a :command:`FetchContent_Declare` call:
  170. ``FETCHCONTENT_BASE_DIR``
  171. In most cases, the saved details do not specify any options relating to the
  172. directories to use for the internal sub-build, final source and build areas.
  173. It is generally best to leave these decisions up to the ``FetchContent``
  174. module to handle on the project's behalf. The ``FETCHCONTENT_BASE_DIR``
  175. cache variable controls the point under which all content population
  176. directories are collected, but in most cases developers would not need to
  177. change this. The default location is ``${CMAKE_BINARY_DIR}/_deps``, but if
  178. developers change this value, they should aim to keep the path short and
  179. just below the top level of the build tree to avoid running into path
  180. length problems on Windows.
  181. ``FETCHCONTENT_QUIET``
  182. The logging output during population can be quite verbose, making the
  183. configure stage quite noisy. This cache option (``ON`` by default) hides
  184. all population output unless an error is encountered. If experiencing
  185. problems with hung downloads, temporarily switching this option off may
  186. help diagnose which content population is causing the issue.
  187. ``FETCHCONTENT_FULLY_DISCONNECTED``
  188. When this option is enabled, no attempt is made to download or update
  189. any content. It is assumed that all content has already been populated in
  190. a previous run or the source directories have been pointed at existing
  191. contents the developer has provided manually (using options described
  192. further below). When the developer knows that no changes have been made to
  193. any content details, turning this option ``ON`` can significantly speed up
  194. the configure stage. It is ``OFF`` by default.
  195. ``FETCHCONTENT_UPDATES_DISCONNECTED``
  196. This is a less severe download/update control compared to
  197. ``FETCHCONTENT_FULLY_DISCONNECTED``. Instead of bypassing all download and
  198. update logic, the ``FETCHCONTENT_UPDATES_DISCONNECTED`` only disables the
  199. update stage. Therefore, if content has not been downloaded previously,
  200. it will still be downloaded when this option is enabled. This can speed up
  201. the configure stage, but not as much as
  202. ``FETCHCONTENT_FULLY_DISCONNECTED``. It is ``OFF`` by default.
  203. In addition to the above cache variables, the following cache variables are
  204. also defined for each content name (``<ucName>`` is the uppercased value of
  205. ``<name>``):
  206. ``FETCHCONTENT_SOURCE_DIR_<ucName>``
  207. If this is set, no download or update steps are performed for the specified
  208. content and the ``<lcName>_SOURCE_DIR`` variable returned to the caller is
  209. pointed at this location. This gives developers a way to have a separate
  210. checkout of the content that they can modify freely without interference
  211. from the build. The build simply uses that existing source, but it still
  212. defines ``<lcName>_BINARY_DIR`` to point inside its own build area.
  213. Developers are strongly encouraged to use this mechanism rather than
  214. editing the sources populated in the default location, as changes to
  215. sources in the default location can be lost when content population details
  216. are changed by the project.
  217. ``FETCHCONTENT_UPDATES_DISCONNECTED_<ucName>``
  218. This is the per-content equivalent of
  219. ``FETCHCONTENT_UPDATES_DISCONNECTED``. If the global option or this option
  220. is ``ON``, then updates will be disabled for the named content.
  221. Disabling updates for individual content can be useful for content whose
  222. details rarely change, while still leaving other frequently changing
  223. content with updates enabled.
  224. The ``FetchContent_Populate()`` command also supports a syntax allowing the
  225. content details to be specified directly rather than using any saved
  226. details. This is more low-level and use of this form is generally to be
  227. avoided in favour of using saved content details as outlined above.
  228. Nevertheless, in certain situations it can be useful to invoke the content
  229. population as an isolated operation (typically as part of implementing some
  230. other higher level feature or when using CMake in script mode):
  231. .. code-block:: cmake
  232. FetchContent_Populate( <name>
  233. [QUIET]
  234. [SUBBUILD_DIR <subBuildDir>]
  235. [SOURCE_DIR <srcDir>]
  236. [BINARY_DIR <binDir>]
  237. ...
  238. )
  239. This form has a number of key differences to that where only ``<name>`` is
  240. provided:
  241. - All required population details are assumed to have been provided directly
  242. in the call to ``FetchContent_Populate()``. Any saved details for
  243. ``<name>`` are ignored.
  244. - No check is made for whether content for ``<name>`` has already been
  245. populated.
  246. - No global property is set to record that the population has occurred.
  247. - No global properties record the source or binary directories used for the
  248. populated content.
  249. - The ``FETCHCONTENT_FULLY_DISCONNECTED`` and
  250. ``FETCHCONTENT_UPDATES_DISCONNECTED`` cache variables are ignored.
  251. The ``<lcName>_SOURCE_DIR`` and ``<lcName>_BINARY_DIR`` variables are still
  252. returned to the caller, but since these locations are not stored as global
  253. properties when this form is used, they are only available to the calling
  254. scope and below rather than the entire project hierarchy. No
  255. ``<lcName>_POPULATED`` variable is set in the caller's scope with this form.
  256. The supported options for ``FetchContent_Populate()`` are the same as those
  257. for :command:`FetchContent_Declare()`. Those few options shown just
  258. above are either specific to ``FetchContent_Populate()`` or their behavior is
  259. slightly modified from how :command:`ExternalProject_Add` treats them.
  260. ``QUIET``
  261. The ``QUIET`` option can be given to hide the output associated with
  262. populating the specified content. If the population fails, the output will
  263. be shown regardless of whether this option was given or not so that the
  264. cause of the failure can be diagnosed. The global ``FETCHCONTENT_QUIET``
  265. cache variable has no effect on ``FetchContent_Populate()`` calls where the
  266. content details are provided directly.
  267. ``SUBBUILD_DIR``
  268. The ``SUBBUILD_DIR`` argument can be provided to change the location of the
  269. sub-build created to perform the population. The default value is
  270. ``${CMAKE_CURRENT_BINARY_DIR}/<lcName>-subbuild`` and it would be unusual
  271. to need to override this default. If a relative path is specified, it will
  272. be interpreted as relative to :variable:`CMAKE_CURRENT_BINARY_DIR`.
  273. ``SOURCE_DIR``, ``BINARY_DIR``
  274. The ``SOURCE_DIR`` and ``BINARY_DIR`` arguments are supported by
  275. :command:`ExternalProject_Add`, but different default values are used by
  276. ``FetchContent_Populate()``. ``SOURCE_DIR`` defaults to
  277. ``${CMAKE_CURRENT_BINARY_DIR}/<lcName>-src`` and ``BINARY_DIR`` defaults to
  278. ``${CMAKE_CURRENT_BINARY_DIR}/<lcName>-build``. If a relative path is
  279. specified, it will be interpreted as relative to
  280. :variable:`CMAKE_CURRENT_BINARY_DIR`.
  281. In addition to the above explicit options, any other unrecognized options are
  282. passed through unmodified to :command:`ExternalProject_Add` to perform the
  283. download, patch and update steps. The following options are explicitly
  284. prohibited (they are disabled by the ``FetchContent_Populate()`` command):
  285. - ``CONFIGURE_COMMAND``
  286. - ``BUILD_COMMAND``
  287. - ``INSTALL_COMMAND``
  288. - ``TEST_COMMAND``
  289. If using ``FetchContent_Populate()`` within CMake's script mode, be aware
  290. that the implementation sets up a sub-build which therefore requires a CMake
  291. generator and build tool to be available. If these cannot be found by
  292. default, then the :variable:`CMAKE_GENERATOR` and/or
  293. :variable:`CMAKE_MAKE_PROGRAM` variables will need to be set appropriately
  294. on the command line invoking the script.
  295. .. command:: FetchContent_GetProperties
  296. When using saved content details, a call to :command:`FetchContent_Populate`
  297. records information in global properties which can be queried at any time.
  298. This information includes the source and binary directories associated with
  299. the content and also whether or not the content population has been processed
  300. during the current configure run.
  301. .. code-block:: cmake
  302. FetchContent_GetProperties( <name>
  303. [SOURCE_DIR <srcDirVar>]
  304. [BINARY_DIR <binDirVar>]
  305. [POPULATED <doneVar>]
  306. )
  307. The ``SOURCE_DIR``, ``BINARY_DIR`` and ``POPULATED`` options can be used to
  308. specify which properties should be retrieved. Each option accepts a value
  309. which is the name of the variable in which to store that property. Most of
  310. the time though, only ``<name>`` is given, in which case the call will then
  311. set the same variables as a call to
  312. :command:`FetchContent_Populate(name) <FetchContent_Populate>`. This allows
  313. the following canonical pattern to be used, which ensures that the relevant
  314. variables will always be defined regardless of whether or not the population
  315. has been performed elsewhere in the project already:
  316. .. code-block:: cmake
  317. FetchContent_GetProperties(foobar)
  318. if(NOT foobar_POPULATED)
  319. FetchContent_Populate(foobar)
  320. ...
  321. endif()
  322. The above pattern allows other parts of the overall project hierarchy to
  323. re-use the same content and ensure that it is only populated once.
  324. .. command:: FetchContent_MakeAvailable
  325. .. code-block:: cmake
  326. FetchContent_MakeAvailable( <name1> [<name2>...] )
  327. This command implements the common pattern typically needed for most
  328. dependencies. It iterates over each of the named dependencies in turn
  329. and for each one it loosely follows the same
  330. :ref:`canonical pattern <fetch-content-canonical-pattern>` as
  331. presented at the beginning of this section. One small difference to
  332. that pattern is that it will only call :command:`add_subdirectory` on the
  333. populated content if there is a ``CMakeLists.txt`` file in its top level
  334. source directory. This allows the command to be used for dependencies
  335. that make downloaded content available at a known location but which do
  336. not need or support being added directly to the build.
  337. .. _`fetch-content-examples`:
  338. Examples
  339. ^^^^^^^^
  340. This first fairly straightforward example ensures that some popular testing
  341. frameworks are available to the main build:
  342. .. code-block:: cmake
  343. include(FetchContent)
  344. FetchContent_Declare(
  345. googletest
  346. GIT_REPOSITORY https://github.com/google/googletest.git
  347. GIT_TAG release-1.8.0
  348. )
  349. FetchContent_Declare(
  350. Catch2
  351. GIT_REPOSITORY https://github.com/catchorg/Catch2.git
  352. GIT_TAG v2.5.0
  353. )
  354. # After the following call, the CMake targets defined by googletest and
  355. # Catch2 will be defined and available to the rest of the build
  356. FetchContent_MakeAvailable(googletest Catch2)
  357. In more complex project hierarchies, the dependency relationships can be more
  358. complicated. Consider a hierarchy where ``projA`` is the top level project and
  359. it depends directly on projects ``projB`` and ``projC``. Both ``projB`` and
  360. ``projC`` can be built standalone and they also both depend on another project
  361. ``projD``. ``projB`` additionally depends on ``projE``. This example assumes
  362. that all five projects are available on a company git server. The
  363. ``CMakeLists.txt`` of each project might have sections like the following:
  364. *projA*:
  365. .. code-block:: cmake
  366. include(FetchContent)
  367. FetchContent_Declare(
  368. projB
  369. GIT_REPOSITORY [email protected]:git/projB.git
  370. GIT_TAG 4a89dc7e24ff212a7b5167bef7ab079d
  371. )
  372. FetchContent_Declare(
  373. projC
  374. GIT_REPOSITORY [email protected]:git/projC.git
  375. GIT_TAG 4ad4016bd1d8d5412d135cf8ceea1bb9
  376. )
  377. FetchContent_Declare(
  378. projD
  379. GIT_REPOSITORY [email protected]:git/projD.git
  380. GIT_TAG origin/integrationBranch
  381. )
  382. FetchContent_Declare(
  383. projE
  384. GIT_REPOSITORY [email protected]:git/projE.git
  385. GIT_TAG origin/release/2.3-rc1
  386. )
  387. # Order is important, see notes in the discussion further below
  388. FetchContent_MakeAvailable(projD projB projC)
  389. *projB*:
  390. .. code-block:: cmake
  391. include(FetchContent)
  392. FetchContent_Declare(
  393. projD
  394. GIT_REPOSITORY [email protected]:git/projD.git
  395. GIT_TAG 20b415f9034bbd2a2e8216e9a5c9e632
  396. )
  397. FetchContent_Declare(
  398. projE
  399. GIT_REPOSITORY [email protected]:git/projE.git
  400. GIT_TAG 68e20f674a48be38d60e129f600faf7d
  401. )
  402. FetchContent_MakeAvailable(projD projE)
  403. *projC*:
  404. .. code-block:: cmake
  405. include(FetchContent)
  406. FetchContent_Declare(
  407. projD
  408. GIT_REPOSITORY [email protected]:git/projD.git
  409. GIT_TAG 7d9a17ad2c962aa13e2fbb8043fb6b8a
  410. )
  411. # This particular version of projD requires workarounds
  412. FetchContent_GetProperties(projD)
  413. if(NOT projd_POPULATED)
  414. FetchContent_Populate(projD)
  415. # Copy an additional/replacement file into the populated source
  416. file(COPY someFile.c DESTINATION ${projd_SOURCE_DIR}/src)
  417. add_subdirectory(${projd_SOURCE_DIR} ${projd_BINARY_DIR})
  418. endif()
  419. A few key points should be noted in the above:
  420. - ``projB`` and ``projC`` define different content details for ``projD``,
  421. but ``projA`` also defines a set of content details for ``projD``.
  422. Because ``projA`` will define them first, the details from ``projB`` and
  423. ``projC`` will not be used. The override details defined by ``projA``
  424. are not required to match either of those from ``projB`` or ``projC``, but
  425. it is up to the higher level project to ensure that the details it does
  426. define still make sense for the child projects.
  427. - In the ``projA`` call to :command:`FetchContent_MakeAvailable`, ``projD``
  428. is listed ahead of ``projB`` and ``projC`` to ensure that ``projA`` is in
  429. control of how ``projD`` is populated.
  430. - While ``projA`` defines content details for ``projE``, it does not need
  431. to explicitly call ``FetchContent_MakeAvailable(projE)`` or
  432. ``FetchContent_Populate(projD)`` itself. Instead, it leaves that to the
  433. child ``projB``. For higher level projects, it is often enough to just
  434. define the override content details and leave the actual population to the
  435. child projects. This saves repeating the same thing at each level of the
  436. project hierarchy unnecessarily.
  437. Projects don't always need to add the populated content to the build.
  438. Sometimes the project just wants to make the downloaded content available at
  439. a predictable location. The next example ensures that a set of standard
  440. company toolchain files (and potentially even the toolchain binaries
  441. themselves) is available early enough to be used for that same build.
  442. .. code-block:: cmake
  443. cmake_minimum_required(VERSION 3.14)
  444. include(FetchContent)
  445. FetchContent_Declare(
  446. mycom_toolchains
  447. URL https://intranet.mycompany.com//toolchains_1.3.2.tar.gz
  448. )
  449. FetchContent_MakeAvailable(mycom_toolchains)
  450. project(CrossCompileExample)
  451. The project could be configured to use one of the downloaded toolchains like
  452. so:
  453. .. code-block:: shell
  454. cmake -DCMAKE_TOOLCHAIN_FILE=_deps/mycom_toolchains-src/toolchain_arm.cmake /path/to/src
  455. When CMake processes the ``CMakeLists.txt`` file, it will download and unpack
  456. the tarball into ``_deps/mycompany_toolchains-src`` relative to the build
  457. directory. The :variable:`CMAKE_TOOLCHAIN_FILE` variable is not used until
  458. the :command:`project` command is reached, at which point CMake looks for the
  459. named toolchain file relative to the build directory. Because the tarball has
  460. already been downloaded and unpacked by then, the toolchain file will be in
  461. place, even the very first time that ``cmake`` is run in the build directory.
  462. Lastly, the following example demonstrates how one might download and unpack a
  463. firmware tarball using CMake's :manual:`script mode <cmake(1)>`. The call to
  464. :command:`FetchContent_Populate` specifies all the content details and the
  465. unpacked firmware will be placed in a ``firmware`` directory below the
  466. current working directory.
  467. *getFirmware.cmake*:
  468. .. code-block:: cmake
  469. # NOTE: Intended to be run in script mode with cmake -P
  470. include(FetchContent)
  471. FetchContent_Populate(
  472. firmware
  473. URL https://mycompany.com/assets/firmware-1.23-arm.tar.gz
  474. URL_HASH MD5=68247684da89b608d466253762b0ff11
  475. SOURCE_DIR firmware
  476. )
  477. #]=======================================================================]
  478. #=======================================================================
  479. # Recording and retrieving content details for later population
  480. #=======================================================================
  481. # Internal use, projects must not call this directly. It is
  482. # intended for use by FetchContent_Declare() only.
  483. #
  484. # Sets a content-specific global property (not meant for use
  485. # outside of functions defined here in this file) which can later
  486. # be retrieved using __FetchContent_getSavedDetails() with just the
  487. # same content name. If there is already a value stored in the
  488. # property, it is left unchanged and this call has no effect.
  489. # This allows parent projects to define the content details,
  490. # overriding anything a child project may try to set (properties
  491. # are not cached between runs, so the first thing to set it in a
  492. # build will be in control).
  493. function(__FetchContent_declareDetails contentName)
  494. string(TOLOWER ${contentName} contentNameLower)
  495. set(propertyName "_FetchContent_${contentNameLower}_savedDetails")
  496. get_property(alreadyDefined GLOBAL PROPERTY ${propertyName} DEFINED)
  497. if(NOT alreadyDefined)
  498. define_property(GLOBAL PROPERTY ${propertyName}
  499. BRIEF_DOCS "Internal implementation detail of FetchContent_Populate()"
  500. FULL_DOCS "Details used by FetchContent_Populate() for ${contentName}"
  501. )
  502. set_property(GLOBAL PROPERTY ${propertyName} ${ARGN})
  503. endif()
  504. endfunction()
  505. # Internal use, projects must not call this directly. It is
  506. # intended for use by the FetchContent_Declare() function.
  507. #
  508. # Retrieves details saved for the specified content in an
  509. # earlier call to __FetchContent_declareDetails().
  510. function(__FetchContent_getSavedDetails contentName outVar)
  511. string(TOLOWER ${contentName} contentNameLower)
  512. set(propertyName "_FetchContent_${contentNameLower}_savedDetails")
  513. get_property(alreadyDefined GLOBAL PROPERTY ${propertyName} DEFINED)
  514. if(NOT alreadyDefined)
  515. message(FATAL_ERROR "No content details recorded for ${contentName}")
  516. endif()
  517. get_property(propertyValue GLOBAL PROPERTY ${propertyName})
  518. set(${outVar} "${propertyValue}" PARENT_SCOPE)
  519. endfunction()
  520. # Saves population details of the content, sets defaults for the
  521. # SOURCE_DIR and BUILD_DIR.
  522. function(FetchContent_Declare contentName)
  523. set(options "")
  524. set(oneValueArgs SVN_REPOSITORY)
  525. set(multiValueArgs "")
  526. cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
  527. unset(srcDirSuffix)
  528. unset(svnRepoArgs)
  529. if(ARG_SVN_REPOSITORY)
  530. # Add a hash of the svn repository URL to the source dir. This works
  531. # around the problem where if the URL changes, the download would
  532. # fail because it tries to checkout/update rather than switch the
  533. # old URL to the new one. We limit the hash to the first 7 characters
  534. # so that the source path doesn't get overly long (which can be a
  535. # problem on windows due to path length limits).
  536. string(SHA1 urlSHA ${ARG_SVN_REPOSITORY})
  537. string(SUBSTRING ${urlSHA} 0 7 urlSHA)
  538. set(srcDirSuffix "-${urlSHA}")
  539. set(svnRepoArgs SVN_REPOSITORY ${ARG_SVN_REPOSITORY})
  540. endif()
  541. string(TOLOWER ${contentName} contentNameLower)
  542. __FetchContent_declareDetails(
  543. ${contentNameLower}
  544. SOURCE_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-src${srcDirSuffix}"
  545. BINARY_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-build"
  546. ${svnRepoArgs}
  547. # List these last so they can override things we set above
  548. ${ARG_UNPARSED_ARGUMENTS}
  549. )
  550. endfunction()
  551. #=======================================================================
  552. # Set/get whether the specified content has been populated yet.
  553. # The setter also records the source and binary dirs used.
  554. #=======================================================================
  555. # Internal use, projects must not call this directly. It is
  556. # intended for use by the FetchContent_Populate() function to
  557. # record when FetchContent_Populate() is called for a particular
  558. # content name.
  559. function(__FetchContent_setPopulated contentName sourceDir binaryDir)
  560. string(TOLOWER ${contentName} contentNameLower)
  561. set(prefix "_FetchContent_${contentNameLower}")
  562. set(propertyName "${prefix}_sourceDir")
  563. define_property(GLOBAL PROPERTY ${propertyName}
  564. BRIEF_DOCS "Internal implementation detail of FetchContent_Populate()"
  565. FULL_DOCS "Details used by FetchContent_Populate() for ${contentName}"
  566. )
  567. set_property(GLOBAL PROPERTY ${propertyName} ${sourceDir})
  568. set(propertyName "${prefix}_binaryDir")
  569. define_property(GLOBAL PROPERTY ${propertyName}
  570. BRIEF_DOCS "Internal implementation detail of FetchContent_Populate()"
  571. FULL_DOCS "Details used by FetchContent_Populate() for ${contentName}"
  572. )
  573. set_property(GLOBAL PROPERTY ${propertyName} ${binaryDir})
  574. set(propertyName "${prefix}_populated")
  575. define_property(GLOBAL PROPERTY ${propertyName}
  576. BRIEF_DOCS "Internal implementation detail of FetchContent_Populate()"
  577. FULL_DOCS "Details used by FetchContent_Populate() for ${contentName}"
  578. )
  579. set_property(GLOBAL PROPERTY ${propertyName} True)
  580. endfunction()
  581. # Set variables in the calling scope for any of the retrievable
  582. # properties. If no specific properties are requested, variables
  583. # will be set for all retrievable properties.
  584. #
  585. # This function is intended to also be used by projects as the canonical
  586. # way to detect whether they should call FetchContent_Populate()
  587. # and pull the populated source into the build with add_subdirectory(),
  588. # if they are using the populated content in that way.
  589. function(FetchContent_GetProperties contentName)
  590. string(TOLOWER ${contentName} contentNameLower)
  591. set(options "")
  592. set(oneValueArgs SOURCE_DIR BINARY_DIR POPULATED)
  593. set(multiValueArgs "")
  594. cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
  595. if(NOT ARG_SOURCE_DIR AND
  596. NOT ARG_BINARY_DIR AND
  597. NOT ARG_POPULATED)
  598. # No specific properties requested, provide them all
  599. set(ARG_SOURCE_DIR ${contentNameLower}_SOURCE_DIR)
  600. set(ARG_BINARY_DIR ${contentNameLower}_BINARY_DIR)
  601. set(ARG_POPULATED ${contentNameLower}_POPULATED)
  602. endif()
  603. set(prefix "_FetchContent_${contentNameLower}")
  604. if(ARG_SOURCE_DIR)
  605. set(propertyName "${prefix}_sourceDir")
  606. get_property(value GLOBAL PROPERTY ${propertyName})
  607. if(value)
  608. set(${ARG_SOURCE_DIR} ${value} PARENT_SCOPE)
  609. endif()
  610. endif()
  611. if(ARG_BINARY_DIR)
  612. set(propertyName "${prefix}_binaryDir")
  613. get_property(value GLOBAL PROPERTY ${propertyName})
  614. if(value)
  615. set(${ARG_BINARY_DIR} ${value} PARENT_SCOPE)
  616. endif()
  617. endif()
  618. if(ARG_POPULATED)
  619. set(propertyName "${prefix}_populated")
  620. get_property(value GLOBAL PROPERTY ${propertyName} DEFINED)
  621. set(${ARG_POPULATED} ${value} PARENT_SCOPE)
  622. endif()
  623. endfunction()
  624. #=======================================================================
  625. # Performing the population
  626. #=======================================================================
  627. # The value of contentName will always have been lowercased by the caller.
  628. # All other arguments are assumed to be options that are understood by
  629. # ExternalProject_Add(), except for QUIET and SUBBUILD_DIR.
  630. function(__FetchContent_directPopulate contentName)
  631. set(options
  632. QUIET
  633. )
  634. set(oneValueArgs
  635. SUBBUILD_DIR
  636. SOURCE_DIR
  637. BINARY_DIR
  638. # We need special processing if DOWNLOAD_NO_EXTRACT is true
  639. DOWNLOAD_NO_EXTRACT
  640. # Prevent the following from being passed through
  641. CONFIGURE_COMMAND
  642. BUILD_COMMAND
  643. INSTALL_COMMAND
  644. TEST_COMMAND
  645. # We force both of these to be ON since we are always executing serially
  646. # and we want all steps to have access to the terminal in case they
  647. # need input from the command line (e.g. ask for a private key password)
  648. # or they want to provide timely progress. We silently absorb and
  649. # discard these if they are set by the caller.
  650. USES_TERMINAL_DOWNLOAD
  651. USES_TERMINAL_UPDATE
  652. )
  653. set(multiValueArgs "")
  654. cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
  655. if(NOT ARG_SUBBUILD_DIR)
  656. message(FATAL_ERROR "Internal error: SUBBUILD_DIR not set")
  657. elseif(NOT IS_ABSOLUTE "${ARG_SUBBUILD_DIR}")
  658. set(ARG_SUBBUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/${ARG_SUBBUILD_DIR}")
  659. endif()
  660. if(NOT ARG_SOURCE_DIR)
  661. message(FATAL_ERROR "Internal error: SOURCE_DIR not set")
  662. elseif(NOT IS_ABSOLUTE "${ARG_SOURCE_DIR}")
  663. set(ARG_SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/${ARG_SOURCE_DIR}")
  664. endif()
  665. if(NOT ARG_BINARY_DIR)
  666. message(FATAL_ERROR "Internal error: BINARY_DIR not set")
  667. elseif(NOT IS_ABSOLUTE "${ARG_BINARY_DIR}")
  668. set(ARG_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/${ARG_BINARY_DIR}")
  669. endif()
  670. # Ensure the caller can know where to find the source and build directories
  671. # with some convenient variables. Doing this here ensures the caller sees
  672. # the correct result in the case where the default values are overridden by
  673. # the content details set by the project.
  674. set(${contentName}_SOURCE_DIR "${ARG_SOURCE_DIR}" PARENT_SCOPE)
  675. set(${contentName}_BINARY_DIR "${ARG_BINARY_DIR}" PARENT_SCOPE)
  676. # The unparsed arguments may contain spaces, so build up ARG_EXTRA
  677. # in such a way that it correctly substitutes into the generated
  678. # CMakeLists.txt file with each argument quoted.
  679. unset(ARG_EXTRA)
  680. foreach(arg IN LISTS ARG_UNPARSED_ARGUMENTS)
  681. set(ARG_EXTRA "${ARG_EXTRA} \"${arg}\"")
  682. endforeach()
  683. if(ARG_DOWNLOAD_NO_EXTRACT)
  684. set(ARG_EXTRA "${ARG_EXTRA} DOWNLOAD_NO_EXTRACT YES")
  685. set(__FETCHCONTENT_COPY_FILE
  686. "
  687. ExternalProject_Get_Property(${contentName}-populate DOWNLOADED_FILE)
  688. get_filename_component(dlFileName \"\${DOWNLOADED_FILE}\" NAME)
  689. ExternalProject_Add_Step(${contentName}-populate copyfile
  690. COMMAND \"${CMAKE_COMMAND}\" -E copy_if_different
  691. \"<DOWNLOADED_FILE>\" \"${ARG_SOURCE_DIR}\"
  692. DEPENDEES patch
  693. DEPENDERS configure
  694. BYPRODUCTS \"${ARG_SOURCE_DIR}/\${dlFileName}\"
  695. COMMENT \"Copying file to SOURCE_DIR\"
  696. )
  697. ")
  698. else()
  699. unset(__FETCHCONTENT_COPY_FILE)
  700. endif()
  701. # Hide output if requested, but save it to a variable in case there's an
  702. # error so we can show the output upon failure. When not quiet, don't
  703. # capture the output to a variable because the user may want to see the
  704. # output as it happens (e.g. progress during long downloads). Combine both
  705. # stdout and stderr in the one capture variable so the output stays in order.
  706. if (ARG_QUIET)
  707. set(outputOptions
  708. OUTPUT_VARIABLE capturedOutput
  709. ERROR_VARIABLE capturedOutput
  710. )
  711. else()
  712. set(capturedOutput)
  713. set(outputOptions)
  714. message(STATUS "Populating ${contentName}")
  715. endif()
  716. if(CMAKE_GENERATOR)
  717. set(generatorOpts "-G${CMAKE_GENERATOR}")
  718. if(CMAKE_GENERATOR_PLATFORM)
  719. list(APPEND generatorOpts "-A${CMAKE_GENERATOR_PLATFORM}")
  720. endif()
  721. if(CMAKE_GENERATOR_TOOLSET)
  722. list(APPEND generatorOpts "-T${CMAKE_GENERATOR_TOOLSET}")
  723. endif()
  724. if(CMAKE_MAKE_PROGRAM)
  725. list(APPEND generatorOpts "-DCMAKE_MAKE_PROGRAM:FILEPATH=${CMAKE_MAKE_PROGRAM}")
  726. endif()
  727. else()
  728. # Likely we've been invoked via CMake's script mode where no
  729. # generator is set (and hence CMAKE_MAKE_PROGRAM could not be
  730. # trusted even if provided). We will have to rely on being
  731. # able to find the default generator and build tool.
  732. unset(generatorOpts)
  733. endif()
  734. # Create and build a separate CMake project to carry out the population.
  735. # If we've already previously done these steps, they will not cause
  736. # anything to be updated, so extra rebuilds of the project won't occur.
  737. # Make sure to pass through CMAKE_MAKE_PROGRAM in case the main project
  738. # has this set to something not findable on the PATH.
  739. configure_file("${CMAKE_CURRENT_FUNCTION_LIST_DIR}/FetchContent/CMakeLists.cmake.in"
  740. "${ARG_SUBBUILD_DIR}/CMakeLists.txt")
  741. execute_process(
  742. COMMAND ${CMAKE_COMMAND} ${generatorOpts} .
  743. RESULT_VARIABLE result
  744. ${outputOptions}
  745. WORKING_DIRECTORY "${ARG_SUBBUILD_DIR}"
  746. )
  747. if(result)
  748. if(capturedOutput)
  749. message("${capturedOutput}")
  750. endif()
  751. message(FATAL_ERROR "CMake step for ${contentName} failed: ${result}")
  752. endif()
  753. execute_process(
  754. COMMAND ${CMAKE_COMMAND} --build .
  755. RESULT_VARIABLE result
  756. ${outputOptions}
  757. WORKING_DIRECTORY "${ARG_SUBBUILD_DIR}"
  758. )
  759. if(result)
  760. if(capturedOutput)
  761. message("${capturedOutput}")
  762. endif()
  763. message(FATAL_ERROR "Build step for ${contentName} failed: ${result}")
  764. endif()
  765. endfunction()
  766. option(FETCHCONTENT_FULLY_DISCONNECTED "Disables all attempts to download or update content and assumes source dirs already exist")
  767. option(FETCHCONTENT_UPDATES_DISCONNECTED "Enables UPDATE_DISCONNECTED behavior for all content population")
  768. option(FETCHCONTENT_QUIET "Enables QUIET option for all content population" ON)
  769. set(FETCHCONTENT_BASE_DIR "${CMAKE_BINARY_DIR}/_deps" CACHE PATH "Directory under which to collect all populated content")
  770. # Populate the specified content using details stored from
  771. # an earlier call to FetchContent_Declare().
  772. function(FetchContent_Populate contentName)
  773. if(NOT contentName)
  774. message(FATAL_ERROR "Empty contentName not allowed for FetchContent_Populate()")
  775. endif()
  776. string(TOLOWER ${contentName} contentNameLower)
  777. if(ARGN)
  778. # This is the direct population form with details fully specified
  779. # as part of the call, so we already have everything we need
  780. __FetchContent_directPopulate(
  781. ${contentNameLower}
  782. SUBBUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/${contentNameLower}-subbuild"
  783. SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/${contentNameLower}-src"
  784. BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/${contentNameLower}-build"
  785. ${ARGN} # Could override any of the above ..._DIR variables
  786. )
  787. # Pass source and binary dir variables back to the caller
  788. set(${contentNameLower}_SOURCE_DIR "${${contentNameLower}_SOURCE_DIR}" PARENT_SCOPE)
  789. set(${contentNameLower}_BINARY_DIR "${${contentNameLower}_BINARY_DIR}" PARENT_SCOPE)
  790. # Don't set global properties, or record that we did this population, since
  791. # this was a direct call outside of the normal declared details form.
  792. # We only want to save values in the global properties for content that
  793. # honours the hierarchical details mechanism so that projects are not
  794. # robbed of the ability to override details set in nested projects.
  795. return()
  796. endif()
  797. # No details provided, so assume they were saved from an earlier call
  798. # to FetchContent_Declare(). Do a check that we haven't already
  799. # populated this content before in case the caller forgot to check.
  800. FetchContent_GetProperties(${contentName})
  801. if(${contentNameLower}_POPULATED)
  802. message(FATAL_ERROR "Content ${contentName} already populated in ${${contentNameLower}_SOURCE_DIR}")
  803. endif()
  804. string(TOUPPER ${contentName} contentNameUpper)
  805. set(FETCHCONTENT_SOURCE_DIR_${contentNameUpper}
  806. "${FETCHCONTENT_SOURCE_DIR_${contentNameUpper}}"
  807. CACHE PATH "When not empty, overrides where to find pre-populated content for ${contentName}")
  808. if(FETCHCONTENT_SOURCE_DIR_${contentNameUpper})
  809. # The source directory has been explicitly provided in the cache,
  810. # so no population is required
  811. set(${contentNameLower}_SOURCE_DIR "${FETCHCONTENT_SOURCE_DIR_${contentNameUpper}}")
  812. set(${contentNameLower}_BINARY_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-build")
  813. elseif(FETCHCONTENT_FULLY_DISCONNECTED)
  814. # Bypass population and assume source is already there from a previous run
  815. set(${contentNameLower}_SOURCE_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-src")
  816. set(${contentNameLower}_BINARY_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-build")
  817. else()
  818. # Support both a global "disconnect all updates" and a per-content
  819. # update test (either one being set disables updates for this content).
  820. option(FETCHCONTENT_UPDATES_DISCONNECTED_${contentNameUpper}
  821. "Enables UPDATE_DISCONNECTED behavior just for population of ${contentName}")
  822. if(FETCHCONTENT_UPDATES_DISCONNECTED OR
  823. FETCHCONTENT_UPDATES_DISCONNECTED_${contentNameUpper})
  824. set(disconnectUpdates True)
  825. else()
  826. set(disconnectUpdates False)
  827. endif()
  828. if(FETCHCONTENT_QUIET)
  829. set(quietFlag QUIET)
  830. else()
  831. unset(quietFlag)
  832. endif()
  833. __FetchContent_getSavedDetails(${contentName} contentDetails)
  834. if("${contentDetails}" STREQUAL "")
  835. message(FATAL_ERROR "No details have been set for content: ${contentName}")
  836. endif()
  837. __FetchContent_directPopulate(
  838. ${contentNameLower}
  839. ${quietFlag}
  840. UPDATE_DISCONNECTED ${disconnectUpdates}
  841. SUBBUILD_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-subbuild"
  842. SOURCE_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-src"
  843. BINARY_DIR "${FETCHCONTENT_BASE_DIR}/${contentNameLower}-build"
  844. # Put the saved details last so they can override any of the
  845. # the options we set above (this can include SOURCE_DIR or
  846. # BUILD_DIR)
  847. ${contentDetails}
  848. )
  849. endif()
  850. __FetchContent_setPopulated(
  851. ${contentName}
  852. ${${contentNameLower}_SOURCE_DIR}
  853. ${${contentNameLower}_BINARY_DIR}
  854. )
  855. # Pass variables back to the caller. The variables passed back here
  856. # must match what FetchContent_GetProperties() sets when it is called
  857. # with just the content name.
  858. set(${contentNameLower}_SOURCE_DIR "${${contentNameLower}_SOURCE_DIR}" PARENT_SCOPE)
  859. set(${contentNameLower}_BINARY_DIR "${${contentNameLower}_BINARY_DIR}" PARENT_SCOPE)
  860. set(${contentNameLower}_POPULATED True PARENT_SCOPE)
  861. endfunction()
  862. # Arguments are assumed to be the names of dependencies that have been
  863. # declared previously and should be populated. It is not an error if
  864. # any of them have already been populated (they will just be skipped in
  865. # that case). The command is implemented as a macro so that the variables
  866. # defined by the FetchContent_GetProperties() and FetchContent_Populate()
  867. # calls will be available to the caller.
  868. macro(FetchContent_MakeAvailable)
  869. foreach(contentName IN ITEMS ${ARGV})
  870. string(TOLOWER ${contentName} contentNameLower)
  871. FetchContent_GetProperties(${contentName})
  872. if(NOT ${contentNameLower}_POPULATED)
  873. FetchContent_Populate(${contentName})
  874. # Only try to call add_subdirectory() if the populated content
  875. # can be treated that way. Protecting the call with the check
  876. # allows this function to be used for projects that just want
  877. # to ensure the content exists, such as to provide content at
  878. # a known location.
  879. if(EXISTS ${${contentNameLower}_SOURCE_DIR}/CMakeLists.txt)
  880. add_subdirectory(${${contentNameLower}_SOURCE_DIR}
  881. ${${contentNameLower}_BINARY_DIR})
  882. endif()
  883. endif()
  884. endforeach()
  885. endmacro()