Compile on MacOS - my experiences

Having trouble installing or compiling FreeCAD? Get help here.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
zisoft
Posts: 49
Joined: Thu Mar 25, 2021 6:23 pm
Contact:

Compile on MacOS - my experiences

Post by zisoft »

I just started to setup my MacBook to compile FreeCAD, because I'm interested in participating in the development. So I want to share my experiences here.

System Spec:
MacOS Big Sur 11.2.3
MacBook Pro 16", 2019
2,3 GHz 8-Core Intel Core i9
32 GB 2667 MHz DDR4

According to the the documentation https://wiki.freecadweb.org/Compile_on_MacOS I started to install the dependencies. I had homebrew already installed so I could easily follow the steps from the documentation page.

I cloned the github repo to ~/FreeCAD/source.

My settings to run CMake are as follows:

Code: Select all

export PREFIX_PATH="/usr/local/Cellar/qt5152/5.15.2/lib/cmake;/usr/local/opt/qt/lib/cmake/;/usr/local/Cellar/nglib/v6.2.2007/Contents/Resources;/usr/local/Cellar/vtk@8.2.0/8.2.0_1/lib/cmake/vtk-8.2;/usr/local/opt/boost-python3@1.75.0/lib/cmake"

cd ./build

cmake \
  -DCMAKE_BUILD_TYPE="Release"   \
  -DBUILD_QT5=1                  \
  -DWITH_PYTHON3=1               \
  -DCMAKE_PREFIX_PATH="$PREFIX_PATH" \
  -DPYTHON_EXECUTABLE="/usr/local/bin/python3" \
  -DFREECAD_USE_EXTERNAL_KDL=1   \
  -DCMAKE_CXX_FLAGS='-std=c++14' \
  -DBUILD_FEM_NETGEN=1           \
  -DFREECAD_CREATE_MAC_APP=1     \
  -DCMAKE_INSTALL_PREFIX="./.."  \
  ../source/
Running cmake leads to "Coin3D not found", which I fixed by running

Code: Select all

brew install coin3d
Now CMake reports:

Code: Select all

CMake Error in src/Gui/CMakeLists.txt:
  Imported target "Shiboken2::libshiboken" includes non-existent path

    "/usr/local/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/include/python3.9

  "

  in its INTERFACE_INCLUDE_DIRECTORIES.  Possible reasons include:
The mentioned path definitely exists, but note the position of the closing doublequotes in the error message. It looks like that two newline characters are appended to the path. Unfortunately I have no idea what causes this and how to fix this.

Now I can start the build process by running

Code: Select all

make -j6 install
in the build folder.
Compilation stops with several errors, all like this:

Code: Select all

src/Mod/TechDraw/Gui/CMakeFiles/TechDrawGui.dir/flags.make:8: *** missing separator.  Stop.
The file flags.make in the mentioned directory looks like this:

Code: Select all

# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.20

# compile CXX with /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
CXX_DEFINES = -DBOOST_ALL_NO_LIB -DBOOST_FILESYSTEM_DYN_LINK -DBOOST_PP_VARIADICS=1 -DBOOST_PROGRAM_OPTIONS_DYN_LINK -DBOOST_REGEX_DYN_LINK -DBOOST_SYSTEM_DYN_LINK -DBOOST_THREAD_DYN_LINK -DGL_SILENCE_DEPRECATION -DHAVE_CONFIG_H -DHAVE_FREEIMAGE -DHAVE_LIMITS_H -DHAVE_RAPIDJSON -DHAVE_TBB -DMOD_TECHDRAW_HANDLE_FACES=1 -DNDEBUG -DOCC_CONVERT_SIGNALS -DPYSIDE_QML_SUPPORT=1 -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_NO_DEBUG -DQT_OPENGL_LIB -DQT_PRINTSUPPORT_LIB -DQT_SVG_LIB -DQT_UITOOLS_LIB -DQT_WIDGETS_LIB -DQT_XMLPATTERNS_LIB -DQT_XML_LIB -DTechDrawGui_EXPORTS -D_OCC64

