1

More detailed explanation (for smaller version, check TL;DR in the end):

I created a framework that I made available in Github. In it, there are 7 Macros that define how the framework should be compiled. I can't just replace them with static const's because 6 of those Macros are used to remove some things from the framework in compiling time.

Those Macros may be divided in groups:

Group 1) Use framework when available

#define USE_THE_METAL_FRAMEWORK_WHEN_AVAILABLE   true
#define USE_THE_OPENGL_FRAMEWORK_WHEN_AVAILABLE  true

Those defines make the framework use the Metal and OpenGL frameworks even if they weren't added to the project. That's done using dlopen. More details below:

I use this so those frameworks can be used only if they are available, so the dev can build his/her app for macOS 10.6 and still use Metal if it's available in the system. The problem is: if your app binary calls dlopen somewhere, you can't add it to the Apple Store (even if you don't really use the function that uses it), so users should be able to remove that from the code if they want. That removes some of the framework functionalities, but make it capable of being submitted.

Group 2) I'm importing the framework

#define IM_IMPORTING_THE_METAL_FRAMEWORK   false
#define IM_IMPORTING_THE_OPENGL_FRAMEWORK  false

Those defines make the framework really use Metal and OpenGL frameworks, without using dlopen. In that way, it can be submitted to the Apple Store and still use the features that were mentioned before.

Group 3) Behaviour changes

#define USER_NOTIFICATIONS_SHOULD_SHOW_A_BIGGER_ICON   true
#define NSDEBUGLOG_SHOULD_PRINT_TO_A_DESKTOP_FILE_TOO  true

The first one can also cause problems in the Apple Store, and the second one is only for debugging purposes.

And at last...

Group 4) Should be released in the Apple Store

#define I_WANT_TO_BE_RELEASED_IN_APPLE_STORE  false

That one is used for that:

#if I_WANT_TO_BE_RELEASED_IN_APPLE_STORE == true
    #define USER_NOTIFICATIONS_SHOULD_SHOW_A_BIGGER_ICON  false
    #define USE_THE_METAL_FRAMEWORK_WHEN_AVAILABLE        false
    #define USE_THE_OPENGL_FRAMEWORK_WHEN_AVAILABLE       false
#endif

It automatically disables the three defines that may cause problems with the Apple Store.

Still, those who use Travis-CI for example are not capable of changing the framework unless they completely copy it to the project. To solve this problem (or at least reduce it), 5 of those 7 defines could be changed by a file in the main project, for example. If anyone has other suggestions that may solve the issue, I'm listening.

(Optional) If this could be done in a way that the user may be warned (by Xcode or by an error in compiling time) that he/she needs to set those variables that would be great, since this would avoid problems with users that may need to set those Macros.

TL;DR: Is it possible to change the values of some Macros within a framework without modifying the framework itself?

VitorMM
  • 1,060
  • 8
  • 33

1 Answers1

0

No. Make some method, that initialize yours module with some parameters. But anyway you are not able to use dlopen.

Cy-4AH
  • 4,370
  • 2
  • 15
  • 22
  • I already use `dlopen`... that's not the matter. The matter is just being capable of using a macro to remove it in compilation time. Avoiding its use with a parameter isn't the same thing; Apple would still decline the app since this exists within the binary, and they won't stop to analyse your app logic to see if you are using it or not (even because they don't have the source code of your app). – VitorMM Oct 10 '18 at 21:05
  • @vitormm, do not use `dlopen` at all. Remove it at compilation time with your's flags. For other options use dynamic parameters. – Cy-4AH Oct 11 '18 at 10:35
  • Then how can I use OpenGL and Metal only when those frameworks are available? – VitorMM Oct 12 '18 at 13:30
  • Also, _why_ shouldn't I use `dlopen` for apps that aren't going to be distributed in Apple Store? – VitorMM Oct 12 '18 at 13:31
  • @vitormm link them as optional, not as required. – Cy-4AH Oct 22 '18 at 09:37
  • How do I do that? – VitorMM Oct 23 '18 at 13:41
  • @vitormm there is `status` column in `Linked frameworks and libraries`. Set there optional. – Cy-4AH Oct 23 '18 at 14:59