Compile on Windows/it: Difference between revisions

From FreeCAD Documentation
No edit summary
No edit summary
Line 171: Line 171:
|}
|}


== Costruzione di FreeCAD ==
== Build di FreeCAD ==


<div class="mw-translate-fuzzy">
<div class="mw-translate-fuzzy">

Revision as of 09:38, 26 December 2022

Questa pagina spiega passo dopo passo come compilare FreeCAD 0.19 o più recente su Windows utilizzando il compilatore MSVC di Microsoft. Per informazioni sull'utilizzo di MSYS2/MinGW, vedere Compilare su MinGW. Per altre piattaforme vedere Compilazione.

Prerequisiti

La compilazione di FreeCAD su Windows richiede diversi strumenti e librerie.

Programmi richiesti

  • Un compilatore. FreeCAD è testato con Visual Studio (MSVC): altri compilatori potrebbero funzionare, ma le istruzioni per l'uso non sono incluse qui. Per maggiori dettagli, vedere la sezione Compilatore di seguito.
  • Git (Sono disponibili anche frontend GUI per Git, vedere la sezione successiva.)
  • CMake versione 3.11.x o successiva.
    Suggerimento: Scegliendo l'opzione Add CMake to the system PATH for all users durante l'installazione di CMake renderà CMake accessibile dal prompt dei comandi di Windows, il che può essere utile.
  • Il LibPack. Questo è un singolo pacchetto contenente tutte le librerie necessarie per compilare FreeCAD su Windows. Scaricare la versione del LibPack che corrisponde alla versione di FreeCAD che si desidera compilare. Per compilare FreeCAD 0.20 scaricare il LibPack versione 2.6, per FreeCAD 0.19 scaricare il /releases/tag/1.0 LibPack versione 1.0. Estrarre il LibPack in una posizione comoda. (Se il tuo computer non riconosce l'estensione .7z, installare il programma 7-zip.)
    Nota: Si consiglia caldamente di compilare FreeCAD con la versione del compilatore per cui è progettato il LibPack. Ad esempio, si potrebbero riscontrare problemi durante la compilazione di FreeCAD 0.20 utilizzando MSVC 2017 perché il LibPack è progettato per essere compilato con MSVC 2019 o versioni successive.
    Per aggiornare il LibPack in un secondo momento, consultare la sezione Aggiornamento del Libpack.

Programmi opzionali

  • Un frontend GUI per Git. Ci sono diversi frontend disponibili, vedi this list. Il vantaggio principale di un frontend è che non devi imparare i comandi Git per ottenere il codice sorgente di FreeCAD o per inviare patch al repository GitHub di FreeCAD.

Di seguito descriviamo la gestione del codice sorgente usando il frontend TortoiseGit. Questo frontend si integra direttamente in Windows con Esplora file e dispone di una grande comunità di utenti per ricevere assistenza in caso di problemi.

  • NSIS viene utilizzato per generare il programma di installazione di Windows di FreeCAD.

Codice sorgente

Ora puoi ottenere il codice sorgente di FreeCAD:

Utilizzo di un frontend

Quando si utilizza il Git frontend TortoiseGit:

  1. Crea una nuova cartella in cui verrà scaricato il codice sorgente.
  2. Fare clic con il tasto destro su questa cartella in Esplora file di Windows e selezionare nel menu contestuale Git Clone.
  3. Apparirà una finestra di dialogo. In esso, inserisci l'URL per il repository Git di FreeCAD

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

e clicca OK.

L'ultimo codice sorgente verrà scaricato dal repository Git di FreeCAD e la cartella verrà tracciata da Git.

Usando la riga di comando

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

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

Compilatore

Il compilatore predefinito (consigliato) è MS Visual Studio (MSVC). Sebbene sia possibile utilizzare altri compilatori, ad esempio gcc tramite Cygwin o MinGW, questi non sono testati o esaminati qui.

È possibile ottenere una versione gratuita di MSVC (per uso individuale) scaricando l'Community edition di MS Visual Studio.

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

Nota: Sebbene l'edizione Community di MSVC sia gratuita, per utilizzare l'IDE per un periodo di prova superiore a 30 giorni è necessario creare un account Microsoft. Se compilerai solo utilizzando la riga di comando, non avrai bisogno dell'IDE e quindi nessun account Microsoft.

Come IDE alternativo gratuito e OpenSource puoi usare KDevelop. Puoi usare KDevelop per modificare e scrivere codice C ++ ma devi usare la riga di comando per compilare.

Optional System Path Configuration

programmi in queste cartelle dalla riga di comando / powershell o se si desidera trovare programmi speciali da parte del compilatore o di CMake. Oltre a ciò, potrebbe essere necessario aggiungere cartelle al PERCORSO se non si sono utilizzate le opzioni corrispondenti durante l'installazione del programma.

  • Puoi includere la cartella del tuo LibPack nella variabile PATH del tuo sistema. Ciò è utile se prevedi di creare più configurazioni / versioni di FreeCAD.
  • Se non hai utilizzato l'opzione per aggiungere CMake al PERCORSO durante l'installazione, aggiungi la sua cartella di installazione

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

  • Se non hai utilizzato l'opzione per aggiungere TortoiseGit al PERCORSO durante l'installazione, aggiungi la sua cartella di installazione

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

Per aggiungere percorsi di cartelle alla variabile PATH:

  1. Nel menu Start di Windows, fai clic con il pulsante destro del mouse su "Computer" e scegli "Proprietà".
  2. Nella finestra di dialogo visualizzata, fai clic su "Impostazioni di sistema avanzate".
  3. Si aprirà un'altra finestra di dialogo. Fare clic lì nella scheda Avanzate in Variabili d'ambiente.
  4. Ancora una volta si aprirà un'altra finestra di dialogo. Seleziona quindi la variabile Percorso e fai clic su Modifica.
  5. E di nuovo si aprirà un'altra finestra di dialogo. Fai clic su Nuovo e aggiungi al percorso la cartella di Git o LibPack.
  6. Infine premi OK e chiudi tutte le finestre di dialogo premendo anche OK.

Configurazione

Una volta che hai tutti gli strumenti, le librerie e il codice sorgente di FreeCAD necessari, sei pronto per iniziare il processo di configurazione e compilazione. Questo processo procederà in cinque fasi:

  1. Eseguire CMake una prima volta per esaminare il tuo sistema e iniziare l'avanzamento della configurazione (verrà segnalato che l'operazione non è riuscita).
  2. Aggiustare le impostazioni CMake necessarie per configurare i percorsi del LibPack e abilitare Qt5.
  3. Rieseguire CMake per finalizzare la configurazione (questa volta dovrebbe riuscire).
  4. Utilizzare CMake per generare il sistema di compilazione di Visual Studio.
  5. Utilizzare Visual Studio per creare FreeCAD.

CMake

Inizialmente configurare l'ambiente di compilazione utilizzando CMake:

  1. Aprire la GUI di CMake
  2. Specificare la cartella di origine di FreeCAD.
  3. Specificare una cartella di compilazione (non utilizzare la cartella di origine: CMake creerà questa cartella se non esiste).
  4. Faire clic su Configura.
  5. Nella finestra di dialogo, che appare, specificare il generatore, che si desidera utilizzare: nella maggior parte dei casi verranno utilizzate le impostazioni predefinite in questa finestra di dialogo. Per lo standard MS Visual Studio utilizzare Visual Studio xx 2yyy dove xx è la versione del compilatore e 2yyy l'anno del suo rilascio. Si consiglia di utilizzare l'opzione predefinita Use default native compilers.

Nota: È importante specificare la variante di bit corretta. Se hai la variante a 64 bit di LibPack devi usare anche il compilatore x64.

Questo avvierà la configurazione e fallirà a causa delle impostazioni mancanti. Questo è normale, non hai ancora specificato la posizione del LibPack. Tuttavia, potrebbero verificarsi altri errori che richiedono ulteriori azioni da parte tua.

Se non riesce con il messaggio che Visual Studio non è stato trovato, il supporto CMake in MSVC non è ancora installato. Per farlo:

  1. Aprire l'IDE MSVC
  2. Utilizzare il menu Strumenti → Ottieni strumenti e funzionalità
  3. Nella scheda Workloads abilita Desktop development with C++
  4. Sul lato destro ora dovresti vedere il messaggio, che il componente Visual C++ tools for CMake verrà installato.
  5. Installarlo.

Se fallisce con un messaggio relativamente alla versione Python errata o Python mancante, allora:

  1. Usare la casella "Search:" in CMake per cercare la stringa "Python"
  2. Se vedi un percorso come C:/Program Files/Python38/python.exe, CMake ha individuato che Python è già installato sul tuo PC, ma che quella versione non è compatibile con il LibPack. Poiché il LibPack include una versione compatibile di Python, modificare le seguenti impostazioni Python in CMake nei suoi percorsi (supponendo che il LibPack si trovi nella cartella D:\FreeCAD-build\FreeCADLibs_12.5.2_x64_VC17):

Se non appaiono errori da Visual Studio o da Python, va tutto bene, ma CMake non conosce ancora tutte le impostazioni necessarie. Pertanto successivamente:

  1. Cercare in CMake la variabile FREECAD_LIBPACK_DIR e specificare la posizione della cartella LibPack, che è stata scaricata in precedenza.
  2. Solo se si sta compilando FreeCAD 0.19, cercare la variabile BUILD_QT5 e abilitare questa opzione.
  3. Fare di nuovo clic su Configure.

Ora non dovrebbero esserci errori. Se continui a riscontrare errori che non riesci a diagnosticare, visita le pagine Install/Compile forum sul sito Web del forum di FreeCAD. Se CMake ha terminato correttamente, cliccare su Generate. Fatto ciò si può chiudere CMake e avviare la compilazione di FreeCAD utilizzando Visual Studio. Tuttavia, per la prima compilazione, tenerlo aperto nel caso in cui si desideri o sia necessario modificare alcune opzioni per il processo di compilazione.

Nota: Durante la compilazione di FreeCAD 0.19, la variabile CMake BUILD_ENABLE_CXX_STD sarà impostata su C++14 mentre per FreeCAD 0.20 sarà impostata su C ++17. Questo perché FreeCAD 0.20 richiede almeno la versione 17 standard del linguaggio C++. Quindi, quando hai compilato l'ultima volta FreeCAD 0.19, è necessario eseguire nuovamente CMake per FreeCAD 0.20 per modificare lo standard del linguaggio C++.

Opzioni per il processo di compilazione

Il sistema di generazione CMake offre la flessibilità necessaria per il processo di creazione. Ciò significa che è possibile attivare e disattivare alcune funzionalità o moduli tramite le variabili CMake.

Ecco una descrizione di alcune di queste variabili:

Nome Variabile Descrizione Valore di Default
BUILD_XXX Fare il Build di FreeCAD con il componente XXX. Se non si vuole o non si ha bisogno di compilare ad es. l'ambiente OpenSCAD, disabilitare la variabile BUILD_OPENSCAD. FreeCAD quindi non avrà questo ambiente di lavoro.Nota: Alcuni componenti sono necessari per altri componenti. Se per esempio deselezioni BUILD_ROBOT CMake ti informerà che il componente Path non può essere compilato correttamente. Pertanto controlla l'output di CMake dopo aver modificato un'opzione BUILD_XXX! depends
BUILD_ENABLE_CXX_STD La versione standard del linguaggio C++. C++14 è il più alto possibile per FreeCAD 0.19 mentre almeno C++17 è richiesto per FreeCAD 0.20. Vedere anche la nota nella sezione Compilazione con Visual Studio 15 (2017) e 16 (2019) depends
BUILD_DESIGNER_PLUGIN Per creare il plug-in Qt Designer, consultare questa sezione di seguito OFF
BUILD_FLAT_MESH Necessaria per avere una build che includa la funzionalità CreateFlatMesh OFF
CMAKE_INSTALL_PREFIX La cartella di output durante la creazione della destinazione INSTALL, vedere anche la sezione Esecuzione e installazione di FreeCAD Cartella d'installazione del programma predefinita di Windows
FREECAD_COPY_DEPEND_DIRS_TO_BUILD Copia le librerie dipendenti necessarie per eseguire FreeCAD.exe nella cartella di compilazione. Vedere anche la sezione Esecuzione e installazione di FreeCAD.
Nota: le opzioni FREECAD_COPY_XXX appaiono solo se le librerie non sono già state copiate. Se si ha solo bisogno di aggiornare/passare a un'altra versione di LibPack, consultare la sezione Aggiornamento del LibPack. Se si desidera ripristinare le opzioni per qualche motivo, si deve eliminare tutte le cartelle nella cartella di compilazione, ad eccezione della cartella LibPack. In CMake cancellare la cache e avviare come se si dovesse compilare per la prima volta.
OFF
FREECAD_COPY_LIBPACK_BIN_TO_BUILD Copia i file binari LibPack necessari per eseguire FreeCAD.exe nella cartella di compilazione. Vedere anche la sezione Esecuzione e installazione di FreeCAD. OFF
FREECAD_COPY_PLUGINS_BIN_TO_BUILD Copia i file del plugin di Qt necessari per eseguire FreeCAD.exe nella cartella di compilazione. Vedere anche la sezione Esecuzione e installazione di FreeCAD. OFF
FREECAD_LIBPACK_USE Attiva o disattiva l'utilizzo di FreeCAD LibPack. ON
FREECAD_LIBPACK_DIR Directory in cui si trova il LibPack. FreeCAD's source code folder
FREECAD_RELEASE_PDB Crea librerie di debug (*.pdb) anche per build di rilascio. Non influisce sulla velocità (come farebbe una vera build di debug) e può essere molto utile per individuare arresti anomali nel codice di FreeCAD. Nel caso in cui FreeCAD si arresti in modo anomalo, verrà creato un file crash.dmp che può essere caricato con MSVC e se si dispone dei file PDB corrispondenti più il codice sorgente di quella versione è possibile eseguire il debug attraverso il codice. Senza i file PDB non è possibile eseguire il debug del codice e tutto ciò che il debugger mostra è il nome della DLL in cui si è verificato il crash. ON
FREECAD_USE_MP_COMPILE_FLAG Aggiunge l'opzione /MP (multiprocessore) ai progetti di Visual Studio, abilitando accelerazioni nelle CPU multi-core. Questo può accelerare notevolmente le build sui processori moderni.
Nota: Se disattivi FREECAD_USE_PCH, la compilazione può sovraccaricare rapidamente lo spazio dell'heap, anche se hai 16 GB di RAM.
ON
FREECAD_USE_PCH Precompiles the headers per risparmiare tempo di compilazione. ON
FREECAD_USE_PYBIND11 Include la libreria PyBind11. Necessario avere una build che includa la funzionalità CreateFlatMesh.
Nota: dopo averla attivata si potrebbe ricevere un errore di configurazione. Basta configurare di nuovo e il problema dovrebbe scomparire.
OFF

Build di FreeCAD

A seconda del compilatore, il processo per la creazione di FreeCAD sarà leggermente diverso. Nelle sezioni seguenti sono descritti i flussi di lavoro noti. Se stai costruendo con Qt Creator, passa a Building with Qt Creator, altrimenti procedi direttamente:

Compilare con Visual Studio 15 2017, e Visual Studio 16 2019

Release Build

  1. Avvia l'IDE di Visual Studio. Questo può essere fatto premendo il pulsante Apri progetto nella GUI di CMake o facendo doppio clic sul file FreeCAD.sln che trovi nella cartella di compilazione.
  2. Nella barra degli strumenti dell'IDE MSVC assicurati di utilizzare per la prima compilation Release.
  3. C'è una finestra chiamata Solution Explorer. Essa elenca tutti i possibili target di compilazione.

Per compilare un FreeCAD pronto all'uso, compila la destinazione INSTALLA , vedi sezione Running and installing FreeCAD.

Se non ricevi errori, hai finito. Congratulazioni! Puoi uscire da MSVC o tenerlo aperto.

Note: FreeCAD 0.20 requires at least the C++ language standard version 17 but the 3rd-party component flann from the LibPack is not yet ready for this. Therefore you will get compilation errors for the target ReverseEngineering. To fix this, right-click on this target in the MSVC solution explorer and select in the context menu the last entry Properties. In the appearing dialog change the C++ Language Standard to ISO C++14. Finally build the target ALL_BUILD again.

Debug Build

For a debug build it is necessary that the Python is used that is included in the LibPack. To assure this:

  1. Search in the CMake GUI for "Python"
  2. If you see there a path like C:/Program Files/Python38/python.exe, CMake recognized the Python that is installed on your PC and not the one of the LibPack. In this case adapt these different Python settings in CMake to this (assuming the LibPack is in the folder D:\FreeCAD-build\FreeCADLibs_12.5.2_x64_VC17):

Now

  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 Debug.
  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 in the context menu.

This will now take quite a long time. If there were no compilation errors, you can start the debug build:

  1. Right-click on the target FreeCADMain and then choose Set as Startup Project in the context menu.
  2. Finally click in the toolbar on the button with the green triangle named Local Windows Debugger.

This will start the debug build of FreeCAD and you can use the MSVC IDE to debug it.

Video Resource

An English language tutorial that begins with configuration in CMake Gui and continues to the `Build` command in Visual Studio 16 2019 is available unlisted on YouTube at Tutorial: Build FreeCAD from source on Windows 10.

Costruire con Qt Creator (obsoleto)

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

I passaggi su come compilare dalla riga di comando dipendono dal compilatore. Per MSVC 2017 i passaggi sono:

  1. Nel menu Start di Windows vai a Visual Studio 2017 → Visual Studio Tools e scegli Prompt dei comandi per sviluppatori per VS 2017
  2. Passa alla tua cartella di build.
  3. Eseguire il comando
msbuild ALL_BUILD.vcxproj /p:Configuration=Release

o

msbuild INSTALL.vcxproj /p:Configuration=Release

Questi passaggi possono anche essere automatizzati. Ecco ad esempio una soluzione per MSVC 2017:

  1. Scarica lo script compile-FC.txt.
  2. Rinominalo in compile-FC.bat
  3. In Esplora file Shift di Winddows + Fare clic con il tasto destro del mouse sulla cartella di creazione e utilizzare dal menu di scelta rapida "Prompt dei comandi qui".
  4. Eseguire il comando
compile-FC install

Invece di chiamare compile-FC con l'opzione installa puoi anche usare debug o release:

debug   - compila FreeCAD nella configurazione di debug

release - compilare FreeCAD nella configurazione della versione

install    - compilare FreeCAD nella configurazione di rilascio e creare un'installazione di installazione

Esecuzione e installazione di FreeCAD

Esistono 2 metodi per eseguire FreeCAD compilato:

Metodo 1: Esegui FreeCAD.exe che trovi nella cartella di compilazione nella sottocartella bin

Metodo 2: costruisci il target INSTALL

Il metodo 2 è quello più semplice perché assicura automaticamente che tutte le librerie necessarie per eseguire FreeCAD.exe siano nella cartella corretta. FreeCAD.exe e le librerie verranno emessi nella cartella specificata nella variabile CMakeCMAKE_INSTALL_PREFIX.

Per il Metodo 1 devi mettere le librerie nella cartella bin della tua cartella di build (dove si trova FreeCAD.exe). Questo può essere fatto facilmente:

  1. Apri la GUI di CMake.
  2. Cerca lì l'opzione variabile FREECAD_COPY_DEPEND_DIRS_TO_BUILD e controllala. Se non esiste tale opzione, le librerie sono già state copiate, vedere la descrizione delle opzioni
  3. Cerca lì l'opzione variabile FREECAD_COPY_LIBPACK_BIN_TO_BUILD e controllala.
  4. Cerca lì l'opzione variabile "FREECAD_COPY_PLUGINS_BIN_TO_BUILD" e controllala.
  5. Fare clic su Configura. Al termine della configurazione CMake copierà automaticamente le librerie necessarie dalla cartella LibPack.

Troubleshooting

When running FreeCAD you may encounter missing DLLs when using certain workbenches or features of workbenches. The error message in FreeCAD's console will not tell you what DLL is missing. To find this out you must use an external tool:

import os
os.system(r"~\DependenciesGui.exe")

Note: Instead of the ~ you must specify the full path to the DependenciesGui.exe on your system.

  • Now drag in the *.pyd file of the workbench with which you get missing DLLs reported.

Aggiornamento della build

FreeCAD è sviluppato molto attivamente. Pertanto il suo codice sorgente cambia quasi quotidianamente. Nuove funzionalità vengono aggiunte e i bug corretti. Per beneficiare di queste modifiche al codice sorgente, è necessario ricostruire FreeCAD. Questo avviene in due fasi:

  1. Aggiornamento del codice sorgente
  2. Ricompilazione

Aggiornamento del codice sorgente

Usando un frontend

Quando si utilizza il Git frontend TortoiseGit:

  1. Fare clic con il tasto destro del mouse sulla cartella del codice sorgente di FreeCAD in Esplora file di Windows e selezionare nel menu di scelta rapida 'Pull' .
  2. Apparirà una finestra di dialogo. Seleziona lì quale ramo di sviluppo vuoi ottenere. master è il ramo principale. Pertanto utilizzare questo a meno che non si desideri compilare una nuova funzionalità speciale da un ramo che non è stato ancora unito a "master". (Per ulteriori informazioni sui rami Git, vedere Git development process.)

Finalmente clicca OK.

Utilizzando la riga di comando

Apri un terminale (prompt dei comandi) e passa alla directory di origine. Quindi digitare:

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

dove master è il nome del ramo di sviluppo principale. Se vuoi ottenere il codice da un altro ramo, usa il suo nome invece di master.

Ricompilazione

  1. Apri l'IDE MSVC facendo doppio clic sul file FreeCAD.sln o sul file ALL_BUILD.vcxproj nella cartella di compilazione.
  2. Continua con il passaggio 2 dalla sezioneBuilding with Visual Studio 15 2017.

Aggiornamento del Libpack

If a new major version of a third-party dependency like Open Cascade is released, or if a third-party dependency has important bug fixes, a new LibPack is released. You can find the latest version here.

To update your LibPack the following recipe is best practice:

  1. Delete the bin folder in your build folder.
  2. Switch to your local LibPack folder and delete everything there.
  3. Extract the content of the new LibPack ZIP file into the existing, but now empty, local LibPack folder.
  4. Open CMake and there press the button Configure and then the button Generate. This recreates the bin folder you just deleted and also copies the new LibPack files into it.
  5. In CMake click the button Open Project and the MSVC IDE will open.
  6. In the MSVC IDE build the target INSTALL.

Tools

In order to join the FreeCAD development you should compile and install the following tools:

Qt Designer plugin

FreeCAD uses Qt as toolkit for its user interface. All dialogs are setup in UI-files that can be edited using the program Qt Designer that is part of any Qt installation and also included in the LibPack. FreeCAD has its own set of Qt widgets to provide special features like adding a unit to input fields and to set preferences properties.

Compilation

The plugin cannot be loaded by the Qt Designer if it was compiled using another Qt version than the one your Qt Designer/Qt Creator is based on. Therefore the plugin must be compiled together with FreeCAD:

  • In the CMake options (see this section above) enable the option BUILD_DESIGNER_PLUGIN and reconfigure.
  • open MSVC and build the target FreeCAD_widgets

As result you will get the plugin file 'FreeCAD_widgets.dll in the folder
~\src\Tools\plugins\widget\Release

Installation

To install the plugin, copy it to either:

  • If you use the LibPack: to the folder
    ~\FreeCADLibs_12.5.4_x64_VC17\bin\designer
    Since there will only be a bin folder and you must first create the designer subfolder.
  • If you have a full Qt installation: you can choose between the folder
    C:\Qt\5.15.2\msvc2019_64\plugins\designer
    or
    C:\Qt\5.15.2\msvc2019_64\bin\designer (you must first create the designer subfolder.)
    (adapt the paths to your installation!).

Finally (re)start Qt Designer and check its menu Help → Plugins. If the plugin FreeCAD_widgets.dll is listed as being loaded, you can now design and change FreeCAD's .ui files. If not, you must compile the DLL by yourself.

If you prefer using Qt Creator instead of Qt Designer, the plugin file must be placed in this folder:
C:\Qt\Qt5.15.2\Tools\QtCreator\bin\plugins\designer
Then (re)start Qt Creator, switch to the mode Design and then check the menu Tools → Form Editor → About Qt Designer Plugins. If the plugin FreeCAD_widgets.dll is listed as being loaded, you can now design and change FreeCAD's .ui files. If not, you must compile the DLL by yourself.

