ExternalProject.cmake 63 KB

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