ExternalProjectWithFilename.cmake 52 KB

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