Allow to relocate EDA libraries out of KICAD_DATA

Introduce a new advanced config variable `KICAD_LIBRARY_DATA` which can
be used to move templates, symbols, footprints, and 3dmodels out of
`KICAD_DATA`. If not defined, everything is kept as before.

To facilitate this, PATHS::GetStockEDALibraryPath() is added. This
allows to differentiate code paths looking for EDA library data vs. code
paths looking for plugins, demos, and the like.

Thanks to Aimylios for the hints and suggestions with regards to the
stock EDA library data path handling on Windows and MacOS.
This commit is contained in:
Johannes Maibaum 2021-03-29 15:37:11 +02:00 committed by Jon Evans
parent f7cc6d1e1e
commit 39c1387b5b
6 changed files with 35 additions and 8 deletions

View File

@ -542,6 +542,9 @@ if( NOT APPLE )
CACHE STRING "Location of KiCad data files." ) CACHE STRING "Location of KiCad data files." )
endif() endif()
set( KICAD_LIBRARY_DATA ${KICAD_DATA}
CACHE STRING "Location of KiCad stock EDA library data" )
if( WIN32 ) if( WIN32 )
set( KICAD_PLUGINS ${KICAD_BIN}/scripting/plugins set( KICAD_PLUGINS ${KICAD_BIN}/scripting/plugins
CACHE PATH "Location of KiCad plugins." ) CACHE PATH "Location of KiCad plugins." )
@ -566,7 +569,7 @@ if( NOT APPLE )
CACHE PATH "Location of KiCad documentation files." ) CACHE PATH "Location of KiCad documentation files." )
set( KICAD_DEMOS ${KICAD_DATA}/demos set( KICAD_DEMOS ${KICAD_DATA}/demos
CACHE PATH "Location of KiCad demo files." ) CACHE PATH "Location of KiCad demo files." )
set( KICAD_TEMPLATE ${KICAD_DATA}/template set( KICAD_TEMPLATE ${KICAD_LIBRARY_DATA}/template
CACHE PATH "Location of KiCad template files." ) CACHE PATH "Location of KiCad template files." )
else() else()
# everything without leading / is relative to CMAKE_INSTALL_PREFIX. # everything without leading / is relative to CMAKE_INSTALL_PREFIX.
@ -642,6 +645,7 @@ mark_as_advanced( KICAD_BIN
KICAD_USER_PLUGIN KICAD_USER_PLUGIN
KICAD_LIB KICAD_LIB
KICAD_DATA KICAD_DATA
KICAD_LIBRARY_DATA
KICAD_DOCS KICAD_DOCS
KICAD_DEMOS KICAD_DEMOS
KICAD_TEMPLATE ) KICAD_TEMPLATE )

View File

@ -85,6 +85,10 @@
/// Allows scripts install directory to be referenced by the program code. /// Allows scripts install directory to be referenced by the program code.
#define KICAD_DATA "@KICAD_DATA@" #define KICAD_DATA "@KICAD_DATA@"
/// Allows KiCad stock EDA library data (templates, symbols, footprints, 3dmodels)
/// directory to be referenced by the program code.
#define KICAD_LIBRARY_DATA "@KICAD_LIBRARY_DATA@"
// Plugins directory // Plugins directory
#define KICAD_PLUGINDIR "@CMAKE_INSTALL_FULL_LIBDIR@" #define KICAD_PLUGINDIR "@CMAKE_INSTALL_FULL_LIBDIR@"

View File

@ -162,6 +162,22 @@ wxString PATHS::GetStockDataPath( bool aRespectRunFromBuildDir )
} }
wxString PATHS::GetStockEDALibraryPath()
{
wxString path;
#if defined( __WXMAC__ )
path = GetOSXKicadMachineDataDir();
#elif defined( __WXMSW__ )
path = GetStockDataPath( false );
#else
path = wxString::FromUTF8Unchecked( KICAD_LIBRARY_DATA );
#endif
return path;
}
wxString PATHS::GetStockScriptingPath() wxString PATHS::GetStockScriptingPath()
{ {
wxString path; wxString path;

View File

@ -279,11 +279,7 @@ bool PGM_BASE::InitPgm()
return false; return false;
wxFileName baseSharePath; wxFileName baseSharePath;
#ifdef __WXMAC__ baseSharePath.AssignDir( PATHS::GetStockEDALibraryPath() );
baseSharePath.AssignDir( PATHS::GetOSXKicadMachineDataDir() );
#else
baseSharePath.AssignDir( PATHS::GetStockDataPath( false ) );
#endif
// KICAD6_FOOTPRINT_DIR // KICAD6_FOOTPRINT_DIR
wxString envVarName = wxT( "KICAD6_FOOTPRINT_DIR" ); wxString envVarName = wxT( "KICAD6_FOOTPRINT_DIR" );

View File

@ -68,9 +68,10 @@ void SystemDirsAppend( SEARCH_STACK* aSearchStack )
maybe.AddPaths( wxT( DEFAULT_INSTALL_PATH ) ); maybe.AddPaths( wxT( DEFAULT_INSTALL_PATH ) );
#ifdef __WXGTK__ #ifdef __WXGTK__
// On Linux, the stock data install path is defined by KICAD_DATA. // On Linux, the stock EDA library data install path can be redefined via
// KICAD_LIBRARY_DATA, otherwise KICAD_DATA will be used.
// Useful when multiple versions of KiCad are installed in parallel. // Useful when multiple versions of KiCad are installed in parallel.
maybe.AddPaths( PATHS::GetStockDataPath( false ) ); maybe.AddPaths( PATHS::GetStockEDALibraryPath() );
#endif #endif
// Add the directory for the user-dependent, program specific data files. // Add the directory for the user-dependent, program specific data files.

View File

@ -72,6 +72,12 @@ public:
*/ */
static wxString GetStockDataPath( bool aRespectRunFromBuildDir = true ); static wxString GetStockDataPath( bool aRespectRunFromBuildDir = true );
/**
* Gets the stock (install) EDA library data path, which is the base path for
* templates, schematic symbols, footprints, and 3D models.
*/
static wxString GetStockEDALibraryPath();
/** /**
* Gets the stock (install) scripting path * Gets the stock (install) scripting path
*/ */