Compile on MacOS: Difference between revisions

From FreeCAD Documentation
m (remove punct)
(Fixed Docnav)
(42 intermediate revisions by 11 users not shown)
Line 1: Line 1:
<languages/>
<translate>
<translate>

<!--T:132-->
{{Docnav
|[[Compile_on_Linux|Compile on Linux]]
|[[Compile_on_Docker|Compile on Docker]]
}}

<!--T:136-->
{{VeryImportantMessage|There is an experimental FreeCAD Docker container that is being tested for FreeCAD development. Read more about it at [[Compile on Docker]]}}

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

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

<!--T:72-->
<!--T:72-->
This page describes how to compile the latest FreeCAD source on macOS X. ''Latest'' means the most recent commit to the master branch of the FreeCAD github repository.
This page describes how to compile the FreeCAD source code on MacOS X. For other platforms, see [[Compiling|Compiling]].


<!--T:134-->
These instructions have been tested on macOS Catalina with standard XCode 11.6. It is known to work on macOS BigSur Beta with XCode 12.0 beta. If you plan to use XCode Beta, please be sure to download Command Line Tools add on through a dmg package to workaround some libz dependency issues.

<!--T:119-->
This page serves as a quick start, and is not intended to be comprehensive with regard to describing all the available build options.
This page serves as a quick start, and is not intended to be comprehensive with regard to describing all the available build options.


