Compile on Windows/it

Questo articolo spiega passo dopo passo come compilare FreeCAD su Windows.

Prerequisiti
At first you must install the following required programs ad libraries:

Programmi richiesti

 * Git Ci sono una serie di alternative come GitCola, Tortoise Git, e altri.
 * CMake versione 2.x.x oppure Cmake 3.x.x
 * Python >2.5 (Questo è necessario solo se non si utilizza il Libpack. Il Libpack è dotato come minimo di Python(2.7.x) idoneo per compilare e eseguire FreeCAD)


 * CMake version 3.11.x - 3.14.x. Note: Usually one cannot take the latest CMake version. Therefore only use a CMake version in the range specified on this page!

It is recommended to use the option Add CMake to the system PATH for all users when installing CMake. Then you can later easily access CMake also from the command line/powershell.


 * LibPack (also called FreeCADLibs). This is a set of libraries necessary to compile FreeCAD on Windows. Depending on the FreeCAD version you want to compile, you must download the corresponding LibPack. For example to compile FreeCAD 0.18, download either the 32bit or the 64bit version of the LibPack for 0.18, to compile the latest development version 0.19, download the LibPack for 0.19 (there is only a 64bit version).

Just download the LibPack, you will unpack and set it up later.

Note: It is recommended to use the same compiler MS Visual Studio (MSVC) version the LibPack is designed for. This assures that the compilation and the execution of the compiled FreeCAD.exe succeeds. So you should for example be able to compile FreeCAD 0.18 using the LibPack for 0.19 and MSVC 15 but you you might get problems compiling FreeCAD 0.18 using the LibPack for 0.18 and MSVC 15 because the LibPack for 0.18 is designed to be built with MSVC 12.

Optional programs

 * Python 3.x. A separate python installation is not mandatory since the LibPack contains Python. However, to be able to test later your FreeCAD build it is useful to have a standalone Python installation. It is recommended to use not the latest version, but the prior version (e.g. not Python 3.7 but 3.6).


 * A GUI frontend for Git. There are several frontends available, see this list. The main benefit of a frontend is that you don't have to learn the Git commands to get the source code of FreeCAD or to send patches to the GitHub repository of FreeCAD.

In the following we describe source code handling using the frontend TortoiseGit. This frontend integrates directly to Windows file explorer and has a large user community to get help in case you have problems.


 * NSIS This is the program to generate the Windows installer of FreeCAD. (Information: For FreeCAD 0.17 and older the program WiX was used to create the installer.)

Codice sorgente
Now you can get the source code of FreeCAD:

Using a frontend
When using the Git frontend TortoiseGit:
 * 1) Create a new folder where the source code should be.
 * 2) Right-click on this folder in the Windows file explorer and select in the context menu Git Clone.
 * 3) A dialog will appear. Use there as URL for the FreeCAD repository

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

and click OK.

Now the source code is downloaded and its folder becomes a folder tracked by Git.

Usando Git (Preferito)
Per creare un ramo locale e scaricare il codice sorgente è necessario aprire un terminale (prompt dei comandi) e portarsi nella directory (cd) in cui si desidera creare il sorgente, quindi digitare:

Compilatore
In Windows, il compilatore di default è MS Visual Studio, sia che si tratti della versione Express oppure Completa 2008, 2012, o 2013.

You can get a free version of MSVC (for OpenSource usage) by downloading the Community edition of MS Visual Studio. To do so, use this URL

https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=Community&rel=xx

where xx is the version number. So to get MSVC 15 (calso called MSVC 2017), use this URL:

https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=Community&rel=15

Per chi vuole evitare l'installazione completa dell'ingombrante Visual Studio al solo scopo di avere un compilatore può vedere Compilare in Windows - Occupare meno spazio.

Note: Despite that the Community edition of MSVC is free, you must create a Microsoft account from withing the MSVC IDE that you can use the IDE for more than 30 days. If you will only compile using the command line, you don't need the IDE and thus no Microsoft account.

