Skip to content

Get it working with OF 0.9.8 (macOS) #34

@michaelbaisch

Description

@michaelbaisch

I would like to see this working on at least macOS and Windows. I started with macOS and I couldn't get the example working. After a while I decided to started from scratch with OF 0.9.8, Xcode 8.3.2, and macOS Sierra 10.12.4.

I tried to make this process a bit more automatic by using the ProjectGenerator as much as possible. This is why the folder structure is a bit different and the building phases are much simpler.

Here is my fork with a cef-test example (To get this working you need to do the first 6 steps anyway).


This is what I did to get it working:
  1. Download the latest Mac OS X 64-bit Build from the Spotify Automated Builds site. (I downloaded the Standard Distribution 3.2987.1601.gf035232)

  2. cmake -G "Xcode" in the root of the downloaded folder.

  3. Open the Xcode project and compile the cefclient

    • I switched in Product -> Scheme -> Edit Scheme… the Build Configuration to Release.
  4. Copy Chromium Embedded Framework.framework and cefclient Helper.app from tests/cefclient/Release/cefclient.app/Contents/Frameworks into the ofxCEF folder in libs/CEF/lib/osx

    • The Helper app might be a separate target in the future again but I wanted to eliminate any potential source of failure, so I simply copied this one.
  5. Also copy libcef_dll_wrapper/Release/libcef_dll_wrapper.a into the same folder libs/CEF/lib/osx.

  6. And copy the contents of the include folder into libs/CEF/include

  7. Now open the project generator and create a new project with ofxCef as addon selected.

  8. Open the Xcode project and drag and drop the cefclient Helper.app into addons/ofxCef/libs/CEF/lib/osx

  9. In the project settings got to Build Phases and add a Copy Files Phase. This is for Chromium Embedded Framework.framework and cefclient Helper.app, the Destination should be set to Frameworks. There might already be a Copy FilesPhase to Frameworks in with Chromium Embedded Framework.framework, in that case just add the cefclient Helper.app.

  10. We need another build phase this time a script phase. In there goes:

    install_name_tool -change "@rpath/Frameworks/Chromium Embedded Framework.framework/Chromium Embedded Framework" "@executable_path/../Frameworks/Chromium Embedded Framework.framework/Chromium Embedded Framework" "${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}"
    rm -rf "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/Frameworks/$PRODUCT_NAME Helper.app"
    mv "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/Frameworks/cefclient Helper.app" "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/Frameworks/$PRODUCT_NAME Helper.app"
    mv "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/Frameworks/$PRODUCT_NAME Helper.app/Contents/MacOS/cefclient Helper" "$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/Frameworks/$PRODUCT_NAME Helper.app/Contents/MacOS/$PRODUCT_NAME Helper"
    

    With that I think I replaced all the other script phases and the additional script.
    As far as I understand only the Helper app and executable name needs to be changed to *appName* + Helper. For some reason we also need to change "@rpath/Frameworks/Chromium Embedded Framework.framework/Chromium Embedded Framework" of the app executable, which I don't understand because it already seems to point to the right place?!

  11. Also remove process_helper_mac.cc from the Compile Sourcesphase.

  12. Now select each .cpp file in addons/ofxCef/src and set the type in the file inspector to Objective-C++ Source. Do the same for ofApp.cpp. (If we have separate source files for macOS and windows we could change the extension for the macOS sources to .mm to skip this step)

  13. Copy the contents from my cef-test project main.cpp, ofApp.cpp, and ofApp.h

Now your project should be in the same state as my cef-test project in my fork and it should hopefully compile and show a website.


Well, sometimes at least. I'm running into a few problems:
  • The web content only showed up when resizing the window. OnPaint isn't called when the the browser initially loads the website, which I don't understand. A dirty workaround was to add this:

     ofSleepMillis(10);	// Seems to help a bit
     reshape(ofGetWidth(), ofGetHeight());
    

    at the end of void ofxCEF::setup()

  • Sometimes the site doesn't seem to show at all. Even after I resize the window a few times. Although I see through Little Snitch that the app makes a connection.

  • Sometimes the memory skyrockets to ~3GB at the start and after a few laggy seconds it goes back to ~1GB. I wasn't able to find out what is using the memory. Looking at the app and the Helper app with Instruments only shows few MB. Normally the Debugging Navigator in Xcode shows around 40MB.

  • The menu bar isn't useable. I also can't cmd+q the app which is annoying.

I looked at cef and the ofxCef code and tried a few things. For example when calling void ofxCEF::setup() in ofApp::setup() NSView * view = [ cocoaWindow contentView]; isn't available. I guess OF hasn't created the window yet. So I moved that into offApp::update() but it didn't really improve a lot.

Is there anyone else who wants to see this production ready? I would appreciate some feedback on the steps I took to get it working and the problems I run into. Maybe I missed something.
And I'm sorry to put all this in one Issue, it's pretty general and everything might be connected after all ;)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions