Fix ngspice version information issue.

The config.h header for ngspice is not packaged with all platforms so
use pkg-config to fetch the version information when available.  When
pkg-config is not available, check if the ngspice/config.h file is
installed on the system before including it to build the ngspice version
string.  If neither pkg-config or ngspice/config.h is available set the
version string to "unknown".

Fixes https://gitlab.com/kicad/code/kicad/issues/4851
This commit is contained in:
Wayne Stambaugh 2020-07-11 16:33:41 -04:00 committed by Simon Richter
parent 13b8708e58
commit 0cf53da0fe
2 changed files with 97 additions and 5 deletions

View File

@ -1,6 +1,8 @@
# CMake script for finding libngspice
# Copyright (C) 2016 CERN
# Copyright (C) 2020 Kicad Developers, see AUTHORS.txt for contributors.
#
# Author: Maciej Suminski <maciej.suminski@cern.ch>
#
# This program is free software; you can redistribute it and/or
@ -20,21 +22,103 @@
# or you may write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
# Usage:
#
# ngspice uses pkg-config to gather the configuration information so the pkg-config
# information is used to populate the CMake find_* commands. When pkg-config is not
# available, the fallback is the default platform search paths set up by CMake. The
# default search paths can be overridden by user. The order of precedence is as
# follows:
#
# User defined root path NGSPICE_ROOT_DIR on CMake command line.
# User defined root path environment variable NGSPICE_ROOT_DIR.
# Paths generated by pkg-config.
# The default system paths configured by CMake
#
# For a specific ngspice include path not defined above set NGSPICE_INCLUDE_PATH.
#
# For a specific ngspice library path not defined above set NGSPICE_LIBRARY_PATH.
# Use pkg-config if it's available.
find_package(PkgConfig)
if( PKG_CONFIG_FOUND )
pkg_check_modules( _NGSPICE ngspice )
if( _NGSPICE_FOUND )
set( NGSPICE_BUILD_VERSION "${_NGSPICE_VERSION}" CACHE STRING
"ngspice version returned by pkg-config" )
endif()
endif()
find_path( NGSPICE_INCLUDE_DIR ngspice/sharedspice.h
PATHS ${NGSPICE_ROOT_DIR} $ENV{NGSPICE_ROOT_DIR} ${NGSPICE_INCLUDE_PATH}
${NGSPICE_ROOT_DIR}/include
PATH_SUFFIXES src/include share/ngspice/include share/ngspice/include/ngspice
PATHS
${NGSPICE_ROOT_DIR}
$ENV{NGSPICE_ROOT_DIR}
${NGSPICE_INCLUDE_PATH}
${_NGSPICE_INCLUDE_DIRS}
PATH_SUFFIXES
include
src/include
share/ngspice/include
share/ngspice/include/ngspice
)
find_library( NGSPICE_LIBRARY ngspice
PATHS ${NGSPICE_ROOT_DIR} $ENV{NGSPICE_ROOT_DIR} ${NGSPICE_LIBRARY_PATH}
PATH_SUFFIXES src/.libs lib
PATHS
${NGSPICE_ROOT_DIR}
$ENV{NGSPICE_ROOT_DIR}
${NGSPICE_LIBRARY_PATH}
${_NGSPICE_LIBRARY_DIRS}
PATH_SUFFIXES
src/.libs
lib
)
# If the ngspice version is not set by pkg-config, see if ngspice/config.h is available.
if( NOT NGSPICE_BUILD_VERSION )
find_file( NGSPICE_CONFIG_H ngspice/config.h
PATHS
${NGSPICE_ROOT_DIR}
$ENV{NGSPICE_ROOT_DIR}
${NGSPICE_INCLUDE_PATH}
${_NGSPICE_INCLUDE_DIRS}
PATH_SUFFIXES
include
src/include
share/ngspice/include
share/ngspice/include/ngspice
)
if( NOT NGSPICE_CONFIG_H-NOTFOUND )
message( STATUS "ngspice configuration file ${NGSPICE_CONFIG_H} found." )
set( NGSPICE_HAVE_CONFIG_H "1" CACHE STRING "ngspice/config.h header found." )
endif()
endif()
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 )
# Some msys versions do not find xxx.dll lib files, only xxx.dll.a files
# so try a find_file in exec paths
if( NGSPICE_DLL STREQUAL "NGSPICE_DLL-NOTFOUND" )
find_file( NGSPICE_DLL NAMES libngspice-0.dll libngspice-1.dll
PATHS
${NGSPICE_ROOT_DIR}
PATH_SUFFIXES
bin
lib
)
endif()
if( NGSPICE_DLL STREQUAL "NGSPICE_DLL-NOTFOUND" )
message( ERROR ":\n***** libngspice-x.dll not found in any executable path *****\n\n" )
else()
message( STATUS ": libngspice shared lib found: ${NGSPICE_DLL}\n" )
endif()
else()
set( NGSPICE_DLL "${NGSPICE_LIBRARY}" )
endif()
@ -62,4 +146,6 @@ mark_as_advanced(
NGSPICE_INCLUDE_DIR
NGSPICE_LIBRARY
NGSPICE_DLL
NGSPICE_BUILD_VERSION
NGSPIC_HAVE_CONFIG_H
)

View File

@ -75,4 +75,10 @@
/// Allows scripts install directory to be referenced by the program code.
#define PYTHON_DEST "@PYTHON_DEST@"
/// ngspice version string detected by pkg-config when available.
#cmakedefine NGSPICE_BUILD_VERSION "@NGSPICE_BUILD_VERSION@"
/// When pkg-config config is not available for ngspice, use ngspice/config.h for version.
#cmakedefine NGSPICE_HAVE_CONFIG_H
#endif // CONFIG_H_