ExternalProject.cmake 56 KB

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