针对 iOS 目标的 CMake xib 到 nib 编译

发布于 2024-12-05 02:54:38 字数 1678 浏览 1 评论 0原文

我的目标是 iOS(设备和模拟器)并设置 CMake 以添加捆绑包中所需的不同资源。 “xib”文件给我带来了一些问题。如果我不采取进一步操作,iPhone/iPad 模拟器运行将失败并显示错误:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', 
  reason: 'Could not load NIB in bundle:
   'NSBundle </Users/danieldekkers/Library/Application Support/iPhone Simulator/4.3.2/Applications/1C29638B-7593-4311-8F94-C8051AF90AD7/Discs.app> 
      (loaded)' with name 'MainWindow''

捆绑包中缺少 NIB 文件。 一个示例 (http://www.vtk.org/Wiki/CMake:OSX_InterfaceBuilderFiles) 显示,对于 OSX,您必须将 xib 文件编译为 nib 文件,并将这些文件作为构建后步骤添加到捆绑包中。 所以我的猜测是 iOS 也有类似的情况。 但我的问题是,...我在哪里添加编译好的 nib 文件?

我现在在 CMakeLists.txt 中执行此操作:

# We need to compile the interface builder *.xib files to *.nib files to add to the bundle
# Make sure we can find the 'ibtool' program. If we can NOT find it we skip generation of this project
FIND_PROGRAM( IBTOOL ibtool HINTS "/usr/bin" "${OSX_DEVELOPER_ROOT}/usr/bin" )
if ( ${IBTOOL} STREQUAL "IBTOOL-NOTFOUND" )
    MESSAGE( SEND_ERROR "ibtool can not be found" )
ENDIF()

# Compile the .xib files using the 'ibtool' program with the destination being the app package
FOREACH( xib ${RSRC_IOS_XIB_FILES} )
    ADD_CUSTOM_COMMAND( TARGET ${RT_APP_NAME} POST_BUILD
    COMMAND ${IBTOOL} --errors --warnings --notices --output-format human-readable-text 
        --compile 
        ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${RT_APP_NAME}.app/Contents/Resources/${xib}.nib
        ${RT_APP_ROOT}/rsrc/apple/ios/${xib}.xib
        COMMENT "Compiling ${RT_APP_ROOT}/rsrc/apple/ios/${xib}.xib")
ENDFOREACH()

但是我并不真正信任编译步骤的“目的地”,尤其是对于模拟器而言。

有谁能做到这一点或者看看我做错了什么?

I'm targeting iOS (device and simulator) and setting up CMake to add the different resources needed in the bundle. The "xib" file is giving me some problems. If I take no further action, the iPhone/iPad simulator run fails with the error:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', 
  reason: 'Could not load NIB in bundle:
   'NSBundle </Users/danieldekkers/Library/Application Support/iPhone Simulator/4.3.2/Applications/1C29638B-7593-4311-8F94-C8051AF90AD7/Discs.app> 
      (loaded)' with name 'MainWindow''

A missing NIB file in the bundle.
An example (http://www.vtk.org/Wiki/CMake:OSX_InterfaceBuilderFiles) shows that for OSX, you have to compile the xib files into nib files and add these to the bundle as a post-build step.
So my guess would be that something similar holds for iOS as well.
But my question is,... where do i add the compiled nib files?

I now do this in the CMakeLists.txt:

# We need to compile the interface builder *.xib files to *.nib files to add to the bundle
# Make sure we can find the 'ibtool' program. If we can NOT find it we skip generation of this project
FIND_PROGRAM( IBTOOL ibtool HINTS "/usr/bin" "${OSX_DEVELOPER_ROOT}/usr/bin" )
if ( ${IBTOOL} STREQUAL "IBTOOL-NOTFOUND" )
    MESSAGE( SEND_ERROR "ibtool can not be found" )
ENDIF()

# Compile the .xib files using the 'ibtool' program with the destination being the app package
FOREACH( xib ${RSRC_IOS_XIB_FILES} )
    ADD_CUSTOM_COMMAND( TARGET ${RT_APP_NAME} POST_BUILD
    COMMAND ${IBTOOL} --errors --warnings --notices --output-format human-readable-text 
        --compile 
        ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${RT_APP_NAME}.app/Contents/Resources/${xib}.nib
        ${RT_APP_ROOT}/rsrc/apple/ios/${xib}.xib
        COMMENT "Compiling ${RT_APP_ROOT}/rsrc/apple/ios/${xib}.xib")
ENDFOREACH()

But iI don't really trust the "destination" of the compilation step, especially for the simulator.

Has anyone got this working or see what it is that I'm doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

荒芜了季节 2024-12-12 02:54:38

它应该与 CMake Xcode 生成器“正常工作”,将 *.xib 文件作为源添加到 add_executable 中,然后将 RESOURCE 目标属性设置为 *.xib 文件列表。 xib 文件。

CMake/Tests/ 中所示iOSNavApp/CMakeLists.txt 文件。

此技术应适用于 CMake 2.8.5 及更高版本以及 Xcode 4 及更高版本。

编辑

链接中的代码复制/粘贴到此处,以防链接将来损坏:

cmake_minimum_required(VERSION 2.8.5)
project(NavApp3)

set(CMAKE_OSX_SYSROOT iphoneos4.3)
set(CMAKE_OSX_ARCHITECTURES "armv6;armv7;i386")
set(CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos;-iphonesimulator")

include_directories(
  ${CMAKE_CURRENT_SOURCE_DIR}
  ${CMAKE_CURRENT_SOURCE_DIR}/Classes
  )

add_library(Functions STATIC TotalFunction.c TotalFunction.h)

set(M_SRCS main.m Classes/NavApp3AppDelegate.m Classes/RootViewController.m)
set(HEADERS Classes/NavApp3AppDelegate.h Classes/RootViewController.h)
set(RESOURCES MainWindow.xib RootViewController.xib)

add_executable(NavApp3 MACOSX_BUNDLE ${M_SRCS} ${HEADERS} ${RESOURCES})

target_link_libraries(NavApp3
  Functions
  "-framework CoreGraphics"
  "-framework Foundation"
  "-framework UIKit"
  )

set_target_properties(NavApp3 PROPERTIES
  MACOSX_BUNDLE_GUI_IDENTIFIER "com.yourcompany.NavApp3"
  MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist.in
  RESOURCE "${RESOURCES}"
  XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer"
  XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT "dwarf-with-dsym"
  XCODE_ATTRIBUTE_GCC_PRECOMPILE_PREFIX_HEADER YES
  XCODE_ATTRIBUTE_GCC_PREFIX_HEADER ${CMAKE_CURRENT_LIST_DIR}/NavApp3_Prefix.pch
  XCODE_ATTRIBUTE_INFOPLIST_PREPROCESS YES
  XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET 3.0
  )

It should "just work" with the CMake Xcode generator to add the *.xib files as sources to add_executable, and then set the RESOURCE target property to the list of *.xib files.

As shown in the CMake/Tests/iOSNavApp/CMakeLists.txt file.

This technique should work with CMake 2.8.5 and up, and Xcode 4 and up.

EDIT

Code from link copied/pasted here in case the link gets broken in the future:

cmake_minimum_required(VERSION 2.8.5)
project(NavApp3)

set(CMAKE_OSX_SYSROOT iphoneos4.3)
set(CMAKE_OSX_ARCHITECTURES "armv6;armv7;i386")
set(CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos;-iphonesimulator")

include_directories(
  ${CMAKE_CURRENT_SOURCE_DIR}
  ${CMAKE_CURRENT_SOURCE_DIR}/Classes
  )

add_library(Functions STATIC TotalFunction.c TotalFunction.h)

set(M_SRCS main.m Classes/NavApp3AppDelegate.m Classes/RootViewController.m)
set(HEADERS Classes/NavApp3AppDelegate.h Classes/RootViewController.h)
set(RESOURCES MainWindow.xib RootViewController.xib)

add_executable(NavApp3 MACOSX_BUNDLE ${M_SRCS} ${HEADERS} ${RESOURCES})

target_link_libraries(NavApp3
  Functions
  "-framework CoreGraphics"
  "-framework Foundation"
  "-framework UIKit"
  )

set_target_properties(NavApp3 PROPERTIES
  MACOSX_BUNDLE_GUI_IDENTIFIER "com.yourcompany.NavApp3"
  MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist.in
  RESOURCE "${RESOURCES}"
  XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer"
  XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT "dwarf-with-dsym"
  XCODE_ATTRIBUTE_GCC_PRECOMPILE_PREFIX_HEADER YES
  XCODE_ATTRIBUTE_GCC_PREFIX_HEADER ${CMAKE_CURRENT_LIST_DIR}/NavApp3_Prefix.pch
  XCODE_ATTRIBUTE_INFOPLIST_PREPROCESS YES
  XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET 3.0
  )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文