1 # - Functions to help assemble a standalone bundle application.
2 # A collection of CMake utility functions useful for dealing with .app
3 # bundles on the Mac and bundle-like directories on any OS.
5 # The following functions are provided by this module:
7 # copy_and_fixup_bundle
9 # get_bundle_main_executable
11 # get_bundle_and_executable
12 # get_bundle_all_executables
15 # set_bundle_key_values
17 # copy_resolved_item_into_bundle
18 # copy_resolved_framework_into_bundle
20 # verify_bundle_prerequisites
21 # verify_bundle_symlinks
22 # Requires CMake 2.6 or greater because it uses function, break and
23 # PARENT_SCOPE. Also depends on GetPrerequisites.cmake.
25 # FIXUP_BUNDLE(<app> <libs> <dirs>)
26 # Fix up a bundle in-place and make it standalone, such that it can be
27 # drag-n-drop copied to another machine and run on that machine as long as all
28 # of the system libraries are compatible.
30 # If you pass plugins to fixup_bundle as the libs parameter, you should install
31 # them or copy them into the bundle before calling fixup_bundle. The "libs"
32 # parameter is a list of libraries that must be fixed up, but that cannot be
33 # determined by otool output analysis. (i.e., plugins)
35 # Gather all the keys for all the executables and libraries in a bundle, and
36 # then, for each key, copy each prerequisite into the bundle. Then fix each one
37 # up according to its own list of prerequisites.
39 # Then clear all the keys and call verify_app on the final bundle to ensure
40 # that it is truly standalone.
42 # COPY_AND_FIXUP_BUNDLE(<src> <dst> <libs> <dirs>)
43 # Makes a copy of the bundle <src> at location <dst> and then fixes up the
44 # new copied bundle in-place at <dst>...
47 # Verifies that an application <app> appears valid based on running analysis
48 # tools on it. Calls "message(FATAL_ERROR" if the application is not verified.
50 # GET_BUNDLE_MAIN_EXECUTABLE(<bundle> <result_var>)
51 # The result will be the full path name of the bundle's main executable file
52 # or an "error:" prefixed string if it could not be determined.
54 # GET_DOTAPP_DIR(<exe> <dotapp_dir_var>)
55 # Returns the nearest parent dir whose name ends with ".app" given the full
56 # path to an executable. If there is no such parent dir, then simply return
57 # the dir containing the executable.
59 # The returned directory may or may not exist.
61 # GET_BUNDLE_AND_EXECUTABLE(<app> <bundle_var> <executable_var> <valid_var>)
62 # Takes either a ".app" directory name or the name of an executable
63 # nested inside a ".app" directory and returns the path to the ".app"
64 # directory in <bundle_var> and the path to its main executable in
67 # GET_BUNDLE_ALL_EXECUTABLES(<bundle> <exes_var>)
68 # Scans the given bundle recursively for all executable files and accumulates
69 # them into a variable.
71 # GET_ITEM_KEY(<item> <key_var>)
72 # Given a file (item) name, generate a key that should be unique considering
73 # the set of libraries that need copying or fixing up to make a bundle
74 # standalone. This is essentially the file name including extension with "."
77 # This key is used as a prefix for CMake variables so that we can associate a
78 # set of variables with a given item based on its key.
80 # CLEAR_BUNDLE_KEYS(<keys_var>)
81 # Loop over the list of keys, clearing all the variables associated with each
82 # key. After the loop, clear the list of keys itself.
84 # Caller of get_bundle_keys should call clear_bundle_keys when done with list
87 # SET_BUNDLE_KEY_VALUES(<keys_var> <context> <item> <exepath> <dirs>
89 # Add a key to the list (if necessary) for the given item. If added,
90 # also set all the variables associated with that key.
92 # GET_BUNDLE_KEYS(<app> <libs> <dirs> <keys_var>)
93 # Loop over all the executable and library files within the bundle (and given
94 # as extra <libs>) and accumulate a list of keys representing them. Set
95 # values associated with each key such that we can loop over all of them and
96 # copy prerequisite libs into the bundle and then do appropriate
97 # install_name_tool fixups.
99 # COPY_RESOLVED_ITEM_INTO_BUNDLE(<resolved_item> <resolved_embedded_item>)
100 # Copy a resolved item into the bundle if necessary. Copy is not necessary if
101 # the resolved_item is "the same as" the resolved_embedded_item.
103 # COPY_RESOLVED_FRAMEWORK_INTO_BUNDLE(<resolved_item> <resolved_embedded_item>)
104 # Copy a resolved framework into the bundle if necessary. Copy is not necessary
105 # if the resolved_item is "the same as" the resolved_embedded_item.
107 # By default, BU_COPY_FULL_FRAMEWORK_CONTENTS is not set. If you want full
108 # frameworks embedded in your bundles, set BU_COPY_FULL_FRAMEWORK_CONTENTS to
109 # ON before calling fixup_bundle. By default,
110 # COPY_RESOLVED_FRAMEWORK_INTO_BUNDLE copies the framework dylib itself plus
111 # the framework Resources directory.
113 # FIXUP_BUNDLE_ITEM(<resolved_embedded_item> <exepath> <dirs>)
114 # Get the direct/non-system prerequisites of the resolved embedded item. For
115 # each prerequisite, change the way it is referenced to the value of the
116 # _EMBEDDED_ITEM keyed variable for that prerequisite. (Most likely changing to
117 # an "@executable_path" style reference.)
119 # This function requires that the resolved_embedded_item be "inside" the bundle
120 # already. In other words, if you pass plugins to fixup_bundle as the libs
121 # parameter, you should install them or copy them into the bundle before
122 # calling fixup_bundle. The "libs" parameter is a list of libraries that must
123 # be fixed up, but that cannot be determined by otool output analysis. (i.e.,
126 # Also, change the id of the item being fixed up to its own _EMBEDDED_ITEM
129 # Accumulate changes in a local variable and make *one* call to
130 # install_name_tool at the end of the function with all the changes at once.
132 # If the BU_CHMOD_BUNDLE_ITEMS variable is set then bundle items will be
133 # marked writable before install_name_tool tries to change them.
135 # VERIFY_BUNDLE_PREREQUISITES(<bundle> <result_var> <info_var>)
136 # Verifies that the sum of all prerequisites of all files inside the bundle
137 # are contained within the bundle or are "system" libraries, presumed to exist
140 # VERIFY_BUNDLE_SYMLINKS(<bundle> <result_var> <info_var>)
141 # Verifies that any symlinks found in the bundle point to other files that are
142 # already also in the bundle... Anything that points to an external file causes
143 # this function to fail the verification.
145 #=============================================================================
146 # Copyright 2008-2009 Kitware, Inc.
148 # Distributed under the OSI-approved BSD License (the "License");
149 # see accompanying file Copyright.txt for details.
151 # This software is distributed WITHOUT ANY WARRANTY; without even the
152 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
153 # See the License for more information.
154 #=============================================================================
155 # (To distribute this file outside of CMake, substitute the full
156 # License text for the above reference.)
158 # The functions defined in this file depend on the get_prerequisites function
159 # (and possibly others) found in:
161 get_filename_component(BundleUtilities_cmake_dir "${CMAKE_CURRENT_LIST_FILE}" PATH)
162 include("${BundleUtilities_cmake_dir}/GetPrerequisites.cmake")
165 function(get_bundle_main_executable bundle result_var)
166 set(result "error: '${bundle}/Contents/Info.plist' file does not exist")
168 if(EXISTS "${bundle}/Contents/Info.plist")
169 set(result "error: no CFBundleExecutable in '${bundle}/Contents/Info.plist' file")
170 set(line_is_main_executable 0)
171 set(bundle_executable "")
173 # Read Info.plist as a list of lines:
176 file(READ "${bundle}/Contents/Info.plist" info_plist)
177 string(REGEX REPLACE ";" "\\\\;" info_plist "${info_plist}")
178 string(REGEX REPLACE "\n" "${eol_char};" info_plist "${info_plist}")
180 # Scan the lines for "<key>CFBundleExecutable</key>" - the line after that
181 # is the name of the main executable.
183 foreach(line ${info_plist})
184 if(line_is_main_executable)
185 string(REGEX REPLACE "^.*<string>(.*)</string>.*$" "\\1" bundle_executable "${line}")
189 if(line MATCHES "^.*<key>CFBundleExecutable</key>.*$")
190 set(line_is_main_executable 1)
194 if(NOT "${bundle_executable}" STREQUAL "")
195 if(EXISTS "${bundle}/Contents/MacOS/${bundle_executable}")
196 set(result "${bundle}/Contents/MacOS/${bundle_executable}")
200 # If not in "Contents/MacOS" then scan the bundle for matching files. If
201 # there is only one executable file that matches, then use it, otherwise
204 #file(GLOB_RECURSE file_list "${bundle}/${bundle_executable}")
206 # But for now, pragmatically, it's an error. Expect the main executable
207 # for the bundle to be in Contents/MacOS, it's an error if it's not:
209 set(result "error: '${bundle}/Contents/MacOS/${bundle_executable}' does not exist")
214 # More inclusive technique... (This one would work on Windows and Linux
215 # too, if a developer followed the typical Mac bundle naming convention...)
217 # If there is no Info.plist file, try to find an executable with the same
218 # base name as the .app directory:
222 set(${result_var} "${result}" PARENT_SCOPE)
226 function(get_dotapp_dir exe dotapp_dir_var)
229 if(s MATCHES "^.*/.*\\.app/.*$")
230 # If there is a ".app" parent directory,
231 # ascend until we hit it:
232 # (typical of a Mac bundle executable)
236 get_filename_component(snamewe "${s}" NAME_WE)
237 get_filename_component(sname "${s}" NAME)
238 get_filename_component(sdir "${s}" PATH)
240 if(sname MATCHES "\\.app$")
242 set(dotapp_dir "${sdir}/${sname}")
246 # Otherwise use a directory containing the exe
247 # (typical of a non-bundle executable on Mac, Windows or Linux)
249 is_file_executable("${s}" is_executable)
251 get_filename_component(sdir "${s}" PATH)
252 set(dotapp_dir "${sdir}")
254 set(dotapp_dir "${s}")
259 set(${dotapp_dir_var} "${dotapp_dir}" PARENT_SCOPE)
263 function(get_bundle_and_executable app bundle_var executable_var valid_var)
267 # Is it a directory ending in .app?
268 if(IS_DIRECTORY "${app}")
269 if(app MATCHES "\\.app$")
270 get_bundle_main_executable("${app}" executable)
271 if(EXISTS "${app}" AND EXISTS "${executable}")
272 set(${bundle_var} "${app}" PARENT_SCOPE)
273 set(${executable_var} "${executable}" PARENT_SCOPE)
275 #message(STATUS "info: handled .app directory case...")
277 message(STATUS "warning: *NOT* handled - .app directory case...")
280 message(STATUS "warning: *NOT* handled - directory but not .app case...")
283 # Is it an executable file?
284 is_file_executable("${app}" is_executable)
286 get_dotapp_dir("${app}" dotapp_dir)
287 if(EXISTS "${dotapp_dir}")
288 set(${bundle_var} "${dotapp_dir}" PARENT_SCOPE)
289 set(${executable_var} "${app}" PARENT_SCOPE)
291 #message(STATUS "info: handled executable file in .app dir case...")
293 get_filename_component(app_dir "${app}" PATH)
294 set(${bundle_var} "${app_dir}" PARENT_SCOPE)
295 set(${executable_var} "${app}" PARENT_SCOPE)
297 #message(STATUS "info: handled executable file in any dir case...")
300 message(STATUS "warning: *NOT* handled - not .app dir, not executable file...")
304 message(STATUS "warning: *NOT* handled - directory/file does not exist...")
308 set(${bundle_var} "error: not a bundle" PARENT_SCOPE)
309 set(${executable_var} "error: not a bundle" PARENT_SCOPE)
312 set(${valid_var} ${valid} PARENT_SCOPE)
316 function(get_bundle_all_executables bundle exes_var)
319 file(GLOB_RECURSE file_list "${bundle}/*")
320 foreach(f ${file_list})
321 is_file_executable("${f}" is_executable)
323 set(exes ${exes} "${f}")
327 set(${exes_var} "${exes}" PARENT_SCOPE)
331 function(get_item_key item key_var)
332 get_filename_component(item_name "${item}" NAME)
334 string(TOLOWER "${item_name}" item_name)
336 string(REGEX REPLACE "\\." "_" ${key_var} "${item_name}")
337 set(${key_var} ${${key_var}} PARENT_SCOPE)
341 function(clear_bundle_keys keys_var)
342 foreach(key ${${keys_var}})
343 set(${key}_ITEM PARENT_SCOPE)
344 set(${key}_RESOLVED_ITEM PARENT_SCOPE)
345 set(${key}_DEFAULT_EMBEDDED_PATH PARENT_SCOPE)
346 set(${key}_EMBEDDED_ITEM PARENT_SCOPE)
347 set(${key}_RESOLVED_EMBEDDED_ITEM PARENT_SCOPE)
348 set(${key}_COPYFLAG PARENT_SCOPE)
350 set(${keys_var} PARENT_SCOPE)
354 function(set_bundle_key_values keys_var context item exepath dirs copyflag)
355 get_filename_component(item_name "${item}" NAME)
357 get_item_key("${item}" key)
359 list(LENGTH ${keys_var} length_before)
360 gp_append_unique(${keys_var} "${key}")
361 list(LENGTH ${keys_var} length_after)
363 if(NOT length_before EQUAL length_after)
364 gp_resolve_item("${context}" "${item}" "${exepath}" "${dirs}" resolved_item)
366 gp_item_default_embedded_path("${item}" default_embedded_path)
368 if(item MATCHES "[^/]+\\.framework/")
369 # For frameworks, construct the name under the embedded path from the
370 # opening "${item_name}.framework/" to the closing "/${item_name}":
372 string(REGEX REPLACE "^.*(${item_name}.framework/.*/${item_name}).*$" "${default_embedded_path}/\\1" embedded_item "${item}")
374 # For other items, just use the same name as the original, but in the
377 set(embedded_item "${default_embedded_path}/${item_name}")
380 # Replace @executable_path and resolve ".." references:
382 string(REPLACE "@executable_path" "${exepath}" resolved_embedded_item "${embedded_item}")
383 get_filename_component(resolved_embedded_item "${resolved_embedded_item}" ABSOLUTE)
385 # *But* -- if we are not copying, then force resolved_embedded_item to be
386 # the same as resolved_item. In the case of multiple executables in the
387 # original bundle, using the default_embedded_path results in looking for
388 # the resolved executable next to the main bundle executable. This is here
389 # so that exes in the other sibling directories (like "bin") get fixed up
393 set(resolved_embedded_item "${resolved_item}")
396 set(${keys_var} ${${keys_var}} PARENT_SCOPE)
397 set(${key}_ITEM "${item}" PARENT_SCOPE)
398 set(${key}_RESOLVED_ITEM "${resolved_item}" PARENT_SCOPE)
399 set(${key}_DEFAULT_EMBEDDED_PATH "${default_embedded_path}" PARENT_SCOPE)
400 set(${key}_EMBEDDED_ITEM "${embedded_item}" PARENT_SCOPE)
401 set(${key}_RESOLVED_EMBEDDED_ITEM "${resolved_embedded_item}" PARENT_SCOPE)
402 set(${key}_COPYFLAG "${copyflag}" PARENT_SCOPE)
404 #message("warning: item key '${key}' already in the list, subsequent references assumed identical to first")
409 function(get_bundle_keys app libs dirs keys_var)
410 set(${keys_var} PARENT_SCOPE)
412 get_bundle_and_executable("${app}" bundle executable valid)
414 # Always use the exepath of the main bundle executable for @executable_path
417 get_filename_component(exepath "${executable}" PATH)
419 # But do fixups on all executables in the bundle:
421 get_bundle_all_executables("${bundle}" exes)
423 # For each extra lib, accumulate a key as well and then also accumulate
424 # any of its prerequisites. (Extra libs are typically dynamically loaded
425 # plugins: libraries that are prerequisites for full runtime functionality
426 # but that do not show up in otool -L output...)
429 set_bundle_key_values(${keys_var} "${lib}" "${lib}" "${exepath}" "${dirs}" 0)
432 get_prerequisites("${lib}" prereqs 1 1 "${exepath}" "${dirs}")
433 foreach(pr ${prereqs})
434 set_bundle_key_values(${keys_var} "${lib}" "${pr}" "${exepath}" "${dirs}" 1)
438 # For each executable found in the bundle, accumulate keys as we go.
439 # The list of keys should be complete when all prerequisites of all
440 # binaries in the bundle have been analyzed.
443 # Add the exe itself to the keys:
445 set_bundle_key_values(${keys_var} "${exe}" "${exe}" "${exepath}" "${dirs}" 0)
447 # Add each prerequisite to the keys:
450 get_prerequisites("${exe}" prereqs 1 1 "${exepath}" "${dirs}")
451 foreach(pr ${prereqs})
452 set_bundle_key_values(${keys_var} "${exe}" "${pr}" "${exepath}" "${dirs}" 1)
456 # Propagate values to caller's scope:
458 set(${keys_var} ${${keys_var}} PARENT_SCOPE)
459 foreach(key ${${keys_var}})
460 set(${key}_ITEM "${${key}_ITEM}" PARENT_SCOPE)
461 set(${key}_RESOLVED_ITEM "${${key}_RESOLVED_ITEM}" PARENT_SCOPE)
462 set(${key}_DEFAULT_EMBEDDED_PATH "${${key}_DEFAULT_EMBEDDED_PATH}" PARENT_SCOPE)
463 set(${key}_EMBEDDED_ITEM "${${key}_EMBEDDED_ITEM}" PARENT_SCOPE)
464 set(${key}_RESOLVED_EMBEDDED_ITEM "${${key}_RESOLVED_EMBEDDED_ITEM}" PARENT_SCOPE)
465 set(${key}_COPYFLAG "${${key}_COPYFLAG}" PARENT_SCOPE)
471 function(copy_resolved_item_into_bundle resolved_item resolved_embedded_item)
473 # ignore case on Windows
474 string(TOLOWER "${resolved_item}" resolved_item_compare)
475 string(TOLOWER "${resolved_embedded_item}" resolved_embedded_item_compare)
477 set(resolved_item_compare "${resolved_item}")
478 set(resolved_embedded_item_compare "${resolved_embedded_item}")
481 if("${resolved_item_compare}" STREQUAL "${resolved_embedded_item_compare}")
482 message(STATUS "warning: resolved_item == resolved_embedded_item - not copying...")
484 #message(STATUS "copying COMMAND ${CMAKE_COMMAND} -E copy ${resolved_item} ${resolved_embedded_item}")
485 execute_process(COMMAND ${CMAKE_COMMAND} -E copy "${resolved_item}" "${resolved_embedded_item}")
486 if(UNIX AND NOT APPLE)
487 file(RPATH_REMOVE FILE "${resolved_embedded_item}")
494 function(copy_resolved_framework_into_bundle resolved_item resolved_embedded_item)
496 # ignore case on Windows
497 string(TOLOWER "${resolved_item}" resolved_item_compare)
498 string(TOLOWER "${resolved_embedded_item}" resolved_embedded_item_compare)
500 set(resolved_item_compare "${resolved_item}")
501 set(resolved_embedded_item_compare "${resolved_embedded_item}")
504 if("${resolved_item_compare}" STREQUAL "${resolved_embedded_item_compare}")
505 message(STATUS "warning: resolved_item == resolved_embedded_item - not copying...")
507 if(BU_COPY_FULL_FRAMEWORK_CONTENTS)
508 # Full Framework (everything):
509 get_filename_component(resolved_dir "${resolved_item}" PATH)
510 get_filename_component(resolved_dir "${resolved_dir}/../.." ABSOLUTE)
511 get_filename_component(resolved_embedded_dir "${resolved_embedded_item}" PATH)
512 get_filename_component(resolved_embedded_dir "${resolved_embedded_dir}/../.." ABSOLUTE)
513 #message(STATUS "copying COMMAND ${CMAKE_COMMAND} -E copy_directory '${resolved_dir}' '${resolved_embedded_dir}'")
514 execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory "${resolved_dir}" "${resolved_embedded_dir}")
516 # Framework lib itself:
517 #message(STATUS "copying COMMAND ${CMAKE_COMMAND} -E copy ${resolved_item} ${resolved_embedded_item}")
518 execute_process(COMMAND ${CMAKE_COMMAND} -E copy "${resolved_item}" "${resolved_embedded_item}")
520 # Plus Resources, if they exist:
521 string(REGEX REPLACE "^(.*)/[^/]+/[^/]+/[^/]+$" "\\1/Resources" resolved_resources "${resolved_item}")
522 string(REGEX REPLACE "^(.*)/[^/]+/[^/]+/[^/]+$" "\\1/Resources" resolved_embedded_resources "${resolved_embedded_item}")
523 if(EXISTS "${resolved_resources}")
524 #message(STATUS "copying COMMAND ${CMAKE_COMMAND} -E copy_directory '${resolved_resources}' '${resolved_embedded_resources}'")
525 execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory "${resolved_resources}" "${resolved_embedded_resources}")
528 if(UNIX AND NOT APPLE)
529 file(RPATH_REMOVE FILE "${resolved_embedded_item}")
536 function(fixup_bundle_item resolved_embedded_item exepath dirs)
537 # This item's key is "ikey":
539 get_item_key("${resolved_embedded_item}" ikey)
541 # Ensure the item is "inside the .app bundle" -- it should not be fixed up if
542 # it is not in the .app bundle... Otherwise, we'll modify files in the build
543 # tree, or in other varied locations around the file system, with our call to
544 # install_name_tool. Make sure that doesn't happen here:
546 get_dotapp_dir("${exepath}" exe_dotapp_dir)
547 string(LENGTH "${exe_dotapp_dir}/" exe_dotapp_dir_length)
548 string(LENGTH "${resolved_embedded_item}" resolved_embedded_item_length)
549 set(path_too_short 0)
551 if(${resolved_embedded_item_length} LESS ${exe_dotapp_dir_length})
552 set(path_too_short 1)
554 if(NOT path_too_short)
555 string(SUBSTRING "${resolved_embedded_item}" 0 ${exe_dotapp_dir_length} item_substring)
556 if("${exe_dotapp_dir}/" STREQUAL "${item_substring}")
561 message(" exe_dotapp_dir/='${exe_dotapp_dir}/'")
562 message(" item_substring='${item_substring}'")
563 message(" resolved_embedded_item='${resolved_embedded_item}'")
565 message("Install or copy the item into the bundle before calling fixup_bundle.")
566 message("Or maybe there's a typo or incorrect path in one of the args to fixup_bundle?")
568 message(FATAL_ERROR "cannot fixup an item that is not in the bundle...")
572 get_prerequisites("${resolved_embedded_item}" prereqs 1 0 "${exepath}" "${dirs}")
576 foreach(pr ${prereqs})
577 # Each referenced item's key is "rkey" in the loop:
579 get_item_key("${pr}" rkey)
581 if(NOT "${${rkey}_EMBEDDED_ITEM}" STREQUAL "")
582 set(changes ${changes} "-change" "${pr}" "${${rkey}_EMBEDDED_ITEM}")
584 message("warning: unexpected reference to '${pr}'")
588 if(BU_CHMOD_BUNDLE_ITEMS)
589 execute_process(COMMAND chmod u+w "${resolved_embedded_item}")
592 # Change this item's id and all of its references in one call
593 # to install_name_tool:
595 execute_process(COMMAND install_name_tool
596 ${changes} -id "${${ikey}_EMBEDDED_ITEM}" "${resolved_embedded_item}"
601 function(fixup_bundle app libs dirs)
602 message(STATUS "fixup_bundle")
603 message(STATUS " app='${app}'")
604 message(STATUS " libs='${libs}'")
605 message(STATUS " dirs='${dirs}'")
607 get_bundle_and_executable("${app}" bundle executable valid)
609 get_filename_component(exepath "${executable}" PATH)
611 message(STATUS "fixup_bundle: preparing...")
612 get_bundle_keys("${app}" "${libs}" "${dirs}" keys)
614 message(STATUS "fixup_bundle: copying...")
621 if(${${key}_COPYFLAG})
622 message(STATUS "${i}/${n}: copying '${${key}_RESOLVED_ITEM}'")
624 message(STATUS "${i}/${n}: *NOT* copying '${${key}_RESOLVED_ITEM}'")
629 message(STATUS "key='${key}'")
630 message(STATUS "item='${${key}_ITEM}'")
631 message(STATUS "resolved_item='${${key}_RESOLVED_ITEM}'")
632 message(STATUS "default_embedded_path='${${key}_DEFAULT_EMBEDDED_PATH}'")
633 message(STATUS "embedded_item='${${key}_EMBEDDED_ITEM}'")
634 message(STATUS "resolved_embedded_item='${${key}_RESOLVED_EMBEDDED_ITEM}'")
635 message(STATUS "copyflag='${${key}_COPYFLAG}'")
639 if(${${key}_COPYFLAG})
640 set(item "${${key}_ITEM}")
641 if(item MATCHES "[^/]+\\.framework/")
642 copy_resolved_framework_into_bundle("${${key}_RESOLVED_ITEM}"
643 "${${key}_RESOLVED_EMBEDDED_ITEM}")
645 copy_resolved_item_into_bundle("${${key}_RESOLVED_ITEM}"
646 "${${key}_RESOLVED_EMBEDDED_ITEM}")
651 message(STATUS "fixup_bundle: fixing...")
655 message(STATUS "${i}/${n}: fixing up '${${key}_RESOLVED_EMBEDDED_ITEM}'")
656 fixup_bundle_item("${${key}_RESOLVED_EMBEDDED_ITEM}" "${exepath}" "${dirs}")
658 message(STATUS "${i}/${n}: fix-up not required on this platform '${${key}_RESOLVED_EMBEDDED_ITEM}'")
662 message(STATUS "fixup_bundle: cleaning up...")
663 clear_bundle_keys(keys)
665 message(STATUS "fixup_bundle: verifying...")
668 message(SEND_ERROR "error: fixup_bundle: not a valid bundle")
671 message(STATUS "fixup_bundle: done")
675 function(copy_and_fixup_bundle src dst libs dirs)
676 execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory "${src}" "${dst}")
677 fixup_bundle("${dst}" "${libs}" "${dirs}")
681 function(verify_bundle_prerequisites bundle result_var info_var)
686 get_bundle_main_executable("${bundle}" main_bundle_exe)
688 file(GLOB_RECURSE file_list "${bundle}/*")
689 foreach(f ${file_list})
690 is_file_executable("${f}" is_executable)
692 get_filename_component(exepath "${f}" PATH)
693 math(EXPR count "${count} + 1")
695 message(STATUS "executable file ${count}: ${f}")
698 get_prerequisites("${f}" prereqs 1 1 "${exepath}" "")
701 # "embedded" and "system" prerequisites are fine... anything else means
702 # the bundle's prerequisites are not verified (i.e., the bundle is not
703 # really "standalone")
705 # On Windows (and others? Linux/Unix/...?)
706 # "local" and "system" prereqs are fine...
708 set(external_prereqs "")
710 foreach(p ${prereqs})
712 gp_file_type("${f}" "${p}" p_type)
715 if(NOT "${p_type}" STREQUAL "embedded" AND NOT "${p_type}" STREQUAL "system")
716 set(external_prereqs ${external_prereqs} "${p}")
719 if(NOT "${p_type}" STREQUAL "local" AND NOT "${p_type}" STREQUAL "system")
720 set(external_prereqs ${external_prereqs} "${p}")
726 # Found non-system/somehow-unacceptable prerequisites:
728 set(info ${info} "external prerequisites found:\nf='${f}'\nexternal_prereqs='${external_prereqs}'\n")
734 set(info "Verified ${count} executable files in '${bundle}'")
737 set(${result_var} "${result}" PARENT_SCOPE)
738 set(${info_var} "${info}" PARENT_SCOPE)
742 function(verify_bundle_symlinks bundle result_var info_var)
747 # TODO: implement this function for real...
748 # Right now, it is just a stub that verifies unconditionally...
750 set(${result_var} "${result}" PARENT_SCOPE)
751 set(${info_var} "${info}" PARENT_SCOPE)
755 function(verify_app app)
759 get_bundle_and_executable("${app}" bundle executable valid)
761 message(STATUS "===========================================================================")
762 message(STATUS "Analyzing app='${app}'")
763 message(STATUS "bundle='${bundle}'")
764 message(STATUS "executable='${executable}'")
765 message(STATUS "valid='${valid}'")
767 # Verify that the bundle does not have any "external" prerequisites:
769 verify_bundle_prerequisites("${bundle}" verified info)
770 message(STATUS "verified='${verified}'")
771 message(STATUS "info='${info}'")
775 # Verify that the bundle does not have any symlinks to external files:
777 verify_bundle_symlinks("${bundle}" verified info)
778 message(STATUS "verified='${verified}'")
779 message(STATUS "info='${info}'")
784 message(FATAL_ERROR "error: verify_app failed")