Compiler sous Linux

From FreeCAD Documentation
Revision as of 10:46, 19 November 2019 by Mario52 (talk | contribs) (Created page with "==== Saut ====")

Sous les distributions GNU/Linux récentes, FreeCAD est généralement facile à compiler, puisque toutes les dépendances sont fournies par le gestionnaire de paquets. Cela se fait en 3 étapes :

  1. Obtenir le code source de FreeCAD
  2. Obtenir les dépendances ou les paquets dont FreeCAD dépend
  3. Configurer avec cmake et compiler avec make

Vous trouverez ci-dessous des instructions détaillées du processus complet, quelques scripts de compilation et des particularités que vous pourriez rencontrer. Si vous constatez des informations erronées ou désuètes (les distributions Linux changent régulièrement), ou si vous utilisez une distribution qui n'est pas listée, pour les discussion voir sur le forum, votre aide pour corriger le tout sera appréciée.

Processus général pour compiler FreeCAD à partir des sources. Les dépendances tierces doivent être dans le système, ainsi que le code source de FreeCAD lui-même. CMake configure le système de manière à ce que le projet entier soit compilé avec une seule instruction make.

Obtenir le code source

Git

Le meilleur moyen d’obtenir le code est de cloner le dépôt Git en lecture seule. Pour cela, vous avez besoin du programme git qui peut être installé dans la plupart des distributions Linux. Il peut également être obtenu sur le site officiel.

Ceci créera une copie de la dernière version du code source de FreeCAD dans un nouveau répertoire nommé freecad-source.

sudo apt install git
git clone https://github.com/FreeCAD/FreeCAD.git freecad-source

Pour plus d'informations sur l'utilisation de Git et sur la contribution de code au projet, voir gestion du code source.

Source sous forme archive

Vous pouvez alternativement télécharger la source sous forme d'archive, en fichier .zip ou .tar.gz, et décompresser cela dans le dossier voulu.

Obtenir les dépendances

Pour compiler FreeCAD, vous devez installer les dépendances requises mentionnées dans les Bibliothèques externes ; les packages contenant ces dépendances sont répertoriés ci-dessous pour différentes distributions Linux. Veuillez noter que les noms et la disponibilité des bibliothèques dépendront de votre distribution particulière. Si votre distribution est ancienne, certains paquets peuvent ne pas être disponibles ou avoir un nom différent. Dans ce cas, consultez la section Anciennes distributions et distributions non-conventionnelles ci-dessous.

Une fois que vous avez toutes les dépendances installées procédez àla Compilation de FreeCAD.

Veuillez noter que le code source de FreeCAD est d’environ 500 Mo ; il peut être trois fois plus gros si vous clonez le référentiel Git avec son historique de modifications complet. Obtenir toutes les dépendances peut nécessiter le téléchargement de 500 Mo ou plus de nouveaux fichiers ; Lorsque ces fichiers sont décompressés, ils peuvent nécessiter 1500 Mo ou plus d’espace. Notez également que le processus de compilation peut générer jusqu'à 1500 Mo de fichiers supplémentaires lorsque le système copie et modifie le code source complet. Par conséquent, assurez-vous de disposer de suffisamment d’espace libre sur votre disque dur, au moins 4 Go, lors de la tentative de compilation.

Debian et Ubuntu

Sous les systèmes basés sur Debian (Debian, Ubuntu, LinuxMint, etc...) , il est très facile d'installer toutes les dépendances requises. La plupart des bibliothèques sont disponibles via apt, le gestionnaire de paquets Synaptic, ou le gestionnaire de paquets de votre choix.

Si vous avez déjà installé FreeCAD depuis les dépôts officiels, vous pouvez installer ses dépendances de compilation à l'aide de cette unique ligne de commande dans un terminal :

sudo apt build-dep freecad

Cependant, si la version de FreeCAD dans les référentiels est ancienne, les dépendances peuvent être mauvaises pour compiler une version récente de FreeCAD. Par conséquent, vérifiez que vous avez installé les packages suivants.

Ces packages sont essentiels à la réussite de toute compilation :

  • build-essential, installe les compilateurs C et C++ et les librairies C.
  • cmake, un outil indispensable pour configurer la source de FreeCAD. Vous pouvez également souhaiter installer cmake-gui et cmake-curses-gui pour une option graphique.
  • libtool, des outils essentiels pour produire des librairies partagées.
  • lsb-release, l'utilitaire reporting de base standard est normalement déjà installé sur un système Debian et vous permet de distinguer, par programme, entre une installation Debian pure et une variante, telle que Ubuntu ou Linux Mint. Ne supprimez pas ce paquet, car de nombreux autres paquets système peuvent en dépendre.