As free and OpenSource alternative IDE you can use KDevelop. You can use KDevelop to modify and write C++ code but must use the command line to compile.

System Path Configuration
All'interno del percorso di sistema assicurarsi di impostare i percorsi corretti per i seguenti programmi:
 * git (non tortoiseGit, ma git.exe) Serve a Cmake per aggiornare correttamente le informazioni "About FreeCAD" nel file version.h che consente a FreeCAD di riportare la versione corretta in About FreeCAD dal menu Aiuto.
 * Opzionalmente è possibile includere il Libpack nel percorso di sistema. Questo è utile se si prevede di costruire più configurazioni o versioni di FreeCAD, si dovranno copiare meno file, come spiegato più avanti nel processo di costruzione.


 * You can include the folder of your LibPack in your system PATH variable. This is useful if you plan to build multiple configurations/versions of FreeCAD.
 * If you did not use the option to add CMake to the PATH while installing it, add its installation folder

C:\Program Files\CMake\bin to the PATH.
 * If you did not use the option to add TortoiseGit to the PATH while installing it, add its installation folder

C:\Program Files\TortoiseGit\bin to the PATH.

Per aggiungere al percorso di sistema:

LibPack
At first you need to setup a build folder:
 * 1) Create a new folder where the compiled FreeCAD should be. It is highly recommended that this folder is not inside the source code folder of FreeCAD.
 * 2) Create there a new subfolder for the LibPack. Note: The name of this subfolder must be the same as the LibPack file name. If e.g. the LibPack has the filename FreeCADLibs_12.1.2_x64_VC15.7z, you must name the subfolder FreeCADLibs_12.1.2_x64_VC15.
 * 3) Extract the LibPack to this subfolder.

CMake
Il primo passo per creare FreeCAD con CMake è configurare l'ambiente. Là sono due modi per farlo:
 * Utilizzo di LibPack
 * Installare tutte le librerie necessarie e lasciare che CMake le trovi

Note: It is important to specify the correct bit variant. If you have the 64bit variant of LibPack you must also use the x64 compiler.

Questo inizierà la configurazione e dovrebbe fallire perché la posizione di FREECAD_LIBPACK_DIR è disinserito.
 * Espandi la categoria FREECAD e imposta FREECAD_LIBPACK_DIR nella posizione corretta
 * Check FREECAD_USE_EXTERNAL_PIVY
 * Facoltativamente Check FREECAD_USE_FREETYPE questo è necessario per utilizzare la funzionalità String di forma di Draft WB
 * Clic Configure ancora
 * Non ci dovrebbero essere errori
 * Clic Generate
 * Chiudi CMake
 * Copia cartella libpack\bin nella nuova cartella di creazione creata da CMake

If it fails with the message that Visual Studio could not be found the CMake support in MSVC is not yet installed. To do this:
 * 1)  Open the MSVC IDE
 * 2)  Use the menu Tools → Get Tools and Features
 * 3)  In the Workloads tab enable Desktop development with C++
 * 4) On the right side you should now see that the component Visual C++ tools for CMake will be installed.
 * 5) Install it.

If there is no error about Visual Studio, everything is fine, but CMake does not yet know all necessary settings. Therefore now:
 * 1) Assure that the search option Advanced is checked.
 * 2) Search in CMake for the variable FREECAD_LIBPACK_DIR and specify there the correct location to the LibPack folder.
 * 3) Search for the variable BUILD_QT5 and enable this option.
 * 4) Click Configure again

There should now be no errors. If so, click on Generate. After this is done you could close CMake and continue to start the compilation of FreeCAD. However, for the first compilation keep it open for the case that you want or need to change some options for the build process:

Opzioni per il processo di compilazione
Il sistema di build CMake ci offre molta più flessibilità durante il processo di costruzione. Questo significa possiamo attivare e disattivare alcune funzioni o moduli. È come la compilazione del kernel di Linux. Hai un sacco di opzioni per determinare il processo di compilazione.

Ecco la descrizione di alcuni di questi interruttori. Molto probabilmente cambieranno molto in futuro perché vogliamo aumentare la flessibilità di costruzione molto di più.

Note: Some components are required for other components. If you for example uncheck BUILD_ROBOT CMake will inform you that then the component Path cannot be compiled correctly. Therefore check the CMake output after you changed a BUILD_XXX option! || depends
 * CMAKE_INSTALL_PREFIX  || The output folder when building the target INSTALL, see also section Running and installing FreeCAD || Windows' default program installation folder
 * FREECAD_COPY_DEPEND_DIRS_TO_BUILD || Copies the LibPack libraries needed to execute the FreeCAD.exe to the build folder. See also section Running and installing FreeCAD. || OFF
 * FREECAD_COPY_LIBPACK_BIN_TO_BUILD || Copies the LibPack binaries needed to execute the FreeCAD.exe to the build folder. See also section Running and installing FreeCAD. || OFF
 * FREECAD_LIBPACK_USE || Switch the usage of the FreeCAD LibPack on or off || ON
 * FREECAD_LIBPACK_DIR || Directory where the LibPack is || FreeCAD's source code folder
 * FREECAD_RELEASE_PDB || Create debug libraries also for release builds || ON
 * }
 * FREECAD_LIBPACK_USE || Switch the usage of the FreeCAD LibPack on or off || ON
 * FREECAD_LIBPACK_DIR || Directory where the LibPack is || FreeCAD's source code folder
 * FREECAD_RELEASE_PDB || Create debug libraries also for release builds || ON
 * }
 * FREECAD_RELEASE_PDB || Create debug libraries also for release builds || ON
 * }

Costruzione di FreeCAD
A seconda della configurazione corrente, il processo di creazione di FreeCAD sarà leggermente diverso. Ciò è dovuto alle differenze nelle versioni software e software disponibili per ciascun sistema operativo.

Building with Visual Studio 15 2017

 * 1) Start the Visual Studio IDE. This can either be done by pressing the button Open Project in the CMake GUI or by double-clicking on the file FreeCAD.sln that you find in your build folder.
 * 2) In the toolbar of the MSVC IDE assure that you use for the first compilation Release.
 * 3) There is a window called Solution explorer. it lists all possible compilation targets.

To start a full compilation, right-click on the target ALL_BUILD and then choose Build. This will now take quite a long time.

To compile a ready-to use FreeCAD, compile the target INSTALL, see section Running and installing FreeCAD.

If you don't get any errors you are done. Congratulations! You can exit MSVC or keep it open.

Costruire con Visual Studio 12 2013
Assicurati di specificare Visual Studio 12 x64 (o il C-Compiler alternativo che stai utilizzando) come generatore in CMake prima di continuare.


 * Avviare Visual Studio 12 2013 facendo clic sull'icona del desktop creata durante l'installazione.

File → Open → Project/Solution
 * Apri il progetto da:


 * Aprire FreeCAD_Trunk.sln dalla cartella di creazione creata da CMake

Questo potrebbe richiedere del tempo a seconda del sistema
 * Passa al menu a discesa Configurazione soluzioni in alto a Rilascia X64


 * Build → Build Solution


 * Ci vorrà molto tempo ...

Se non ricevi errori, hai finito. Uscire da Visual Studio e avviare FreeCAD facendo doppio clic sull'icona di FreeCAD nella cartella bin della directory di build.

Installazione e configurazione di Qt Creator

 * Scarica e installa Qt Creator
 * Strumenti → Opzioni → Editor di testo → scheda Comportamento:
 * Codifica dei file → Codifiche predefinite:
 * Impostato su: ISO-8859-1 /...csISOLatin1 (Alcuni caratteri creano errori / avvertimenti con Qt Creator se lasciato impostato su UTF-8. Questo sembra risolverlo.)
 * Strumenti → Opzioni → Crea ed esegui:
 * Scheda CMake
 * Riempi la casella Eseguibile con il percorso di cmake.exe
 * Scheda Kit
 * Nome: MSVC 2008
 * Compilatore: Microsoft Visual C++ Compiler 9.0 (x86)
 * Debugger: rilevato automaticamente ...
 * Versione Qt: Nessuna
 * Scheda Generale
 * Deselezionare: crea sempre un progetto prima di distribuirlo
 * Deselezionare: distribuire sempre il progetto prima di eseguirlo

