2

I've created a firebreath plugin on mac os which HAVE TO pop up a window to get user input(just a text field and two buttons).

This is my current projectDef.cmake for testing.

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}
)

the add_custom_command block takes no effect from cmake, no nib file compiled when my plugin target build successfully, but ibtool works from command line in terminal.

Leo.Zhou
  • 175
  • 1
  • 12
  • sorry, i'm new to cocoa. maybe i shouldn't use panel. i need the input dialog to be window-modal according to browser's current tab window. how can i implement that? – Leo.Zhou Mar 13 '12 at 11:33
  • There is no way to directly tie it to the tab; all you can do is make it modal and hope it is good enough. You don't have a reference to the browser's NSWindow – taxilian Mar 13 '12 at 16:13
  • thanks taxulian, i will use application-modal dialog. for now, the _window is always null so i cannot show it up. i don't know why, something i'm missing? – Leo.Zhou Mar 14 '12 at 03:22
  • i followed the instructions from firebreath wiki. first, get the plugin's bundle name from bundle identifier, then get the absolute path for my xib resource. Everything seems correct, but just can't load the window! :( – Leo.Zhou Mar 14 '12 at 08:34
  • I'm still confused; what is _window? I don't see a _window anywhere in your code. – taxilian Mar 14 '12 at 19:27
  • _window and _windowNibName are internal to NSWindowController. After calling [myController window], the _window should have some value so the window have been loaded. i'm still digging. – Leo.Zhou Mar 15 '12 at 01:00
  • i figured it out. the xib file is copied into the final plugin bundle, untouched without compilation. what can i do with my MAC/projectDef.cmake to tell XCode project to compile xib to nib? – Leo.Zhou Mar 15 '12 at 01:46

2 Answers2

1

Looks like what you need to do is compile the .xib file to a .nib file. There is an example of how to do that here:

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

basically you'll do something similar to this:

# 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
)

You need to set the location for the NIB file, but remember that you also need to set it to GENERATED because it won't be there when the prep script is run for the first time.

taxilian
  • 14,229
  • 4
  • 34
  • 73
  • many thanks, taxilian. the xcode build process issues some errors. this line seems incorrect.(set (NIBFILE ${CMAKE_CURRENT_BINARY_DIR}/\${CONFIGURATION}/input.nib)). i cannot find ${CONFIGURATION} in cmake tutorials. – Leo.Zhou Mar 15 '12 at 04:51
  • That's because ${CONFIGURATION} is not a cmake variable, it's an xcode variable. You could probably use the cmake variable ${CMAKE_CFG_INTDIR} instead. (http://www.cmake.org/cmake/help/cmake-2-8-docs.html#variable:CMAKE_CFG_INTDIR) – taxilian Mar 15 '12 at 04:52
  • even though i set GENERATED=1, problem still exists. the nib file is generated too late(after target is build). pbxcp: input.nib: No such file or directory. Is there any command can replace "set_source_files_properties"? – Leo.Zhou Mar 15 '12 at 05:21
  • modified the projectDef.cmake, it still doesn't work. please see my edited question. – Leo.Zhou Mar 15 '12 at 08:56
  • try making it PRE_BUILD; are you sure it isn't running? search your build directory for it and see if you can find it. It may be running but for some reason not getting copied into the the bundle. – taxilian Mar 15 '12 at 16:07
0

Problem solved. See this link. That method works. My final solution is as follows:

//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()

My modification seems not so beautiful, I don't understand cmake very well. hi taxilian, can you update the macro to support external resources like xib? By the way, thanks a lot, man.

Costique
  • 23,712
  • 4
  • 76
  • 79
Leo.Zhou
  • 175
  • 1
  • 12