CompileOnUnix/it

Nelle distribuzioni Linux recenti FreeCAD si compila facilmente, dato che di solito tutte le dipendenze sono fornite dal gestore di pacchetti. Fondamentalmente si tratta di eseguire 3 passaggi:
 * 1) Ottenere il codice sorgente di FreeCAD
 * 2) Ottenere le dipendenze (i pacchetti da cui dipende FreeCAD)
 * 3) Configurare con "cmake" e compilare con "make"

Qui, di seguito, troverete le spiegazioni dettagliate di tutto il processo, delle particolarità che si possono incontrare e alcuni script di build,. Se trovate qualcosa di sbagliato o di non aggiornato nel testo successivo (le distribuzioni Linux cambiano spesso), o se utilizzate una distribuzione che non è elencata, per favore aiutateci a correggerlo.

Ottenere il sorgente
Per poter compilare FreeCAD è necessario il codice sorgente. Ci sono 3 modi per ottenerlo:

Git
Il modo migliore e più veloce per ottenere il codice è quello di clonare il repository git di sola lettura ora ospitato in GitHub (bisogna avere il pacchetto git installato):

Questo crea una copia locale della versione più recente del codice sorgente di FreeCAD in una nuova directory chiamata "freecad-code".

Pacchetto sorgente
In alternativa è possibile scaricare il pacchetto sorgente, ma potrebbe già essere abbastanza vecchio, e quindi è sempre meglio ottenere i sorgenti più recenti tramite git o github.

Ottenere le dipendenze
Per compilare FreeCAD sotto Linux è necessario installare prima tutte le librerie indicate nella pagina Librerie di terze parti. Notare che i nomi e la disponibilità delle librerie dipendono dalla vostra distribuzione. Notare che se non si utilizza la versione più recente della propria distribuzione, alcuni dei pacchetti indicati in seguito potrebbero mancare dal vostro repository. In questo caso, cercare nel paragrafo sottostante dedicato alle Distribuzioni vecchie e non convenzionali.

Passa al paragrafo Compilare FreeCAD

Debian e Ubuntu
Su sistemi Debian-based (Debian, Ubuntu, Mint, etc...) è abbastanza facile ottenere tutte le dipendenze che devono essere installate. La maggior parte delle librerie sono disponibili tramite apt-get o il gestore dei pacchetti synaptic.

If you already installed FreeCAD from the official repositories, you can install its build dependencies with this single line of code in a terminal:

This command may install the wrong libraries, so please verify that you have installed the following packages.

These packages are essential for any sort of compilation to succeed:
 * , installs the C and C++ compilers and C libraries.
 * , essential tool to configure the source of FreeCAD.
 * , essential tools to produce shared libraries.

Scripting in FreeCAD uses the Python language, so it needs to be installed:
 * or
 * or

The Coin libraries need to be installed:
 * for Debian Jessie, Stretch, Ubuntu 16.04 to 18.10, or
 * for Debian Buster, Ubuntu 19.04 and newer, as well as for Ubuntu 18.04/18.10 with the freecad-stable/freecad-daily PPAs added to your software sources.

The Boost libraries need to be installed:

Some utilities needs to be installed:
 * , to report the system used.
 * , to integrate C++ code with Python.

Several libraries that deal with mathematics, computer vision, triangulated surfaces, meshes, cartographic projection, 3D visualization, XML parsing, Zip file reading, and the X11 Window system need to be installed:
 * or
 * or
 * or
 * or
 * or
 * or
 * or
 * or

Python 2 and Qt4
To compile FreeCAD for Debian Jessie, Stretch, Ubuntu 16.04, using Python 2 and Qt4, install the following dependencies. This is not recommended anymore as both Python 2 and Qt4 are obsolete and will disappear from future Linux distributions.

Python 3 and Qt5
To compile FreeCAD for Debian Buster, Ubuntu 19.04 and newer, as well as Ubuntu 18.04/18.10 with the freecad-stable/freecad-daily PPAs added to your software sources, install the following dependencies.
 * or
 * or
 * or

OpenCascade kernel
The OpenCascade kernel is the core graphics library to create 3D shapes. It exists in an official version OCCT, and a community version OCE. The community version is no longer recommended, as it's outdated.

For Debian Buster and Ubuntu 18.10 and newer, as well as Ubuntu 18.04 with the freecad-stable/freecad-daily PPAs added to your software sources, install the official packages.

For Debian Jessie, Stretch, Ubuntu 16.04 and newer, install the community edition packages.

Notare che liboce*-dev include le seguenti librerie:

Opzionalmente è anche possibile installare questi pacchetti extra:
 * , to make Coin support additional image file formats.
 * and, if you intend to generate source code documentation.
 * , for 3Dconnexion devices support, like the Space Navigator or Space Pilot.
 * , to register your installed files into your system's package manager, so you can uninstall it later.

Single command for Python 3 and Qt5
Requires Pyside2 available in Debian buster and the freecad-stable/freecad-daily PPAs.

