Building FreeCAD on MacOS X

My main programming project over the last couple days involves “building” FreeCAD on Apple OS X. Building is the process that takes a program’s source code and turns it into an executable program. The details often involve some changes depending on which operating system the program is meant to be built and used on.

Apparently not many people have been building FreeCAD on OS X recently, so getting a current version of FreeCAD was a bit difficult for OS X users – especially for non-programmers. There were some scattered instructions on the wiki, which I had used successfully in the past, but it seemed like most FreeCAD compilation was done on Linux or Windows.

I use a Mac for my personal work, and my “gut feel” (backed up by some research) says there are lots of other potential FreeCAD Mac users. So, I wanted to work on improving FreeCAD on my Mac, and might as well make it easier for other people to do the same!

What does that involve? A mix of work, but for FreeCAD the glue that holds the build process together is CMake. Essentially, CMake lets developers write a program, which in turn helps to build another program. A snippet from a CMake script:

# For building on OS X
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")

    # If the user doesn't tell us which package manager they're using
    if(NOT DEFINED MACPORTS_PREFIX AND NOT DEFINED HOMEBREW_PREFIX)

        # Try to find MacPorts path
        find_program(MACPORTS_EXECUTABLE port)
        if(EXISTS ${MACPORTS_EXECUTABLE})
            string(REPLACE "/bin/port" "" MACPORTS_PREFIX ${MACPORTS_EXECUTABLE})
            message(STATUS "Detected MacPorts install at ${MACPORTS_PREFIX}")
        endif(EXISTS ${MACPORTS_EXECUTABLE})

        # Try to find Homebrew path
        find_program(HOMEBREW_EXECUTABLE brew)
        if(EXISTS ${HOMEBREW_EXECUTABLE})
            set(HOMEBREW_PREFIX "/usr/local")
            message(STATUS "Detected Homebrew install at ${HOMEBREW_PREFIX}")
        endif()

    endif(NOT DEFINED MACPORTS_PREFIX AND NOT DEFINED HOMEBREW_PREFIX)

    # In case someone tries to shoot themselves in the foot
    if(DEFINED MACPORTS_PREFIX AND DEFINED HOMEBREW_PREFIX)
        message(SEND_ERROR
                "Multiple package management systems detected - ")
        message(SEND_ERROR
                "define either MACPORTS_PREFIX or HOMEBREW_PREFIX")

To get FreeCAD built on my system, I initially had to figure out what to tell CMake, so it could find the relevant libraries and such on my computer. Fortunately, another FreeCAD developer had recently done some work along the same lines, so this wasn’t too difficult. Result at this stage for my computer looks something like:

cmake -DBUILD_ROBOT="0" -DFREECAD_USE_EXTERNAL_PIVY="1" -DCMAKE_BUILD_TYPE="Release" -DOCE_DIR="/opt/local/Library/Frameworks/OCE.framework/Versions/0.15/Resources" -DPYTHON_LIBRARY="/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib" -DPYTHON_EXECUTABLE="/opt/local/bin/python2.7" -DShiboken_DIR="/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/cmake/Shiboken-1.2.2/" -DPySide_DIR="/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/cmake/PySide-1.2.2/" -DPYSIDERCC4BINARY="/opt/local/bin/pyside-rcc-2.7" -DPYSIDEUIC4BINARY="/opt/local/bin/pyside-uic-2.7" -DPYTHON_INCLUDE_DIR="/opt/local/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/" -DFREECAD_CREATE_MAC_APP="1" ../freecad-code

Then, once that was done, the next step was to make the CMake script smarter so that other people wouldn’t need to bother with that whole mess. The OS X platform poses some additional challenges here, in that there are a few competing package managers in common use. This means the location of some relevant libraries will be different, even among computers with the same operating system.

So, I’ve spent some time over the last couple days mucking around with CMake scripts to make the build process on Mac a bit more automated using two of the most common package managers. Once this is all done, the cmake command line above will hopefully be reduced for MacPorts and Homebrew users to something more like:

cmake -DBUILD_ROBOT="0" ../freecad-code

Cost: Approximately 5 cups tea, counting this post, so far, and feeling close to done.

2 thoughts on “Building FreeCAD on MacOS X

  1. Martin

    So what should an interested person do to get your CMake script? The current Wiki entry for how to compile FreeCAD for OSX results in an error and not in a proper make file. I could resolve some of the issues but there are still errors that prevents CMake from generating a proper make file. 😦

    Like

    Reply
    1. ianrrees Post author

      All that work is in the newer FreeCAD source, don’t think it got committed in time for 0.15, but is definitely in the latest master. I’d suggest starting a thread in the Install/Compile section of the forum if you’re following the wiki instructions and having problems. I’m pretty busy with other things lately, but will try to help out there. -Ian-

      Like

      Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s