POST_BUILD of MODULE library when the BUNDLE property is set to yes runs before resources and executables are copied into the bundle
I was using cmake to create a macOS preference pane. I have something like
add_library(pref-pane MODULE ${NIB_LOCATION} ${INCLUDE_FILES} ${PREFPANE_SOURCES} ${PREFPANE_RESOURCES} ${XIB_FILE})
target_link_libraries(pref-pane .....)
set_target_properties(pref-pane PROPERTIES OUTPUT_NAME ${REAL_NAME} BUNDLE YES BUNDLE_EXTENSION prefPane MACOSX_BUNDLE_INFO_PLIST ${MY_PLIST_TEMPLATE})
add_custom_command(TARGET pref-pane POST_BUILD COMMAND codesign -s ${IDENTITY} $<TARGET_FILE_DIR:pref-pane>/../..)
What I expected was for codesign to be run after everything was put into the bundle but what happens is that it is codesigned after the pref-pane module is created but before anything is copied around to the final destination.
As an aside, it would be nice for bundles to be able to get the top level of the bundle instead of having to rely on the module dir and up two levels.