From a4c59e6b97fd4d1a733cac88d4f2f2e8a352bce3 Mon Sep 17 00:00:00 2001 From: Bernhard Stegmaier Date: Thu, 16 Oct 2014 18:13:01 -0400 Subject: [PATCH] More OSX build fixes. * Many path related fixes. * Fix execution of external applications. * Update mac-osx.txt. * Add top-level links for standalone applications inside OSX bundle. * Fix document icons for Eeschema and pl_editor. * Create individual bundles for standalone applications inside the main application bundle. * Add usual 'site-packages' to python path in OSX bundle. * Fix name of OSX bundle plugin folder. --- bitmap2component/CMakeLists.txt | 35 ++++++++++++++++++-- common/common.cpp | 47 ++++++++++++++++++++++++++ common/systemdirsappend.cpp | 27 +++++++-------- include/common.h | 30 ++++++++++------- pcbnew/CMakeLists.txt | 58 ++++++++++++++++++++++++--------- 5 files changed, 153 insertions(+), 44 deletions(-) diff --git a/bitmap2component/CMakeLists.txt b/bitmap2component/CMakeLists.txt index d513c4379d..a088ffb222 100644 --- a/bitmap2component/CMakeLists.txt +++ b/bitmap2component/CMakeLists.txt @@ -20,7 +20,18 @@ set_source_files_properties( bitmap2cmp_gui.cpp PROPERTIES COMPILE_DEFINITIONS "COMPILING_DLL" ) -add_executable( bitmap2component WIN32 +if( APPLE ) + # setup bundle + 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.kicad ) + set( MACOSX_BUNDLE_NAME bitmap2component ) +endif() + +add_executable( bitmap2component WIN32 MACOSX_BUNDLE ${BITMAP2COMPONENT_SRCS} ${BITMAP2COMPONENT_RESOURCES} ) @@ -34,9 +45,27 @@ target_link_libraries( bitmap2component ) if( APPLE ) - # puts binaries into the *.app bundle while linking set_target_properties( bitmap2component PROPERTIES - RUNTIME_OUTPUT_DIRECTORY ${OSX_BUNDLE_BUILD_BIN_DIR} + MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist + ) + + # put individual bundle outside of main bundle as a first step + # will be pulled into the main bundle when creating main bundle + install( TARGETS bitmap2component + DESTINATION ${KICAD_BIN} + COMPONENT binary + ) + install( CODE " + # override default embedded path settings + ${OSX_BUNDLE_OVERRIDE_PATHS} + + # do all the work + include( BundleUtilities ) + fixup_bundle( ${KICAD_BIN}/bitmap2component.app/Contents/MacOS/bitmap2component + \"\" + \"\" + ) + " COMPONENT Runtime ) else() install( TARGETS bitmap2component diff --git a/common/common.cpp b/common/common.cpp index 88916764f0..88881fa386 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -343,3 +343,50 @@ wxString GetKicadConfigPath() return cfgpath.GetPath(); } + +#ifdef __WXMAC__ +wxString GetOSXKicadUserDataDir() +{ + // According to wxWidgets documentation for GetUserDataDir: + // Mac: ~/Library/Application Support/appname + wxFileName udir( wxStandardPaths::Get().GetUserDataDir(), wxEmptyString ); + + // Since appname is different if started via launcher or standalone binary + // map all to "kicad" here + udir.RemoveLastDir(); + udir.AppendDir( wxT( "kicad" ) ); + + return udir.GetPath(); +} + + +wxString GetOSXKicadMachineDataDir() +{ + return wxT( "/Library/Application Support/kicad" ); +} + + +wxString GetOSXKicadDataDir() +{ + // According to wxWidgets documentation for GetDataDir: + // Mac: appname.app/Contents/SharedSupport bundle subdirectory + wxFileName ddir( wxStandardPaths::Get().GetDataDir(), wxEmptyString ); + + // This must be mapped to main bundle for everything but kicad.app + const wxArrayString dirs = ddir.GetDirs(); + if( dirs[dirs.GetCount() - 3] != wxT( "kicad.app" ) ) + { + // Bundle structure resp. current path is + // kicad.app/Contents/Applications/.app/Contents/SharedSupport + // and will be mapped to + // kicad.app/Contents/SharedSupprt + ddir.RemoveLastDir(); + ddir.RemoveLastDir(); + ddir.RemoveLastDir(); + ddir.RemoveLastDir(); + ddir.AppendDir( wxT( "SharedSupport" ) ); + } + + return ddir.GetPath(); +} +#endif diff --git a/common/systemdirsappend.cpp b/common/systemdirsappend.cpp index fe254df670..3ea88ad255 100644 --- a/common/systemdirsappend.cpp +++ b/common/systemdirsappend.cpp @@ -26,30 +26,27 @@ void SystemDirsAppend( SEARCH_STACK* aSearchStack ) // Otherwise don't set it. maybe.AddPaths( wxGetenv( wxT( "KICAD" ) ) ); -#ifndef __WXMAC__ +#ifdef __WXMAC__ + // Add the directory for the user-dependent, program specific data files. + maybe.AddPaths( GetOSXKicadUserDataDir() ); + + // Global machine specific application data + maybe.AddPaths( GetOSXKicadMachineDataDir() ); + + // Global application specific data files inside bundle + maybe.AddPaths( GetOSXKicadDataDir() ); +#else // This is from CMAKE_INSTALL_PREFIX. // Useful when KiCad is installed by `make install`. // Use as second ranked place. 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. + // According to wxWidgets documentation: // Unix: ~/.appname // Windows: C:\Documents and Settings\username\Application Data\appname - // Mac: ~/Library/Application Support/appname 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. wxString bin_dir = Pgm().GetExecutablePath(); diff --git a/include/common.h b/include/common.h index ad9c970d74..1c1cb3a4f1 100644 --- a/include/common.h +++ b/include/common.h @@ -88,7 +88,6 @@ enum pseudokeys { #define PCB_CALCULATOR_EXE wxT( "pcb_calculator.exe" ) #define PL_EDITOR_EXE wxT( "pl_editor.exe" ) #else -#ifndef __WXMAC__ #define CVPCB_EXE wxT( "cvpcb" ) #define PCBNEW_EXE wxT( "pcbnew" ) #define EESCHEMA_EXE wxT( "eeschema" ) @@ -96,16 +95,6 @@ enum pseudokeys { #define BITMAPCONVERTER_EXE wxT( "bitmap2component" ) #define PCB_CALCULATOR_EXE wxT( "pcb_calculator" ) #define PL_EDITOR_EXE wxT( "pl_editor" ) -#else -// All binaries are now in kicad.app bundle -#define CVPCB_EXE wxT( "kicad.app/Contents/MacOS/cvpcb" ) -#define PCBNEW_EXE wxT( "kicad.app/Contents/MacOS/pcbnew" ) -#define EESCHEMA_EXE wxT( "kicad.app/Contents/MacOS/eeschema" ) -#define GERBVIEW_EXE wxT( "kicad.app/Contents/MacOS/gerbview" ) -#define BITMAPCONVERTER_EXE wxT( "kicad.app/Contents/MacOS/bitmap2component" ) -#define PCB_CALCULATOR_EXE wxT( "kicad.app/Contents/MacOS/pcb_calculator" ) -#define PL_EDITOR_EXE wxT( "kicad.app/Contents/MacOS/pl_editor" ) -# endif #endif @@ -643,5 +632,24 @@ wxConfigBase* GetNewConfig( const wxString& aProgName ); */ wxString GetKicadConfigPath(); +#ifdef __WXMAC__ +/** + * OSX specific function GetOSXKicadUserDataDir + * @return A wxString pointing to the user data directory for Kicad + */ +wxString GetOSXKicadUserDataDir(); + +/** + * OSX specific function GetOSXMachineDataDir + * @return A wxString pointing to the machine data directory for Kicad + */ +wxString GetOSXKicadMachineDataDir(); + +/** + * OSX specific function GetOSXKicadDataDir + * @return A wxString pointing to the bundle data directory for Kicad + */ +wxString GetOSXKicadDataDir(); +#endif #endif // INCLUDE__COMMON_H_ diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index 7d2e506e4c..23538faef5 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -473,6 +473,22 @@ if( MINGW ) mingw_resource_compiler( pcbnew ) endif() + +if( APPLE ) + # setup bundle + set( PCBNEW_RESOURCES pcbnew.icns pcbnew_doc.icns ) + set_source_files_properties( "${CMAKE_CURRENT_SOURCE_DIR}/pcbnew.icns" PROPERTIES + MACOSX_PACKAGE_LOCATION Resources + ) + set_source_files_properties( "${CMAKE_CURRENT_SOURCE_DIR}/pcbnew_doc.icns" PROPERTIES + MACOSX_PACKAGE_LOCATION Resources + ) + set( MACOSX_BUNDLE_ICON_FILE pcbnew.icns ) + set( MACOSX_BUNDLE_GUI_IDENTIFIER org.kicad-eda.kicad ) + set( MACOSX_BUNDLE_NAME pcbnew ) +endif() + + # Create a C++ compilable string initializer containing html text into a *.h file: add_custom_command( OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/dialogs/dialog_freeroute_exchange_help_html.h @@ -513,7 +529,7 @@ if( USE_KIWAY_DLLS ) #if( false ) # a very small program launcher for pcbnew_kiface - add_executable( pcbnew WIN32 + add_executable( pcbnew WIN32 MACOSX_BUNDLE ../common/single_top.cpp ${PCBNEW_RESOURCES} ) @@ -593,13 +609,32 @@ if( USE_KIWAY_DLLS ) # these 2 binaries are a matched set, keep them together: if( APPLE ) - # puts binaries into the *.app bundle while linking set_target_properties( pcbnew PROPERTIES - RUNTIME_OUTPUT_DIRECTORY ${OSX_BUNDLE_BUILD_BIN_DIR} + MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist ) + + # puts binaries into the *.app bundle while linking set_target_properties( pcbnew_kiface PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${OSX_BUNDLE_BUILD_KIFACE_DIR} ) + # put individual bundle outside of main bundle as a first step + # will be pulled into the main bundle when creating main bundle + install( TARGETS pcbnew + DESTINATION ${KICAD_BIN} + COMPONENT binary + ) + install( CODE " + # override default embedded path settings + ${OSX_BUNDLE_OVERRIDE_PATHS} + + # do all the work + include( BundleUtilities ) + fixup_bundle( ${KICAD_BIN}/pcbnew.app/Contents/MacOS/pcbnew + \"\" + \"\" + ) + " COMPONENT Runtime + ) else() install( TARGETS pcbnew DESTINATION ${KICAD_BIN} @@ -613,7 +648,7 @@ if( USE_KIWAY_DLLS ) else() # milestone A) kills this off: - add_executable( pcbnew WIN32 + add_executable( pcbnew WIN32 MACOSX_BUNDLE ../common/single_top.cpp pcbnew.cpp ${PCBNEW_SRCS} @@ -666,17 +701,10 @@ else() # milestone A) kills this off: ) endif() - if( APPLE ) - # puts binaries into the *.app bundle while linking - set_target_properties( pcbnew PROPERTIES - RUNTIME_OUTPUT_DIRECTORY ${OSX_BUNDLE_BUILD_BIN_DIR} - ) - else() - install( TARGETS pcbnew - DESTINATION ${KICAD_BIN} - COMPONENT binary - ) - endif() + install( TARGETS pcbnew + DESTINATION ${KICAD_BIN} + COMPONENT binary + ) endif()