Compiling (Speeding up): Difference between revisions

From FreeCAD Documentation
(Marked this version for translation)
(Marked this version for translation)
 
(21 intermediate revisions by 6 users not shown)
Line 1: Line 1:
<languages/>
<languages/>
<translate>
<translate>

<!--T:8-->
<!--T:8-->
{{Docnav
{{Docnav|CompileOnMac|Third Party Libraries}}
|[[FreeCAD_Docker_CLI_mode|FreeCAD Docker CLI mode]]
|[[Third_Party_Libraries|Third Party Libraries]]
}}

</translate>
{{TOCright}}
<translate>

==Overview== <!--T:15-->


<!--T:1-->
<!--T:1-->
FreeCAD is a large application that may take from 10 minutes to one hour to compile completely from source. This depends primarily on the CPU that you have, and the number of cores that are used in the compilation process. Here are some tips to shorten that process and make build times shorter.
FreeCAD is a large application that may take from 10 minutes to one hour to compile completely from source. This depends primarily on the CPU that you have, and the number of cores that are used in the compilation process. Here are some tips to shorten that process and make build times shorter.


== CCache == <!--T:2-->
== CCache == <!--T:16-->

<!--T:2-->
Install {{incode|ccache}} to cache builds.
Install {{incode|ccache}} to cache builds.


== Disable modules == <!--T:3-->
<!--T:17-->
[https://ccache.dev/ Ccache] speeds up recompilation by caching previous compilations and detecting when the same compilation is done again. Ccache is free software, released under GPLv3 or later.

<!--T:23-->
On most systems ccache will be automatically detected and enabled, you can use the {{incode|FREECAD_USE_CCACHE}} {{incode|cmake}} option to control this behavior.

== Disable modules == <!--T:18-->

<!--T:3-->
When using {{incode|cmake}} to configure the build, you can disable the compilation of certain workbenches that you may not need at the moment. This is useful if you only need to test a few workbenches.
When using {{incode|cmake}} to configure the build, you can disable the compilation of certain workbenches that you may not need at the moment. This is useful if you only need to test a few workbenches.


<!--T:10-->
<!--T:10-->
For example, to avoid building the FEM and Mesh workbenches:
For example, to avoid building the FEM and Mesh workbenches:

</translate>
{{Code|code=
{{Code|code=
cmake -DBUILD_FEM=OFF -DBUILD_MESH=OFF ../freecad-source
cmake -DBUILD_FEM=OFF -DBUILD_MESH=OFF ../freecad-source
}}
}}
<translate>


<!--T:11-->
<!--T:11-->
Use {{incode|cmake-gui}}, {{incode|cmake-curses-gui}}, or {{incode|cmake-qt-gui}} to display all the possible variables that can be edited in the configuration; using these interfaces you can easily switch on or off different workbenches.
Use {{incode|cmake-gui}}, {{incode|cmake-curses-gui}}, or {{incode|cmake-qt-gui}} to display all the possible variables that can be edited in the configuration; using these interfaces you can easily switch on or off different workbenches.


== Number of jobs in parallel == <!--T:4-->
== Number of jobs in parallel == <!--T:19-->

<!--T:4-->
After configuring with {{incode|cmake}}, the {{incode|make}} program launches the actual C++ compiler to work on the source code files. You can speed up compilation by working on various files at the same time. This is achieved with the {{incode|-j}} option of {{incode|make}}, which denotes the number of "jobs" or compilation commands that are run simultaneously. This option is an integer number.
After configuring with {{incode|cmake}}, the {{incode|make}} program launches the actual C++ compiler to work on the source code files. You can speed up compilation by working on various files at the same time. This is achieved with the {{incode|-j}} option of {{incode|make}}, which denotes the number of "jobs" or compilation commands that are run simultaneously. This option is an integer number.


Line 36: Line 61:
<!--T:13-->
<!--T:13-->
Compile as many files in parallel as the number of CPU cores in your system. This is useful if you have many cores and want to use them all to compile the software.
Compile as many files in parallel as the number of CPU cores in your system. This is useful if you have many cores and want to use them all to compile the software.

</translate>
</translate>
{{code|code=
{{code|code=
Line 44: Line 70:
<!--T:14-->
<!--T:14-->
Compile as many files in parallel as the number of CPU cores in your system, minus two. Use this so that your system is still responsive to do some other task; for example, two cores will allow you to use a browser, while the rest of the cores keep compiling the software on the background.
Compile as many files in parallel as the number of CPU cores in your system, minus two. Use this so that your system is still responsive to do some other task; for example, two cores will allow you to use a browser, while the rest of the cores keep compiling the software on the background.

</translate>
</translate>
{{code|code=
{{code|code=
Line 50: Line 77:
<translate>
<translate>


== distcc == <!--T:7-->
== distcc == <!--T:20-->

<!--T:7-->
The {{incode|distcc}} program can be used to perform distributed compilation of C and C++ code across several machines in a network.
The {{incode|distcc}} program can be used to perform distributed compilation of C and C++ code across several machines in a network.


<!--T:5-->
<!--T:21-->
[https://www.distcc.org/ Distcc] should always generate the same results as a local compilation. It is free, simple to install and use, and often two or more times faster than compiling locally.
{{Docnav|CompileOnMac|Third Party Libraries}}


<!--T:9-->
<!--T:22-->
FreeCAD dev 'etrombly' has published a short explanation on [https://forum.freecadweb.org/viewtopic.php?f=4&t=50810&p=459142#p458614 how to install distcc to compile FreeCAD on a network of computers using Docker].
{{Userdocnavi}}



<!--T:6-->
<!--T:5-->
[[Category: Developer Documentation]]
{{Docnav
|[[FreeCAD_Docker_CLI_mode|FreeCAD Docker CLI mode]]
|[[Third_Party_Libraries|Third Party Libraries]]
}}


</translate>
</translate>
{{Userdocnavi{{#translation:}}}}
{{clear}}
[[Category:Developer_Documentation{{#translation:}}]]
[[Category:Developer{{#translation:}}]]

Latest revision as of 14:55, 23 July 2023

Overview

FreeCAD is a large application that may take from 10 minutes to one hour to compile completely from source. This depends primarily on the CPU that you have, and the number of cores that are used in the compilation process. Here are some tips to shorten that process and make build times shorter.

CCache

Install ccache to cache builds.

Ccache speeds up recompilation by caching previous compilations and detecting when the same compilation is done again. Ccache is free software, released under GPLv3 or later.

On most systems ccache will be automatically detected and enabled, you can use the FREECAD_USE_CCACHE cmake option to control this behavior.

Disable modules

When using cmake to configure the build, you can disable the compilation of certain workbenches that you may not need at the moment. This is useful if you only need to test a few workbenches.

For example, to avoid building the FEM and Mesh workbenches:

cmake -DBUILD_FEM=OFF -DBUILD_MESH=OFF ../freecad-source

Use cmake-gui, cmake-curses-gui, or cmake-qt-gui to display all the possible variables that can be edited in the configuration; using these interfaces you can easily switch on or off different workbenches.

Number of jobs in parallel

After configuring with cmake, the make program launches the actual C++ compiler to work on the source code files. You can speed up compilation by working on various files at the same time. This is achieved with the -j option of make, which denotes the number of "jobs" or compilation commands that are run simultaneously. This option is an integer number.

Run four compilation commands in parallel:

make -j4

Compile as many files in parallel as the number of CPU cores in your system. This is useful if you have many cores and want to use them all to compile the software.

make -j$(nproc)

Compile as many files in parallel as the number of CPU cores in your system, minus two. Use this so that your system is still responsive to do some other task; for example, two cores will allow you to use a browser, while the rest of the cores keep compiling the software on the background.

make -j$(nproc --ignore=2)

distcc

The distcc program can be used to perform distributed compilation of C and C++ code across several machines in a network.

Distcc should always generate the same results as a local compilation. It is free, simple to install and use, and often two or more times faster than compiling locally.

FreeCAD dev 'etrombly' has published a short explanation on how to install distcc to compile FreeCAD on a network of computers using Docker.