Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Special use cases (Xcode) – Add .app, custom build phase, Objective-C++ sources #171

Open
michaelbaisch opened this issue Jan 8, 2018 · 6 comments

Comments

@michaelbaisch
Copy link

Hello everybody,

I'm working on an addon with some special use cases for the PG. Right now I'm working on macOS (Xcode) side, and I would like to know if I can do the following in the addon_config.mk:

  1. I would like to add an .app bundle to the Xcode project and also add it to the Copy Files Build Phase with the Frameworks directory as destination. It's exactly what happens when you add a Framework to ADDON_FRAMEWORKS. Sadly I it doesn't work when I add the .app bundle with ADDON_FRAMEWORKS.

  2. I would like to add a custom Run Script build phase.

  3. The addon uses sources which contain C++ and Objective-C code. In Xcode you have to declare the source file as Objective-C++ to compile correctly. Is there a way to tell the PG to declare a .cpp as Objective-C++ source file. I've already tired ADDON_OBJC_SOURCES which didn't work. (Changing the extension might lead to problems on the VS side of things)

If PG isn't able to do those things does anybody have a quick idea how to simply automate those steps, preferably without running another script?

Thanks a lot.

@arturoc
Copy link
Member

arturoc commented Jan 9, 2018

  1. you can't specify copying something to the bundle but you can use a script i can imagine

  2. you can add a run script phase using:

osx:
        ADDON_AFTER = ...

plus commands you want to run.

  1. adding objc sources should be working now using ADDON_OBJC_SOURCES. there was an error before but it's solved now in master. you'll need to compile the PG yourself though

I'm going to close this but feel free to keep posting if you find any problem with the proposed solutions

@arturoc arturoc closed this as completed Jan 9, 2018
@michaelbaisch
Copy link
Author

Thanks for the reply. Sadly I couldn't get ADDON_AFTER and ADDON_OBJC_SOURCES to work. Initially I worked with of_0.9.8 but I now also work with GitHub master OF branch. And I also updated the projectGenerator submodule, so I have your latest commit.

  1. ADDON_AFTER: with the new PG I saw a new Script Phase with AppStore stuff. But not another with my test string.

  2. ADDON_OBJC_SOURCES: the .cpp source file is still declared as C++ Source instead of Objective-C++ Source. Also wildcards ADDON_OBJC_SOURCES = src/*.cpp would be neat.

  3. On the Windows side of things: I need to copy a few recourses (some DLLs, some other) to the bin directory. There is already ADDON_DLLS_TO_COPY which is great. But my question is, can I somehow use a wildcard? With ADDON_DATA the comment says "you can use wildcards like * and ?". This is sadly not working with ADDON_DLLS_TO_COPY and I have a directory 'locales' which needs to be copied with over 100 files. Alternatively I also tried ADDON_AFTER to see if something would show up in the Post-Build Events where one could add another robocopy line to achieve the same result, but also without any luck.

  4. With the new OF and PG I also noticed that the Framework Search Paths for ADDON_FRAMEWORKS is not getting set anymore, by adding it manually again the project builds again (macOS Xcode).

My current addon_config.mk:

…

common:

  ADDON_INCLUDES_EXCLUDE = libs
  ADDON_INCLUDES_EXCLUDE += libs/cef/include/%
  ADDON_INCLUDES_EXCLUDE += libs/cef/lib
  ADDON_INCLUDES_EXCLUDE += libs/cef/lib/%

  ADDON_SOURCES_EXCLUDE = src/process_helper_mac.cpp

vs:
  ADDON_LIBS_EXCLUDE = "libs/cef/export/vs/x64"
  ADDON_LIBS_EXCLUDE = "libs/cef/export/vs/x64/%"
  
  ADDON_AFTER = "THIS IS A TEST"
  ADDON_DLLS_TO_COPY  = "libs/cef/export/vs/x64/%"
  ADDON_DLLS_TO_COPY += "libs/cef/export/vs/x64/*"
  ADDON_DLLS_TO_COPY += "libs/cef/export/vs/x64/?"
  ADDON_DLLS_TO_COPY += "libs/cef/export/vs/x64/chrome_elf.dll"
  ADDON_DLLS_TO_COPY += "libs/cef/export/vs/x64/cef.pak"

osx:
  ADDON_FRAMEWORKS = "../../../addons/ofxCef/libs/cef/lib/osx/Chromium Embedded Framework.framework"
  ADDON_AFTER = "THIS IS A TEST"
  ADDON_OBJC_SOURCES = src/ofxCEF.cpp

Thanks again!

@arturoc arturoc reopened this Jan 10, 2018
@arturoc
Copy link
Member

arturoc commented Jan 10, 2018

mmh ok that's strange. thinking about it i believe the after rule might only work with makefiles but was never ported to work on the PG. about the rest. both objective c sources and wildcards with all the options should be working so not sure what' might be going on, i'll take a look when i have a moment

@michaelbaisch
Copy link
Author

I did a bit of digging in the source, here some notes to possibly make it easier for you:

ADDON_AFTER: yeah I was already wondering because I didn't find any reference to it in the source. Any plans to implement it?

ADDON_OBJC_SOURCES: Can't find anything weird by quickly browsing through the code. I was just thinking if PG already finds the file as "ordinary" C++ source and then I declare it as Objective-C, could this lead to a weird situation?

ADDON_DLLS_TO_COPY: In 'visualStudioProject.cpp:430' I found this:

std::string dll = std::filesystem::absolute(addon.dllsToCopy[i], addon.addonPath).string();
ofFile(dll).copyTo(ofFilePath::join(projectDir,"bin/"),false,true);

As far as I can tell dllsToCopy contains the raw strings I define with ADDON_DLLS_TO_COPY. And I'm guessing that ofFile doesn't handle wildcards like this. And I just couldn't find out how ADDON_DATA does it's thing.

@arturoc
Copy link
Member

arturoc commented Jan 10, 2018

ADDON_OBJC_SOURCES: Can't find anything weird by quickly browsing through the code. I was just thinking if PG already finds the file as "ordinary" C++ source and then I declare it as Objective-C, could this lead to a weird situation?

ah yes, you probably need to exclude the files as source first so they are then recognized as objc sources. the PG should be doing this automatically but it doesn't yet

@michaelbaisch
Copy link
Author

I couldn't get the exclusion to work. When I try to exclude a file with ADDON_SOURCES_EXCLUDE, it excluded the files for good. See ofAddon.cpp:417:

exclude(srcFiles,excludeSources);
exclude(csrcFiles,excludeSources);
exclude(cppsrcFiles,excludeSources);
exclude(objcsrcFiles,excludeSources);
exclude(headersrcFiles,excludeSources);

The only other thing I found where I could exclude something is ADDON_INCLUDES_EXCLUDE and as far as I know it only excluded paths from Header Search Paths.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants