- Install CMake GUI
- Install Visual Studio Community
- https://visualstudio.microsoft.com/downloads/
- Ensure you enable
Desktop Development with C++
Pick a location to store the FreeCAD source code. We will refer to whatever location you have selected as $FREECAD
throughout the rest of the document.
git clone https://github.com/FreeCAD/FreeCAD.git
cd FreeCAD
git submodule update --init
- Set
Where is the source code
to$FREECAD
- Set
Where to build the binaries
to$FREECAD/build
- Click
Configure
If your build directory doesn't exist, it'll ask you if it should be created. Hit "Yes"
.
The defaults should be good for most situations.
Make sure to set the architecture if you're using something other than x64.
Click Finish
. Expect it to fail with an error popup:
Error in configuration process, project files may be invalid
The following errors are expected. See the Troubleshooting
section for other issues.
Libpack NOT found.
If you intend to use a Windows libpack, set the FREECAD_LIBPACK_DIR to the libpack directory.
Solution: Set FREECAD_LIBPACK_DIR
to $FREECAD/LibPack
CMake Error at cMake/FreeCAD_Helpers/ChooseQtVersion.cmake:79 (message):
Could not find a valid Qt installation. Consider setting Qt5_DIR or
Qt6_DIR (as needed).
Solution: Set Qt5_DIR
to $FREECAD/LickPack/lib/cmake/Qt5
Ensure to also set the following CMake settings.
Enable / set FREECAD_COPY_DEPEND_DIRS_TO_BUILD
to true.
Enable / set FREECAD_COPY_LIBPACK_BIN_TO_BUILD
to true.
Enable / set FREECAD_COPY_PLUGINS_BIN_TO_BUILD
to true.
Check CMake Variables
if you would like to further customize the build.
Finally, if CMake reports no configuration errors, hit the Generate
button. This will create the Visual Studio solution files.
When it finishes click Open Solution
.
Open the CMake generated solution with Visual Studio.
In the Visual Studio toolbar, there are two dropdowns:
- Set the first to
Release
- The second is usually set to
x64
by default.- Change it if you're on or building for a different architecture.
- Under the "Solution Explorer" are all the projects:
- Right-click the
FreeCADMain
project and selectSet as startup project
- Right-click the
ALL BUILD
project and select"Build"
.
- Right-click the
If there are no compilation errors, you can select Debug -> Run without Debugging
to start the compiled FreeCAD.
If you update the FreeCAD code (git pull
) or make your own changes, make sure to rebuild FreeCAD by again right-clicking the ALL BUILD
project and selecting "Build"
.
In the Visual Studio toolbar, there are two dropdowns:
- Set the first to
Debug
- The second is usually set to
x64
by default.- Change it if you're on or building for a different architecture.
Before compiling a debug build, you need to install the debug versions of FreeCAD's dependencies.
Overwrite all files when prompted:
- Copy everything from
$FREECAD/LibPack/bind
to$FREECAD/build/bin
- Copy everything from
$FREECAD/LibPack/libd
to$FREECAD/build/lib
You can now debug the build by selecting Debug -> Start Debugging
.
OCCT's types are used throughout FreeCAD. However, Visual Studio's debugger can't show their information without OCCT's debug symbols.
While LibPack comes with a debug build of OCCT, unfortunately it does not include debugging symbols.
Follow the Building OpenCASCADE
page in order to compile a debug version of OCCT with debug symbols. Then, follow the next section.
If you've built OCCT yourself, and want to use it in your FreeCAD build, first follow the steps on the Building OpenCASCADE
page.
When asked, replace all existing files during the copy.
Installing a Release Build
- Copy all files from
$OCCT/build/win64/vc14/bin
to$FREECAD/build/bin
- Copy all files from
$OCCT/build/win64/vc14/lib
to$FREECAD/build/lib
Installing a Debug Build
- Copy all files from
$OCCT/build/win64/vc14/bind
to$FREECAD/build/bin
- Copy all files from
$OCCT/build/win64/vc14/libd
to$FREECAD/build/lib
There are additional variables for customizing your FreeCAD build.
Variable | Description | Default |
---|---|---|
BUILD_XXX | Enable / disable major FreeCAD components. Note: Some components depend on others. CMake will complain if any enabled components depend on disabled ones. |
- |
BUILD_ENABLE_CXX_STD | C++ language-standard version. Note: - FreeCAD 0.19: <= C++14 - FreeCAD 0.20: >= C++17 |
- |
CMAKE_INSTALL_PREFIX | Output path when building the Visual Studio INSTALL project. |
Default Windows install path. |
FREECAD_COPY_DEPEND_DIRS_TO_BUILD | Copy third-party dependencies need to run FreeCAD.exe to the build folder.Note: Option only present if dependencies are not already present in the build folder. Delete the build folder and CMake cache to restore. |
OFF |
FREECAD_COPY_LIBPACK_BIN_TO_BUILD | Copy LibPack provided binaries required to run FreeCAD.exe to the build folder.Note: Option only present if dependencies are not already present in the build folder. Delete the build folder and CMake cache to restore. |
|
FREECAD_COPY_PLUGINS_BIN_TO_BUILD | Copy Qt plugin files required to run FreeCAD.exe to the build folder.Note: Option only present if dependencies are not already present in the build folder. Delete the build folder and CMake cache to restore. |
OFF |
FREECAD_LIBPACK_USE | Utilize LibPack provided artifacts during build. | ON |
FREECAD_LIBPACK_DIR | Path to extracted LibPack archive. | Path you specified as FreeCAD root directory in CMake GUI |
FREECAD_RELEASE_PDB | Produce debugging symbols for release builds. | ON |
FREECAD_USE_MP_COMPILE_FLAG | Use multiple CPU cores during compilation for potentially reduced build times. Note: With FREECAD_USE_PCH , compilation may overload your heap space, even with 16GB of RAM. |
ON |
FREECAD_USE_PYBIND11 | Include the PyBind11 library. This is necessary for builds that enable the CreateFlatMesh feature. |
OFF |
-
CMake Deprecation Warning
This is a warning that some CMake feature utilized by the FreeCAD or OCCT build tooling might be removed in a future version of CMake. -
Wrong or missing Python Version If CMake complains that it can't find Python or the version is wrong, set the following CMake variables:
Variable | Value |
---|---|
PYTHON_DEBUG_LIBRARY | $FREECAD/LibPack/bin/libs/python38_d.lib |
PYTHON_EXECUTABLE | $FREECAD/LibPack/bin/python.exe |
PYTHON_INCLUDE_DIR | $FREECAD/LibPack/bin/include |
PYTHON_LIBRARY | $FREECAD/bin/libs/python38.lib |