macOS: find_library should maybe consider library architecture
I run several macOS buildbots that build several open source projects. Yesterday I installed MacPorts on them and installed a few ports (notably subversion
). This tool places files in /opt/local/lib
and /opt/local/include
. In particular, it so happened to install /opt/local/lib/libmagic.dylib
.
One project I build nightly is GDCM and it was building yesterday but failed today with:
[CTest: warning matched] ld: warning: ignoring file /opt/local/lib/libmagic.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
Undefined symbols for architecture arm64:
"_magic_close", referenced from:
_main in EncapsulateFileInRawData.cxx.o
"_magic_file", referenced from:
_main in EncapsulateFileInRawData.cxx.o
"_magic_open", referenced from:
_main in EncapsulateFileInRawData.cxx.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
This build of GDCM specifies CMAKE_OSX_ARCHITECTURES=x86_64;arm64
(i.e. a Universal Binary). MacPorts installed x86_64-only on this Intel Mac. find_library
found the existence of a file at /opt/local/lib/libmagic.dylib
but it seems it doesn't check what architectures the found file contains, and whether they align with what my build specifies in CMAKE_OSX_ARCHITECTURES
. libmagic is optional for GDCM, so yesterday it found nothing, and built fine. Today it found an Intel-only version from MacPorts and the universal build is broken.
Perhaps find_library
should use file
or otool
to preflight the libs it finds?