CXX_INCLUDES = -I/Users/mario/FreeCAD/build -I/Users/mario/FreeCAD/build/src -I/Users/mario/FreeCAD/source/src -I/Users/mario/FreeCAD/build/src/Mod/TechDraw/Gui -I/Users/mario/FreeCAD/source/src/Mod/TechDraw/Gui -I/usr/local/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/include/python3.9 -I/usr/local/include/opencascade -isystem /usr/local/include -iframework /usr/local/Cellar/qt5152/5.15.2/lib -isystem /usr/local/Cellar/qt5152/5.15.2/lib/QtXmlPatterns.framework/Headers -isystem /usr/local/Cellar/qt5152/5.15.2/lib/QtNetwork.framework/Headers -isystem /usr/local/Cellar/qt5152/5.15.2/lib/QtCore.framework/Headers -isystem /usr/local/Cellar/qt5152/5.15.2/./mkspecs/macx-clang -isystem /usr/local/Cellar/qt5152/5.15.2/lib/QtXml.framework/Headers -isystem /usr/local/Cellar/qt5152/5.15.2/lib/QtWidgets.framework/Headers -isystem /usr/local/Cellar/qt5152/5.15.2/lib/QtGui.framework/Headers -isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/OpenGL.framework/Headers -isystem /usr/local/Cellar/qt5152/5.15.2/lib/QtOpenGL.framework/Headers -isystem /usr/local/Cellar/qt5152/5.15.2/lib/QtPrintSupport.framework/Headers -isystem /usr/local/Cellar/qt5152/5.15.2/lib/QtSvg.framework/Headers -isystem /usr/local/Cellar/qt5152/5.15.2/include -isystem /usr/local/Cellar/qt5152/5.15.2/include/QtUiTools -isystem /usr/local/include/shiboken2 -isystem /usr/local/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/include/python3.9
 -isystem /usr/local/include/PySide2

CXX_FLAGS = -Wall -Wextra -Wpedantic -Wno-write-strings -std=c++14 -Wno-undefined-var-template -O3 -DNDEBUG -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk -fPIC -F/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks  -I/usr/local/Cellar/open-mpi/4.1.0/include -fPIC -std=gnu++17
The reason for the error is the last line of the CXX_INCLUDES, there is a newline character in front of -isystem /usr/local/include/PySide2. It's again the appended newline character at the ...python3.9 path in the preceding line.

This is the case for ALL flags.make files in the

Code: Select all

