mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.65k stars 1.64k forks source link

Framework handling on macOS with cmake dependency still has some issues. #12622

Open vespakoen opened 11 months ago

vespakoen commented 11 months ago

Describe the bug I am trying to compile "dune3d" using meson on macOS. dune3d depends on OpenCASCADE, which it adds using this line of code:

opencascade = dependency('OpenCASCADE', method : 'cmake')

At the linking stage, I get a bunch of these errors:

ld: multiple errors: file cannot be mmap()ed, errno=22 path=/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/System/Library/Frameworks/AppKit.framework in '/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/System/Library/Frameworks/AppKit.framework'; file cannot be mmap()ed, errno=22 path=/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/System/Library/Frameworks/IOKit.framework in '/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/System/Library/Frameworks/IOKit.framework'

I then found the following relevant issues: #8045 and the PR #8134 However, the .framework's in my case are added through another mechanism, namely through: INTERFACE_LINK_LIBRARIES, which are not handled in the mentioned pull request.

So I believe the /Full/Path/To/Some.framework -> -framework Some.framework conversion that is currently done is in the wrong place, and should be moved "towards the end" where also targets are present that can be added through other mechanisms.

To Reproduce

On macOS, install opencascade brew install opencascade

opencascade = dependency('OpenCASCADE', method : 'cmake')

And build something with the above.

Or, look at the following snippet of the debug log I got from mason:

CMake TARGET:
  -- name:      TKDraw
  -- type:      SHARED
  -- imported:  True
  -- properties: {
      'INTERFACE_INCLUDE_DIRECTORIES': ['/opt/homebrew/include/opencascade']
      'INTERFACE_LINK_LIBRARIES': ['TKernel', 'TKG2d', 'TKGeomBase', 'TKG3d', 'TKMath', 'TKBRep', 'TKGeomAlgo', 'TKShHealing', 'TKMesh', 'TKService', 'TKHLR', 'TKTopAlgo', '/opt/homebrew/opt/tcl-tk/lib/libtcl8.6.dylib', '/opt/homebrew/opt/tcl-tk/lib/libtk8.6.dylib', '/opt/homebrew/opt/tbb/lib/libtbb.12.10.dylib', '/opt/homebrew/opt/tbb/lib/libtbbmalloc.2.10.dylib', 'objc', '/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/System/Library/Frameworks/AppKit.framework', '/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk/System/Library/Frameworks/IOKit.framework']
      'IMPORTED_CONFIGURATIONS': ['RELEASE']
      'IMPORTED_LOCATION_RELEASE': ['/opt/homebrew/lib/libTKDraw.7.7.2.dylib']
      'IMPORTED_SONAME_RELEASE': ['@rpath/libTKDraw.7.7.dylib']
     }
  -- tline: CMake TRACE: /opt/homebrew/lib/cmake/opencascade/OpenCASCADEDrawTargets.cmake:59 add_library(['TKDraw', 'SHARED', 'IMPORTED'])

Expected behavior I would expect the link command at the end to use -framework NameOfFramework in stead of adding an incorrect path.

system parameters

HealthyPear commented 11 months ago

Hi,

I found a similar issue myself and opened a discussion https://github.com/mesonbuild/meson/discussions/12661

is this the same problem?

meson 1.2.2 and 1.3.1 macos 11.7.10 (Big Sur)

vespakoen commented 11 months ago

@HealthyPear in your link command there is /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/OpenGL.framework which should be -framework OpenGL, which is possibly coming from the same place indeed.

I wrote a hacky script to work around this issue over here: https://github.com/dune3d/dune3d/pull/45/files#diff-50ed1090aedf71598ab3968b9e04d656c81a62ed14923b94982c64611db4a56e and hope that someone can fix it in meson one day, I don't really have time to dig into meson myself at the moment unfortunately.