Compile on MacOS/sv: Difference between revisions

From FreeCAD Documentation
(Updating to match new version of source page)
Line 1: Line 1:
This page explains how to compile the latest FreeCAD source code on Mac OS X.
Att kompilera FreeCAD på en Mac skiljer sig inte så mycket från stegen i Linux eller andra UNIX varianter. Den största utmaningen är att verkligen få alla beroenden installerade. I de följande avsnitten, kommer Jag (lhagan) att beskriva exakt de stegen som jag fick gå igenom för att få denna applikation att kompileras på Leopard och Snow Leopard med en Intel Mac (PowerPC borde vara möjligt, men kräver omkompilering av några binära bibliotek som jag inte hunnit än). Såvitt jag vet, så är jag den enda som har lyckats bygga FreeCAD på en Mac nyligen, så var snäll och posta på [http://forum.freecadweb.org/viewforum.php?f=8 discussion forum] om dessa steg fungerar för dig, på[http://forum.freecadweb.org/viewforum.php?f=4 help forum] om de inte fungerar, eller redigera denna sidan om du hittar fel.


== Prerequisites ==
=== Ladda ned FreeCAD källkoden ===
First of all, you will need to install the following software.


=== Xcode Development Tools ===

Unless you want to use the Xcode IDE for FreeCAD development, you will only need to install the Command Line Tools. To do this on 10.9 and later, open Terminal, run the following command, and then click Install in the dialog that comes up.
Först så behöver du en kopia av FreeCAD's källkodsträd. Kolla den senaste revisionen från Sourceforge subversion programförråd genom att använda detta kommandot i terminalen:

=== Git ===
The quickest and best way to get the code is to clone the read-only git repository (you need the [http://git-scm.com/ git] package installed):
<pre>
<pre>
xcode-select --install
git clone git://free-cad.git.sourceforge.net/gitroot/free-cad/free-cad freecad
</pre>
</pre>
For other versions of OS X, you can get the package from the Apple developer [https://developer.apple.com/downloads/index.action?q=xcode downloads page] (sign in with the same Apple ID you use for other Apple services). Specifically, you will need to download Development Tools 3.2 for OS X 10.6, and Command Line Tools 4.8 for OS X 10.8.
This will place a copy of the latest version of the FreeCAD source code in a new directory called "freecad". The first time you try connecting to the free-cad.git.sourceforge.net host, you will receive a message asking to authenticate the sourceforge SSH key, which is normally safe to accept (you can check their SSH keys on the sourceforge website if you are not sure)


=== Github ===
=== CMake ===
Install the latest version of CMake from http://www.cmake.org/download. Although Homebrew will also install CMake, it only installs the command line executable.
There is an always up to date FreeCAD repository on Gihub:
[https://github.com/FreeCAD/FreeCAD_sf_master github.com/FreeCAD/FreeCAD_sf_master]
=== Source package ===
Alternatively you can download a source package, but they could be already quite old so it's always better to get the latest sources. Depending on your distribution, there are several ways to obtain a source package:


=== Homebrew ===
Official FreeCAD source packages (distribution-independent):
To install Homebrew, enter the following in Terminal:
https://sourceforge.net/projects/free-cad/files/FreeCAD%20Source/

Debian:
http://packages.debian.org/source/sid/freecad

Ubuntu:
http://packages.ubuntu.com/source/precise/freecad

=== Install Dependencies ===
On Mac OS X 10.7, the following dependencies are NOT bundled with the operating and thus must be installed before building FreeCAD:
*sip
*fortran
*xerces-c
*boost
*eigen
*ftgl
*coin3d
*OpenCASCADE
*Qt
*pyqt
*soqt

==== Option 1: Homebrew ====
'''Note''': this section is still a work in progress! See the help forum post for the latest.
:https://forum.freecadweb.org/viewtopic.php?f=4&t=2064&p=15405
Download and install the package manager Homebrew:
:http://mxcl.github.com/homebrew/
Then compile and install most of FreeCAD's dependencies:
<pre>
<pre>
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install sip gfortran xerces-c boost eigen coin qt pyqt soqt ftgl
</pre>
</pre>
== Getting the source ==
Go on to [[CompileOnMac#Build OpenCASCADE]].
In this guide, the source and build folders are created in '''/Users/username/FreeCAD''', but you can of course use whatever folder you want.
==== Option 2: MacPorts/Fink ====

'''Note: this section is in need of updates.'''

Sedan, om du inte redan har gjort det, installera MacPorts. MacPorts är ett system som tillåter dig att ladda ned, kompilera, och installera många vanliga öppen-källkodsapplikationer med ett enda kommando. Liknanade applikationer från UNIX/Linux världen är PKGSRC och APT. För att installera, ladda bara ned diskavbildningen från MacPorts sajten och följ anvisningarna:
:http://www.macports.org/install.php
Antingen eller om du just installerade MacPorts, så vill du förmodligen försäkra dig om att den är uppdaterad. Kör:
<pre>
<pre>
mkdir ~/FreeCAD
sudo port selfupdate
cd ~/FreeCAD
</pre>
</pre>
To get the FreeCAD source code, run:
Nu när MacPorts är installerad och uppdaterad, så kan du börja att installera några av FreeCAD's nödvändiga paket:
*xercesc
*boost
*py-sip
*ftlg
*f2c
*eigen3
*py-pyqt4
*Coin
Följande kommando kommer att kompilera/installera alla nödvändiga bibliotek. Om MacPorts producerar fel, såkanske du kan prova att installera dem en åt gången.
<pre>
<pre>
git clone git://git.code.sf.net/p/free-cad/code FreeCAD-git
sudo port install xercesc boost ftgl f2c eigen3 py-sip py-pyqt4 Coin
</pre>
</pre>
Alternatively, you can use the github mirror: https://github.com/FreeCAD/FreeCAD_sf_master.git
Note that for python packages like py-sip and py-pyqt4, there are multiple packages, one for each MacPorts version of Python.


== Installing the Dependencies ==
Note that boost is a large package, and py-pyqt4 depends on qt4-mac, which is a large package. You may want to run port -v install so that you have more of an idea what's going on during these long builds.
All of the needed libraries can be installed using Homebrew.

Qt4 is also available for Mac as a binary installer from the Qt web site. I'm not sure how nicely this approach plays with FreeCAD compiling.

It is also possible to choose the version of the gcc compiler to use, some recent versions might sometimes cause problems:
<pre>
<pre>
brew tap homebrew/science
sudo port -v install gcc_select
brew tap sanelson/freecad
sudo port select --list gcc
brew install boost eigen freetype oce python qt pyside pyside-tools xerces-c
sudo port select --set gcc mp-gcc46
brew install --without-framework --without-soqt sanelson/freecad/coin
brew install --HEAD pivy
</pre>
</pre>
== Compiling FreeCAD ==
'''Install Fortran Compiler'''
First, create a new folder for the build:

You also need a FORTRAN compiler. Apple's fork of gcc on OSX does not come with FORTRAN.

An installer for GFortran can be found here, and will do the trick:
http://gcc.gnu.org/wiki/GFortranBinaries#MacOS
If you are using fink, another method is to use the following commands (attempted by Shaneyfelt 2100.Nov.14)
<pre>
<pre>
mkdir ~/FreeCAD/build
sudo fink selfupdate
sudo fink install gcc46
</pre>
</pre>
Now you will need to run CMake to generate the build files. Open the CMake app, and fill in the source and build folder fields. In this case, it would be '''/Users/username/FreeCAD/FreeCAD-git''' for the source, and '''/Users/username/FreeCAD/build''' for the build folder.
''This installs another gcc compiler collection with the name gcc-4 to avoid a name conflict with the apple one.''


Next, click the '''Configure''' button. This will display a dialog asking you to specify what generator to use. Leave it at the default '''Unix Makefiles.''' Configuring will fail the first time because there are some options that need to be changed. Note: You will need to check the '''Advanced''' checkbox to get all of the options.
MacPorts gcc4x packages also include FORTRAN compilers, so this should also work:
<pre>
sudo port install gcc46
</pre>
Another possible MacPorts package is g95. This seems to be a valid FORTRAN90 compiler and will pass FreeCAD's cmake configuration tests, but the actual build seems to ask for gcc-specific options, so probably easier to stick to gcc4x.


{| class="wikitable" style="text-align:left"
'''Install Eigen3'''
|-
! Option name !! Value !! Notes
|-
| BUILD_ROBOT || OFF (unchecked) || As of 12/19/2014, the robot module fails to build using newer versions of clang (OS X 10.9 and later)
|-
| CMAKE_BUILD_TYPE || Release ||
|-
| FREECAD_USE_EXTERNAL_PIVY || ON (checked) ||
|-
| FREETYPE_INCLUDE_DIR_freetype2 || /usr/local/include/freetype2 || You will only need to set this if you are using a CMake version older than 3.1.0
|-
| OCE_DIR || /usr/local/Cellar/oce/0.16.1/OCE.framework/Versions/0.16/Resources ||
|-
| PYSIDERCC4BINARY || /usr/local/bin/pyside-rcc ||
|-
| PYSIDEUIC4BINARY || /usr/local/bin/pyside-uic ||
|-
| PYTHON_EXECUTABLE || /usr/local/bin/python ||
|-
| PYTHON_INCLUDE_DIR || /usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/include/python2.7 ||
|-
| PYTHON_LIBRARY || /usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib ||
|-
|}
Note: The above paths for OCE and Python are for versions 0.16.1 and 2.7.9, respectively -- change as needed.


Now click '''Configure''' again and then '''Generate'''.
Download and unzip the latest eigen3 library here:
http://eigen.tuxfamily.org/index.php?title=Main_Page
These are needed for solver functionality. Once unzipped, the folder named 'Eigen' can be dropped into


Finally, run '''make''' to compile FreeCAD.
'''/usr/local/include/eigen3/'''

=== Build OpenCASCADE ===

Currently, the easiest way to build OpenCASCADE on OS X is from the community edition (oce). Download the source or check out the Git repository from:
:https://github.com/tpaviot/oce
Then, in terminal:
<pre>
<pre>
mkdir build
cd ~/FreeCAD/build
make –j3
cd build
cmake ..
cd ..
make
make install/strip
</pre>
</pre>
The -j option specifies how many make processes to run at once. One plus the number of CPU cores is usually a good number to use. However, if compiling fails for some reason, it is useful to rerun make without the -j option, so that you can see exactly where the error occurred.
You may need cmake:
<pre>
sudo port install cmake
</pre>
=== Ladda ned och 'installera' FreeCAD.app mall ===


If make finishes without any errors, you can now launch FreeCAD, either from Terminal with '''./bin/FreeCAD''', or by double clicking the executable in Finder.
Följande arkiv innehåller en applikationsbunt mall för FreeCAD. Denna är inte strikt nödvändig, men den gör arbete med FreeCAD mycket smidigare är standardinstallationskonfigurationen. Min är i /Applications mappen, men du ska kunna lägga den var du vill -- kom bara ihåg att bunten inte kan flyttas efter att FreeCAD har kompilerats och installerats (utan några ytterligare ändringar). Genom att köra make install med konfigurationen nedan kommer mallen att installeras i denna bunt.
== Creating an application bundle ==
:http://dl.getdropbox.com/u/103808/FreeCAD/FreeCAD_bundle_template_20091128.tar.gz
TODO
=== Kompilera ===
== Updating ==

FreeCAD development happens fast; everyday or so there are bug fixes or new features. To get these changes, run:
Konfigurera, kompilera, och installera nu FreeCAD genom att använda följande kommandon inifrån FreeCAD's rotmapp. Om du lägger din FreeCAD.app bunt på någon annan plats än /Applications (eller inte använder bunten), ändra 'PREFIX' raden motsvarande.
<pre>
<pre>
cd ~/FreeCAD/FreeCAD-git
./autogen.sh
git pull
PREFIX=/Applications/FreeCAD.app/Contents
</pre>
</pre>
And then repeat the compile step above.
If you installed dependencies using Option 1 (Homebrew):
== Troubleshooting ==

TODO
''Note'': this config line has not been verified and may contain errors!
{{docnav|CompileOnUnix|Third Party Libraries}}
<pre>
./configure --with-xercesc-lib=/usr/local/lib --with-xercesc-include=/usr/local/include \
--with-boost-lib=/usr/local/lib --with-boost-include=/usr/local/include \
--with-qt4-dir=/usr/local--with-qt4-lib=/usr/local/lib --with-qt4-include=/usr/local/include \
--with-qt4-framework=/usr/local/lib --with-qt4-bin=/usr/local/bin --with-occ-lib=/usr/local/lib \
--with-occ-include=/usr/local/include/oce --with-coin=/usr/local/lib --with-soqt=/usr/local/lib \
--prefix=/Applications/FreeCAD.app/Contents --bindir=/Applications/FreeCAD.app/Contents/MacOS \
--libdir=/Applications/FreeCAD.app/Contents/Frameworks/FreeCAD \
--includedir=/Applications/FreeCAD.app/Contents/Resources/include \
--datarootdir=/Applications/FreeCAD.app/Contents/Resources/share --enable-debug=no \
--with-python-include=/System/Library/Frameworks/Python.framework/Versions/2.5/Headers
</pre>
Or if you installed dependencies using Option 2 (MacPorts/Fink):
<pre>
./configure --with-xercesc-lib=/opt/local/lib --with-xercesc-include=/opt/local/include \
--with-boost-lib=/opt/local/lib --with-boost-include=/opt/local/include \
--with-qt4-dir=/usr/local/Trolltech/Qt-4.8.0 --with-qt4-lib=/usr/local/Trolltech/Qt-4.8.0/lib \
--with-qt4-include=/usr/local/Trolltech/Qt-4.8.0/include --with-qt4-framework=/Library/Frameworks \
--with-qt4-bin=/usr/local/Trolltech/Qt-4.8.0/bin --with-occ-lib=/usr/local/lib \
--with-occ-include=/usr/local/include/oce --with-coin=/Library/Frameworks \
--with-soqt=/Library/Frameworks --prefix=/Applications/FreeCAD.app/Contents \
--bindir=/Applications/FreeCAD.app/Contents/MacOS --libdir=/Applications/FreeCAD.app/Contents/Frameworks/FreeCAD \
--includedir=/Applications/FreeCAD.app/Contents/Resources/include \
--datarootdir=/Applications/FreeCAD.app/Contents/Resources/share --enable-debug=no \
--with-python-include=/System/Library/Frameworks/Python.framework/Versions/2.5/Headers
</pre>
Then:
<pre>
make
make install
</pre>
Depending on your machine's processing power, the make step can take quite a while.

=== Kör ===

Om allt fungerade som det skulle, så ska ett dubbelklick på .app bunten starta FreeCAD. Om du har några problem, posta detaljerna på [http://forum.freecadweb.org/viewforum.php?f=4 help forum].

=== PyQt4 ===

Some users reported facing a "No Module named PyQt4" message on FreeCAD startup. This is a workaround to correct it:
<pre>
cd /Library/Python/2.6/site-packages
sudo ln -s /contrib/lib/python2.6/site-packages/PyQt4 .
sudo ln -s /contrib/lib/python2.6/site-packages/sip* .
cd /volatile/FreeCAD-r5443-ser/bin/pivy
cp _coin.dylib _coin.so
cd /volatile/FreeCAD-r5443-ser/lib
for i in *.dylib; do j=`basename $i .dylib`; cp $i $j.so; done
</pre>
=== Pivy ===
Some FreeCAD components won't work without Pivy. See [[Extra_python_modules#Pivy|here]] for partial build instructions.


{{docnav/sv|CompileOnUnix/sv|Third Party Libraries/sv}}


[[Category:Developer Documentation/sv]]
[[Category:Developer Documentation]]


{{clear}}
{{clear}}

Revision as of 11:33, 20 December 2014

This page explains how to compile the latest FreeCAD source code on Mac OS X.

Prerequisites

First of all, you will need to install the following software.

Xcode Development Tools

Unless you want to use the Xcode IDE for FreeCAD development, you will only need to install the Command Line Tools. To do this on 10.9 and later, open Terminal, run the following command, and then click Install in the dialog that comes up.

xcode-select --install

For other versions of OS X, you can get the package from the Apple developer downloads page (sign in with the same Apple ID you use for other Apple services). Specifically, you will need to download Development Tools 3.2 for OS X 10.6, and Command Line Tools 4.8 for OS X 10.8.

CMake

Install the latest version of CMake from http://www.cmake.org/download. Although Homebrew will also install CMake, it only installs the command line executable.

Homebrew

To install Homebrew, enter the following in Terminal:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Getting the source

In this guide, the source and build folders are created in /Users/username/FreeCAD, but you can of course use whatever folder you want.

mkdir ~/FreeCAD
cd ~/FreeCAD

To get the FreeCAD source code, run:

git clone git://git.code.sf.net/p/free-cad/code FreeCAD-git

Alternatively, you can use the github mirror: https://github.com/FreeCAD/FreeCAD_sf_master.git

Installing the Dependencies

All of the needed libraries can be installed using Homebrew.

brew tap homebrew/science
brew tap sanelson/freecad
brew install boost eigen freetype oce python qt pyside pyside-tools xerces-c
brew install --without-framework --without-soqt sanelson/freecad/coin
brew install --HEAD pivy

Compiling FreeCAD

First, create a new folder for the build:

mkdir ~/FreeCAD/build

Now you will need to run CMake to generate the build files. Open the CMake app, and fill in the source and build folder fields. In this case, it would be /Users/username/FreeCAD/FreeCAD-git for the source, and /Users/username/FreeCAD/build for the build folder.

Next, click the Configure button. This will display a dialog asking you to specify what generator to use. Leave it at the default Unix Makefiles. Configuring will fail the first time because there are some options that need to be changed. Note: You will need to check the Advanced checkbox to get all of the options.

Option name Value Notes
BUILD_ROBOT OFF (unchecked) As of 12/19/2014, the robot module fails to build using newer versions of clang (OS X 10.9 and later)
CMAKE_BUILD_TYPE Release
FREECAD_USE_EXTERNAL_PIVY ON (checked)
FREETYPE_INCLUDE_DIR_freetype2 /usr/local/include/freetype2 You will only need to set this if you are using a CMake version older than 3.1.0
OCE_DIR /usr/local/Cellar/oce/0.16.1/OCE.framework/Versions/0.16/Resources
PYSIDERCC4BINARY /usr/local/bin/pyside-rcc
PYSIDEUIC4BINARY /usr/local/bin/pyside-uic
PYTHON_EXECUTABLE /usr/local/bin/python
PYTHON_INCLUDE_DIR /usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/include/python2.7
PYTHON_LIBRARY /usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib

Note: The above paths for OCE and Python are for versions 0.16.1 and 2.7.9, respectively -- change as needed.

Now click Configure again and then Generate.

Finally, run make to compile FreeCAD.

cd ~/FreeCAD/build
make –j3

The -j option specifies how many make processes to run at once. One plus the number of CPU cores is usually a good number to use. However, if compiling fails for some reason, it is useful to rerun make without the -j option, so that you can see exactly where the error occurred.

If make finishes without any errors, you can now launch FreeCAD, either from Terminal with ./bin/FreeCAD, or by double clicking the executable in Finder.

Creating an application bundle

TODO

Updating

FreeCAD development happens fast; everyday or so there are bug fixes or new features. To get these changes, run:

cd ~/FreeCAD/FreeCAD-git
git pull

And then repeat the compile step above.

Troubleshooting

TODO

CompileOnUnix
Third Party Libraries