Commit 8b3c14c0 authored by Bernhard Stegmaier's avatar Bernhard Stegmaier Committed by Wayne Stambaugh
Browse files

OSX build improvements.

* Compile all binaries into a single application bundle.
* Use CMake BundleUtilities to make application bundle relocatable.
* Restructure build output to directly create an image file.
* Fix default search paths.
* Set KIGITHUB environment variable.
* Added patch to fix wxWidgets so names for OSX.
parent e6274f70
Loading
Loading
Loading
Loading
+37 −5
Original line number Original line Diff line number Diff line
@@ -312,7 +312,7 @@ set( KICAD_BIN bin
set( KICAD_FP_LIB_INSTALL_PATH "${CMAKE_INSTALL_PREFIX}"
set( KICAD_FP_LIB_INSTALL_PATH "${CMAKE_INSTALL_PREFIX}"
     CACHE PATH "Default path where footprint libraries are installed." )
     CACHE PATH "Default path where footprint libraries are installed." )


if( UNIX )
if( UNIX AND NOT APPLE )
    # Everything without leading / is relative to CMAKE_INSTALL_PREFIX.
    # Everything without leading / is relative to CMAKE_INSTALL_PREFIX.
    set( KICAD_PLUGINS lib/kicad/plugins
    set( KICAD_PLUGINS lib/kicad/plugins
        CACHE PATH "Location of KiCad plugins." )
        CACHE PATH "Location of KiCad plugins." )
@@ -339,6 +339,38 @@ set( KICAD_DEMOS ${KICAD_DATA}/demos
set( KICAD_TEMPLATE ${KICAD_DATA}/template
set( KICAD_TEMPLATE ${KICAD_DATA}/template
    CACHE PATH "Location of KiCad template files." )
    CACHE PATH "Location of KiCad template files." )


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

    # everything provided with the application bundle goes into
    # kicad.app/Contents/SharedSupport => accessible via GetDataDir()
    # everything else to the .dmg image
    set( KICAD_DATA ${CMAKE_INSTALL_PREFIX}/kicad.app/Contents/SharedSupport
        CACHE PATH "Location of KiCad data files." FORCE )
    set( KICAD_PLUGINS ${KICAD_DATA}/plugins
        CACHE PATH "Location of KiCad plugins." FORCE )
    set( KICAD_DOCS doc
        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
        CACHE PATH "Location of KiCad demo files." FORCE )

    # 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( 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()

mark_as_advanced( KICAD_BIN
mark_as_advanced( KICAD_BIN
    KICAD_PLUGINS
    KICAD_PLUGINS
    KICAD_DATA
    KICAD_DATA
@@ -397,10 +429,10 @@ add_custom_target( lib-dependencies )


# Only download and build all dependencies from source on OSX if the user specifically requests
# Only download and build all dependencies from source on OSX if the user specifically requests
# it.  Otherwise, respect the developers wishes to use the dependencies already installed on
# it.  Otherwise, respect the developers wishes to use the dependencies already installed on
# their systme.
# their system
if( APPLE AND USE_OSX_DEPS_BUILDER )
if( APPLE AND USE_OSX_DEPS_BUILDER )


    # This should be built in all cases, if swig exec is not avaiable
    # This should be built in all cases, if swig exec is not available
    # will be impossible also enable SCRIPTING being for PCBNEW required immediately
    # will be impossible also enable SCRIPTING being for PCBNEW required immediately


    include( download_pcre )
    include( download_pcre )
@@ -570,7 +602,7 @@ if( KICAD_SCRIPTING OR KICAD_SCRIPTING_MODULES )
            )
            )


        if( NOT PYTHON_SITE_PACKAGE_PATH )
        if( NOT PYTHON_SITE_PACKAGE_PATH )
            message( FATAL_ERROR "Error occurred while attemping to find the Python site library path." )
            message( FATAL_ERROR "Error occurred while attempting to find the Python site library path." )
        endif()
        endif()
    endif()
    endif()


@@ -733,7 +765,7 @@ endif()
###
###
# FreeDesktop .desktop and MIME resources
# FreeDesktop .desktop and MIME resources
###
###
if( UNIX )
if( UNIX AND NOT APPLE )


    # Set paths
    # Set paths
    set( UNIX_MIME_DIR resources/linux/mime )
    set( UNIX_MIME_DIR resources/linux/mime )
+147 −60
Original line number Original line Diff line number Diff line
Compiling KiCad on Apple Mac OS X
Compiling KiCad on Apple Mac OS X
=================================
=================================
 First written: 2010-01-31
 by: Jerry Jacobs <xor.gate.engineering[at]gmail[dot]com>


 Modified at: 2014-02-07
Building on OSX is very similar to building on Linux. This document will provide a
 by: Marco Serantoni <marco.serantoni[at]gmail[dot]com>
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.
Snow Leopard

------------


Prerequisites
Requirements
-------------
  * XCode Tools    (http://developer.apple.com/tools/xcode)

  * bzr (bazaar)
Tools needed for building KiCad:
  * CMake          (http://www.cmake.org)
* XCode Tools

* bzr       - Bazaar version control system
  The build of Kicad for OSX is now easier than before.
* CMake     - Cross-platform make
  The building system will download and compile the needed libraries for you

  patching them accordly to the needs.
Optional tools:

* Doxygen   - Documentation system for several programming languages
Building Kicad with no support for Scripting

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Mandatory library dependencies needed to compile KiCad:

* GLEW      - The OpenGL Extension Wrangler Library
  The building needs to know if you want a static binary or a dynamic one
* cairo     - 2D graphics library
  Just set ONE of those two options KICAD_BUILD_STATIC or KICAD_BUILD_DYNAMIC
* wxWidgets - Cross-Platform GUI Library
  

  If you set KICAD_BUILD_DYNAMIC the building system will build all and include
Optional library dependencies, depends on used KiCad features
  the needed libraries for each executable in its bundle
* OpenSSL - The Open Source toolkit for SSL/TLS

  => Needed for github plugin
      cmake -DKICAD_BUILD_DYNAMIC=ON .

      make
All tools (except XCode, of course) and all dependencies except wxWidgets can be compiled

manually, but it is advised to install them using your favorite package manager for OSX
Building Kicad with support for Scripting
like MacPorts or Homebrew.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Depending on the package manager the development packages of the library dependencies
  Due some problems with some dependencies the build of this kind of binary is a bit 
may have to be installed (usually something like <pkg>-dev or <pkg>-devel).
  more complex, you should initially set KICAD_BUILD_DYNAMIC
Further, depending on the configuration of your package manager packages might have to
  then issue for example
be compiled with special flags/variants to support the correct architecture. E.g., some

packages of MacPorts need to have the "+universal" variant set to also include the
      cmake -DKICAD_BUILD_DYNAMIC=ON .
x86_64 variant that might be chosen automatically by KiCad build process.
      make swig


IMPORTANT:
  After successfully building you can set your KICAD_SCRIPTING* options (for example):
At the moment you *must not* use a wxWidgets version installed by any package manager.

KiCad on OSX needs overlay support and some other fixes, which are not yet contained in
      cmake -DKICAD_SCRIPTING=ON -DKICAD_SCRIPTING_WXPYTHON=ON -DKICAD_SCRIPTING_MODULES=ON .
mainline wxWidgets sources and builds.
      make


Install now the tools and library dependencies as mentioned above.
  The system will build all accordling your choices and package all in the bundle

  I know bundles will be huge, but those will be autosufficient.


Folder Structure
Building Kicad for other processors or Universal binaries
----------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


This documentation will use the following folder structure as an example, but it is not
   I wish remember you should set the processor like
mandatory to do it like that:

KiCad/
       cmake -DCMAKE_OSX_ARCHITECTURES="x86_64"
  +-- kicad/            KiCad source folder

  +-- build/            KiCad build folder
   for other platforms 
  +-- bin/              KiCad binaries folder

  +-- wx-src/           wxWidgets source folder
       cmake -DCMAKE_OSX_ARCHITECTURES="x86_64 -arch i386"
  +-- wx-build/         wxWidgets build folder
       cmake -DCMAKE_OSX_ARCHITECTURES="x86_64 -arch i386 -arch ppc"
  +-- wx-bin/           wxWidgets binaries folder


   I know some you should prefer use ; as separator, this will be accomplished soon

   keeping support for both the syntaxes
Get KiCad sources
-----------------

Create your work root "KiCad" wherever you like and sync KiCad sources to it:
  # mkdir KiCad
  # cd KiCad
  # bzr branch lp:kicad


Compiling wxWidgets
-------------------

Get wxWidgets sources from
  http://www.wxwidgets.org/downloads/
and unpack them to the wx-src folder.
It's recommended to use the latest stable (at the time of this writing 3.0.1) version.

Apply the patches needed for KiCad:
  # cd wx-src
  # 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_soname.patch

Configure:
  # cd ..
  # mkdir wx-build
  # cd wx-build
  # ../wx-src/configure \
      --prefix=`pwd`/../wx-bin \
      --with-opengl \
      --enable-aui \
      --enable-utf8 \
      --enable-html \
      --enable-stl \
      --with-libjpeg=builtin \
      --with-libpng=builtin \
      --with-regex=builtin \
      --with-libtiff=builtin \
      --with-zlib=builtin \
      --with-expat=builtin \
      --without-liblzma \
      --with-macosx-version-min=10.5 \
      CPPFLAGS="-stdlib=libstdc++” \
      LDFLAGS="-stdlib=libstdc++” \
      CC=clang \
      CXX=clang++

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 (without scripting support)
-------------------------------------------

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

Configure KiCad:
  # cd build
  # cmake ../kicad \
      -DCMAKE_C_COMPILER=clang \
      -DCMAKE_CXX_COMPILER=clang++ \
      -DwxWidgets_CONFIG_EXECUTABLE=../wx-bin/bin/wx-config \
      -DKICAD_SCRIPTING=OFF \
      -DKICAD_SCRIPTING_MODULES=OFF \
      -DKICAD_SCRIPTING_WXPYTHON=OFF \
      -DCMAKE_INSTALL_PREFIX=../bin \
      -DCMAKE_BUILD_TYPE=Release

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

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

Again, if everything went fine you will now have KiCad binaries in the "bin" 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
the KiCad binaries and/or support files (like demos or documentation) wherever you want.
+12 −19
Original line number Original line Diff line number Diff line
@@ -20,7 +20,7 @@ set_source_files_properties( bitmap2cmp_gui.cpp PROPERTIES
    COMPILE_DEFINITIONS     "COMPILING_DLL"
    COMPILE_DEFINITIONS     "COMPILING_DLL"
    )
    )


add_executable( bitmap2component WIN32 MACOSX_BUNDLE
add_executable( bitmap2component WIN32
    ${BITMAP2COMPONENT_SRCS}
    ${BITMAP2COMPONENT_SRCS}
    ${BITMAP2COMPONENT_RESOURCES}
    ${BITMAP2COMPONENT_RESOURCES}
    )
    )
@@ -33,10 +33,17 @@ target_link_libraries( bitmap2component
    potrace
    potrace
    )
    )


if( APPLE )
    # puts binaries into the *.app bundle while linking
    set_target_properties( bitmap2component PROPERTIES
        RUNTIME_OUTPUT_DIRECTORY ${OSX_BUNDLE_BUILD_BIN_DIR}
        )
else()
    install( TARGETS bitmap2component
    install( TARGETS bitmap2component
        DESTINATION ${KICAD_BIN}
        DESTINATION ${KICAD_BIN}
        COMPONENT binary
        COMPONENT binary
        )
        )
endif()




if( false )     # linker map with cross reference
if( false )     # linker map with cross reference
@@ -52,17 +59,3 @@ if( MINGW )
else()
else()
    set( BITMAP2COMPONENT_RESOURCES bitmap2component.rc )
    set( BITMAP2COMPONENT_RESOURCES bitmap2component.rc )
endif()
endif()


if( APPLE )
    set( BITMAP2COMPONENT_RESOURCES bitmap2component.icns )
    set_source_files_properties( "${CMAKE_CURRENT_SOURCE_DIR}/bitmap2component.icns" PROPERTIES
        MACOSX_PACKAGE_LOCATION Resources
        )
    set( MACOSX_BUNDLE_ICON_FILE bitmap2component.icns )
    set( MACOSX_BUNDLE_GUI_IDENTIFIER org.kicad-eda.bitmap2component )

    set_target_properties( bitmap2component PROPERTIES
        MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist
        )
endif()
+2 −0
Original line number Original line Diff line number Diff line
@@ -80,7 +80,9 @@ static void setSearchPaths( SEARCH_STACK* aDst, KIWAY::FACE_T aId )
        aDst->AddPaths( fn.GetPath() );
        aDst->AddPaths( fn.GetPath() );
    }
    }


