Link eeschema with ngspice DLL

Adds a link-time dependency for libngspice, so that other tools may
detect ngspice as a KiCad dependency.

The library is still loaded with dlopen() as it gives a way to reload it
in case of problems. The DLL name is recognized during CMake
configuration and used to load the library at runtime.
This commit is contained in:
Maciej Suminski 2018-10-29 14:23:03 +01:00
parent dba32717b1
commit dd39599903
3 changed files with 30 additions and 7 deletions

View File

@ -12,6 +12,15 @@ find_library( NGSPICE_LIBRARY ngspice
PATH_SUFFIXES src/.libs lib PATH_SUFFIXES src/.libs lib
) )
if( WIN32 AND MSYS )
# NGSPICE_LIBRARY points to libngspice.dll.a on Windows,
# but the goal is to find out the DLL name.
find_library( NGSPICE_DLL NAMES libngspice-0.dll libngspice-1.dll )
else()
set( NGSPICE_DLL "${NGSPICE_LIBRARY}" )
endif()
include( FindPackageHandleStandardArgs ) include( FindPackageHandleStandardArgs )
if( ${NGSPICE_INCLUDE_DIR} STREQUAL "NGSPICE_INCLUDE_DIR-NOTFOUND" OR ${NGSPICE_LIBRARY} STREQUAL "NGSPICE_LIBRARY-NOTFOUND" ) if( ${NGSPICE_INCLUDE_DIR} STREQUAL "NGSPICE_INCLUDE_DIR-NOTFOUND" OR ${NGSPICE_LIBRARY} STREQUAL "NGSPICE_LIBRARY-NOTFOUND" )
@ -28,12 +37,10 @@ if( ${NGSPICE_INCLUDE_DIR} STREQUAL "NGSPICE_INCLUDE_DIR-NOTFOUND" OR ${NGSPICE_
endif() endif()
find_package_handle_standard_args( ngspice find_package_handle_standard_args( ngspice
REQUIRED_VARS REQUIRED_VARS NGSPICE_INCLUDE_DIR NGSPICE_LIBRARY NGSPICE_DLL )
NGSPICE_INCLUDE_DIR
NGSPICE_LIBRARY
)
mark_as_advanced( mark_as_advanced(
NGSPICE_INCLUDE_DIR NGSPICE_INCLUDE_DIR
NGSPICE_LIBRARY NGSPICE_LIBRARY
NGSPICE_DLL
) )

View File

@ -7,6 +7,15 @@ add_definitions( -DEESCHEMA )
if( KICAD_SPICE ) if( KICAD_SPICE )
set( INC_AFTER ${INC_AFTER} ${NGSPICE_INCLUDE_DIR} ) set( INC_AFTER ${INC_AFTER} ${NGSPICE_INCLUDE_DIR} )
# Find out the exact libngspice file name
get_filename_component( NGSPICE_DLL_REALPATH "${NGSPICE_DLL}" REALPATH )
get_filename_component( NGSPICE_DLL_FILE "${NGSPICE_DLL_REALPATH}" NAME )
set_property( SOURCE sim/ngspice.cpp
APPEND PROPERTY COMPILE_DEFINITIONS
NGSPICE_DLL_FILE="${NGSPICE_DLL_FILE}"
)
endif() endif()
include_directories( BEFORE ${INC_BEFORE} ) include_directories( BEFORE ${INC_BEFORE} )
@ -315,6 +324,13 @@ target_link_libraries( eeschema_kiface
${wxWidgets_LIBRARIES} ${wxWidgets_LIBRARIES}
${GDI_PLUS_LIBRARIES} ${GDI_PLUS_LIBRARIES}
) )
if( KICAD_SPICE )
target_link_libraries( eeschema_kiface
${NGSPICE_LIBRARY}
)
endif()
set_target_properties( eeschema_kiface PROPERTIES set_target_properties( eeschema_kiface PROPERTIES
# Decorate OUTPUT_NAME with PREFIX and SUFFIX, creating something like # Decorate OUTPUT_NAME with PREFIX and SUFFIX, creating something like
# _eeschema.so, _eeschema.dll, or _eeschema.kiface # _eeschema.so, _eeschema.dll, or _eeschema.kiface

View File

@ -289,11 +289,11 @@ void NGSPICE::init_dll()
// Extra effort to find libngspice // Extra effort to find libngspice
#if defined(__WINDOWS__) || (__WXMAC__) #if defined(__WINDOWS__) || (__WXMAC__)
#ifdef __WINDOWS__ #ifdef __WINDOWS__
wxFileName dllFile( "", "libngspice-0.dll" ); wxFileName dllFile( "", NGSPICE_DLL_FILE );
const vector<string> dllPaths = { "", "/mingw64/bin", "/mingw32/bin" }; const vector<string> dllPaths = { "", "/mingw64/bin", "/mingw32/bin" };
#endif /* __WINDOWS__ */ #endif /* __WINDOWS__ */
#ifdef __WXMAC__ #ifdef __WXMAC__
wxFileName dllFile( "", "libngspice.0.dylib" ); wxFileName dllFile( "", NGSPICE_DLL_FILE );
const vector<string> dllPaths = { const vector<string> dllPaths = {
GetOSXKicadUserDataDir() + "/PlugIns/ngspice", GetOSXKicadUserDataDir() + "/PlugIns/ngspice",
GetOSXKicadMachineDataDir() + "/PlugIns/ngspice", GetOSXKicadMachineDataDir() + "/PlugIns/ngspice",
@ -320,7 +320,7 @@ void NGSPICE::init_dll()
if( !m_dll.IsLoaded() ) // try also the system libraries if( !m_dll.IsLoaded() ) // try also the system libraries
m_dll.Load( wxDynamicLibrary::CanonicalizeName( "ngspice" ) ); m_dll.Load( wxDynamicLibrary::CanonicalizeName( "ngspice" ) );
#else #else
m_dll.Load("libngspice.so.0"); m_dll.Load( NGSPICE_DLL_FILE );
#endif /* __WINDOWS || __WXMAC__ */ #endif /* __WINDOWS || __WXMAC__ */
if( !m_dll.IsLoaded() ) if( !m_dll.IsLoaded() )