Single command for Python 2 and Qt4
Gli utenti di Ubuntu 16.04  vedano anche queste ulteriori instruzioni.

Fedora
Sono necessari i seguenti pacchetti:


 * 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

(if coin2 is the latest available for your version of Fedora, use packages from http://www.zultron.com/rpm-repo/)
 * soqt-devel
 * freetype
 * freetype-devel

E opzionalmente:


 * libspnav-devel (for 3Dconnexion devices support like the Space Navigator or Space Pilot)
 * pivy ( https://bugzilla.redhat.com/show_bug.cgi?id=458975 Pivy non è obbligatorio, ma è necessario per il modulo Draft )

Gentoo
Il modo più semplice per controllare quali pacchetti sono necessari per compilare FreeCAD è quello di verificare tramite Portage:

emerge -pv freecad

Questo dovrebbe dare una bella lista di pacchetti extra che è necessario installare sul proprio sistema.

If FreeCAD is not available on portage, it is available on the waebbl overlay. The issue tracker on the waebbl overlay Github may help guide through some issues you may come across. The overlay provides freecad-9999, which you can choose to compile, or simply use to get the dependencies.

layman -a waebbl

Tumbleweed
The following commands will install the packages required for building FreeCAD with Qt5 and Python 3.

The following command will install Qt Creator and the GNU Project Debugger.

If any packages are missing, then you can check the Tumbleweed "FreeCAD.spec" file on the Open Build Service.

Also, check to see if there are any patches you need to apply (such as 0001-find-openmpi2-include-files.patch).

Leap
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

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. Beware that some of them might have a slightly different package name in your distribution (such as name, libname, name-dev, name-devel, etc...).

You also need the GNU gcc compiler version equal or above 3.0.0. g++ is also needed because FreeCAD is completely written in C++. During the compilation some Python scripts get executed. So the Python interpreter has to work properly. To avoid any linker problems during the build process it is also a good idea to have the library paths either in your LD_LIBRARY_PATH variable or in your ld.so.conf file. This is normally already the case in recent distributions.

For more details have also a look to README.Linux in your sources.

Pivy
Pivy is not needed to build FreeCAD or to run it, but it is needed for the Draft module to work. If you are not going to use that module, you won't need pivy. By November 2015 the obsolete version of Pivy included with FreeCAD source code will no longer compile on many systems, due to its age. If you cannot find Pivy in your distribution's packages repository or elsewhere, you can compile pivy yourself, see Pivy compilation instructions.

Compilare FreeCAD
FreeCAD uses CMake as its main build system. CMake is a build system 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 configures the build system 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 produces the FreeCAD executable.

Poiché FreeCAD è un'applicazione pesante, la compilazione può richiedere un po' di tempo (circa 10 minuti su una macchina veloce, 30 minuti, o più, su una lenta)

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

Costruzione Out-of-source
Se intendete seguire la rapida evoluzione di FreeCAD, convenie costruire in una cartella separata (Out-of-source build). Ogni volta che il codice sorgente viene aggiornato, cMake riconosce intelligentemente i file che sono stati modificati e ricompila solo ciò che è necessario. La costruzione Out-of-source è particolarmente utile quando si utilizza il sistema Git, perché si può facilmente provare altri rami senza confondere il sistema di compilazione. Per costruire out-of-source, è sufficiente creare una cartella di generazione, distinta dalla cartella di origine FreeCAD, e, dalla cartella di compilazione, indirizzare CMake (o se si usa cmake-gui sostituire nel codice seguente "cmake" con "cmake-gui") verso la cartella di origine :

The option controls how many files are compiled in parallel; the  program prints the number of CPU cores in your system; using the latter program in the indicated manner will use all the cores in your system, except two, to compile the software. The FreeCAD executable will eventually appear in the directory.

Costruzione In-source
Se avete dei dubbi, a causa di suoi limiti, non fate una costruzione interna al sorgente, ma create una costruzione out-of-source, come spiegato nella sezione successiva. FreeCAD può essere costruito nel sorgente (in-source), il che significa che tutti i file risultanti dalla compilazione si trovano nella stessa cartella del codice sorgente. Questo va bene per "dare un'occhiata" a FreeCAD, e permette di rimuoverlo facilmente eliminando semplicemente la sua cartella. Quando si prevede di compilarlo spesso, si consiglia invece di fare una costruzione esterna al sorgente (out-of-source) perchè offre maggiori vantaggi. I seguenti comandi compilano FreeCAD:

In-source builds are fine if you are just looking at FreeCAD, and want to be able to remove it easily by just deleting that folder.

The following commands will compile FreeCAD:

The FreeCAD executable will then reside in the directory.

How to repair your source code directory after accidentally running an in-source build
If you accidentally performed a compilation inside the source code directory, and would like to restore the contents to only the original source code, you can perform the following steps.

The first line clears the 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. 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 file.

If you do not clear the source directory, subsequent runs of 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.

Where is the directory that contains the source code. The may be omitted in most cases. The space after the option may also be omitted.

For example, to avoid building the FEM module:

All possible variables are listed in the file, located in the  directory. In this file, search for the word to see all the variables that can be set and their default values.

Alternatively, use the command to list the current configuration, and thus all variables that can be changed (a big list). Below, we've listed some of the more relevant options you may want to use.

Per una Degug build
Create a build to troubleshoot crashes in FreeCAD. Beware that the Sketcher becomes very slow with complex sketches with a build.

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

Building against Qt5
By default, FreeCAD builds for Qt4. It is possible to build for Qt5 with the following option.

Building against Python 3 and Qt5
In a modern Linux distribution you only need to provide the path to the Python interpreter for the compilation system to be configured correctly.

Building for a specific Python version
By default your system may use Python 2, so CMake will try to configure the compilation of FreeCAD against this version. It is possible to choose a specific version of Python by specifying the desired Python executable.

If that doesn't work, you may have to define other variables with the required Python directories.

The locations and version numbers of your Python files and directories will depend on your particular distribution. Use to show the version of Python that you are using currently. Only the first two numbers are necessary; for example, if the result is, 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 command.

Also use in a terminal to determine the  or  directories.

Building with Qt Creator against Python 3 and Qt5
To compile in Qt Creator add the following to the bottom of.

Again, specify the correct paths and Python version that you want to use.

Go to and choose  to compile the graphical version of FreeCAD, or  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 to

and call

to create a Makefile.

Once that's done, run

to create a library. To make this library known to Qt Designer you have to copy the file to.

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.

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

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

Making a debian package
Se prevedete di costruire un pacchetto Debian indipendente dai sorgenti è necessario installare prima i seguenti pacchetti:

Per costruire un pacchetto, aprire una console, andare nella directory di FreeCAD e chiamare

Quando il pacchetto è costruito, è possibile utilizzare lintian per verificare se il pacchetto contiene errori

Note for 64bit systems
When building FreeCAD for 64-bit there is a known issue with the OpenCASCADE 64-bit package. To get FreeCAD running properly you might need to run the ./configure script with the additional define _OCC64 set:

For Debian based systems this workaround is not needed when using the prebuilt package because there the OpenCASCADE package is built to set internally this define. Now you just need to compile FreeCAD the same way as described above.

Script di build automatico
Ecco tutto quello che vi serve per una compilazione completa di FreeCAD. Si tratta di uno script di approccio e funziona su una distro di recente installazione. I comandi richiedono la password di root (per l'installazione di pacchetti) e talvolta di riconoscere un'impronta digitale per il server di un repository esterno o un repository https-subversion. Questi script dovrebbero funzionare su versioni a 32 e 64 bit. Essi sono scritti per diverse versioni, e dovrebbero essere eseguibili anche su versioni successive, con o senza grandi cambiamenti.

Se disponete di uno script per la vostra distribuzione preferita, siete pregati di inviarlo! Noi lo incorporeremo in questo articolo.

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 FreeCAD Ubuntu PPA repositories, and should work on any version of Ubuntu targeted by the PPA. The 'daily' PPA targets recent versions of Ubuntu, and the 'stable' PPA targets all officially supported versions of Ubuntu.

This script installs dependencies for the daily development snapshot of FreeCAD.

This script installs dependencies for the latest stable release of FreeCAD. (For Ubuntu 12.04, omit "--enable-source" from the add-apt-repository command.)

(These scripts also install the PPA build of FreeCAD itself, as a side effect. You could then uninstall that while leaving the dependencies in place. However, leaving it installed will enable the package manager to keep the set of dependencies up to date, which is useful if you are following the development for a long time.)

After installing the dependencies, please see the generic instructions for getting the source code, running CMake, and compiling. The following script is an example of one way to do this.

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

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

Fedora 27/28/29
Posted by user [PrzemoF] in the forum.

{ echo "~/$MAIN_DIR already exist. Quitting.."; exit; } cd $MAIN_DIR git clone https://github.com/FreeCAD/FreeCAD.git mkdir $BUILD_DIR

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. . Optionally change directory eg..
 * 2) Clone the AUR repository :
 * 3) Enter AUR repository folder :
 * 4) Compile using Arch makepkg : . The -s or --syncdeps flag will also install required dependencies.
 * 5) Install created package : 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 inside the folder.

Aggiornare il codice sorgente
Lo sviluppo di FreeCAD è veloce, quasi ogni giorno ci sono correzioni di bug o nuove funzionalità. Il sistema cmake consente di aggiornare il codice sorgente in modo intelligente e di ricompilare solo ciò che è cambiato, con delle compilazioni successive molto veloci. Con git o subversion è molto semplice aggiornare il codice sorgente:

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.

Then move into the build directory where the code was compiled initially, and run again. In this case do not specify the path to the source code, just specify the present directory (denoted by a dot).

To use all CPU cores for compilation use

Link
Vedere anche Velocizzare la compilazione Come velocizzare la compilazione di FreeCAD