#ifndef __WXMAC__
    aDst->AddPaths( wxT( "/usr/local/share" ) );
    aDst->AddPaths( wxT( "/usr/local/share" ) );
#endif


#if 1 && defined(DEBUG)
#if 1 && defined(DEBUG)
    aDst->Show( "kiface" );
    aDst->Show( "kiface" );
+18 −4
Original line number Original line Diff line number Diff line
@@ -26,10 +26,12 @@ void SystemDirsAppend( SEARCH_STACK* aSearchStack )
    // Otherwise don't set it.
    // Otherwise don't set it.
    maybe.AddPaths( wxGetenv( wxT( "KICAD" ) ) );
    maybe.AddPaths( wxGetenv( wxT( "KICAD" ) ) );


#ifndef __WXMAC__
    // This is from CMAKE_INSTALL_PREFIX.
    // This is from CMAKE_INSTALL_PREFIX.
    // Useful when KiCad is installed by `make install`.
    // Useful when KiCad is installed by `make install`.
    // Use as second ranked place.
    // Use as second ranked place.
    maybe.AddPaths( wxT( DEFAULT_INSTALL_PATH ) );
    maybe.AddPaths( wxT( DEFAULT_INSTALL_PATH ) );
#endif


    // Add the directory for the user-dependent, program specific, data files:
    // Add the directory for the user-dependent, program specific, data files:
    // Unix: ~/.appname
    // Unix: ~/.appname
