问题
I'm using CMake generate build files for a cross platform game and want to specify custom NSMainNibFile
and NSPrincipalClass
values in certain bundle's Info.plist file
Here's the relevant portion of my Info.plist.in template:
<key>NSMainNibFile</key>
<string>${MAIN_NIBFILE}</string>
<key>NSPrincipalClass</key>
<string>${PRINCIPAL_CLASS}</string>
What I'm doing in my CMakeLists.txt is:
set_target_properties(GLWindow PROPERTIES
MACOSX_BUNDLE_BUNDLE_NAME "OpenGL Test"
MAIN_NIBFILE "MainMenu"
PRINCIPAL_CLASS "NSApplication")
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/CMake/Info.plist.in)`
If I get the MAIN_NIBFILE
property for the target, it returns MainMenu as expected, but the actual generated Info.plist is empty.
BUT...
If I globally set these variables, it works fine.
# I would prefer to set these at target scope,
# but it doesn't bloody work!
set(MAIN_NIBFILE "MainMenu")
set(PRINCIPAL_CLASS "NSApplication")
Am I missing something here or is this a limitation of CMake or how it handles macOS bundles?
回答1:
If you look at the documentation for MACOSX_BUNDLE_INFO_PLIST, you will see that it only supports setting a limited number of properties that affect the Info.plist template (MACOSX_BUNDLE_BUNDLE_NAME
, etc). None of these are for the NSMainNibFile
or NSPrincipalClass
keys. However, in that documentation it gives a hint at the functionality of the template:
its Info.plist file is created by configuring a template
What is actually happening, is that the module is calling configure_file on the .plist.in file. This is why setting variables at the global scope works, but setting them at the property level does not.
So, the answer is that you must set those as variables, not as target properties. If you are worried about scope of these, you can unset the variables immediately after use, and, it should be noted that variables only are not visible to their parent scopes, unless they are specifically set as such.
来源:https://stackoverflow.com/questions/42313808/customising-macos-bundles-info-plist-file-with-cmake