ExternalProject.cmake 61 KB

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