BundleUtilities.cmake 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #.rst:
  4. # BundleUtilities
  5. # ---------------
  6. #
  7. # Functions to help assemble a standalone bundle application.
  8. #
  9. # A collection of CMake utility functions useful for dealing with .app
  10. # bundles on the Mac and bundle-like directories on any OS.
  11. #
  12. # The following functions are provided by this module:
  13. #
  14. # ::
  15. #
  16. # fixup_bundle
  17. # copy_and_fixup_bundle
  18. # verify_app
  19. # get_bundle_main_executable
  20. # get_dotapp_dir
  21. # get_bundle_and_executable
  22. # get_bundle_all_executables
  23. # get_item_key
  24. # get_item_rpaths
  25. # clear_bundle_keys
  26. # set_bundle_key_values
  27. # get_bundle_keys
  28. # copy_resolved_item_into_bundle
  29. # copy_resolved_framework_into_bundle
  30. # fixup_bundle_item
  31. # verify_bundle_prerequisites
  32. # verify_bundle_symlinks
  33. #
  34. # Requires CMake 2.6 or greater because it uses function, break and
  35. # PARENT_SCOPE. Also depends on GetPrerequisites.cmake.
  36. #
  37. # ::
  38. #
  39. # FIXUP_BUNDLE(<app> <libs> <dirs>)
  40. #
  41. # Fix up a bundle in-place and make it standalone, such that it can be
  42. # drag-n-drop copied to another machine and run on that machine as long
  43. # as all of the system libraries are compatible.
  44. #
  45. # If you pass plugins to fixup_bundle as the libs parameter, you should
  46. # install them or copy them into the bundle before calling fixup_bundle.
  47. # The "libs" parameter is a list of libraries that must be fixed up, but
  48. # that cannot be determined by otool output analysis. (i.e., plugins)
  49. #
  50. # Gather all the keys for all the executables and libraries in a bundle,
  51. # and then, for each key, copy each prerequisite into the bundle. Then
  52. # fix each one up according to its own list of prerequisites.
  53. #
  54. # Then clear all the keys and call verify_app on the final bundle to
  55. # ensure that it is truly standalone.
  56. #
  57. # As an optional parameter (IGNORE_ITEM) a list of file names can be passed,
  58. # which are then ignored (e.g. IGNORE_ITEM "vcredist_x86.exe;vcredist_x64.exe")
  59. #
  60. # ::
  61. #
  62. # COPY_AND_FIXUP_BUNDLE(<src> <dst> <libs> <dirs>)
  63. #
  64. # Makes a copy of the bundle <src> at location <dst> and then fixes up
  65. # the new copied bundle in-place at <dst>...
  66. #
  67. # ::
  68. #
  69. # VERIFY_APP(<app>)
  70. #
  71. # Verifies that an application <app> appears valid based on running
  72. # analysis tools on it. Calls "message(FATAL_ERROR" if the application
  73. # is not verified.
  74. #
  75. # As an optional parameter (IGNORE_ITEM) a list of file names can be passed,
  76. # which are then ignored (e.g. IGNORE_ITEM "vcredist_x86.exe;vcredist_x64.exe")
  77. #
  78. # ::
  79. #
  80. # GET_BUNDLE_MAIN_EXECUTABLE(<bundle> <result_var>)
  81. #
  82. # The result will be the full path name of the bundle's main executable
  83. # file or an "error:" prefixed string if it could not be determined.
  84. #
  85. # ::
  86. #
  87. # GET_DOTAPP_DIR(<exe> <dotapp_dir_var>)
  88. #
  89. # Returns the nearest parent dir whose name ends with ".app" given the
  90. # full path to an executable. If there is no such parent dir, then
  91. # simply return the dir containing the executable.
  92. #
  93. # The returned directory may or may not exist.
  94. #
  95. # ::
  96. #
  97. # GET_BUNDLE_AND_EXECUTABLE(<app> <bundle_var> <executable_var> <valid_var>)
  98. #
  99. # Takes either a ".app" directory name or the name of an executable
  100. # nested inside a ".app" directory and returns the path to the ".app"
  101. # directory in <bundle_var> and the path to its main executable in
  102. # <executable_var>
  103. #
  104. # ::
  105. #
  106. # GET_BUNDLE_ALL_EXECUTABLES(<bundle> <exes_var>)
  107. #
  108. # Scans the given bundle recursively for all executable files and
  109. # accumulates them into a variable.
  110. #
  111. # ::
  112. #
  113. # GET_ITEM_KEY(<item> <key_var>)
  114. #
  115. # Given a file (item) name, generate a key that should be unique
  116. # considering the set of libraries that need copying or fixing up to
  117. # make a bundle standalone. This is essentially the file name including
  118. # extension with "." replaced by "_"
  119. #
  120. # This key is used as a prefix for CMake variables so that we can
  121. # associate a set of variables with a given item based on its key.
  122. #
  123. # ::
  124. #
  125. # CLEAR_BUNDLE_KEYS(<keys_var>)
  126. #
  127. # Loop over the list of keys, clearing all the variables associated with
  128. # each key. After the loop, clear the list of keys itself.
  129. #
  130. # Caller of get_bundle_keys should call clear_bundle_keys when done with
  131. # list of keys.
  132. #
  133. # ::
  134. #
  135. # SET_BUNDLE_KEY_VALUES(<keys_var> <context> <item> <exepath> <dirs>
  136. # <copyflag> [<rpaths>])
  137. #
  138. # Add a key to the list (if necessary) for the given item. If added,
  139. # also set all the variables associated with that key.
  140. #
  141. # ::
  142. #
  143. # GET_BUNDLE_KEYS(<app> <libs> <dirs> <keys_var>)
  144. #
  145. # Loop over all the executable and library files within the bundle (and
  146. # given as extra <libs>) and accumulate a list of keys representing
  147. # them. Set values associated with each key such that we can loop over
  148. # all of them and copy prerequisite libs into the bundle and then do
  149. # appropriate install_name_tool fixups.
  150. #
  151. # As an optional parameter (IGNORE_ITEM) a list of file names can be passed,
  152. # which are then ignored (e.g. IGNORE_ITEM "vcredist_x86.exe;vcredist_x64.exe")
  153. #
  154. # ::
  155. #
  156. # COPY_RESOLVED_ITEM_INTO_BUNDLE(<resolved_item> <resolved_embedded_item>)
  157. #
  158. # Copy a resolved item into the bundle if necessary. Copy is not
  159. # necessary if the resolved_item is "the same as" the
  160. # resolved_embedded_item.
  161. #
  162. # ::
  163. #
  164. # COPY_RESOLVED_FRAMEWORK_INTO_BUNDLE(<resolved_item> <resolved_embedded_item>)
  165. #
  166. # Copy a resolved framework into the bundle if necessary. Copy is not
  167. # necessary if the resolved_item is "the same as" the
  168. # resolved_embedded_item.
  169. #
  170. # By default, BU_COPY_FULL_FRAMEWORK_CONTENTS is not set. If you want
  171. # full frameworks embedded in your bundles, set
  172. # BU_COPY_FULL_FRAMEWORK_CONTENTS to ON before calling fixup_bundle. By
  173. # default, COPY_RESOLVED_FRAMEWORK_INTO_BUNDLE copies the framework
  174. # dylib itself plus the framework Resources directory.
  175. #
  176. # ::
  177. #
  178. # FIXUP_BUNDLE_ITEM(<resolved_embedded_item> <exepath> <dirs>)
  179. #
  180. # Get the direct/non-system prerequisites of the resolved embedded item.
  181. # For each prerequisite, change the way it is referenced to the value of
  182. # the _EMBEDDED_ITEM keyed variable for that prerequisite. (Most likely
  183. # changing to an "@executable_path" style reference.)
  184. #
  185. # This function requires that the resolved_embedded_item be "inside" the
  186. # bundle already. In other words, if you pass plugins to fixup_bundle
  187. # as the libs parameter, you should install them or copy them into the
  188. # bundle before calling fixup_bundle. The "libs" parameter is a list of
  189. # libraries that must be fixed up, but that cannot be determined by
  190. # otool output analysis. (i.e., plugins)
  191. #
  192. # Also, change the id of the item being fixed up to its own
  193. # _EMBEDDED_ITEM value.
  194. #
  195. # Accumulate changes in a local variable and make *one* call to
  196. # install_name_tool at the end of the function with all the changes at
  197. # once.
  198. #
  199. # If the BU_CHMOD_BUNDLE_ITEMS variable is set then bundle items will be
  200. # marked writable before install_name_tool tries to change them.
  201. #
  202. # ::
  203. #
  204. # VERIFY_BUNDLE_PREREQUISITES(<bundle> <result_var> <info_var>)
  205. #
  206. # Verifies that the sum of all prerequisites of all files inside the
  207. # bundle are contained within the bundle or are "system" libraries,
  208. # presumed to exist everywhere.
  209. #
  210. # As an optional parameter (IGNORE_ITEM) a list of file names can be passed,
  211. # which are then ignored (e.g. IGNORE_ITEM "vcredist_x86.exe;vcredist_x64.exe")
  212. #
  213. # ::
  214. #
  215. # VERIFY_BUNDLE_SYMLINKS(<bundle> <result_var> <info_var>)
  216. #
  217. # Verifies that any symlinks found in the bundle point to other files
  218. # that are already also in the bundle... Anything that points to an
  219. # external file causes this function to fail the verification.
  220. # The functions defined in this file depend on the get_prerequisites function
  221. # (and possibly others) found in:
  222. #
  223. get_filename_component(BundleUtilities_cmake_dir "${CMAKE_CURRENT_LIST_FILE}" PATH)
  224. include("${BundleUtilities_cmake_dir}/GetPrerequisites.cmake")
  225. function(get_bundle_main_executable bundle result_var)
  226. set(result "error: '${bundle}/Contents/Info.plist' file does not exist")
  227. if(EXISTS "${bundle}/Contents/Info.plist")
  228. set(result "error: no CFBundleExecutable in '${bundle}/Contents/Info.plist' file")
  229. set(line_is_main_executable 0)
  230. set(bundle_executable "")
  231. # Read Info.plist as a list of lines:
  232. #
  233. set(eol_char "E")
  234. file(READ "${bundle}/Contents/Info.plist" info_plist)
  235. string(REPLACE ";" "\\;" info_plist "${info_plist}")
  236. string(REPLACE "\n" "${eol_char};" info_plist "${info_plist}")
  237. string(REPLACE "\r" "${eol_char};" info_plist "${info_plist}")
  238. # Scan the lines for "<key>CFBundleExecutable</key>" - the line after that
  239. # is the name of the main executable.
  240. #
  241. foreach(line ${info_plist})
  242. if(line_is_main_executable)
  243. string(REGEX REPLACE "^.*<string>(.*)</string>.*$" "\\1" bundle_executable "${line}")
  244. break()
  245. endif()
  246. if(line MATCHES "<key>CFBundleExecutable</key>")
  247. set(line_is_main_executable 1)
  248. endif()
  249. endforeach()
  250. if(NOT "${bundle_executable}" STREQUAL "")
  251. if(EXISTS "${bundle}/Contents/MacOS/${bundle_executable}")
  252. set(result "${bundle}/Contents/MacOS/${bundle_executable}")
  253. else()
  254. # Ultimate goal:
  255. # If not in "Contents/MacOS" then scan the bundle for matching files. If
  256. # there is only one executable file that matches, then use it, otherwise
  257. # it's an error...
  258. #
  259. #file(GLOB_RECURSE file_list "${bundle}/${bundle_executable}")
  260. # But for now, pragmatically, it's an error. Expect the main executable
  261. # for the bundle to be in Contents/MacOS, it's an error if it's not:
  262. #
  263. set(result "error: '${bundle}/Contents/MacOS/${bundle_executable}' does not exist")
  264. endif()
  265. endif()
  266. else()
  267. #
  268. # More inclusive technique... (This one would work on Windows and Linux
  269. # too, if a developer followed the typical Mac bundle naming convention...)
  270. #
  271. # If there is no Info.plist file, try to find an executable with the same
  272. # base name as the .app directory:
  273. #
  274. endif()
  275. set(${result_var} "${result}" PARENT_SCOPE)
  276. endfunction()
  277. function(get_dotapp_dir exe dotapp_dir_var)
  278. set(s "${exe}")
  279. if(s MATCHES "/.*\\.app/")
  280. # If there is a ".app" parent directory,
  281. # ascend until we hit it:
  282. # (typical of a Mac bundle executable)
  283. #
  284. set(done 0)
  285. while(NOT ${done})
  286. get_filename_component(snamewe "${s}" NAME_WE)
  287. get_filename_component(sname "${s}" NAME)
  288. get_filename_component(sdir "${s}" PATH)
  289. set(s "${sdir}")
  290. if(sname MATCHES "\\.app$")
  291. set(done 1)
  292. set(dotapp_dir "${sdir}/${sname}")
  293. endif()
  294. endwhile()
  295. else()
  296. # Otherwise use a directory containing the exe
  297. # (typical of a non-bundle executable on Mac, Windows or Linux)
  298. #
  299. is_file_executable("${s}" is_executable)
  300. if(is_executable)
  301. get_filename_component(sdir "${s}" PATH)
  302. set(dotapp_dir "${sdir}")
  303. else()
  304. set(dotapp_dir "${s}")
  305. endif()
  306. endif()
  307. set(${dotapp_dir_var} "${dotapp_dir}" PARENT_SCOPE)
  308. endfunction()
  309. function(get_bundle_and_executable app bundle_var executable_var valid_var)
  310. set(valid 0)
  311. if(EXISTS "${app}")
  312. # Is it a directory ending in .app?
  313. if(IS_DIRECTORY "${app}")
  314. if(app MATCHES "\\.app$")
  315. get_bundle_main_executable("${app}" executable)
  316. if(EXISTS "${app}" AND EXISTS "${executable}")
  317. set(${bundle_var} "${app}" PARENT_SCOPE)
  318. set(${executable_var} "${executable}" PARENT_SCOPE)
  319. set(valid 1)
  320. #message(STATUS "info: handled .app directory case...")
  321. else()
  322. message(STATUS "warning: *NOT* handled - .app directory case...")
  323. endif()
  324. else()
  325. message(STATUS "warning: *NOT* handled - directory but not .app case...")
  326. endif()
  327. else()
  328. # Is it an executable file?
  329. is_file_executable("${app}" is_executable)
  330. if(is_executable)
  331. get_dotapp_dir("${app}" dotapp_dir)
  332. if(EXISTS "${dotapp_dir}")
  333. set(${bundle_var} "${dotapp_dir}" PARENT_SCOPE)
  334. set(${executable_var} "${app}" PARENT_SCOPE)
  335. set(valid 1)
  336. #message(STATUS "info: handled executable file in .app dir case...")
  337. else()
  338. get_filename_component(app_dir "${app}" PATH)
  339. set(${bundle_var} "${app_dir}" PARENT_SCOPE)
  340. set(${executable_var} "${app}" PARENT_SCOPE)
  341. set(valid 1)
  342. #message(STATUS "info: handled executable file in any dir case...")
  343. endif()
  344. else()
  345. message(STATUS "warning: *NOT* handled - not .app dir, not executable file...")
  346. endif()
  347. endif()
  348. else()
  349. message(STATUS "warning: *NOT* handled - directory/file does not exist...")
  350. endif()
  351. if(NOT valid)
  352. set(${bundle_var} "error: not a bundle" PARENT_SCOPE)
  353. set(${executable_var} "error: not a bundle" PARENT_SCOPE)
  354. endif()
  355. set(${valid_var} ${valid} PARENT_SCOPE)
  356. endfunction()
  357. function(get_bundle_all_executables bundle exes_var)
  358. set(exes "")
  359. if(UNIX)
  360. find_program(find_cmd "find")
  361. mark_as_advanced(find_cmd)
  362. endif()
  363. # find command is much quicker than checking every file one by one on Unix
  364. # which can take long time for large bundles, and since anyway we expect
  365. # executable to have execute flag set we can narrow the list much quicker.
  366. if(find_cmd)
  367. execute_process(COMMAND "${find_cmd}" "${bundle}"
  368. -type f \( -perm -0100 -o -perm -0010 -o -perm -0001 \)
  369. OUTPUT_VARIABLE file_list
  370. OUTPUT_STRIP_TRAILING_WHITESPACE
  371. )
  372. string(REPLACE "\n" ";" file_list "${file_list}")
  373. else()
  374. file(GLOB_RECURSE file_list "${bundle}/*")
  375. endif()
  376. foreach(f ${file_list})
  377. is_file_executable("${f}" is_executable)
  378. if(is_executable)
  379. set(exes ${exes} "${f}")
  380. endif()
  381. endforeach()
  382. set(${exes_var} "${exes}" PARENT_SCOPE)
  383. endfunction()
  384. function(get_item_rpaths item rpaths_var)
  385. if(APPLE)
  386. find_program(otool_cmd "otool")
  387. mark_as_advanced(otool_cmd)
  388. endif()
  389. if(otool_cmd)
  390. execute_process(
  391. COMMAND "${otool_cmd}" -l "${item}"
  392. OUTPUT_VARIABLE load_cmds_ov
  393. )
  394. string(REGEX REPLACE "[^\n]+cmd LC_RPATH\n[^\n]+\n[^\n]+path ([^\n]+) \\(offset[^\n]+\n" "rpath \\1\n" load_cmds_ov "${load_cmds_ov}")
  395. string(REGEX MATCHALL "rpath [^\n]+" load_cmds_ov "${load_cmds_ov}")
  396. string(REGEX REPLACE "rpath " "" load_cmds_ov "${load_cmds_ov}")
  397. if(load_cmds_ov)
  398. foreach(rpath ${load_cmds_ov})
  399. gp_append_unique(${rpaths_var} "${rpath}")
  400. endforeach()
  401. endif()
  402. endif()
  403. if(UNIX AND NOT APPLE)
  404. file(READ_ELF ${item} RPATH rpath_var RUNPATH runpath_var CAPTURE_ERROR error_var)
  405. get_filename_component(item_dir ${item} DIRECTORY)
  406. foreach(rpath ${rpath_var} ${runpath_var})
  407. # Substitute $ORIGIN with the exepath and add to the found rpaths
  408. string(REPLACE "$ORIGIN" "${item_dir}" rpath "${rpath}")
  409. gp_append_unique(${rpaths_var} "${rpath}")
  410. endforeach()
  411. endif()
  412. set(${rpaths_var} ${${rpaths_var}} PARENT_SCOPE)
  413. endfunction()
  414. function(get_item_key item key_var)
  415. get_filename_component(item_name "${item}" NAME)
  416. if(WIN32)
  417. string(TOLOWER "${item_name}" item_name)
  418. endif()
  419. string(REPLACE "." "_" ${key_var} "${item_name}")
  420. set(${key_var} ${${key_var}} PARENT_SCOPE)
  421. endfunction()
  422. function(clear_bundle_keys keys_var)
  423. foreach(key ${${keys_var}})
  424. set(${key}_ITEM PARENT_SCOPE)
  425. set(${key}_RESOLVED_ITEM PARENT_SCOPE)
  426. set(${key}_DEFAULT_EMBEDDED_PATH PARENT_SCOPE)
  427. set(${key}_EMBEDDED_ITEM PARENT_SCOPE)
  428. set(${key}_RESOLVED_EMBEDDED_ITEM PARENT_SCOPE)
  429. set(${key}_COPYFLAG PARENT_SCOPE)
  430. set(${key}_RPATHS PARENT_SCOPE)
  431. endforeach()
  432. set(${keys_var} PARENT_SCOPE)
  433. endfunction()
  434. function(set_bundle_key_values keys_var context item exepath dirs copyflag)
  435. if(ARGC GREATER 6)
  436. set(rpaths "${ARGV6}")
  437. else()
  438. set(rpaths "")
  439. endif()
  440. get_filename_component(item_name "${item}" NAME)
  441. get_item_key("${item}" key)
  442. list(LENGTH ${keys_var} length_before)
  443. gp_append_unique(${keys_var} "${key}")
  444. list(LENGTH ${keys_var} length_after)
  445. if(NOT length_before EQUAL length_after)
  446. gp_resolve_item("${context}" "${item}" "${exepath}" "${dirs}" resolved_item "${rpaths}")
  447. gp_item_default_embedded_path("${item}" default_embedded_path)
  448. get_item_rpaths("${resolved_item}" item_rpaths)
  449. if((NOT item MATCHES "\\.dylib$") AND (item MATCHES "[^/]+\\.framework/"))
  450. # For frameworks, construct the name under the embedded path from the
  451. # opening "${item_name}.framework/" to the closing "/${item_name}":
  452. #
  453. string(REGEX REPLACE "^.*(${item_name}.framework/.*/?${item_name}).*$" "${default_embedded_path}/\\1" embedded_item "${item}")
  454. else()
  455. # For other items, just use the same name as the original, but in the
  456. # embedded path:
  457. #
  458. set(embedded_item "${default_embedded_path}/${item_name}")
  459. endif()
  460. # Replace @executable_path and resolve ".." references:
  461. #
  462. string(REPLACE "@executable_path" "${exepath}" resolved_embedded_item "${embedded_item}")
  463. get_filename_component(resolved_embedded_item "${resolved_embedded_item}" ABSOLUTE)
  464. # *But* -- if we are not copying, then force resolved_embedded_item to be
  465. # the same as resolved_item. In the case of multiple executables in the
  466. # original bundle, using the default_embedded_path results in looking for
  467. # the resolved executable next to the main bundle executable. This is here
  468. # so that exes in the other sibling directories (like "bin") get fixed up
  469. # properly...
  470. #
  471. if(NOT copyflag)
  472. set(resolved_embedded_item "${resolved_item}")
  473. endif()
  474. set(${keys_var} ${${keys_var}} PARENT_SCOPE)
  475. set(${key}_ITEM "${item}" PARENT_SCOPE)
  476. set(${key}_RESOLVED_ITEM "${resolved_item}" PARENT_SCOPE)
  477. set(${key}_DEFAULT_EMBEDDED_PATH "${default_embedded_path}" PARENT_SCOPE)
  478. set(${key}_EMBEDDED_ITEM "${embedded_item}" PARENT_SCOPE)
  479. set(${key}_RESOLVED_EMBEDDED_ITEM "${resolved_embedded_item}" PARENT_SCOPE)
  480. set(${key}_COPYFLAG "${copyflag}" PARENT_SCOPE)
  481. set(${key}_RPATHS "${item_rpaths}" PARENT_SCOPE)
  482. set(${key}_RDEP_RPATHS "${rpaths}" PARENT_SCOPE)
  483. else()
  484. #message("warning: item key '${key}' already in the list, subsequent references assumed identical to first")
  485. endif()
  486. endfunction()
  487. function(get_bundle_keys app libs dirs keys_var)
  488. set(${keys_var} PARENT_SCOPE)
  489. set(options)
  490. set(oneValueArgs)
  491. set(multiValueArgs IGNORE_ITEM)
  492. cmake_parse_arguments(CFG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
  493. get_bundle_and_executable("${app}" bundle executable valid)
  494. if(valid)
  495. # Always use the exepath of the main bundle executable for @executable_path
  496. # replacements:
  497. #
  498. get_filename_component(exepath "${executable}" PATH)
  499. # But do fixups on all executables in the bundle:
  500. #
  501. get_bundle_all_executables("${bundle}" exes)
  502. # Set keys for main executable first:
  503. #
  504. set_bundle_key_values(${keys_var} "${executable}" "${executable}" "${exepath}" "${dirs}" 0)
  505. # Get rpaths specified by main executable:
  506. #
  507. get_item_key("${executable}" executable_key)
  508. set(main_rpaths "${${executable_key}_RPATHS}")
  509. # For each extra lib, accumulate a key as well and then also accumulate
  510. # any of its prerequisites. (Extra libs are typically dynamically loaded
  511. # plugins: libraries that are prerequisites for full runtime functionality
  512. # but that do not show up in otool -L output...)
  513. #
  514. foreach(lib ${libs})
  515. set_bundle_key_values(${keys_var} "${lib}" "${lib}" "${exepath}" "${dirs}" 0 "${main_rpaths}")
  516. set(prereqs "")
  517. set(ignoreFile FALSE)
  518. get_filename_component(prereq_filename ${lib} NAME)
  519. if(NOT "${CFG_IGNORE_ITEM}" STREQUAL "" )
  520. foreach(item ${CFG_IGNORE_ITEM})
  521. if("${item}" STREQUAL "${prereq_filename}")
  522. set(ignoreFile TRUE)
  523. endif()
  524. endforeach()
  525. endif()
  526. if(NOT ignoreFile)
  527. get_prerequisites("${lib}" prereqs 1 1 "${exepath}" "${dirs}" "${main_rpaths}")
  528. foreach(pr ${prereqs})
  529. set_bundle_key_values(${keys_var} "${lib}" "${pr}" "${exepath}" "${dirs}" 1 "${main_rpaths}")
  530. endforeach()
  531. else()
  532. message(STATUS "Ignoring file: ${prereq_filename}")
  533. endif()
  534. endforeach()
  535. # For each executable found in the bundle, accumulate keys as we go.
  536. # The list of keys should be complete when all prerequisites of all
  537. # binaries in the bundle have been analyzed.
  538. #
  539. foreach(exe ${exes})
  540. # Main executable is scanned first above:
  541. #
  542. if(NOT "${exe}" STREQUAL "${executable}")
  543. # Add the exe itself to the keys:
  544. #
  545. set_bundle_key_values(${keys_var} "${exe}" "${exe}" "${exepath}" "${dirs}" 0 "${main_rpaths}")
  546. # Get rpaths specified by executable:
  547. #
  548. get_item_key("${exe}" exe_key)
  549. set(exe_rpaths "${main_rpaths}" "${${exe_key}_RPATHS}")
  550. else()
  551. set(exe_rpaths "${main_rpaths}")
  552. endif()
  553. # Add each prerequisite to the keys:
  554. #
  555. set(prereqs "")
  556. set(ignoreFile FALSE)
  557. get_filename_component(prereq_filename ${exe} NAME)
  558. if(NOT "${CFG_IGNORE_ITEM}" STREQUAL "" )
  559. foreach(item ${CFG_IGNORE_ITEM})
  560. if("${item}" STREQUAL "${prereq_filename}")
  561. set(ignoreFile TRUE)
  562. endif()
  563. endforeach()
  564. endif()
  565. if(NOT ignoreFile)
  566. get_prerequisites("${exe}" prereqs 1 1 "${exepath}" "${dirs}" "${exe_rpaths}")
  567. foreach(pr ${prereqs})
  568. set_bundle_key_values(${keys_var} "${exe}" "${pr}" "${exepath}" "${dirs}" 1 "${exe_rpaths}")
  569. endforeach()
  570. else()
  571. message(STATUS "Ignoring file: ${prereq_filename}")
  572. endif()
  573. endforeach()
  574. # preserve library symlink structure
  575. foreach(key ${${keys_var}})
  576. if("${${key}_COPYFLAG}" STREQUAL 1)
  577. if(IS_SYMLINK "${${key}_RESOLVED_ITEM}")
  578. get_filename_component(target "${${key}_RESOLVED_ITEM}" REALPATH)
  579. set_bundle_key_values(${keys_var} "${exe}" "${target}" "${exepath}" "${dirs}" 1 "${exe_rpaths}")
  580. get_item_key("${target}" targetkey)
  581. if(WIN32)
  582. # ignore case on Windows
  583. string(TOLOWER "${${key}_RESOLVED_ITEM}" resolved_item_compare)
  584. string(TOLOWER "${${targetkey}_RESOLVED_EMBEDDED_ITEM}" resolved_embedded_item_compare)
  585. else()
  586. set(resolved_item_compare "${${key}_RESOLVED_ITEM}")
  587. set(resolved_embedded_item_compare "${${targetkey}_RESOLVED_EMBEDDED_ITEM}")
  588. endif()
  589. get_filename_component(resolved_item_compare "${resolved_item_compare}" NAME)
  590. get_filename_component(resolved_embedded_item_compare "${resolved_embedded_item_compare}" NAME)
  591. if(NOT "${resolved_item_compare}" STREQUAL "${resolved_embedded_item_compare}")
  592. set(${key}_COPYFLAG "2")
  593. set(${key}_RESOLVED_ITEM "${${targetkey}_RESOLVED_EMBEDDED_ITEM}")
  594. endif()
  595. endif()
  596. endif()
  597. endforeach()
  598. # Propagate values to caller's scope:
  599. #
  600. set(${keys_var} ${${keys_var}} PARENT_SCOPE)
  601. foreach(key ${${keys_var}})
  602. set(${key}_ITEM "${${key}_ITEM}" PARENT_SCOPE)
  603. set(${key}_RESOLVED_ITEM "${${key}_RESOLVED_ITEM}" PARENT_SCOPE)
  604. set(${key}_DEFAULT_EMBEDDED_PATH "${${key}_DEFAULT_EMBEDDED_PATH}" PARENT_SCOPE)
  605. set(${key}_EMBEDDED_ITEM "${${key}_EMBEDDED_ITEM}" PARENT_SCOPE)
  606. set(${key}_RESOLVED_EMBEDDED_ITEM "${${key}_RESOLVED_EMBEDDED_ITEM}" PARENT_SCOPE)
  607. set(${key}_COPYFLAG "${${key}_COPYFLAG}" PARENT_SCOPE)
  608. set(${key}_RPATHS "${${key}_RPATHS}" PARENT_SCOPE)
  609. set(${key}_RDEP_RPATHS "${${key}_RDEP_RPATHS}" PARENT_SCOPE)
  610. endforeach()
  611. endif()
  612. endfunction()
  613. function(link_resolved_item_into_bundle resolved_item resolved_embedded_item)
  614. if(WIN32)
  615. # ignore case on Windows
  616. string(TOLOWER "${resolved_item}" resolved_item_compare)
  617. string(TOLOWER "${resolved_embedded_item}" resolved_embedded_item_compare)
  618. else()
  619. set(resolved_item_compare "${resolved_item}")
  620. set(resolved_embedded_item_compare "${resolved_embedded_item}")
  621. endif()
  622. if("${resolved_item_compare}" STREQUAL "${resolved_embedded_item_compare}")
  623. message(STATUS "warning: resolved_item == resolved_embedded_item - not linking...")
  624. else()
  625. get_filename_component(target_dir "${resolved_embedded_item}" DIRECTORY)
  626. file(RELATIVE_PATH symlink_target "${target_dir}" "${resolved_item}")
  627. execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${symlink_target}" "${resolved_embedded_item}")
  628. endif()
  629. endfunction()
  630. function(copy_resolved_item_into_bundle resolved_item resolved_embedded_item)
  631. if(WIN32)
  632. # ignore case on Windows
  633. string(TOLOWER "${resolved_item}" resolved_item_compare)
  634. string(TOLOWER "${resolved_embedded_item}" resolved_embedded_item_compare)
  635. else()
  636. set(resolved_item_compare "${resolved_item}")
  637. set(resolved_embedded_item_compare "${resolved_embedded_item}")
  638. endif()
  639. if("${resolved_item_compare}" STREQUAL "${resolved_embedded_item_compare}")
  640. message(STATUS "warning: resolved_item == resolved_embedded_item - not copying...")
  641. else()
  642. #message(STATUS "copying COMMAND ${CMAKE_COMMAND} -E copy ${resolved_item} ${resolved_embedded_item}")
  643. execute_process(COMMAND ${CMAKE_COMMAND} -E copy "${resolved_item}" "${resolved_embedded_item}")
  644. if(UNIX AND NOT APPLE)
  645. file(RPATH_REMOVE FILE "${resolved_embedded_item}")
  646. endif()
  647. endif()
  648. endfunction()
  649. function(copy_resolved_framework_into_bundle resolved_item resolved_embedded_item)
  650. if(WIN32)
  651. # ignore case on Windows
  652. string(TOLOWER "${resolved_item}" resolved_item_compare)
  653. string(TOLOWER "${resolved_embedded_item}" resolved_embedded_item_compare)
  654. else()
  655. set(resolved_item_compare "${resolved_item}")
  656. set(resolved_embedded_item_compare "${resolved_embedded_item}")
  657. endif()
  658. if("${resolved_item_compare}" STREQUAL "${resolved_embedded_item_compare}")
  659. message(STATUS "warning: resolved_item == resolved_embedded_item - not copying...")
  660. else()
  661. if(BU_COPY_FULL_FRAMEWORK_CONTENTS)
  662. # Full Framework (everything):
  663. get_filename_component(resolved_dir "${resolved_item}" PATH)
  664. get_filename_component(resolved_dir "${resolved_dir}/../.." ABSOLUTE)
  665. get_filename_component(resolved_embedded_dir "${resolved_embedded_item}" PATH)
  666. get_filename_component(resolved_embedded_dir "${resolved_embedded_dir}/../.." ABSOLUTE)
  667. #message(STATUS "copying COMMAND ${CMAKE_COMMAND} -E copy_directory '${resolved_dir}' '${resolved_embedded_dir}'")
  668. execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory "${resolved_dir}" "${resolved_embedded_dir}")
  669. else()
  670. # Framework lib itself:
  671. #message(STATUS "copying COMMAND ${CMAKE_COMMAND} -E copy ${resolved_item} ${resolved_embedded_item}")
  672. execute_process(COMMAND ${CMAKE_COMMAND} -E copy "${resolved_item}" "${resolved_embedded_item}")
  673. # Plus Resources, if they exist:
  674. string(REGEX REPLACE "^(.*)/[^/]+$" "\\1/Resources" resolved_resources "${resolved_item}")
  675. string(REGEX REPLACE "^(.*)/[^/]+$" "\\1/Resources" resolved_embedded_resources "${resolved_embedded_item}")
  676. if(EXISTS "${resolved_resources}")
  677. #message(STATUS "copying COMMAND ${CMAKE_COMMAND} -E copy_directory '${resolved_resources}' '${resolved_embedded_resources}'")
  678. execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory "${resolved_resources}" "${resolved_embedded_resources}")
  679. endif()
  680. # Some frameworks e.g. Qt put Info.plist in wrong place, so when it is
  681. # missing in resources, copy it from other well known incorrect locations:
  682. if(NOT EXISTS "${resolved_resources}/Info.plist")
  683. # Check for Contents/Info.plist in framework root (older Qt SDK):
  684. string(REGEX REPLACE "^(.*)/[^/]+/[^/]+/[^/]+$" "\\1/Contents/Info.plist" resolved_info_plist "${resolved_item}")
  685. string(REGEX REPLACE "^(.*)/[^/]+$" "\\1/Resources/Info.plist" resolved_embedded_info_plist "${resolved_embedded_item}")
  686. if(EXISTS "${resolved_info_plist}")
  687. #message(STATUS "copying COMMAND ${CMAKE_COMMAND} -E copy_directory '${resolved_info_plist}' '${resolved_embedded_info_plist}'")
  688. execute_process(COMMAND ${CMAKE_COMMAND} -E copy "${resolved_info_plist}" "${resolved_embedded_info_plist}")
  689. endif()
  690. endif()
  691. # Check if framework is versioned and fix it layout
  692. string(REGEX REPLACE "^.*/([^/]+)/[^/]+$" "\\1" resolved_embedded_version "${resolved_embedded_item}")
  693. string(REGEX REPLACE "^(.*)/[^/]+/[^/]+$" "\\1" resolved_embedded_versions "${resolved_embedded_item}")
  694. string(REGEX REPLACE "^.*/([^/]+)/[^/]+/[^/]+$" "\\1" resolved_embedded_versions_basename "${resolved_embedded_item}")
  695. if(resolved_embedded_versions_basename STREQUAL "Versions")
  696. # Ensure Current symlink points to the framework version
  697. if(NOT EXISTS "${resolved_embedded_versions}/Current")
  698. execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${resolved_embedded_version}" "${resolved_embedded_versions}/Current")
  699. endif()
  700. # Restore symlinks in framework root pointing to current framework
  701. # binary and resources:
  702. string(REGEX REPLACE "^(.*)/[^/]+/[^/]+/[^/]+$" "\\1" resolved_embedded_root "${resolved_embedded_item}")
  703. string(REGEX REPLACE "^.*/([^/]+)$" "\\1" resolved_embedded_item_basename "${resolved_embedded_item}")
  704. if(NOT EXISTS "${resolved_embedded_root}/${resolved_embedded_item_basename}")
  705. execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "Versions/Current/${resolved_embedded_item_basename}" "${resolved_embedded_root}/${resolved_embedded_item_basename}")
  706. endif()
  707. if(NOT EXISTS "${resolved_embedded_root}/Resources")
  708. execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "Versions/Current/Resources" "${resolved_embedded_root}/Resources")
  709. endif()
  710. endif()
  711. endif()
  712. if(UNIX AND NOT APPLE)
  713. file(RPATH_REMOVE FILE "${resolved_embedded_item}")
  714. endif()
  715. endif()
  716. endfunction()
  717. function(fixup_bundle_item resolved_embedded_item exepath dirs)
  718. # This item's key is "ikey":
  719. #
  720. get_item_key("${resolved_embedded_item}" ikey)
  721. # Ensure the item is "inside the .app bundle" -- it should not be fixed up if
  722. # it is not in the .app bundle... Otherwise, we'll modify files in the build
  723. # tree, or in other varied locations around the file system, with our call to
  724. # install_name_tool. Make sure that doesn't happen here:
  725. #
  726. get_dotapp_dir("${exepath}" exe_dotapp_dir)
  727. string(LENGTH "${exe_dotapp_dir}/" exe_dotapp_dir_length)
  728. string(LENGTH "${resolved_embedded_item}" resolved_embedded_item_length)
  729. set(path_too_short 0)
  730. set(is_embedded 0)
  731. if(${resolved_embedded_item_length} LESS ${exe_dotapp_dir_length})
  732. set(path_too_short 1)
  733. endif()
  734. if(NOT path_too_short)
  735. string(SUBSTRING "${resolved_embedded_item}" 0 ${exe_dotapp_dir_length} item_substring)
  736. if("${exe_dotapp_dir}/" STREQUAL "${item_substring}")
  737. set(is_embedded 1)
  738. endif()
  739. endif()
  740. if(NOT is_embedded)
  741. message(" exe_dotapp_dir/='${exe_dotapp_dir}/'")
  742. message(" item_substring='${item_substring}'")
  743. message(" resolved_embedded_item='${resolved_embedded_item}'")
  744. message("")
  745. message("Install or copy the item into the bundle before calling fixup_bundle.")
  746. message("Or maybe there's a typo or incorrect path in one of the args to fixup_bundle?")
  747. message("")
  748. message(FATAL_ERROR "cannot fixup an item that is not in the bundle...")
  749. endif()
  750. set(rpaths "${${ikey}_RPATHS}" "${${ikey}_RDEP_RPATHS}")
  751. set(prereqs "")
  752. get_prerequisites("${resolved_embedded_item}" prereqs 1 0 "${exepath}" "${dirs}" "${rpaths}")
  753. set(changes "")
  754. foreach(pr ${prereqs})
  755. # Each referenced item's key is "rkey" in the loop:
  756. #
  757. get_item_key("${pr}" rkey)
  758. if(NOT "${${rkey}_EMBEDDED_ITEM}" STREQUAL "")
  759. set(changes ${changes} "-change" "${pr}" "${${rkey}_EMBEDDED_ITEM}")
  760. else()
  761. message("warning: unexpected reference to '${pr}'")
  762. endif()
  763. endforeach()
  764. if(BU_CHMOD_BUNDLE_ITEMS)
  765. execute_process(COMMAND chmod u+w "${resolved_embedded_item}")
  766. endif()
  767. # Only if install_name_tool supports -delete_rpath:
  768. #
  769. execute_process(COMMAND install_name_tool
  770. OUTPUT_VARIABLE install_name_tool_usage
  771. ERROR_VARIABLE install_name_tool_usage
  772. )
  773. if(install_name_tool_usage MATCHES ".*-delete_rpath.*")
  774. foreach(rpath ${${ikey}_RPATHS})
  775. set(changes ${changes} -delete_rpath "${rpath}")
  776. endforeach()
  777. endif()
  778. if(${ikey}_EMBEDDED_ITEM)
  779. set(changes ${changes} -id "${${ikey}_EMBEDDED_ITEM}")
  780. endif()
  781. # Change this item's id and all of its references in one call
  782. # to install_name_tool:
  783. #
  784. if(changes)
  785. set(cmd install_name_tool ${changes} "${resolved_embedded_item}")
  786. execute_process(COMMAND ${cmd} RESULT_VARIABLE install_name_tool_result)
  787. if(NOT install_name_tool_result EQUAL 0)
  788. string(REPLACE ";" "' '" msg "'${cmd}'")
  789. message(FATAL_ERROR "Command failed:\n ${msg}")
  790. endif()
  791. endif()
  792. endfunction()
  793. function(fixup_bundle app libs dirs)
  794. message(STATUS "fixup_bundle")
  795. message(STATUS " app='${app}'")
  796. message(STATUS " libs='${libs}'")
  797. message(STATUS " dirs='${dirs}'")
  798. set(options)
  799. set(oneValueArgs)
  800. set(multiValueArgs IGNORE_ITEM)
  801. cmake_parse_arguments(CFG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
  802. message(STATUS " ignoreItems='${CFG_IGNORE_ITEM}'")
  803. get_bundle_and_executable("${app}" bundle executable valid)
  804. if(valid)
  805. get_filename_component(exepath "${executable}" PATH)
  806. message(STATUS "fixup_bundle: preparing...")
  807. get_bundle_keys("${app}" "${libs}" "${dirs}" keys IGNORE_ITEM "${CFG_IGNORE_ITEM}")
  808. message(STATUS "fixup_bundle: copying...")
  809. list(LENGTH keys n)
  810. math(EXPR n ${n}*2)
  811. set(i 0)
  812. foreach(key ${keys})
  813. math(EXPR i ${i}+1)
  814. if("${${key}_COPYFLAG}" STREQUAL "2")
  815. message(STATUS "${i}/${n}: linking '${${key}_RESOLVED_ITEM}' -> '${${key}_RESOLVED_EMBEDDED_ITEM}'")
  816. elseif(${${key}_COPYFLAG})
  817. message(STATUS "${i}/${n}: copying '${${key}_RESOLVED_ITEM}'")
  818. else()
  819. message(STATUS "${i}/${n}: *NOT* copying '${${key}_RESOLVED_ITEM}'")
  820. endif()
  821. set(show_status 0)
  822. if(show_status)
  823. message(STATUS "key='${key}'")
  824. message(STATUS "item='${${key}_ITEM}'")
  825. message(STATUS "resolved_item='${${key}_RESOLVED_ITEM}'")
  826. message(STATUS "default_embedded_path='${${key}_DEFAULT_EMBEDDED_PATH}'")
  827. message(STATUS "embedded_item='${${key}_EMBEDDED_ITEM}'")
  828. message(STATUS "resolved_embedded_item='${${key}_RESOLVED_EMBEDDED_ITEM}'")
  829. message(STATUS "copyflag='${${key}_COPYFLAG}'")
  830. message(STATUS "")
  831. endif()
  832. if("${${key}_COPYFLAG}" STREQUAL "2")
  833. link_resolved_item_into_bundle("${${key}_RESOLVED_ITEM}"
  834. "${${key}_RESOLVED_EMBEDDED_ITEM}")
  835. elseif(${${key}_COPYFLAG})
  836. set(item "${${key}_ITEM}")
  837. if(item MATCHES "[^/]+\\.framework/")
  838. copy_resolved_framework_into_bundle("${${key}_RESOLVED_ITEM}"
  839. "${${key}_RESOLVED_EMBEDDED_ITEM}")
  840. else()
  841. copy_resolved_item_into_bundle("${${key}_RESOLVED_ITEM}"
  842. "${${key}_RESOLVED_EMBEDDED_ITEM}")
  843. endif()
  844. endif()
  845. endforeach()
  846. message(STATUS "fixup_bundle: fixing...")
  847. foreach(key ${keys})
  848. math(EXPR i ${i}+1)
  849. if(APPLE)
  850. message(STATUS "${i}/${n}: fixing up '${${key}_RESOLVED_EMBEDDED_ITEM}'")
  851. if(NOT "${${key}_COPYFLAG}" STREQUAL "2")
  852. fixup_bundle_item("${${key}_RESOLVED_EMBEDDED_ITEM}" "${exepath}" "${dirs}")
  853. endif()
  854. else()
  855. message(STATUS "${i}/${n}: fix-up not required on this platform '${${key}_RESOLVED_EMBEDDED_ITEM}'")
  856. endif()
  857. endforeach()
  858. message(STATUS "fixup_bundle: cleaning up...")
  859. clear_bundle_keys(keys)
  860. message(STATUS "fixup_bundle: verifying...")
  861. verify_app("${app}" IGNORE_ITEM "${CFG_IGNORE_ITEM}")
  862. else()
  863. message(SEND_ERROR "error: fixup_bundle: not a valid bundle")
  864. endif()
  865. message(STATUS "fixup_bundle: done")
  866. endfunction()
  867. function(copy_and_fixup_bundle src dst libs dirs)
  868. execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory "${src}" "${dst}")
  869. fixup_bundle("${dst}" "${libs}" "${dirs}")
  870. endfunction()
  871. function(verify_bundle_prerequisites bundle result_var info_var)
  872. set(result 1)
  873. set(info "")
  874. set(count 0)
  875. set(options)
  876. set(oneValueArgs)
  877. set(multiValueArgs IGNORE_ITEM)
  878. cmake_parse_arguments(CFG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
  879. get_bundle_main_executable("${bundle}" main_bundle_exe)
  880. get_bundle_all_executables("${bundle}" file_list)
  881. foreach(f ${file_list})
  882. get_filename_component(exepath "${f}" PATH)
  883. math(EXPR count "${count} + 1")
  884. message(STATUS "executable file ${count}: ${f}")
  885. set(prereqs "")
  886. set(ignoreFile FALSE)
  887. get_filename_component(prereq_filename ${f} NAME)
  888. if(NOT "${CFG_IGNORE_ITEM}" STREQUAL "" )
  889. foreach(item ${CFG_IGNORE_ITEM})
  890. if("${item}" STREQUAL "${prereq_filename}")
  891. set(ignoreFile TRUE)
  892. endif()
  893. endforeach()
  894. endif()
  895. if(NOT ignoreFile)
  896. get_item_rpaths(${f} _main_exe_rpaths)
  897. get_prerequisites("${f}" prereqs 1 1 "${exepath}" "${_main_exe_rpaths}")
  898. # On the Mac,
  899. # "embedded" and "system" prerequisites are fine... anything else means
  900. # the bundle's prerequisites are not verified (i.e., the bundle is not
  901. # really "standalone")
  902. #
  903. # On Windows (and others? Linux/Unix/...?)
  904. # "local" and "system" prereqs are fine...
  905. #
  906. set(external_prereqs "")
  907. foreach(p ${prereqs})
  908. set(p_type "")
  909. gp_file_type("${f}" "${p}" p_type)
  910. if(APPLE)
  911. if(NOT "${p_type}" STREQUAL "embedded" AND NOT "${p_type}" STREQUAL "system")
  912. set(external_prereqs ${external_prereqs} "${p}")
  913. endif()
  914. else()
  915. if(NOT "${p_type}" STREQUAL "local" AND NOT "${p_type}" STREQUAL "system")
  916. set(external_prereqs ${external_prereqs} "${p}")
  917. endif()
  918. endif()
  919. endforeach()
  920. if(external_prereqs)
  921. # Found non-system/somehow-unacceptable prerequisites:
  922. set(result 0)
  923. set(info ${info} "external prerequisites found:\nf='${f}'\nexternal_prereqs='${external_prereqs}'\n")
  924. endif()
  925. else()
  926. message(STATUS "Ignoring file: ${prereq_filename}")
  927. endif()
  928. endforeach()
  929. if(result)
  930. set(info "Verified ${count} executable files in '${bundle}'")
  931. endif()
  932. set(${result_var} "${result}" PARENT_SCOPE)
  933. set(${info_var} "${info}" PARENT_SCOPE)
  934. endfunction()
  935. function(verify_bundle_symlinks bundle result_var info_var)
  936. set(result 1)
  937. set(info "")
  938. set(count 0)
  939. # TODO: implement this function for real...
  940. # Right now, it is just a stub that verifies unconditionally...
  941. set(${result_var} "${result}" PARENT_SCOPE)
  942. set(${info_var} "${info}" PARENT_SCOPE)
  943. endfunction()
  944. function(verify_app app)
  945. set(verified 0)
  946. set(info "")
  947. set(options)
  948. set(oneValueArgs)
  949. set(multiValueArgs IGNORE_ITEM)
  950. cmake_parse_arguments(CFG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
  951. get_bundle_and_executable("${app}" bundle executable valid)
  952. message(STATUS "===========================================================================")
  953. message(STATUS "Analyzing app='${app}'")
  954. message(STATUS "bundle='${bundle}'")
  955. message(STATUS "executable='${executable}'")
  956. message(STATUS "valid='${valid}'")
  957. # Verify that the bundle does not have any "external" prerequisites:
  958. #
  959. verify_bundle_prerequisites("${bundle}" verified info IGNORE_ITEM "${CFG_IGNORE_ITEM}")
  960. message(STATUS "verified='${verified}'")
  961. message(STATUS "info='${info}'")
  962. message(STATUS "")
  963. if(verified)
  964. # Verify that the bundle does not have any symlinks to external files:
  965. #
  966. verify_bundle_symlinks("${bundle}" verified info)
  967. message(STATUS "verified='${verified}'")
  968. message(STATUS "info='${info}'")
  969. message(STATUS "")
  970. endif()
  971. if(NOT verified)
  972. message(FATAL_ERROR "error: verify_app failed")
  973. endif()
  974. endfunction()