2

I'm putting together a little project that's supposed to be cross-platform, built with CMake, and it needs to link with Adobe's XMP toolkit (libxmp). Ideally I'd like CMake to be responsible for building the dependencies, including libxmp, in one fell swoop.

Unfortunately the XMP toolkit is designed to be built with XCode on OSX and CMake on Linux. The CMake build process doesn't appear to work out of the box on OSX.

What's the minimal change I can make to the XMP toolkit to get it to build with CMake on OSX? Should I just keep hacking away at it until it works, or is this a known/solved problem? And, more generally, what additions should I make to my own CMakeLists.txt file to integrate this project with my own?

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055

1 Answers1

4

I've learnt a few things today and several misconceptions have apparently evaporated.

After fulfilling the third-party dependency requirements (expat and zlib; this is just a matter of extracting files from source tarballs into a designated location), this was pretty easy once I realised that XCode can be leveraged here from the commandline, and that XMP's own "build system" has sufficient tools to do everything I need.

In short, from the build directory:

./cmake.command 64 Dynamic WarningAsError ToolchainLLVM.cmake
cd xcode/dynamic/intel_64
xcodebuild -scheme ALL_BUILD build

Then, the framework files are found under public/libraries/macintosh/intel_64/Debug, and the includes were already available under public/include.

After some liberal symlinking, in my own project's CMakeLists.txt it's just a matter of:

target_compile_definitions(myProject
    PUBLIC
        MAC_ENV
)

target_include_directories(
    myProject
    PRIVATE
        include/libxmp
)

# Add build dir to path for finding frameworks (libmxp)
set_target_properties(
    myProject 
    PROPERTIES
        LINK_FLAGS "-Wl,-F${CMAKE_BINARY_DIR}/Frameworks"
)

target_link_libraries(
    myProject
    PRIVATE
        catch
        "-framework XMPCore"
        "-framework XMPFiles"
)

It surely could be finessed, but this does otherwise "just work".


If you are using the XMP Toolkit 2016.07 (and, at time of writing, there is no newer version) and have Xcode 10+ & Mojave, you will need to put together a few patches before you build:

  1. Xcode version detect fix
  2. stdlib config fix
  3. Map/pair type alias fixes

Furthermore, if you use expat 2.2.2 or newer:

  1. Define HAVE_ARC4RANDOM_BUF or XML_POOR_ENTROPY at the top of expat's xmlparse.c (because the libxmp build system won't do this for you)
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055