Difference between revisions of "CompilingMacOsX"

From Inkscape Wiki
Jump to navigation Jump to search
(Update homebrew instructions for gtk4)
 
(117 intermediate revisions by 21 users not shown)
Line 1: Line 1:
= For the impatient =
__TOC__


1. Install [http://developer.apple.com/tools/xcode/ XCode tools] from your OS X installation DVD
<span style="color:darkred;font-weight:bold">Section about MacPorts IS OUTDATED AND UNMAINTAINED!</span>
<span style="color:darkgreen;font-weight:bold">Section about HomeBrew IS UP TO DATE as of Oct 30, 2024</span>


2. Download and install [http://www.macports.org/ MacPorts]
= Using MacPorts =


3. In Terminal (Applications>Utilities>Terminal) type
If you can build successfully with MacPorts, please update this file and remove above comment.
<pre>sudo port sync
sudo port selfupdate
sudo port install cairo +pdf boehmgc gtkmm gtk-engines2 intltool libxslt lcms popt poppler boost \
gnome-vfs libgnomeprintui automake autoconf subversion</pre>


Note: subversion is pre-installed on Leopard, so you may be fine leaving subversion out of the port install command chain.
<ol>
<li>Download and install [http://www.macports.org/ MacPorts]
<li>Edit the MacPorts variants config (optional).
<br>Add this line to <code>/opt/local/etc/macports/variants.conf</code>
<pre>-x11 +quartz</pre>
<li>In Terminal (Applications>Utilities>Terminal) type
<syntaxhighlight lang="bash">sudo port install \
    adwaita-icon-theme \
    boehmgc \
    boost \
    cairo \
    ccache \
    cmake \
    double-conversion \
    gdl3 \
    gettext \
    gsl \
    gtkmm3 \
    gtk-osx-application-gtk3 \
    lcms2 \
    libsoup \
    libxslt \
    ninja \
    poppler \
    potrace \
    py-lxml \
    py-numpy \
    -x11 +quartz
</syntaxhighlight>
<li>In Terminal, get Inkscape
<syntaxhighlight lang="bash">git clone --recurse-submodules https://gitlab.com/inkscape/inkscape.git</syntaxhighlight>
<li>And build inkscape
<syntaxhighlight lang="bash">
# use a clean MacPorts environment (optional)
LIBPREFIX="/opt/local"
export PATH="$LIBPREFIX/bin:/usr/bin:/bin:/usr/sbin:/sbin"


Grab a cup of coffee
# where to install
PREFIX="$PWD/install-prefix"


4. In Terminal, get and build Inkscape
# where to build
<pre>
mkdir build
svn co https://inkscape.svn.sourceforge.net/svnroot/inkscape/inkscape/trunk inkscape
cd build
cd inkscape/packaging/macosx/
./osx-build.sh a c b i -s p</pre>


''Et voilà''. If you want to understand what you just did, read on.
cmake \
    -G Ninja \
    -DCMAKE_PREFIX_PATH="$LIBPREFIX" \
    -DCMAKE_INSTALL_PREFIX="$PREFIX" \
    -DCMAKE_C_COMPILER_LAUNCHER=ccache \
    -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
    -DWITH_OPENMP=OFF \
    ../inkscape


= Requirements =
ninja
To compile Inkscape from source you need:
ninja install
*Mac OS X > 10.3
</syntaxhighlight>
*XCode Tools. They are on your installation DVD, in the optional installs, or can be download from [http://developer.apple.com/tools/xcode/ Apple Developer Connection]. You can customize the install to make it smaller (avoir documentation and example software for example). You need at least: gcc, XCode, X11SDK.
''Note: Using [https://en.wikipedia.org/wiki/Ccache ccache] and [https://ninja-build.org/ ninja] is not required, but very common because it speeds up compilation.''
*Inkscape's source code. You can download an [http://www.inkscape.org/download.php official release source code], a [http://inkscape.modevia.com/svn-snap/?M=D development snapshot] or checkout a copy of the current state of the [http://www.inkscape.org/svn.php?lang=en SVN repository] using [http://subversion.tigris.org/ subversion]. Subversion comes pre-installed on Leopard. On previous system, subversion can be installed by package management systems (see point below) or with an OS X installer [http://homepage.mac.com/martinott/ package]
<li>Run Inkscape
*A means of getting Inkscape's numerous dependencies: glibmm, gtkmm, lmcs, boehmgc... We recommend the use of [http://www.macports.org/ MacPorts] right now. ([http://www.finkproject.org/ Fink] was used in the past but it no longer meets Inkscape's needs currently.)
<syntaxhighlight lang="bash">
$PREFIX/bin/inkscape
</syntaxhighlight>
</ol>


= Compiling Inkscape with X11, using MacPorts [Recommended method]=
= Using Homebrew =


== Installing dependencies ==
Prerequisites:
You can use MacPorts to list Inkscape dependencies:
* Xcode (AppStore)
<pre>port deps inkscape</pre>
* Xcode command line tools (<code>xcode-select --install</code>)
* HomeBrew


Some are mandatory and you can install them with the command:
If you are using [https://brew.sh/ Homebrew] instead, you can still use the above guidelines with small modifications.
<pre>sudo port install boehmgc gtkmm gtk-engines2 intltool libxslt lcms popt boost gsl</pre>
(Make sure you don't have any MacPorts stuff in your PATH.)


Others provide additional functionality to Inkscape:
List of '''packages''' to install with brew
* <code>gnome-vfs</code> : access to remote servers, in particular import from Open Clipart Library
(for Inkscape on master branch using GTK4):
* <code>aspell</code> : check spelling of text elements [Note: I have never seen it working on OS X, though at least it should install fine]
* <code>libgnomeprintui</code>
* <code>loudmouth</code> : jabber library used by InkBoard
* <code>cairo +pdf</code> (cairo with the pdf variant) : better pdf export
* <code>poppler</code> : better pdf import
<pre>sudo port install gnome-vfs aspell libgnomeprintui loudmouth cairo +pdf poppler</pre>
NB: Cairo was already installed at previous step as a GTK dependency. You need to either deactivate the old version and install this one, or directly write it on the command line above.
If you're unsure about MacPorts commands, you can find a guide that is easy to skim here: [http://guide.macports.org/ MacPorts Guide]


In addition, Inkscape requires versions of the autotools more recent thant those that ship with OS X. Install them:
<syntaxhighlight lang="bash">
<pre>sudo port install autoconf automake</pre>
brew install \
    adwaita-icon-theme \
    bdw-gc \
    boost \
    cairomm \
    ccache \
    cmake \
    double-conversion \
    gettext \
    gsl \
    gspell \
    gtkmm4 \
    gtksourceview5 \
    imagemagick \
    intltool \
    lcms2 \
    libomp \
    libsoup@2 \
    libxslt \
    ninja \
    pkg-config \
    poppler \
    potrace
</syntaxhighlight>


More recent (Sep 2008) pre-packaged nightly builds for Mac OS X also feature additional dependencies:
You may substitute <code>imagemagick</code> with <code>graphicsmagick</code>.
<pre>sudo port install librsvg libwpd libwpg libcroco</pre>


NB: At the time of editing (2008-12-01) there was a problem fetching "lzmautils" as the URL MacPorts tried to use as download source dies in a timeout.
Some keg-only libraries need to be added to <code>$PKG_CONFIG_PATH</code>
As this package is needed as a dependency for one or more packages noted above you need to download the source tarball of lzmautils from somewhere else (for example, from [ftp://sunfreeware.mirrors.tds.net/pub/sunfreeware/SOURCES/lzma-4.32.7.tar.gz here]) and put that into the local MacPorts repository at "/opt/local/var/macports/distfiles/lzmautils". You should now be able to run the commands above.


Also make sure that you have "libxml2" and "libxslt" installed with MacPorts. This should have been installed previously, either directly or as a dependency.
Some libraries can cause trouble if they are picked up from the SDK instead of Homebrew (observed with <code>libxslt</code> and <code>libxml2</code>). Adding them to <code>$PKG_CONFIG_PATH</code> should fix this.
You will need those later to compile the "lxml" Python module if you want to use Python effects. First check what's installed and if they are missing from your MacPorts repository install them by doing:


<pre>port installed
Check out the source if you haven't already:
sudo port install libxml2 libxslt</pre>


== Pre-compiling the Python modules  ==
<syntaxhighlight lang="bash">git clone --recurse-submodules https://gitlab.com/inkscape/inkscape.git</syntaxhighlight>


If you cannot use the pre-built Python modules from [http://inkscape.modevia.com/macosx-snap/?C=M;O=D Modevia] (say, because you're using a different Python version) you need to search MacPorts for both "numpy" and "lxml" and install the ones suitable for the Python version active within MacPorts.
Then <code>cd inkscape</code> and follow the steps below.
<pre>port search lxml numpy</pre>


If you are using a more recent Python version (say, MacPython 2.6) you will need to compile both modules outside of MacPorts. Download both modules from [http://pypi.python.org PyPI] if they are available there for Python 2.6. At the time of editing (2008-12-01) however both modules were only available through SVN for Python 2.6.
Tested with:
* M1 MacBook Air with macOS 11.6 and Inkscape 1.2-dev
* M2 MacBook Air with macOS 13.0.1 and Inkscape 1.2.1, 1.2.x from git.
* M2 Mac Mini with macOS 14.2 and Inkscape 1.4-dev. (After adding pkg-config.)
* VM with macOS 15.1 and Inkscape 1.5-dev (master branch)


There are enough tutorials for building and installing the "numpy" module but building the "lxml" module deviates a little from the standard way, so here is the command you need:
<syntaxhighlight lang="bash">
<pre>cd /path/to/lxml/source
# use a clean Homebrew environment (optional)
sudo python setup.py install --with-xslt-config=/opt/local/bin/xslt-config \
LIBPREFIX="/opt/homebrew"
--with-xml2-config=/opt/local/bin/xml2-config</pre>
export PATH="$LIBPREFIX/bin:/usr/bin:/bin:/usr/sbin:/sbin"


This tells it to use the libxml2 and libxslt packages we installed earlier with MacPorts.
# keg-only libraries
export PKG_CONFIG_PATH="$LIBPREFIX/opt/icu4c/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$LIBPREFIX/opt/libsoup@2/lib/pkgconfig"


If you are compiling the Python modules outside of MacPorts you will need to make a mental note for after running the Inkscape.app building script (detailed later in this guide) to copy both the "lxml" and "numpy" dir from the standard installation destination (normally "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages") to the extensions folder inside the Inkscape.app bundle ("Inkscape.app/Contents/Resources/extensions").
# prevent picking up libxslt and libxml2 from the (wrong) SDK
This should take care of the "...needs fantastic libxml2 wrapper..." message when executing Python effects.
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$LIBPREFIX/opt/libxslt/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$LIBPREFIX/opt/libxml2/lib/pkgconfig"


== Setting the build environment ==
# where to install
MacPorts's hierarchy (/opt/local/) is not searched for libraries by default. Therefore, before the configuration starts, some environment variables need to be set. The environment variables are presented in bash syntax here.
PREFIX="$PWD/install-prefix"
<pre>export LIBPREFIX="/opt/local"
#  automake seach path
export CPATH="$LIBPREFIX/include"
#  configure search path
export CPPFLAGS="-I$LIBPREFIX/include"
export LDFLAGS="-L$LIBPREFIX/lib"
#  compiler arguments
export CFLAGS="-O3 -Wall"
export CXXFLAGS="$CFLAGS"
</pre>


You can also use <code>[http://en.wikipedia.org/wiki/Ccache ccache]</code> (<code>sudo port install ccache</code>) to speed up the compilation a bit. To do so, add compiler variables:
mkdir -p build
<pre>export CC="ccache gcc"
cd build
export CXX="ccache g++"</pre>


== Configuring ==
cmake \
If you compile Inkscape for the first time from an svn checkout you need to generate the configure script. Navigate to Inkscape's source directory and run:
    -G Ninja \
<pre>./autogen.sh</pre>
    -DCMAKE_SHARED_LINKER_FLAGS="-L$LIBPREFIX/lib" \
    -DCMAKE_EXE_LINKER_FLAGS="-L$LIBPREFIX/lib" \
    -DCMAKE_INSTALL_PREFIX=$PREFIX \
    -DCMAKE_C_COMPILER_LAUNCHER=ccache \
    -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
    -DWITH_DBUS=OFF \
    ..


Then run configure with the options <code>--disable-static --enable-shared</code> and <code>--prefix</code> which sets the directory where the build products are placed. It must be somewhere you have write access to.
ninja
<pre>./configure --disable-static --enable-shared --prefix=/path/to/build/products/</pre>
ninja install
</syntaxhighlight>


I you want to package Inkscape into a double-clickable <code>.app</code> bundle in order to access it like a regular OS X application (you probably want to), you need to add the option <code>--enable-osxapp</code>:
=Packaging=
<pre>./configure {...} --enable-osxapp</pre>


If you have loudmouth installed and you want to enable whiteboard functionality in Inkscape, add <code>--enable-inkboard</code>.
If <code>$PREFIX/bin/inkscape</code> works when executed and you want to turn it into an app or a DMG, have a look at the files inside the <code>inkscape/packaging/macos</code> directory. More info can be found on upstream mibap:


Other configuration options can be set, check the list of options by issuing:
* https://github.com/dehesselle/mibap
<pre>./configure --help</pre>


== Building and Installing ==
Follow the steps to install the toolset, package the app, and create a DMG. In case you use upstream mibap, you will get the app under <code>/Users/Shared/work/mibap-*/</code> and you will get a DMG file in the same place you ran <code>./build_inkscape.sh</code>.
Just run:
<pre>make
make install</pre>


== Creating an .app bundle ==
=See also=
Assuming that you have used the <code>--enable-osxapp</code> option during <code>configure</code>, navigate to Mac OS X packaging directory in Inkscape source code and use the automated script:
* [[Tracking Dependencies]]
<pre>cd packaging/macosx
* [[Extension requirements]]
./osx-app.sh -s -b /path/to/install/prefix/bin/inkscape -p ../../Info.plist</pre>
*[[Compiling Inkscape]]
The script copies Inkscape binary and all its dependencies into the app bundle. The <code>-s</code> options strips libraries from debugging information (the bundle is therefore smaller). Omit this option if you want to keep debugging info.
*[[Notes on Packaging for OS X]]
 
* https://github.com/valerioa/Inkscape-MacOS-Curated-Build
== Creating a disk image to distribute Inkscape ==
* [https://github.com/ipatch/homebrew-us-05/blob/master/inkscape/inkscape-building-for-macOS.md ipatch's collection of notes] about building Inkscape using Homebrew
Inkscape.app created at the previous step is completely independent from the original location of MacPorts libraries and can therefore be distributed. It will only work on your platform though (PPC or Intel) and incompatibilities are known between X11 versions on different major versions of OS X (Panther, Tiger and Leopard). The general rule is that versions are not backward compatible.
 
The most widespread way of distributing applications on Mac OS X is via .dmg images. You can created a dmg image of Inkscape, with a nice background and all, using the script:
<pre>./osx-dmg.sh -p Inkscape.app</pre>
in the packaging directory for Mac OS X (where your app bundle should be, otherwise modify the path to Inkscape.app).
 
== Automated build script ==
All essential steps are automated by a build script: <code>osx-build.sh</code>. It has built-in help so to know how to use it just type:
<pre>./osx-build.sh help</pre>
 
NB: Excluded steps involve Pre-compiliation of the Python modules and installing the additional nightly build features.
 
= Compiling a Universal Binary of Inkscape with X11, using MacPorts=
 
These instructions should work on both 10.4 and 10.5 machines with the latest Xcode version installed.
 
== Update Macport sources ==
 
The port descriptions in Macports do not currently all compile properly with their Universal variants.  For this reason, we currently use a modified set of some of the portfiles that will compile a universal libraries.  Work is being done to integrate these changes into Macports itself.
 
You can use our modified portfiles by adding our ports to your sources:
 
1. Checkout our ports directory:
<pre>svn co https://inkscape.svn.sourceforge.net/svnroot/inkscape/experimental/trunk/mjwybrow/ports ports</pre>
 
2. Edit your sources list to include this directory:
<pre>sudo vim /opt/local/etc/macports/sources.conf</pre>
And add the following line *before* the existing rsync source:
<pre>file:///Users/YOURUSERNAME/directory/to/ports</pre>
 
3. Run the portindex command in the checked-out port directory:
<pre>portindex</pre>
 
4. Run port sync
<pre>sudo port sync</pre>
 
== Build Universal dependencies ==
 
You should now be able to compile Inkscape's essential dependencies as Universal libraries on either 10.4 or 10.5,  by giving the "+universal" option for each, e.g.
<pre>sudo port -v install poppler +universal gtk2 +universal ...</pre>
 
If you already have non-universal versions of these ports installed you may need to deactivate the port and rebuild it, e.g.
<pre>sudo port -f uninstall cairo
sudo port clean cairo
sudo port -v install cairo +universal</pre>
 
== Build Universal Inkscape ==
 
First, Set your SDK, 10.5 for Leopard, 10.4u for TIger:
 
<CODE>export SDK=/Developer/SDKs/MacOSX10.5.sdk</code>  &nbsp; &nbsp; (For Leopard)<br />
<CODE>export SDK=/Developer/SDKs/MacOSX10.4u.sdk</code>  &nbsp; &nbsp;  (For Tiger)<br />
 
Then, set up your environment to point to the Macports libraries:
<pre>export MACPORTS="/opt/local"
export PATH=$MACPORTS/bin:$MACPORTS/sbin:/usr/X11R6/bin:/bin:/sbin:/usr/bin:/usr/local/bin:/usr/sbin
#  automake seach path
export CPATH="$MACPORTS/include"
#  configure search path
export CPPFLAGS="-I$MACPORTS/include"
export LDFLAGS="-L$MACPORTS/lib"
#  compiler arguments
export CFLAGS="-O3 -Wall -isysroot $SDK -arch ppc -arch i386"
export CXXFLAGS="$CFLAGS"</pre>
 
The final step is to configure and compile Inkscape.  Inkscape must be configured with the following options:
 
<code>--enable-osxapp</code> &nbsp; &nbsp;  Sets the correct path for Inkscape to be used from an .app bundle<br />
<code>--disable-dependency-tracking</code>  &nbsp; &nbsp; Dependency tracking can't be user when compiling universal binaries.
 
Inkscape can then be built (with make), installed, and packaged into a Universal .app bundle using the standard .app bundle building instruction above.
 
= Compiling Inkscape with native GTK using MacPorts [experimental] =
This process is very similar to compiling an X11 version of Inkscape except for the building of dependencies: need to build native versions of Inkscape dependencies. At the moment (2007-12-17) this process does not produce a usable version of Inkscape but the more people try to use it, the quicker the bugs will be ironed out!
 
== Native version of Inkscape dependencies ==
Thanks to the power of port "variants" and port "deactivation" you can install native versions of gtk, cairo, pango and such, alongside the regular X11 ones. To know which ports have a <code>quartz</code> or <code>no_x11</code> variant, use the command:
<pre>port list variant:quartz variant:no_x11</pre>
This will give you an idea of what need to be replaced.
 
Assuming your MacPorts tree has been already used to build regular versions of Inkscape, you first need to deactivate (suppress from the tree without really uninstalling) the X11 versions of gtk, cairo, cairomm and pango:
<pre>sudo port deactivate gtk2 cairo cairomm pango</pre>
 
Then install native variants:
<pre>sudo port install cairo +quartz+pdf+no_x11 cairomm +quartz pango +no_x11 poppler +quartz gtk2 +quartz</pre>
 
Rather than deactivating and reactivating ports, you can also keep two MacPorts trees side by side, provided you install the second one from source. Let say I want to install a new tree for native versions in /opt/local/native, I would do
<pre>export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin
cd ~/MacPorts-1.x.x/
./configure --prefix=/opt/local-native --with-tclpackage=/Library/Tcl/macports-native
make
sudo make install</pre>
Then you need to have only one version of the port command in the path at any time so you need to setup your .bashrc (or .bash_profile or .profile) accordingly. I use shell aliases to quickly and temporarily switch to the universal version:
<pre>alias portpathregular="export PATH=/opt/local/bin:/opt/local/sbin:/Developer/Tools:/usr/local/bin: \
/usr/X11R6/bin:/bin:/sbin:/usr/bin:/usr/sbin"
alias portpathuniv="export PATH=/opt/local-univ/bin:/opt/local-univ/sbin:/Developer/Tools:/usr/local/bin:  \
/usr/X11R6/bin:/bin:/sbin:/usr/bin:/usr/sbin"</pre>
NB: the \ are just to mark line continuation here, suppress them and put everything in one line.
 
== Install the rest ==
Eventually, follow the regular install procedure for the rest:
<pre>sudo port install libxslt boost boehmgc gtkmm lcms intltool popt</pre>
If your MacPorts tree was already ready to compile Inkscape, you should not need to reinstall anything, with the possible exception of gtkmm, which may need to be rebuilt against the native version of gtk rather than against the X11 one (please someone confirm this).
 
Get inkscape source code and go in the mac OS X specific packaging directory
<pre>cd packaging/macosx</pre>
There edit <code>osx-build.sh</code> to remove the configure option <code>--enable-osxapp</code> because it puts inkscape in a .app bundle where it is started together with X11, which would defeat the purpose of this native compilation. You can also specify an alternative install prefix if you want. Then
<pre>./osx-build.sh u a c b i</pre>
and a native version of Inkscape is installed in the prefix you specified or in the <code>Build/bin</code> directory of Inkscape's source code. You can test it by
<pre> cd ../../Build/bin/
./inkscape</pre>
 
NB: if you compiled a GTK theme engine against your old GTK install (i.e. the one with X11) and try to use it with the new install, it will complain, so edit <code>~/.gtkrc-2.0</code> to remove the offending theme or recompile it with the new native GTK.
 
= Compiling Inkscape with native GTK using the all in one build script [experimental] =
 
To build a native-GTK build of Inkscape, GTK and some of its dependencies must be built with special options. You can do this using the build-gtk.sh script from the Inkscape repository (it's in packaging/macosx/native-gtk/).  This is a modified version of the Imendio native build script, found with instructions on this page:
http://developer.imendio.com/projects/gtk-macosx/build-instructions
 
This process is relatively untested. If you have any troubles using this process then please report them to Michael Wybrow (mjwybrow on sourceforge).
 
The process is:
<pre>export PREFIX=/your/install/prefix
./build-gtk bootstrap
./build-gtk build inkscape
</pre>
 
 
= Enabling python effects =
moved to [[GettingEffectsWorking]]. They should work out of the box in the new versions anyway.
 
= Links =
 
== User Examples ==
* Adam Strzeleki has outlined some improvements to this process on the Inkscape [http://www.nabble.com/Inkscape-native-Mac-OS-X-build---look-improvements-td14733036.html email list]. See his screenshot from January 10, 2008 [http://www.nabble.com/attachment/14733036/1/Inkscape%20OSX%20PL.gif here].
* JiHO has a video of his builds [http://jo.irisson.free.fr/?p=34 here] and [http://jo.irisson.free.fr/?p=62 here].
 
== Apple Documentation ==
* [http://developer.apple.com/documentation/MacOSX/Conceptual/BPRuntimeConfig/BPRuntimeConfig.html Introduction to Runtime Configuration] Covers the Info.plist files, Preferences, Environment variables and has a list of the most important Properties that the Property List should contain.
 
== Packaging ==
 
* [http://www.sveinbjorn.org/platypus Sveinbjorn Thordarson's Website] The author of Platypus, the Script Exec wrapper that launches the Inkscape binary.
* [http://freespace.ausgamers.com/2005/02/creating-os-x-application-bundles-step.html  Creating OS X application bundles step by step] Covers the bundle concepts, copying libraries into the bundle, editing libraries with the install_name_tool, the Info.plist file and adding an icon.
* [http://java.sun.com/developer/technicalArticles/JavaLP/JavaToMac3/ Bringing your Java Application to Mac OS X] I would regard this a little dated, and the detail is (unsurprisingly) Java-related, but it is a gentle introduction to the role of the .app bundle and give a most clear account of how to create one.
* The [http://gimp-app.sourceforge.net/gimp.app.howto.txt Gimp .app Howto] This is a very bare document, and would be of little help to you if you were new to making packages. Note that it seems to refer to a more mature Clipboard technique and Online help than we currently have; and we ought to move to parity in these areas.


[[Category:Developer Documentation]]
[[Category:Developer Documentation]]

Latest revision as of 02:45, 31 October 2024

Section about MacPorts IS OUTDATED AND UNMAINTAINED! Section about HomeBrew IS UP TO DATE as of Oct 30, 2024

Using MacPorts

If you can build successfully with MacPorts, please update this file and remove above comment.

  1. Download and install MacPorts
  2. Edit the MacPorts variants config (optional).
    Add this line to /opt/local/etc/macports/variants.conf
    -x11 +quartz
  3. In Terminal (Applications>Utilities>Terminal) type
    sudo port install \
         adwaita-icon-theme \
         boehmgc \
         boost \
         cairo \
         ccache \
         cmake \
         double-conversion \
         gdl3 \
         gettext \
         gsl \
         gtkmm3 \
         gtk-osx-application-gtk3 \
         lcms2 \
         libsoup \
         libxslt \
         ninja \
         poppler \
         potrace \
         py-lxml \
         py-numpy \
         -x11 +quartz
    
  4. In Terminal, get Inkscape
    git clone --recurse-submodules https://gitlab.com/inkscape/inkscape.git
    
  5. And build inkscape
    # use a clean MacPorts environment (optional)
    LIBPREFIX="/opt/local"
    export PATH="$LIBPREFIX/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    
    # where to install
    PREFIX="$PWD/install-prefix"
    
    # where to build
    mkdir build
    cd build
    
    cmake \
        -G Ninja \
        -DCMAKE_PREFIX_PATH="$LIBPREFIX" \
        -DCMAKE_INSTALL_PREFIX="$PREFIX" \
        -DCMAKE_C_COMPILER_LAUNCHER=ccache \
        -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
        -DWITH_OPENMP=OFF \
        ../inkscape
    
    ninja
    ninja install
    

    Note: Using ccache and ninja is not required, but very common because it speeds up compilation.

  6. Run Inkscape
    $PREFIX/bin/inkscape
    

Using Homebrew

Prerequisites:

  • Xcode (AppStore)
  • Xcode command line tools (xcode-select --install)
  • HomeBrew

If you are using Homebrew instead, you can still use the above guidelines with small modifications. (Make sure you don't have any MacPorts stuff in your PATH.)

List of packages to install with brew (for Inkscape on master branch using GTK4):

brew install \
    adwaita-icon-theme \
    bdw-gc \
    boost \
    cairomm \
    ccache \
    cmake \
    double-conversion \
    gettext \
    gsl \
    gspell \
    gtkmm4 \
    gtksourceview5 \
    imagemagick \
    intltool \
    lcms2 \
    libomp \
    libsoup@2 \
    libxslt \
    ninja \
    pkg-config \
    poppler \
    potrace

You may substitute imagemagick with graphicsmagick.

Some keg-only libraries need to be added to $PKG_CONFIG_PATH

Some libraries can cause trouble if they are picked up from the SDK instead of Homebrew (observed with libxslt and libxml2). Adding them to $PKG_CONFIG_PATH should fix this.

Check out the source if you haven't already:

git clone --recurse-submodules https://gitlab.com/inkscape/inkscape.git

Then cd inkscape and follow the steps below.

Tested with:

  • M1 MacBook Air with macOS 11.6 and Inkscape 1.2-dev
  • M2 MacBook Air with macOS 13.0.1 and Inkscape 1.2.1, 1.2.x from git.
  • M2 Mac Mini with macOS 14.2 and Inkscape 1.4-dev. (After adding pkg-config.)
  • VM with macOS 15.1 and Inkscape 1.5-dev (master branch)
# use a clean Homebrew environment (optional)
LIBPREFIX="/opt/homebrew"
export PATH="$LIBPREFIX/bin:/usr/bin:/bin:/usr/sbin:/sbin"

# keg-only libraries
export PKG_CONFIG_PATH="$LIBPREFIX/opt/icu4c/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$LIBPREFIX/opt/libsoup@2/lib/pkgconfig"

# prevent picking up libxslt and libxml2 from the (wrong) SDK
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$LIBPREFIX/opt/libxslt/lib/pkgconfig"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$LIBPREFIX/opt/libxml2/lib/pkgconfig"

# where to install
PREFIX="$PWD/install-prefix"

mkdir -p build
cd build

cmake \
    -G Ninja \
    -DCMAKE_SHARED_LINKER_FLAGS="-L$LIBPREFIX/lib" \
    -DCMAKE_EXE_LINKER_FLAGS="-L$LIBPREFIX/lib" \
    -DCMAKE_INSTALL_PREFIX=$PREFIX \
    -DCMAKE_C_COMPILER_LAUNCHER=ccache \
    -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
    -DWITH_DBUS=OFF \
    ..

ninja
ninja install

Packaging

If $PREFIX/bin/inkscape works when executed and you want to turn it into an app or a DMG, have a look at the files inside the inkscape/packaging/macos directory. More info can be found on upstream mibap:

Follow the steps to install the toolset, package the app, and create a DMG. In case you use upstream mibap, you will get the app under /Users/Shared/work/mibap-*/ and you will get a DMG file in the same place you ran ./build_inkscape.sh.

See also