ExternalProject.cmake 60 KB

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