Looking for clarity on using find_package with a dylib and xcframework in same directory.

Hello,

Sorry if this should be obvious but I’m relatively new to cmake and haven’t been able to find a clean solution to my issue.

I’m trying to create some imported targets for an installation of a library on my system. Let’s call it Foo. I’ve created a FooConfig.cmake file so I can use find_package(Foo CONFIG) and its targets.

The Foo install has a lib directory containing (among other things): libFoo.a, libFoo.dylib, and Foo.xcframework (used for Swift).

Calling find_library(Foo_LIBRARY NAMES Foo PATHS lib) results in lib/Foo.xcframework. I assume this is related to the fact that CMAKE_FIND_LIBRARY_SUFFIXES has this order on macOS .tbd;.dylib;.so;.a. I would prefer to get the dynamic library.

I could of course specify libFoo.dylib build I would prefer to use NAMES Foo as the library is cross-platform and also has Windows and Linux installs. I grepped though the FindXXX.cmake files that are included in cmake and didn’t see many (any?) .dylib in find_library calls so I’m not sure what the right approach is.

Is there way to ask find_library to not include xcframeworks?

Or is one of these solutions the most CMake friendly approach:

  • Move Foo.xcframework to a lib/XCFrameworks or lib/Frameworks to avoid the issue
  • Use a variable for the name which is set to Foo for Windows/Linux and libFoo.dylib on macOS
  • Remove .tdb from CMAKE_FIND_LIBRARY_SUFFIXES for the whole build.
  • Something else?

Thanks in advance.

You can control whether find_library() prefers frameworks or non-framework libraries by setting the CMAKE_FIND_FRAMEWORK variable. See those docs for how to use it.

Thanks, I completely missed this.