From 2cb8dff650d4219b91ba1663c8b4d0665373641f Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Tue, 12 Jan 2021 08:19:59 -0800 Subject: [PATCH] Use KICAD_DATA for data path lookup in scripting Fixes https://gitlab.com/kicad/code/kicad/issues/7036 --- CMakeLists.txt | 10 ++++++++-- CMakeModules/config.h.cmake | 3 +++ pcbnew/swig/python_scripting.cpp | 4 +++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 738bbddd3a..8e8115dd6e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -490,8 +490,14 @@ if( NOT APPLE ) set( KICAD_BIN bin CACHE PATH "Location of KiCad binaries." ) - set( KICAD_DATA ${CMAKE_INSTALL_DATADIR}/kicad - CACHE PATH "Location of KiCad data files." ) + # Do not make these variables "PATH" b/c cmake will truncate them and we need the full path + if( NOT IS_ABSOLUTE ${CMAKE_INSTALL_DATADIR} ) + set( KICAD_DATA ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/kicad + CACHE STRING "Location of KiCad data files." ) + else() + set( KICAD_DATA ${CMAKE_INSTALL_DATADIR}/kicad + CACHE STRING "Location of KiCad data files." ) + endif() if( WIN32 ) set( KICAD_PLUGINS ${KICAD_BIN}/scripting/plugins diff --git a/CMakeModules/config.h.cmake b/CMakeModules/config.h.cmake index 134d0a88ab..18ea68e46a 100644 --- a/CMakeModules/config.h.cmake +++ b/CMakeModules/config.h.cmake @@ -77,6 +77,9 @@ /// Allows scripts install directory to be referenced by the program code. #define PYTHON_DEST "@PYTHON_DEST@" +/// Allows scripts install directory to be referenced by the program code. +#define KICAD_DATA "@KICAD_DATA@" + /// ngspice version string detected by pkg-config when available. #cmakedefine NGSPICE_BUILD_VERSION "@NGSPICE_BUILD_VERSION@" diff --git a/pcbnew/swig/python_scripting.cpp b/pcbnew/swig/python_scripting.cpp index 5dd4340b17..37eb48dfae 100644 --- a/pcbnew/swig/python_scripting.cpp +++ b/pcbnew/swig/python_scripting.cpp @@ -41,6 +41,8 @@ #include +#include + /* init functions defined by swig */ #if PY_MAJOR_VERSION >= 3 @@ -658,7 +660,7 @@ wxString PyScriptingPath( bool aUserPath ) #if defined( __WXMAC__ ) path = GetOSXKicadDataDir() + wxT( "/scripting" ); #else - path = Pgm().GetExecutablePath() + wxT( "../share/kicad/scripting" ); + path = Pgm().GetExecutablePath() + KICAD_DATA + wxS( "/scripting" ); #endif } }