ExternalProject.cmake 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808
  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 "set(ENV{VS_UNICODE_OUTPUT} \"\")\n${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(ENV{VS_UNICODE_OUTPUT} \"\")
  879. set(command \"${command}\")
  880. execute_process(
  881. COMMAND \${command}
  882. RESULT_VARIABLE result
  883. OUTPUT_FILE \"${logbase}-out.log\"
  884. ERROR_FILE \"${logbase}-err.log\"
  885. )
  886. if(result)
  887. set(msg \"Command failed: \${result}\\n\")
  888. foreach(arg IN LISTS command)
  889. set(msg \"\${msg} '\${arg}'\")
  890. endforeach()
  891. set(msg \"\${msg}\\nSee also\\n ${logbase}-*.log\\n\")
  892. message(FATAL_ERROR \"\${msg}\")
  893. else()
  894. set(msg \"${name} ${step} command succeeded. See also ${logbase}-*.log\\n\")
  895. message(STATUS \"\${msg}\")
  896. endif()
  897. ")
  898. set(command ${CMAKE_COMMAND} ${make} ${config} -P ${script})
  899. set(${cmd_var} "${command}" PARENT_SCOPE)
  900. endfunction()
  901. # This module used to use "/${CMAKE_CFG_INTDIR}" directly and produced
  902. # makefiles with "/./" in paths for custom command dependencies. Which
  903. # resulted in problems with parallel make -j invocations.
  904. #
  905. # This function was added so that the suffix (search below for ${cfgdir}) is
  906. # only set to "/${CMAKE_CFG_INTDIR}" when ${CMAKE_CFG_INTDIR} is not going to
  907. # be "." (multi-configuration build systems like Visual Studio and Xcode...)
  908. #
  909. function(_ep_get_configuration_subdir_suffix suffix_var)
  910. set(suffix "")
  911. if(CMAKE_CONFIGURATION_TYPES)
  912. set(suffix "/${CMAKE_CFG_INTDIR}")
  913. endif()
  914. set(${suffix_var} "${suffix}" PARENT_SCOPE)
  915. endfunction()
  916. function(_ep_get_step_stampfile name step stampfile_var)
  917. ExternalProject_Get_Property(${name} stamp_dir)
  918. _ep_get_configuration_subdir_suffix(cfgdir)
  919. set(stampfile "${stamp_dir}${cfgdir}/${name}-${step}")
  920. set(${stampfile_var} "${stampfile}" PARENT_SCOPE)
  921. endfunction()
  922. function(ExternalProject_Add_StepTargets name)
  923. set(steps ${ARGN})
  924. foreach(step ${steps})
  925. _ep_get_step_stampfile(${name} ${step} stamp_file)
  926. add_custom_target(${name}-${step}
  927. DEPENDS ${stamp_file})
  928. # Depend on other external projects (target-level).
  929. get_property(deps TARGET ${name} PROPERTY _EP_DEPENDS)
  930. foreach(arg IN LISTS deps)
  931. add_dependencies(${name}-${step} ${arg})
  932. endforeach()
  933. endforeach()
  934. endfunction()
  935. function(ExternalProject_Add_Step name step)
  936. set(cmf_dir ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles)
  937. _ep_get_configuration_subdir_suffix(cfgdir)
  938. set(complete_stamp_file "${cmf_dir}${cfgdir}/${name}-complete")
  939. _ep_get_step_stampfile(${name} ${step} stamp_file)
  940. add_custom_command(APPEND
  941. OUTPUT ${complete_stamp_file}
  942. DEPENDS ${stamp_file}
  943. )
  944. _ep_parse_arguments(ExternalProject_Add_Step
  945. ${name} _EP_${step}_ "${ARGN}")
  946. # Steps depending on this step.
  947. get_property(dependers TARGET ${name} PROPERTY _EP_${step}_DEPENDERS)
  948. foreach(depender IN LISTS dependers)
  949. _ep_get_step_stampfile(${name} ${depender} depender_stamp_file)
  950. add_custom_command(APPEND
  951. OUTPUT ${depender_stamp_file}
  952. DEPENDS ${stamp_file}
  953. )
  954. endforeach()
  955. # Dependencies on files.
  956. get_property(depends TARGET ${name} PROPERTY _EP_${step}_DEPENDS)
  957. # Dependencies on steps.
  958. get_property(dependees TARGET ${name} PROPERTY _EP_${step}_DEPENDEES)
  959. foreach(dependee IN LISTS dependees)
  960. _ep_get_step_stampfile(${name} ${dependee} dependee_stamp_file)
  961. list(APPEND depends ${dependee_stamp_file})
  962. endforeach()
  963. # The command to run.
  964. get_property(command TARGET ${name} PROPERTY _EP_${step}_COMMAND)
  965. if(command)
  966. set(comment "Performing ${step} step for '${name}'")
  967. else()
  968. set(comment "No ${step} step for '${name}'")
  969. endif()
  970. get_property(work_dir TARGET ${name} PROPERTY _EP_${step}_WORKING_DIRECTORY)
  971. # Replace list separators.
  972. get_property(sep TARGET ${name} PROPERTY _EP_LIST_SEPARATOR)
  973. if(sep AND command)
  974. string(REPLACE "${sep}" "\\;" command "${command}")
  975. endif()
  976. # Replace location tags.
  977. _ep_replace_location_tags(${name} comment command work_dir)
  978. # Custom comment?
  979. get_property(comment_set TARGET ${name} PROPERTY _EP_${step}_COMMENT SET)
  980. if(comment_set)
  981. get_property(comment TARGET ${name} PROPERTY _EP_${step}_COMMENT)
  982. endif()
  983. # Run every time?
  984. get_property(always TARGET ${name} PROPERTY _EP_${step}_ALWAYS)
  985. if(always)
  986. set_property(SOURCE ${stamp_file} PROPERTY SYMBOLIC 1)
  987. set(touch)
  988. else()
  989. set(touch ${CMAKE_COMMAND} -E touch ${stamp_file})
  990. endif()
  991. # Wrap with log script?
  992. get_property(log TARGET ${name} PROPERTY _EP_${step}_LOG)
  993. if(command AND log)
  994. _ep_write_log_script(${name} ${step} command)
  995. endif()
  996. add_custom_command(
  997. OUTPUT ${stamp_file}
  998. COMMENT ${comment}
  999. COMMAND ${command}
  1000. COMMAND ${touch}
  1001. DEPENDS ${depends}
  1002. WORKING_DIRECTORY ${work_dir}
  1003. VERBATIM
  1004. )
  1005. # Add custom "step target"?
  1006. get_property(step_targets TARGET ${name} PROPERTY _EP_STEP_TARGETS)
  1007. if(NOT step_targets)
  1008. get_property(step_targets DIRECTORY PROPERTY EP_STEP_TARGETS)
  1009. endif()
  1010. foreach(st ${step_targets})
  1011. if("${st}" STREQUAL "${step}")
  1012. ExternalProject_Add_StepTargets(${name} ${step})
  1013. break()
  1014. endif()
  1015. endforeach()
  1016. endfunction()
  1017. function(_ep_add_mkdir_command name)
  1018. ExternalProject_Get_Property(${name}
  1019. source_dir binary_dir install_dir stamp_dir download_dir tmp_dir)
  1020. _ep_get_configuration_subdir_suffix(cfgdir)
  1021. ExternalProject_Add_Step(${name} mkdir
  1022. COMMENT "Creating directories for '${name}'"
  1023. COMMAND ${CMAKE_COMMAND} -E make_directory ${source_dir}
  1024. COMMAND ${CMAKE_COMMAND} -E make_directory ${binary_dir}
  1025. COMMAND ${CMAKE_COMMAND} -E make_directory ${install_dir}
  1026. COMMAND ${CMAKE_COMMAND} -E make_directory ${tmp_dir}
  1027. COMMAND ${CMAKE_COMMAND} -E make_directory ${stamp_dir}${cfgdir}
  1028. COMMAND ${CMAKE_COMMAND} -E make_directory ${download_dir}
  1029. )
  1030. endfunction()
  1031. function(_ep_get_git_version git_EXECUTABLE git_version_var)
  1032. if(git_EXECUTABLE)
  1033. execute_process(
  1034. COMMAND "${git_EXECUTABLE}" --version
  1035. OUTPUT_VARIABLE ov
  1036. ERROR_VARIABLE ev
  1037. OUTPUT_STRIP_TRAILING_WHITESPACE
  1038. )
  1039. string(REGEX REPLACE "^git version (.+)$" "\\1" version "${ov}")
  1040. set(${git_version_var} "${version}" PARENT_SCOPE)
  1041. endif()
  1042. endfunction()
  1043. function(_ep_is_dir_empty dir empty_var)
  1044. file(GLOB gr "${dir}/*")
  1045. if("${gr}" STREQUAL "")
  1046. set(${empty_var} 1 PARENT_SCOPE)
  1047. else()
  1048. set(${empty_var} 0 PARENT_SCOPE)
  1049. endif()
  1050. endfunction()
  1051. function(_ep_add_download_command name)
  1052. ExternalProject_Get_Property(${name} source_dir stamp_dir download_dir tmp_dir)
  1053. get_property(cmd_set TARGET ${name} PROPERTY _EP_DOWNLOAD_COMMAND SET)
  1054. get_property(cmd TARGET ${name} PROPERTY _EP_DOWNLOAD_COMMAND)
  1055. get_property(cvs_repository TARGET ${name} PROPERTY _EP_CVS_REPOSITORY)
  1056. get_property(svn_repository TARGET ${name} PROPERTY _EP_SVN_REPOSITORY)
  1057. get_property(git_repository TARGET ${name} PROPERTY _EP_GIT_REPOSITORY)
  1058. get_property(hg_repository TARGET ${name} PROPERTY _EP_HG_REPOSITORY )
  1059. get_property(url TARGET ${name} PROPERTY _EP_URL)
  1060. get_property(fname TARGET ${name} PROPERTY _EP_DOWNLOAD_NAME)
  1061. # TODO: Perhaps file:// should be copied to download dir before extraction.
  1062. string(REGEX REPLACE "^file://" "" url "${url}")
  1063. set(depends)
  1064. set(comment)
  1065. set(work_dir)
  1066. if(cmd_set)
  1067. set(work_dir ${download_dir})
  1068. elseif(cvs_repository)
  1069. find_package(CVS)
  1070. if(NOT CVS_EXECUTABLE)
  1071. message(FATAL_ERROR "error: could not find cvs for checkout of ${name}")
  1072. endif()
  1073. get_target_property(cvs_module ${name} _EP_CVS_MODULE)
  1074. if(NOT cvs_module)
  1075. message(FATAL_ERROR "error: no CVS_MODULE")
  1076. endif()
  1077. get_property(cvs_tag TARGET ${name} PROPERTY _EP_CVS_TAG)
  1078. set(repository ${cvs_repository})
  1079. set(module ${cvs_module})
  1080. set(tag ${cvs_tag})
  1081. configure_file(
  1082. "${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in"
  1083. "${stamp_dir}/${name}-cvsinfo.txt"
  1084. @ONLY
  1085. )
  1086. get_filename_component(src_name "${source_dir}" NAME)
  1087. get_filename_component(work_dir "${source_dir}" PATH)
  1088. set(comment "Performing download step (CVS checkout) for '${name}'")
  1089. set(cmd ${CVS_EXECUTABLE} -d ${cvs_repository} -q co ${cvs_tag} -d ${src_name} ${cvs_module})
  1090. list(APPEND depends ${stamp_dir}/${name}-cvsinfo.txt)
  1091. elseif(svn_repository)
  1092. find_package(Subversion)
  1093. if(NOT Subversion_SVN_EXECUTABLE)
  1094. message(FATAL_ERROR "error: could not find svn for checkout of ${name}")
  1095. endif()
  1096. get_property(svn_revision TARGET ${name} PROPERTY _EP_SVN_REVISION)
  1097. get_property(svn_username TARGET ${name} PROPERTY _EP_SVN_USERNAME)
  1098. get_property(svn_password TARGET ${name} PROPERTY _EP_SVN_PASSWORD)
  1099. get_property(svn_trust_cert TARGET ${name} PROPERTY _EP_SVN_TRUST_CERT)
  1100. set(repository "${svn_repository} user=${svn_username} password=${svn_password}")
  1101. set(module)
  1102. set(tag ${svn_revision})
  1103. configure_file(
  1104. "${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in"
  1105. "${stamp_dir}/${name}-svninfo.txt"
  1106. @ONLY
  1107. )
  1108. get_filename_component(src_name "${source_dir}" NAME)
  1109. get_filename_component(work_dir "${source_dir}" PATH)
  1110. set(comment "Performing download step (SVN checkout) for '${name}'")
  1111. set(svn_user_pw_args "")
  1112. if(DEFINED svn_username)
  1113. set(svn_user_pw_args ${svn_user_pw_args} "--username=${svn_username}")
  1114. endif()
  1115. if(DEFINED svn_password)
  1116. set(svn_user_pw_args ${svn_user_pw_args} "--password=${svn_password}")
  1117. endif()
  1118. if(svn_trust_cert)
  1119. set(svn_trust_cert_args --trust-server-cert)
  1120. endif()
  1121. set(cmd ${Subversion_SVN_EXECUTABLE} co ${svn_repository} ${svn_revision}
  1122. --non-interactive ${svn_trust_cert_args} ${svn_user_pw_args} ${src_name})
  1123. list(APPEND depends ${stamp_dir}/${name}-svninfo.txt)
  1124. elseif(git_repository)
  1125. find_package(Git)
  1126. if(NOT GIT_EXECUTABLE)
  1127. message(FATAL_ERROR "error: could not find git for clone of ${name}")
  1128. endif()
  1129. # The git submodule update '--recursive' flag requires git >= v1.6.5
  1130. #
  1131. _ep_get_git_version("${GIT_EXECUTABLE}" git_version)
  1132. if(git_version VERSION_LESS 1.6.5)
  1133. message(FATAL_ERROR "error: git version 1.6.5 or later required for 'git submodule update --recursive': git_version='${git_version}'")
  1134. endif()
  1135. get_property(git_tag TARGET ${name} PROPERTY _EP_GIT_TAG)
  1136. if(NOT git_tag)
  1137. set(git_tag "master")
  1138. endif()
  1139. # For the download step, and the git clone operation, only the repository
  1140. # should be recorded in a configured RepositoryInfo file. If the repo
  1141. # changes, the clone script should be run again. But if only the tag
  1142. # changes, avoid running the clone script again. Let the 'always' running
  1143. # update step checkout the new tag.
  1144. #
  1145. set(repository ${git_repository})
  1146. set(module)
  1147. set(tag)
  1148. configure_file(
  1149. "${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in"
  1150. "${stamp_dir}/${name}-gitinfo.txt"
  1151. @ONLY
  1152. )
  1153. get_filename_component(src_name "${source_dir}" NAME)
  1154. get_filename_component(work_dir "${source_dir}" PATH)
  1155. # Since git clone doesn't succeed if the non-empty source_dir exists,
  1156. # create a cmake script to invoke as download command.
  1157. # The script will delete the source directory and then call git clone.
  1158. #
  1159. _ep_write_gitclone_script(${tmp_dir}/${name}-gitclone.cmake ${source_dir}
  1160. ${GIT_EXECUTABLE} ${git_repository} ${git_tag} ${src_name} ${work_dir}
  1161. ${stamp_dir}/${name}-gitinfo.txt ${stamp_dir}/${name}-gitclone-lastrun.txt
  1162. )
  1163. set(comment "Performing download step (git clone) for '${name}'")
  1164. set(cmd ${CMAKE_COMMAND} -P ${tmp_dir}/${name}-gitclone.cmake)
  1165. list(APPEND depends ${stamp_dir}/${name}-gitinfo.txt)
  1166. elseif(hg_repository)
  1167. find_package(Hg)
  1168. if(NOT HG_EXECUTABLE)
  1169. message(FATAL_ERROR "error: could not find hg for clone of ${name}")
  1170. endif()
  1171. get_property(hg_tag TARGET ${name} PROPERTY _EP_HG_TAG)
  1172. if(NOT hg_tag)
  1173. set(hg_tag "tip")
  1174. endif()
  1175. # For the download step, and the hg clone operation, only the repository
  1176. # should be recorded in a configured RepositoryInfo file. If the repo
  1177. # changes, the clone script should be run again. But if only the tag
  1178. # changes, avoid running the clone script again. Let the 'always' running
  1179. # update step checkout the new tag.
  1180. #
  1181. set(repository ${hg_repository})
  1182. set(module)
  1183. set(tag)
  1184. configure_file(
  1185. "${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in"
  1186. "${stamp_dir}/${name}-hginfo.txt"
  1187. @ONLY
  1188. )
  1189. get_filename_component(src_name "${source_dir}" NAME)
  1190. get_filename_component(work_dir "${source_dir}" PATH)
  1191. # Since hg clone doesn't succeed if the non-empty source_dir exists,
  1192. # create a cmake script to invoke as download command.
  1193. # The script will delete the source directory and then call hg clone.
  1194. #
  1195. _ep_write_hgclone_script(${tmp_dir}/${name}-hgclone.cmake ${source_dir}
  1196. ${HG_EXECUTABLE} ${hg_repository} ${hg_tag} ${src_name} ${work_dir}
  1197. ${stamp_dir}/${name}-hginfo.txt ${stamp_dir}/${name}-hgclone-lastrun.txt
  1198. )
  1199. set(comment "Performing download step (hg clone) for '${name}'")
  1200. set(cmd ${CMAKE_COMMAND} -P ${tmp_dir}/${name}-hgclone.cmake)
  1201. list(APPEND depends ${stamp_dir}/${name}-hginfo.txt)
  1202. elseif(url)
  1203. get_filename_component(work_dir "${source_dir}" PATH)
  1204. get_property(hash TARGET ${name} PROPERTY _EP_URL_HASH)
  1205. if(hash AND NOT "${hash}" MATCHES "${_ep_hash_regex}")
  1206. message(FATAL_ERROR "URL_HASH is set to\n ${hash}\n"
  1207. "but must be ALGO=value where ALGO is\n ${_ep_hash_algos}\n"
  1208. "and value is a hex string.")
  1209. endif()
  1210. get_property(md5 TARGET ${name} PROPERTY _EP_URL_MD5)
  1211. if(md5 AND NOT "MD5=${md5}" MATCHES "${_ep_hash_regex}")
  1212. message(FATAL_ERROR "URL_MD5 is set to\n ${md5}\nbut must be a hex string.")
  1213. endif()
  1214. if(md5 AND NOT hash)
  1215. set(hash "MD5=${md5}")
  1216. endif()
  1217. set(repository "external project URL")
  1218. set(module "${url}")
  1219. set(tag "${hash}")
  1220. configure_file(
  1221. "${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in"
  1222. "${stamp_dir}/${name}-urlinfo.txt"
  1223. @ONLY
  1224. )
  1225. list(APPEND depends ${stamp_dir}/${name}-urlinfo.txt)
  1226. if(IS_DIRECTORY "${url}")
  1227. get_filename_component(abs_dir "${url}" ABSOLUTE)
  1228. set(comment "Performing download step (DIR copy) for '${name}'")
  1229. set(cmd ${CMAKE_COMMAND} -E remove_directory ${source_dir}
  1230. COMMAND ${CMAKE_COMMAND} -E copy_directory ${abs_dir} ${source_dir})
  1231. else()
  1232. if("${url}" MATCHES "^[a-z]+://")
  1233. # TODO: Should download and extraction be different steps?
  1234. if("x${fname}" STREQUAL "x")
  1235. string(REGEX MATCH "[^/\\?]*$" fname "${url}")
  1236. endif()
  1237. if(NOT "${fname}" MATCHES "(\\.|=)(bz2|tar|tgz|tar\\.gz|zip)$")
  1238. string(REGEX MATCH "([^/\\?]+(\\.|=)(bz2|tar|tgz|tar\\.gz|zip))/.*$" match_result "${url}")
  1239. set(fname "${CMAKE_MATCH_1}")
  1240. endif()
  1241. if(NOT "${fname}" MATCHES "(\\.|=)(bz2|tar|tgz|tar\\.gz|zip)$")
  1242. message(FATAL_ERROR "Could not extract tarball filename from url:\n ${url}")
  1243. endif()
  1244. string(REPLACE ";" "-" fname "${fname}")
  1245. set(file ${download_dir}/${fname})
  1246. get_property(timeout TARGET ${name} PROPERTY _EP_TIMEOUT)
  1247. get_property(tls_verify TARGET ${name} PROPERTY _EP_TLS_VERIFY)
  1248. get_property(tls_cainfo TARGET ${name} PROPERTY _EP_TLS_CAINFO)
  1249. _ep_write_downloadfile_script("${stamp_dir}/download-${name}.cmake"
  1250. "${url}" "${file}" "${timeout}" "${hash}" "${tls_verify}" "${tls_cainfo}")
  1251. set(cmd ${CMAKE_COMMAND} -P ${stamp_dir}/download-${name}.cmake
  1252. COMMAND)
  1253. set(comment "Performing download step (download, verify and extract) for '${name}'")
  1254. else()
  1255. set(file "${url}")
  1256. set(comment "Performing download step (verify and extract) for '${name}'")
  1257. endif()
  1258. _ep_write_verifyfile_script("${stamp_dir}/verify-${name}.cmake" "${file}" "${hash}")
  1259. list(APPEND cmd ${CMAKE_COMMAND} -P ${stamp_dir}/verify-${name}.cmake
  1260. COMMAND)
  1261. _ep_write_extractfile_script("${stamp_dir}/extract-${name}.cmake" "${name}" "${file}" "${source_dir}")
  1262. list(APPEND cmd ${CMAKE_COMMAND} -P ${stamp_dir}/extract-${name}.cmake)
  1263. endif()
  1264. else()
  1265. _ep_is_dir_empty("${source_dir}" empty)
  1266. if(${empty})
  1267. 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")
  1268. endif()
  1269. endif()
  1270. get_property(log TARGET ${name} PROPERTY _EP_LOG_DOWNLOAD)
  1271. if(log)
  1272. set(log LOG 1)
  1273. else()
  1274. set(log "")
  1275. endif()
  1276. ExternalProject_Add_Step(${name} download
  1277. COMMENT ${comment}
  1278. COMMAND ${cmd}
  1279. WORKING_DIRECTORY ${work_dir}
  1280. DEPENDS ${depends}
  1281. DEPENDEES mkdir
  1282. ${log}
  1283. )
  1284. endfunction()
  1285. function(_ep_add_update_command name)
  1286. ExternalProject_Get_Property(${name} source_dir tmp_dir)
  1287. get_property(cmd_set TARGET ${name} PROPERTY _EP_UPDATE_COMMAND SET)
  1288. get_property(cmd TARGET ${name} PROPERTY _EP_UPDATE_COMMAND)
  1289. get_property(cvs_repository TARGET ${name} PROPERTY _EP_CVS_REPOSITORY)
  1290. get_property(svn_repository TARGET ${name} PROPERTY _EP_SVN_REPOSITORY)
  1291. get_property(git_repository TARGET ${name} PROPERTY _EP_GIT_REPOSITORY)
  1292. get_property(hg_repository TARGET ${name} PROPERTY _EP_HG_REPOSITORY )
  1293. set(work_dir)
  1294. set(comment)
  1295. set(always)
  1296. if(cmd_set)
  1297. set(work_dir ${source_dir})
  1298. elseif(cvs_repository)
  1299. if(NOT CVS_EXECUTABLE)
  1300. message(FATAL_ERROR "error: could not find cvs for update of ${name}")
  1301. endif()
  1302. set(work_dir ${source_dir})
  1303. set(comment "Performing update step (CVS update) for '${name}'")
  1304. get_property(cvs_tag TARGET ${name} PROPERTY _EP_CVS_TAG)
  1305. set(cmd ${CVS_EXECUTABLE} -d ${cvs_repository} -q up -dP ${cvs_tag})
  1306. set(always 1)
  1307. elseif(svn_repository)
  1308. if(NOT Subversion_SVN_EXECUTABLE)
  1309. message(FATAL_ERROR "error: could not find svn for update of ${name}")
  1310. endif()
  1311. set(work_dir ${source_dir})
  1312. set(comment "Performing update step (SVN update) for '${name}'")
  1313. get_property(svn_revision TARGET ${name} PROPERTY _EP_SVN_REVISION)
  1314. get_property(svn_username TARGET ${name} PROPERTY _EP_SVN_USERNAME)
  1315. get_property(svn_password TARGET ${name} PROPERTY _EP_SVN_PASSWORD)
  1316. get_property(svn_trust_cert TARGET ${name} PROPERTY _EP_SVN_TRUST_CERT)
  1317. set(svn_user_pw_args "")
  1318. if(DEFINED svn_username)
  1319. set(svn_user_pw_args ${svn_user_pw_args} "--username=${svn_username}")
  1320. endif()
  1321. if(DEFINED svn_password)
  1322. set(svn_user_pw_args ${svn_user_pw_args} "--password=${svn_password}")
  1323. endif()
  1324. if(svn_trust_cert)
  1325. set(svn_trust_cert_args --trust-server-cert)
  1326. endif()
  1327. set(cmd ${Subversion_SVN_EXECUTABLE} up ${svn_revision}
  1328. --non-interactive ${svn_trust_cert_args} ${svn_user_pw_args})
  1329. set(always 1)
  1330. elseif(git_repository)
  1331. if(NOT GIT_EXECUTABLE)
  1332. message(FATAL_ERROR "error: could not find git for fetch of ${name}")
  1333. endif()
  1334. set(work_dir ${source_dir})
  1335. set(comment "Performing update step for '${name}'")
  1336. get_property(git_tag TARGET ${name} PROPERTY _EP_GIT_TAG)
  1337. if(NOT git_tag)
  1338. set(git_tag "master")
  1339. endif()
  1340. _ep_write_gitupdate_script(${tmp_dir}/${name}-gitupdate.cmake
  1341. ${GIT_EXECUTABLE} ${git_tag} ${git_repository} ${work_dir}
  1342. )
  1343. set(cmd ${CMAKE_COMMAND} -P ${tmp_dir}/${name}-gitupdate.cmake)
  1344. set(always 1)
  1345. elseif(hg_repository)
  1346. if(NOT HG_EXECUTABLE)
  1347. message(FATAL_ERROR "error: could not find hg for pull of ${name}")
  1348. endif()
  1349. set(work_dir ${source_dir})
  1350. set(comment "Performing update step (hg pull) for '${name}'")
  1351. get_property(hg_tag TARGET ${name} PROPERTY _EP_HG_TAG)
  1352. if(NOT hg_tag)
  1353. set(hg_tag "tip")
  1354. endif()
  1355. if("${HG_VERSION_STRING}" STREQUAL "2.1")
  1356. message(WARNING "Mercurial 2.1 does not distinguish an empty pull from a failed pull:
  1357. http://mercurial.selenic.com/wiki/UpgradeNotes#A2.1.1:_revert_pull_return_code_change.2C_compile_issue_on_OS_X
  1358. http://thread.gmane.org/gmane.comp.version-control.mercurial.devel/47656
  1359. Update to Mercurial >= 2.1.1.
  1360. ")
  1361. endif()
  1362. set(cmd ${HG_EXECUTABLE} pull
  1363. COMMAND ${HG_EXECUTABLE} update ${hg_tag}
  1364. )
  1365. set(always 1)
  1366. endif()
  1367. get_property(log TARGET ${name} PROPERTY _EP_LOG_UPDATE)
  1368. if(log)
  1369. set(log LOG 1)
  1370. else()
  1371. set(log "")
  1372. endif()
  1373. ExternalProject_Add_Step(${name} update
  1374. COMMENT ${comment}
  1375. COMMAND ${cmd}
  1376. ALWAYS ${always}
  1377. WORKING_DIRECTORY ${work_dir}
  1378. DEPENDEES download
  1379. ${log}
  1380. )
  1381. endfunction()
  1382. function(_ep_add_patch_command name)
  1383. ExternalProject_Get_Property(${name} source_dir)
  1384. get_property(cmd_set TARGET ${name} PROPERTY _EP_PATCH_COMMAND SET)
  1385. get_property(cmd TARGET ${name} PROPERTY _EP_PATCH_COMMAND)
  1386. set(work_dir)
  1387. if(cmd_set)
  1388. set(work_dir ${source_dir})
  1389. endif()
  1390. ExternalProject_Add_Step(${name} patch
  1391. COMMAND ${cmd}
  1392. WORKING_DIRECTORY ${work_dir}
  1393. DEPENDEES download
  1394. )
  1395. endfunction()
  1396. # TODO: Make sure external projects use the proper compiler
  1397. function(_ep_add_configure_command name)
  1398. ExternalProject_Get_Property(${name} source_dir binary_dir tmp_dir)
  1399. # Depend on other external projects (file-level).
  1400. set(file_deps)
  1401. get_property(deps TARGET ${name} PROPERTY _EP_DEPENDS)
  1402. foreach(dep IN LISTS deps)
  1403. get_property(is_ep TARGET ${dep} PROPERTY _EP_IS_EXTERNAL_PROJECT)
  1404. if(is_ep)
  1405. _ep_get_step_stampfile(${dep} "done" done_stamp_file)
  1406. list(APPEND file_deps ${done_stamp_file})
  1407. endif()
  1408. endforeach()
  1409. get_property(cmd_set TARGET ${name} PROPERTY _EP_CONFIGURE_COMMAND SET)
  1410. if(cmd_set)
  1411. get_property(cmd TARGET ${name} PROPERTY _EP_CONFIGURE_COMMAND)
  1412. else()
  1413. get_target_property(cmake_command ${name} _EP_CMAKE_COMMAND)
  1414. if(cmake_command)
  1415. set(cmd "${cmake_command}")
  1416. else()
  1417. set(cmd "${CMAKE_COMMAND}")
  1418. endif()
  1419. get_property(cmake_args TARGET ${name} PROPERTY _EP_CMAKE_ARGS)
  1420. list(APPEND cmd ${cmake_args})
  1421. # If there are any CMAKE_CACHE_ARGS, write an initial cache and use it
  1422. get_property(cmake_cache_args TARGET ${name} PROPERTY _EP_CMAKE_CACHE_ARGS)
  1423. if(cmake_cache_args)
  1424. set(_ep_cache_args_script "${tmp_dir}/${name}-cache.cmake")
  1425. _ep_write_initial_cache(${name} "${_ep_cache_args_script}" "${cmake_cache_args}")
  1426. list(APPEND cmd "-C${_ep_cache_args_script}")
  1427. endif()
  1428. get_target_property(cmake_generator ${name} _EP_CMAKE_GENERATOR)
  1429. get_target_property(cmake_generator_toolset ${name} _EP_CMAKE_GENERATOR_TOOLSET)
  1430. if(cmake_generator)
  1431. list(APPEND cmd "-G${cmake_generator}")
  1432. if(cmake_generator_toolset)
  1433. list(APPEND cmd "-T${cmake_generator_toolset}")
  1434. endif()
  1435. else()
  1436. if(CMAKE_EXTRA_GENERATOR)
  1437. list(APPEND cmd "-G${CMAKE_EXTRA_GENERATOR} - ${CMAKE_GENERATOR}")
  1438. else()
  1439. list(APPEND cmd "-G${CMAKE_GENERATOR}")
  1440. endif()
  1441. if(cmake_generator_toolset)
  1442. message(FATAL_ERROR "Option CMAKE_GENERATOR_TOOLSET not allowed without CMAKE_GENERATOR.")
  1443. endif()
  1444. if(CMAKE_GENERATOR_TOOLSET)
  1445. list(APPEND cmd "-T${CMAKE_GENERATOR_TOOLSET}")
  1446. endif()
  1447. endif()
  1448. list(APPEND cmd "${source_dir}")
  1449. endif()
  1450. # If anything about the configure command changes, (command itself, cmake
  1451. # used, cmake args or cmake generator) then re-run the configure step.
  1452. # Fixes issue http://public.kitware.com/Bug/view.php?id=10258
  1453. #
  1454. if(NOT EXISTS ${tmp_dir}/${name}-cfgcmd.txt.in)
  1455. file(WRITE ${tmp_dir}/${name}-cfgcmd.txt.in "cmd='\@cmd\@'\n")
  1456. endif()
  1457. configure_file(${tmp_dir}/${name}-cfgcmd.txt.in ${tmp_dir}/${name}-cfgcmd.txt)
  1458. list(APPEND file_deps ${tmp_dir}/${name}-cfgcmd.txt)
  1459. list(APPEND file_deps ${_ep_cache_args_script})
  1460. get_property(log TARGET ${name} PROPERTY _EP_LOG_CONFIGURE)
  1461. if(log)
  1462. set(log LOG 1)
  1463. else()
  1464. set(log "")
  1465. endif()
  1466. ExternalProject_Add_Step(${name} configure
  1467. COMMAND ${cmd}
  1468. WORKING_DIRECTORY ${binary_dir}
  1469. DEPENDEES update patch
  1470. DEPENDS ${file_deps}
  1471. ${log}
  1472. )
  1473. endfunction()
  1474. function(_ep_add_build_command name)
  1475. ExternalProject_Get_Property(${name} binary_dir)
  1476. get_property(cmd_set TARGET ${name} PROPERTY _EP_BUILD_COMMAND SET)
  1477. if(cmd_set)
  1478. get_property(cmd TARGET ${name} PROPERTY _EP_BUILD_COMMAND)
  1479. else()
  1480. _ep_get_build_command(${name} BUILD cmd)
  1481. endif()
  1482. get_property(log TARGET ${name} PROPERTY _EP_LOG_BUILD)
  1483. if(log)
  1484. set(log LOG 1)
  1485. else()
  1486. set(log "")
  1487. endif()
  1488. ExternalProject_Add_Step(${name} build
  1489. COMMAND ${cmd}
  1490. WORKING_DIRECTORY ${binary_dir}
  1491. DEPENDEES configure
  1492. ${log}
  1493. )
  1494. endfunction()
  1495. function(_ep_add_install_command name)
  1496. ExternalProject_Get_Property(${name} binary_dir)
  1497. get_property(cmd_set TARGET ${name} PROPERTY _EP_INSTALL_COMMAND SET)
  1498. if(cmd_set)
  1499. get_property(cmd TARGET ${name} PROPERTY _EP_INSTALL_COMMAND)
  1500. else()
  1501. _ep_get_build_command(${name} INSTALL cmd)
  1502. endif()
  1503. get_property(log TARGET ${name} PROPERTY _EP_LOG_INSTALL)
  1504. if(log)
  1505. set(log LOG 1)
  1506. else()
  1507. set(log "")
  1508. endif()
  1509. ExternalProject_Add_Step(${name} install
  1510. COMMAND ${cmd}
  1511. WORKING_DIRECTORY ${binary_dir}
  1512. DEPENDEES build
  1513. ${log}
  1514. )
  1515. endfunction()
  1516. function(_ep_add_test_command name)
  1517. ExternalProject_Get_Property(${name} binary_dir)
  1518. get_property(before TARGET ${name} PROPERTY _EP_TEST_BEFORE_INSTALL)
  1519. get_property(after TARGET ${name} PROPERTY _EP_TEST_AFTER_INSTALL)
  1520. get_property(cmd_set TARGET ${name} PROPERTY _EP_TEST_COMMAND SET)
  1521. # Only actually add the test step if one of the test related properties is
  1522. # explicitly set. (i.e. the test step is omitted unless requested...)
  1523. #
  1524. if(cmd_set OR before OR after)
  1525. if(cmd_set)
  1526. get_property(cmd TARGET ${name} PROPERTY _EP_TEST_COMMAND)
  1527. else()
  1528. _ep_get_build_command(${name} TEST cmd)
  1529. endif()
  1530. if(before)
  1531. set(dep_args DEPENDEES build DEPENDERS install)
  1532. else()
  1533. set(dep_args DEPENDEES install)
  1534. endif()
  1535. get_property(log TARGET ${name} PROPERTY _EP_LOG_TEST)
  1536. if(log)
  1537. set(log LOG 1)
  1538. else()
  1539. set(log "")
  1540. endif()
  1541. ExternalProject_Add_Step(${name} test
  1542. COMMAND ${cmd}
  1543. WORKING_DIRECTORY ${binary_dir}
  1544. ${dep_args}
  1545. ${log}
  1546. )
  1547. endif()
  1548. endfunction()
  1549. function(ExternalProject_Add name)
  1550. _ep_get_configuration_subdir_suffix(cfgdir)
  1551. # Add a custom target for the external project.
  1552. set(cmf_dir ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles)
  1553. set(complete_stamp_file "${cmf_dir}${cfgdir}/${name}-complete")
  1554. add_custom_target(${name} ALL DEPENDS ${complete_stamp_file})
  1555. set_property(TARGET ${name} PROPERTY _EP_IS_EXTERNAL_PROJECT 1)
  1556. _ep_parse_arguments(ExternalProject_Add ${name} _EP_ "${ARGN}")
  1557. _ep_set_directories(${name})
  1558. _ep_get_step_stampfile(${name} "done" done_stamp_file)
  1559. _ep_get_step_stampfile(${name} "install" install_stamp_file)
  1560. # The 'complete' step depends on all other steps and creates a
  1561. # 'done' mark. A dependent external project's 'configure' step
  1562. # depends on the 'done' mark so that it rebuilds when this project
  1563. # rebuilds. It is important that 'done' is not the output of any
  1564. # custom command so that CMake does not propagate build rules to
  1565. # other external project targets, which may cause problems during
  1566. # parallel builds. However, the Ninja generator needs to see the entire
  1567. # dependency graph, and can cope with custom commands belonging to
  1568. # multiple targets, so we add the 'done' mark as an output for Ninja only.
  1569. set(complete_outputs ${complete_stamp_file})
  1570. if(${CMAKE_GENERATOR} MATCHES "Ninja")
  1571. set(complete_outputs ${complete_outputs} ${done_stamp_file})
  1572. endif()
  1573. add_custom_command(
  1574. OUTPUT ${complete_outputs}
  1575. COMMENT "Completed '${name}'"
  1576. COMMAND ${CMAKE_COMMAND} -E make_directory ${cmf_dir}${cfgdir}
  1577. COMMAND ${CMAKE_COMMAND} -E touch ${complete_stamp_file}
  1578. COMMAND ${CMAKE_COMMAND} -E touch ${done_stamp_file}
  1579. DEPENDS ${install_stamp_file}
  1580. VERBATIM
  1581. )
  1582. # Depend on other external projects (target-level).
  1583. get_property(deps TARGET ${name} PROPERTY _EP_DEPENDS)
  1584. foreach(arg IN LISTS deps)
  1585. add_dependencies(${name} ${arg})
  1586. endforeach()
  1587. # Set up custom build steps based on the target properties.
  1588. # Each step depends on the previous one.
  1589. #
  1590. # The target depends on the output of the final step.
  1591. # (Already set up above in the DEPENDS of the add_custom_target command.)
  1592. #
  1593. _ep_add_mkdir_command(${name})
  1594. _ep_add_download_command(${name})
  1595. _ep_add_update_command(${name})
  1596. _ep_add_patch_command(${name})
  1597. _ep_add_configure_command(${name})
  1598. _ep_add_build_command(${name})
  1599. _ep_add_install_command(${name})
  1600. # Test is special in that it might depend on build, or it might depend
  1601. # on install.
  1602. #
  1603. _ep_add_test_command(${name})
  1604. endfunction()