Compiling (Speeding up): Difference between revisions

From FreeCAD Documentation
(Marked this version for translation)
No edit summary
(16 intermediate revisions by 5 users not shown)
Line 1: Line 1:
<languages/>
<translate>
<translate>
<!--T:8-->
{{Docnav
|[[FreeCAD Docker CLI mode|FreeCAD Docker CLI mode]]
|[[Third Party Libraries|Third-party libraries]]
}}
</translate>
{{TOCright}}
<translate>
==Overview== <!--T:15-->

<!--T:1-->
<!--T:1-->
When developing FreeCAD one needs to build from source and the compiling/build phase can start eating in to precious development time. Here are some tips to shorten that process and make build times more efficient.
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:2-->
Install ccache to cache builds
Install {{incode|ccache}} to cache builds.


=== Disable Modules === <!--T:3-->
== Disable modules == <!--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.
Use cmake-curses-gui, cmake-qt-gui, or cmake flags to disable modules you aren't working on


=== make -j === <!--T:4-->
<!--T:10-->
For example, to avoid building the FEM and Mesh workbenches:
Use make -j # to specify the number of jobs. A suggested value is your number of computer cores, e.g.
<pre>make -j $(nproc)</pre>


</translate>
=== distcc === <!--T:7-->
{{Code|code=
Distcc can be used for distributed compilation on a network.
cmake -DBUILD_FEM=OFF -DBUILD_MESH=OFF ../freecad-source
}}
<translate>


<!--T:5-->
<!--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.
{{Docnav|CompileOnMac|Third Party Libraries}}


<!--T:6-->
== Number of jobs in parallel == <!--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.
[[Category: Developer Documentation]]

<!--T:12-->
Run four compilation commands in parallel:


</translate>
</translate>
{{Code|code=
{{clear}}
make -j4
<languages/>
}}
<translate>

<!--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.

</translate>
{{code|code=
make -j$(nproc)
}}
<translate>

<!--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.

</translate>
{{code|code=
make -j$(nproc --ignore=2)
}}
<translate>

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

<!--T:5-->
{{Docnav
|[[FreeCAD Docker CLI mode|FreeCAD Docker CLI mode]]
|[[Third Party Libraries|Third-party libraries]]
}}

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

Revision as of 20:28, 4 September 2020

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.

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.