Importa progetto e crea

 * File → Apri file o progetto
 * Apri CMakeLists.txt che si trova nel livello più alto della fonte
 * Questo avvierà CMake
 * Scegli la cartella di costruzione e fai clic su Avanti
 * Imposta generatore su NMake Generator (MSVC 2008)
 * Clicca Esegui CMake. Segui le istruzioni illustrate sopra per configurare CMake a tuo piacimento.

Ora è possibile creare FreeCAD
 * Build → Build All
 * Ci vorrà molto tempo ...

Una volta completato, può essere eseguito: Ci sono 2 triangoli verdi in basso a sinistra. Uno è il debug. L'altro è eseguito. Scegli quello che vuoi.

Configurazione della riga di comando
The steps how to compile from the command line depends on the compiler. For MSVC 2017 the steps are:
 * 1) In Windows' start menu go to  and choose Developer Command Prompt for VS 2017
 * 2) Change to your build folder.
 * 3) Execute the command

or

Ecco un esempio su come creare FreeCAD dalla riga di comando:

Instead of calling compile-FC with the option install you can also use debug or release:

debug  - compile FreeCAD in debug configuration

release - compile FreeCAD in release configuration

install   - compile FreeCAD in release configuration and create an install setup

Running and installing FreeCAD
There are 2 methods to run the compiled FreeCAD:

Method 1: You execute the FreeCAD.exe that you find in your build folder in the subfolder bin

Method 2: You build the target INSTALL

Method 2 is the simpler one because it automatically assures that all libraries needed to run the FreeCAD.exe are in the correct folder. The FreeCAD.exe and the libraries will be output in the folder you specified in the CMake variable CMAKE_INSTALL_PREFIX.

For Method 1 you need to put the libraries into the bin folder of your build folder (where the FreeCAD.exe is). This can easily be done:
 * 1) Open the CMake GUI.
 * 2) Search there for the variable option FREECAD_COPY_DEPEND_DIRS_TO_BUILD and check it.
 * 3) Search there for the variable option FREECAD_COPY_LIBPACK_BIN_TO_BUILD and check it.
 * 4) Click on Configure. At the end of the configuration CMake will automatically copy the necessary libraries from the LibPack folder.

For FreeCAD 0.19 there is currently only one issue that requires manual action:
 * 1) Download the file qwindowsvistastyle.zip from the FreeCAD forum.
 * 2) Create a new subfolder named styles in the bin folder (where the FreeCAD.exe is).
 * 3) Extract the ZIP-file to this folder.

This adds the necessary style to make FreeCAD look like a normal Win 10 program. Otherwise it looks like in Windows 98.

Updating the build
FreeCAD is very actively developed. Therefore its source code changes almost daily. New features are added and bugs are fixed. To benefit from these source code changes, you must rebuild your FreeCAD. This is done in two steps:
 * 1) Updating the source code
 * 2) Recompilation

Using a frontend
When using the Git frontend TortoiseGit:
 * 1) Right-click on your FreeCAD source code folder in the Windows file explorer and select in the context menu Pull.
 * 2) A dialog will appear. Select there what development branch you want to get. master is the main branch. Therefore use this unless you want to compile a special new feature from a branch that has not yet been merged to master. (For more about Git branches, see Git development process.)

Finally click OK.

Using the command line
Open a terminal (command prompt) and switch there to your source directory. Then type:

where master the the name of the main development branch. If you want to get code from another branch, use its name instead of master.

Recompilation

 * 1) Open the MSVC IDE by double-clicking either on the file FreeCAD.sln or on the file ALL_BUILD.vcxproj in your build folder.
 * 2) Continue with step 2 from section Building with Visual Studio 15 2017.

Riferimenti

 * Vedere anche Compilare in Windows con Visual Studio 2013
 * Velocizzare la compilazione