Skip to content

Instantly share code, notes, and snippets.

@dustinlacewell
Last active April 13, 2024 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dustinlacewell/708b5bc616b583e2e03437b31844b638 to your computer and use it in GitHub Desktop.
Save dustinlacewell/708b5bc616b583e2e03437b31844b638 to your computer and use it in GitHub Desktop.

Tools

Source Code

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.

Clone the code to $FREECAD

git clone https://github.com/FreeCAD/FreeCAD.git
cd FreeCAD
git submodule update --init

Extract latest "LibPack" to $FREECAD/LibPack

Configure Build

Open the CMake UI

  • 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".

Configuration Dialog

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

CMake Configuration Errors

The following errors are expected. See the Troubleshooting section for other issues.

FREECAD_LIBPACK_DIR
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

Qt5_DIR
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

Additional Build Settings

Ensure to also set the following CMake settings.

FREECAD_COPY_DEPEND_DIRS_TO_BUILD

Enable / set FREECAD_COPY_DEPEND_DIRS_TO_BUILD to true.

FREECAD_COPY_LIBPACK_BIN_TO_BUILD

Enable / set FREECAD_COPY_LIBPACK_BIN_TO_BUILD to true.

FREECAD_COPY_PLUGINS_BIN_TO_BUILD

Enable / set FREECAD_COPY_PLUGINS_BIN_TO_BUILD to true.

Check CMake Variables if you would like to further customize the build.

Generate Solution Files

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.

Building FreeCAD

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 select Set as startup project
    • Right-click the ALL BUILD project and select "Build".

Running the Build

If there are no compilation errors, you can select Debug -> Run without Debugging to start the compiled FreeCAD.

Rebuilding Changes

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

Debugging FreeCAD

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.

Installing Debug Dependencies

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

Running the Debugger

You can now debug the build by selecting Debug -> Start Debugging.

OpenCASCADE Debug Symbols

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.

Installing Custom OpenCASCADE

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

Additional CMake Options

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

Troubleshooting

FreeCAD CMake Issues

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

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

Tools

Source Code

Pick a location to store the OpenCASCADE source code. We will refer to whatever location you have selected as $OCCT throughout the rest of the document.

Clone the code to $OCCT

git clone https://github.com/Open-Cascade-SAS/OCCT.git

Third-party Dependencies

Download OCCT's required third-party dependencies to $OCCT/deps

Here are the latest versions available:

Extract both archives to $OCCT/deps

Configure Build

Open the CMake UI

  • Set Where is the source code to $OCCT
  • Set Where to build the binaries to $OCCT/build
  • Click Configure

If your build directory doesn't exist, it'll ask you if it should be created. Hit "Yes".

Configuration Dialog

The defaults should be good for most situations.

Make 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

CMake Configuration Errors

The following errors are expected. See the Troubleshooting section for other issues.

3RDPARTY_DIR

CMake Error at CMakeLists.txt:868 (message):  
Could not find headers of used third-party products:  
3RDPARTY_TCL_INCLUDE_DIR 3RDPARTY_TK_INCLUDE_DIR  
3RDPARTY_FREETYPE_INCLUDE_DIR_ft2build  
3RDPARTY_FREETYPE_INCLUDE_DIR_freetype2

Solution: Set 3RDPARTY_DIR to $OCCT/deps

Additional Build Settings

Ensure to also set the following CMake settings.

INSTALL_DIR

Set INSTALL_DIR to $OCCT/deps.

INSTALL_FREETYPE

Enable / set INSTALL_FREETYPE to true.

INSTALL_TCL

Enable / set INSTALL_TCL to true.

INSTALL_TK

Enable / set INSTALL_TK to true.

Generate Solution Files

Now hit Generate. If no errors occur, you can hit Open Solution.

Building OCCT

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.
  • Select Build -> Build Solution or hit F7

Rebuilding Changes

If you update the OCCT code (git pull) or make your own changes, make sure to rebuild OCCT by again selecting Build -> Build Solution or hitting F7.

Debug Builds

To create a debug build, simply change the Visual Studio toolbar dropdown from Release to Debug then rebuild.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment