Commit b8d1789a authored by Berhnard Stegmaier's avatar Berhnard Stegmaier Committed by Wayne Stambaugh
Browse files

OSX build fixes and improvements.

* Fix creation of single app bundle with respect to scripting support.
* Cleanup scripting search paths for OSX.
* Fix some small CMake bugs from previous OSX build change.
* Optimize bundle file structure to be consistent with Apple specs.
* Add helper script for compiling wxWidgets and wxPython
* Update OSX build instructions.
parent 0b2cadbc
Loading
Loading
Loading
Loading
+32 −19
Original line number Original line Diff line number Diff line
@@ -340,35 +340,43 @@ set( KICAD_TEMPLATE ${KICAD_DATA}/template
    CACHE PATH "Location of KiCad template files." )
    CACHE PATH "Location of KiCad template files." )


if( APPLE )
if( APPLE )
    # Everything without leading / is relative to CMAKE_INSTALL_PREFIX.
    # everything without leading / is relative to CMAKE_INSTALL_PREFIX.
    # CMAKE_INSTALL_PREFIX is root of .dmg image
    # CMAKE_INSTALL_PREFIX is root of .dmg image
    set( KICAD_BIN ${CMAKE_INSTALL_PREFIX}
    set( KICAD_BIN ${CMAKE_INSTALL_PREFIX}
        CACHE PATH "Location of KiCad binaries." FORCE )
        CACHE PATH "Location of KiCad binaries." FORCE )


    # some paths to single app bundle
    set( OSX_BUNDLE_MAIN "kicad.app" )
    set( OSX_BUNDLE_BIN_DIR "Contents/MacOS" )
    set( OSX_BUNDLE_LIB_DIR "Contents/Frameworks" )
    set( OSX_BUNDLE_KIFACE_DIR "Contents/Plugins" )
    set( OSX_BUNDLE_SUP_DIR "Contents/SharedSupport" )
    set( OSX_BUNDLE_BUILD_DIR "${CMAKE_BINARY_DIR}/kicad/${OSX_BUNDLE_MAIN}" )
    set( OSX_BUNDLE_BUILD_BIN_DIR "${OSX_BUNDLE_BUILD_DIR}/${OSX_BUNDLE_BIN_DIR}" )
    set( OSX_BUNDLE_BUILD_LIB_DIR "${OSX_BUNDLE_BUILD_DIR}/${OSX_BUNDLE_LIB_DIR}" )
    set( OSX_BUNDLE_BUILD_KIFACE_DIR "${OSX_BUNDLE_BUILD_DIR}/${OSX_BUNDLE_KIFACE_DIR}" )
    set( OSX_BUNDLE_INSTALL_DIR "${KICAD_BIN}/${OSX_BUNDLE_MAIN}" )
    set( OSX_BUNDLE_INSTALL_BIN_DIR "${OSX_BUNDLE_INSTALL_DIR}/${OSX_BUNDLE_BIN_DIR}" )
    set( OSX_BUNDLE_INSTALL_LIB_DIR "${OSX_BUNDLE_INSTALL_DIR}/${OSX_BUNDLE_LIB_DIR}" )
    set( OSX_BUNDLE_INSTALL_KIFACE_DIR "${OSX_BUNDLE_INSTALL_DIR}/${OSX_BUNDLE_KIFACE_DIR}" )

    # everything provided with the application bundle goes into
    # everything provided with the application bundle goes into
    # kicad.app/Contents/SharedSupport => accessible via GetDataDir()
    # kicad.app/Contents/SharedSupport => accessible via GetDataDir()
    # everything else to the .dmg image
    # everything else to the .dmg image
    set( KICAD_DATA ${CMAKE_INSTALL_PREFIX}/kicad.app/Contents/SharedSupport
    set( KICAD_DATA ${OSX_BUNDLE_INSTALL_DIR}/${OSX_BUNDLE_SUP_DIR}
        CACHE PATH "Location of KiCad data files." FORCE )
        CACHE PATH "Location of KiCad data files." FORCE )
    set( KICAD_TEMPLATE ${KICAD_DATA}/template
        CACHE PATH "Location of KiCad template files." FORCE )
    set( KICAD_PLUGINS ${KICAD_DATA}/plugins
    set( KICAD_PLUGINS ${KICAD_DATA}/plugins
        CACHE PATH "Location of KiCad plugins." FORCE )
        CACHE PATH "Location of KiCad plugins." FORCE )
    set( KICAD_DOCS doc
    set( KICAD_DOCS doc
        CACHE PATH "Location of KiCad documentation files." FORCE )
        CACHE PATH "Location of KiCad documentation files." FORCE )
    set( KICAD_TEMPLATE ${KICAD_DATA}/template
        CACHE PATH "Location of KiCad template files." FORCE )
    set( KICAD_DEMOS demos
    set( KICAD_DEMOS demos
        CACHE PATH "Location of KiCad demo files." FORCE )
        CACHE PATH "Location of KiCad demo files." FORCE )


    # used to set DEFAULT_FP_LIB_PATH in config.h.cmake, but then never used
    # used to set DEFAULT_FP_LIB_PATH in config.h.cmake, but then never used
    # set it to correct value just in case (see common.cpp)
    # set it to correct value just in case (see common.cpp)
    set( KICAD_FP_LIB_INSTALL_PATH "~/Library/Preferences/kicad" )
    set( KICAD_FP_LIB_INSTALL_PATH "~/Library/Preferences/kicad" )

    # path to binaries in single app bundle
    set( OSX_BUNDLE_BUILD_BIN_DIR "${CMAKE_BINARY_DIR}/kicad/kicad.app/Contents/MacOS" )
    set( OSX_BUNDLE_INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/kicad.app/Contents/MacOS" )

    # plugins/libs to additionally relocate during fixup_bundle (e.g., *.kiface added in subfolders)
    set( OSX_BUNDLE_PLUGINS "" )
endif()
endif()


mark_as_advanced( KICAD_BIN
mark_as_advanced( KICAD_BIN
@@ -400,13 +408,7 @@ add_definitions( -DWX_COMPATIBILITY )
# See line 41 of CMakeModules/FindwxWidgets.cmake
# See line 41 of CMakeModules/FindwxWidgets.cmake
set( wxWidgets_CONFIG_OPTIONS --static=no )
set( wxWidgets_CONFIG_OPTIONS --static=no )


# On Apple only wxwidgets 2.9 or higher doesn't need to find aui part of base
# Seems no longer needed on wx-3
if( APPLE AND ( KICAD_SCRIPTING OR KICAD_SCRIPTING_MODULES OR KICAD_SCRIPTING_WXPYTHON) )
    find_package( wxWidgets 3.0.0 COMPONENTS gl adv html core net base xml REQUIRED )
else()
find_package( wxWidgets 3.0.0 COMPONENTS gl aui adv html core net base xml REQUIRED )
find_package( wxWidgets 3.0.0 COMPONENTS gl aui adv html core net base xml REQUIRED )
endif()


# Include wxWidgets macros.
# Include wxWidgets macros.
include( ${wxWidgets_USE_FILE} )
include( ${wxWidgets_USE_FILE} )
@@ -606,7 +608,18 @@ if( KICAD_SCRIPTING OR KICAD_SCRIPTING_MODULES )
        endif()
        endif()
    endif()
    endif()


    set( PYTHON_DEST "${PYTHON_SITE_PACKAGE_PATH}" CACHE PATH "Python module install path." )
    if( NOT APPLE )
        set( PYTHON_DEST "${PYTHON_SITE_PACKAGE_PATH}"
            CACHE PATH "Python module install path."
            )
    else()
        # relative path for python in bundle
        set( PYTHON_LIB_DIR "python" )
        # install into bundle Frameworks folder
        set( PYTHON_DEST "${OSX_BUNDLE_BUILD_LIB_DIR}/${PYTHON_LIB_DIR}"
            CACHE PATH "Python module install path."
            )
    endif()
    mark_as_advanced( PYTHON_DEST )
    mark_as_advanced( PYTHON_DEST )
    message( STATUS "Python module install path: ${PYTHON_DEST}" )
    message( STATUS "Python module install path: ${PYTHON_DEST}" )


+99 −51
Original line number Original line Diff line number Diff line
Compiling KiCad on Apple Mac OS X
Compiling KiCad on Apple Mac OS X
=================================
=================================


Building on OSX is very similar to building on Linux. This document will provide a
Building on OSX is very similar to building on Linux. This document will provide
complete walk-through on what to do but it will focus on OSX specific things.
a complete walk-through on what to do but it will focus on OSX specific things.
See general documentation on non-OSX specific KiCad build switches, etc.
See general documentation on non-OSX specific KiCad build switches, etc.




@@ -21,25 +21,34 @@ Mandatory library dependencies needed to compile KiCad:
* GLEW      - The OpenGL Extension Wrangler Library
* GLEW      - The OpenGL Extension Wrangler Library
* cairo     - 2D graphics library
* cairo     - 2D graphics library
* wxWidgets - Cross-Platform GUI Library
* wxWidgets - Cross-Platform GUI Library
   OR
  wxPython  - A blending of the wxWidgets C++ class library with the Python
              programming language


Optional library dependencies, depends on used KiCad features
Optional library dependencies, depends on used KiCad features
* OpenSSL - The Open Source toolkit for SSL/TLS
* OpenSSL - The Open Source toolkit for SSL/TLS
  => Needed for github plugin
  => Needed for github plugin


All tools (except XCode, of course) and all dependencies except wxWidgets can be compiled
All tools (except XCode, of course) and all dependencies except wxWidgets/wxPython
manually, but it is advised to install them using your favorite package manager for OSX
can be compiled manually, but it is advised to install them using your favorite
like MacPorts or Homebrew.
package manager for OSX like MacPorts or Homebrew.
Depending on the package manager the development packages of the library dependencies
Depending on the package manager the development packages of the library
may have to be installed (usually something like <pkg>-dev or <pkg>-devel).
dependencies may have to be installed (usually something like <pkg>-dev or
Further, depending on the configuration of your package manager packages might have to
<pkg>-devel).
be compiled with special flags/variants to support the correct architecture. E.g., some
Further, depending on the configuration of your package manager packages might
packages of MacPorts need to have the "+universal" variant set to also include the
have to be compiled with special flags/variants to support the correct
x86_64 variant that might be chosen automatically by KiCad build process.
architecture. E.g., some packages of MacPorts need to have the "+universal"
variant set to also include the x86_64 variant that might be chosen
automatically by KiCad build process.


IMPORTANT:
IMPORTANT:
At the moment you *must not* use a wxWidgets version installed by any package manager.
At the moment you *must not* use a wxWidgets/wxPython version installed by any
KiCad on OSX needs overlay support and some other fixes, which are not yet contained in
package manager.
mainline wxWidgets sources and builds.
KiCad on OSX needs overlay support and some other fixes, which are not yet
contained in mainline wxWidgets/wxPython sources and builds.
If you don't use a patched wxWidgets you will get graphical artifacts (something
like a magnifying glass effect in the upper left corner of KiCad windows) or
KiCad will just crash on start (due to duplicate libraries).


Install now the tools and library dependencies as mentioned above.
Install now the tools and library dependencies as mentioned above.


@@ -47,15 +56,15 @@ Install now the tools and library dependencies as mentioned above.
Folder Structure
Folder Structure
----------------
----------------


This documentation will use the following folder structure as an example, but it is not
This documentation will use the following folder structure as an example, but it
mandatory to do it like that:
is not mandatory to do it like that:
KiCad/
KiCad/
  +-- kicad/            KiCad source folder
  +-- kicad/            KiCad source folder
  +-- build/            KiCad build folder
  +-- build/            KiCad build folder
  +-- bin/              KiCad binaries folder
  +-- bin/              KiCad binaries folder
  +-- wx-src/           wxWidgets source folder
  +-- wx-src/           wxWidgets/wxPython source folder
  +-- wx-build/         wxWidgets build folder
  +-- wx-build/         wxWidgets/wxPython build folder
  +-- wx-bin/           wxWidgets binaries folder
  +-- wx-bin/           wxWidgets/wxPython binaries folder




Get KiCad sources
Get KiCad sources
@@ -67,24 +76,46 @@ Create your work root "KiCad" wherever you like and sync KiCad sources to it:
  # bzr branch lp:kicad
  # bzr branch lp:kicad




Compiling wxWidgets
Compiling wxWidgets / wxPython
-------------------
------------------------------

If you don't intend to build KiCad with scripting support then you only need
wxWidgets, otherwise you need wxPython (which also contains wxWidgets).


Get wxWidgets sources from
Get wxWidgets sources from
  http://www.wxwidgets.org/downloads/
  http://www.wxwidgets.org/downloads/
and unpack them to the wx-src folder.
or wxPython sources from
It's recommended to use the latest stable (at the time of this writing 3.0.1) version.
  http://www.wxpython.org/download.php#source
and unpack it to the wx-src folder.
It is recommended to use the latest stable version. As of this writing this is
3.0.2 for wxWidgets or 3.0.1.1 for wxPython.

There is a little helper script osx_build_wx.sh in kicad/scripts that does all
the patching/configuring/compiling of wxWidgets or wxPython for you.
Go to your working root "KiCad" and run:
  # kicad/scripts/osx_build_wx.sh wx-src wx-bin kicad "-j4"

First parameter is the source folder of wxWidgets/wxPython, second parameter the
target folder for compiled binaries, third parameter is the kicad folder, and
the last optional parameter are make options used during the build (in this
case for building with 4 jobs in parallel).
The script will automatically detect if you are compiling wxWidgets or wxPython.
CAUTION: The script will erase existing wx-build and target folders (wx-bin)
without any confirmation!

If everything went fine during compilation you will now have a working
wxWidgets/wxPython installation in the wx-bin folder.
For building KiCad it is sufficient to keep the wx-bin folder.


Apply the patches needed for KiCad:
The script doesn't have to be used, the usual "configure/make/make install" will
  # cd wx-src
also work. If you do so, be sure to apply the patches needed for KiCad:
  # patch -p0 < ../kicad/patches/wxwidgets-3.0.0_macosx.patch
  # patch -p0 < ../kicad/patches/wxwidgets-3.0.0_macosx.patch
  # patch -p0 < ../kicad/patches/wxwidgets-3.0.0_macosx_bug_15908.patch
  # patch -p0 < ../kicad/patches/wxwidgets-3.0.0_macosx_bug_15908.patch
  # patch -p0 < ../kicad/patches/wxwidgets-3.0.0_macosx_soname.patch
  # patch -p0 < ../kicad/patches/wxwidgets-3.0.0_macosx_soname.patch
The same patches apply both for wxWidgets and for wxPython.


Configure:
The script uses the following configure command/options for wxWidgets known to
  # cd ..
work:
  # mkdir wx-build
  # cd wx-build
  # ../wx-src/configure \
  # ../wx-src/configure \
      --prefix=`pwd`/../wx-bin \
      --prefix=`pwd`/../wx-bin \
      --with-opengl \
      --with-opengl \
@@ -100,31 +131,22 @@ Configure:
      --with-expat=builtin \
      --with-expat=builtin \
      --without-liblzma \
      --without-liblzma \
      --with-macosx-version-min=10.5 \
      --with-macosx-version-min=10.5 \
      --enable-universal-binary=i386,x86_64 \
      CPPFLAGS="-stdlib=libstdc++" \
      CPPFLAGS="-stdlib=libstdc++" \
      LDFLAGS="-stdlib=libstdc++" \
      LDFLAGS="-stdlib=libstdc++" \
      CC=clang \
      CC=clang \
      CXX=clang++
      CXX=clang++
If you know what you are doing, you can of course use different settings.


Build & Install:
  # make
    ... will take some time ...
  # make install

If everything went fine you will now have a working wxWidgets installation in the wx-bin
folder.
For building KiCad it is sufficient to keep the wx-bin folder.
The above configuration of wxWidgets is known to work, if you know what you are doing
you of course can use different settings.



Compiling KiCad
Compiling KiCad (without scripting support)
---------------
-------------------------------------------


Change to your working root "KiCad" and create the build folder there:
Change to your working root "KiCad" and create the build folder there:
  # mkdir build
  # mkdir build

Configure KiCad:
  # cd build
  # cd build

Now, configure KiCad without scripting support:
  # cmake ../kicad \
  # cmake ../kicad \
      -DCMAKE_C_COMPILER=clang \
      -DCMAKE_C_COMPILER=clang \
      -DCMAKE_CXX_COMPILER=clang++ \
      -DCMAKE_CXX_COMPILER=clang++ \
@@ -135,16 +157,42 @@ Configure KiCad:
      -DCMAKE_INSTALL_PREFIX=../bin \
      -DCMAKE_INSTALL_PREFIX=../bin \
      -DCMAKE_BUILD_TYPE=Release
      -DCMAKE_BUILD_TYPE=Release


Now KiCad is configured using default features/build-switches without scripting support.
or, configure KiCad with scripting support:
See Documentation/compiling/build-config.txt for a list of all CMake options available
  # cmake ../kicad \
when compiling KiCad.
      -DCMAKE_C_COMPILER=clang \
      -DCMAKE_CXX_COMPILER=clang++ \
      -DwxWidgets_CONFIG_EXECUTABLE=../wx-bin/bin/wx-config \
      -DPYTHON_EXECUTABLE=`which python` \
      -DPYTHON_SITE_PACKAGE_PATH=`pwd`/../wx-bin/lib/python2.7/site-packages \
      -DKICAD_SCRIPTING=ON \
      -DKICAD_SCRIPTING_MODULES=ON \
      -DKICAD_SCRIPTING_WXPYTHON=ON \
      -DCMAKE_INSTALL_PREFIX=../bin \
      -DCMAKE_BUILD_TYPE=Release
Note, that depending on your python version the "python2.7" part of the
"-DPYTHON_SITE_PACKAGE_PATH" variable might have to be adjusted to what has
been generated when compiling/installing wxPython. If you want to use a specific
python, you can also specify it via "-DPYTHON_EXECUTABLE" instead of using
`which python` (this one will just detect/use you default python).

Now KiCad is configured using default features/build-switches.
See Documentation/compiling/build-config.txt for a list of all CMake options
available when compiling KiCad.


Build & Install:
Build & Install:
  # make
  # make
    ... will take some time ...
    ... will take some time ...
  # make install
  # make install


Again, if everything went fine you will now have KiCad binaries in the "bin" folder.
Again, if everything went fine you will now have KiCad binaries in the "bin"
KiCad application can be directly run from there to test.
folder. KiCad application can be directly run from there to test.
If everything is OK, you can create a .dmg image of your "bin" folder or just copy/install
If everything is OK, you can create a .dmg image of your "bin" folder or just
the KiCad binaries and/or support files (like demos or documentation) wherever you want.
copy/install the KiCad binaries and/or support files (like demos or
documentation) wherever you want.

If you resync to newer versions of KiCad you don't have to rebuild wxWidgets or
other dependencies.
CMake should pick up the changes automatically and build correctly. However, it
is advised that you make a clean build to be sure (just delete the build folder
and go again through the configure/build steps).
+5 −0
Original line number Original line Diff line number Diff line
@@ -114,6 +114,11 @@ const wxString KIWAY::dso_full_path( FACE_T aFaceId )
    }
    }


    wxFileName fn = wxStandardPaths::Get().GetExecutablePath();
    wxFileName fn = wxStandardPaths::Get().GetExecutablePath();
