ExternalProject.cmake 62 KB

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