meson icon indicating copy to clipboard operation
meson copied to clipboard

macos framework paths not found when using clang with -std=C++<ver> or std=gnu++<ver> external CXX args

Open christophecvr opened this issue 1 year ago • 0 comments

When building some packages with macports such as gstreamer1-plugins-bad for macos system and using xcode basic systems clang apple compiler or upgraded apple clang compiler sometimes extra CXX compiler args such as for this package -std=gnu++11 is required. When building package it issues a meson configure error:

Called: `/opt/local/bin/pkg-config --modversion CoreFoundation` -> 1
stderr:
Package CoreFoundation was not found in the pkg-config search path.
Perhaps you should add the directory containing `CoreFoundation.pc'
to the PKG_CONFIG_PATH environment variable
No package 'CoreFoundation' found
-----------
Finding framework path by running:  /usr/bin/clang++ -v -E - -pipe -Os -std=gnu++11 -stdlib=libc++ -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk -arch x86_64 -I/opt/local/include -L/opt/local/lib -Wno-unused-command-line-argument -isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk 

CMake binary for host machine is cached.
Preliminary CMake check failed. Aborting.
Run-time dependency corefoundation found: NO (tried pkgconfig, framework and cmake)

sys/applemedia/meson.build:42:21: ERROR: Dependency "CoreFoundation" not found, tried pkgconfig, framework and cmake

Further investigation showed that the issued framework find path command failed. I tried it in terminal on it's own. failure message :

Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
<whole command ...>
error: invalid argument '-std=gnu++11' not allowed with 'C'

Due to the error which can't be silenced on clang compiler the command issues 1 and is broken result : framework path not found.

When searching further on the net this issue does show up very much in environments where clang and meson is used. this for -std=c++11,-std=gnu++11,-std=c++17 or -std=gnu++17 ....

The cause is that indeed those args are only allowed for C++/Gobj++ not for 'C'

I did finally found a simple (and do think a clean solution to this issue) : First :

  • Meson does a very good job at run time by only using the required external args for the type of file to build.
  • The Framework-path find command on the other hand go's for all file type c++,cojb++,c,cobj,cpp and ...
  • that is required also every external arg CXX,CPP,C,COBJ,COBJ.. flags may contain required extra links and ..
  • Making a solution which just ommits the CXX,Cobj flags is not a option.

My solution is just to omit the invalid flags for just the framework find path command how :

changing in file mesonbuild/compilers/mixins/clike.py line 1187-1195 from :

        # TODO: this really needs to be *AppleClang*, not just any clang.
        if self.id != 'clang':
            raise mesonlib.MesonException('Cannot find framework path with non-clang compiler')
        # Construct the compiler command-line
        commands = self.get_exelist(ccache=False) + ['-v', '-E', '-']
        commands += self.get_always_args()
        # Add CFLAGS/CXXFLAGS/OBJCFLAGS/OBJCXXFLAGS from the env
        commands += env.coredata.get_external_args(self.for_machine, self.language)
        mlog.debug('Finding framework path by running: ', ' '.join(commands), '\n')

to :

        # TODO: this really needs to be *AppleClang*, not just any clang.
        if self.id != 'clang':
            raise mesonlib.MesonException('Cannot find framework path with non-clang compiler')
        # Construct the compiler command-line
        commands = self.get_exelist(ccache=False) + ['-v', '-E', '-']
        commands += self.get_always_args()
        # Add CFLAGS/CXXFLAGS/OBJCFLAGS/OBJCXXFLAGS from the env
        # 'std=c++<ver>','std=gnu++<ver>' are valid for C++/ObjC++ but not for 'C'
        commands += [x for x in env.coredata.get_external_args(self.for_machine, self.language) if '-std=c++' not in x and '-std=gnu++' not in x]
        mlog.debug('Finding framework path by running: ', ' '.join(commands), '\n')

Then all the framwork paths are found again and project builds fine .

I will submit in short a pull request with this change. I just added this issue first so I can refer to this issue in pull request commit.

christophecvr avatar Sep 06 '24 12:09 christophecvr