Difference between revisions of "CompilingMacOsX"

From Inkscape Wiki
Jump to navigation Jump to search
(→‎Native version of GTK and Cairo: finished the instructions to build inkscape natively with MP)
 
(153 intermediate revisions by 25 users not shown)
Line 1: Line 1:
== Requirements ==
__TOC__
To compile Inkscape from source you will need:
*Mac OS X > 10.3
*XCode Tools (with gcc)
*Inkscape's source code. You can get the [http://www.inkscape.org/download.php official release source code], a [http://inkscape.modevia.com/svn-snap/?M=D SVN snapshot] or a copy of the [http://www.inkscape.org/svn.php?lang=en SVN repository].
*Inkscape's dependencies: glibmm, gtkmm, lmcs, boehm gc... You can use a package distribution system ([http://www.finkproject.org/ Fink] or [http://www.macports.org/ MacPorts], formerly known as [http://darwinports.opendarwin.org/ DarwinPorts]) or Inkscape all-in-one universal build script to install them. Inkscape requires a recent version of gtk, hence only MacPorts can be used at the moment. Once Fink updates gtk it should not be a problem to use it.


== Compiling Inkscape with X11, using MacPorts ==
= Using MacPorts =


=== Installing dependencies ===
<ol>
You can use MacPorts to list Inkscape dependencies:
<li>Download and install [http://www.macports.org/ MacPorts]
<pre>port deps inkscape</pre>
<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"


Some are mandatory and you can install them with the command:
# where to install
<pre>sudo port install boehmgc gtkmm intltool libxslt lcms popt boost</pre>
PREFIX="$PWD/install-prefix"


Others provide additional functionality to Inkscape:
# where to build
* <code>gnome-vfs</code> : access to remote servers, in particular import from Open Clipart Library
mkdir build
* <code>aspell</code> : check spelling of text elements [Note: I have never seen it working on OS X]
cd build
* <code>libgnomeprintui</code>
* <code>loudmouth</code> : jabber library used by InkBoard
<pre>sudo port install gnome-vfs aspell libgnomeprintui loudmouth</pre>


=== For the impatient ===
cmake \
There is an automated build script for Mac OS X included with Inkscape source code, in the directory packaging/macosx. It has built-in help:
    -G Ninja \
<pre> cd packaging/macosx/
    -DCMAKE_PREFIX_PATH="$LIBPREFIX" \
./osx-build.sh help</pre>
    -DCMAKE_INSTALL_PREFIX="$PREFIX" \
    -DCMAKE_C_COMPILER_LAUNCHER=ccache \
    -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
    -DWITH_OPENMP=OFF \
    ../inkscape


Basically to update from svn, generate the configure script, configure, build, install and package Inkscape into a double clickable app bundle you just need to issue the command
ninja
<pre>./osx-build.sh update autogen configure build install -s package</pre>
ninja install
or more simply
</syntaxhighlight>
<pre>./osx-build.sh u a c b i -s p</pre>
''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.''
or even more simply
<li>Run Inkscape
<pre>./osx-build.sh all -s</pre>
<syntaxhighlight lang="bash">
$PREFIX/bin/inkscape
</syntaxhighlight>
</ol>


= Using Homebrew =


=== Step by step instructions ===
If you are using [https://brew.sh/ Homebrew] instead, you can still use the above guidelines with small modifications.
If you want to know what you are doing or to understand how the build script works, please read the following paragraphs.


==== Setting the build environment ====
List of '''packages''' to install with brew
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.
(for Inkscape 1.1):
<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:
<syntaxhighlight lang="bash">
<pre>export CC="ccache gcc"
brew install \
export CXX="ccache g++"</pre>
    adwaita-icon-theme \
    bdw-gc \
    boost \
    cairomm \
    ccache \
    cmake \
    double-conversion \
    gettext \
    gsl \
    gspell \
    gtk-mac-integration \
    gtkmm3 \
    imagemagick \
    intltool \
    lcms2 \
    libomp \
    libsoup@2 \
    libxslt \
    ninja \
    poppler \
    potrace
</syntaxhighlight>


==== Configuring ====
You may substitute <code>imagemagick</code> with <code>graphicsmagick</code>.
If you compile Inkscape for the first time from an svn checkout you probably need to build the configure script. Navigate to Inkscape's source directory and run:
<pre>./autogen.sh</pre>


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.
<code>gtk-mac-integration</code> is not needed with latest <code>1.2-dev</code>.
<pre>./configure --disable-static --enable-shared --prefix=/path/to/build/products/</pre>


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 do it), you need to add the option <code>--enable-osxapp</code>:
Some keg-only libraries need to be added to <code>$PKG_CONFIG_PATH</code>
<pre>./configure {...} --enable-osxapp</pre>


If you have loudmouth installed and you want to enable whiteboard functionality in Inkscape, add <code>--enable-inkboard</code>.
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.


Other configuration options can be set, check the list of options by issuing:
Check out the source if you haven't already:
<pre>./configure --help</pre>


==== Building and Installing ====
<syntaxhighlight lang="bash">git clone --recurse-submodules https://gitlab.com/inkscape/inkscape.git</syntaxhighlight>
Just run:
<pre>make
make install</pre>


==== Creating an .app bundle ====
Then <code>cd inkscape</code> and follow the steps below.
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:
<pre>cd packaging/macosx
./osx-app.sh -s /path/to/install/prefix/bin/inkscape ../Info.plist macosx</pre>
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.


==== Creating a disk image to distribute Inkscape ====
This was tested on an M1 MacBook Air with macOS 11.6 and Inkscape 1.2-dev, and an M2 MacBook Air with macOS 13.0.1 and Inkscape 1.2.1, 1.2.x from git.
Inkscape.app created at the previous step is completely independent from the original location of the libraries and can therefore be distributed. It will only work on one platform though (PPC or Intel): the one you built it on.
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, with the script:
<pre>./osx-dmg.sh</pre>
in the packaging directory for Mac OS X.


== Compiling a Universal Binary of Inkscape with X11, using the all-in-one build script ==
<syntaxhighlight lang="bash">
# use a clean Homebrew environment (optional)
LIBPREFIX="/opt/homebrew"
export PATH="$LIBPREFIX/bin:/usr/bin:/bin:/usr/sbin:/sbin"


To build a Universal Binary of Inkscape you also need to build Universal versions of all its dependencies (i.e., gtk+, cairo, pango, etc).  You can do this using the build-gtk.sh script from the Inkscape repository (it's in packaging/macosx/native-gtk/).
# 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"


This process is relatively untested, as it is only being used by Michael Wybrow  for official Inkscape release builds.  If you have any troubles using this process then please report them to Michael (mjwybrow on sourceforge).
# 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"


The process is:
# where to install
        export PREFIX=/your/install/prefix
PREFIX="$PWD/install-prefix"
        export UNIVERSAL_BUILD=Yes
        ./build-gtk bootstrap
        ./build-gtk build inkscape


mkdir -p build
cd build


== Compiling Inkscape with native GTK using MacPorts [experimental] ==
cmake \
This process will be very similar to compiling a X11 version of Inkscape except for the building of dependencies: you will need to build native versions of GTK and Cairo.
    -G Ninja \
At the moment (2007-09-31) 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!
    -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 \
    ..


=== Native version of GTK and Cairo ===
ninja
In theory you should be able to install a second MacPorts tree independent from your usual one (in /opt/local-native/ for example) but I did not manage to have the two cohabit so I would advise doing everything in your regular MacPorts tree. However, this should not be too much of a problem thanks to the power of port "variants" and port "deactivation".
ninja install
</syntaxhighlight>


You need to deactivate (suppress from the tree without really uninstalling) current version of gtk, cairo, cairomm and pango:
=Packaging=
<pre>sudo port deactivate gtk2 cairo cairomm</pre>
Then install native variants:
<pre>sudo port install cairo +quartz cairomm +quartz gtk2 +quartz</pre>
There is currently an incompatibility with gtk and cairo native ports. It is reported in this ticket at MacPorts [http://trac.macports.org/projects/macports/ticket/11745]
You need to edit the Portfile for gtk2 according to the Portfile patch:
<pre>sudo port edit gtk2</pre>
and add the patch to the <code>files</code> directory next to the Portfile. If you edit your file in a Cocoa editor just Command+click on the filename in the window title bar and this will bring a menu with the file hierarchy down to the Portfile. Go one step up and you're there. Otherwise the path is <pre>/opt/localquartz/var/macports/sources/rsync.macports.org/release/ports/x11/gtk2</pre>


=== Pango without X requirements ===
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:
Then you need to prevent Pango to try using Xft or X to render fonts. To do this kind of cleanly we'll create a new variant for Pango, called <code>no_x</code>. So:
<pre>sudo edit pango</pre>
and, after configure.arg add:
<pre>variant no_x description {Remove X and Xft rendering} {
configure.args-append --with-x=no
depends_lib-delete lib:libX11.6:XFree86 \
port:Xft2
}</pre>
The deactivate pango and install the new variant:
<pre>sudo port deactivate pango
sudo port install pango +no_x</pre>


=== Install the rest ===
* https://github.com/dehesselle/mibap
Eventually, follow the regular install procedure:
<pre>sudo port install libxslt boost boehmgc gtkmm lcms intltool popt</pre>
Get inkscape source code and go in the mac OS X specific packaging directory
<pre>cd packaging/macosx</pre>
There edit osx-build.sh 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.


== Compiling Inkscape as a native application (no X11) ==
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>.


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:
=See also=
http://developer.imendio.com/projects/gtk-macosx/build-instructions
* [[Tracking Dependencies]]
 
* [[Extension requirements]]
This process is relatively untested. If you have any troubles using this process then please report them to Michael Wybrow (mjwybrow on sourceforge).
*[[Compiling Inkscape]]
 
*[[Notes on Packaging for OS X]]
The process is:
* https://github.com/valerioa/Inkscape-MacOS-Curated-Build
      export PREFIX=/your/install/prefix
* [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
      ./build-gtk bootstrap
      ./build-gtk build inkscape
 
== Enabling python effects ==
Many "effects" in the Effect menu of Inkscape use python as a scripting language. Mac OS X ships with python but without some packages that Inkscape uses: [http://pyxml.sourceforge.net/ pyXML] (which will be suppressed as of version 0.46), [http://numpy.scipy.org/ numpy] and [http://codespeak.net/lxml/ lxml]
 
=== Binary packages ===
You can install a binary version compiled by us, downloadable with the development builds of Inkscape:
:http://inkscape.modevia.com/macosx-snap/?M=D
or in an official stable package for 0.44.PPC or later (their name contains "+python").
You need to copy the folders for pyXML (_xmlplus), numpy (numpy) and lxml (*lxml*.egg) to /System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages (there is a link in the dmg on which the folders can be dropped).
 
=== Compiling from source ===
If you prefer, you can install them from source, it is really easy.
 
==== pyXML ====
# download the source code from [http://sourceforge.net/project/showfiles.php?group_id=6473 sourceforge]
# unpack the <code>.tar.gz</code> file
# cd into the newly created directory
# set the variable <code>MACOSX_DEPLOYMENT_TARGET</code> to version of your operating system (10.3 for Panther, 10.4 for Tiger, 10.5 for Leopard. It probably won't work on previous systems). In bash syntax this means typing:<pre>export MACOSX_DEPLOYMENT_TARGET=10.?</pre>
# move the python files and build C extensions by just typing <pre>python setup.py build</pre>
# install (the install is system wide so you need administrator rights)<pre>sudo python setup.py install</pre>and type your password.
 
==== numpy and lxml====
# download the source code from [http://sourceforge.net/project/showfiles.php?group_id=1369&package_id=175103 sourceforge numpy repository] or [http://codespeak.net/lxml/index.html#download lxml download section]
# unpack the <code>.tar.gz</code> file
# cd into the newly created directory
# build C extensions and install (the install is system wide so you need administrator rights)<pre>sudo python setup.py install</pre>and type your password.
 
== Links ==
 
=== 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:51, 6 December 2022

Using MacPorts

  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

If you are using Homebrew instead, you can still use the above guidelines with small modifications.

List of packages to install with brew (for Inkscape 1.1):

brew install \
    adwaita-icon-theme \
    bdw-gc \
    boost \
    cairomm \
    ccache \
    cmake \
    double-conversion \
    gettext \
    gsl \
    gspell \
    gtk-mac-integration \
    gtkmm3 \
    imagemagick \
    intltool \
    lcms2 \
    libomp \
    libsoup@2 \
    libxslt \
    ninja \
    poppler \
    potrace

You may substitute imagemagick with graphicsmagick.

gtk-mac-integration is not needed with latest 1.2-dev.

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.

This was tested on an M1 MacBook Air with macOS 11.6 and Inkscape 1.2-dev, and an M2 MacBook Air with macOS 13.0.1 and Inkscape 1.2.1, 1.2.x from git.

# 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