ExternalProject.cmake 84 KB

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