src/Mod/**/Gui/CMakeFiles/*Gui.dir/
directories.

I have fixed all these files by removing the newline character. First time by hand, then I have writte a small ruby script to automate this.

Now the compilation finishes without errors but when building the MacOS app bundle in the final step it says:

Code: Select all

CMake Error at src/MacAppBundle/cmake_install.cmake:74 (file):
  file INSTALL cannot find
  "/Users/mario/FreeCAD/source/src/MacAppBundle/import site": No such file or
  directory.
Call Stack (most recent call first):
  src/cmake_install.cmake:51 (include)
  cmake_install.cmake:68 (include)


make: *** [install] Error 1
I have seen a discussion about that in the github issues, but no sulution so far.

The FreeCAD.app file is created anyway but crashes immediately on start without any further message.

However, I can successfully start FreeCAD from the command line by launching

Code: Select all

./build/bin/FreeCAD
That's the story so far.

Does anyone has any helpful hints how to fix the CMake errors and the creation of the flags.make files?

Thank you and sorry for the long post.
zisoft
Posts: 49
Joined: Thu Mar 25, 2021 6:23 pm
Contact:

Re: Compile on MacOS - my experiences

Post by zisoft »

I could fix all the cmake problems by adding

Code: Select all

  -DPYTHON_INCLUDE_DIR=$(python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())")  \
to the cmake parameters. The automatically generated PYTHON_INCLUDE_DIR contains a newline character at the end of the path which causes make to complain.

Now I'm digging further for the Mac app bundle error...
zisoft
Posts: 49
Joined: Thu Mar 25, 2021 6:23 pm
Contact:

Re: Compile on MacOS - my experiences

Post by zisoft »

With the great help of @vejmarie I can now compile and build the app.

Now, when I run FreeCAD, create a new document and open the Draft workbench, FreeCAD crashes.

Terminal output:

Code: Select all

FreeCAD 0.20, Libs: 0.20R24711 (Git)
© Juergen Riegel, Werner Mayer, Yorik van Havre and others 2001-2021
FreeCAD is free and open-source software licensed under the terms of LGPL2+ license.
FreeCAD wouldn't be possible without FreeCAD community.
  #####                 ####  ###   ####  
  #                    #      # #   #   # 
  #     ##  #### ####  #     #   #  #   # 
  ####  # # #  # #  #  #     #####  #   # 
  #     #   #### ####  #    #     # #   # 
  #     #   #    #     #    #     # #   #  ##  ##  ##
  #     #   #### ####   ### #     # ####   ##  ##  ##

Persistent toolbars: Snapper toolbar not managed.
'NoneType' object has no attribute 'pnts'
Traceback (most recent call last):
  File "<string>", line 132, in Activated
  File "/Users/mario/FreeCAD/build/Mod/Draft/draftguitools/gui_snapper.py", line 1643, in show
    self.setTrackers()
  File "/Users/mario/FreeCAD/build/Mod/Draft/draftguitools/gui_snapper.py", line 1701, in setTrackers
    self.dim1 = trackers.archDimTracker(mode=2)
  File "/Users/mario/FreeCAD/build/Mod/Draft/draftguitools/gui_trackers.py", line 1317, in __init__
    self.dimnode.pnts.setValues([p1node, p2node])

[1]    91404 segmentation fault  /Users/mario/FreeCAD/build/bin/FreeCAD
Saving session...completed.
Any ideas?
User avatar
sgrogan
Veteran
Posts: 6499
Joined: Wed Oct 22, 2014 5:02 pm

Re: Compile on MacOS - my experiences

Post by sgrogan »

zisoft wrote: Fri Apr 16, 2021 4:28 pmAny ideas?
Wild guess.
Any chance you have persistenttoolbars installed as an Addon?
This should all be handled by the Tux module in master, maybe some conflict?
"fight the good fight"
zisoft
Posts: 49
Joined: Thu Mar 25, 2021 6:23 pm
Contact:

Re: Compile on MacOS - my experiences

Post by zisoft »

sgrogan wrote: Fri Apr 16, 2021 5:25 pm Any chance you have persistenttoolbars installed as an Addon?
No additional addons installed.

This is all very frustrating.
BTW: The image from the weekly builds https://github.com/FreeCAD/FreeCAD-AppI ... kly-builds does not crash, so it must have something to do with my compile setup.
chrisb
Veteran
Posts: 54280
Joined: Tue Mar 17, 2015 9:14 am

Re: Compile on MacOS - my experiences

Post by chrisb »

Does it also crash if you switch to Path workbench? Then I would guess that there is a conflict with Python versions.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
zisoft
Posts: 49
Joined: Thu Mar 25, 2021 6:23 pm
Contact:

Re: Compile on MacOS - my experiences

Post by zisoft »

No problem with path workbench, but I get the same crash with the arch workbench.

Will check my python installations now, thank you for pointing.
zisoft
Posts: 49
Joined: Thu Mar 25, 2021 6:23 pm
Contact:

Re: Compile on MacOS - my experiences

Post by zisoft »

chrisb wrote: Fri Apr 16, 2021 8:17 pm I would guess that there is a conflict with Python versions.
I forced a

Code: Select all

brew link --overwrite python@3
that seems so solve the problem. No more crashes so far.

Thank you!
chrisb
Veteran
Posts: 54280
Joined: Tue Mar 17, 2015 9:14 am

Re: Compile on MacOS - my experiences

Post by chrisb »

Can this occur in normal usage as well? Should this be added to the Known OS specific issues? Or is it something that affects only self compilers?
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
sgrogan
Veteran
Posts: 6499
Joined: Wed Oct 22, 2014 5:02 pm

Re: Compile on MacOS - my experiences

Post by sgrogan »

zisoft wrote: Sat Apr 17, 2021 5:59 am No problem with path workbench, but I get the same crash with the arch workbench.
This might indicate a problem with PysSide2?
"fight the good fight"
Post Reply