@@ -37,6 +39,17 @@ void SystemDirsAppend( SEARCH_STACK* aSearchStack )
    // Mac: ~/Library/Application Support/appname
    // Mac: ~/Library/Application Support/appname
    maybe.AddPaths( wxStandardPaths::Get().GetUserDataDir() );
    maybe.AddPaths( wxStandardPaths::Get().GetUserDataDir() );


#ifdef __WXMAC__
    // global machine specific application data
    maybe.AddPaths( wxT( "/Library/Application Support/kicad" ) );

    // Dir of the global (not user-specific), application specific, data files.
    // From wx docs:
    // Unix: prefix/share/appname
    // Windows: the directory where the executable file is located
    // Mac: appname.app/Contents/SharedSupport bundle subdirectory
    maybe.AddPaths( wxStandardPaths::Get().GetDataDir() );
#else
    {
    {
        // Should be full path to this program executable.
        // Should be full path to this program executable.
        wxString   bin_dir = Pgm().GetExecutablePath();
        wxString   bin_dir = Pgm().GetExecutablePath();
@@ -77,12 +90,10 @@ void SystemDirsAppend( SEARCH_STACK* aSearchStack )
     */
     */
#if defined(__MINGW32__)
#if defined(__MINGW32__)
    maybe.AddPaths( wxGetenv( wxT( "PROGRAMFILES" ) ) );
    maybe.AddPaths( wxGetenv( wxT( "PROGRAMFILES" ) ) );
#elif __WXMAC__
    maybe.AddPaths( wxString( wxGetenv( wxT( "HOME" ) ) ) + wxT( "/Library/Application Support" ) );
    maybe.AddPaths( wxT( "/Library/Application Support" ) );
#else
#else
    maybe.AddPaths( wxGetenv( wxT( "PATH" ) ) );
    maybe.AddPaths( wxGetenv( wxT( "PATH" ) ) );
#endif
#endif
#endif


#if defined(DEBUG) && 0
#if defined(DEBUG) && 0
    maybe.Show( "maybe wish list" );
    maybe.Show( "maybe wish list" );
@@ -96,6 +107,7 @@ void SystemDirsAppend( SEARCH_STACK* aSearchStack )
    {
    {
        wxFileName fn( maybe[i], wxEmptyString );
        wxFileName fn( maybe[i], wxEmptyString );


#ifndef __WXMAC__
        if( fn.GetPath().AfterLast( fn.GetPathSeparator() ) == wxT( "bin" ) )
        if( fn.GetPath().AfterLast( fn.GetPathSeparator() ) == wxT( "bin" ) )
        {
        {
            fn.RemoveLastDir();
            fn.RemoveLastDir();
@@ -103,9 +115,11 @@ void SystemDirsAppend( SEARCH_STACK* aSearchStack )
            if( !fn.GetDirCount() )
            if( !fn.GetDirCount() )
                continue;               // at least on linux
                continue;               // at least on linux
        }
        }
#endif


        aSearchStack->AddPaths( fn.GetPath() );
        aSearchStack->AddPaths( fn.GetPath() );


#ifndef __WXMAC__
        fn.AppendDir( wxT( "kicad" ) );
        fn.AppendDir( wxT( "kicad" ) );
        aSearchStack->AddPaths( fn.GetPath() );     // add maybe[i]/kicad
        aSearchStack->AddPaths( fn.GetPath() );     // add maybe[i]/kicad


@@ -120,6 +134,7 @@ void SystemDirsAppend( SEARCH_STACK* aSearchStack )


        fn.AppendDir( wxT( "kicad" ) );
        fn.AppendDir( wxT( "kicad" ) );
        aSearchStack->AddPaths( fn.GetPath() );     // add maybe[i]/share/kicad
        aSearchStack->AddPaths( fn.GetPath() );     // add maybe[i]/share/kicad
#endif
    }
    }


#if defined(DEBUG) && 0
#if defined(DEBUG) && 0
@@ -127,4 +142,3 @@ void SystemDirsAppend( SEARCH_STACK* aSearchStack )
    aSearchStack->Show( __func__ );
    aSearchStack->Show( __func__ );
#endif
#endif
}
}
Loading