ExternalProject.cmake 84 KB

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