ExternalProject.cmake 62 KB

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