From 5b0a250609e4778d7ee58f8d0df02583b176c62c Mon Sep 17 00:00:00 2001 From: Bernhard Stegmaier Date: Tue, 1 Mar 2016 10:08:19 +1100 Subject: [PATCH] Fix compilation and install for OSX plus general code cleanup --- 3d-viewer/3d_cache/3d_cache.cpp | 38 -------------- 3d-viewer/3d_cache/3d_filename_resolver.cpp | 2 +- 3d-viewer/3d_cache/3d_plugin_manager.cpp | 51 +++++++++++++------ 3d-viewer/3d_cache/sg/CMakeLists.txt | 12 ++++- .../c3d_render_createscene_ogl_legacy.cpp | 14 ----- CMakeLists.txt | 18 ++++--- kicad/CMakeLists.txt | 4 +- plugins/3d/idf/CMakeLists.txt | 10 ++-- plugins/3d/idf/s3d_plugin_idf.cpp | 4 +- plugins/3d/vrml/CMakeLists.txt | 7 +++ plugins/3d/vrml/v1/vrml1_base.cpp | 2 +- plugins/3d/vrml/v1/vrml1_base.h | 2 +- plugins/3d/vrml/v1/vrml1_material.h | 2 +- plugins/3d/vrml/v2/vrml2_base.cpp | 2 +- plugins/3d/vrml/v2/vrml2_base.h | 2 +- 15 files changed, 80 insertions(+), 90 deletions(-) diff --git a/3d-viewer/3d_cache/3d_cache.cpp b/3d-viewer/3d_cache/3d_cache.cpp index e4e01a1411..fdf4a5a7a3 100644 --- a/3d-viewer/3d_cache/3d_cache.cpp +++ b/3d-viewer/3d_cache/3d_cache.cpp @@ -96,44 +96,6 @@ static const wxString sha1ToWXString( const unsigned char* aSHA1Sum ) } -static bool sha1Matches( const unsigned char* sha1a, const unsigned char* sha1b ) -{ - for( int i = 0; i < 20; ++i ) - { - if( sha1a[i] != sha1b[i] ) - return false; - } - - return true; -} - - -static bool isSHA1null( const unsigned char* aSHA1Sum ) -{ - if( NULL == aSHA1Sum ) - { - #ifdef DEBUG - do { - std::ostringstream ostr; - ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; - ostr << " * [BUG] NULL passed for aSHA1Sum"; - wxLogTrace( MASK_3D_CACHE, "%s\n", ostr.str().c_str() ); - } while( 0 ); - #endif - - return false; - } - - for( int i = 0; i < 20; ++i ) - { - if( 0 != aSHA1Sum[i] ) - return false; - } - - return true; -} - - class S3D_CACHE_ENTRY { private: diff --git a/3d-viewer/3d_cache/3d_filename_resolver.cpp b/3d-viewer/3d_cache/3d_filename_resolver.cpp index 0e69de2e70..23c4d7e6cb 100644 --- a/3d-viewer/3d_cache/3d_filename_resolver.cpp +++ b/3d-viewer/3d_cache/3d_filename_resolver.cpp @@ -843,7 +843,7 @@ static bool getHollerith( const std::string& aString, size_t& aIndex, wxString& { aResult.clear(); - if( aIndex < 0 || aIndex >= aString.size() ) + if( aIndex >= aString.size() ) { std::ostringstream ostr; ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; diff --git a/3d-viewer/3d_cache/3d_plugin_manager.cpp b/3d-viewer/3d_cache/3d_plugin_manager.cpp index 1283c953cb..69c7cdcc69 100644 --- a/3d-viewer/3d_cache/3d_plugin_manager.cpp +++ b/3d-viewer/3d_cache/3d_plugin_manager.cpp @@ -34,6 +34,8 @@ #include #include +#include "common.h" +#include "pgm_base.h" #include "3d_plugin_manager.h" #include "plugins/3d/3d_plugin.h" #include "3d_cache/sg/scenegraph.h" @@ -118,7 +120,9 @@ void S3D_PLUGIN_MANAGER::loadPlugins( void ) std::list< wxString > pluginlist; wxFileName fn; -#ifdef DEBUG +#ifndef __WXMAC__ + + #ifdef DEBUG // set up to work from the build directory fn.Assign( wxStandardPaths::Get().GetExecutablePath() ); fn.AppendDir( wxT("..") ); @@ -127,11 +131,11 @@ void S3D_PLUGIN_MANAGER::loadPlugins( void ) std::string testpath = std::string( fn.GetPathWithSep().ToUTF8() ); checkPluginPath( testpath, searchpaths ); -#endif + #endif #ifndef _WIN32 // suppress 'kicad' subdir since it is redundant on MSWin - fn.Assign( wxStandardPaths::Get().GetPluginsDir() ); - fn.AppendDir( wxT( "kicad" ) ); + fn.Assign( wxStandardPaths::Get().GetPluginsDir() ); + fn.AppendDir( wxT( "kicad" ) ); #else fn.Assign( wxStandardPaths::Get().GetExecutablePath() ); #endif @@ -144,18 +148,6 @@ void S3D_PLUGIN_MANAGER::loadPlugins( void ) checkPluginPath( wxT( "/usr/local/lib/kicad/plugins/3d" ), searchpaths ); checkPluginPath( wxT( "/opt/kicad/lib/kicad/plugins/3d" ), searchpaths ); -#ifdef __APPLE__ - // XXX - we want to use GetOSX... so add support for that somehow in order to avoid hard coding - // "/Library/Application Support/kicad/plugins/3d" - checkPluginPath( wxT( "/Library/Application Support/kicad/plugins/3d" ), searchpaths ); - - // /Library/Application Support/kicad/plugins - //fn.Assign( GetOSXKicadMachineDataDir() ); - //fn.AppendDir( wxT( "plugins" ) ); - //fn.AppendDir( wxT( "3d" ) ); - //checkPluginPath( fn.GetPathWithSep(), searchpaths ); -#endif - // note: GetUserDataDir() gives '.pcbnew' rather than '.kicad' since it uses the exe name; fn.Assign( wxStandardPaths::Get().GetUserDataDir() ); fn.AppendDir( wxT( ".kicad" ) ); @@ -163,6 +155,22 @@ void S3D_PLUGIN_MANAGER::loadPlugins( void ) fn.AppendDir( wxT( "3d" ) ); checkPluginPath( fn.GetPathWithSep(), searchpaths ); +#else + + // Search path on OS X is + // (1) User ~/Library/Application Support/kicad/PlugIns/3d + checkPluginPath( GetOSXKicadUserDataDir() + wxT( "/PlugIns/3d" ), searchpaths ); + // (2) Machine /Library/Application Support/kicad/PlugIns/3d + checkPluginPath( GetOSXKicadMachineDataDir() + wxT( "/PlugIns/3d" ), searchpaths ); + // (3) Bundle kicad.app/Contents/PlugIns/3d + fn.Assign( Pgm().GetExecutablePath() ); + fn.AppendDir( wxT( "Contents" ) ); + fn.AppendDir( wxT( "PlugIns" ) ); + fn.AppendDir( wxT( "3d" ) ); + checkPluginPath( fn.GetPathWithSep(), searchpaths ); + +#endif + std::list< wxString >::iterator sPL = searchpaths.begin(); std::list< wxString >::iterator ePL = searchpaths.end(); @@ -269,7 +277,18 @@ void S3D_PLUGIN_MANAGER::listPlugins( const wxString& aPath, return; nameFilter = wxT( "*" ); + +#ifndef __WXMAC__ nameFilter.Append( wxDynamicLibrary::GetDllExt( wxDL_MODULE ) ); +#else + // wxDynamicLibrary::GetDllExt( wxDL_MODULE ) will return ".bundle" on OS X. + // This might be correct, but cmake builds a ".so" for a library MODULE. + // Per definition a loadable "xxx.bundle" is similar to an "xxx.app" app + // bundle being a folder with some special content in it. We obviously don't + // want to have that here for our loadable module, so just use ".so". + nameFilter.Append( wxT( ".so" ) ); +#endif + wxString lp = wd.GetNameWithSep(); if( wd.GetFirst( &lName, nameFilter, wxDIR_FILES ) ) diff --git a/3d-viewer/3d_cache/sg/CMakeLists.txt b/3d-viewer/3d_cache/sg/CMakeLists.txt index 5d5da36f1c..244384dc6f 100644 --- a/3d-viewer/3d_cache/sg/CMakeLists.txt +++ b/3d-viewer/3d_cache/sg/CMakeLists.txt @@ -29,14 +29,22 @@ add_library( kicad_3dsg SHARED ifsg_api.cpp ) +if( APPLE ) + # puts library into the main kicad.app bundle in build tree + set_target_properties( kicad_3dsg PROPERTIES + LIBRARY_OUTPUT_DIRECTORY "${OSX_BUNDLE_BUILD_LIB_DIR}" + INSTALL_NAME_DIR "${OSX_BUNDLE_BUILD_LIB_DIR}" + ) +endif() + find_file( S3DSG_VERSION_FILE sg_version.h PATHS ${CMAKE_SOURCE_DIR}/include/plugins/3dapi NO_DEFAULT_PATH ) if( NOT ${S3DSG_VERSION_FILE} STREQUAL "S3DSG_VERSION_FILE-NOTFOUND" ) - # extract the "#define SG_VERSION_*" lines + # extract the "#define KICADSG_VERSION_*" lines file( STRINGS ${S3DSG_VERSION_FILE} _version - REGEX "^[' ','\t']*#define[' ','\t']*SG_VERSION_.*" ) + REGEX "^[' ','\t']*#define[' ','\t']*KICADSG_VERSION_.*" ) foreach( SVAR ${_version} ) string( REGEX MATCH KICADSG_VERSION_[M,A,J,O,R,I,N,P,T,C,H,E,V]* _VARNAME ${SVAR} ) diff --git a/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_createscene_ogl_legacy.cpp b/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_createscene_ogl_legacy.cpp index e7ae88cfd6..ce6ab8719b 100644 --- a/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_createscene_ogl_legacy.cpp +++ b/3d-viewer/3d_rendering/3d_render_ogl_legacy/c3d_render_createscene_ogl_legacy.cpp @@ -48,16 +48,11 @@ void C3D_RENDER_OGL_LEGACY::reload() COBJECT2D_STATS::Instance().ResetStats(); - printf("InitSettings...\n"); - unsigned stats_startReloadTime = GetRunningMicroSecs(); m_settings.InitSettings(); - unsigned stats_endReloadTime = GetRunningMicroSecs(); SFVEC3F camera_pos = m_settings.GetBoardCenter3DU(); m_settings.CameraGet().SetBoardLookAtPos( camera_pos ); - unsigned stats_start_OpenGL_Load_Time = GetRunningMicroSecs(); - // Create Board // ///////////////////////////////////////////////////////////////////////// printf("Create board...\n"); @@ -297,7 +292,6 @@ void C3D_RENDER_OGL_LEGACY::reload() float radius = filledCircle->GetRadius() * 2.0f; // Double because the render triangle float radiusSquared = radius * radius; - const float texture_factor = (0.9f/(float)SIZE_OF_CIRCLE_TEXTURE) + 1.0f; const float f = (sqrtf(2.0f) / 2.0f) * radius * 0.9;// * texture_factor; layerTriangles->m_layer_top_segment_ends->AddTriangle( SFVEC3F( center.x + f, center.y, layer_z_top ), @@ -793,14 +787,6 @@ void C3D_RENDER_OGL_LEGACY::reload() layerColor ); }// for each layer on map - unsigned stats_end_OpenGL_Load_Time = GetRunningMicroSecs(); - -#ifdef RAYTRACING_PRINT_STATISTICS - printf( "C3D_RENDER_OGL_LEGACY::reload times:\n" ); - printf( " Reload board: %.3f ms\n", (float)( stats_endReloadTime - stats_startReloadTime ) / 1000.0f ); - printf( " Loading to openGL: %.3f ms\n", (float)( stats_end_OpenGL_Load_Time - stats_start_OpenGL_Load_Time ) / 1000.0f ); - COBJECT2D_STATS::Instance().PrintStats(); -#endif } diff --git a/CMakeLists.txt b/CMakeLists.txt index eb1d29e77b..cd7cd6b6f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -328,11 +328,6 @@ else() set( KICAD_BIN ${CMAKE_INSTALL_PREFIX} CACHE PATH "Location of KiCad binaries." FORCE ) - set( KICAD_LIB /Applications/kicad.app/Contents/Macos - CACHE PATH "Location of KiCad shared objects" FORCE ) - - set( KICAD_USER_PLUGIN /Applications/kicad.app/SharedSupport/plugins - CACHE PATH "Location of KiCad user-loaded plugins" FORCE ) # some paths to single app bundle set( OSX_BUNDLE_MAIN "kicad.app" ) @@ -345,16 +340,22 @@ else() 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_BUILD_PLUGIN_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}" ) + set( OSX_BUNDLE_INSTALL_PLUGIN_DIR "${OSX_BUNDLE_INSTALL_DIR}/${OSX_BUNDLE_KIFACE_DIR}" ) # everything provided with the application bundle goes into # kicad.app/Contents/SharedSupport => accessible via GetDataDir() # everything else to the .dmg image set( KICAD_DATA ${OSX_BUNDLE_INSTALL_DIR}/${OSX_BUNDLE_SUP_DIR} CACHE PATH "Location of KiCad data files." FORCE ) + set( KICAD_LIB ${OSX_BUNDLE_INSTALL_DIR}/${OSX_BUNDLE_LIB_DIR} + CACHE PATH "Location of KiCad shared objects" FORCE ) + set( KICAD_USER_PLUGIN ${OSX_BUNDLE_INSTALL_PLUGIN_DIR} + CACHE PATH "Location of KiCad user-loaded plugins" FORCE ) set( KICAD_TEMPLATE ${KICAD_DATA}/template CACHE PATH "Location of KiCad template files." FORCE ) set( KICAD_PLUGINS ${KICAD_DATA}/plugins @@ -364,6 +365,9 @@ else() set( KICAD_DEMOS demos CACHE PATH "Location of KiCad demo files." FORCE ) + # RPATH setttings for building shared libraries + set( CMAKE_MACOSX_RPATH FALSE ) + # Override default paths for fixup_bundle set( OSX_BUNDLE_OVERRIDE_PATHS " function( gp_item_default_embedded_path_override item default_embedded_path_var ) @@ -652,6 +656,7 @@ add_subdirectory( pagelayout_editor ) add_subdirectory( potrace ) add_subdirectory( bitmap2component ) add_subdirectory( pcb_calculator ) +add_subdirectory( plugins ) # 3D plugins must be built before kicad add_subdirectory( kicad ) # should follow pcbnew, eeschema add_subdirectory( tools ) add_subdirectory( utils ) @@ -777,6 +782,3 @@ if( UNIX AND NOT APPLE ) include( CPack ) endif() - -# 3D plugins -add_subdirectory( plugins ) diff --git a/kicad/CMakeLists.txt b/kicad/CMakeLists.txt index f0e2438c04..6d6ab5edf9 100644 --- a/kicad/CMakeLists.txt +++ b/kicad/CMakeLists.txt @@ -94,7 +94,9 @@ if( APPLE ) # make main bundle relocatable install( CODE " # find all libs and modules - file( GLOB BUNDLE_FIX_LIBS ${OSX_BUNDLE_INSTALL_KIFACE_DIR}/*.kiface ) + file( GLOB PLUGINS_KIFACE ${OSX_BUNDLE_INSTALL_KIFACE_DIR}/*.kiface ) + file( GLOB_RECURSE PLUGINS_SO ${OSX_BUNDLE_INSTALL_PLUGIN_DIR}/*.so ) + set( BUNDLE_FIX_LIBS \${PLUGINS_KIFACE} \${PLUGINS_SO} ) if( ${SCRIPTING_HELPER} ) file( GLOB WXPYTHON_DIR RELATIVE ${OSX_BUNDLE_INSTALL_LIB_DIR}/${PYTHON_LIB_DIR} ${OSX_BUNDLE_INSTALL_LIB_DIR}/${PYTHON_LIB_DIR}/wx-?.?-osx_cocoa ) file( GLOB PYTHON_SCRIPTING_SO ${OSX_BUNDLE_INSTALL_LIB_DIR}/${PYTHON_LIB_DIR}/*.so ) diff --git a/plugins/3d/idf/CMakeLists.txt b/plugins/3d/idf/CMakeLists.txt index c2f5a84e6a..51b30e05a1 100644 --- a/plugins/3d/idf/CMakeLists.txt +++ b/plugins/3d/idf/CMakeLists.txt @@ -8,11 +8,15 @@ add_library( s3d_plugin_idf MODULE ${CMAKE_SOURCE_DIR}/utils/idftools/vrml_layer.cpp ) -set_target_properties( s3d_plugin_idf PROPERTIES - LINK_FLAGS -L${CMAKE_BINARY_DIR}/utils/idftools ) - target_link_libraries( s3d_plugin_idf kicad_3dsg idf3 ${OPENGL_LIBRARIES} ${wxWidgets_LIBRARIES} ) +if( APPLE ) + # puts library into the main kicad.app bundle in build tree + set_target_properties( s3d_plugin_idf PROPERTIES + LIBRARY_OUTPUT_DIRECTORY "${OSX_BUNDLE_BUILD_PLUGIN_DIR}/3d" + ) +endif() + install( TARGETS s3d_plugin_idf DESTINATION ${KICAD_USER_PLUGIN}/3d diff --git a/plugins/3d/idf/s3d_plugin_idf.cpp b/plugins/3d/idf/s3d_plugin_idf.cpp index 68f97d0948..7af7b42293 100644 --- a/plugins/3d/idf/s3d_plugin_idf.cpp +++ b/plugins/3d/idf/s3d_plugin_idf.cpp @@ -783,7 +783,7 @@ static bool makeComponents( IDF3_BOARD& brd, SGNODE* aParent ) while( so != eo ) { - if( abs( (*so)->GetOutline()->GetThickness() ) < 0.001 ) + if( std::abs( (*so)->GetOutline()->GetThickness() ) < 0.001 ) { ++so; continue; @@ -889,7 +889,7 @@ static bool makeOtherOutlines( IDF3_BOARD& brd, SGNODE* aParent ) { pout = sc->second; - if( abs( pout->GetThickness() ) < 0.001 ) + if( std::abs( pout->GetThickness() ) < 0.001 ) { ++sc; continue; diff --git a/plugins/3d/vrml/CMakeLists.txt b/plugins/3d/vrml/CMakeLists.txt index 8c2528600e..ad607b8f3a 100644 --- a/plugins/3d/vrml/CMakeLists.txt +++ b/plugins/3d/vrml/CMakeLists.txt @@ -51,6 +51,13 @@ add_library( s3d_plugin_vrml MODULE target_link_libraries( s3d_plugin_vrml kicad_3dsg ${OPENGL_LIBRARIES} ${wxWidgets_LIBRARIES} ) +if( APPLE ) + # puts library into the main kicad.app bundle in build tree + set_target_properties( s3d_plugin_vrml PROPERTIES + LIBRARY_OUTPUT_DIRECTORY "${OSX_BUNDLE_BUILD_PLUGIN_DIR}/3d" + ) +endif() + install( TARGETS s3d_plugin_vrml DESTINATION ${KICAD_USER_PLUGIN}/3d diff --git a/plugins/3d/vrml/v1/vrml1_base.cpp b/plugins/3d/vrml/v1/vrml1_base.cpp index 59f5bc5e32..cdea65cebd 100644 --- a/plugins/3d/vrml/v1/vrml1_base.cpp +++ b/plugins/3d/vrml/v1/vrml1_base.cpp @@ -58,7 +58,7 @@ WRL1BASE::~WRL1BASE() // functions inherited from WRL1NODE -bool WRL1BASE::SetParent( WRL1NODE* aParent ) +bool WRL1BASE::SetParent( WRL1NODE* aParent, bool /* doUnlink */ ) { #ifdef DEBUG_VRML1 do { diff --git a/plugins/3d/vrml/v1/vrml1_base.h b/plugins/3d/vrml/v1/vrml1_base.h index 5ea5849758..195fd6a090 100644 --- a/plugins/3d/vrml/v1/vrml1_base.h +++ b/plugins/3d/vrml/v1/vrml1_base.h @@ -75,7 +75,7 @@ public: // functions inherited from WRL1NODE bool Read( WRLPROC& proc, WRL1BASE* aTopNode ); - bool SetParent( WRL1NODE* aParent ); + bool SetParent( WRL1NODE* aParent, bool doUnlink = true ); SGNODE* TranslateToSG( SGNODE* aParent, WRL1STATUS* sp ); }; diff --git a/plugins/3d/vrml/v1/vrml1_material.h b/plugins/3d/vrml/v1/vrml1_material.h index 00933e5396..50facb193b 100644 --- a/plugins/3d/vrml/v1/vrml1_material.h +++ b/plugins/3d/vrml/v1/vrml1_material.h @@ -35,7 +35,7 @@ class WRL1BASE; class SGNODE; -struct SGCOLOR; +class SGCOLOR; /** * Class WRL1MATERIAL diff --git a/plugins/3d/vrml/v2/vrml2_base.cpp b/plugins/3d/vrml/v2/vrml2_base.cpp index 76f50a9d99..dbce4bca1c 100644 --- a/plugins/3d/vrml/v2/vrml2_base.cpp +++ b/plugins/3d/vrml/v2/vrml2_base.cpp @@ -78,7 +78,7 @@ WRL2BASE::~WRL2BASE() // functions inherited from WRL2NODE -bool WRL2BASE::SetParent( WRL2NODE* aParent ) +bool WRL2BASE::SetParent( WRL2NODE* aParent, bool /* doUnlink */ ) { #ifdef DEBUG_VRML2 do { diff --git a/plugins/3d/vrml/v2/vrml2_base.h b/plugins/3d/vrml/v2/vrml2_base.h index 36ba710912..f8ab805a02 100644 --- a/plugins/3d/vrml/v2/vrml2_base.h +++ b/plugins/3d/vrml/v2/vrml2_base.h @@ -109,7 +109,7 @@ public: // functions inherited from WRL2NODE bool Read( WRLPROC& proc, WRL2BASE* aTopNode ); - bool SetParent( WRL2NODE* aParent ); + bool SetParent( WRL2NODE* aParent, bool doUnlink = true ); SGNODE* TranslateToSG( SGNODE* aParent ); };