La compilation de FreeCAD utilise le langage Python, et est également utilisé au moment de l'exécution en tant que script. Si vous utilisez une distribution basée sur Debian, l'interpréteur Python est normalement déjà installé.

  • python3
  • swig, l'outil qui crée des interfaces entre le code C++ et Python.

Veuillez vérifier que vous avez installé Python 3. Python 2 étant obsolète en 2019, les nouveaux développements dans FreeCAD ne sont pas testés avec cette version du langage.

Les librairies Boost doivent être installées :

  • libboost-dev
  • libboost-date-time-dev
  • libboost-filesystem-dev
  • libboost-graph-dev
  • libboost-iostreams-dev
  • libboost-program-options-dev
  • libboost-python-dev
  • libboost-regex-dev
  • libboost-serialization-dev
  • libboost-signals-dev
  • libboost-thread-dev

Les librairies Coin doivent être installées :

  • libcoin80-dev, pour Debian Jessie, Stretch, Ubuntu 16.04 à 18.10, ou
  • libcoin-dev, pour Debian Buster, Ubuntu 19.04 et suivants, ainsi que pour Ubuntu 18.04/18.10 avec les PPAs freecad-stable/freecad-daily ajoutés à vos sources logicielles.

Plusieurs librairies traitant des mathématiques, des surfaces triangulées, du tri, des maillages, de la vision par ordinateur, des projections cartographiques, de la visualisation 3D, du système X11 Window, de l'analyse XML et de la lecture de fichiers Zip :

  • libeigen3-dev
  • libgts-bin
  • libgts-dev
  • libkdtree++-dev
  • libmedc-dev
  • libopencv-dev or libcv-dev
  • libproj-dev
  • libvtk7-dev or libvtk6-dev
  • libx11-dev
  • libxerces-c-dev
  • libzipios++-dev

Python 2 et Qt4

Ceci n’est plus recommandé pour les nouvelles installations car Python 2 et Qt4 sont obsolètes.

Pour compiler FreeCAD pour Debian Jessie, Stretch, Ubuntu 16.04, en utilisant Python 2 et Qt4, installez les dépendances suivantes.

  • qt4-dev-tools
  • libqt4-dev
  • libqt4-opengl-dev
  • libqtwebkit-dev
  • libshiboken-dev
  • libpyside-dev
  • pyside-tools
  • python-dev
  • python-matplotlib
  • python-pivy
  • python-ply
  • python-pyside

Python 3 et Qt5

Pour compiler FreeCAD avec Debian Buster, Ubuntu 19.04 et ultérieures, ainsi que Ubuntu 18.04/18.10 avec l'un ou l'autre des dépôts PPA freecad-stable/freecad-daily ajouté à vos sources de logiciels, installez les dépendances suivantes.

  • qtbase5-dev
  • qttools5-dev
  • libqt5opengl5-dev
  • libqt5svg5-dev
  • libqt5webkit5-dev or qtwebengine5-dev
  • libqt5xmlpatterns5-dev
  • libqt5x11extras5-dev
  • libpyside2-dev
  • libshiboken2-dev
  • pyside2-tools
  • python3-dev
  • python3-matplotlib
  • python3-pivy
  • python3-ply
  • python3-pyside2.qtcore
  • python3-pyside2.qtgui
  • python3-pyside2.qtsvg
  • python3-pyside2.qtwidgets
  • python3-pyside2uic

Noyau OpenCascade

Le noyau OpenCascade est la librairie graphique principale pour créer des formes 3D. Il existe dans une version officielle OCCT et une version communautaire OCE. La version communautaire n'est plus recommandée car elle est obsolète.

Pour Debian Buster, Ubuntu 18.10 et versions ultérieures, ainsi que pour Ubuntu 18.04 avec les freecad-stable/freecad-daily PPAs ajoutés à vos sources de logiciels, installez les paquets officiels.

  • libocct*-dev
    • libocct-data-exchange-dev
    • libocct-draw-dev
    • libocct-foundation-dev
    • libocct-modeling-algorithms-dev
    • libocct-modeling-data-dev
    • libocct-ocaf-dev
    • libocct-visualization-dev
  • occt-draw

