ExternalProject.cmake 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088
  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 to use for Subversion checkout and update
  20. # [SVN_PASSWORD doe ] # Password to use for Subversion checkout and update
  21. # [GIT_REPOSITORY url] # URL of GIT repo
  22. # [GIT_TAG tag] # Git branch name, commit id or tag
  23. # [URL /.../src.tgz] # Full path or URL of source
  24. # [TIMEOUT seconds] # Time allowed for file download operations
  25. # #--Update/Patch step----------
  26. # [UPDATE_COMMAND cmd...] # Source work-tree update command
  27. # [PATCH_COMMAND cmd...] # Command to patch downloaded source
  28. # #--Configure step-------------
  29. # [SOURCE_DIR dir] # Source dir to be used for build
  30. # [CONFIGURE_COMMAND cmd...] # Build tree configuration command
  31. # [CMAKE_COMMAND /.../cmake] # Specify alternative cmake executable
  32. # [CMAKE_GENERATOR gen] # Specify generator for native build
  33. # [CMAKE_ARGS args...] # Arguments to CMake command line
  34. # #--Build step-----------------
  35. # [BINARY_DIR dir] # Specify build dir location
  36. # [BUILD_COMMAND cmd...] # Command to drive the native build
  37. # [BUILD_IN_SOURCE 1] # Use source dir for build dir
  38. # #--Install step---------------
  39. # [INSTALL_DIR dir] # Installation prefix
  40. # [INSTALL_COMMAND cmd...] # Command to drive install after build
  41. # #--Test step---------------
  42. # [TEST_BEFORE_INSTALL 1] # Add test step executed before install step
  43. # [TEST_AFTER_INSTALL 1] # Add test step executed after install step
  44. # [TEST_COMMAND cmd...] # Command to drive test
  45. # )
  46. # The *_DIR options specify directories for the project, with default
  47. # directories computed as follows.
  48. # If the PREFIX option is given to ExternalProject_Add() or the EP_PREFIX
  49. # directory property is set, then an external project is built and installed
  50. # under the specified prefix:
  51. # TMP_DIR = <prefix>/tmp
  52. # STAMP_DIR = <prefix>/src/<name>-stamp
  53. # DOWNLOAD_DIR = <prefix>/src
  54. # SOURCE_DIR = <prefix>/src/<name>
  55. # BINARY_DIR = <prefix>/src/<name>-build
  56. # INSTALL_DIR = <prefix>
  57. # Otherwise, if the EP_BASE directory property is set then components
  58. # of an external project are stored under the specified base:
  59. # TMP_DIR = <base>/tmp/<name>
  60. # STAMP_DIR = <base>/Stamp/<name>
  61. # DOWNLOAD_DIR = <base>/Download/<name>
  62. # SOURCE_DIR = <base>/Source/<name>
  63. # BINARY_DIR = <base>/Build/<name>
  64. # INSTALL_DIR = <base>/Install/<name>
  65. # If no PREFIX, EP_PREFIX, or EP_BASE is specified then the default
  66. # is to set PREFIX to "<name>-prefix".
  67. # Relative paths are interpreted with respect to the build directory
  68. # corresponding to the source directory in which ExternalProject_Add is
  69. # invoked.
  70. #
  71. # If SOURCE_DIR is explicitly set to an existing directory the project
  72. # will be built from it.
  73. # Otherwise a download step must be specified using one of the
  74. # DOWNLOAD_COMMAND, CVS_*, SVN_*, or URL options.
  75. # The URL option may refer locally to a directory or source tarball,
  76. # or refer to a remote tarball (e.g. http://.../src.tgz).
  77. #
  78. # The 'ExternalProject_Add_Step' function adds a custom step to an external
  79. # project:
  80. # ExternalProject_Add_Step(<name> <step> # Names of project and custom step
  81. # [COMMAND cmd...] # Command line invoked by this step
  82. # [COMMENT "text..."] # Text printed when step executes
  83. # [DEPENDEES steps...] # Steps on which this step depends
  84. # [DEPENDERS steps...] # Steps that depend on this step
  85. # [DEPENDS files...] # Files on which this step depends
  86. # [ALWAYS 1] # No stamp file, step always runs
  87. # [WORKING_DIRECTORY dir] # Working directory for command
  88. # )
  89. # The command line, comment, and working directory of every standard
  90. # and custom step is processed to replace tokens
  91. # <SOURCE_DIR>,
  92. # <BINARY_DIR>,
  93. # <INSTALL_DIR>,
  94. # and <TMP_DIR>
  95. # with corresponding property values.
  96. #
  97. # The 'ExternalProject_Get_Property' function retrieves external project
  98. # target properties:
  99. # ExternalProject_Get_Property(<name> [prop1 [prop2 [...]]])
  100. # It stores property values in variables of the same name.
  101. # Property names correspond to the keyword argument names of
  102. # 'ExternalProject_Add'.
  103. #=============================================================================
  104. # Copyright 2008-2009 Kitware, Inc.
  105. #
  106. # Distributed under the OSI-approved BSD License (the "License");
  107. # see accompanying file Copyright.txt for details.
  108. #
  109. # This software is distributed WITHOUT ANY WARRANTY; without even the
  110. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  111. # See the License for more information.
  112. #=============================================================================
  113. # (To distributed this file outside of CMake, substitute the full
  114. # License text for the above reference.)
  115. # Pre-compute a regex to match documented keywords for each command.
  116. file(STRINGS "${CMAKE_CURRENT_LIST_FILE}" lines LIMIT_COUNT 103
  117. REGEX "^# ( \\[[A-Z_]+ [^]]*\\] +#.*$|[A-Za-z_]+\\()")
  118. foreach(line IN LISTS lines)
  119. if("${line}" MATCHES "^# [A-Za-z_]+\\(")
  120. if(_ep_func)
  121. set(_ep_keywords_${_ep_func} "${_ep_keywords_${_ep_func}})$")
  122. endif()
  123. string(REGEX REPLACE "^# ([A-Za-z_]+)\\(.*" "\\1" _ep_func "${line}")
  124. #message("function [${_ep_func}]")
  125. set(_ep_keywords_${_ep_func} "^(")
  126. set(_ep_keyword_sep)
  127. else()
  128. string(REGEX REPLACE "^# \\[([A-Z_]+) .*" "\\1" _ep_key "${line}")
  129. #message(" keyword [${_ep_key}]")
  130. set(_ep_keywords_${_ep_func}
  131. "${_ep_keywords_${_ep_func}}${_ep_keyword_sep}${_ep_key}")
  132. set(_ep_keyword_sep "|")
  133. endif()
  134. endforeach()
  135. if(_ep_func)
  136. set(_ep_keywords_${_ep_func} "${_ep_keywords_${_ep_func}})$")
  137. endif()
  138. function(_ep_parse_arguments f name ns args)
  139. # Transfer the arguments to this function into target properties for the
  140. # new custom target we just added so that we can set up all the build steps
  141. # correctly based on target properties.
  142. #
  143. # We loop through ARGN and consider the namespace starting with an
  144. # upper-case letter followed by at least two more upper-case letters
  145. # or underscores to be keywords.
  146. set(key)
  147. foreach(arg IN LISTS args)
  148. set(is_value 1)
  149. if(arg MATCHES "^[A-Z][A-Z_][A-Z_]+$" AND
  150. NOT ((arg STREQUAL "${key}") AND (key STREQUAL "COMMAND")) AND
  151. NOT arg MATCHES "^(TRUE|FALSE)$")
  152. if(_ep_keywords_${f} AND arg MATCHES "${_ep_keywords_${f}}")
  153. set(is_value 0)
  154. else()
  155. if(NOT (key STREQUAL "COMMAND")
  156. AND NOT (key STREQUAL "CVS_MODULE")
  157. AND NOT (key STREQUAL "DEPENDS")
  158. )
  159. message(AUTHOR_WARNING "unknown ${f} keyword: ${arg}")
  160. endif()
  161. endif()
  162. endif()
  163. if(is_value)
  164. if(key)
  165. # Value
  166. if(NOT arg STREQUAL "")
  167. set_property(TARGET ${name} APPEND PROPERTY ${ns}${key} "${arg}")
  168. else()
  169. get_property(have_key TARGET ${name} PROPERTY ${ns}${key} SET)
  170. if(have_key)
  171. get_property(value TARGET ${name} PROPERTY ${ns}${key})
  172. set_property(TARGET ${name} PROPERTY ${ns}${key} "${value};${arg}")
  173. else()
  174. set_property(TARGET ${name} PROPERTY ${ns}${key} "${arg}")
  175. endif()
  176. endif()
  177. else()
  178. # Missing Keyword
  179. message(AUTHOR_WARNING "value '${arg}' with no previous keyword in ${f}")
  180. endif()
  181. else()
  182. set(key "${arg}")
  183. endif()
  184. endforeach()
  185. endfunction(_ep_parse_arguments)
  186. define_property(DIRECTORY PROPERTY "EP_BASE" INHERITED
  187. BRIEF_DOCS "Base directory for External Project storage."
  188. FULL_DOCS
  189. "See documentation of the ExternalProject_Add() function in the "
  190. "ExternalProject module."
  191. )
  192. define_property(DIRECTORY PROPERTY "EP_PREFIX" INHERITED
  193. BRIEF_DOCS "Top prefix for External Project storage."
  194. FULL_DOCS
  195. "See documentation of the ExternalProject_Add() function in the "
  196. "ExternalProject module."
  197. )
  198. function(_ep_write_gitclone_script script_filename source_dir git_EXECUTABLE git_repository git_tag src_name work_dir)
  199. file(WRITE ${script_filename}
  200. "execute_process(
  201. COMMAND \${CMAKE_COMMAND} -E remove_directory \"${source_dir}\"
  202. RESULT_VARIABLE error_code
  203. )
  204. if(error_code)
  205. message(FATAL_ERROR \"Failed to remove directory: '${source_dir}'\")
  206. endif()
  207. execute_process(
  208. COMMAND \"${git_EXECUTABLE}\" clone \"${git_repository}\" \"${src_name}\"
  209. WORKING_DIRECTORY \"${work_dir}\"
  210. RESULT_VARIABLE error_code
  211. )
  212. if(error_code)
  213. message(FATAL_ERROR \"Failed to clone repository: '${git_repository}'\")
  214. endif()
  215. if(NOT \"${git_tag}\" STREQUAL \"\")
  216. execute_process(
  217. COMMAND \"${git_EXECUTABLE}\" checkout ${git_tag}
  218. WORKING_DIRECTORY \"${work_dir}/${src_name}\"
  219. RESULT_VARIABLE error_code
  220. ERROR_QUIET
  221. )
  222. if(error_code)
  223. message(FATAL_ERROR \"Failed to checkout tag: '${git_tag}'\")
  224. endif()
  225. endif()
  226. "
  227. )
  228. endfunction(_ep_write_gitclone_script)
  229. function(_ep_write_downloadfile_script script_filename remote local timeout)
  230. if(timeout)
  231. set(timeout_args TIMEOUT ${timeout})
  232. set(timeout_msg "${timeout} seconds")
  233. else()
  234. set(timeout_args "# no TIMEOUT")
  235. set(timeout_msg "none")
  236. endif()
  237. file(WRITE ${script_filename}
  238. "message(STATUS \"downloading...
  239. src='${remote}'
  240. dst='${local}'
  241. timeout='${timeout_msg}'\")
  242. file(DOWNLOAD
  243. \"${remote}\"
  244. \"${local}\"
  245. ${timeout_args}
  246. STATUS status
  247. LOG log)
  248. list(GET status 0 status_code)
  249. list(GET status 1 status_string)
  250. if(NOT status_code EQUAL 0)
  251. message(FATAL_ERROR \"error: downloading '${remote}' failed
  252. status_code: \${status_code}
  253. status_string: \${status_string}
  254. log: \${log}
  255. \")
  256. endif()
  257. message(STATUS \"downloading... done\")
  258. "
  259. )
  260. endfunction(_ep_write_downloadfile_script)
  261. function(_ep_write_extractfile_script script_filename filename tmp directory)
  262. set(args "")
  263. if(filename MATCHES ".tar$")
  264. set(args xf)
  265. endif()
  266. if(filename MATCHES ".tgz$")
  267. set(args xfz)
  268. endif()
  269. if(filename MATCHES ".tar.gz$")
  270. set(args xfz)
  271. endif()
  272. if(args STREQUAL "")
  273. message(SEND_ERROR "error: do not know how to extract '${filename}' -- known types are .tar, .tgz and .tar.gz")
  274. return()
  275. endif()
  276. file(WRITE ${script_filename}
  277. "# Make file names absolute:
  278. #
  279. get_filename_component(filename \"${filename}\" ABSOLUTE)
  280. get_filename_component(tmp \"${tmp}\" ABSOLUTE)
  281. get_filename_component(directory \"${directory}\" ABSOLUTE)
  282. message(STATUS \"extracting...
  283. src='\${filename}'
  284. dst='\${directory}'\")
  285. # Prepare a space for extracting:
  286. #
  287. set(i 1)
  288. while(EXISTS \"\${tmp}/extract\${i}\")
  289. math(EXPR i \"\${i} + 1\")
  290. endwhile()
  291. set(ut_dir \"\${tmp}/extract\${i}\")
  292. file(MAKE_DIRECTORY \"\${ut_dir}\")
  293. # Extract it:
  294. #
  295. message(STATUS \"extracting... [tar ${args}]\")
  296. execute_process(COMMAND \${CMAKE_COMMAND} -E tar ${args} \${filename}
  297. WORKING_DIRECTORY \${ut_dir}
  298. RESULT_VARIABLE rv)
  299. if(NOT rv EQUAL 0)
  300. message(STATUS \"extracting... [error clean up]\")
  301. file(REMOVE_RECURSE \"\${ut_dir}\")
  302. message(FATAL_ERROR \"error: extract of '\${filename}' failed\")
  303. endif()
  304. # Analyze what came out of the tar file:
  305. #
  306. message(STATUS \"extracting... [analysis]\")
  307. file(GLOB contents \"\${ut_dir}/*\")
  308. list(LENGTH contents n)
  309. if(NOT n EQUAL 1 OR NOT IS_DIRECTORY \"\${contents}\")
  310. set(contents \"\${ut_dir}\")
  311. endif()
  312. # Copy \"the one\" directory to the final directory:
  313. #
  314. message(STATUS \"extracting... [copy]\")
  315. file(COPY \"\${contents}/\" DESTINATION \${directory})
  316. # Clean up:
  317. #
  318. message(STATUS \"extracting... [clean up]\")
  319. file(REMOVE_RECURSE \"\${ut_dir}\")
  320. message(STATUS \"extracting... done\")
  321. "
  322. )
  323. endfunction(_ep_write_extractfile_script)
  324. function(_ep_set_directories name)
  325. get_property(prefix TARGET ${name} PROPERTY _EP_PREFIX)
  326. if(NOT prefix)
  327. get_property(prefix DIRECTORY PROPERTY EP_PREFIX)
  328. if(NOT prefix)
  329. get_property(base DIRECTORY PROPERTY EP_BASE)
  330. if(NOT base)
  331. set(prefix "${name}-prefix")
  332. endif()
  333. endif()
  334. endif()
  335. if(prefix)
  336. set(tmp_default "${prefix}/tmp")
  337. set(download_default "${prefix}/src")
  338. set(source_default "${prefix}/src/${name}")
  339. set(binary_default "${prefix}/src/${name}-build")
  340. set(stamp_default "${prefix}/src/${name}-stamp")
  341. set(install_default "${prefix}")
  342. else() # assert(base)
  343. set(tmp_default "${base}/tmp/${name}")
  344. set(download_default "${base}/Download/${name}")
  345. set(source_default "${base}/Source/${name}")
  346. set(binary_default "${base}/Build/${name}")
  347. set(stamp_default "${base}/Stamp/${name}")
  348. set(install_default "${base}/Install/${name}")
  349. endif()
  350. get_property(build_in_source TARGET ${name} PROPERTY _EP_BUILD_IN_SOURCE)
  351. if(build_in_source)
  352. get_property(have_binary_dir TARGET ${name} PROPERTY _EP_BINARY_DIR SET)
  353. if(have_binary_dir)
  354. message(FATAL_ERROR
  355. "External project ${name} has both BINARY_DIR and BUILD_IN_SOURCE!")
  356. endif()
  357. endif()
  358. set(top "${CMAKE_CURRENT_BINARY_DIR}")
  359. set(places stamp download source binary install tmp)
  360. foreach(var ${places})
  361. string(TOUPPER "${var}" VAR)
  362. get_property(${var}_dir TARGET ${name} PROPERTY _EP_${VAR}_DIR)
  363. if(NOT ${var}_dir)
  364. set(${var}_dir "${${var}_default}")
  365. endif()
  366. if(NOT IS_ABSOLUTE "${${var}_dir}")
  367. get_filename_component(${var}_dir "${top}/${${var}_dir}" ABSOLUTE)
  368. endif()
  369. set_property(TARGET ${name} PROPERTY _EP_${VAR}_DIR "${${var}_dir}")
  370. endforeach()
  371. if(build_in_source)
  372. get_property(source_dir TARGET ${name} PROPERTY _EP_SOURCE_DIR)
  373. set_property(TARGET ${name} PROPERTY _EP_BINARY_DIR "${source_dir}")
  374. endif()
  375. # Make the directories at CMake configure time *and* add a custom command
  376. # to make them at build time. They need to exist at makefile generation
  377. # time for Borland make and wmake so that CMake may generate makefiles
  378. # with "cd C:\short\paths\with\no\spaces" commands in them.
  379. #
  380. # Additionally, the add_custom_command is still used in case somebody
  381. # removes one of the necessary directories and tries to rebuild without
  382. # re-running cmake.
  383. foreach(var ${places})
  384. string(TOUPPER "${var}" VAR)
  385. get_property(dir TARGET ${name} PROPERTY _EP_${VAR}_DIR)
  386. file(MAKE_DIRECTORY "${dir}")
  387. if(NOT EXISTS "${dir}")
  388. message(FATAL_ERROR "dir '${dir}' does not exist after file(MAKE_DIRECTORY)")
  389. endif()
  390. endforeach()
  391. endfunction(_ep_set_directories)
  392. function(ExternalProject_Get_Property name)
  393. foreach(var ${ARGN})
  394. string(TOUPPER "${var}" VAR)
  395. get_property(${var} TARGET ${name} PROPERTY _EP_${VAR})
  396. if(NOT ${var})
  397. message(FATAL_ERROR "External project \"${name}\" has no ${var}")
  398. endif()
  399. set(${var} "${${var}}" PARENT_SCOPE)
  400. endforeach()
  401. endfunction(ExternalProject_Get_Property)
  402. function(_ep_get_configure_command_id name cfg_cmd_id_var)
  403. get_target_property(cmd ${name} _EP_CONFIGURE_COMMAND)
  404. if(cmd STREQUAL "")
  405. # Explicit empty string means no configure step for this project
  406. set(${cfg_cmd_id_var} "none" PARENT_SCOPE)
  407. else()
  408. if(NOT cmd)
  409. # Default is "use cmake":
  410. set(${cfg_cmd_id_var} "cmake" PARENT_SCOPE)
  411. else()
  412. # Otherwise we have to analyze the value:
  413. if(cmd MATCHES "^[^;]*/configure")
  414. set(${cfg_cmd_id_var} "configure" PARENT_SCOPE)
  415. elseif(cmd MATCHES "^[^;]*/cmake" AND NOT cmd MATCHES ";-[PE];")
  416. set(${cfg_cmd_id_var} "cmake" PARENT_SCOPE)
  417. elseif(cmd MATCHES "config")
  418. set(${cfg_cmd_id_var} "configure" PARENT_SCOPE)
  419. else()
  420. set(${cfg_cmd_id_var} "unknown:${cmd}" PARENT_SCOPE)
  421. endif()
  422. endif()
  423. endif()
  424. endfunction(_ep_get_configure_command_id)
  425. function(_ep_get_build_command name step cmd_var)
  426. set(cmd "${${cmd_var}}")
  427. if(NOT cmd)
  428. set(args)
  429. _ep_get_configure_command_id(${name} cfg_cmd_id)
  430. if(cfg_cmd_id STREQUAL "cmake")
  431. # CMake project. Select build command based on generator.
  432. get_target_property(cmake_generator ${name} _EP_CMAKE_GENERATOR)
  433. if("${cmake_generator}" MATCHES "Make" AND
  434. "${cmake_generator}" STREQUAL "${CMAKE_GENERATOR}")
  435. # The project uses the same Makefile generator. Use recursive make.
  436. set(cmd "$(MAKE)")
  437. if(step STREQUAL "INSTALL")
  438. set(args install)
  439. endif()
  440. if(step STREQUAL "TEST")
  441. set(args test)
  442. endif()
  443. else()
  444. # Drive the project with "cmake --build".
  445. get_target_property(cmake_command ${name} _EP_CMAKE_COMMAND)
  446. if(cmake_command)
  447. set(cmd "${cmake_command}")
  448. else()
  449. set(cmd "${CMAKE_COMMAND}")
  450. endif()
  451. set(args --build ${binary_dir} --config ${CMAKE_CFG_INTDIR})
  452. if(step STREQUAL "INSTALL")
  453. list(APPEND args --target install)
  454. endif()
  455. # But for "TEST" drive the project with corresponding "ctest".
  456. if(step STREQUAL "TEST")
  457. string(REGEX REPLACE "^(.*/)cmake([^/]*)$" "\\1ctest\\2" cmd "${cmd}")
  458. set(args "")
  459. endif()
  460. endif()
  461. else() # if(cfg_cmd_id STREQUAL "configure")
  462. # Non-CMake project. Guess "make" and "make install" and "make test".
  463. set(cmd "make")
  464. if(step STREQUAL "INSTALL")
  465. set(args install)
  466. endif()
  467. if(step STREQUAL "TEST")
  468. set(args test)
  469. endif()
  470. endif()
  471. # Use user-specified arguments instead of default arguments, if any.
  472. get_property(have_args TARGET ${name} PROPERTY _EP_${step}_ARGS SET)
  473. if(have_args)
  474. get_target_property(args ${name} _EP_${step}_ARGS)
  475. endif()
  476. list(APPEND cmd ${args})
  477. endif()
  478. set(${cmd_var} "${cmd}" PARENT_SCOPE)
  479. endfunction(_ep_get_build_command)
  480. # This module used to use "/${CMAKE_CFG_INTDIR}" directly and produced
  481. # makefiles with "/./" in paths for custom command dependencies. Which
  482. # resulted in problems with parallel make -j invocations.
  483. #
  484. # This function was added so that the suffix (search below for ${cfgdir}) is
  485. # only set to "/${CMAKE_CFG_INTDIR}" when ${CMAKE_CFG_INTDIR} is not going to
  486. # be "." (multi-configuration build systems like Visual Studio and Xcode...)
  487. #
  488. function(_ep_get_configuration_subdir_suffix suffix_var)
  489. set(suffix "")
  490. if(CMAKE_CONFIGURATION_TYPES)
  491. set(suffix "/${CMAKE_CFG_INTDIR}")
  492. endif()
  493. set(${suffix_var} "${suffix}" PARENT_SCOPE)
  494. endfunction(_ep_get_configuration_subdir_suffix)
  495. function(ExternalProject_Add_Step name step)
  496. set(cmf_dir ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles)
  497. ExternalProject_Get_Property(${name} stamp_dir)
  498. _ep_get_configuration_subdir_suffix(cfgdir)
  499. add_custom_command(APPEND
  500. OUTPUT ${cmf_dir}${cfgdir}/${name}-complete
  501. DEPENDS ${stamp_dir}${cfgdir}/${name}-${step}
  502. )
  503. _ep_parse_arguments(ExternalProject_Add_Step
  504. ${name} _EP_${step}_ "${ARGN}")
  505. # Steps depending on this step.
  506. get_property(dependers TARGET ${name} PROPERTY _EP_${step}_DEPENDERS)
  507. foreach(depender IN LISTS dependers)
  508. add_custom_command(APPEND
  509. OUTPUT ${stamp_dir}${cfgdir}/${name}-${depender}
  510. DEPENDS ${stamp_dir}${cfgdir}/${name}-${step}
  511. )
  512. endforeach()
  513. # Dependencies on files.
  514. get_property(depends TARGET ${name} PROPERTY _EP_${step}_DEPENDS)
  515. # Dependencies on steps.
  516. get_property(dependees TARGET ${name} PROPERTY _EP_${step}_DEPENDEES)
  517. foreach(dependee IN LISTS dependees)
  518. list(APPEND depends ${stamp_dir}${cfgdir}/${name}-${dependee})
  519. endforeach()
  520. # The command to run.
  521. get_property(command TARGET ${name} PROPERTY _EP_${step}_COMMAND)
  522. if(command)
  523. set(comment "Performing ${step} step for '${name}'")
  524. else()
  525. set(comment "No ${step} step for '${name}'")
  526. endif()
  527. get_property(work_dir TARGET ${name} PROPERTY _EP_${step}_WORKING_DIRECTORY)
  528. # Replace list separators.
  529. get_property(sep TARGET ${name} PROPERTY _EP_LIST_SEPARATOR)
  530. if(sep AND command)
  531. string(REPLACE "${sep}" "\\;" command "${command}")
  532. endif()
  533. # Replace location tags.
  534. foreach(var comment command work_dir)
  535. if(${var})
  536. foreach(dir SOURCE_DIR BINARY_DIR INSTALL_DIR TMP_DIR)
  537. get_property(val TARGET ${name} PROPERTY _EP_${dir})
  538. string(REPLACE "<${dir}>" "${val}" ${var} "${${var}}")
  539. endforeach()
  540. endif()
  541. endforeach()
  542. # Custom comment?
  543. get_property(comment_set TARGET ${name} PROPERTY _EP_${step}_COMMENT SET)
  544. if(comment_set)
  545. get_property(comment TARGET ${name} PROPERTY _EP_${step}_COMMENT)
  546. endif()
  547. # Run every time?
  548. get_property(always TARGET ${name} PROPERTY _EP_${step}_ALWAYS)
  549. if(always)
  550. set_property(SOURCE ${stamp_dir}${cfgdir}/${name}-${step} PROPERTY SYMBOLIC 1)
  551. set(touch)
  552. else()
  553. set(touch ${CMAKE_COMMAND} -E touch ${stamp_dir}${cfgdir}/${name}-${step})
  554. endif()
  555. add_custom_command(
  556. OUTPUT ${stamp_dir}${cfgdir}/${name}-${step}
  557. COMMENT ${comment}
  558. COMMAND ${command}
  559. COMMAND ${touch}
  560. DEPENDS ${depends}
  561. WORKING_DIRECTORY ${work_dir}
  562. VERBATIM
  563. )
  564. endfunction(ExternalProject_Add_Step)
  565. function(_ep_add_mkdir_command name)
  566. ExternalProject_Get_Property(${name}
  567. source_dir binary_dir install_dir stamp_dir download_dir tmp_dir)
  568. _ep_get_configuration_subdir_suffix(cfgdir)
  569. ExternalProject_Add_Step(${name} mkdir
  570. COMMENT "Creating directories for '${name}'"
  571. COMMAND ${CMAKE_COMMAND} -E make_directory ${source_dir}
  572. COMMAND ${CMAKE_COMMAND} -E make_directory ${binary_dir}
  573. COMMAND ${CMAKE_COMMAND} -E make_directory ${install_dir}
  574. COMMAND ${CMAKE_COMMAND} -E make_directory ${tmp_dir}
  575. COMMAND ${CMAKE_COMMAND} -E make_directory ${stamp_dir}${cfgdir}
  576. COMMAND ${CMAKE_COMMAND} -E make_directory ${download_dir}
  577. )
  578. endfunction(_ep_add_mkdir_command)
  579. function(_ep_get_git_version git_EXECUTABLE git_version_var)
  580. if(git_EXECUTABLE)
  581. execute_process(
  582. COMMAND "${git_EXECUTABLE}" --version
  583. OUTPUT_VARIABLE ov
  584. OUTPUT_STRIP_TRAILING_WHITESPACE
  585. )
  586. string(REGEX REPLACE "^git version (.+)$" "\\1" version "${ov}")
  587. set(${git_version_var} "${version}" PARENT_SCOPE)
  588. endif()
  589. endfunction()
  590. function(_ep_add_download_command name)
  591. ExternalProject_Get_Property(${name} source_dir stamp_dir download_dir tmp_dir)
  592. get_property(cmd_set TARGET ${name} PROPERTY _EP_DOWNLOAD_COMMAND SET)
  593. get_property(cmd TARGET ${name} PROPERTY _EP_DOWNLOAD_COMMAND)
  594. get_property(cvs_repository TARGET ${name} PROPERTY _EP_CVS_REPOSITORY)
  595. get_property(svn_repository TARGET ${name} PROPERTY _EP_SVN_REPOSITORY)
  596. get_property(git_repository TARGET ${name} PROPERTY _EP_GIT_REPOSITORY)
  597. get_property(url TARGET ${name} PROPERTY _EP_URL)
  598. # TODO: Perhaps file:// should be copied to download dir before extraction.
  599. string(REGEX REPLACE "^file://" "" url "${url}")
  600. set(depends)
  601. set(comment)
  602. set(work_dir)
  603. if(cmd_set)
  604. set(work_dir ${download_dir})
  605. elseif(cvs_repository)
  606. find_package(CVS)
  607. if(NOT CVS_EXECUTABLE)
  608. message(FATAL_ERROR "error: could not find cvs for checkout of ${name}")
  609. endif()
  610. get_target_property(cvs_module ${name} _EP_CVS_MODULE)
  611. if(NOT cvs_module)
  612. message(FATAL_ERROR "error: no CVS_MODULE")
  613. endif()
  614. get_property(cvs_tag TARGET ${name} PROPERTY _EP_CVS_TAG)
  615. set(repository ${cvs_repository})
  616. set(module ${cvs_module})
  617. set(tag ${cvs_tag})
  618. configure_file(
  619. "${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in"
  620. "${stamp_dir}/${name}-cvsinfo.txt"
  621. @ONLY
  622. )
  623. get_filename_component(src_name "${source_dir}" NAME)
  624. get_filename_component(work_dir "${source_dir}" PATH)
  625. set(comment "Performing download step (CVS checkout) for '${name}'")
  626. set(cmd ${CVS_EXECUTABLE} -d ${cvs_repository} -q co ${cvs_tag} -d ${src_name} ${cvs_module})
  627. list(APPEND depends ${stamp_dir}/${name}-cvsinfo.txt)
  628. elseif(svn_repository)
  629. find_package(Subversion)
  630. if(NOT Subversion_SVN_EXECUTABLE)
  631. message(FATAL_ERROR "error: could not find svn for checkout of ${name}")
  632. endif()
  633. get_property(svn_revision TARGET ${name} PROPERTY _EP_SVN_REVISION)
  634. get_property(svn_username TARGET ${name} PROPERTY _EP_SVN_USERNAME)
  635. get_property(svn_password TARGET ${name} PROPERTY _EP_SVN_PASSWORD)
  636. set(repository ${svn_repository})
  637. set(module)
  638. set(tag ${svn_revision})
  639. configure_file(
  640. "${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in"
  641. "${stamp_dir}/${name}-svninfo.txt"
  642. @ONLY
  643. )
  644. get_filename_component(src_name "${source_dir}" NAME)
  645. get_filename_component(work_dir "${source_dir}" PATH)
  646. set(comment "Performing download step (SVN checkout) for '${name}'")
  647. set(cmd ${Subversion_SVN_EXECUTABLE} co ${svn_repository} ${svn_revision} --username=${svn_username} --password=${svn_password} ${src_name})
  648. list(APPEND depends ${stamp_dir}/${name}-svninfo.txt)
  649. elseif(git_repository)
  650. #find_package(Git)
  651. # If 'git.cmd' are 'eg.cmd' are used, execute_process fails and outputs the following error:
  652. # 'chcp' is not recognized as an internal or external command, operable program or batch file
  653. find_program(git_EXECUTABLE
  654. NAMES git eg
  655. PATHS
  656. "C:/Program Files/Git/bin"
  657. "C:/Program Files (x86)/Git/bin"
  658. DOC "git command line client")
  659. if(NOT git_EXECUTABLE)
  660. message(FATAL_ERROR "error: could not find git for clone of ${name} - Make sure git_EXECUTABLE is set properly")
  661. endif()
  662. # The git submodule update '--recursive' flag requires git >= v1.6.5
  663. #
  664. _ep_get_git_version("${git_EXECUTABLE}" git_version)
  665. if(git_version VERSION_LESS 1.6.5)
  666. message(FATAL_ERROR "error: git version 1.6.5 or later required for 'git submodule update --recursive': git_version='${git_version}'")
  667. endif()
  668. get_property(git_tag TARGET ${name} PROPERTY _EP_GIT_TAG)
  669. if(NOT git_tag)
  670. set(git_tag "master")
  671. endif()
  672. set(repository ${git_repository})
  673. set(module)
  674. set(tag ${git_tag})
  675. configure_file(
  676. "${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in"
  677. "${stamp_dir}/${name}-gitinfo.txt"
  678. @ONLY
  679. )
  680. get_filename_component(src_name "${source_dir}" NAME)
  681. get_filename_component(work_dir "${source_dir}" PATH)
  682. # Since git clone doesn't succeed if the non-empty source_dir exists,
  683. # create a cmake script to invoke as download command.
  684. # The script will delete the source directory and then call git clone.
  685. #
  686. _ep_write_gitclone_script(${tmp_dir}/${name}-gitclone.cmake ${source_dir}
  687. ${git_EXECUTABLE} ${git_repository} "${git_tag}" ${src_name} ${work_dir})
  688. set(comment "Performing download step (git clone) for '${name}'")
  689. set(cmd ${CMAKE_COMMAND} -P ${tmp_dir}/${name}-gitclone.cmake)
  690. list(APPEND depends ${stamp_dir}/${name}-gitinfo.txt)
  691. elseif(url)
  692. get_filename_component(work_dir "${source_dir}" PATH)
  693. set(repository "external project URL")
  694. set(module "${url}")
  695. set(tag "")
  696. configure_file(
  697. "${CMAKE_ROOT}/Modules/RepositoryInfo.txt.in"
  698. "${stamp_dir}/${name}-urlinfo.txt"
  699. @ONLY
  700. )
  701. list(APPEND depends ${stamp_dir}/${name}-urlinfo.txt)
  702. if(IS_DIRECTORY "${url}")
  703. get_filename_component(abs_dir "${url}" ABSOLUTE)
  704. set(comment "Performing download step (DIR copy) for '${name}'")
  705. set(cmd ${CMAKE_COMMAND} -E remove_directory ${source_dir}
  706. COMMAND ${CMAKE_COMMAND} -E copy_directory ${abs_dir} ${source_dir})
  707. else()
  708. if("${url}" MATCHES "^[a-z]+://")
  709. # TODO: Should download and extraction be different steps?
  710. string(REGEX MATCH "[^/]*$" fname "${url}")
  711. if(NOT "${fname}" MATCHES "\\.(tar|tgz|tar\\.gz)$")
  712. message(FATAL_ERROR "Could not extract tarball filename from url:\n ${url}")
  713. endif()
  714. set(file ${download_dir}/${fname})
  715. get_property(timeout TARGET ${name} PROPERTY _EP_TIMEOUT)
  716. _ep_write_downloadfile_script("${stamp_dir}/download-${name}.cmake" "${url}" "${file}" "${timeout}")
  717. set(cmd ${CMAKE_COMMAND} -P ${stamp_dir}/download-${name}.cmake
  718. COMMAND)
  719. set(comment "Performing download step (download and extract) for '${name}'")
  720. else()
  721. set(file "${url}")
  722. set(comment "Performing download step (extract) for '${name}'")
  723. endif()
  724. # TODO: Support other archive formats.
  725. _ep_write_extractfile_script("${stamp_dir}/extract-${name}.cmake" "${file}" "${tmp_dir}" "${source_dir}")
  726. list(APPEND cmd ${CMAKE_COMMAND} -P ${stamp_dir}/extract-${name}.cmake)
  727. endif()
  728. else()
  729. message(SEND_ERROR "error: no download info for '${name}' -- please specify existing SOURCE_DIR or one of URL, CVS_REPOSITORY and CVS_MODULE, SVN_REPOSITORY or DOWNLOAD_COMMAND")
  730. endif()
  731. ExternalProject_Add_Step(${name} download
  732. COMMENT ${comment}
  733. COMMAND ${cmd}
  734. WORKING_DIRECTORY ${work_dir}
  735. DEPENDS ${depends}
  736. DEPENDEES mkdir
  737. )
  738. endfunction(_ep_add_download_command)
  739. function(_ep_add_update_command name)
  740. ExternalProject_Get_Property(${name} source_dir tmp_dir)
  741. get_property(cmd_set TARGET ${name} PROPERTY _EP_UPDATE_COMMAND SET)
  742. get_property(cmd TARGET ${name} PROPERTY _EP_UPDATE_COMMAND)
  743. get_property(cvs_repository TARGET ${name} PROPERTY _EP_CVS_REPOSITORY)
  744. get_property(svn_repository TARGET ${name} PROPERTY _EP_SVN_REPOSITORY)
  745. get_property(git_repository TARGET ${name} PROPERTY _EP_GIT_REPOSITORY)
  746. set(work_dir)
  747. set(comment)
  748. set(always)
  749. if(cmd_set)
  750. set(work_dir ${source_dir})
  751. elseif(cvs_repository)
  752. if(NOT CVS_EXECUTABLE)
  753. message(FATAL_ERROR "error: could not find cvs for update of ${name}")
  754. endif()
  755. set(work_dir ${source_dir})
  756. set(comment "Performing update step (CVS update) for '${name}'")
  757. get_property(cvs_tag TARGET ${name} PROPERTY _EP_CVS_TAG)
  758. set(cmd ${CVS_EXECUTABLE} -d ${cvs_repository} -q up -dP ${cvs_tag})
  759. set(always 1)
  760. elseif(svn_repository)
  761. if(NOT Subversion_SVN_EXECUTABLE)
  762. message(FATAL_ERROR "error: could not find svn for update of ${name}")
  763. endif()
  764. set(work_dir ${source_dir})
  765. set(comment "Performing update step (SVN update) for '${name}'")
  766. get_property(svn_revision TARGET ${name} PROPERTY _EP_SVN_REVISION)
  767. get_property(svn_username TARGET ${name} PROPERTY _EP_SVN_USERNAME)
  768. get_property(svn_password TARGET ${name} PROPERTY _EP_SVN_PASSWORD)
  769. set(cmd ${Subversion_SVN_EXECUTABLE} up ${svn_revision} --username=${svn_username} --password=${svn_password})
  770. set(always 1)
  771. elseif(git_repository)
  772. if(NOT git_EXECUTABLE)
  773. message(FATAL_ERROR "error: could not find git for fetch of ${name}")
  774. endif()
  775. set(comment "Performing update step (git fetch) for '${name}'")
  776. set(work_dir ${source_dir})
  777. get_property(git_tag TARGET ${name} PROPERTY _EP_GIT_TAG)
  778. if(NOT git_tag)
  779. set(git_tag "master")
  780. endif()
  781. set(cmd ${git_EXECUTABLE} fetch
  782. COMMAND ${git_EXECUTABLE} checkout ${git_tag}
  783. COMMAND ${git_EXECUTABLE} pull
  784. COMMAND ${git_EXECUTABLE} submodule update --recursive
  785. )
  786. set(always 1)
  787. endif()
  788. ExternalProject_Add_Step(${name} update
  789. COMMENT ${comment}
  790. COMMAND ${cmd}
  791. ALWAYS ${always}
  792. WORKING_DIRECTORY ${work_dir}
  793. DEPENDEES download
  794. )
  795. endfunction(_ep_add_update_command)
  796. function(_ep_add_patch_command name)
  797. ExternalProject_Get_Property(${name} source_dir)
  798. get_property(cmd_set TARGET ${name} PROPERTY _EP_PATCH_COMMAND SET)
  799. get_property(cmd TARGET ${name} PROPERTY _EP_PATCH_COMMAND)
  800. set(work_dir)
  801. if(cmd_set)
  802. set(work_dir ${source_dir})
  803. endif()
  804. ExternalProject_Add_Step(${name} patch
  805. COMMAND ${cmd}
  806. WORKING_DIRECTORY ${work_dir}
  807. DEPENDEES download
  808. )
  809. endfunction(_ep_add_patch_command)
  810. # TODO: Make sure external projects use the proper compiler
  811. function(_ep_add_configure_command name)
  812. ExternalProject_Get_Property(${name} source_dir binary_dir tmp_dir)
  813. # If anything about the configure command changes, (command itself, cmake
  814. # used, cmake args or cmake generator) then re-run the configure step.
  815. # Fixes issue http://public.kitware.com/Bug/view.php?id=10258
  816. #
  817. if(NOT EXISTS ${tmp_dir}/${name}-cfgcmd.txt.in)
  818. file(WRITE ${tmp_dir}/${name}-cfgcmd.txt.in "cmd='@cmd@'\n")
  819. endif()
  820. configure_file(${tmp_dir}/${name}-cfgcmd.txt.in ${tmp_dir}/${name}-cfgcmd.txt)
  821. list(APPEND file_deps ${tmp_dir}/${name}-cfgcmd.txt)
  822. _ep_get_configuration_subdir_suffix(cfgdir)
  823. # Depend on other external projects (file-level).
  824. set(file_deps)
  825. get_property(deps TARGET ${name} PROPERTY _EP_DEPENDS)
  826. foreach(dep IN LISTS deps)
  827. get_property(dep_stamp_dir TARGET ${dep} PROPERTY _EP_STAMP_DIR)
  828. list(APPEND file_deps ${dep_stamp_dir}${cfgdir}/${dep}-done)
  829. endforeach()
  830. get_property(cmd_set TARGET ${name} PROPERTY _EP_CONFIGURE_COMMAND SET)
  831. if(cmd_set)
  832. get_property(cmd TARGET ${name} PROPERTY _EP_CONFIGURE_COMMAND)
  833. else()
  834. get_target_property(cmake_command ${name} _EP_CMAKE_COMMAND)
  835. if(cmake_command)
  836. set(cmd "${cmake_command}")
  837. else()
  838. set(cmd "${CMAKE_COMMAND}")
  839. endif()
  840. get_property(cmake_args TARGET ${name} PROPERTY _EP_CMAKE_ARGS)
  841. list(APPEND cmd ${cmake_args})
  842. get_target_property(cmake_generator ${name} _EP_CMAKE_GENERATOR)
  843. if(cmake_generator)
  844. list(APPEND cmd "-G${cmake_generator}" "${source_dir}")
  845. else()
  846. list(APPEND cmd "-G${CMAKE_GENERATOR}" "${source_dir}")
  847. endif()
  848. endif()
  849. ExternalProject_Add_Step(${name} configure
  850. COMMAND ${cmd}
  851. WORKING_DIRECTORY ${binary_dir}
  852. DEPENDEES update patch
  853. DEPENDS ${file_deps}
  854. )
  855. endfunction(_ep_add_configure_command)
  856. function(_ep_add_build_command name)
  857. ExternalProject_Get_Property(${name} binary_dir)
  858. get_property(cmd_set TARGET ${name} PROPERTY _EP_BUILD_COMMAND SET)
  859. if(cmd_set)
  860. get_property(cmd TARGET ${name} PROPERTY _EP_BUILD_COMMAND)
  861. else()
  862. _ep_get_build_command(${name} BUILD cmd)
  863. endif()
  864. ExternalProject_Add_Step(${name} build
  865. COMMAND ${cmd}
  866. WORKING_DIRECTORY ${binary_dir}
  867. DEPENDEES configure
  868. )
  869. endfunction(_ep_add_build_command)
  870. function(_ep_add_install_command name)
  871. ExternalProject_Get_Property(${name} binary_dir)
  872. get_property(cmd_set TARGET ${name} PROPERTY _EP_INSTALL_COMMAND SET)
  873. if(cmd_set)
  874. get_property(cmd TARGET ${name} PROPERTY _EP_INSTALL_COMMAND)
  875. else()
  876. _ep_get_build_command(${name} INSTALL cmd)
  877. endif()
  878. ExternalProject_Add_Step(${name} install
  879. COMMAND ${cmd}
  880. WORKING_DIRECTORY ${binary_dir}
  881. DEPENDEES build
  882. )
  883. endfunction(_ep_add_install_command)
  884. function(_ep_add_test_command name)
  885. ExternalProject_Get_Property(${name} binary_dir)
  886. get_property(before TARGET ${name} PROPERTY _EP_TEST_BEFORE_INSTALL)
  887. get_property(after TARGET ${name} PROPERTY _EP_TEST_AFTER_INSTALL)
  888. get_property(cmd_set TARGET ${name} PROPERTY _EP_TEST_COMMAND SET)
  889. # Only actually add the test step if one of the test related properties is
  890. # explicitly set. (i.e. the test step is omitted unless requested...)
  891. #
  892. if(cmd_set OR before OR after)
  893. if(cmd_set)
  894. get_property(cmd TARGET ${name} PROPERTY _EP_TEST_COMMAND)
  895. else()
  896. _ep_get_build_command(${name} TEST cmd)
  897. endif()
  898. if(before)
  899. set(dep_args DEPENDEES build DEPENDERS install)
  900. else()
  901. set(dep_args DEPENDEES install)
  902. endif()
  903. ExternalProject_Add_Step(${name} test
  904. COMMAND ${cmd}
  905. WORKING_DIRECTORY ${binary_dir}
  906. ${dep_args}
  907. )
  908. endif()
  909. endfunction(_ep_add_test_command)
  910. function(ExternalProject_Add name)
  911. _ep_get_configuration_subdir_suffix(cfgdir)
  912. # Add a custom target for the external project.
  913. set(cmf_dir ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles)
  914. add_custom_target(${name} ALL DEPENDS ${cmf_dir}${cfgdir}/${name}-complete)
  915. set_property(TARGET ${name} PROPERTY _EP_IS_EXTERNAL_PROJECT 1)
  916. _ep_parse_arguments(ExternalProject_Add ${name} _EP_ "${ARGN}")
  917. _ep_set_directories(${name})
  918. ExternalProject_Get_Property(${name} stamp_dir)
  919. # The 'complete' step depends on all other steps and creates a
  920. # 'done' mark. A dependent external project's 'configure' step
  921. # depends on the 'done' mark so that it rebuilds when this project
  922. # rebuilds. It is important that 'done' is not the output of any
  923. # custom command so that CMake does not propagate build rules to
  924. # other external project targets.
  925. add_custom_command(
  926. OUTPUT ${cmf_dir}${cfgdir}/${name}-complete
  927. COMMENT "Completed '${name}'"
  928. COMMAND ${CMAKE_COMMAND} -E make_directory ${cmf_dir}${cfgdir}
  929. COMMAND ${CMAKE_COMMAND} -E touch ${cmf_dir}${cfgdir}/${name}-complete
  930. COMMAND ${CMAKE_COMMAND} -E touch ${stamp_dir}${cfgdir}/${name}-done
  931. DEPENDS ${stamp_dir}${cfgdir}/${name}-install
  932. VERBATIM
  933. )
  934. # Depend on other external projects (target-level).
  935. get_property(deps TARGET ${name} PROPERTY _EP_DEPENDS)
  936. foreach(arg IN LISTS deps)
  937. add_dependencies(${name} ${arg})
  938. endforeach()
  939. # Set up custom build steps based on the target properties.
  940. # Each step depends on the previous one.
  941. #
  942. # The target depends on the output of the final step.
  943. # (Already set up above in the DEPENDS of the add_custom_target command.)
  944. #
  945. _ep_add_mkdir_command(${name})
  946. _ep_add_download_command(${name})
  947. _ep_add_update_command(${name})
  948. _ep_add_patch_command(${name})
  949. _ep_add_configure_command(${name})
  950. _ep_add_build_command(${name})
  951. _ep_add_install_command(${name})
  952. # Test is special in that it might depend on build, or it might depend
  953. # on install.
  954. #
  955. _ep_add_test_command(${name})
  956. endfunction(ExternalProject_Add)