ExternalProject.cmake 81 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452
  1. #[=======================================================================[.rst:
  2. ExternalProject
  3. ---------------
  4. Create custom targets to build projects in external trees
  5. .. command:: ExternalProject_Add
  6. The ``ExternalProject_Add`` function creates a custom target to drive
  7. download, update/patch, configure, build, install and test steps of an
  8. external project::
  9. ExternalProject_Add(<name> [<option>...])
  10. General options are:
  11. ``DEPENDS <projects>...``
  12. Targets on which the project depends
  13. ``PREFIX <dir>``
  14. Root dir for entire project
  15. ``LIST_SEPARATOR <sep>``
  16. Sep to be replaced by ; in cmd lines
  17. ``TMP_DIR <dir>``
  18. Directory to store temporary files
  19. ``STAMP_DIR <dir>``
  20. Directory to store step timestamps
  21. ``EXCLUDE_FROM_ALL 1``
  22. The "all" target does not depend on this
  23. Download step options are:
  24. ``DOWNLOAD_NAME <fname>``
  25. File name to store (if not end of URL)
  26. ``DOWNLOAD_DIR <dir>``
  27. Directory to store downloaded files
  28. ``DOWNLOAD_COMMAND <cmd>...``
  29. Command to download source tree
  30. ``DOWNLOAD_NO_PROGRESS 1``
  31. Disable download progress reports
  32. ``CVS_REPOSITORY <cvsroot>``
  33. CVSROOT of CVS repository
  34. ``CVS_MODULE <mod>``
  35. Module to checkout from CVS repo
  36. ``CVS_TAG <tag>``
  37. Tag to checkout from CVS repo
  38. ``SVN_REPOSITORY <url>``
  39. URL of Subversion repo
  40. ``SVN_REVISION -r<rev>``
  41. Revision to checkout from Subversion repo
  42. ``SVN_USERNAME <username>``
  43. Username for Subversion checkout and update
  44. ``SVN_PASSWORD <password>``
  45. Password for Subversion checkout and update
  46. ``SVN_TRUST_CERT 1``
  47. Trust the Subversion server site certificate
  48. ``GIT_REPOSITORY <url>``
  49. URL of git repo
  50. ``GIT_TAG <tag>``
  51. Git branch name, commit id or tag
  52. ``GIT_REMOTE_NAME <name>``
  53. The optional name of the remote, default to ``origin``
  54. ``GIT_SUBMODULES <module>...``
  55. Git submodules that shall be updated, all if empty
  56. ``HG_REPOSITORY <url>``
  57. URL of mercurial repo
  58. ``HG_TAG <tag>``
  59. Mercurial branch name, commit id or tag
  60. ``URL /.../src.tgz``
  61. Full path or URL of source
  62. ``URL_HASH ALGO=value``
  63. Hash of file at URL
  64. ``URL_MD5 md5``
  65. Equivalent to URL_HASH MD5=md5
  66. ``TLS_VERIFY <bool>``
  67. Should certificate for https be checked
  68. ``TLS_CAINFO <file>``
  69. Path to a certificate authority file
  70. ``TIMEOUT <seconds>``
  71. Time allowed for file download operations
  72. Update/Patch step options are:
  73. ``UPDATE_COMMAND <cmd>...``
  74. Source work-tree update command
  75. ``UPDATE_DISCONNECTED 1``
  76. Never update automatically from the remote repository
  77. ``PATCH_COMMAND <cmd>...``
  78. Command to patch downloaded source
  79. Configure step options are:
  80. ``SOURCE_DIR <dir>``
  81. Source dir to be used for build
  82. ``CONFIGURE_COMMAND <cmd>...``
  83. Build tree configuration command
  84. ``CMAKE_COMMAND /.../cmake``
  85. Specify alternative cmake executable
  86. ``CMAKE_GENERATOR <gen>``
  87. Specify generator for native build
  88. ``CMAKE_GENERATOR_PLATFORM <platform>``
  89. Generator-specific platform name
  90. ``CMAKE_GENERATOR_TOOLSET <toolset>``
  91. Generator-specific toolset name
  92. ``CMAKE_ARGS <arg>...``
  93. Arguments to CMake command line.
  94. These arguments are passed to CMake command line, and can contain
  95. arguments other than cache values, see also
  96. :manual:`CMake Options <cmake(1)>`. Arguments in the form
  97. ``-Dvar:string=on`` are always passed to the command line, and
  98. therefore cannot be changed by the user.
  99. Arguments may use
  100. :manual:`generator expressions <cmake-generator-expressions(7)>`.
  101. ``CMAKE_CACHE_ARGS <arg>...``
  102. Initial cache arguments, of the form ``-Dvar:string=on``.
  103. These arguments are written in a pre-load a script that populates
  104. CMake cache, see also :manual:`cmake -C <cmake(1)>`. This allows to
  105. overcome command line length limits.
  106. These arguments are :command:`set` using the ``FORCE`` argument,
  107. and therefore cannot be changed by the user.
  108. Arguments may use
  109. :manual:`generator expressions <cmake-generator-expressions(7)>`.
  110. ``CMAKE_CACHE_DEFAULT_ARGS <arg>...``
  111. Initial default cache arguments, of the form ``-Dvar:string=on``.
  112. These arguments are written in a pre-load a script that populates
  113. CMake cache, see also :manual:`cmake -C <cmake(1)>`. This allows to
  114. overcome command line length limits.
  115. These arguments can be used as default value that will be set if no
  116. previous value is found in the cache, and that the user can change
  117. later.
  118. Arguments may use
  119. :manual:`generator expressions <cmake-generator-expressions(7)>`.
  120. Build step options are:
  121. ``BINARY_DIR <dir>``
  122. Specify build dir location
  123. ``BUILD_COMMAND <cmd>...``
  124. Command to drive the native build
  125. ``BUILD_IN_SOURCE 1``
  126. Use source dir for build dir
  127. ``BUILD_ALWAYS 1``
  128. No stamp file, build step always runs
  129. ``BUILD_BYPRODUCTS <file>...``
  130. Files that will be generated by the build command but may or may
  131. not have their modification time updated by subsequent builds.
  132. Install step options are:
  133. ``INSTALL_DIR <dir>``
  134. Installation prefix
  135. ``INSTALL_COMMAND <cmd>...``
  136. Command to drive install after build
  137. Test step options are:
  138. ``TEST_BEFORE_INSTALL 1``
  139. Add test step executed before install step
  140. ``TEST_AFTER_INSTALL 1``
  141. Add test step executed after install step
  142. ``TEST_EXCLUDE_FROM_MAIN 1``
  143. Main target does not depend on the test step
  144. ``TEST_COMMAND <cmd>...``
  145. Command to drive test
  146. Output logging options are:
  147. ``LOG_DOWNLOAD 1``
  148. Wrap download in script to log output
  149. ``LOG_UPDATE 1``
  150. Wrap update in script to log output
  151. ``LOG_CONFIGURE 1``
  152. Wrap configure in script to log output
  153. ``LOG_BUILD 1``
  154. Wrap build in script to log output
  155. ``LOG_TEST 1``
  156. Wrap test in script to log output
  157. ``LOG_INSTALL 1``
  158. Wrap install in script to log output
  159. Steps can be given direct access to the terminal if possible. With
  160. the :generator:`Ninja` generator, this places the steps in the
  161. ``console`` :prop_gbl:`pool <JOB_POOLS>`. Options are:
  162. ``USES_TERMINAL_DOWNLOAD 1``
  163. Give download terminal access.
  164. ``USES_TERMINAL_UPDATE 1``
  165. Give update terminal access.
  166. ``USES_TERMINAL_CONFIGURE 1``
  167. Give configure terminal access.
  168. ``USES_TERMINAL_BUILD 1``
  169. Give build terminal access.
  170. ``USES_TERMINAL_TEST 1``
  171. Give test terminal access.
  172. ``USES_TERMINAL_INSTALL 1``
  173. Give install terminal access.
  174. Other options are:
  175. ``STEP_TARGETS <step-target>...``
  176. Generate custom targets for these steps
  177. ``INDEPENDENT_STEP_TARGETS <step-target>...``
  178. Generate custom targets for these steps that do not depend on other
  179. external projects even if a dependency is set
  180. The ``*_DIR`` options specify directories for the project, with default
  181. directories computed as follows. If the ``PREFIX`` option is given to
  182. ``ExternalProject_Add()`` or the ``EP_PREFIX`` directory property is set,
  183. then an external project is built and installed under the specified prefix::
  184. TMP_DIR = <prefix>/tmp
  185. STAMP_DIR = <prefix>/src/<name>-stamp
  186. DOWNLOAD_DIR = <prefix>/src
  187. SOURCE_DIR = <prefix>/src/<name>
  188. BINARY_DIR = <prefix>/src/<name>-build
  189. INSTALL_DIR = <prefix>
  190. Otherwise, if the ``EP_BASE`` directory property is set then components
  191. of an external project are stored under the specified base::
  192. TMP_DIR = <base>/tmp/<name>
  193. STAMP_DIR = <base>/Stamp/<name>
  194. DOWNLOAD_DIR = <base>/Download/<name>
  195. SOURCE_DIR = <base>/Source/<name>
  196. BINARY_DIR = <base>/Build/<name>
  197. INSTALL_DIR = <base>/Install/<name>
  198. If no ``PREFIX``, ``EP_PREFIX``, or ``EP_BASE`` is specified then the
  199. default is to set ``PREFIX`` to ``<name>-prefix``. Relative paths are
  200. interpreted with respect to the build directory corresponding to the
  201. source directory in which ``ExternalProject_Add`` is invoked.
  202. If ``SOURCE_DIR`` is explicitly set to an existing directory the project
  203. will be built from it. Otherwise a download step must be specified
  204. using one of the ``DOWNLOAD_COMMAND``, ``CVS_*``, ``SVN_*``, or ``URL``
  205. options. The ``URL`` option may refer locally to a directory or source
  206. tarball, or refer to a remote tarball (e.g. ``http://.../src.tgz``).
  207. If ``UPDATE_DISCONNECTED`` is set, the update step is not executed
  208. automatically when building the main target. The update step can still
  209. be added as a step target and called manually. This is useful if you
  210. want to allow to build the project when you are disconnected from the
  211. network (you might still need the network for the download step).
  212. This is disabled by default.
  213. The directory property ``EP_UPDATE_DISCONNECTED`` can be used to change
  214. the default value for all the external projects in the current
  215. directory and its subdirectories.
  216. .. command:: ExternalProject_Add_Step
  217. The ``ExternalProject_Add_Step`` function adds a custom step to an
  218. external project::
  219. ExternalProject_Add_Step(<name> <step> [<option>...])
  220. Options are:
  221. ``COMMAND <cmd>...``
  222. Command line invoked by this step
  223. ``COMMENT "<text>..."``
  224. Text printed when step executes
  225. ``DEPENDEES <step>...``
  226. Steps on which this step depends
  227. ``DEPENDERS <step>...``
  228. Steps that depend on this step
  229. ``DEPENDS <file>...``
  230. Files on which this step depends
  231. ``BYPRODUCTS <file>...``
  232. Files that will be generated by this step but may or may not
  233. have their modification time updated by subsequent builds.
  234. ``ALWAYS 1``
  235. No stamp file, step always runs
  236. ``EXCLUDE_FROM_MAIN 1``
  237. Main target does not depend on this step
  238. ``WORKING_DIRECTORY <dir>``
  239. Working directory for command
  240. ``LOG 1``
  241. Wrap step in script to log output
  242. ``USES_TERMINAL 1``
  243. Give the step direct access to the terminal if possible.
  244. The command line, comment, working directory, and byproducts of every
  245. standard and custom step are processed to replace tokens ``<SOURCE_DIR>``,
  246. ``<BINARY_DIR>``, ``<INSTALL_DIR>``, and ``<TMP_DIR>`` with
  247. corresponding property values.
  248. Any builtin step that specifies a ``<step>_COMMAND cmd...`` or custom
  249. step that specifies a ``COMMAND cmd...`` may specify additional command
  250. lines using the form ``COMMAND cmd...``. At build time the commands
  251. will be executed in order and aborted if any one fails. For example::
  252. ... BUILD_COMMAND make COMMAND echo done ...
  253. specifies to run ``make`` and then ``echo done`` during the build step.
  254. Whether the current working directory is preserved between commands is
  255. not defined. Behavior of shell operators like ``&&`` is not defined.
  256. Arguments to ``<step>_COMMAND`` or ``COMMAND`` options may use
  257. :manual:`generator expressions <cmake-generator-expressions(7)>`.
  258. .. command:: ExternalProject_Get_Property
  259. The ``ExternalProject_Get_Property`` function retrieves external project
  260. target properties::
  261. ExternalProject_Get_Property(<name> [prop1 [prop2 [...]]])
  262. It stores property values in variables of the same name. Property
  263. names correspond to the keyword argument names of
  264. ``ExternalProject_Add``.
  265. .. command:: ExternalProject_Add_StepTargets
  266. The ``ExternalProject_Add_StepTargets`` function generates custom
  267. targets for the steps listed::
  268. ExternalProject_Add_StepTargets(<name> [NO_DEPENDS] [step1 [step2 [...]]])
  269. If ``NO_DEPENDS`` is set, the target will not depend on the
  270. dependencies of the complete project. This is usually safe to use for
  271. the download, update, and patch steps that do not require that all the
  272. dependencies are updated and built. Using ``NO_DEPENDS`` for other
  273. of the default steps might break parallel builds, so you should avoid,
  274. it. For custom steps, you should consider whether or not the custom
  275. commands requires that the dependencies are configured, built and
  276. installed.
  277. If ``STEP_TARGETS`` or ``INDEPENDENT_STEP_TARGETS`` is set then
  278. ``ExternalProject_Add_StepTargets`` is automatically called at the end
  279. of matching calls to ``ExternalProject_Add_Step``. Pass
  280. ``STEP_TARGETS`` or ``INDEPENDENT_STEP_TARGETS`` explicitly to
  281. individual ``ExternalProject_Add`` calls, or implicitly to all
  282. ``ExternalProject_Add`` calls by setting the directory properties
  283. ``EP_STEP_TARGETS`` and ``EP_INDEPENDENT_STEP_TARGETS``. The
  284. ``INDEPENDENT`` version of the argument and of the property will call
  285. ``ExternalProject_Add_StepTargets`` with the ``NO_DEPENDS`` argument.
  286. If ``STEP_TARGETS`` and ``INDEPENDENT_STEP_TARGETS`` are not set,
  287. clients may still manually call ``ExternalProject_Add_StepTargets``
  288. after calling ``ExternalProject_Add`` or ``ExternalProject_Add_Step``.
  289. This functionality is provided to make it easy to drive the steps
  290. independently of each other by specifying targets on build command
  291. lines. For example, you may be submitting to a sub-project based
  292. dashboard, where you want to drive the configure portion of the build,
  293. then submit to the dashboard, followed by the build portion, followed
  294. by tests. If you invoke a custom target that depends on a step
  295. halfway through the step dependency chain, then all the previous steps
  296. will also run to ensure everything is up to date.
  297. For example, to drive configure, build and test steps independently
  298. for each ``ExternalProject_Add`` call in your project, write the following
  299. line prior to any ``ExternalProject_Add`` calls in your ``CMakeLists.txt``
  300. file::
  301. set_property(DIRECTORY PROPERTY EP_STEP_TARGETS configure build test)
  302. .. command:: ExternalProject_Add_StepDependencies
  303. The ``ExternalProject_Add_StepDependencies`` function add some
  304. dependencies for some external project step::
  305. ExternalProject_Add_StepDependencies(<name> <step> [target1 [target2 [...]]])
  306. This function takes care to set both target and file level
  307. dependencies, and will ensure that parallel builds will not break.
  308. It should be used instead of :command:`add_dependencies()` when adding
  309. a dependency for some of the step targets generated by
  310. ``ExternalProject``.
  311. #]=======================================================================]
  312. #=============================================================================
  313. # Copyright 2008-2013 Kitware, Inc.
  314. #
  315. # Distributed under the OSI-approved BSD License (the "License");
  316. # see accompanying file Copyright.txt for details.
  317. #
  318. # This software is distributed WITHOUT ANY WARRANTY; without even the
  319. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  320. # See the License for more information.
  321. #=============================================================================
  322. # (To distribute this file outside of CMake, substitute the full
  323. # License text for the above reference.)
  324. # Pre-compute a regex to match documented keywords for each command.
  325. math(EXPR _ep_documentation_line_count "${CMAKE_CURRENT_LIST_LINE} - 16")
  326. file(STRINGS "${CMAKE_CURRENT_LIST_FILE}" lines
  327. LIMIT_COUNT ${_ep_documentation_line_count}
  328. REGEX "^\\.\\. command:: [A-Za-z0-9_]+|^ ``[A-Z0-9_]+ .*``$")
  329. foreach(line IN LISTS lines)
  330. if("${line}" MATCHES "^\\.\\. command:: ([A-Za-z0-9_]+)")
  331. if(_ep_func)
  332. set(_ep_keywords_${_ep_func} "${_ep_keywords_${_ep_func}})$")
  333. endif()
  334. set(_ep_func "${CMAKE_MATCH_1}")
  335. #message("function [${_ep_func}]")
  336. set(_ep_keywords_${_ep_func} "^(")
  337. set(_ep_keyword_sep)
  338. elseif("${line}" MATCHES "^ ``([A-Z0-9_]+) .*``$")
  339. set(_ep_key "${CMAKE_MATCH_1}")
  340. #message(" keyword [${_ep_key}]")
  341. set(_ep_keywords_${_ep_func}
  342. "${_ep_keywords_${_ep_func}}${_ep_keyword_sep}${_ep_key}")
  343. set(_ep_keyword_sep "|")
  344. endif()
  345. endforeach()
  346. if(_ep_func)
  347. set(_ep_keywords_${_ep_func} "${_ep_keywords_${_ep_func}})$")
  348. endif()
  349. # Save regex matching supported hash algorithm names.
  350. set(_ep_hash_algos "MD5|SHA1|SHA224|SHA256|SHA384|SHA512")
  351. set(_ep_hash_regex "^(${_ep_hash_algos})=([0-9A-Fa-f]+)$")
  352. function(_ep_parse_arguments f name ns args)
  353. # Transfer the arguments to this function into target properties for the
  354. # new custom target we just added so that we can set up all the build steps
  355. # correctly based on target properties.
  356. #
  357. # We loop through ARGN and consider the namespace starting with an
  358. # upper-case letter followed by at least two more upper-case letters,
  359. # numbers or underscores to be keywords.
  360. set(key)
  361. foreach(arg IN LISTS args)
  362. set(is_value 1)
  363. if(arg MATCHES "^[A-Z][A-Z0-9_][A-Z0-9_]+$" AND
  364. NOT (("x${arg}x" STREQUAL "x${key}x") AND ("x${key}x" STREQUAL "xCOMMANDx")) AND
  365. NOT arg MATCHES "^(TRUE|FALSE)$")
  366. if(_ep_keywords_${f} AND arg MATCHES "${_ep_keywords_${f}}")
  367. set(is_value 0)
  368. endif()
  369. endif()
  370. if(is_value)
  371. if(key)
  372. # Value
  373. if(NOT arg STREQUAL "")
  374. set_property(TARGET ${name} APPEND PROPERTY ${ns}${key} "${arg}")
  375. else()
  376. get_property(have_key TARGET ${name} PROPERTY ${ns}${key} SET)
  377. if(have_key)
  378. get_property(value TARGET ${name} PROPERTY ${ns}${key})
  379. set_property(TARGET ${name} PROPERTY ${ns}${key} "${value};${arg}")
  380. else()
  381. set_property(TARGET ${name} PROPERTY ${ns}${key} "${arg}")
  382. endif()
  383. endif()
  384. else()
  385. # Missing Keyword
  386. message(AUTHOR_WARNING "value '${arg}' with no previous keyword in ${f}")
  387. endif()
  388. else()
  389. set(key "${arg}")
  390. endif()
  391. endforeach()
  392. endfunction()
  393. define_property(DIRECTORY PROPERTY "EP_BASE" INHERITED
  394. BRIEF_DOCS "Base directory for External Project storage."
  395. FULL_DOCS
  396. "See documentation of the ExternalProject_Add() function in the "
  397. "ExternalProject module."
  398. )
  399. define_property(DIRECTORY PROPERTY "EP_PREFIX" INHERITED
  400. BRIEF_DOCS "Top prefix for External Project storage."
  401. FULL_DOCS
  402. "See documentation of the ExternalProject_Add() function in the "
  403. "ExternalProject module."
  404. )
  405. define_property(DIRECTORY PROPERTY "EP_STEP_TARGETS" INHERITED
  406. BRIEF_DOCS
  407. "List of ExternalProject steps that automatically get corresponding targets"
  408. FULL_DOCS
  409. "These targets will be dependent on the main target dependencies"
  410. "See documentation of the ExternalProject_Add_StepTargets() function in the "
  411. "ExternalProject module."
  412. )
  413. define_property(DIRECTORY PROPERTY "EP_INDEPENDENT_STEP_TARGETS" INHERITED
  414. BRIEF_DOCS
  415. "List of ExternalProject steps that automatically get corresponding targets"
  416. FULL_DOCS
  417. "These targets will not be dependent on the main target dependencies"
  418. "See documentation of the ExternalProject_Add_StepTargets() function in the "
  419. "ExternalProject module."
  420. )
  421. define_property(DIRECTORY PROPERTY "EP_UPDATE_DISCONNECTED" INHERITED
  422. BRIEF_DOCS "Never update automatically from the remote repo."
  423. FULL_DOCS
  424. "See documentation of the ExternalProject_Add() function in the "
  425. "ExternalProject module."
  426. )
  427. function(_ep_write_gitclone_script script_filename source_dir git_EXECUTABLE git_repository git_tag git_remote_name git_submodules src_name work_dir gitclone_infofile gitclone_stampfile)
  428. file(WRITE ${script_filename}
  429. "if(\"${git_tag}\" STREQUAL \"\")
  430. message(FATAL_ERROR \"Tag for git checkout should not be empty.\")
  431. endif()
  432. set(run 0)
  433. if(\"${gitclone_infofile}\" IS_NEWER_THAN \"${gitclone_stampfile}\")
  434. set(run 1)
  435. endif()
  436. if(NOT run)
  437. message(STATUS \"Avoiding repeated git clone, stamp file is up to date: '${gitclone_stampfile}'\")
  438. return()
  439. endif()
  440. execute_process(
  441. COMMAND \${CMAKE_COMMAND} -E remove_directory \"${source_dir}\"
  442. RESULT_VARIABLE error_code
  443. )
  444. if(error_code)
  445. message(FATAL_ERROR \"Failed to remove directory: '${source_dir}'\")
  446. endif()
  447. # try the clone 3 times incase there is an odd git clone issue
  448. set(error_code 1)
  449. set(number_of_tries 0)
  450. while(error_code AND number_of_tries LESS 3)
  451. execute_process(
  452. COMMAND \"${git_EXECUTABLE}\" clone --origin \"${git_remote_name}\" \"${git_repository}\" \"${src_name}\"
  453. WORKING_DIRECTORY \"${work_dir}\"
  454. RESULT_VARIABLE error_code
  455. )
  456. math(EXPR number_of_tries \"\${number_of_tries} + 1\")
  457. endwhile()
  458. if(number_of_tries GREATER 1)
  459. message(STATUS \"Had to git clone more than once:
  460. \${number_of_tries} times.\")
  461. endif()
  462. if(error_code)
  463. message(FATAL_ERROR \"Failed to clone repository: '${git_repository}'\")
  464. endif()
  465. execute_process(
  466. COMMAND \"${git_EXECUTABLE}\" checkout ${git_tag}
  467. WORKING_DIRECTORY \"${work_dir}/${src_name}\"
  468. RESULT_VARIABLE error_code
  469. )
  470. if(error_code)
  471. message(FATAL_ERROR \"Failed to checkout tag: '${git_tag}'\")
  472. endif()
  473. execute_process(
  474. COMMAND \"${git_EXECUTABLE}\" submodule init ${git_submodules}
  475. WORKING_DIRECTORY \"${work_dir}/${src_name}\"
  476. RESULT_VARIABLE error_code
  477. )
  478. if(error_code)
  479. message(FATAL_ERROR \"Failed to init submodules in: '${work_dir}/${src_name}'\")
  480. endif()
  481. execute_process(
  482. COMMAND \"${git_EXECUTABLE}\" submodule update --recursive ${git_submodules}
  483. WORKING_DIRECTORY \"${work_dir}/${src_name}\"
  484. RESULT_VARIABLE error_code
  485. )
  486. if(error_code)
  487. message(FATAL_ERROR \"Failed to update submodules in: '${work_dir}/${src_name}'\")
  488. endif()
  489. # Complete success, update the script-last-run stamp file:
  490. #
  491. execute_process(
  492. COMMAND \${CMAKE_COMMAND} -E copy
  493. \"${gitclone_infofile}\"
  494. \"${gitclone_stampfile}\"
  495. WORKING_DIRECTORY \"${work_dir}/${src_name}\"
  496. RESULT_VARIABLE error_code
  497. )
  498. if(error_code)
  499. message(FATAL_ERROR \"Failed to copy script-last-run stamp file: '${gitclone_stampfile}'\")
  500. endif()
  501. "
  502. )
  503. endfunction()
  504. function(_ep_write_hgclone_script script_filename source_dir hg_EXECUTABLE hg_repository hg_tag src_name work_dir hgclone_infofile hgclone_stampfile)
  505. file(WRITE ${script_filename}
  506. "if(\"${hg_tag}\" STREQUAL \"\")
  507. message(FATAL_ERROR \"Tag for hg checkout should not be empty.\")
  508. endif()
  509. set(run 0)
  510. if(\"${hgclone_infofile}\" IS_NEWER_THAN \"${hgclone_stampfile}\")
  511. set(run 1)
  512. endif()
  513. if(NOT run)
  514. message(STATUS \"Avoiding repeated hg clone, stamp file is up to date: '${hgclone_stampfile}'\")
  515. return()
  516. endif()
  517. execute_process(
  518. COMMAND \${CMAKE_COMMAND} -E remove_directory \"${source_dir}\"
  519. RESULT_VARIABLE error_code
  520. )
  521. if(error_code)
  522. message(FATAL_ERROR \"Failed to remove directory: '${source_dir}'\")
  523. endif()
  524. execute_process(
  525. COMMAND \"${hg_EXECUTABLE}\" clone -U \"${hg_repository}\" \"${src_name}\"
  526. WORKING_DIRECTORY \"${work_dir}\"
  527. RESULT_VARIABLE error_code
  528. )
  529. if(error_code)
  530. message(FATAL_ERROR \"Failed to clone repository: '${hg_repository}'\")
  531. endif()
  532. execute_process(
  533. COMMAND \"${hg_EXECUTABLE}\" update ${hg_tag}
  534. WORKING_DIRECTORY \"${work_dir}/${src_name}\"
  535. RESULT_VARIABLE error_code
  536. )
  537. if(error_code)
  538. message(FATAL_ERROR \"Failed to checkout tag: '${hg_tag}'\")
  539. endif()
  540. # Complete success, update the script-last-run stamp file:
  541. #
  542. execute_process(
  543. COMMAND \${CMAKE_COMMAND} -E copy
  544. \"${hgclone_infofile}\"
  545. \"${hgclone_stampfile}\"
  546. WORKING_DIRECTORY \"${work_dir}/${src_name}\"
  547. RESULT_VARIABLE error_code
  548. )
  549. if(error_code)
  550. message(FATAL_ERROR \"Failed to copy script-last-run stamp file: '${hgclone_stampfile}'\")
  551. endif()
  552. "
  553. )
  554. endfunction()
  555. function(_ep_write_gitupdate_script script_filename git_EXECUTABLE git_tag git_remote_name git_submodules git_repository work_dir)
  556. if(NOT GIT_VERSION_STRING VERSION_LESS 1.7.6)
  557. set(git_stash_save_options --all --quiet)
  558. else()
  559. set(git_stash_save_options --quiet)
  560. endif()
  561. file(WRITE ${script_filename}
  562. "if(\"${git_tag}\" STREQUAL \"\")
  563. message(FATAL_ERROR \"Tag for git checkout should not be empty.\")
  564. endif()
  565. execute_process(
  566. COMMAND \"${git_EXECUTABLE}\" rev-list --max-count=1 HEAD
  567. WORKING_DIRECTORY \"${work_dir}\"
  568. RESULT_VARIABLE error_code
  569. OUTPUT_VARIABLE head_sha
  570. OUTPUT_STRIP_TRAILING_WHITESPACE
  571. )
  572. if(error_code)
  573. message(FATAL_ERROR \"Failed to get the hash for HEAD\")
  574. endif()
  575. execute_process(
  576. COMMAND \"${git_EXECUTABLE}\" show-ref ${git_tag}
  577. WORKING_DIRECTORY \"${work_dir}\"
  578. OUTPUT_VARIABLE show_ref_output
  579. )
  580. # If a remote ref is asked for, which can possibly move around,
  581. # we must always do a fetch and checkout.
  582. if(\"\${show_ref_output}\" MATCHES \"remotes\")
  583. set(is_remote_ref 1)
  584. else()
  585. set(is_remote_ref 0)
  586. endif()
  587. # Tag is in the form <remote>/<tag> (i.e. origin/master) we must strip
  588. # the remote from the tag.
  589. if(\"\${show_ref_output}\" MATCHES \"refs/remotes/${git_tag}\")
  590. string(REGEX MATCH \"^([^/]+)/(.+)$\" _unused \"${git_tag}\")
  591. set(git_remote \"\${CMAKE_MATCH_1}\")
  592. set(git_tag \"\${CMAKE_MATCH_2}\")
  593. else()
  594. set(git_remote \"${git_remote_name}\")
  595. set(git_tag \"${git_tag}\")
  596. endif()
  597. # This will fail if the tag does not exist (it probably has not been fetched
  598. # yet).
  599. execute_process(
  600. COMMAND \"${git_EXECUTABLE}\" rev-list --max-count=1 ${git_tag}
  601. WORKING_DIRECTORY \"${work_dir}\"
  602. RESULT_VARIABLE error_code
  603. OUTPUT_VARIABLE tag_sha
  604. OUTPUT_STRIP_TRAILING_WHITESPACE
  605. )
  606. # Is the hash checkout out that we want?
  607. if(error_code OR is_remote_ref OR NOT (\"\${tag_sha}\" STREQUAL \"\${head_sha}\"))
  608. execute_process(
  609. COMMAND \"${git_EXECUTABLE}\" fetch
  610. WORKING_DIRECTORY \"${work_dir}\"
  611. RESULT_VARIABLE error_code
  612. )
  613. if(error_code)
  614. message(FATAL_ERROR \"Failed to fetch repository '${git_repository}'\")
  615. endif()
  616. if(is_remote_ref)
  617. # Check if stash is needed
  618. execute_process(
  619. COMMAND \"${git_EXECUTABLE}\" status --porcelain
  620. WORKING_DIRECTORY \"${work_dir}\"
  621. RESULT_VARIABLE error_code
  622. OUTPUT_VARIABLE repo_status
  623. )
  624. if(error_code)
  625. message(FATAL_ERROR \"Failed to get the status\")
  626. endif()
  627. string(LENGTH \"\${repo_status}\" need_stash)
  628. # If not in clean state, stash changes in order to be able to be able to
  629. # perform git pull --rebase
  630. if(need_stash)
  631. execute_process(
  632. COMMAND \"${git_EXECUTABLE}\" stash save ${git_stash_save_options}
  633. WORKING_DIRECTORY \"${work_dir}\"
  634. RESULT_VARIABLE error_code
  635. )
  636. if(error_code)
  637. message(FATAL_ERROR \"Failed to stash changes\")
  638. endif()
  639. endif()
  640. # Pull changes from the remote branch
  641. execute_process(
  642. COMMAND \"${git_EXECUTABLE}\" rebase \${git_remote}/\${git_tag}
  643. WORKING_DIRECTORY \"${work_dir}\"
  644. RESULT_VARIABLE error_code
  645. )
  646. if(error_code)
  647. # Rebase failed: Restore previous state.
  648. execute_process(
  649. COMMAND \"${git_EXECUTABLE}\" rebase --abort
  650. WORKING_DIRECTORY \"${work_dir}\"
  651. )
  652. if(need_stash)
  653. execute_process(
  654. COMMAND \"${git_EXECUTABLE}\" stash pop --index --quiet
  655. WORKING_DIRECTORY \"${work_dir}\"
  656. )
  657. endif()
  658. message(FATAL_ERROR \"\\nFailed to rebase in: '${work_dir}/${src_name}'.\\nYou will have to resolve the conflicts manually\")
  659. endif()
  660. if(need_stash)
  661. execute_process(
  662. COMMAND \"${git_EXECUTABLE}\" stash pop --index --quiet
  663. WORKING_DIRECTORY \"${work_dir}\"
  664. RESULT_VARIABLE error_code
  665. )
  666. if(error_code)
  667. # Stash pop --index failed: Try again dropping the index
  668. execute_process(
  669. COMMAND \"${git_EXECUTABLE}\" reset --hard --quiet
  670. WORKING_DIRECTORY \"${work_dir}\"
  671. RESULT_VARIABLE error_code
  672. )
  673. execute_process(
  674. COMMAND \"${git_EXECUTABLE}\" stash pop --quiet
  675. WORKING_DIRECTORY \"${work_dir}\"
  676. RESULT_VARIABLE error_code
  677. )
  678. if(error_code)
  679. # Stash pop failed: Restore previous state.
  680. execute_process(
  681. COMMAND \"${git_EXECUTABLE}\" reset --hard --quiet \${head_sha}
  682. WORKING_DIRECTORY \"${work_dir}\"
  683. )
  684. execute_process(
  685. COMMAND \"${git_EXECUTABLE}\" stash pop --index --quiet
  686. WORKING_DIRECTORY \"${work_dir}\"
  687. )
  688. message(FATAL_ERROR \"\\nFailed to unstash changes in: '${work_dir}/${src_name}'.\\nYou will have to resolve the conflicts manually\")
  689. endif()
  690. endif()
  691. endif()
  692. else()
  693. execute_process(
  694. COMMAND \"${git_EXECUTABLE}\" checkout ${git_tag}
  695. WORKING_DIRECTORY \"${work_dir}\"
  696. RESULT_VARIABLE error_code
  697. )
  698. if(error_code)
  699. message(FATAL_ERROR \"Failed to checkout tag: '${git_tag}'\")
  700. endif()
  701. endif()
  702. execute_process(
  703. COMMAND \"${git_EXECUTABLE}\" submodule update --recursive ${git_submodules}
  704. WORKING_DIRECTORY \"${work_dir}/${src_name}\"
  705. RESULT_VARIABLE error_code
  706. )
  707. if(error_code)
  708. message(FATAL_ERROR \"Failed to update submodules in: '${work_dir}/${src_name}'\")
  709. endif()
  710. endif()
  711. "
  712. )
  713. endfunction(_ep_write_gitupdate_script)
  714. function(_ep_write_downloadfile_script script_filename remote local timeout no_progress hash tls_verify tls_cainfo)
  715. if(timeout)
  716. set(timeout_args TIMEOUT ${timeout})
  717. set(timeout_msg "${timeout} seconds")
  718. else()
  719. set(timeout_args "# no TIMEOUT")
  720. set(timeout_msg "none")
  721. endif()
  722. if(no_progress)
  723. set(show_progress "")
  724. else()
  725. set(show_progress "SHOW_PROGRESS")
  726. endif()
  727. if("${hash}" MATCHES "${_ep_hash_regex}")
  728. string(CONCAT hash_check
  729. "if(EXISTS \"${local}\")\n"
  730. " file(\"${CMAKE_MATCH_1}\" \"${local}\" hash_value)\n"
  731. " if(\"x\${hash_value}\" STREQUAL \"x${CMAKE_MATCH_2}\")\n"
  732. " return()\n"
  733. " endif()\n"
  734. "endif()\n"
  735. )
  736. else()
  737. set(hash_check "")
  738. endif()
  739. # check for curl globals in the project
  740. if(DEFINED CMAKE_TLS_VERIFY)
  741. set(tls_verify "set(CMAKE_TLS_VERIFY ${CMAKE_TLS_VERIFY})")
  742. endif()
  743. if(DEFINED CMAKE_TLS_CAINFO)
  744. set(tls_cainfo "set(CMAKE_TLS_CAINFO \"${CMAKE_TLS_CAINFO}\")")
  745. endif()
  746. # now check for curl locals so that the local values
  747. # will override the globals
  748. # check for tls_verify argument
  749. string(LENGTH "${tls_verify}" tls_verify_len)
  750. if(tls_verify_len GREATER 0)
  751. set(tls_verify "set(CMAKE_TLS_VERIFY ${tls_verify})")
  752. endif()
  753. # check for tls_cainfo argument
  754. string(LENGTH "${tls_cainfo}" tls_cainfo_len)
  755. if(tls_cainfo_len GREATER 0)
  756. set(tls_cainfo "set(CMAKE_TLS_CAINFO \"${tls_cainfo}\")")
  757. endif()
  758. file(WRITE ${script_filename}
  759. "${hash_check}message(STATUS \"downloading...
  760. src='${remote}'
  761. dst='${local}'
  762. timeout='${timeout_msg}'\")
  763. ${tls_verify}
  764. ${tls_cainfo}
  765. file(DOWNLOAD
  766. \"${remote}\"
  767. \"${local}\"
  768. ${show_progress}
  769. ${timeout_args}
  770. STATUS status
  771. LOG log)
  772. list(GET status 0 status_code)
  773. list(GET status 1 status_string)
  774. if(NOT status_code EQUAL 0)
  775. message(FATAL_ERROR \"error: downloading '${remote}' failed
  776. status_code: \${status_code}
  777. status_string: \${status_string}
  778. log: \${log}
  779. \")
  780. endif()
  781. message(STATUS \"downloading... done\")
  782. "
  783. )
  784. endfunction()
  785. function(_ep_write_verifyfile_script script_filename local hash retries download_script)
  786. if("${hash}" MATCHES "${_ep_hash_regex}")
  787. set(algo "${CMAKE_MATCH_1}")
  788. string(TOLOWER "${CMAKE_MATCH_2}" expect_value)
  789. set(script_content "set(expect_value \"${expect_value}\")
  790. set(attempt 0)
  791. set(succeeded 0)
  792. while(\${attempt} LESS ${retries} OR \${attempt} EQUAL ${retries} AND NOT \${succeeded})
  793. file(${algo} \"\${file}\" actual_value)
  794. if(\"\${actual_value}\" STREQUAL \"\${expect_value}\")
  795. set(succeeded 1)
  796. elseif(\${attempt} LESS ${retries})
  797. message(STATUS \"${algo} hash of \${file}
  798. does not match expected value
  799. expected: \${expect_value}
  800. actual: \${actual_value}
  801. Retrying download.
  802. \")
  803. file(REMOVE \"\${file}\")
  804. execute_process(COMMAND \${CMAKE_COMMAND} -P \"${download_script}\")
  805. endif()
  806. math(EXPR attempt \"\${attempt} + 1\")
  807. endwhile()
  808. if(\${succeeded})
  809. message(STATUS \"verifying file... done\")
  810. else()
  811. message(FATAL_ERROR \"error: ${algo} hash of
  812. \${file}
  813. does not match expected value
  814. expected: \${expect_value}
  815. actual: \${actual_value}
  816. \")
  817. endif()")
  818. else()
  819. set(script_content "message(STATUS \"verifying file... warning: did not verify file - no URL_HASH specified?\")")
  820. endif()
  821. file(WRITE ${script_filename} "set(file \"${local}\")
  822. message(STATUS \"verifying file...
  823. file='\${file}'\")
  824. ${script_content}
  825. ")
  826. endfunction()
  827. function(_ep_write_extractfile_script script_filename name filename directory)
  828. set(args "")
  829. if(filename MATCHES "(\\.|=)(7z|tar\\.bz2|tar\\.gz|tar\\.xz|tbz2|tgz|txz|zip)$")
  830. set(args xfz)
  831. endif()
  832. if(filename MATCHES "(\\.|=)tar$")
  833. set(args xf)
  834. endif()
  835. if(args STREQUAL "")
  836. message(SEND_ERROR "error: do not know how to extract '${filename}' -- known types are .7z, .tar, .tar.bz2, .tar.gz, .tar.xz, .tbz2, .tgz, .txz and .zip")
  837. return()
  838. endif()
  839. file(WRITE ${script_filename}
  840. "# Make file names absolute:
  841. #
  842. get_filename_component(filename \"${filename}\" ABSOLUTE)
  843. get_filename_component(directory \"${directory}\" ABSOLUTE)
  844. message(STATUS \"extracting...
  845. src='\${filename}'
  846. dst='\${directory}'\")
  847. if(NOT EXISTS \"\${filename}\")
  848. message(FATAL_ERROR \"error: file to extract does not exist: '\${filename}'\")
  849. endif()
  850. # Prepare a space for extracting:
  851. #
  852. set(i 1234)
  853. while(EXISTS \"\${directory}/../ex-${name}\${i}\")
  854. math(EXPR i \"\${i} + 1\")
  855. endwhile()
  856. set(ut_dir \"\${directory}/../ex-${name}\${i}\")
  857. file(MAKE_DIRECTORY \"\${ut_dir}\")
  858. # Extract it:
  859. #
  860. message(STATUS \"extracting... [tar ${args}]\")
  861. execute_process(COMMAND \${CMAKE_COMMAND} -E tar ${args} \${filename}
  862. WORKING_DIRECTORY \${ut_dir}
  863. RESULT_VARIABLE rv)
  864. if(NOT rv EQUAL 0)
  865. message(STATUS \"extracting... [error clean up]\")
  866. file(REMOVE_RECURSE \"\${ut_dir}\")
  867. message(FATAL_ERROR \"error: extract of '\${filename}' failed\")
  868. endif()
  869. # Analyze what came out of the tar file:
  870. #
  871. message(STATUS \"extracting... [analysis]\")
  872. file(GLOB contents \"\${ut_dir}/*\")
  873. list(LENGTH contents n)
  874. if(NOT n EQUAL 1 OR NOT IS_DIRECTORY \"\${contents}\")
  875. set(contents \"\${ut_dir}\")
  876. endif()
  877. # Move \"the one\" directory to the final directory:
  878. #
  879. message(STATUS \"extracting... [rename]\")
  880. file(REMOVE_RECURSE \${directory})
  881. get_filename_component(contents \${contents} ABSOLUTE)
  882. file(RENAME \${contents} \${directory})
  883. # Clean up:
  884. #
  885. message(STATUS \"extracting... [clean up]\")
  886. file(REMOVE_RECURSE \"\${ut_dir}\")
  887. message(STATUS \"extracting... done\")
  888. "
  889. )
  890. endfunction()
  891. function(_ep_set_directories name)
  892. get_property(prefix TARGET ${name} PROPERTY _EP_PREFIX)
  893. if(NOT prefix)
  894. get_property(prefix DIRECTORY PROPERTY EP_PREFIX)
  895. if(NOT prefix)
  896. get_property(base DIRECTORY PROPERTY EP_BASE)
  897. if(NOT base)
  898. set(prefix "${name}-prefix")
  899. endif()
  900. endif()
  901. endif()
  902. if(prefix)
  903. set(tmp_default "${prefix}/tmp")
  904. set(download_default "${prefix}/src")
  905. set(source_default "${prefix}/src/${name}")
  906. set(binary_default "${prefix}/src/${name}-build")
  907. set(stamp_default "${prefix}/src/${name}-stamp")
  908. set(install_default "${prefix}")
  909. else()
  910. set(tmp_default "${base}/tmp/${name}")
  911. set(download_default "${base}/Download/${name}")
  912. set(source_default "${base}/Source/${name}")
  913. set(binary_default "${base}/Build/${name}")
  914. set(stamp_default "${base}/Stamp/${name}")
  915. set(install_default "${base}/Install/${name}")
  916. endif()
  917. get_property(build_in_source TARGET ${name} PROPERTY _EP_BUILD_IN_SOURCE)
  918. if(build_in_source)
  919. get_property(have_binary_dir TARGET ${name} PROPERTY _EP_BINARY_DIR SET)
  920. if(have_binary_dir)
  921. message(FATAL_ERROR
  922. "External project ${name} has both BINARY_DIR and BUILD_IN_SOURCE!")
  923. endif()
  924. endif()
  925. set(top "${CMAKE_CURRENT_BINARY_DIR}")
  926. set(places stamp download source binary install tmp)
  927. foreach(var ${places})
  928. string(TOUPPER "${var}" VAR)
  929. get_property(${var}_dir TARGET ${name} PROPERTY _EP_${VAR}_DIR)
  930. if(NOT ${var}_dir)
  931. set(${var}_dir "${${var}_default}")
  932. endif()
  933. if(NOT IS_ABSOLUTE "${${var}_dir}")
  934. get_filename_component(${var}_dir "${top}/${${var}_dir}" ABSOLUTE)
  935. endif()
  936. set_property(TARGET ${name} PROPERTY _EP_${VAR}_DIR "${${var}_dir}")
  937. endforeach()
  938. if(build_in_source)
  939. get_property(source_dir TARGET ${name} PROPERTY _EP_SOURCE_DIR)
  940. set_property(TARGET ${name} PROPERTY _EP_BINARY_DIR "${source_dir}")
  941. endif()
  942. # Make the directories at CMake configure time *and* add a custom command
  943. # to make them at build time. They need to exist at makefile generation
  944. # time for Borland make and wmake so that CMake may generate makefiles
  945. # with "cd C:\short\paths\with\no\spaces" commands in them.
  946. #
  947. # Additionally, the add_custom_command is still used in case somebody
  948. # removes one of the necessary directories and tries to rebuild without
  949. # re-running cmake.
  950. foreach(var ${places})
  951. string(TOUPPER "${var}" VAR)
  952. get_property(dir TARGET ${name} PROPERTY _EP_${VAR}_DIR)
  953. file(MAKE_DIRECTORY "${dir}")
  954. if(NOT EXISTS "${dir}")
  955. message(FATAL_ERROR "dir '${dir}' does not exist after file(MAKE_DIRECTORY)")
  956. endif()
  957. endforeach()
  958. endfunction()
  959. # IMPORTANT: this MUST be a macro and not a function because of the
  960. # in-place replacements that occur in each ${var}
  961. #
  962. macro(_ep_replace_location_tags target_name)
  963. set(vars ${ARGN})
  964. foreach(var ${vars})
  965. if(${var})
  966. foreach(dir SOURCE_DIR BINARY_DIR INSTALL_DIR TMP_DIR)
  967. get_property(val TARGET ${target_name} PROPERTY _EP_${dir})
  968. string(REPLACE "<${dir}>" "${val}" ${var} "${${var}}")
  969. endforeach()
  970. endif()
  971. endforeach()
  972. endmacro()
  973. function(_ep_command_line_to_initial_cache var args force)
  974. set(script_initial_cache "")
  975. set(regex "^([^:]+):([^=]+)=(.*)$")
  976. set(setArg "")
  977. set(forceArg "")
  978. if(force)
  979. set(forceArg "FORCE")
  980. endif()
  981. foreach(line ${args})
  982. if("${line}" MATCHES "^-D(.*)")
  983. set(line "${CMAKE_MATCH_1}")
  984. if(setArg)
  985. # This is required to build up lists in variables, or complete an entry
  986. set(setArg "${setArg}${accumulator}\" CACHE ${type} \"Initial cache\" ${forceArg})")
  987. set(script_initial_cache "${script_initial_cache}\n${setArg}")
  988. set(accumulator "")
  989. set(setArg "")
  990. endif()
  991. if("${line}" MATCHES "${regex}")
  992. set(name "${CMAKE_MATCH_1}")
  993. set(type "${CMAKE_MATCH_2}")
  994. set(value "${CMAKE_MATCH_3}")
  995. set(setArg "set(${name} \"${value}")
  996. else()
  997. message(WARNING "Line '${line}' does not match regex. Ignoring.")
  998. endif()
  999. else()
  1000. # Assume this is a list to append to the last var
  1001. set(accumulator "${accumulator};${line}")
  1002. endif()
  1003. endforeach()
  1004. # Catch the final line of the args
  1005. if(setArg)
  1006. set(setArg "${setArg}${accumulator}\" CACHE ${type} \"Initial cache\" ${forceArg})")
  1007. set(script_initial_cache "${script_initial_cache}\n${setArg}")
  1008. endif()
  1009. set(${var} ${script_initial_cache} PARENT_SCOPE)
  1010. endfunction()
  1011. function(_ep_write_initial_cache target_name script_filename script_initial_cache)
  1012. # Write out values into an initial cache, that will be passed to CMake with -C
  1013. # Replace location tags.
  1014. _ep_replace_location_tags(${target_name} script_initial_cache)
  1015. # Write out the initial cache file to the location specified.
  1016. file(GENERATE OUTPUT "${script_filename}" CONTENT "${script_initial_cache}")
  1017. endfunction()
  1018. function(ExternalProject_Get_Property name)
  1019. foreach(var ${ARGN})
  1020. string(TOUPPER "${var}" VAR)
  1021. get_property(${var} TARGET ${name} PROPERTY _EP_${VAR})
  1022. if(NOT ${var})
  1023. message(FATAL_ERROR "External project \"${name}\" has no ${var}")
  1024. endif()
  1025. set(${var} "${${var}}" PARENT_SCOPE)
  1026. endforeach()
  1027. endfunction()
  1028. function(_ep_get_configure_command_id name cfg_cmd_id_var)
  1029. get_target_property(cmd ${name} _EP_CONFIGURE_COMMAND)
  1030. if(cmd STREQUAL "")
  1031. # Explicit empty string means no configure step for this project
  1032. set(${cfg_cmd_id_var} "none" PARENT_SCOPE)
  1033. else()
  1034. if(NOT cmd)
  1035. # Default is "use cmake":
  1036. set(${cfg_cmd_id_var} "cmake" PARENT_SCOPE)
  1037. else()
  1038. # Otherwise we have to analyze the value:
  1039. if(cmd MATCHES "^[^;]*/configure")
  1040. set(${cfg_cmd_id_var} "configure" PARENT_SCOPE)
  1041. elseif(cmd MATCHES "^[^;]*/cmake" AND NOT cmd MATCHES ";-[PE];")
  1042. set(${cfg_cmd_id_var} "cmake" PARENT_SCOPE)
  1043. elseif(cmd MATCHES "config")
  1044. set(${cfg_cmd_id_var} "configure" PARENT_SCOPE)
  1045. else()
  1046. set(${cfg_cmd_id_var} "unknown:${cmd}" PARENT_SCOPE)
  1047. endif()
  1048. endif()
  1049. endif()
  1050. endfunction()
  1051. function(_ep_get_build_command name step cmd_var)
  1052. set(cmd "${${cmd_var}}")
  1053. if(NOT cmd)
  1054. set(args)
  1055. _ep_get_configure_command_id(${name} cfg_cmd_id)
  1056. if(cfg_cmd_id STREQUAL "cmake")
  1057. # CMake project. Select build command based on generator.
  1058. get_target_property(cmake_generator ${name} _EP_CMAKE_GENERATOR)
  1059. if("${CMAKE_GENERATOR}" MATCHES "Make" AND
  1060. ("${cmake_generator}" MATCHES "Make" OR NOT cmake_generator))
  1061. # The project uses the same Makefile generator. Use recursive make.
  1062. set(cmd "$(MAKE)")
  1063. if(step STREQUAL "INSTALL")
  1064. set(args install)
  1065. endif()
  1066. if("x${step}x" STREQUAL "xTESTx")
  1067. set(args test)
  1068. endif()
  1069. else()
  1070. # Drive the project with "cmake --build".
  1071. get_target_property(cmake_command ${name} _EP_CMAKE_COMMAND)
  1072. if(cmake_command)
  1073. set(cmd "${cmake_command}")
  1074. else()
  1075. set(cmd "${CMAKE_COMMAND}")
  1076. endif()
  1077. set(args --build ".")
  1078. if (CMAKE_CFG_INTDIR AND NOT CMAKE_CFG_INTDIR STREQUAL ".")
  1079. list(APPEND args --config "${CMAKE_CFG_INTDIR}")
  1080. endif ()
  1081. if(step STREQUAL "INSTALL")
  1082. list(APPEND args --target install)
  1083. endif()
  1084. # But for "TEST" drive the project with corresponding "ctest".
  1085. if("x${step}x" STREQUAL "xTESTx")
  1086. string(REGEX REPLACE "^(.*/)cmake([^/]*)$" "\\1ctest\\2" cmd "${cmd}")
  1087. set(args "")
  1088. endif()
  1089. endif()
  1090. else()
  1091. # Non-CMake project. Guess "make" and "make install" and "make test".
  1092. if("${CMAKE_GENERATOR}" MATCHES "Makefiles")
  1093. # Try to get the parallel arguments
  1094. set(cmd "$(MAKE)")
  1095. else()
  1096. set(cmd "make")
  1097. endif()
  1098. if(step STREQUAL "INSTALL")
  1099. set(args install)
  1100. endif()
  1101. if("x${step}x" STREQUAL "xTESTx")
  1102. set(args test)
  1103. endif()
  1104. endif()
  1105. # Use user-specified arguments instead of default arguments, if any.
  1106. get_property(have_args TARGET ${name} PROPERTY _EP_${step}_ARGS SET)
  1107. if(have_args)
  1108. get_target_property(args ${name} _EP_${step}_ARGS)
  1109. endif()
  1110. list(APPEND cmd ${args})
  1111. endif()
  1112. set(${cmd_var} "${cmd}" PARENT_SCOPE)
  1113. endfunction()
  1114. function(_ep_write_log_script name step cmd_var)
  1115. ExternalProject_Get_Property(${name} stamp_dir)
  1116. set(command "${${cmd_var}}")
  1117. set(make "")
  1118. set(code_cygpath_make "")
  1119. if(command MATCHES "^\\$\\(MAKE\\)")
  1120. # GNU make recognizes the string "$(MAKE)" as recursive make, so
  1121. # ensure that it appears directly in the makefile.
  1122. string(REGEX REPLACE "^\\$\\(MAKE\\)" "\${make}" command "${command}")
  1123. set(make "-Dmake=$(MAKE)")
  1124. if(WIN32 AND NOT CYGWIN)
  1125. set(code_cygpath_make "
  1126. if(\${make} MATCHES \"^/\")
  1127. execute_process(
  1128. COMMAND cygpath -w \${make}
  1129. OUTPUT_VARIABLE cygpath_make
  1130. ERROR_VARIABLE cygpath_make
  1131. RESULT_VARIABLE cygpath_error
  1132. OUTPUT_STRIP_TRAILING_WHITESPACE
  1133. )
  1134. if(NOT cygpath_error)
  1135. set(make \${cygpath_make})
  1136. endif()
  1137. endif()
  1138. ")
  1139. endif()
  1140. endif()
  1141. set(config "")
  1142. if("${CMAKE_CFG_INTDIR}" MATCHES "^\\$")
  1143. string(REPLACE "${CMAKE_CFG_INTDIR}" "\${config}" command "${command}")
  1144. set(config "-Dconfig=${CMAKE_CFG_INTDIR}")
  1145. endif()
  1146. # Wrap multiple 'COMMAND' lines up into a second-level wrapper
  1147. # script so all output can be sent to one log file.
  1148. if(command MATCHES "(^|;)COMMAND;")
  1149. set(code_execute_process "
  1150. ${code_cygpath_make}
  1151. execute_process(COMMAND \${command} RESULT_VARIABLE result)
  1152. if(result)
  1153. set(msg \"Command failed (\${result}):\\n\")
  1154. foreach(arg IN LISTS command)
  1155. set(msg \"\${msg} '\${arg}'\")
  1156. endforeach()
  1157. message(FATAL_ERROR \"\${msg}\")
  1158. endif()
  1159. ")
  1160. set(code "")
  1161. set(cmd "")
  1162. set(sep "")
  1163. foreach(arg IN LISTS command)
  1164. if("x${arg}" STREQUAL "xCOMMAND")
  1165. if(NOT "x${cmd}" STREQUAL "x")
  1166. set(code "${code}set(command \"${cmd}\")${code_execute_process}")
  1167. endif()
  1168. set(cmd "")
  1169. set(sep "")
  1170. else()
  1171. set(cmd "${cmd}${sep}${arg}")
  1172. set(sep ";")
  1173. endif()
  1174. endforeach()
  1175. set(code "${code}set(command \"${cmd}\")${code_execute_process}")
  1176. file(GENERATE OUTPUT "${stamp_dir}/${name}-${step}-$<CONFIG>-impl.cmake" CONTENT "${code}")
  1177. set(command ${CMAKE_COMMAND} "-Dmake=\${make}" "-Dconfig=\${config}" -P ${stamp_dir}/${name}-${step}-$<CONFIG>-impl.cmake)
  1178. endif()
  1179. # Wrap the command in a script to log output to files.
  1180. set(script ${stamp_dir}/${name}-${step}-$<CONFIG>.cmake)
  1181. set(logbase ${stamp_dir}/${name}-${step})
  1182. set(code "
  1183. ${code_cygpath_make}
  1184. set(command \"${command}\")
  1185. execute_process(
  1186. COMMAND \${command}
  1187. RESULT_VARIABLE result
  1188. OUTPUT_FILE \"${logbase}-out.log\"
  1189. ERROR_FILE \"${logbase}-err.log\"
  1190. )
  1191. if(result)
  1192. set(msg \"Command failed: \${result}\\n\")
  1193. foreach(arg IN LISTS command)
  1194. set(msg \"\${msg} '\${arg}'\")
  1195. endforeach()
  1196. set(msg \"\${msg}\\nSee also\\n ${logbase}-*.log\")
  1197. message(FATAL_ERROR \"\${msg}\")
  1198. else()
  1199. set(msg \"${name} ${step} command succeeded. See also ${logbase}-*.log\")
  1200. message(STATUS \"\${msg}\")
  1201. endif()
  1202. ")
  1203. file(GENERATE OUTPUT "${script}" CONTENT "${code}")
  1204. set(command ${CMAKE_COMMAND} ${make} ${config} -P ${script})
  1205. set(${cmd_var} "${command}" PARENT_SCOPE)
  1206. endfunction()
  1207. # This module used to use "/${CMAKE_CFG_INTDIR}" directly and produced
  1208. # makefiles with "/./" in paths for custom command dependencies. Which
  1209. # resulted in problems with parallel make -j invocations.
  1210. #
  1211. # This function was added so that the suffix (search below for ${cfgdir}) is
  1212. # only set to "/${CMAKE_CFG_INTDIR}" when ${CMAKE_CFG_INTDIR} is not going to
  1213. # be "." (multi-configuration build systems like Visual Studio and Xcode...)
  1214. #
  1215. function(_ep_get_configuration_subdir_suffix suffix_var)
  1216. set(suffix "")
  1217. if(CMAKE_CONFIGURATION_TYPES)
  1218. set(suffix "/${CMAKE_CFG_INTDIR}")
  1219. endif()
  1220. set(${suffix_var} "${suffix}" PARENT_SCOPE)
  1221. endfunction()
  1222. function(_ep_get_step_stampfile name step stampfile_var)
  1223. ExternalProject_Get_Property(${name} stamp_dir)
  1224. _ep_get_configuration_subdir_suffix(cfgdir)
  1225. set(stampfile "${stamp_dir}${cfgdir}/${name}-${step}")
  1226. set(${stampfile_var} "${stampfile}" PARENT_SCOPE)
  1227. endfunction()
  1228. function(ExternalProject_Add_StepTargets name)
  1229. set(steps ${ARGN})
  1230. if(ARGC GREATER 1 AND "${ARGV1}" STREQUAL "NO_DEPENDS")
  1231. set(no_deps 1)
  1232. list(REMOVE_AT steps 0)
  1233. endif()
  1234. foreach(step ${steps})
  1235. if(no_deps AND "${step}" MATCHES "^(configure|build|install|test)$")
  1236. message(AUTHOR_WARNING "Using NO_DEPENDS for \"${step}\" step might break parallel builds")
  1237. endif()
  1238. _ep_get_step_stampfile(${name} ${step} stamp_file)
  1239. add_custom_target(${name}-${step}
  1240. DEPENDS ${stamp_file})
  1241. set_property(TARGET ${name}-${step} PROPERTY _EP_IS_EXTERNAL_PROJECT_STEP 1)
  1242. set_property(TARGET ${name}-${step} PROPERTY LABELS ${name})
  1243. set_property(TARGET ${name}-${step} PROPERTY FOLDER "ExternalProjectTargets/${name}")
  1244. # Depend on other external projects (target-level).
  1245. if(NOT no_deps)
  1246. get_property(deps TARGET ${name} PROPERTY _EP_DEPENDS)
  1247. foreach(arg IN LISTS deps)
  1248. add_dependencies(${name}-${step} ${arg})
  1249. endforeach()
  1250. endif()
  1251. endforeach()
  1252. endfunction()
  1253. function(ExternalProject_Add_Step name step)
  1254. set(cmf_dir ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles)
  1255. _ep_get_configuration_subdir_suffix(cfgdir)
  1256. set(complete_stamp_file "${cmf_dir}${cfgdir}/${name}-complete")
  1257. _ep_get_step_stampfile(${name} ${step} stamp_file)
  1258. _ep_parse_arguments(ExternalProject_Add_Step
  1259. ${name} _EP_${step}_ "${ARGN}")
  1260. get_property(exclude_from_main TARGET ${name} PROPERTY _EP_${step}_EXCLUDE_FROM_MAIN)
  1261. if(NOT exclude_from_main)
  1262. add_custom_command(APPEND
  1263. OUTPUT ${complete_stamp_file}
  1264. DEPENDS ${stamp_file}
  1265. )
  1266. endif()
  1267. # Steps depending on this step.
  1268. get_property(dependers TARGET ${name} PROPERTY _EP_${step}_DEPENDERS)
  1269. foreach(depender IN LISTS dependers)
  1270. _ep_get_step_stampfile(${name} ${depender} depender_stamp_file)
  1271. add_custom_command(APPEND
  1272. OUTPUT ${depender_stamp_file}
  1273. DEPENDS ${stamp_file}
  1274. )
  1275. endforeach()
  1276. # Dependencies on files.
  1277. get_property(depends TARGET ${name} PROPERTY _EP_${step}_DEPENDS)
  1278. # Byproducts of the step.
  1279. get_property(byproducts TARGET ${name} PROPERTY _EP_${step}_BYPRODUCTS)
  1280. # Dependencies on steps.
  1281. get_property(dependees TARGET ${name} PROPERTY _EP_${step}_DEPENDEES)
  1282. foreach(dependee IN LISTS dependees)
  1283. _ep_get_step_stampfile(${name} ${dependee} dependee_stamp_file)
  1284. list(APPEND depends ${dependee_stamp_file})
  1285. endforeach()
  1286. # The command to run.
  1287. get_property(command TARGET ${name} PROPERTY _EP_${step}_COMMAND)
  1288. if(command)
  1289. set(comment "Performing ${step} step for '${name}'")
  1290. else()
  1291. set(comment "No ${step} step for '${name}'")
  1292. endif()
  1293. get_property(work_dir TARGET ${name} PROPERTY _EP_${step}_WORKING_DIRECTORY)
  1294. # Replace list separators.
  1295. get_property(sep TARGET ${name} PROPERTY _EP_LIST_SEPARATOR)
  1296. if(sep AND command)
  1297. string(REPLACE "${sep}" "\\;" command "${command}")
  1298. endif()
  1299. # Replace location tags.
  1300. _ep_replace_location_tags(${name} comment command work_dir byproducts)
  1301. # Custom comment?
  1302. get_property(comment_set TARGET ${name} PROPERTY _EP_${step}_COMMENT SET)
  1303. if(comment_set)
  1304. get_property(comment TARGET ${name} PROPERTY _EP_${step}_COMMENT)
  1305. endif()
  1306. # Uses terminal?
  1307. get_property(uses_terminal TARGET ${name} PROPERTY _EP_${step}_USES_TERMINAL)
  1308. if(uses_terminal)
  1309. set(uses_terminal USES_TERMINAL)
  1310. else()
  1311. set(uses_terminal "")
  1312. endif()
  1313. # Run every time?
  1314. get_property(always TARGET ${name} PROPERTY _EP_${step}_ALWAYS)
  1315. if(always)
  1316. set_property(SOURCE ${stamp_file} PROPERTY SYMBOLIC 1)
  1317. set(touch)
  1318. # Remove any existing stamp in case the option changed in an existing tree.
  1319. if(CMAKE_CONFIGURATION_TYPES)
  1320. foreach(cfg ${CMAKE_CONFIGURATION_TYPES})
  1321. string(REPLACE "/${CMAKE_CFG_INTDIR}" "/${cfg}" stamp_file_config "${stamp_file}")
  1322. file(REMOVE ${stamp_file_config})
  1323. endforeach()
  1324. else()
  1325. file(REMOVE ${stamp_file})
  1326. endif()
  1327. else()
  1328. set(touch ${CMAKE_COMMAND} -E touch ${stamp_file})
  1329. endif()
  1330. # Wrap with log script?
  1331. get_property(log TARGET ${name} PROPERTY _EP_${step}_LOG)
  1332. if(command AND log)
  1333. _ep_write_log_script(${name} ${step} command)
  1334. endif()
  1335. if("${command}" STREQUAL "")
  1336. # Some generators (i.e. Xcode) will not generate a file level target
  1337. # if no command is set, and therefore the dependencies on this
  1338. # target will be broken.
  1339. # The empty command is replaced by an echo command here in order to
  1340. # avoid this issue.
  1341. set(command ${CMAKE_COMMAND} -E echo_append)
  1342. endif()
  1343. add_custom_command(
  1344. OUTPUT ${stamp_file}
  1345. BYPRODUCTS ${byproducts}
  1346. COMMENT ${comment}
  1347. COMMAND ${command}
  1348. COMMAND ${touch}
  1349. DEPENDS ${depends}
  1350. WORKING_DIRECTORY ${work_dir}
  1351. VERBATIM
  1352. ${uses_terminal}
  1353. )
  1354. set_property(TARGET ${name} APPEND PROPERTY _EP_STEPS ${step})
  1355. # Add custom "step target"?
  1356. get_property(step_targets TARGET ${name} PROPERTY _EP_STEP_TARGETS)
  1357. if(NOT step_targets)
  1358. get_property(step_targets DIRECTORY PROPERTY EP_STEP_TARGETS)
  1359. endif()
  1360. foreach(st ${step_targets})
  1361. if("${st}" STREQUAL "${step}")
  1362. ExternalProject_Add_StepTargets(${name} ${step})
  1363. break()
  1364. endif()
  1365. endforeach()
  1366. get_property(independent_step_targets TARGET ${name} PROPERTY _EP_INDEPENDENT_STEP_TARGETS)
  1367. if(NOT independent_step_targets)
  1368. get_property(independent_step_targets DIRECTORY PROPERTY EP_INDEPENDENT_STEP_TARGETS)
  1369. endif()
  1370. foreach(st ${independent_step_targets})
  1371. if("${st}" STREQUAL "${step}")
  1372. ExternalProject_Add_StepTargets(${name} NO_DEPENDS ${step})
  1373. break()
  1374. endif()
  1375. endforeach()
  1376. endfunction()
  1377. function(ExternalProject_Add_StepDependencies name step)
  1378. set(dependencies ${ARGN})
  1379. # Sanity checks on "name" and "step".
  1380. if(NOT TARGET ${name})
  1381. message(FATAL_ERROR "Cannot find target \"${name}\". Perhaps it has not yet been created using ExternalProject_Add.")
  1382. endif()
  1383. get_property(type TARGET ${name} PROPERTY TYPE)
  1384. if(NOT type STREQUAL "UTILITY")
  1385. message(FATAL_ERROR "Target \"${name}\" was not generated by ExternalProject_Add.")
  1386. endif()
  1387. get_property(is_ep TARGET ${name} PROPERTY _EP_IS_EXTERNAL_PROJECT)
  1388. if(NOT is_ep)
  1389. message(FATAL_ERROR "Target \"${name}\" was not generated by ExternalProject_Add.")
  1390. endif()
  1391. get_property(steps TARGET ${name} PROPERTY _EP_STEPS)
  1392. list(FIND steps ${step} is_step)
  1393. if(NOT is_step)
  1394. message(FATAL_ERROR "External project \"${name}\" does not have a step \"${step}\".")
  1395. endif()
  1396. if(TARGET ${name}-${step})
  1397. get_property(type TARGET ${name}-${step} PROPERTY TYPE)
  1398. if(NOT type STREQUAL "UTILITY")
  1399. message(FATAL_ERROR "Target \"${name}-${step}\" was not generated by ExternalProject_Add_StepTargets.")
  1400. endif()
  1401. get_property(is_ep_step TARGET ${name}-${step} PROPERTY _EP_IS_EXTERNAL_PROJECT_STEP)
  1402. if(NOT is_ep_step)
  1403. message(FATAL_ERROR "Target \"${name}-${step}\" was not generated by ExternalProject_Add_StepTargets.")
  1404. endif()
  1405. endif()
  1406. # Always add file-level dependency, but add target-level dependency
  1407. # only if the target exists for that step.
  1408. _ep_get_step_stampfile(${name} ${step} stamp_file)
  1409. foreach(dep ${dependencies})
  1410. add_custom_command(APPEND
  1411. OUTPUT ${stamp_file}
  1412. DEPENDS ${dep})
  1413. if(TARGET ${name}-${step})
  1414. foreach(dep ${dependencies})
  1415. add_dependencies(${name}-${step} ${dep})
  1416. endforeach()
  1417. endif()
  1418. endforeach()
  1419. endfunction()
  1420. function(_ep_add_mkdir_command name)
  1421. ExternalProject_Get_Property(${name}
  1422. source_dir binary_dir install_dir stamp_dir download_dir tmp_dir)
  1423. _ep_get_configuration_subdir_suffix(cfgdir)
  1424. ExternalProject_Add_Step(${name} mkdir
  1425. COMMENT "Creating directories for '${name}'"
  1426. COMMAND ${CMAKE_COMMAND} -E make_directory ${source_dir}
  1427. COMMAND ${CMAKE_COMMAND} -E make_directory ${binary_dir}
  1428. COMMAND ${CMAKE_COMMAND} -E make_directory ${install_dir}
  1429. COMMAND ${CMAKE_COMMAND} -E make_directory ${tmp_dir}
  1430. COMMAND ${CMAKE_COMMAND} -E make_directory ${stamp_dir}${cfgdir}
  1431. COMMAND ${CMAKE_COMMAND} -E make_directory ${download_dir}
  1432. )
  1433. endfunction()
  1434. function(_ep_is_dir_empty dir empty_var)
  1435. file(GLOB gr "${dir}/*")
  1436. if("${gr}" STREQUAL "")
  1437. set(${empty_var} 1 PARENT_SCOPE)
  1438. else()
  1439. set(${empty_var} 0 PARENT_SCOPE)
  1440. endif()
  1441. endfunction()
  1442. function(_ep_add_download_command name)
  1443. ExternalProject_Get_Property(${name} source_dir stamp_dir download_dir tmp_dir)
  1444. get_property(cmd_set TARGET ${name} PROPERTY _EP_DOWNLOAD_COMMAND SET)
  1445. get_property(cmd TARGET ${name} PROPERTY _EP_DOWNLOAD_COMMAND)
  1446. get_property(cvs_repository TARGET ${name} PROPERTY _EP_CVS_REPOSITORY)
  1447. get_property(svn_repository TARGET ${name} PROPERTY _EP_SVN_REPOSITORY)
  1448. get_property(git_repository TARGET ${name} PROPERTY _EP_GIT_REPOSITORY)
  1449. get_property(hg_repository TARGET ${name} PROPERTY _EP_HG_REPOSITORY )
  1450. get_property(url TARGET ${name} PROPERTY _EP_URL)
  1451. get_property(fname TARGET ${name} PROPERTY _EP_DOWNLOAD_NAME)
  1452. # TODO: Perhaps file:// should be copied to download dir before extraction.
  1453. string(REGEX REPLACE "^file://" "" url "${url}")
  1454. set(depends)
  1455. set(comment)
  1456. set(work_dir)
  1457. if(cmd_set)
  1458. set(work_dir ${download_dir})
  1459. elseif(cvs_repository)
  1460. find_package(CVS QUIET)
  1461. if(NOT CVS_EXECUTABLE)
  1462. message(FATAL_ERROR "error: could not find cvs for checkout of ${name}")
  1463. endif()
  1464. get_target_property(cvs_module ${name} _EP_CVS_MODULE)
  1465. if(NOT cvs_module)
  1466. message(FATAL_ERROR "error: no CVS_MODULE")
  1467. endif()
  1468. get_property(cvs_tag TARGET ${name} PROPERTY _EP_CVS_TAG)
  1469. set(repository ${cvs_repository})
  1470. set(module ${cvs_module})
  1471. set(tag ${cvs_tag})
  1472. configure_file(
  1473. "${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in"
  1474. "${stamp_dir}/${name}-cvsinfo.txt"
  1475. @ONLY
  1476. )
  1477. get_filename_component(src_name "${source_dir}" NAME)
  1478. get_filename_component(work_dir "${source_dir}" PATH)
  1479. set(comment "Performing download step (CVS checkout) for '${name}'")
  1480. set(cmd ${CVS_EXECUTABLE} -d ${cvs_repository} -q co ${cvs_tag} -d ${src_name} ${cvs_module})
  1481. list(APPEND depends ${stamp_dir}/${name}-cvsinfo.txt)
  1482. elseif(svn_repository)
  1483. find_package(Subversion QUIET)
  1484. if(NOT Subversion_SVN_EXECUTABLE)
  1485. message(FATAL_ERROR "error: could not find svn for checkout of ${name}")
  1486. endif()
  1487. get_property(svn_revision TARGET ${name} PROPERTY _EP_SVN_REVISION)
  1488. get_property(svn_username TARGET ${name} PROPERTY _EP_SVN_USERNAME)
  1489. get_property(svn_password TARGET ${name} PROPERTY _EP_SVN_PASSWORD)
  1490. get_property(svn_trust_cert TARGET ${name} PROPERTY _EP_SVN_TRUST_CERT)
  1491. set(repository "${svn_repository} user=${svn_username} password=${svn_password}")
  1492. set(module)
  1493. set(tag ${svn_revision})
  1494. configure_file(
  1495. "${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in"
  1496. "${stamp_dir}/${name}-svninfo.txt"
  1497. @ONLY
  1498. )
  1499. get_filename_component(src_name "${source_dir}" NAME)
  1500. get_filename_component(work_dir "${source_dir}" PATH)
  1501. set(comment "Performing download step (SVN checkout) for '${name}'")
  1502. set(svn_user_pw_args "")
  1503. if(DEFINED svn_username)
  1504. set(svn_user_pw_args ${svn_user_pw_args} "--username=${svn_username}")
  1505. endif()
  1506. if(DEFINED svn_password)
  1507. set(svn_user_pw_args ${svn_user_pw_args} "--password=${svn_password}")
  1508. endif()
  1509. if(svn_trust_cert)
  1510. set(svn_trust_cert_args --trust-server-cert)
  1511. endif()
  1512. set(cmd ${Subversion_SVN_EXECUTABLE} co ${svn_repository} ${svn_revision}
  1513. --non-interactive ${svn_trust_cert_args} ${svn_user_pw_args} ${src_name})
  1514. list(APPEND depends ${stamp_dir}/${name}-svninfo.txt)
  1515. elseif(git_repository)
  1516. unset(CMAKE_MODULE_PATH) # Use CMake builtin find module
  1517. find_package(Git QUIET)
  1518. if(NOT GIT_EXECUTABLE)
  1519. message(FATAL_ERROR "error: could not find git for clone of ${name}")
  1520. endif()
  1521. # The git submodule update '--recursive' flag requires git >= v1.6.5
  1522. #
  1523. if(GIT_VERSION_STRING VERSION_LESS 1.6.5)
  1524. message(FATAL_ERROR "error: git version 1.6.5 or later required for 'git submodule update --recursive': GIT_VERSION_STRING='${GIT_VERSION_STRING}'")
  1525. endif()
  1526. get_property(git_tag TARGET ${name} PROPERTY _EP_GIT_TAG)
  1527. if(NOT git_tag)
  1528. set(git_tag "master")
  1529. endif()
  1530. get_property(git_submodules TARGET ${name} PROPERTY _EP_GIT_SUBMODULES)
  1531. get_property(git_remote_name TARGET ${name} PROPERTY _EP_GIT_REMOTE_NAME)
  1532. if(NOT git_remote_name)
  1533. set(git_remote_name "origin")
  1534. endif()
  1535. # For the download step, and the git clone operation, only the repository
  1536. # should be recorded in a configured RepositoryInfo file. If the repo
  1537. # changes, the clone script should be run again. But if only the tag
  1538. # changes, avoid running the clone script again. Let the 'always' running
  1539. # update step checkout the new tag.
  1540. #
  1541. set(repository ${git_repository})
  1542. set(module)
  1543. set(tag)
  1544. configure_file(
  1545. "${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in"
  1546. "${stamp_dir}/${name}-gitinfo.txt"
  1547. @ONLY
  1548. )
  1549. get_filename_component(src_name "${source_dir}" NAME)
  1550. get_filename_component(work_dir "${source_dir}" PATH)
  1551. # Since git clone doesn't succeed if the non-empty source_dir exists,
  1552. # create a cmake script to invoke as download command.
  1553. # The script will delete the source directory and then call git clone.
  1554. #
  1555. _ep_write_gitclone_script(${tmp_dir}/${name}-gitclone.cmake ${source_dir}
  1556. ${GIT_EXECUTABLE} ${git_repository} ${git_tag} ${git_remote_name} "${git_submodules}" ${src_name} ${work_dir}
  1557. ${stamp_dir}/${name}-gitinfo.txt ${stamp_dir}/${name}-gitclone-lastrun.txt
  1558. )
  1559. set(comment "Performing download step (git clone) for '${name}'")
  1560. set(cmd ${CMAKE_COMMAND} -P ${tmp_dir}/${name}-gitclone.cmake)
  1561. list(APPEND depends ${stamp_dir}/${name}-gitinfo.txt)
  1562. elseif(hg_repository)
  1563. find_package(Hg QUIET)
  1564. if(NOT HG_EXECUTABLE)
  1565. message(FATAL_ERROR "error: could not find hg for clone of ${name}")
  1566. endif()
  1567. get_property(hg_tag TARGET ${name} PROPERTY _EP_HG_TAG)
  1568. if(NOT hg_tag)
  1569. set(hg_tag "tip")
  1570. endif()
  1571. # For the download step, and the hg clone operation, only the repository
  1572. # should be recorded in a configured RepositoryInfo file. If the repo
  1573. # changes, the clone script should be run again. But if only the tag
  1574. # changes, avoid running the clone script again. Let the 'always' running
  1575. # update step checkout the new tag.
  1576. #
  1577. set(repository ${hg_repository})
  1578. set(module)
  1579. set(tag)
  1580. configure_file(
  1581. "${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in"
  1582. "${stamp_dir}/${name}-hginfo.txt"
  1583. @ONLY
  1584. )
  1585. get_filename_component(src_name "${source_dir}" NAME)
  1586. get_filename_component(work_dir "${source_dir}" PATH)
  1587. # Since hg clone doesn't succeed if the non-empty source_dir exists,
  1588. # create a cmake script to invoke as download command.
  1589. # The script will delete the source directory and then call hg clone.
  1590. #
  1591. _ep_write_hgclone_script(${tmp_dir}/${name}-hgclone.cmake ${source_dir}
  1592. ${HG_EXECUTABLE} ${hg_repository} ${hg_tag} ${src_name} ${work_dir}
  1593. ${stamp_dir}/${name}-hginfo.txt ${stamp_dir}/${name}-hgclone-lastrun.txt
  1594. )
  1595. set(comment "Performing download step (hg clone) for '${name}'")
  1596. set(cmd ${CMAKE_COMMAND} -P ${tmp_dir}/${name}-hgclone.cmake)
  1597. list(APPEND depends ${stamp_dir}/${name}-hginfo.txt)
  1598. elseif(url)
  1599. get_filename_component(work_dir "${source_dir}" PATH)
  1600. get_property(hash TARGET ${name} PROPERTY _EP_URL_HASH)
  1601. if(hash AND NOT "${hash}" MATCHES "${_ep_hash_regex}")
  1602. message(FATAL_ERROR "URL_HASH is set to\n ${hash}\n"
  1603. "but must be ALGO=value where ALGO is\n ${_ep_hash_algos}\n"
  1604. "and value is a hex string.")
  1605. endif()
  1606. get_property(md5 TARGET ${name} PROPERTY _EP_URL_MD5)
  1607. if(md5 AND NOT "MD5=${md5}" MATCHES "${_ep_hash_regex}")
  1608. message(FATAL_ERROR "URL_MD5 is set to\n ${md5}\nbut must be a hex string.")
  1609. endif()
  1610. if(md5 AND NOT hash)
  1611. set(hash "MD5=${md5}")
  1612. endif()
  1613. set(repository "external project URL")
  1614. set(module "${url}")
  1615. set(tag "${hash}")
  1616. set(retries 0)
  1617. set(download_script "")
  1618. configure_file(
  1619. "${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in"
  1620. "${stamp_dir}/${name}-urlinfo.txt"
  1621. @ONLY
  1622. )
  1623. list(APPEND depends ${stamp_dir}/${name}-urlinfo.txt)
  1624. if(IS_DIRECTORY "${url}")
  1625. get_filename_component(abs_dir "${url}" ABSOLUTE)
  1626. set(comment "Performing download step (DIR copy) for '${name}'")
  1627. set(cmd ${CMAKE_COMMAND} -E remove_directory ${source_dir}
  1628. COMMAND ${CMAKE_COMMAND} -E copy_directory ${abs_dir} ${source_dir})
  1629. else()
  1630. if("${url}" MATCHES "^[a-z]+://")
  1631. # TODO: Should download and extraction be different steps?
  1632. if("x${fname}" STREQUAL "x")
  1633. string(REGEX MATCH "[^/\\?]*$" fname "${url}")
  1634. endif()
  1635. if(NOT "${fname}" MATCHES "(\\.|=)(7z|tar|tar\\.bz2|tar\\.gz|tar\\.xz|tbz2|tgz|txz|zip)$")
  1636. string(REGEX MATCH "([^/\\?]+(\\.|=)(7z|tar|tar\\.bz2|tar\\.gz|tar\\.xz|tbz2|tgz|txz|zip))/.*$" match_result "${url}")
  1637. set(fname "${CMAKE_MATCH_1}")
  1638. endif()
  1639. if(NOT "${fname}" MATCHES "(\\.|=)(7z|tar|tar\\.bz2|tar\\.gz|tar\\.xz|tbz2|tgz|txz|zip)$")
  1640. message(FATAL_ERROR "Could not extract tarball filename from url:\n ${url}")
  1641. endif()
  1642. string(REPLACE ";" "-" fname "${fname}")
  1643. set(file ${download_dir}/${fname})
  1644. get_property(timeout TARGET ${name} PROPERTY _EP_TIMEOUT)
  1645. get_property(no_progress TARGET ${name} PROPERTY _EP_DOWNLOAD_NO_PROGRESS)
  1646. get_property(tls_verify TARGET ${name} PROPERTY _EP_TLS_VERIFY)
  1647. get_property(tls_cainfo TARGET ${name} PROPERTY _EP_TLS_CAINFO)
  1648. set(download_script "${stamp_dir}/download-${name}.cmake")
  1649. _ep_write_downloadfile_script("${download_script}" "${url}" "${file}" "${timeout}" "${no_progress}" "${hash}" "${tls_verify}" "${tls_cainfo}")
  1650. set(cmd ${CMAKE_COMMAND} -P "${download_script}"
  1651. COMMAND)
  1652. set(retries 3)
  1653. set(comment "Performing download step (download, verify and extract) for '${name}'")
  1654. else()
  1655. set(file "${url}")
  1656. set(comment "Performing download step (verify and extract) for '${name}'")
  1657. endif()
  1658. _ep_write_verifyfile_script("${stamp_dir}/verify-${name}.cmake" "${file}" "${hash}" "${retries}" "${download_script}")
  1659. list(APPEND cmd ${CMAKE_COMMAND} -P ${stamp_dir}/verify-${name}.cmake
  1660. COMMAND)
  1661. _ep_write_extractfile_script("${stamp_dir}/extract-${name}.cmake" "${name}" "${file}" "${source_dir}")
  1662. list(APPEND cmd ${CMAKE_COMMAND} -P ${stamp_dir}/extract-${name}.cmake)
  1663. endif()
  1664. else()
  1665. _ep_is_dir_empty("${source_dir}" empty)
  1666. if(${empty})
  1667. message(SEND_ERROR
  1668. "No download info given for '${name}' and its source directory:\n"
  1669. " ${source_dir}\n"
  1670. "is not an existing non-empty directory. Please specify one of:\n"
  1671. " * SOURCE_DIR with an existing non-empty directory\n"
  1672. " * URL\n"
  1673. " * GIT_REPOSITORY\n"
  1674. " * HG_REPOSITORY\n"
  1675. " * CVS_REPOSITORY and CVS_MODULE\n"
  1676. " * SVN_REVISION\n"
  1677. " * DOWNLOAD_COMMAND"
  1678. )
  1679. endif()
  1680. endif()
  1681. get_property(log TARGET ${name} PROPERTY _EP_LOG_DOWNLOAD)
  1682. if(log)
  1683. set(log LOG 1)
  1684. else()
  1685. set(log "")
  1686. endif()
  1687. get_property(uses_terminal TARGET ${name} PROPERTY
  1688. _EP_USES_TERMINAL_DOWNLOAD)
  1689. if(uses_terminal)
  1690. set(uses_terminal USES_TERMINAL 1)
  1691. else()
  1692. set(uses_terminal "")
  1693. endif()
  1694. ExternalProject_Add_Step(${name} download
  1695. COMMENT ${comment}
  1696. COMMAND ${cmd}
  1697. WORKING_DIRECTORY ${work_dir}
  1698. DEPENDS ${depends}
  1699. DEPENDEES mkdir
  1700. ${log}
  1701. ${uses_terminal}
  1702. )
  1703. endfunction()
  1704. function(_ep_add_update_command name)
  1705. ExternalProject_Get_Property(${name} source_dir tmp_dir)
  1706. get_property(cmd_set TARGET ${name} PROPERTY _EP_UPDATE_COMMAND SET)
  1707. get_property(cmd TARGET ${name} PROPERTY _EP_UPDATE_COMMAND)
  1708. get_property(cvs_repository TARGET ${name} PROPERTY _EP_CVS_REPOSITORY)
  1709. get_property(svn_repository TARGET ${name} PROPERTY _EP_SVN_REPOSITORY)
  1710. get_property(git_repository TARGET ${name} PROPERTY _EP_GIT_REPOSITORY)
  1711. get_property(hg_repository TARGET ${name} PROPERTY _EP_HG_REPOSITORY )
  1712. get_property(update_disconnected_set TARGET ${name} PROPERTY _EP_UPDATE_DISCONNECTED SET)
  1713. if(update_disconnected_set)
  1714. get_property(update_disconnected TARGET ${name} PROPERTY _EP_UPDATE_DISCONNECTED)
  1715. else()
  1716. get_property(update_disconnected DIRECTORY PROPERTY EP_UPDATE_DISCONNECTED)
  1717. endif()
  1718. set(work_dir)
  1719. set(comment)
  1720. set(always)
  1721. if(cmd_set)
  1722. set(work_dir ${source_dir})
  1723. elseif(cvs_repository)
  1724. if(NOT CVS_EXECUTABLE)
  1725. message(FATAL_ERROR "error: could not find cvs for update of ${name}")
  1726. endif()
  1727. set(work_dir ${source_dir})
  1728. set(comment "Performing update step (CVS update) for '${name}'")
  1729. get_property(cvs_tag TARGET ${name} PROPERTY _EP_CVS_TAG)
  1730. set(cmd ${CVS_EXECUTABLE} -d ${cvs_repository} -q up -dP ${cvs_tag})
  1731. set(always 1)
  1732. elseif(svn_repository)
  1733. if(NOT Subversion_SVN_EXECUTABLE)
  1734. message(FATAL_ERROR "error: could not find svn for update of ${name}")
  1735. endif()
  1736. set(work_dir ${source_dir})
  1737. set(comment "Performing update step (SVN update) for '${name}'")
  1738. get_property(svn_revision TARGET ${name} PROPERTY _EP_SVN_REVISION)
  1739. get_property(svn_username TARGET ${name} PROPERTY _EP_SVN_USERNAME)
  1740. get_property(svn_password TARGET ${name} PROPERTY _EP_SVN_PASSWORD)
  1741. get_property(svn_trust_cert TARGET ${name} PROPERTY _EP_SVN_TRUST_CERT)
  1742. set(svn_user_pw_args "")
  1743. if(DEFINED svn_username)
  1744. set(svn_user_pw_args ${svn_user_pw_args} "--username=${svn_username}")
  1745. endif()
  1746. if(DEFINED svn_password)
  1747. set(svn_user_pw_args ${svn_user_pw_args} "--password=${svn_password}")
  1748. endif()
  1749. if(svn_trust_cert)
  1750. set(svn_trust_cert_args --trust-server-cert)
  1751. endif()
  1752. set(cmd ${Subversion_SVN_EXECUTABLE} up ${svn_revision}
  1753. --non-interactive ${svn_trust_cert_args} ${svn_user_pw_args})
  1754. set(always 1)
  1755. elseif(git_repository)
  1756. if(NOT GIT_EXECUTABLE)
  1757. message(FATAL_ERROR "error: could not find git for fetch of ${name}")
  1758. endif()
  1759. set(work_dir ${source_dir})
  1760. set(comment "Performing update step for '${name}'")
  1761. get_property(git_tag TARGET ${name} PROPERTY _EP_GIT_TAG)
  1762. if(NOT git_tag)
  1763. set(git_tag "master")
  1764. endif()
  1765. get_property(git_remote_name TARGET ${name} PROPERTY _EP_GIT_REMOTE_NAME)
  1766. if(NOT git_remote_name)
  1767. set(git_remote_name "origin")
  1768. endif()
  1769. get_property(git_submodules TARGET ${name} PROPERTY _EP_GIT_SUBMODULES)
  1770. _ep_write_gitupdate_script(${tmp_dir}/${name}-gitupdate.cmake
  1771. ${GIT_EXECUTABLE} ${git_tag} ${git_remote_name} "${git_submodules}" ${git_repository} ${work_dir}
  1772. )
  1773. set(cmd ${CMAKE_COMMAND} -P ${tmp_dir}/${name}-gitupdate.cmake)
  1774. set(always 1)
  1775. elseif(hg_repository)
  1776. if(NOT HG_EXECUTABLE)
  1777. message(FATAL_ERROR "error: could not find hg for pull of ${name}")
  1778. endif()
  1779. set(work_dir ${source_dir})
  1780. set(comment "Performing update step (hg pull) for '${name}'")
  1781. get_property(hg_tag TARGET ${name} PROPERTY _EP_HG_TAG)
  1782. if(NOT hg_tag)
  1783. set(hg_tag "tip")
  1784. endif()
  1785. if("${HG_VERSION_STRING}" STREQUAL "2.1")
  1786. message(WARNING "Mercurial 2.1 does not distinguish an empty pull from a failed pull:
  1787. http://mercurial.selenic.com/wiki/UpgradeNotes#A2.1.1:_revert_pull_return_code_change.2C_compile_issue_on_OS_X
  1788. http://thread.gmane.org/gmane.comp.version-control.mercurial.devel/47656
  1789. Update to Mercurial >= 2.1.1.
  1790. ")
  1791. endif()
  1792. set(cmd ${HG_EXECUTABLE} pull
  1793. COMMAND ${HG_EXECUTABLE} update ${hg_tag}
  1794. )
  1795. set(always 1)
  1796. endif()
  1797. get_property(log TARGET ${name} PROPERTY _EP_LOG_UPDATE)
  1798. if(log)
  1799. set(log LOG 1)
  1800. else()
  1801. set(log "")
  1802. endif()
  1803. get_property(uses_terminal TARGET ${name} PROPERTY
  1804. _EP_USES_TERMINAL_UPDATE)
  1805. if(uses_terminal)
  1806. set(uses_terminal USES_TERMINAL 1)
  1807. else()
  1808. set(uses_terminal "")
  1809. endif()
  1810. ExternalProject_Add_Step(${name} update
  1811. COMMENT ${comment}
  1812. COMMAND ${cmd}
  1813. ALWAYS ${always}
  1814. EXCLUDE_FROM_MAIN ${update_disconnected}
  1815. WORKING_DIRECTORY ${work_dir}
  1816. DEPENDEES download
  1817. ${log}
  1818. ${uses_terminal}
  1819. )
  1820. if(always AND update_disconnected)
  1821. _ep_get_step_stampfile(${name} skip-update skip-update_stamp_file)
  1822. string(REPLACE "Performing" "Skipping" comment "${comment}")
  1823. ExternalProject_Add_Step(${name} skip-update
  1824. COMMENT ${comment}
  1825. ALWAYS 1
  1826. EXCLUDE_FROM_MAIN 1
  1827. WORKING_DIRECTORY ${work_dir}
  1828. DEPENDEES download
  1829. ${log}
  1830. ${uses_terminal}
  1831. )
  1832. set_property(SOURCE ${skip-update_stamp_file} PROPERTY SYMBOLIC 1)
  1833. endif()
  1834. endfunction()
  1835. function(_ep_add_patch_command name)
  1836. ExternalProject_Get_Property(${name} source_dir)
  1837. get_property(cmd_set TARGET ${name} PROPERTY _EP_PATCH_COMMAND SET)
  1838. get_property(cmd TARGET ${name} PROPERTY _EP_PATCH_COMMAND)
  1839. set(work_dir)
  1840. if(cmd_set)
  1841. set(work_dir ${source_dir})
  1842. endif()
  1843. ExternalProject_Add_Step(${name} patch
  1844. COMMAND ${cmd}
  1845. WORKING_DIRECTORY ${work_dir}
  1846. DEPENDEES download
  1847. )
  1848. endfunction()
  1849. # TODO: Make sure external projects use the proper compiler
  1850. function(_ep_add_configure_command name)
  1851. ExternalProject_Get_Property(${name} source_dir binary_dir tmp_dir)
  1852. # Depend on other external projects (file-level).
  1853. set(file_deps)
  1854. get_property(deps TARGET ${name} PROPERTY _EP_DEPENDS)
  1855. foreach(dep IN LISTS deps)
  1856. get_property(dep_type TARGET ${dep} PROPERTY TYPE)
  1857. if(dep_type STREQUAL "UTILITY")
  1858. get_property(is_ep TARGET ${dep} PROPERTY _EP_IS_EXTERNAL_PROJECT)
  1859. if(is_ep)
  1860. _ep_get_step_stampfile(${dep} "done" done_stamp_file)
  1861. list(APPEND file_deps ${done_stamp_file})
  1862. endif()
  1863. endif()
  1864. endforeach()
  1865. get_property(cmd_set TARGET ${name} PROPERTY _EP_CONFIGURE_COMMAND SET)
  1866. if(cmd_set)
  1867. get_property(cmd TARGET ${name} PROPERTY _EP_CONFIGURE_COMMAND)
  1868. else()
  1869. get_target_property(cmake_command ${name} _EP_CMAKE_COMMAND)
  1870. if(cmake_command)
  1871. set(cmd "${cmake_command}")
  1872. else()
  1873. set(cmd "${CMAKE_COMMAND}")
  1874. endif()
  1875. get_property(cmake_args TARGET ${name} PROPERTY _EP_CMAKE_ARGS)
  1876. list(APPEND cmd ${cmake_args})
  1877. # If there are any CMAKE_CACHE_ARGS or CMAKE_CACHE_DEFAULT_ARGS,
  1878. # write an initial cache and use it
  1879. get_property(cmake_cache_args TARGET ${name} PROPERTY _EP_CMAKE_CACHE_ARGS)
  1880. get_property(cmake_cache_default_args TARGET ${name} PROPERTY _EP_CMAKE_CACHE_DEFAULT_ARGS)
  1881. if(cmake_cache_args OR cmake_cache_default_args)
  1882. set(_ep_cache_args_script "${tmp_dir}/${name}-cache-$<CONFIG>.cmake")
  1883. if(cmake_cache_args)
  1884. _ep_command_line_to_initial_cache(script_initial_cache_force "${cmake_cache_args}" 1)
  1885. endif()
  1886. if(cmake_cache_default_args)
  1887. _ep_command_line_to_initial_cache(script_initial_cache_default "${cmake_cache_default_args}" 0)
  1888. endif()
  1889. _ep_write_initial_cache(${name} "${_ep_cache_args_script}" "${script_initial_cache_force}${script_initial_cache_default}")
  1890. list(APPEND cmd "-C${_ep_cache_args_script}")
  1891. endif()
  1892. get_target_property(cmake_generator ${name} _EP_CMAKE_GENERATOR)
  1893. get_target_property(cmake_generator_platform ${name} _EP_CMAKE_GENERATOR_PLATFORM)
  1894. get_target_property(cmake_generator_toolset ${name} _EP_CMAKE_GENERATOR_TOOLSET)
  1895. if(cmake_generator)
  1896. list(APPEND cmd "-G${cmake_generator}")
  1897. if(cmake_generator_platform)
  1898. list(APPEND cmd "-A${cmake_generator_platform}")
  1899. endif()
  1900. if(cmake_generator_toolset)
  1901. list(APPEND cmd "-T${cmake_generator_toolset}")
  1902. endif()
  1903. else()
  1904. if(CMAKE_EXTRA_GENERATOR)
  1905. list(APPEND cmd "-G${CMAKE_EXTRA_GENERATOR} - ${CMAKE_GENERATOR}")
  1906. else()
  1907. list(APPEND cmd "-G${CMAKE_GENERATOR}")
  1908. endif()
  1909. if(cmake_generator_platform)
  1910. message(FATAL_ERROR "Option CMAKE_GENERATOR_PLATFORM not allowed without CMAKE_GENERATOR.")
  1911. endif()
  1912. if(CMAKE_GENERATOR_PLATFORM)
  1913. list(APPEND cmd "-A${CMAKE_GENERATOR_PLATFORM}")
  1914. endif()
  1915. if(cmake_generator_toolset)
  1916. message(FATAL_ERROR "Option CMAKE_GENERATOR_TOOLSET not allowed without CMAKE_GENERATOR.")
  1917. endif()
  1918. if(CMAKE_GENERATOR_TOOLSET)
  1919. list(APPEND cmd "-T${CMAKE_GENERATOR_TOOLSET}")
  1920. endif()
  1921. endif()
  1922. list(APPEND cmd "${source_dir}")
  1923. endif()
  1924. # If anything about the configure command changes, (command itself, cmake
  1925. # used, cmake args or cmake generator) then re-run the configure step.
  1926. # Fixes issue http://public.kitware.com/Bug/view.php?id=10258
  1927. #
  1928. if(NOT EXISTS ${tmp_dir}/${name}-cfgcmd.txt.in)
  1929. file(WRITE ${tmp_dir}/${name}-cfgcmd.txt.in "cmd='\@cmd\@'\n")
  1930. endif()
  1931. configure_file(${tmp_dir}/${name}-cfgcmd.txt.in ${tmp_dir}/${name}-cfgcmd.txt)
  1932. list(APPEND file_deps ${tmp_dir}/${name}-cfgcmd.txt)
  1933. list(APPEND file_deps ${_ep_cache_args_script})
  1934. get_property(log TARGET ${name} PROPERTY _EP_LOG_CONFIGURE)
  1935. if(log)
  1936. set(log LOG 1)
  1937. else()
  1938. set(log "")
  1939. endif()
  1940. get_property(uses_terminal TARGET ${name} PROPERTY
  1941. _EP_USES_TERMINAL_CONFIGURE)
  1942. if(uses_terminal)
  1943. set(uses_terminal USES_TERMINAL 1)
  1944. else()
  1945. set(uses_terminal "")
  1946. endif()
  1947. get_property(update_disconnected_set TARGET ${name} PROPERTY _EP_UPDATE_DISCONNECTED SET)
  1948. if(update_disconnected_set)
  1949. get_property(update_disconnected TARGET ${name} PROPERTY _EP_UPDATE_DISCONNECTED)
  1950. else()
  1951. get_property(update_disconnected DIRECTORY PROPERTY EP_UPDATE_DISCONNECTED)
  1952. endif()
  1953. if(update_disconnected)
  1954. set(update_dep skip-update)
  1955. else()
  1956. set(update_dep update)
  1957. endif()
  1958. ExternalProject_Add_Step(${name} configure
  1959. COMMAND ${cmd}
  1960. WORKING_DIRECTORY ${binary_dir}
  1961. DEPENDEES ${update_dep} patch
  1962. DEPENDS ${file_deps}
  1963. ${log}
  1964. ${uses_terminal}
  1965. )
  1966. endfunction()
  1967. function(_ep_add_build_command name)
  1968. ExternalProject_Get_Property(${name} binary_dir)
  1969. get_property(cmd_set TARGET ${name} PROPERTY _EP_BUILD_COMMAND SET)
  1970. if(cmd_set)
  1971. get_property(cmd TARGET ${name} PROPERTY _EP_BUILD_COMMAND)
  1972. else()
  1973. _ep_get_build_command(${name} BUILD cmd)
  1974. endif()
  1975. get_property(log TARGET ${name} PROPERTY _EP_LOG_BUILD)
  1976. if(log)
  1977. set(log LOG 1)
  1978. else()
  1979. set(log "")
  1980. endif()
  1981. get_property(uses_terminal TARGET ${name} PROPERTY
  1982. _EP_USES_TERMINAL_BUILD)
  1983. if(uses_terminal)
  1984. set(uses_terminal USES_TERMINAL 1)
  1985. else()
  1986. set(uses_terminal "")
  1987. endif()
  1988. get_property(build_always TARGET ${name} PROPERTY _EP_BUILD_ALWAYS)
  1989. if(build_always)
  1990. set(always 1)
  1991. else()
  1992. set(always 0)
  1993. endif()
  1994. get_property(build_byproducts TARGET ${name} PROPERTY _EP_BUILD_BYPRODUCTS)
  1995. ExternalProject_Add_Step(${name} build
  1996. COMMAND ${cmd}
  1997. BYPRODUCTS ${build_byproducts}
  1998. WORKING_DIRECTORY ${binary_dir}
  1999. DEPENDEES configure
  2000. ALWAYS ${always}
  2001. ${log}
  2002. ${uses_terminal}
  2003. )
  2004. endfunction()
  2005. function(_ep_add_install_command name)
  2006. ExternalProject_Get_Property(${name} binary_dir)
  2007. get_property(cmd_set TARGET ${name} PROPERTY _EP_INSTALL_COMMAND SET)
  2008. if(cmd_set)
  2009. get_property(cmd TARGET ${name} PROPERTY _EP_INSTALL_COMMAND)
  2010. else()
  2011. _ep_get_build_command(${name} INSTALL cmd)
  2012. endif()
  2013. get_property(log TARGET ${name} PROPERTY _EP_LOG_INSTALL)
  2014. if(log)
  2015. set(log LOG 1)
  2016. else()
  2017. set(log "")
  2018. endif()
  2019. get_property(uses_terminal TARGET ${name} PROPERTY
  2020. _EP_USES_TERMINAL_INSTALL)
  2021. if(uses_terminal)
  2022. set(uses_terminal USES_TERMINAL 1)
  2023. else()
  2024. set(uses_terminal "")
  2025. endif()
  2026. ExternalProject_Add_Step(${name} install
  2027. COMMAND ${cmd}
  2028. WORKING_DIRECTORY ${binary_dir}
  2029. DEPENDEES build
  2030. ${log}
  2031. ${uses_terminal}
  2032. )
  2033. endfunction()
  2034. function(_ep_add_test_command name)
  2035. ExternalProject_Get_Property(${name} binary_dir)
  2036. get_property(before TARGET ${name} PROPERTY _EP_TEST_BEFORE_INSTALL)
  2037. get_property(after TARGET ${name} PROPERTY _EP_TEST_AFTER_INSTALL)
  2038. get_property(exclude TARGET ${name} PROPERTY _EP_TEST_EXCLUDE_FROM_MAIN)
  2039. get_property(cmd_set TARGET ${name} PROPERTY _EP_TEST_COMMAND SET)
  2040. # Only actually add the test step if one of the test related properties is
  2041. # explicitly set. (i.e. the test step is omitted unless requested...)
  2042. #
  2043. if(cmd_set OR before OR after OR exclude)
  2044. if(cmd_set)
  2045. get_property(cmd TARGET ${name} PROPERTY _EP_TEST_COMMAND)
  2046. else()
  2047. _ep_get_build_command(${name} TEST cmd)
  2048. endif()
  2049. if(before)
  2050. set(dependees_args DEPENDEES build)
  2051. else()
  2052. set(dependees_args DEPENDEES install)
  2053. endif()
  2054. if(exclude)
  2055. set(dependers_args "")
  2056. set(exclude_args EXCLUDE_FROM_MAIN 1)
  2057. else()
  2058. if(before)
  2059. set(dependers_args DEPENDERS install)
  2060. else()
  2061. set(dependers_args "")
  2062. endif()
  2063. set(exclude_args "")
  2064. endif()
  2065. get_property(log TARGET ${name} PROPERTY _EP_LOG_TEST)
  2066. if(log)
  2067. set(log LOG 1)
  2068. else()
  2069. set(log "")
  2070. endif()
  2071. get_property(uses_terminal TARGET ${name} PROPERTY
  2072. _EP_USES_TERMINAL_TEST)
  2073. if(uses_terminal)
  2074. set(uses_terminal USES_TERMINAL 1)
  2075. else()
  2076. set(uses_terminal "")
  2077. endif()
  2078. ExternalProject_Add_Step(${name} test
  2079. COMMAND ${cmd}
  2080. WORKING_DIRECTORY ${binary_dir}
  2081. ${dependees_args}
  2082. ${dependers_args}
  2083. ${exclude_args}
  2084. ${log}
  2085. ${uses_terminal}
  2086. )
  2087. endif()
  2088. endfunction()
  2089. function(ExternalProject_Add name)
  2090. _ep_get_configuration_subdir_suffix(cfgdir)
  2091. # Add a custom target for the external project.
  2092. set(cmf_dir ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles)
  2093. set(complete_stamp_file "${cmf_dir}${cfgdir}/${name}-complete")
  2094. # The "ALL" option to add_custom_target just tells it to not set the
  2095. # EXCLUDE_FROM_ALL target property. Later, if the EXCLUDE_FROM_ALL
  2096. # argument was passed, we explicitly set it for the target.
  2097. add_custom_target(${name} ALL DEPENDS ${complete_stamp_file})
  2098. set_property(TARGET ${name} PROPERTY _EP_IS_EXTERNAL_PROJECT 1)
  2099. set_property(TARGET ${name} PROPERTY LABELS ${name})
  2100. set_property(TARGET ${name} PROPERTY FOLDER "ExternalProjectTargets/${name}")
  2101. _ep_parse_arguments(ExternalProject_Add ${name} _EP_ "${ARGN}")
  2102. _ep_set_directories(${name})
  2103. _ep_get_step_stampfile(${name} "done" done_stamp_file)
  2104. _ep_get_step_stampfile(${name} "install" install_stamp_file)
  2105. # Set the EXCLUDE_FROM_ALL target property if required.
  2106. get_property(exclude_from_all TARGET ${name} PROPERTY _EP_EXCLUDE_FROM_ALL)
  2107. if(exclude_from_all)
  2108. set_property(TARGET ${name} PROPERTY EXCLUDE_FROM_ALL TRUE)
  2109. endif()
  2110. # The 'complete' step depends on all other steps and creates a
  2111. # 'done' mark. A dependent external project's 'configure' step
  2112. # depends on the 'done' mark so that it rebuilds when this project
  2113. # rebuilds. It is important that 'done' is not the output of any
  2114. # custom command so that CMake does not propagate build rules to
  2115. # other external project targets, which may cause problems during
  2116. # parallel builds. However, the Ninja generator needs to see the entire
  2117. # dependency graph, and can cope with custom commands belonging to
  2118. # multiple targets, so we add the 'done' mark as an output for Ninja only.
  2119. set(complete_outputs ${complete_stamp_file})
  2120. if(${CMAKE_GENERATOR} MATCHES "Ninja")
  2121. set(complete_outputs ${complete_outputs} ${done_stamp_file})
  2122. endif()
  2123. add_custom_command(
  2124. OUTPUT ${complete_outputs}
  2125. COMMENT "Completed '${name}'"
  2126. COMMAND ${CMAKE_COMMAND} -E make_directory ${cmf_dir}${cfgdir}
  2127. COMMAND ${CMAKE_COMMAND} -E touch ${complete_stamp_file}
  2128. COMMAND ${CMAKE_COMMAND} -E touch ${done_stamp_file}
  2129. DEPENDS ${install_stamp_file}
  2130. VERBATIM
  2131. )
  2132. # Depend on other external projects (target-level).
  2133. get_property(deps TARGET ${name} PROPERTY _EP_DEPENDS)
  2134. foreach(arg IN LISTS deps)
  2135. add_dependencies(${name} ${arg})
  2136. endforeach()
  2137. # Set up custom build steps based on the target properties.
  2138. # Each step depends on the previous one.
  2139. #
  2140. # The target depends on the output of the final step.
  2141. # (Already set up above in the DEPENDS of the add_custom_target command.)
  2142. #
  2143. _ep_add_mkdir_command(${name})
  2144. _ep_add_download_command(${name})
  2145. _ep_add_update_command(${name})
  2146. _ep_add_patch_command(${name})
  2147. _ep_add_configure_command(${name})
  2148. _ep_add_build_command(${name})
  2149. _ep_add_install_command(${name})
  2150. # Test is special in that it might depend on build, or it might depend
  2151. # on install.
  2152. #
  2153. _ep_add_test_command(${name})
  2154. endfunction()