<!--T:120-->
If you just want to evaluate the latest pre-release build of FreeCAD, you can download pre-built binaries [https://github.com/FreeCAD/FreeCAD/releases from here].
If you just want to evaluate the latest pre-release build of FreeCAD, you can download pre-built binaries [https://github.com/FreeCAD/FreeCAD/releases from here].


== Install Prerequisites == <!--T:73-->
== Install Prerequisites == <!--T:73-->

<!--T:139-->
The following software must be installed to support the build process.
The following software must be installed to support the build process.


=== Homebrew Package Manager === <!--T:76-->
=== Homebrew Package Manager === <!--T:76-->

<!--T:140-->
Homebrew is a command line based package manager for macOS. The [https://brew.sh/ Homebrew main page] provides an installation command line that you simply paste into a terminal window.
Homebrew is a command line based package manager for macOS. The [https://brew.sh/ Homebrew main page] provides an installation command line that you simply paste into a terminal window.


=== CMake === <!--T:79-->
=== CMake === <!--T:79-->

CMake is build tool that generates a build configuration based on variables you specify. You then issue the 'make' command to actually build that configuration. The command-line version of CMake is automatically installed as part of the Homebrew installation, above. If you prefer to use a GUI version of CMake, you can download it from [https://www.cmake.org/downloadDownload here].
<!--T:141-->
CMake is a build tool that generates a build configuration based on variables you specify. You then issue the 'make' command to actually build that configuration. The command-line version of CMake is automatically installed as part of the Homebrew installation, above. If you prefer to use a GUI version of CMake, you can download it from [https://www.cmake.org/downloadDownload here].


== Install Dependencies == <!--T:82-->
== Install Dependencies == <!--T:82-->

<!--T:142-->
FreeCAD maintains a Homebrew 'tap' which installs the required formulas and dependencies. Issue the following brew commands in your terminal.
FreeCAD maintains a Homebrew 'tap' which installs the required formulas and dependencies. Issue the following brew commands in your terminal.


<!--T:116-->
<br />
</translate>
</translate>
{{Code|code=
<pre>
brew tap homebrew/science
brew tap freecad/freecad
brew tap freecad/freecad
brew install eigen
brew install eigen
brew install --only-dependencies freecad --with-packaging-utils
brew install --only-dependencies freecad --with-packaging-utils
}}
brew install --only-dependencies freecad --with-packaging-utils
</pre>
<translate>
<translate>

<!--T:121-->
Notes:
Notes:
# 'brew install' may take quite a while, so you may want go grab a beverage. :-).
# The duplicate 'brew install' command for freecad dependencies is intentional. There is currently a bug where some of the dependencies are not installed on the first run.
# Homebrew is currently shipping with Boost 1.73, which contains a bug to compile FreeCAD please edit the file /usr/local/opt/boost/include/boost/geometry/index/detail/rtree/visitors/insert.hpp and on line 265 declare MembersHolder::visitor as being a Public value by replacing : MembersHolder::visitor with : public MembersHolder::visitor
# 'brew install' may take quite a while, so you may want go grab a beverage. :-)



== Get the source == <!--T:85-->
== Get the source == <!--T:85-->

<!--T:143-->
In the following instructions, the source and build folders are created side-by-side under
In the following instructions, the source and build folders are created side-by-side under


</translate>
{{Code|code=
/Users/username/FreeCAD
/Users/username/FreeCAD
}}
<translate>


<!--T:123-->
but you can use whatever folders you want.
but you can use whatever folders you want.

</translate>
</translate>
{{Code|code=
<pre>
mkdir ~/FreeCAD
mkdir ~/FreeCAD
cd ~/FreeCAD
cd ~/FreeCAD
}}
</pre>
<translate>
<translate>

<!--T:86-->
<!--T:86-->
The following command will clone the FreeCAD git repository into a directory called FreeCAD-git.
The following command will clone the FreeCAD git repository into a directory called FreeCAD-git.

</translate>
</translate>
{{Code|code=
<pre>
git clone https://github.com/FreeCAD/FreeCAD FreeCAD-git
git clone https://github.com/FreeCAD/FreeCAD FreeCAD-git
}}
</pre>
<translate>
<translate>

<!--T:89-->
<!--T:89-->
Create the build folder.
Create the build folder.

</translate>
</translate>
{{Code|code=
<pre>
mkdir ~/FreeCAD/build
mkdir ~/FreeCAD/build
}}
</pre>
<br />
<translate>
<translate>


== Run CMake == <!--T:88-->
== Run CMake == <!--T:88-->


<!--T:124-->
Next, we will run CMake to generate the build configuration. Several options must be passed to CMake. The following table describes the options and gives some background.
Next, we will run CMake to generate the build configuration. Several options must be passed to CMake. The following table describes the options and gives some background.


Line 77: Line 118:
| BUILD_QT5 || 1 (BOOL) || Required to build with Qt5.
| BUILD_QT5 || 1 (BOOL) || Required to build with Qt5.
|-
|-
| CMAKE_PREFIX_PATH || "/usr/local/Cellar/qt@5.6/5.6.2/lib/cmake" (PATH) || Required to build with Qt5. See note below.
| CMAKE_PREFIX_PATH || "/usr/local/opt/qt5/lib/cmake/;" ... (PATH) || Required to build with Qt5. See note below. You also need to add path to VTK libraries and NGLIB libraries cmake configuration file.


<!--T:125-->
|-
|-
| FREECAD_CREATE_MAC_APP || 1 (BOOL) || Create a FreeCAD.app bundle at the location specified in CMAKE_INSTALL_PREFIX, when the 'make install' command issued.
| FREECAD_CREATE_MAC_APP || 1 (BOOL) || Create a FreeCAD.app bundle at the location specified in CMAKE_INSTALL_PREFIX, when the 'make install' command issued.
Line 89: Line 131:
|}
|}


<!--T:126-->
Note: Command line to generate CMAKE_PREFIX_PATH:
Note: Command line to generate CMAKE_PREFIX_PATH:

</translate>
</translate>
<!--NOT CHANGE THE <pre> </pre> BALISE CAUSE THE PIPE OR SPACE IN MACRO CODE CUT THE MACRO-->
<pre>
ls -d $(brew list -1 | grep qt | tail -1 | xargs brew --cellar)/*/lib/cmake
ls -d $(brew list -1 | grep qt | tail -1 | xargs brew --cellar)/*/lib/cmake
</pre>
<translate>
<translate>


=== CMake GUI === <!--T:92-->
=== CMake GUI === <!--T:92-->

<!--T:144-->
Open the CMake app, and fill in the source and build folder fields. In this example, it would be '''/Users/username/FreeCAD/FreeCAD-git''' for the source, and '''/Users/username/FreeCAD/build''' for the build folder.
Open the CMake app, and fill in the source and build folder fields. In this example, it would be '''/Users/username/FreeCAD/FreeCAD-git''' for the source, and '''/Users/username/FreeCAD/build''' for the build folder.


Line 102: Line 147:
Next, click the '''Configure''' button to populate the list of configuration options. This will display a dialog asking you to specify what generator to use. Leave it at the default '''Unix Makefiles.''' Configuring will fail the first time because there are some options that need to be changed. Note: You will need to check the '''Advanced''' checkbox to get all of the options.
Next, click the '''Configure''' button to populate the list of configuration options. This will display a dialog asking you to specify what generator to use. Leave it at the default '''Unix Makefiles.''' Configuring will fail the first time because there are some options that need to be changed. Note: You will need to check the '''Advanced''' checkbox to get all of the options.


<!--T:135-->
Set options from the table above, then click '''Configure''' again and then '''Generate'''.
Set options from the table above, then click '''Configure''' again and then '''Generate'''.

=== CMake command line === <!--T:94-->
=== CMake command line === <!--T:94-->

<!--T:145-->
Enter the following in the terminal.
Enter the following in the terminal.

</translate>
{{Code|code=
export PREFIX_PATH="/usr/local/opt/qt/lib/cmake/;/usr/local/Cellar/nglib/v6.2.2007/Contents/Resources;/usr/local/Cellar/vtk@8.2/8.2.0_1/lib/cmake/"
}}
<translate>

</translate>
</translate>
{{Code|code=
<pre>
$cd ~/FreeCAD/build
$cd ~/FreeCAD/build
$cmake \
$cmake \
-DCMAKE_BUILD_TYPE="Release" \
-DCMAKE_BUILD_TYPE="Release" \
-DBUILD_QT5=1 \
-DBUILD_QT5=1 \
-DWITH_PYTHON3=1 \
-DCMAKE_PREFIX_PATH="/usr/local/Cellar/qt@5.6/5.6.2/lib/cmake" \
-DCMAKE_PREFIX_PATH="$PREFIX_PATH" \
-DPYTHON_EXECUTABLE="/usr/local/bin/python3" \
-DFREECAD_USE_EXTERNAL_KDL=1 \
-DFREECAD_USE_EXTERNAL_KDL=1 \
-DCMAKE_CXX_FLAGS='-std=c++14' \
-DBUILD_FEM_NETGEN=1 \
-DBUILD_FEM_NETGEN=1 \
-DFREECAD_CREATE_MAC_APP=1 \
-DFREECAD_CREATE_MAC_APP=1 \
Line 118: Line 177:
../FreeCAD-git/
../FreeCAD-git/


}}
</pre>
<translate>
<translate>


== Run make == <!--T:88-->
== Run make == <!--T:127-->

<!--T:146-->
Finally, from a terminal run '''make''' to compile and link FreeCAD, and generate the app bundle.
Finally, from a terminal run '''make''' to compile and link FreeCAD, and generate the app bundle.

</translate>
</translate>
{{Code|code=
<pre>
cd ~/FreeCAD/build
cd ~/FreeCAD/build
make –j5 install
make -j5 install
}}
</pre>
<translate>
<translate>

<!--T:96-->
<!--T:96-->
The -j option specifies how many make processes to run at once. One plus the number of CPU cores is usually a good number to use. However, if compiling fails for some reason, it is useful to rerun make without the -j option, so that you can see exactly where the error occurred.
The -j option specifies how many make processes to run at once. One plus the number of CPU cores is usually a good number to use. However, if compiling fails for some reason, it is useful to rerun make without the -j option, so that you can see exactly where the error occurred.
Line 139: Line 202:


== Updating from Github == <!--T:98-->
== Updating from Github == <!--T:98-->

<!--T:147-->
FreeCAD development happens fast; every day or so there are bug fixes or new features. To get the latest changes, use git to update the source directory (see [[Source code management]]), then re-run the CMake and make steps above. It is not usually necessary to start with a clean build directory in this case, and subsequent compiles will generally go much faster than the first one.
FreeCAD development happens fast; every day or so there are bug fixes or new features. To get the latest changes, use git to update the source directory (see [[Source code management]]), then re-run the CMake and make steps above. It is not usually necessary to start with a clean build directory in this case, and subsequent compiles will generally go much faster than the first one.


== Building with Qt4 == <!--T:100-->
== Building with Qt4 and Python 2.7 == <!--T:100-->
FreeCAD has transitioned from Qt 4 to Qt 5. If you need to build with Qt4, the following additional steps are required.


<!--T:148-->
# Append '--with-qt4' to the 'brew install' command.
FreeCAD has transitioned from Qt 4 to Qt 5 as well as homebrew. Qt 4 is no longer available as an option for new build on macOS following Qt 5 transition. Python 2.7 has been deprecated within homebrew and upcoming macOS and we do not support it anymore for macOS build either.
# Do not specify BUILD_QT5 CMake option.
# Do not specify CMAKE_PREFIX_PATH CMake option


== Troubleshooting == <!--T:130-->
After you install Qt4, if you want to switch to building with Qt5, you will need to uninstall Qt4.
</translate>
<pre>
brew uninstall --ignore-dependencies --force cartr/qt4/shiboken@1.2 cartr/qt4/pyside@1.2 cartr/qt4/pyside-tools@1.2 cartr/qt4/qt
</pre>
<translate>


== Troubleshooting == <!--T:100-->
=== Segfault on Qt5 launch === <!--T:131-->


<!--T:149-->
=== Segfault on Qt5 launch ===
If Qt4 was previously installed via brew, and you then build with Qt5, you may get a EXC_BAD_ACCESS (SEGSEGV) exception when launching the new Qt5 build. The fix for this is to manually uninstall Qt4.
If Qt4 was previously installed via brew, and you then build with Qt5, you may get a EXC_BAD_ACCESS (SEGSEGV) exception when launching the new Qt5 build. The fix for this is to manually uninstall Qt4.

</translate>
</translate>
{{Code|code=
<pre>
brew uninstall --ignore-dependencies --force cartr/qt4/shiboken@1.2 cartr/qt4/pyside@1.2 cartr/qt4/pyside-tools@1.2 cartr/qt4/qt-legacy-formula
brew uninstall --ignore-dependencies --force cartr/qt4/shiboken@1.2 cartr/qt4/pyside@1.2 cartr/qt4/pyside-tools@1.2 cartr/qt4/qt-legacy-formula
}}
</pre>
<translate>
<translate>


=== Fortran === <!--T:101-->
=== Fortran === <!--T:101-->

<!--T:150-->
''"No CMAKE_Fortran_COMPILER could be found."'' during configuration - Older versions of FreeCAD will need a fortran compiler installed. With Homebrew, do "brew install gcc" and try configuring again, giving cmake the path to Fortran ie -DCMAKE_Fortran_COMPILER=/opt/local/bin/gfortran-mp-4.9 . Or, preferably use a more current version of FreeCAD source!
''"No CMAKE_Fortran_COMPILER could be found."'' during configuration - Older versions of FreeCAD will need a fortran compiler installed. With Homebrew, do "brew install gcc" and try configuring again, giving cmake the path to Fortran ie -DCMAKE_Fortran_COMPILER=/opt/local/bin/gfortran-mp-4.9 . Or, preferably use a more current version of FreeCAD source!


=== OpenGL === <!--T:104-->
=== OpenGL === <!--T:104-->

<!--T:151-->
See [[OpenGL_on_MacOS|OpenGL on MacOS]] for OpenGL issues when Qt 4.8 and earlier are used on MacOS.
See [[OpenGL_on_MacOS|OpenGL on MacOS]] for OpenGL issues when Qt 4.8 and earlier are used on MacOS.


=== FreeType === <!--T:117-->
=== FreeType === <!--T:117-->

<!--T:152-->
When using CMake versions older than 3.1.0, it's necessary to set CMake variable FREETYPE_INCLUDE_DIR_freetype2 manually, eg /usr/local/include/freetype2
When using CMake versions older than 3.1.0, it's necessary to set CMake variable FREETYPE_INCLUDE_DIR_freetype2 manually, eg /usr/local/include/freetype2



<!--T:102-->
<!--T:102-->
{{Docnav
{{docnav|CompileOnUnix|Compiling (Speeding up)}}
|[[Compile_on_Linux|Compile on Linux]]

|[[Compile_on_Docker|Compile on Docker]]
<!--T:103-->
}}
[[Category:Developer Documentation]]


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

Revision as of 21:17, 29 December 2020

There is an experimental FreeCAD Docker container that is being tested for FreeCAD development. Read more about it at Compile on Docker

Overview

This page describes how to compile the FreeCAD source code on MacOS X. For other platforms, see Compiling.

These instructions have been tested on macOS Catalina with standard XCode 11.6. It is known to work on macOS BigSur Beta with XCode 12.0 beta. If you plan to use XCode Beta, please be sure to download Command Line Tools add on through a dmg package to workaround some libz dependency issues.

This page serves as a quick start, and is not intended to be comprehensive with regard to describing all the available build options.

If you just want to evaluate the latest pre-release build of FreeCAD, you can download pre-built binaries from here.

Install Prerequisites

The following software must be installed to support the build process.

Homebrew Package Manager

Homebrew is a command line based package manager for macOS. The Homebrew main page provides an installation command line that you simply paste into a terminal window.

CMake

CMake is a build tool that generates a build configuration based on variables you specify. You then issue the 'make' command to actually build that configuration. The command-line version of CMake is automatically installed as part of the Homebrew installation, above. If you prefer to use a GUI version of CMake, you can download it from here.

Install Dependencies

FreeCAD maintains a Homebrew 'tap' which installs the required formulas and dependencies. Issue the following brew commands in your terminal.

brew tap freecad/freecad
brew install eigen
brew install --only-dependencies freecad --with-packaging-utils

Notes:

  1. 'brew install' may take quite a while, so you may want go grab a beverage. :-).
  2. Homebrew is currently shipping with Boost 1.73, which contains a bug to compile FreeCAD please edit the file /usr/local/opt/boost/include/boost/geometry/index/detail/rtree/visitors/insert.hpp and on line 265 declare MembersHolder::visitor as being a Public value by replacing : MembersHolder::visitor with : public MembersHolder::visitor


Get the source

In the following instructions, the source and build folders are created side-by-side under

/Users/username/FreeCAD

but you can use whatever folders you want.

mkdir ~/FreeCAD
cd ~/FreeCAD

The following command will clone the FreeCAD git repository into a directory called FreeCAD-git.

git clone https://github.com/FreeCAD/FreeCAD FreeCAD-git

Create the build folder.

mkdir ~/FreeCAD/build

Run CMake

Next, we will run CMake to generate the build configuration. Several options must be passed to CMake. The following table describes the options and gives some background.

CMake Options

Name Value Notes
CMAKE_BUILD_TYPE Release (STRING) Release or Debug. Debug is generally used for developer-level testing but may also be required for user-level testing and troubleshooting.
BUILD_QT5 1 (BOOL) Required to build with Qt5.
CMAKE_PREFIX_PATH "/usr/local/opt/qt5/lib/cmake/;" ... (PATH) Required to build with Qt5. See note below. You also need to add path to VTK libraries and NGLIB libraries cmake configuration file.
FREECAD_CREATE_MAC_APP 1 (BOOL) Create a FreeCAD.app bundle at the location specified in CMAKE_INSTALL_PREFIX, when the 'make install' command issued.
CMAKE_INSTALL_PREFIX "./.." (PATH) Path where you want to generate the FreeCAD.app bundle.
FREECAD_USE_EXTERNAL_KDL 1 (BOOL) Required.
BUILD_FEM_NETGEN 1 (BOOL) Required.

Note: Command line to generate CMAKE_PREFIX_PATH:

ls -d $(brew list -1 | grep qt | tail -1 | xargs brew --cellar)/*/lib/cmake

CMake GUI

Open the CMake app, and fill in the source and build folder fields. In this example, it would be /Users/username/FreeCAD/FreeCAD-git for the source, and /Users/username/FreeCAD/build for the build folder.

Next, click the Configure button to populate the list of configuration options. This will display a dialog asking you to specify what generator to use. Leave it at the default Unix Makefiles. Configuring will fail the first time because there are some options that need to be changed. Note: You will need to check the Advanced checkbox to get all of the options.

Set options from the table above, then click Configure again and then Generate.

CMake command line

Enter the following in the terminal.

export PREFIX_PATH="/usr/local/opt/qt/lib/cmake/;/usr/local/Cellar/nglib/v6.2.2007/Contents/Resources;/usr/local/Cellar/vtk@8.2/8.2.0_1/lib/cmake/"
$cd ~/FreeCAD/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="./.."  \
  ../FreeCAD-git/

Run make

Finally, from a terminal run make to compile and link FreeCAD, and generate the app bundle.

cd ~/FreeCAD/build
make -j5 install

The -j option specifies how many make processes to run at once. One plus the number of CPU cores is usually a good number to use. However, if compiling fails for some reason, it is useful to rerun make without the -j option, so that you can see exactly where the error occurred.

See also Compiling - Speeding up.

If make finishes without any errors, you can now launch FreeCAD by double clicking the executable in the Finder.

Updating from Github

FreeCAD development happens fast; every day or so there are bug fixes or new features. To get the latest changes, use git to update the source directory (see Source code management), then re-run the CMake and make steps above. It is not usually necessary to start with a clean build directory in this case, and subsequent compiles will generally go much faster than the first one.

Building with Qt4 and Python 2.7

FreeCAD has transitioned from Qt 4 to Qt 5 as well as homebrew. Qt 4 is no longer available as an option for new build on macOS following Qt 5 transition. Python 2.7 has been deprecated within homebrew and upcoming macOS and we do not support it anymore for macOS build either.

Troubleshooting

Segfault on Qt5 launch

If Qt4 was previously installed via brew, and you then build with Qt5, you may get a EXC_BAD_ACCESS (SEGSEGV) exception when launching the new Qt5 build. The fix for this is to manually uninstall Qt4.

brew uninstall --ignore-dependencies --force cartr/qt4/shiboken@1.2 cartr/qt4/pyside@1.2 cartr/qt4/pyside-tools@1.2 cartr/qt4/qt-legacy-formula

Fortran

"No CMAKE_Fortran_COMPILER could be found." during configuration - Older versions of FreeCAD will need a fortran compiler installed. With Homebrew, do "brew install gcc" and try configuring again, giving cmake the path to Fortran ie -DCMAKE_Fortran_COMPILER=/opt/local/bin/gfortran-mp-4.9 . Or, preferably use a more current version of FreeCAD source!

OpenGL

See OpenGL on MacOS for OpenGL issues when Qt 4.8 and earlier are used on MacOS.

FreeType

When using CMake versions older than 3.1.0, it's necessary to set CMake variable FREETYPE_INCLUDE_DIR_freetype2 manually, eg /usr/local/include/freetype2