ExternalProject.cmake 71 KB

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