Search Unity

Feedback How to change C dialect using Xcode API

Discussion in 'Unity Build Automation' started by francismoy, Jul 19, 2019.

  1. francismoy

    francismoy

    Joined:
    Jul 5, 2017
    Posts:
    46
    I've recently found a problem and in order to solve it, I would need to set the C dialect of the Xcode project generated by Unity to GNU**, instead of C**, using the Xcode API as a postbuild step using the PostProcessBuildAttribute, since I build in Cloud Build.


    I've naively tried:


    proj.SetBuildProperty(mainTarget, "C++ Language Dialect", "GNU++11");


    But it didn't work. How can this be achieved?


    If you're curious as of why, it's because I'm having problems building the Facebook SDK. The problem is that in one file they're using:

    __weak typeof(self) weakSelf = self;

    And typeof (as opposed to __typeof), is a C extension only admitted by GNU.

    Also, as I don't understand how everything works at the lowest level, I wonder: is the Facebook SDK exported as an Xcode project once the files are downloaded via Cocoapods? If so, is it possible to compile ONLY this Xcode project with that setting?

    PS: I added mistakenly the feedback prefix to the thread and I don't know how to remove it...
     
  2. francismoy

    francismoy

    Joined:
    Jul 5, 2017
    Posts:
    46
    This is what I've tried for now, but it's still not working:

    Code (CSharp):
    1. public class PostProcessBuildCloud
    2. {
    3.     public static void PostExport(string xcodeProjectPath)
    4.     {
    5.         var targetName = PBXProject.GetUnityTargetName();
    6.         var proj_path = PBXProject.GetPBXProjectPath(xcodeProjectPath);
    7.         var proj = new PBXProject();
    8.         proj.ReadFromFile(proj_path);
    9.         var mainTarget = proj.TargetGuidByName(targetName);
    10.         proj.SetBuildProperty(mainTarget, "CLANG_CXX_LANGUAGE_STANDARD", "gnu++0x");
    11.         File.WriteAllText(proj_path, proj.WriteToString());
    12.     }
    13. }
    I specify in the Cloud Build Advanced Settings that the Postexport method is: PostProcessBuildCloud.PostExport. In the Build Cloud log I can see the method is considered and called, but then, when Xcode compiles, the log shows:

    /APPLICATION_PATH/Xcode10_2_0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x objective-c -arch armv7 -fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -std=c11 (more stuff)

    Note that the Xcode is using c11 as the language dialect, but I would like it to be gnu++0x so I must be doing something wrong. Any hint?
     
  3. francismoy

    francismoy

    Joined:
    Jul 5, 2017
    Posts:
    46
    Well, what I was doing wrong was that if I was mixing CLANG_CXX_LANGUAGE_STANDARD (C++ dialect, which I didn't want to change) with GCC_C_LANGUAGE_STANDARD (C dialect, which I did want to change to gnu99). So basically, all I had to do was:

    Code (CSharp):
    1. public class PostProcessBuildCloud
    2. {
    3.     public static void PostExport(string xcodeProjectPath)
    4.     {
    5.         var targetName = PBXProject.GetUnityTargetName();
    6.         var proj_path = PBXProject.GetPBXProjectPath(xcodeProjectPath);
    7.         var proj = new PBXProject();
    8.         proj.ReadFromFile(proj_path);
    9.         var mainTarget = proj.TargetGuidByName(targetName);
    10.         proj.SetBuildProperty(mainTarget, "GCC_C_LANGUAGE_STANDARD", "gnu99");
    11.         File.WriteAllText(proj_path, proj.WriteToString());
    12.     }
    13. }
    The compilation error due to the use of typeof was effectively gone and Xcode was compiling using -std=gnu99.