Search code examples
macoscmakemacports

How do I instruct CMake to look for libraries installed by MacPorts?


I'm trying to build some of our software, which was designed to run solely on Linux, on MacOS X. We are using CMake and I installed MacPorts so I could easily get CMake along with some of the third party libraries that we depend on.

Now the problem is that CMake doesn't appear to look for libraries from MacPorts by default so several of our targets are disabled as it fails to find the dependencies which are all in /opt/local.

How can I instruct CMake to also look for includes and libraries from MacPorts?


Solution

  • I added a toolchain file for "Darwin" which adds the necessary include and library paths. I was hoping for something a little more automatic but at least it solves the problem.

    darwin.cmake:

    SET(CMAKE_SYSTEM_NAME Darwin)
    
    # Add MacPorts
    INCLUDE_DIRECTORIES(/opt/local/include)
    LINK_DIRECTORIES(/opt/local/lib)