I am attempting to make a cross-platform macOS and Linux library that imports the HDF5 C library. HDF5 can be installed on macOS with brew hdf5
or on Ubuntu 18.04 with sudo apt install libhdf5-serial-dev
. This installs files in these locations:
On macOS:
- Library: /usr/local/lib/libhdf5.*
- Header: /usr/local/include/hdf5.h
- To build:
swift build -Xlinker -L/usr/local/lib/
On Ubuntu:
- Library: /usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5.*
- Headher: /usr/include/hdf5/serial/hdf5.h
- To build:
swift build -Xlinker -L/usr/lib/x86_64-linux-gnu/hdf5/serial
HDF5 does not appear to support pkg-config and hence does not contain a .pc file.
Currently, this is my full module.modulemap:
module CHDF5 [system] {
// Linux:
// Lib is at /usr/lib/hdf5/serial/libhdf5.*
// umbrella header "/usr/include/hdf5/serial/hdf5.h"
// macOS:
// Lib is at /usr/local/lib/libhdf5.*
umbrella header "/usr/local/include/hdf5.h"
link "hdf5"
export *
}
To compile on one platform vs the other I have to uncomment the appropriate line.
I attempted to do the following in the module.modulemap:
#if os(Linux)
#else
#endif
But these lines were not recognized as valid tokens.
Is there no way to do a system module import on a library that doesn't have built-in pkg-config support that is cross-platform compatible?
Clone the full code to reproduce here.
All of the above is on Xcode 12's Swift 5.3 release.