DELBERGUE Guillaume

Improve FindSystemC and FindTLM

Add SystemC 2.3.1 support and MinGW.
Remove uneeded link_directories with new version

Signed-off-by: Guillaume Delbergue <guillaume.delbergue@greensocs.com>
... ... @@ -45,7 +45,6 @@ LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
FIND_PACKAGE(SystemC)
if(SystemC_FOUND)
INCLUDE_DIRECTORIES(${SystemC_INCLUDE_DIRS})
LINK_DIRECTORIES(${SystemC_LIBRARY_DIRS})
else()
MESSAGE(FATAL_ERROR "SystemC library not found.")
endif()
... ...
# - Find SystemC
# Find SystemC
# This module finds if SystemC is installed and determines where the
# include files and libraries are. This code sets the following
# variables: (from kernel/sc_ver.h)
#
# SystemC_VERSION_MAJOR = The major version of the package found.
# SystemC_VERSION_MINOR = The minor version of the package found.
# SystemC_VERSION_REV = The patch version of the package found.
# SystemC_VERSION = This is set to: $major.$minor.$rev
#
# The minimum required version of SystemC can be specified using the
# standard CMake syntax, e.g. FIND_PACKAGE(SystemC 2.2)
# SystemC_VERSION_MAJOR = The major version of the package found
# SystemC_VERSION_MINOR = The minor version of the package found
# SystemC_VERSION_PATCH = The patch version of the package found
# SystemC_VERSION = The full version string of the package found
#
# For these components the following variables are set:
#
# SystemC_INCLUDE_DIRS - Full paths to all include dirs.
# SystemC_LIBRARIES - Full paths to all libraries.
# SystemC_INCLUDE_DIRS - Full paths to all include dirs
# SystemC_LIBRARY_DIRS - Link directories for SystemC libraries
# SystemC::SystemC - Full path to SystemC library
# SystemC::SystemC_STATIC - Full path to SystemC static library
#
# Example Usages:
# FIND_PACKAGE(SystemC)
# FIND_PACKAGE(SystemC 2.3)
#
# find_package(SystemC)
#=============================================================================
# Copyright 2012 GreenSocs
#
# Copyright 2015 GreenSocs
#=============================================================================
message(STATUS "Searching for SystemC")
# The HINTS option should only be used for values computed from the system.
SET(_SYSTEMC_HINTS
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\SystemC\\2.2;SystemcHome]/include"
${SYSTEMC_PREFIX}/include
${SYSTEMC_PREFIX}/lib
${SYSTEMC_PREFIX}/lib-linux
${SYSTEMC_PREFIX}/lib-linux64
${SYSTEMC_PREFIX}/lib-macos
${SYSTEMC_PREFIX}/lib-macosx64
$ENV{SYSTEMC_PREFIX}/include
$ENV{SYSTEMC_PREFIX}/lib
$ENV{SYSTEMC_PREFIX}/lib-linux
$ENV{SYSTEMC_PREFIX}/lib-linux64
$ENV{SYSTEMC_PREFIX}/lib-macos
$ENV{SYSTEMC_PREFIX}/lib-macosx64
${CMAKE_INSTALL_PREFIX}/include
${CMAKE_INSTALL_PREFIX}/lib
${CMAKE_INSTALL_PREFIX}/lib-linux
${CMAKE_INSTALL_PREFIX}/lib-linux64
${CMAKE_INSTALL_PREFIX}/lib-macos
${CMAKE_INSTALL_PREFIX}/lib-macosx64
)
# Hard-coded guesses should still go in PATHS. This ensures that the user
# environment can always override hard guesses.
SET(_SYSTEMC_PATHS
/usr/include/systemc
/usr/lib
/usr/lib-linux
/usr/lib-linux64
/usr/lib-macos
/usr/lib-macosx64
/usr/local/lib
/usr/local/lib-linux
/usr/local/lib-linux64
/usr/local/lib-macos
/usr/local/lib-macosx64
)
FIND_FILE(_SYSTEMC_VERSION_FILE
NAMES sc_ver.h
HINTS ${_SYSTEMC_HINTS}
PATHS ${_SYSTEMC_PATHS}
PATH_SUFFIXES sysc/kernel
)
EXEC_PROGRAM("cat ${_SYSTEMC_VERSION_FILE} |grep '#define SC_API_VERSION_STRING' | cut -d '_' -f 7 "
OUTPUT_VARIABLE SystemC_MAJOR)
EXEC_PROGRAM("cat ${_SYSTEMC_VERSION_FILE} |grep '#define SC_API_VERSION_STRING' | cut -d '_' -f 8 "
OUTPUT_VARIABLE SystemC_MINOR)
EXEC_PROGRAM("cat ${_SYSTEMC_VERSION_FILE} |grep '#define SC_API_VERSION_STRING' | cut -d '_' -f 9 "
OUTPUT_VARIABLE SystemC_REV)
set(SystemC_VERSION ${SystemC_MAJOR}.${SystemC_MINOR}.${SystemC_REV})
if("${SystemC_MAJOR}" MATCHES "2")
set(SystemC_FOUND TRUE)
endif("${SystemC_MAJOR}" MATCHES "2")
message(STATUS "SystemC version = ${SystemC_VERSION}")
FIND_PATH(SystemC_INCLUDE_DIRS
NAMES systemc.h
HINTS ${_SYSTEMC_HINTS}
PATHS ${_SYSTEMC_PATHS}
)
FIND_PATH(SystemC_LIBRARY_DIRS
NAMES libsystemc.a
HINTS ${_SYSTEMC_HINTS}
PATHS ${_SYSTEMC_PATHS}
)
set(SystemC_LIBRARIES ${SystemC_LIBRARY_DIRS}/libsystemc.a)
message(STATUS "SystemC library = ${SystemC_LIBRARIES}")
function(SYSTEMC_APPEND_TARGET var prefix)
set(listVar "")
foreach(f ${ARGN})
list(APPEND listVar "${prefix}${f}")
endforeach(f)
set(${var} "${listVar}" PARENT_SCOPE)
endfunction(SYSTEMC_APPEND_TARGET)
set(_SYSTEMC_TARGET_SUFFIXES linux
linux64
bsd
bsd64
macosx
macosx64
macosxppc
macosxppc64
mingw
mingw64
gccsparcOS5
sparcOS5)
SYSTEMC_APPEND_TARGET(_SYSTEMC_PREFIX_SUFFIXES ${SYSTEMC_PREFIX}/lib- ${_SYSTEMC_TARGET_SUFFIXES})
SYSTEMC_APPEND_TARGET(_SYSTEMC_HOME_SUFFIXES $ENV{SYSTEMC_HOME}/lib- ${_SYSTEMC_TARGET_SUFFIXES})
SYSTEMC_APPEND_TARGET(_USR_SUFFIXES /usr/lib- ${_SYSTEMC_TARGET_SUFFIXES})
SYSTEMC_APPEND_TARGET(_USR_LOCAL_SUFFIXES /usr/local/lib- ${_SYSTEMC_TARGET_SUFFIXES})
set(_SYSTEMC_HINTS
${SYSTEMC_PREFIX}/include
${SYSTEMC_PREFIX}/lib
${_SYSTEMC_PREFIX_SUFFIXES}
$ENV{SYSTEMC_HOME}/lib
$ENV{SYSTEMC_HOME}/include
${_SYSTEMC_HOME_SUFFIXES})
set(_SYSTEMC_PATHS
/usr/local/lib
${_USR_LOCAL_SUFFIXES}
/usr/local/lib64
/usr/local/include
/usr/local/systemc
/usr/local/systemc/include
/usr/lib
${_USR_SUFFIXES}
/usr/lib64
/usr/include
/usr/systemc
/usr/systemc/include)
find_file(_SYSTEMC_VERSION_FILE
NAMES sc_ver.h
HINTS ${_SYSTEMC_HINTS}
PATHS ${_SYSTEMC_PATHS}
PATH_SUFFIXES sysc/kernel)
if(EXISTS ${_SYSTEMC_VERSION_FILE})
file (READ ${_SYSTEMC_VERSION_FILE} _SYSTEMC_VERSION_FILE_CONTENTS)
string (REGEX MATCH
"SC_API_VERSION_STRING[ \t]+sc_api_version_([0-9]+)_([0-9]+)_([0-9]+)"
SC_API_VERSION_STRING ${_SYSTEMC_VERSION_FILE_CONTENTS})
if(NOT "${SC_API_VERSION_STRING}" MATCHES "")
# SystemC < 2.3.1
string (REGEX MATCHALL "([0-9]+)" _SystemC_VERSION
${SC_API_VERSION_STRING})
list(GET _SystemC_VERSION 0 SystemC_VERSION_MAJOR)
list(GET _SystemC_VERSION 1 SystemC_VERSION_MINOR)
list(GET _SystemC_VERSION 2 SystemC_VERSION_PATCH)
else()
# SystemC >= 2.3.1
string (REGEX MATCH "SC_VERSION_MAJOR[ \t]+([0-9]+)"
SystemC_VERSION_MAJOR ${_SYSTEMC_VERSION_FILE_CONTENTS})
string (REGEX MATCH "([0-9]+)" SystemC_VERSION_MAJOR
${SystemC_VERSION_MAJOR})
string (REGEX MATCH "SC_VERSION_MINOR[ \t]+([0-9]+)"
SystemC_VERSION_MINOR ${_SYSTEMC_VERSION_FILE_CONTENTS})
string (REGEX MATCH "([0-9]+)" SystemC_VERSION_MINOR
${SystemC_VERSION_MINOR})
string (REGEX MATCH "SC_VERSION_PATCH[ \t]+([0-9]+)"
SystemC_VERSION_PATCH ${_SYSTEMC_VERSION_FILE_CONTENTS})
string (REGEX MATCH "([0-9]+)" SystemC_VERSION_PATCH
${SystemC_VERSION_PATCH})
endif()
set(SystemC_VERSION "${SystemC_VERSION_MAJOR}.${SystemC_VERSION_MINOR}.${SystemC_VERSION_PATCH}")
# Compatibility variable
set(SystemC_VERSION_STRING ${SystemC_VERSION})
find_path(SystemC_INCLUDE_DIRS
NAMES systemc systemc.h
HINTS ${_SYSTEMC_HINTS}
PATHS ${_SYSTEMC_PATHS})
# Static
set(_SystemC_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
if(WIN32)
set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
else()
set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
endif()
find_library(SystemC_LIBRARIES_STATIC
NAMES systemc SystemC
HINTS ${_SYSTEMC_HINTS}
PATHS ${_SYSTEMC_PATHS})
# Restore original CMAKE_FIND_LIBRARY_SUFFIXES
set(CMAKE_FIND_LIBRARY_SUFFIXES ${_SystemC_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
# If SystemC_USE_STATIC_LIBS set to ON, force the use of the static libraries
if(SystemC_USE_STATIC_LIBS)
set(SystemC_LIBRARIES SystemC_LIBRARIES_STATIC)
else()
find_library(SystemC_LIBRARIES
NAMES systemc SystemC
HINTS ${_SYSTEMC_HINTS}
PATHS ${_SYSTEMC_PATHS})
endif()
# Default
if(NOT TARGET SystemC::SystemC)
add_library(SystemC::SystemC UNKNOWN IMPORTED)
set_target_properties(SystemC::SystemC PROPERTIES
IMPORTED_LOCATION "${SystemC_LIBRARIES}")
endif()
# Static
if(NOT TARGET SystemC::SystemC_STATIC)
add_library(SystemC::SystemC_STATIC STATIC IMPORTED)
set_target_properties(SystemC::SystemC_STATIC PROPERTIES
IMPORTED_LOCATION "${SystemC_LIBRARIES_STATIC}")
endif()
if("${CMAKE_VERSION}" VERSION_GREATER 2.8.12)
get_filename_component(SystemC_LIBRARY_DIRS ${SystemC_LIBRARIES}
DIRECTORY)
else("${CMAKE_VERSION}" VERSION_GREATER 2.8.12)
get_filename_component(SystemC_LIBRARY_DIRS ${SystemC_LIBRARIES}
PATH)
endif()
endif()
include(FindPackageHandleStandardArgs)
if("${CMAKE_VERSION}" VERSION_GREATER 2.8.10)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SystemC
FOUND_VAR SystemC_FOUND
REQUIRED_VARS SystemC_LIBRARIES SystemC_LIBRARY_DIRS SystemC_INCLUDE_DIRS
VERSION_VAR SystemC_VERSION)
else()
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SystemC
REQUIRED_VARS SystemC_LIBRARIES SystemC_LIBRARY_DIRS SystemC_INCLUDE_DIRS
VERSION_VAR SystemC_VERSION)
set(SystemC_FOUND ${SYSTEMC_FOUND})
endif()
mark_as_advanced(SystemC_LIBRARIES SystemC_LIBRARY_DIRS SystemC_INCLUDE_DIRS)
... ...
# - Find TLM
# Find TLM
# This module finds if TLM is installed and determines where the
# include files and libraries are. This code sets the following
# variables: (from kernel/sc_ver.h)
# variables: (from tlm_version.h)
#
# TLM_VERSION_STRING = Version of the package found, eg. "2.2.0"
# TLM_VERSION_MAJOR = The major version of the package found.
# TLM_VERSION_MINOR = The minor version of the package found.
# TLM_VERSION_PATCH = The patch version of the package found.
# TLM_VERSION_DATE = The date of release (from TLM_VERSION)
# TLM_VERSION = This is set to: $major.$minor.$patch
# TLM_VERSION = The full version string of the package found.
#
# The minimum required version of TLM can be specified using the
# standard CMake syntax, e.g. FIND_PACKAGE(TLM 2.2)
... ... @@ -17,74 +15,61 @@
#
# TLM_FOUND - TRUE if all components are found.
# TLM_INCLUDE_DIRS - Full paths to all include dirs.
# TLM_LIBRARIES - Full paths to all libraries.
# TLM_<component>_FOUND - TRUE if <component> is found.
#
# Example Usages:
# FIND_PACKAGE(TLM)
# FIND_PACKAGE(TLM 2.3)
#
#=============================================================================
# Copyright 2012 GreenSocs
#
# Copyright 2015 GreenSocs
#=============================================================================
message(STATUS "Searching for TLM")
set(_TLM_HINTS
${TLM_PREFIX}
${SYSTEMC_PREFIX}/include
$ENV{TLM_HOME}
$ENV{SYSTEMC_HOME}/include)
set(_TLM_PATHS
/usr/local/include/tlm
/usr/local/include/systemc
/usr/include/tlm
/usr/include/systemc)
# The HINTS option should only be used for values computed from the system.
SET(_TLM_HINTS
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\TLM\\2.2;TLMHome]/include"
$ENV{TLM_HOME}
${SYSTEMC_PREFIX}/include
${SYSTEMC_PREFIX}/lib
${SYSTEMC_PREFIX}/lib-linux
${SYSTEMC_PREFIX}/lib-linux64
${SYSTEMC_PREFIX}/lib-macos
${SYSTEMC_PREFIX}/lib-macosx64
$ENV{SYSTEMC_PREFIX}/include
$ENV{SYSTEMC_PREFIX}/lib
$ENV{SYSTEMC_PREFIX}/lib-linux
$ENV{SYSTEMC_PREFIX}/lib-linux64
$ENV{SYSTEMC_PREFIX}/lib-macos
$ENV{SYSTEMC_PREFIX}/lib-macosx64
${CMAKE_INSTALL_PREFIX}/include
${CMAKE_INSTALL_PREFIX}/lib
${CMAKE_INSTALL_PREFIX}/lib-linux
${CMAKE_INSTALL_PREFIX}/lib-linux64
${CMAKE_INSTALL_PREFIX}/lib-macos
${CMAKE_INSTALL_PREFIX}/lib-macosx64
)
# Hard-coded guesses should still go in PATHS. This ensures that the user
# environment can always override hard guesses.
SET(_TLM_PATHS
/usr/include/TLM
/usr/include/systemc
/usr/lib
/usr/lib-linux
/usr/lib-linux64
/usr/lib-macos
/usr/lib-macosx64
/usr/local/lib
/usr/local/lib-linux
/usr/local/lib-linux64
/usr/local/lib-macos
/usr/local/lib-macosx64
)
find_file(_TLM_VERSION_FILE
NAMES tlm_version.h
HINTS ${_TLM_HINTS}
PATHS ${_TLM_PATHS}
PATH_SUFFIXES tlm_h
tlm/tlm_h
tlm_core/tlm_2)
FIND_PATH(TLM_INCLUDE_DIRS
NAMES tlm.h
HINTS ${_TLM_HINTS}
PATHS ${_TLM_PATHS}
PATH_SUFFIXES include/tlm
)
if(EXISTS ${_TLM_VERSION_FILE})
file (READ ${_TLM_VERSION_FILE} _TLM_VERSION_FILE_CONTENTS)
EXEC_PROGRAM("ls ${TLM_INCLUDE_DIRS}/tlm.h"
RETURN_VALUE ret)
string (REGEX MATCH "TLM_VERSION_MAJOR[ \t]+([0-9]+)"
TLM_VERSION_MAJOR ${_TLM_VERSION_FILE_CONTENTS})
string (REGEX MATCH "([0-9]+)" TLM_VERSION_MAJOR
${TLM_VERSION_MAJOR})
string (REGEX MATCH "TLM_VERSION_MINOR[ \t]+([0-9]+)"
TLM_VERSION_MINOR ${_TLM_VERSION_FILE_CONTENTS})
string (REGEX MATCH "([0-9]+)" TLM_VERSION_MINOR
${TLM_VERSION_MINOR})
string (REGEX MATCH "TLM_VERSION_PATCH[ \t]+([0-9]+)"
TLM_VERSION_PATCH ${_TLM_VERSION_FILE_CONTENTS})
string (REGEX MATCH "([0-9]+)" TLM_VERSION_PATCH
${TLM_VERSION_PATCH})
if("${ret}" MATCHES "0")
set(TLM_FOUND TRUE)
endif("${ret}" MATCHES "0")
set(TLM_VERSION "${TLM_VERSION_MAJOR}.${TLM_VERSION_MINOR}.${TLM_VERSION_PATCH}")
find_path(TLM_INCLUDE_DIRS
NAMES tlm tlm.h
HINTS ${_TLM_HINTS}
PATHS ${_TLM_PATHS}
PATH_SUFFIXES tlm)
message(STATUS "TLM library = ${TLM_INCLUDE_DIRS}/tlm.h")
endif()
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(TLM
REQUIRED_VARS TLM_INCLUDE_DIRS
VERSION_VAR TLM_VERSION)
\ No newline at end of file
... ...