Thumbnail Provider

FreeCAD has the feature to provide preview thumbnails for *.FCStd files. That means that in the Windows file explorer *.FCStd files are shown with a screenshot of the model it contains. To provide this feature, FreeCAD needs to have the file FCStdThumbnail.dll installed to Windows.

Installation

The DLL is installed this way:

  1. Download this ZIP file and extract it.
  2. Open a Windows command prompt with administrator privileges (these privileges are a requirement).
  3. Change to the folder where the DLL is.
  4. Execute this command
    regsvr32 FCStdThumbnail.dll
    

So check if it works, assure that in FreeCAD the preferences option Save thumbnail into project file when saving document is enabled and save a model. Then view in Windows Explorer the folder of the saved model using a symbol view. You should now see a screenshot of the model in the folder view.

Compilation

To compile the FCStdThumbnail.dll

  1. Change to the FreeCAD source folder
    ~\src\Tools\thumbs\ThumbnailProvider
  2. Open the CMake GUI
  3. Specify there as source folder the one you are currently in.
  4. Use the same folder as build folder.
  5. Click Configure
  6. In the appearing dialog, specify the generator according to the one you want to use. For the standard MS Visual Studio use Visual Studio xx 2yyy where xx is the compiler version and 2yyy the year of its release. It is recommended to use the default option Use default native compilers.
    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.
  7. Click on Generate.
  8. You should now have the file ALL_BUILD.vcxproj in the folder ~\src\Tools\thumbs\ThumbnailProvider. Double-click on it and the MSVC IDE will open.
  9. In the toolbar of the MSVC IDE assure that you use the compilation target Release.
  10. There is a window called Solution Explorer. Right-click there on ALL_BUILD and then choose Build.
  11. As result you should now have a FCStdThumbnail.dll in the folder ~\src\Tools\thumbs\ThumbnailProvider\release that you can install as described above.

Compiling Open Cascade

The LibPack comes with a version of Open Cascade that is suitable for general use. However, under some circumstances you may wish to compile against an alternate version of Open Cascade, such as one of their official releases, or a patched fork.

When compiling Open Cascade for FreeCAD note that there is no guarantee that FreeCAD will work with all versions of Open Cascade. Note also that when you are using the Netgen library, you must use the a NetGen version that it approved to compile with the Open Cascade version you like to compile.

To compile:

  • Then open the CMake GUI to configure the build system in a similar manner to building FreeCAD. These CMake options have to be set (or explicitly not set):
Variable name Description Default
3RDPARTY_DIR The path to 3rdparty components. It is recommended to use the folder as input where your used LibPack is. Explicitly leave this field empty. empty
3RDPARTY_DOXYGEN_EXECUTABLE The path to the executable of the 3rdparty component Doxygen. It is recommended to install Doxygen. CMake will then find it automatically. empty
3RDPARTY_FREETYPE_DIR The path to the necessary 3rdparty component Freetype. It is recommended to use the folder as input where your used LibPack is. empty
3RDPARTY_RAPIDJSON_DIR Only available if USE_RAPIDJSON is used. The path to the 3rdparty component RapidJSON. It is recommended NOT to use an existing LibPack folder as input. You can use the RapidJSOn folder from a LibPack, but copy it to a new folder and use this new folder as input. empty
3RDPARTY_TCL_DIR The path to the necessary 3rdparty component TCL. It is recommended NOT to use an existing LibPack folder as input. Take for example one of these releases, extract it and take this as input folder for CMake. empty
3RDPARTY_TK_DIR The path to the necessary 3rdparty component TK. It is recommended NOT to use an existing LibPack folder as input. Take for example one of these releases, extract it and take this as input folder for CMake. empty
3RDPARTY_VTK_DIR Only available if USE_VTK is used. The path to the necessary 3rdparty component VTK. It is recommended to use the folder as input where your used LibPack is. If you use another folder please assure that you don't use VTK 9.x or newer. empty
BUILD_RELEASE_DISABLE_EXCEPTIONS Disables exception handling for release builds. For FreeCAD you must set it to OFF. ON
INSTALL_DIR The output folder when building the target INSTALL. If the build was successful, take the files from this folder to update your LibPack. Windows default program installation folder
INSTALL_DIR_BIN The output subfolder for the DLL when building the target INSTALL. You must change it to bin win64/vc14/bin
INSTALL_DIR_LIB The output subfolder for the .lib files when building the target INSTALL. You must change it to lib win64/vc14/lib
USE_RAPIDJSON To compile Open Cascade with support for RapidJSON. Enabling this is mandatory in order to get support for the file format glTF. OFF
USE_VTK To compile Open Cascade with support for VTK. Enabling this is optimal. You can use this to build Open Cascade's VTK bridge. OFF
  • Open the project in Visual Studio and first build the ALL_BUILD and then INSTALL targets in the Release mode.
  • Repeat building the two targets in the Debug mode.

