ExternalProject.cmake 81 KB

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