在firebreath插件中使用xib

时间:2012-03-13 08:36:54

标签: xcode xib firebreath

我在mac os上创建了一个firebreath插件,它必须弹出一个窗口来获取用户输入(只是一个文本字段和两个按钮)。

这是我当前的projectDef.cmake进行测试。

file (GLOB XIB RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
Mac/bundle_template/input.xib
)

# 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 and is needed to compile the .xib files.      It should have been installed with the Apple developer tools. The default system paths were searched in addition to ${OSX_DEVELOPER_ROOT}/usr/bin")
endif()

# make the compiled nib file to desktop for testing
set (NIBFILE /Users/develop/Desktop/input.nib)

add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD 
    COMMAND ${IBTOOL} --errors --warnings --notices --output-format human-readable-text  --compile ${NIBFILE} ${XIB}
    COMMENT "Compiling input.xib")

set (SOURCES
    ${SOURCES}
    ${PLATFORM}
    ${XIB}
)

add_custom_command块对cmake没有任何影响,当我的插件目标构建成功时没有编译nib文件,但ibtool在终端的命令行工作。

2 个答案:

答案 0 :(得分:1)

看起来您需要做的是将.xib文件编译为.nib文件。这里有一个如何做到这一点的例子:

http://www.cmake.org/Wiki/CMake:OSX_InterfaceBuilderFiles

基本上你会做类似的事情:

# 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 and is needed to compile the .xib files. It should have been installed with the Apple developer tools. The default system paths were searched in addition to ${OSX_DEVELOPER_ROOT}/usr/bin")
endif()

set (NIBFILE ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/input.nib)

add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD 
    COMMAND ${IBTOOL} --errors --warnings --notices --output-format human-readable-text 
            --compile ${NIBFILE} ${XIB}
    COMMENT "Compiling input.xib")

set (SOURCES
    ${SOURCES}
    ${PLATFORM}
    ${XIB}
    ${NIBFILE}
)

set_source_files_properties(${NIBFILE}
    PROPERTIES
        MACOSX_PACKAGE_LOCATION "Resources/English.lproj"
        GENERATED 1
)

您需要设置NIB文件的位置,但请记住,您还需要将其设置为GENERATED,因为首次运行准备脚本时它不会存在。

答案 1 :(得分:0)

问题解决了。见this link。那种方法有效。我的最终解决方案如下:

//projectDef.cmake

set(XIB "Mac/bundle_template/input.xib")

add_mac_plugin(${PROJECT_NAME} ${PLIST} ${STRINGS} ${LOCALIZED} SOURCES ${XIB})

//Mac.cmake in "add_mac_plugin" macro

if (${ARGC} GREATER 5)
add_library( ${PROJECT_NAME} MODULE
    ${SOURCES} 
    ${ARGN}
    )
else()
add_library( ${PROJECT_NAME} MODULE
    ${SOURCES} 
    )
endif()

if (${ARGC} GREATER 5)
set_target_properties(${PROJECT_NAME} PROPERTIES
    BUNDLE 1
    BUNDLE_EXTENSION plugin
    XCODE_ATTRIBUTE_WRAPPER_EXTENSION plugin  #sets the extension to .plugin
    XCODE_ATTRIBUTE_MACH_O_TYPE mh_bundle
    XCODE_ATTRIBUTE_INFOPLIST_FILE ${CMAKE_CURRENT_BINARY_DIR}/bundle/Info.plist
    MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_BINARY_DIR}/bundle/Info.plist
    RESOURCE ${ARGN}
    LINK_FLAGS "-Wl,- exported_symbols_list,${FB_ESC_ROOT_DIR}/gen_templates/ExportList_plugin.txt")
else()
set_target_properties(${PROJECT_NAME} PROPERTIES
    BUNDLE 1
    BUNDLE_EXTENSION plugin
    XCODE_ATTRIBUTE_WRAPPER_EXTENSION plugin  #sets the extension to .plugin
    XCODE_ATTRIBUTE_MACH_O_TYPE mh_bundle
    XCODE_ATTRIBUTE_INFOPLIST_FILE ${CMAKE_CURRENT_BINARY_DIR}/bundle/Info.plist
    MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_BINARY_DIR}/bundle/Info.plist
    LINK_FLAGS "-Wl,-exported_symbols_list,${FB_ESC_ROOT_DIR}/gen_templates/ExportList_plugin.txt")
endif()

我的修改似乎不那么美好,我不太了解cmake。您是否可以更新宏以支持xib等外部资源?顺便说一句,非常感谢,伙计。