To build FreeCAD using the self-compiled Open Cascade, you must do the following:

  • Copy all folders from the INSTALL_DIR to your LibPack folder (overwrite the existing files)
  • Switch to the LibPack folder and go there to the subfolder cmake
  • Open there the file OpenCASCADEDrawTargets.cmake with a text editor
  • Search there for absolute paths to your LibPack folder and remove them. So e.g. the absolute path
    D:/FreeCADLibs_12.5.4_x64_VC17/lib/freetype.lib
    becomes just
    freetype.lib
  • Do the same for the file OpenCASCADEVisualizationTargets.cmake

Compiling Netgen

The LibPack comes with a version of Netgen that will was tested to be build with the Open Cascade version of the LibPack. The problem is that every new release of Netgen changes the API. Also every new release of Open Cascade does the same. Therefore one cannot just easily change the Netgen version.

However, you might build Netgen nevertheless. This is an easy task:

  • First obtain the Netgen source code, either directly from Netgen 's git repository.
  • Then open the CMake GUI to configure the build system in a similar manner to building FreeCAD. These CMake options have to be set:
Variable name Description Default
CMAKE_INSTALL_PREFIX The output folder when building the target INSTALL. If the build was successful, take the files from this folder to update your LibPack. C:/netgen
OpenCasCade_DIR The path to the CMake files of Open Cascade. If you built Open Cascade as described in the section Compiling Open Cascade you can use the subfolder cmake of there folder you used as INSTALL_DIR. If not, use the subfolder cmake of your LibPack. Note hereby that the LibPack must then already contain a proper Open Cascade build. Independent what folder you use, you must now also create there a subfolder lib and copy in the files freetype.lib and freetyped.lib from your LibPack. empty
USE_GUI set it to OFF ON
USE_NATIVE_ARCH set it to OFF; this is only necessary important to support older CPU that don't have the AVX2 instruction set ON
USE_OCC set it to ON OFF
USE_PYTHON set it to OFF ON
USE_SUPERBUILD set it to OFF ON
ZLIB_INCLUDE_DIR The path to the necessary 3rdparty component zlib. It is recommended to use the folder as input where your used LibPack is. empty
ZLIB_LIBRARY_DEBUG The path to the ZLib file zlibd.lib. It is located in the subfolder lib of your LibPack folder. empty
ZLIB_LIBRARY_RELEASE The path to the ZLib file zlib.lib. It is located in the subfolder lib of your LibPack folder. empty
  • Additionally you need to add a new CMake entry:

name: CMAKE_DEBUG_POSTFIX, type: string, content: _d
This assures that he file names of the debug libraries get another name than the release libraries and can later not be accidentally exchanged.

  • Press the Configure button in CMake to generate the *.cmake files.
  • Only necessary if older CPU should be supported that don't have the AVX2 instruction set:
    • Search your Netgen build folder for the file netgen-targets.cmake and open it with a text editor. Remove the setting ;/arch:AVX2 in the Option INTERFACE_COMPILE_OPTIONS.
    • Press the Configure button in CMake again.
  • Press the Generate button in CMake.
  • Open the project in Visual Studio and first build the ALL_BUILD and then INSTALL targets in the Release mode.
  • Repeat building the two targets in the Debug mode.

To build FreeCAD using the self-compiled Netgen, you must do the following:

  • Copy all folders from the CMAKE_INSTALL_PREFIX to your LibPack folder (overwrite the existing files)

Riferimenti