#ifdef __WXMAC__
    // we have the dso's in @executable_path/../Plugins in OSX bundle
    fn.RemoveLastDir();
    fn.AppendDir( wxT( "Plugins" ) );
#endif


    fn.SetName( name );
    fn.SetName( name );


+1 −4
Original line number Original line Diff line number Diff line
@@ -146,10 +146,7 @@ if( USE_KIWAY_DLLS )
            RUNTIME_OUTPUT_DIRECTORY ${OSX_BUNDLE_BUILD_BIN_DIR}
            RUNTIME_OUTPUT_DIRECTORY ${OSX_BUNDLE_BUILD_BIN_DIR}
            )
            )
        set_target_properties( cvpcb_kiface PROPERTIES
        set_target_properties( cvpcb_kiface PROPERTIES
            LIBRARY_OUTPUT_DIRECTORY ${OSX_BUNDLE_BUILD_BIN_DIR}
            LIBRARY_OUTPUT_DIRECTORY ${OSX_BUNDLE_BUILD_KIFACE_DIR}
            )
        set( OSX_BUNDLE_PLUGINS ${OSX_BUNDLE_PLUGINS} "${OSX_BUNDLE_INSTALL_BIN_DIR}/_cvpcb.kiface"
            PARENT_SCOPE
            )
            )
    else()
    else()
        install( TARGETS cvpcb
        install( TARGETS cvpcb
+1 −4
Original line number Original line Diff line number Diff line
@@ -297,10 +297,7 @@ if( USE_KIWAY_DLLS )
            RUNTIME_OUTPUT_DIRECTORY ${OSX_BUNDLE_BUILD_BIN_DIR}
            RUNTIME_OUTPUT_DIRECTORY ${OSX_BUNDLE_BUILD_BIN_DIR}
            )
            )
        set_target_properties( eeschema_kiface PROPERTIES
        set_target_properties( eeschema_kiface PROPERTIES
            LIBRARY_OUTPUT_DIRECTORY ${OSX_BUNDLE_BUILD_BIN_DIR}
            LIBRARY_OUTPUT_DIRECTORY ${OSX_BUNDLE_BUILD_KIFACE_DIR}
            )
        set( OSX_BUNDLE_PLUGINS ${OSX_BUNDLE_PLUGINS} "${OSX_BUNDLE_INSTALL_BIN_DIR}/_eeschema.kiface"
            PARENT_SCOPE
            )
            )
    else()
    else()
        install( TARGETS eeschema
        install( TARGETS eeschema
Loading