You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
5.7 KiB

  1. # CMake script for finding libngspice
  2. # Copyright (C) 2016 CERN
  3. # Copyright (C) 2022 Kicad Developers, see AUTHORS.txt for contributors.
  4. #
  5. # Author: Maciej Suminski <maciej.suminski@cern.ch>
  6. #
  7. # This program is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU General Public License
  9. # as published by the Free Software Foundation; either version 2
  10. # of the License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, you may find one here:
  19. # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. # or you may search the http://www.gnu.org website for the version 2 license,
  21. # or you may write to the Free Software Foundation, Inc.,
  22. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. # Usage:
  24. #
  25. # ngspice uses pkg-config to gather the configuration information so the pkg-config
  26. # information is used to populate the CMake find_* commands. When pkg-config is not
  27. # available, the fallback is the default platform search paths set up by CMake. The
  28. # default search paths can be overridden by user. The order of precedence is as
  29. # follows:
  30. #
  31. # User defined root path NGSPICE_ROOT_DIR on CMake command line.
  32. # User defined root path environment variable NGSPICE_ROOT_DIR.
  33. # Paths generated by pkg-config.
  34. # The default system paths configured by CMake
  35. #
  36. # For a specific ngspice include path not defined above set NGSPICE_INCLUDE_PATH.
  37. #
  38. # For a specific ngspice library path not defined above set NGSPICE_LIBRARY_PATH.
  39. # Use pkg-config if it's available.
  40. find_package(PkgConfig)
  41. if( PKG_CONFIG_FOUND )
  42. pkg_check_modules( _NGSPICE ngspice )
  43. if( _NGSPICE_FOUND )
  44. set( NGSPICE_BUILD_VERSION "${_NGSPICE_VERSION}" CACHE STRING
  45. "ngspice version returned by pkg-config" )
  46. endif()
  47. endif()
  48. find_path( NGSPICE_INCLUDE_DIR ngspice/sharedspice.h
  49. PATHS
  50. ${NGSPICE_ROOT_DIR}
  51. $ENV{NGSPICE_ROOT_DIR}
  52. ${NGSPICE_INCLUDE_PATH}
  53. ${_NGSPICE_INCLUDE_DIRS}
  54. PATH_SUFFIXES
  55. include
  56. src/include
  57. share/ngspice/include
  58. share/ngspice/include/ngspice
  59. )
  60. if( UNIX )
  61. set( NGSPICE_LIB_NAME libngspice.so.0 CACHE STRING "Optionally versioned name of the shared library" )
  62. else()
  63. set( NGSPICE_LIB_NAME ngspice CACHE STRING "Optionally versioned name of the shared library" )
  64. endif()
  65. find_library( NGSPICE_LIBRARY ${NGSPICE_LIB_NAME}
  66. PATHS
  67. ${NGSPICE_ROOT_DIR}
  68. $ENV{NGSPICE_ROOT_DIR}
  69. ${NGSPICE_LIBRARY_PATH}
  70. ${_NGSPICE_LIBRARY_DIRS}
  71. PATH_SUFFIXES
  72. src/.libs
  73. lib
  74. )
  75. # If the ngspice version is not set by pkg-config, see if ngspice/config.h is available.
  76. if( NOT NGSPICE_BUILD_VERSION )
  77. find_file( NGSPICE_CONFIG_H ngspice/config.h
  78. PATHS
  79. ${NGSPICE_ROOT_DIR}
  80. $ENV{NGSPICE_ROOT_DIR}
  81. ${NGSPICE_INCLUDE_PATH}
  82. ${_NGSPICE_INCLUDE_DIRS}
  83. PATH_SUFFIXES
  84. include
  85. src/include
  86. share/ngspice/include
  87. share/ngspice/include/ngspice
  88. )
  89. if( NOT ${NGSPICE_CONFIG_H} STREQUAL "NGSPICE_CONFIG_H-NOTFOUND" )
  90. message( STATUS "ngspice configuration file ${NGSPICE_CONFIG_H} found." )
  91. set( NGSPICE_HAVE_CONFIG_H "1" CACHE STRING "ngspice/config.h header found." )
  92. endif()
  93. endif()
  94. if( WIN32 AND MSYS )
  95. # NGSPICE_LIBRARY points to libngspice.dll.a on Windows,
  96. # but the goal is to find out the DLL name.
  97. # Note: libngspice-0.dll or libngspice-1.dll must be in a executable path
  98. find_library( NGSPICE_DLL NAMES libngspice-0.dll libngspice-1.dll )
  99. # Some msys versions do not find xxx.dll lib files, only xxx.dll.a files
  100. # so try a find_file in exec paths
  101. if( NGSPICE_DLL STREQUAL "NGSPICE_DLL-NOTFOUND" )
  102. find_file( NGSPICE_DLL NAMES libngspice-0.dll libngspice-1.dll
  103. PATHS
  104. ${NGSPICE_ROOT_DIR}
  105. PATH_SUFFIXES
  106. bin
  107. lib
  108. )
  109. endif()
  110. if( NGSPICE_DLL STREQUAL "NGSPICE_DLL-NOTFOUND" )
  111. message( ERROR ":\n***** libngspice-x.dll not found in any executable path *****\n\n" )
  112. else()
  113. message( STATUS ": libngspice shared lib found: ${NGSPICE_DLL}\n" )
  114. endif()
  115. elseif( WIN32 AND MSVC )
  116. find_file( NGSPICE_DLL NAMES ngspice.dll
  117. PATHS
  118. ${NGSPICE_ROOT_DIR}
  119. PATH_SUFFIXES
  120. bin
  121. lib
  122. )
  123. find_path(NGSPICE_CM_DIR
  124. NAMES analog.cm digital.cm spice2poly.cm
  125. PATH_SUFFIXES
  126. lib/ngspice
  127. )
  128. else()
  129. set( NGSPICE_DLL "${NGSPICE_LIBRARY}" )
  130. endif()
  131. include( FindPackageHandleStandardArgs )
  132. if( ${NGSPICE_INCLUDE_DIR} STREQUAL "NGSPICE_INCLUDE_DIR-NOTFOUND" OR ${NGSPICE_LIBRARY} STREQUAL "NGSPICE_LIBRARY-NOTFOUND" )
  133. message( "" )
  134. message( "*** NGSPICE library missing ***" )
  135. message( "Most of ngspice packages do not provide the required libngspice library." )
  136. message( "You can either compile ngspice configured with --with-ngshared parameter" )
  137. message( "or run a script that does the job for you:" )
  138. message( " cd ./tools/build" )
  139. message( " chmod +x get_libngspice_so.sh" )
  140. message( " ./get_libngspice_so.sh" )
  141. message( " sudo ./get_libngspice_so.sh install" )
  142. message( "" )
  143. endif()
  144. find_package_handle_standard_args( ngspice
  145. REQUIRED_VARS NGSPICE_INCLUDE_DIR NGSPICE_LIBRARY NGSPICE_DLL )
  146. mark_as_advanced(
  147. NGSPICE_INCLUDE_DIR
  148. NGSPICE_LIBRARY
  149. NGSPICE_DLL
  150. NGSPICE_BUILD_VERSION
  151. NGSPICE_HAVE_CONFIG_H
  152. )