Pour Debian Jessie, Stretch, Ubuntu 16.04 et plus récente, installez les paquetages Édition Communautaire.

  • liboce*-dev
    • liboce-foundation-dev
    • liboce-modeling-dev
    • liboce-ocaf-dev
    • liboce-ocaf-lite-dev
    • liboce-visualization-dev
  • oce-draw

Vous pouvez installer toutes les librairies individuellement ou en utilisant l’extension astérisque. Changez occ par oce si vous voulez installer les librairies de la communauté.

sudo apt install libocct*-dev

Paquets optionnels

Vous pouvez éventuellement installer ces paquets supplémentaires :

  • libsimage-dev, pour que Coin prenne en charge d'autres formats de fichier image.
  • doxygen et libcoin-doc (ou libcoin80-doc pour d'anciens systèmes), si vous avez l’intention de générer de la documentation sur le code source.
  • libspnav-dev, pour la prise en charge des périphériques 3Dconnexion, comme "Space Navigator" ou "Space Pilot".
  • checkinstall, si vous avez l'intention d'enregistrer vos fichiers installés dans le gestionnaire de paquets de votre système, afin de pouvoir les désinstaller ultérieurement.

Commande unique pour Qt5 et Python 3

Requiert Pyside2, disponible sous Debian Buster et les freecad-stable/freecad-daily PPAs.

sudo apt install cmake cmake-gui libboost-date-time-dev libboost-dev libboost-filesystem-dev libboost-graph-dev libboost-iostreams-dev libboost-program-options-dev libboost-python-dev libboost-regex-dev libboost-serialization-dev libboost-signals-dev libboost-thread-dev libcoin-dev libeigen3-dev libgts-bin libgts-dev libkdtree++-dev libmedc-dev libocct-data-exchange-dev libocct-ocaf-dev libocct-visualization-dev libopencv-dev libproj-dev libpyside2-dev libqt5opengl5-dev libqt5svg5-dev libqt5webkit5-dev libqt5x11extras5-dev libqt5xmlpatterns5-dev libshiboken2-dev libspnav-dev libvtk7-dev libx11-dev libxerces-c-dev libzipios++-dev occt-draw pyside2-tools python3-dev python3-matplotlib python3-pivy python3-ply python3-pyside2.qtcore python3-pyside2.qtgui python3-pyside2.qtsvg python3-pyside2.qtwidgets python3-pyside2uic qtbase5-dev qttools5-dev swig

Commande unique pour Python 2 et Qt4

Ceci n'est pas recommandé pour les installations plus récentes car Python 2 et Qt4 sont obsolètes.

sudo apt install cmake debhelper dh-exec dh-python libboost-date-time-dev libboost-dev libboost-filesystem-dev libboost-graph-dev libboost-iostreams-dev libboost-program-options-dev libboost-python-dev libboost-regex-dev libboost-serialization-dev libboost-signals-dev libboost-thread-dev libcoin80-dev libeigen3-dev libgts-bin libgts-dev libkdtree++-dev libmedc-dev libocct-data-exchange-dev libocct-ocaf-dev libocct-visualization-dev libopencv-dev libproj-dev libpyside-dev libqt4-dev libqt4-opengl-dev libqtwebkit-dev libshiboken-dev libspnav-dev libvtk6-dev libx11-dev libxerces-c-dev libzipios++-dev lsb-release occt-draw pyside-tools python-dev python-matplotlib python-pivy python-ply swig

Utilisateurs de Ubuntu 16.04, veuillez aussi consulter la discussion sur la compilation dans le forum Compiler sur Linux (Kubuntu): CMake ne peut pas trouver VTK.

Fedora

Vous avez besoin des paquets suivants :

  • gcc-c++ (or possibly another C++ compiler?)
  • cmake
  • doxygen
  • swig
  • gettext
  • dos2unix
  • desktop-file-utils
  • libXmu-devel
  • freeimage-devel
  • mesa-libGLU-devel
  • OCE-devel
  • python
  • python-devel
  • python-pyside-devel
  • pyside-tools
  • boost-devel
  • tbb-devel
  • eigen3-devel
  • qt-devel
  • qt-webkit-devel
  • ode-devel
  • xerces-c
  • xerces-c-devel
  • opencv-devel
  • smesh-devel
  • coin3-devel

(si coin2 est la dernière disponible pour votre version de Fedora, utilisez les paquets à partir de http://www.zultron.com/rpm-repo/)

  • soqt-devel
  • freetype
  • freetype-devel

Et optionnellement :


Gentoo

Le moyen le plus facile de vérifier quels paquets sont nécessaires pour compiler FreeCAD et de vérifier via portage :

emerge -pv freecad

Ceci devrait vous donner une superbe liste de paquets supplémentaires que devez avoir installés sur votre système.

Si FreeCAD n'est pas disponible sur portage, il est disponible sur la waebbl overlay. Le suivi des problèmes sur le recouvrement waebbl Github peut vous aider à résoudre certains problèmes que vous pourriez rencontrer. La superposition fournit freecad-9999 , que vous pouvez choisir de compiler ou simplement utiliser pour obtenir les dépendances.

layman -a waebbl

openSUSE

Tumbleweed

Les commandes suivantes installeront les packages nécessaires à la construction de FreeCAD avec Qt5 et Python 3.

zypper in --no-recommends -t pattern devel_C_C++ devel_qt5

zypper in libqt5-qtbase-devel libqt5-qtsvg-devel libqt5-qttools-devel boost-devel swig libboost_program_options-devel libboost_mpi_python3-devel libboost_system-devel libboost_program_options-devel libboost_regex-devel libboost_python3-devel libboost_thread-devel libboost_system-devel libboost_headers-devel libboost_graph-devel python3 python3-devel python3-matplotlib python3-matplotlib-qt5 python3-pyside2 python3-pyside2-devel python3-pivy gcc gcc-fortran cmake occt-devel libXi-devel opencv-devel libxerces-c-devel Coin-devel SoQt-devel freetype2-devel eigen3-devel libode6 vtk-devel libmed-devel hdf5-openmpi-devel openmpi2-devel netgen-devel freeglut-devel libspnav-devel f2c doxygen dos2unix glew-devel

La commande suivante installera Qt Creator et le débogueur de projet GNU.

zypper in libqt5-creator gdb

S'il manque des packages, vous pouvez vérifier le fichier Tumbleweed "FreeCAD.spec" sur Open Build Service.

Vérifiez également s’il existe des correctifs à appliquer (tels que 0001-find-openmpi2-include-files.patch).

Saut

If there is a difference between the available packages on Tumbleweed and Leap, then you can read the Leap "FreeCAD.spec" file on the Open Build Service to determine the required packages.

Arch Linux

You will need the following libraries from the official repositories:

  • boost-libs
  • curl
  • desktop-file-utils
  • glew
  • hicolor-icon-theme
  • jsoncpp
  • libspnav
  • med
  • opencascade
  • shiboken2
  • xerces-c
  • pyside2
  • python-matplotlib
  • python-netcdf4
  • qt5-svg
  • qt5-webkit
  • qt5-webengine
  • boost
  • cmake
  • eigen
  • git
  • gcc-fortran
  • pyside2-tools
  • swig
  • qt5-tools
  • shared-mime-info

Also, make sure to check the AUR for any missing packages that are not on the repositories, currently:

  • coin
  • python-pivy
  • med
sudo pacman -S boost-libs curl desktop-file-utils glew hicolor-icon-theme jsoncpp libspnav med opencascade shiboken2 xerces-c pyside2 python-matplotlib python-netcdf4 qt5-svg qt5-webkit qt5-webengine cmake eigen git gcc-fortran pyside2-tools swig qt5-tools shared-mime-info coin python-pivy med

Older and non-conventional distributions

On other distributions, we have very few feedback from users, so it might be harder to find the required packages.

Try first locating the required libraries mentioned in third party libraries in your package manager. Beware that some of them might have a slightly different package name; search for name, but also libname, name-dev, name-devel, and similar. If that is not possible try compiling those libraries yourself.

FreeCAD requires the GNU g++ compiler version equal or above 3.0.0, as FreeCAD is mostly written in C++. During the compilation some Python scripts are executed, so the Python interpreter has to work properly. To avoid any linker problems it is also a good idea to have the library paths in the LD_LIBRARY_PATH variable or in the ld.so.conf file. This is already done in modern Linux distributions, but may need to be set in older ones.

Pivy

Pivy (Python wrappers to Coin3d) is not needed to build FreeCAD or to start it, but it is needed as a runtime dependency by the Draft Workbench. If you are not going to use this workbench, you won't need Pivy. However, do notice that the Draft Workbench is used internally by other workbenches, like Arch and BIM, so Pivy needs to be installed to use these workbenches as well.

By November 2015 the obsolete version of Pivy included with the FreeCAD source code will no longer compile on many systems. This isn't a big problem as normally you should get Pivy from your distribution's package manager; if you cannot find Pivy, you may have to compile it yourself, see Pivy compilation instructions.

Debug symbols

In order to troubleshoot crashes in FreeCAD, it is useful to have the debug symbols of important dependency libraries such as Qt. For this, try installing the dependency packages that end with -dbg, -dbgsym, -debuginfo or similar, depending on your Linux distribution.

For Ubuntu, you may have to enable especial repositories to be able to see and install these debug packages with the package manager. See Debug Symbol Packages for more information.

Compile FreeCAD

FreeCAD uses CMake as its main build system, as it's available on all major operating systems. Compiling with CMake is usually very simple and happens in two steps.

  1. CMake checks that every needed program and library is present on your system, and generates a Makefile that is configured for the second step. FreeCAD has several configuration options to choose from, but it comes with sensible defaults. Some alternatives are detailed below.
  2. The compilation itself, which is done with the program make, which generates the FreeCAD executables.

Since FreeCAD is a large application, compiling the entire source code can take anywhere from 10 minutes to one hour, depending on your CPU and the number of CPU cores used for compilation.

You can build the code either in or out of the source directory. Out-of-source building is generally the best option.

Out-of-source build

Building in a separate folder is more convenient than building in the same directory where the source code is located as every time you update the source code CMake can intelligently determine which files have changed, and recompile only what is needed. This is very useful when testing different Git branches as you don't confuse the build system.

To build out-of-source, simply create a build directory, freecad-build, distinct from your FreeCAD source folder, freecad-source; then from this build directory point cmake to the right source folder. You can use cmake-gui or ccmake instead of cmake in the instructions below as well. Once cmake finishes configuring the environment, use make to start the actual compilation.

mkdir freecad-build
cd freecad-build
cmake ../freecad-source
make -j$(nproc --ignore=2)

The -j option of make controls how many jobs (files) are compiled in parallel. The nproc program prints the number of CPU cores in your system; by using it together with the -j option you can choose to process as many files as you have cores, in order to speed up overall compilation of the program. In the example above, it will use all cores in your system except two; this will keep your computer responsive for other uses while compilation proceeds in the background. The FreeCAD executable will eventually appear in the freecad-build/bin directory. See also Compiling (speeding up) to improve compilation speed.

In-source building

In-source builds are fine if you want to compile a version of FreeCAD quickly, and don't intend to update the source code often. In this case, you can remove the compiled program and the source just by deleting a single folder.

Change to the source directory, and point cmake to the present directory (denoted by a single point):

cd freecad-source
cmake .
make -j$(nproc --ignore=2)

The FreeCAD executable will then reside in the freecad-source/bin directory.

How to repair your source code directory

If you accidentally performed a compilation inside the source code directory, or added strange files, and would like to restore the contents to only the original source code, you can perform the following steps.

> .gitignore
git clean -df
git reset --hard HEAD

The first line clears the .gitignore file. This ensures that the following clean and reset commands will affect everything in the directory and will not ignore items matching the expressions in .gitignore. The second line deletes all files and directories that are not tracked by the git repository; then the last command will reset any changes to tracked files, including the first command which cleared the .gitignore file.

If you do not clear the source directory, subsequent runs of cmake may not capture new options to the system if the code changes.

Configuration

By passing different options to cmake, you can change how FreeCAD is compiled. The syntax is as follows.

cmake -D <var>:<type>=<value> $SOURCE_DIR

Where $SOURCE_DIR is the directory that contains the source code. The <type> may be omitted in most cases. The space after the -D option may also be omitted.

For example, to avoid building the FEM Workbench:

cmake -D BUILD_FEM:BOOL=OFF ../freecad-source
cmake -DBUILD_FEM=OFF ../freecad-source

All possible variables are listed in the CMakeLists.txt file, located in the toplevel freecad-source directory. In this file, search for the word option to get to the variables that can be set, and see their default values.


# ==============================================================================
# =================   All the options for the build process    =================
# ==============================================================================

option(BUILD_FORCE_DIRECTORY "The build directory must be different to the source directory." OFF)
option(BUILD_GUI "Build FreeCAD Gui. Otherwise you have only the command line and the Python import module." ON)
option(FREECAD_USE_EXTERNAL_ZIPIOS "Use system installed zipios++ instead of the bundled." OFF)
option(FREECAD_USE_EXTERNAL_SMESH "Use system installed smesh instead of the bundled." OFF)
...

Alternatively, use the command cmake -LH to list the current configuration, and thus all variables that can be changed. You may also install and use cmake-gui to launch a graphical interface showing all the variables that can be modified. In the next sections we list some of the more relevant options that you may want to use.

For a Debug build

Create a Debug build to troubleshoot crashes in FreeCAD. Beware that with this build the Sketcher becomes very slow with complex sketches.

cmake -DCMAKE_BUILD_TYPE=Debug ../freecad-source

For a Release build

Create a Release build to test code that doesn't crash. A Release build will run much faster than a Debug build.

cmake -DCMAKE_BUILD_TYPE=Release ../freecad-source

Building against Python 3 and Qt5

By default, FreeCAD builds for Python 2 and Qt4. Since these two packages are obsolete, it is better to build for Python 3 and Qt5.

In a modern Linux distribution you only need to provide two variables specifying the use of Qt5, and the path to the Python interpreter.

cmake -DBUILD_QT5=ON -DPYTHON_EXECUTABLE=/usr/bin/python3 ../freecad-source

Building for a specific Python version

If the default python executable in your system is a symbolic link to Python 2, cmake will try to configure FreeCAD for this version. You can choose another version of Python by giving the path to a specific executable:

cmake -DPYTHON_EXECUTABLE=/usr/bin/python3 ../freecad-source

If that doesn't work, you may have to define additional variables pointing to the desired Python libraries and include directories:

cmake -DPYTHON_EXECUTABLE=/usr/bin/python3.6 \
    -DPYTHON_INCLUDE_DIR=/usr/include/python3.6m \
    -DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.6m.so \
    -DPYTHON_PACKAGES_PATH=/usr/lib/python3.6/site-packages/ \
    ../freecad-source

It is possible to have several independent versions of Python in the same system, so the locations and version numbers of your Python files will depend on your particular Linux distribution. Use python3 -V to display the version of Python that you are using currently; only the first two numbers are necessary; for example, if the result is Python 3.6.8, you need to specify the directories that relate to the 3.6 version. If you don't know the right directories, try searching for them with the locate command.

locate python3.6

You may use python3 -m site in a terminal to determine the site-packages directory, or dist-packages for Debian systems.

Building with Qt Creator against Python 3 and Qt5

To compile in Qt Creator add the appropriate variables to the bottom of Projects → Manage Kits → Kits → Default (or your kit) → CMake Configuration. Again, specify the correct paths and Python version that you want to use.

PYTHON_EXECUTABLE=/usr/bin/python3.7
PYTHON_INCLUDE_DIR=/usr/include/python3.7m
PYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.7m.so
PYTHON_PACKAGES_PATH=/usr/lib/python3.7/site-packages
BUILD_QT5=ON

Go to Projects → Run → Run Configuration and choose FreeCADMain to compile the graphical version of FreeCAD, or FreeCADMainCMD to compile only the command line version.

Qt designer plugin

If you want to develop Qt code for FreeCAD, you'll need the Qt Designer plugin that provides all custom widgets of FreeCAD.

Go into an auxiliary directory of the source code, the run qmake with the indicated project file to create a Makefile; then run make to compile the plugin.

cd freecad-source/src/Tools/plugins/widget
qmake plugin.pro
make

If you are compiling for Qt5, make sure the qmake binary is the one for this version, so that the resulting Makefile contains the necessary information for Qt5.

cd freecad-source/src/Tools/plugins/widget
$QT_DIR/bin/qmake plugin.pro
make

where $QT_DIR is the directory that stores Qt binary libraries, for example, /usr/lib/x86_64-linux-gnu/qt5.

The library created is libFreeCAD_widgets.so, which needs to be copied to $QT_DIR/plugins/designer.

sudo cp libFreeCAD_widgets.so $QT_DIR/plugins/designer

External or internal Pivy

Previously, a version of Pivy was included in the source code of FreeCAD (internal). If you wanted to use your system's copy of Pivy (external), you needed to use -DFREECAD_USE_EXTERNAL_PIVY=1.

Using external Pivy became the default during development of FreeCAD 0.16, therefore this option does not need to be set manually anymore.

Doxygen documentation

If you have Doxygen installed you can build the source code documentation. See source documentation for instructions.

Additional documentation

The source code of FreeCAD is very extensive, and with CMake it's possible to configure many options. Learning to use CMake fully may be useful to choose the right options for your particular needs.

Making a debian package

If you plan to build a Debian package out of the sources you need to install certain packages first:

sudo apt install dh-make devscripts lintian

Go to the FreeCAD directory and call

debuild

Once the package is built, you can use lintian to check if the package contains errors

lintian freecad-package.deb

Updating the source code

The CMake system allows you to intelligently update the source code, and only recompile what has changed, making subsequent compilations faster.

Move to the location where the FreeCAD source code was first downloaded, and pull the new code:

cd freecad-source
git pull

Then move into the build directory where the code was compiled initially, and run cmake specifying the present directory (denoted by a dot); then trigger the re-compilation with make.

cd ../freecad-build
cmake .
make -j$(nproc --ignore=2)

Troubleshooting

For 64 bit systems

When building FreeCAD for 64-bit there is a known issue with the OpenCASCADE (OCCT) 64-bit package. To get FreeCAD running properly you might need to run the configure script and set additional CXXFLAGS:

./configure CXXFLAGS="-D_OCC64"

For Debian based systems this option is not needed when using the pre-built OpenCASCADE packages because these ones set the proper CXXFLAGS internally.

Automatic build scripts

Here is all what you need for a complete build of FreeCAD. It's a one-script-approach and works on a freshly installed Linux distribution. The commands will ask for the root password for installation of packages and new online repositories. These scripts should run on 32 and 64 bit versions. They are written for different versions, but are also likely to run on a later version with or without major changes.

If you have such a script for your preferred distribution, please discuss it on the FreeCAD forum so we can incorporate it.

Ubuntu

These scripts provide a reliable way to install the correct set of dependencies required to build and run FreeCAD on Ubuntu. They make use of the Ubuntu personal package archives (PPA), and should work on any version of Ubuntu targeted by the PPA. The freecad-daily PPA targets recent versions of Ubuntu, while the freecad-stable PPA targets officially supported versions of Ubuntu.

This script installs the daily compiled snapshot of FreeCAD and its dependencies. It adds the daily repository, gets the dependencies to build this version, and installs the required packages. Afterwards it proceeds to pull the source code into a particular directory, creates a build directory and changes into it, configures the compilation environment with cmake, and finally builds the entire program with make. Save the script to a file, make it executable, and run it, but don't use sudo; superuser privileges will be asked only for selected commands.

#!/bin/sh
sudo add-apt-repository --enable-source ppa:freecad-maintainers/freecad-daily && sudo apt-get update
sudo apt-get build-dep freecad-daily
sudo apt-get install freecad-daily

git clone https://github.com/FreeCAD/FreeCAD.git freecad-source
mkdir freecad-build
cd freecad-build
cmake -DBUILD_QT5=ON -DPYTHON_EXECUTABLE=/usr/bin/python3 ../freecad-source
make -j$(nproc --ignore=2)

If you wish, you can uninstall the pre-compiled version of FreeCAD (freecad-daily) while leaving the dependencies in place, however, leaving this package installed will allow the package manager to keep its dependencies up to date as well; this is mostly useful if you intend to follow the development of FreeCAD, and constantly update and compile the sources from the Git repository.

The previous script assumes that you want to compile the latest version of FreeCAD, so you are using the "daily" repository to get the dependencies. However, you can instead get the build dependencies of the "stable" version for your current Ubuntu release. If this is the case, replace the top part of the previous script with the following instructions. For Ubuntu 12.04, omit --enable-source from the command.

#!/bin/sh
sudo add-apt-repository --enable-source ppa:freecad-maintainers/freecad-stable && sudo apt-get update
sudo apt-get build-dep freecad
sudo apt-get install freecad

Once you install the freecad package from the freecad-stable repository, it will supersede the FreeCAD executable that is available from the Universe Ubuntu repository. The executable will be named simply freecad, and not freecad-stable.

OpenSUSE 12.2

No external Repositories are needed to compile FreeCAD 0.13 with this release. However, there is an imcompatability with python3-devel which needs to be removed. FreeCAD can be compiled from GIT similar to in OpenSUSE 12.2

# install needed packages for development
sudo zypper install gcc cmake OpenCASCADE-devel libXerces-c-devel \
python-devel libqt4-devel python-qt4 Coin-devel SoQt-devel boost-devel \
libode-devel libQtWebKit-devel libeigen3-devel gcc-fortran git swig
 
# create new dir, and go into it
mkdir FreeCAD-Compiled 
cd FreeCAD-Compiled
 
# get the source
git clone https://github.com/FreeCAD/FreeCAD.git free-cad
 
# Now you will have subfolder in this location called free-cad. It contains the source
 
# make another dir for compilation, and go into it
mkdir FreeCAD-Build1
cd FreeCAD-Build1 
 
# build configuration 
cmake ../free-cad
 
# build FreeCAD
make
 
# test FreeCAD
cd bin
./FreeCAD -t 0

Since you are using git, next time you wish to compile you do not have to clone everything, just pull from git and compile once more

# go into free-cad dir created earlier
cd free-cad
 
# pull
git pull
 
# get back to previous dir
cd ..
 
# Now repeat last few steps from before.
 
# make another dir for compilation, and go into it
mkdir FreeCAD-Build2
cd FreeCAD-Build2
 
# build configuration 
cmake ../free-cad
 
# build FreeCAD
# Note: to speed up build use all CPU cores: make -j$(nproc)
make
 
# test FreeCAD
cd bin
./FreeCAD -t 0

Debian Squeeze

# get the needed tools and libs
sudo apt-get install build-essential python libcoin60-dev libsoqt4-dev \
libxerces-c2-dev libboost-dev libboost-date-time-dev libboost-filesystem-dev \
libboost-graph-dev libboost-iostreams-dev libboost-program-options-dev \
libboost-serialization-dev libboost-signals-dev libboost-regex-dev \
libqt4-dev qt4-dev-tools python2.5-dev \
libsimage-dev libopencascade-dev \
libsoqt4-dev libode-dev subversion cmake libeigen2-dev python-pivy \
libtool autotools-dev automake gfortran
 
# checkout the latest source
git clone https://github.com/FreeCAD/FreeCAD.git freecad
 
# go to source dir
cd freecad
 
# build configuration 
cmake .
 
# build FreeCAD
# Note: to speed up build use all CPU cores: make -j$(nproc)
make
 
# test FreeCAD
cd bin
./FreeCAD -t 0

Fedora 27/28/29

Posted by user [PrzemoF] in the forum.

#!/bin/bash

ARCH=$(arch)

MAIN_DIR=FreeCAD
BUILD_DIR=build

#FEDORA_VERSION=27
#FEDORA_VERSION=28
FEDORA_VERSION=29

PACKAGES="gcc cmake gcc-c++ boost-devel zlib-devel swig eigen3 qt-devel \
shiboken shiboken-devel pyside-tools python-pyside python-pyside-devel xerces-c \
xerces-c-devel OCE-devel smesh graphviz python-pivy python-matplotlib tbb-devel \
 freeimage-devel Coin3 Coin3-devel med-devel vtk-devel"

FEDORA_29_PACKAGES="boost-python2 boost-python3 boost-python2-devel boost-python3-devel"

if [ "$FEDORA_VERSION" = "29" ]; then
    PACKAGES="$PACKAGES $FEDORA_29_PACKAGES"
fi

echo "Installing packages required to build FreeCAD"
sudo dnf -y install $PACKAGES
cd ~
mkdir $MAIN_DIR || { echo "~/$MAIN_DIR already exist. Quitting.."; exit; }
cd $MAIN_DIR
git clone https://github.com/FreeCAD/FreeCAD.git
mkdir $BUILD_DIR || { echo "~/$BUILD_DIR already exist. Quitting.."; exit; }
cd $BUILD_DIR
cmake ../FreeCAD 
make -j$(nproc)

Arch using AUR

Arch User Repository (AUR) is a collection user made recipes to build packages which are not officially supported by distribution maintainers / community. They are usually safe. You can see who maintain the package and for how long he did. It is recommended to check construction files. Also non open source software are available in this area even if maintained by the official owning company.

Prerequisite : git

Steps :

  1. Open a terminal. Optionally create a directory eg. mkdir git. Optionally change directory eg. cd git.
  2. Clone the AUR repository : git clone http://aur.archlinux.org/packages/freecad-git
  3. Enter AUR repository folder : cd freecad-git
  4. Compile using Arch makepkg : makepkg -s. The -s or --syncdeps flag will also install required dependencies.
  5. Install created package : makepkg --install or double click on the pkgname-pkgver.pkg.tar.xz inside your file browser.

To update FreeCAD to latest build just repeat from step 3. Update AUR repo when there is some breaking change in the recipe or new features using git checkout -f inside the folder.