ExternalProject.cmake 85 KB

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