ExternalProject.cmake 77 KB

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