Compile on MacOS/fr: Difference between revisions

From FreeCAD Documentation
(Created page with "Puis, compilez et installez la plupart des dépendances de FreeCAD :")
(Updating to match new version of source page)
(80 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<languages/>
Comme Mac OS X est basé sur la distribution''' BSD (UNIX)''', la compilation de FreeCAD sur '''Mac''' n'est pas très différente de [[CompileOnUnix/fr|CompileOnUnix]], mais il existe cependant un certain nombre de détails très importants, spécifiques au Mac, pour que tout fonctionne correctement. Ces instructions ont été testées sur '''Lion (10.7)''', mais ''devrait fonctionner'' sur les '''Macs Intel''' qui utilisent '''(Snow) Leopard'''.
{{docnav|CompileOnUnix|Compiling (Speeding up)}}


This page describes how to compile the latest FreeCAD source on macOS X. ''Latest'' means the most recent commit to the master branch of the FreeCAD github repository.
== Obtenir le code source ==


These instructions have been tested on macOS High Sierra
Avant de compiler FreeCAD, vous avez besoin du code source. Il y a trois moyens de l'obtenir :


This page serves as a quick start, and is not intended to be comprehensive with regard to describing all the available build options.
=== Git ===


If you just want to evaluate the latest pre-release build of FreeCAD, you can download pre-built binaries [https://github.com/FreeCAD/FreeCAD/releases from here].
La méthode la meilleure et la plus rapide d'obtenir le code est de « cloner » le dépôt Git en lecture seule (il vous faut le paquet [http://git-scm.com/ git] installé):
<pre>
git clone git://free-cad.git.sourceforge.net/gitroot/free-cad/free-cad freecad
</pre>
Ceci place une copie de la plus récente version du code source de FreeCAD dans un nouveau répertoire nommé « freecad ». La première fois que vous vous connectez à l'hôte free-cad.git.sourceforge.net, vous obtiendrez un message vous demandant d'authentifier la clé SSH de Sourceforge. Celle-ci peut normalement être acceptée sans danger (vous pouvez vérifier les clés SSH de Sourceforge sur leur site Web si vous voulez vous en assurer)


=== Gihub ===
== Install Prerequisites ==
The following software must be installed to support the build process.


=== Homebrew Package Manager ===
Il y a également une copie synchronisée régulièrement du dépôt FreeCAD sur GitHub :
Homebrew is a command line based package manager for macOS. The [https://brew.sh/ Homebrew main page] provides an installation command line that you simply paste into a terminal window.
[https://github.com/FreeCAD/FreeCAD_sf_master github.com/FreeCAD/FreeCAD_sf_master]
=== Paquet source ===


=== CMake ===
Vous pouvez également télécharger un paquet source, mais celui-ci pourrait être assez vieux ; il est donc préférable de télécharger les sources les plus récentes via git ou github. Dépendant de votre distribution, il y a plusieurs façons d'obtenir un paquet source :
CMake is build tool that generates a build configuration based on variables you specify. You then issue the 'make' command to actually build that configuration. The command-line version of CMake is automatically installed as part of the Homebrew installation, above. If you prefer to use a GUI version of CMake, you can download it from [https://www.cmake.org/downloadDownload here].


== Install Dependencies ==
Paquets source FreeCAD officiels (indépendants des distributions):
FreeCAD maintains a Homebrew 'tap' which installs the required formulas and dependencies. Issue the following brew commands in your terminal.
https://sourceforge.net/projects/free-cad/files/FreeCAD%20Source/


<br />
Debian:
<pre>
http://packages.debian.org/source/sid/freecad
brew tap freecad/freecad
brew install eigen
brew install --only-dependencies freecad --with-packaging-utils
</pre>
Notes:
# 'brew install' may take quite a while, so you may want go grab a beverage. :-)


== Get the source ==
Ubuntu:
In the following instructions, the source and build folders are created side-by-side under
http://packages.ubuntu.com/source/precise/freecad


/Users/username/FreeCAD
=== Dépendances de l'installation ===


but you can use whatever folders you want.
Sur '''Mac OS X 10.7''', les dépendances suivantes ne sont pas fournies avec le système, et '''doivent''' donc être installées '''avant''' la compilation de FreeCAD :
*sip
*fortran
*xerces-c
*boost
*eigen
*ftgl
*coin3d
*OpenCASCADE
*Qt
*pyqt
*soqt

==== Option 1: Homebrew ====

'''PS :''' cette section est toujours en cours d'élaboration ! Lisez le post sur ​​le forum d'aide pour plus d'informations.
:https://forum.freecadweb.org/viewtopic.php?f=4&t=2064&p=15405
Téléchargement et installation des gestionnaires de paquets '''Homebrew''' :
:http://mxcl.github.com/homebrew/
Puis, compilez et installez la plupart des dépendances de FreeCAD :
<pre>
<pre>
mkdir ~/FreeCAD
brew install sip gfortran xerces-c boost eigen coin qt pyqt soqt ftgl
cd ~/FreeCAD
</pre>
</pre>
The following command will clone the FreeCAD git repository into a directory called FreeCAD-git.
Go on to [[CompileOnMac#Build OpenCASCADE]].
==== Option 2: MacPorts/Fink ====

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

Install MacPorts (if you don't already have it). MacPorts is a system that allows you to download, compile, and install many common open-source applications with a single command. Similar applications from the UNIX/Linux world are PKGSRC and APT. To install, just download the disk image from the MacPorts site and follow the directions:
:http://www.macports.org/install.php
Whether or not you just installed MacPorts, you'll probably want to make sure it's up to date. Run:
<pre>
<pre>
git clone https://github.com/FreeCAD/FreeCAD FreeCAD-git
sudo port selfupdate
</pre>
</pre>
Create the build folder.
Now that MacPorts is installed and up to date, you can start installing some of FreeCAD's required packages:
*xercesc
*boost
*py-sip
*ftlg
*f2c
*eigen3
*py-pyqt4
*Coin
The following command will compile/install the above libraries. If MacPorts produces errors, you may want to try installing them one at a time.
<pre>
<pre>
mkdir ~/FreeCAD/build
sudo port install xercesc boost ftgl f2c eigen3 py-sip py-pyqt4 Coin
</pre>
</pre>
<br />
Note that for python packages like py-sip and py-pyqt4, there are multiple packages, one for each MacPorts version of Python.


== Run CMake ==
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.


Next, we will run CMake to generate the build configuration. Several options must be passed to CMake. The following table describes the options and gives some background.
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.


=== CMake Options ===
It is also possible to choose the version of the gcc compiler to use, some recent versions might sometimes cause problems:

{| class="wikitable" style="text-align:left"
|-
! Name !! Value !! Notes
|-
| CMAKE_BUILD_TYPE || Release (STRING) || Release or Debug. Debug is generally used for developer-level testing but may also be required for user-level testing and troubleshooting.
|-
| BUILD_QT5 || 1 (BOOL) || Required to build with Qt5.
|-
| CMAKE_PREFIX_PATH || "/usr/local/Cellar/qt@5.6/5.6.2/lib/cmake" (PATH) || Required to build with Qt5. See note below.

|-
| FREECAD_CREATE_MAC_APP || 1 (BOOL) || Create a FreeCAD.app bundle at the location specified in CMAKE_INSTALL_PREFIX, when the 'make install' command issued.
|-
| CMAKE_INSTALL_PREFIX || "./.." (PATH) || Path where you want to generate the FreeCAD.app bundle.
|-
| FREECAD_USE_EXTERNAL_KDL || 1 (BOOL) || Required.
|-
| BUILD_FEM_NETGEN || 1 (BOOL) || Required.
|}

Note: Command line to generate CMAKE_PREFIX_PATH:
<pre>
<pre>
ls -d $(brew list -1 | grep qt | tail -1 | xargs brew --cellar)/*/lib/cmake
sudo port -v install gcc_select
sudo port select --list gcc
sudo port select --set gcc mp-gcc46
</pre>
</pre>
'''Install Fortran Compiler'''


=== CMake GUI ===
You also need a FORTRAN compiler. Apple's fork of gcc on OSX does not come with FORTRAN.
Open the CMake app, and fill in the source and build folder fields. In this example, 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 to populate the list of configuration options. 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.
An installer for GFortran can be found here, and will do the trick:

http://gcc.gnu.org/wiki/GFortranBinaries#MacOS
Set options from the table above, then click '''Configure''' again and then '''Generate'''.
If you are using fink, another method is to use the following commands (attempted by Shaneyfelt 2100.Nov.14)
=== CMake command line ===
Enter the following in the terminal.
<pre>
<pre>
$cd ~/FreeCAD/build
sudo fink selfupdate
$cmake \
sudo fink install gcc46
-DCMAKE_BUILD_TYPE="Release" \
-DBUILD_QT5=1 \
-DCMAKE_PREFIX_PATH="/usr/local/Cellar/qt@5.6/5.6.2/lib/cmake" \
-DFREECAD_USE_EXTERNAL_KDL=1 \
-DBUILD_FEM_NETGEN=1 \
-DFREECAD_CREATE_MAC_APP=1 \
-DCMAKE_INSTALL_PREFIX="./.." \
../FreeCAD-git/

</pre>
</pre>
''This installs another gcc compiler collection with the name gcc-4 to avoid a name conflict with the apple one.''


== Run make ==
MacPorts gcc4x packages also include FORTRAN compilers, so this should also work:
Finally, from a terminal run '''make''' to compile and link FreeCAD, and generate the app bundle.
<pre>
<pre>
cd ~/FreeCAD/build
sudo port install gcc46
make -j5 install
</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.
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.


See also [[Compiling_(Speeding_up)|Compiling - Speeding up]].
'''Install Eigen3'''


If make finishes without any errors, you can now launch FreeCAD by double clicking the executable in the Finder.
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


== Updating from Github ==
'''/usr/local/include/eigen3/'''
FreeCAD development happens fast; every day or so there are bug fixes or new features. To get the latest changes, use git to update the source directory (see [[Source code management]]), then re-run the CMake and make steps above. It is not usually necessary to start with a clean build directory in this case, and subsequent compiles will generally go much faster than the first one.


=== Build OpenCASCADE ===
== Building with Qt4 ==
FreeCAD has transitioned from Qt 4 to Qt 5. If you need to build with Qt4, the following additional steps are required.


# Append '--with-qt4' to the 'brew install' command.
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:
# Do not specify BUILD_QT5 CMake option.
:https://github.com/tpaviot/oce
# Do not specify CMAKE_PREFIX_PATH CMake option
Then, in terminal:

After you install Qt4, if you want to switch to building with Qt5, you will need to uninstall Qt4.
<pre>
<pre>
brew uninstall --ignore-dependencies --force cartr/qt4/shiboken@1.2 cartr/qt4/pyside@1.2 cartr/qt4/pyside-tools@1.2 cartr/qt4/qt
mkdir build
</pre>
cd build
cmake ..
cd ..
make
make install/strip
</pre>
You may need cmake:
<pre>
sudo port install cmake
</pre>
=== Download and 'install' the FreeCAD.app template ===
The following archive contains an application bundle template for FreeCAD. This is not strictly necessary, but it makes working with FreeCAD more convenient than the default installation configuration. The recommended install location for the bundle is the /Applications folder, but you should be able to put it anywhere you want -- just remember that the bundle can't be moved after FreeCAD is complied and installed without further modifications. Running make install using the configuration in the next step will install into this bundle.
:http://dl.getdropbox.com/u/103808/FreeCAD/FreeCAD_bundle_template_20091128.tar.gz
=== Compile ===
Configure, compile, and install FreeCAD using the following commands from within the root FreeCAD folder. If you put your FreeCAD.app bundle somewhere other than /Applications (or aren't using the bundle), change the 'PREFIX' argument accordingly.
<pre>
./autogen.sh
PREFIX=/Applications/FreeCAD.app/Contents
</pre>
If you installed dependencies using Option 1 (Homebrew):


== Troubleshooting ==
''Note'': this config line has not been verified and may contain errors!

<pre>
=== Segfault on Qt5 launch ===
./configure --with-xercesc-lib=/usr/local/lib --with-xercesc-include=/usr/local/include \
If Qt4 was previously installed via brew, and you then build with Qt5, you may get a EXC_BAD_ACCESS (SEGSEGV) exception when launching the new Qt5 build. The fix for this is to manually uninstall Qt4.
--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>
<pre>
brew uninstall --ignore-dependencies --force cartr/qt4/shiboken@1.2 cartr/qt4/pyside@1.2 cartr/qt4/pyside-tools@1.2 cartr/qt4/qt-legacy-formula
make
make install
</pre>
</pre>
Depending on your machine's processing power, the make step can take quite a while.


=== Run ===
=== Fortran ===
''"No CMAKE_Fortran_COMPILER could be found."'' during configuration - Older versions of FreeCAD will need a fortran compiler installed. With Homebrew, do "brew install gcc" and try configuring again, giving cmake the path to Fortran ie -DCMAKE_Fortran_COMPILER=/opt/local/bin/gfortran-mp-4.9 . Or, preferably use a more current version of FreeCAD source!
If everything went OK, double-clicking the .app bundle should start FreeCAD. If you have any issues, post the details on the [http://forum.freecadweb.org/viewforum.php?f=4 help forum].


=== PyQt4 ===
=== OpenGL ===
See [[OpenGL_on_MacOS|OpenGL on MacOS]] for OpenGL issues when Qt 4.8 and earlier are used on MacOS.


=== FreeType ===
Some users reported facing a "No Module named PyQt4" message on FreeCAD startup. This is a workaround to correct it:
When using CMake versions older than 3.1.0, it's necessary to set CMake variable FREETYPE_INCLUDE_DIR_freetype2 manually, eg /usr/local/include/freetype2
<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/fr|[[CompileOnUnix/fr|CompileOnUnix]]|[[Third Party Libraries/fr|Third Party Libraries]]}}


{{Userdocnavi}}
{{docnav|CompileOnUnix|Third Party Libraries}}


[[Category:Developer Documentation]]
[[Category:Developer Documentation/fr]]


{{clear}}
{{clear}}
<languages/>

Revision as of 10:03, 13 July 2019

CompileOnUnix
Compiling (Speeding up)

This page describes how to compile the latest FreeCAD source on macOS X. Latest means the most recent commit to the master branch of the FreeCAD github repository.

These instructions have been tested on macOS High Sierra

This page serves as a quick start, and is not intended to be comprehensive with regard to describing all the available build options.

If you just want to evaluate the latest pre-release build of FreeCAD, you can download pre-built binaries from here.

Install Prerequisites

The following software must be installed to support the build process.

Homebrew Package Manager

Homebrew is a command line based package manager for macOS. The Homebrew main page provides an installation command line that you simply paste into a terminal window.

CMake

CMake is build tool that generates a build configuration based on variables you specify. You then issue the 'make' command to actually build that configuration. The command-line version of CMake is automatically installed as part of the Homebrew installation, above. If you prefer to use a GUI version of CMake, you can download it from here.

Install Dependencies

FreeCAD maintains a Homebrew 'tap' which installs the required formulas and dependencies. Issue the following brew commands in your terminal.


brew tap freecad/freecad
brew install eigen
brew install --only-dependencies freecad --with-packaging-utils

Notes:

  1. 'brew install' may take quite a while, so you may want go grab a beverage. :-)

Get the source

In the following instructions, the source and build folders are created side-by-side under

/Users/username/FreeCAD

but you can use whatever folders you want.

mkdir ~/FreeCAD
cd ~/FreeCAD

The following command will clone the FreeCAD git repository into a directory called FreeCAD-git.

git clone https://github.com/FreeCAD/FreeCAD FreeCAD-git

Create the build folder.

mkdir ~/FreeCAD/build


Run CMake

Next, we will run CMake to generate the build configuration. Several options must be passed to CMake. The following table describes the options and gives some background.

CMake Options

Name Value Notes
CMAKE_BUILD_TYPE Release (STRING) Release or Debug. Debug is generally used for developer-level testing but may also be required for user-level testing and troubleshooting.
BUILD_QT5 1 (BOOL) Required to build with Qt5.
CMAKE_PREFIX_PATH "/usr/local/Cellar/qt@5.6/5.6.2/lib/cmake" (PATH) Required to build with Qt5. See note below.
FREECAD_CREATE_MAC_APP 1 (BOOL) Create a FreeCAD.app bundle at the location specified in CMAKE_INSTALL_PREFIX, when the 'make install' command issued.
CMAKE_INSTALL_PREFIX "./.." (PATH) Path where you want to generate the FreeCAD.app bundle.
FREECAD_USE_EXTERNAL_KDL 1 (BOOL) Required.
BUILD_FEM_NETGEN 1 (BOOL) Required.

Note: Command line to generate CMAKE_PREFIX_PATH:

ls -d $(brew list -1 | grep qt | tail -1 | xargs brew --cellar)/*/lib/cmake

CMake GUI

Open the CMake app, and fill in the source and build folder fields. In this example, 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 to populate the list of configuration options. 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.

Set options from the table above, then click Configure again and then Generate.

CMake command line

Enter the following in the terminal.

$cd ~/FreeCAD/build
$cmake \
  -DCMAKE_BUILD_TYPE="Release"   \
  -DBUILD_QT5=1                  \
  -DCMAKE_PREFIX_PATH="/usr/local/Cellar/qt@5.6/5.6.2/lib/cmake"  \
  -DFREECAD_USE_EXTERNAL_KDL=1   \
  -DBUILD_FEM_NETGEN=1           \
  -DFREECAD_CREATE_MAC_APP=1     \
  -DCMAKE_INSTALL_PREFIX="./.."  \
  ../FreeCAD-git/

Run make

Finally, from a terminal run make to compile and link FreeCAD, and generate the app bundle.

cd ~/FreeCAD/build
make -j5 install

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.

See also Compiling - Speeding up.

If make finishes without any errors, you can now launch FreeCAD by double clicking the executable in the Finder.

Updating from Github

FreeCAD development happens fast; every day or so there are bug fixes or new features. To get the latest changes, use git to update the source directory (see Source code management), then re-run the CMake and make steps above. It is not usually necessary to start with a clean build directory in this case, and subsequent compiles will generally go much faster than the first one.

Building with Qt4

FreeCAD has transitioned from Qt 4 to Qt 5. If you need to build with Qt4, the following additional steps are required.

  1. Append '--with-qt4' to the 'brew install' command.
  2. Do not specify BUILD_QT5 CMake option.
  3. Do not specify CMAKE_PREFIX_PATH CMake option

After you install Qt4, if you want to switch to building with Qt5, you will need to uninstall Qt4.

brew uninstall --ignore-dependencies --force cartr/qt4/shiboken@1.2 cartr/qt4/pyside@1.2 cartr/qt4/pyside-tools@1.2 cartr/qt4/qt

Troubleshooting

Segfault on Qt5 launch

If Qt4 was previously installed via brew, and you then build with Qt5, you may get a EXC_BAD_ACCESS (SEGSEGV) exception when launching the new Qt5 build. The fix for this is to manually uninstall Qt4.

brew uninstall --ignore-dependencies --force cartr/qt4/shiboken@1.2 cartr/qt4/pyside@1.2 cartr/qt4/pyside-tools@1.2 cartr/qt4/qt-legacy-formula

Fortran

"No CMAKE_Fortran_COMPILER could be found." during configuration - Older versions of FreeCAD will need a fortran compiler installed. With Homebrew, do "brew install gcc" and try configuring again, giving cmake the path to Fortran ie -DCMAKE_Fortran_COMPILER=/opt/local/bin/gfortran-mp-4.9 . Or, preferably use a more current version of FreeCAD source!

OpenGL

See OpenGL on MacOS for OpenGL issues when Qt 4.8 and earlier are used on MacOS.

FreeType

When using CMake versions older than 3.1.0, it's necessary to set CMake variable FREETYPE_INCLUDE_DIR_freetype2 manually, eg /usr/local/include/freetype2