fixup_bundle runs before the target is installed
fixup_bundle()
inside install(CODE)
runs before the target is installed and fixup_bundle fails with a file not found error. If running make install
twice, the executable is found and the bundle executes correctly.
This behavior occurs when the target is defined in a subdirectory, and the install(CODE)
is in the parent directory, even if install(CODE)
is after the add_subdirectory()
. I still don't understand why this execution order is obtained in this condition.
Here is a repo with a minimal example to reproduce the issue. I was able to reproduce the problem at least on Windows (VS2017, MinGW) and Linux.
https://gitlab.com/fgiraldeau/cmake-bundle-before-install-issue
We see that the order is wrong in cmake_install.txt
:
if("x${CMAKE_INSTALL_COMPONENT}x" STREQUAL "xRuntimex" OR NOT CMAKE_INSTALL_COMPONENT)
include(BundleUtilities)
fixup_bundle("${CMAKE_INSTALL_PREFIX}/bin/Foo.exe" "" "")
endif()
if(NOT CMAKE_INSTALL_LOCAL_ONLY)
# Include the install script for each subdirectory.
include("E:/cmake-install-issue/build/foo/cmake_install.cmake")
endif()
The documentation does not indicate where to put the install(CODE)
statement. We might want to add:
The install(CODE) statement must be located in the file that defines the target, otherwise the installation order is undefined.