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}) @@ -45,7 +45,6 @@ LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
45 FIND_PACKAGE(SystemC) 45 FIND_PACKAGE(SystemC)
46 if(SystemC_FOUND) 46 if(SystemC_FOUND)
47 INCLUDE_DIRECTORIES(${SystemC_INCLUDE_DIRS}) 47 INCLUDE_DIRECTORIES(${SystemC_INCLUDE_DIRS})
48 - LINK_DIRECTORIES(${SystemC_LIBRARY_DIRS})  
49 else() 48 else()
50 MESSAGE(FATAL_ERROR "SystemC library not found.") 49 MESSAGE(FATAL_ERROR "SystemC library not found.")
51 endif() 50 endif()
1 -# - Find SystemC 1 +# Find SystemC
2 # This module finds if SystemC is installed and determines where the 2 # This module finds if SystemC is installed and determines where the
3 # include files and libraries are. This code sets the following 3 # include files and libraries are. This code sets the following
4 # variables: (from kernel/sc_ver.h) 4 # variables: (from kernel/sc_ver.h)
5 # 5 #
6 -# SystemC_VERSION_MAJOR = The major version of the package found. 6 +# SystemC_VERSION_MAJOR = The major version of the package found
7 -# SystemC_VERSION_MINOR = The minor version of the package found. 7 +# SystemC_VERSION_MINOR = The minor version of the package found
8 -# SystemC_VERSION_REV = The patch version of the package found. 8 +# SystemC_VERSION_PATCH = The patch version of the package found
9 -# SystemC_VERSION = This is set to: $major.$minor.$rev 9 +# SystemC_VERSION = The full version string of the package found
10 -#  
11 -# The minimum required version of SystemC can be specified using the  
12 -# standard CMake syntax, e.g. FIND_PACKAGE(SystemC 2.2)  
13 # 10 #
14 # For these components the following variables are set: 11 # For these components the following variables are set:
15 # 12 #
16 -# SystemC_INCLUDE_DIRS - Full paths to all include dirs. 13 +# SystemC_INCLUDE_DIRS - Full paths to all include dirs
17 -# SystemC_LIBRARIES - Full paths to all libraries. 14 +# SystemC_LIBRARY_DIRS - Link directories for SystemC libraries
  15 +# SystemC::SystemC - Full path to SystemC library
  16 +# SystemC::SystemC_STATIC - Full path to SystemC static library
18 # 17 #
19 # Example Usages: 18 # Example Usages:
20 -# FIND_PACKAGE(SystemC) 19 +# find_package(SystemC)
21 -# FIND_PACKAGE(SystemC 2.3)  
22 -#  
23 20
24 #============================================================================= 21 #=============================================================================
25 -# Copyright 2012 GreenSocs 22 +# Copyright 2015 GreenSocs
26 -#  
27 #============================================================================= 23 #=============================================================================
28 24
29 -message(STATUS "Searching for SystemC") 25 +function(SYSTEMC_APPEND_TARGET var prefix)
30 - 26 + set(listVar "")
31 -# The HINTS option should only be used for values computed from the system. 27 + foreach(f ${ARGN})
32 -SET(_SYSTEMC_HINTS 28 + list(APPEND listVar "${prefix}${f}")
33 - "[HKEY_LOCAL_MACHINE\\SOFTWARE\\SystemC\\2.2;SystemcHome]/include" 29 + endforeach(f)
34 - ${SYSTEMC_PREFIX}/include 30 + set(${var} "${listVar}" PARENT_SCOPE)
35 - ${SYSTEMC_PREFIX}/lib 31 +endfunction(SYSTEMC_APPEND_TARGET)
36 - ${SYSTEMC_PREFIX}/lib-linux 32 +
37 - ${SYSTEMC_PREFIX}/lib-linux64 33 +set(_SYSTEMC_TARGET_SUFFIXES linux
38 - ${SYSTEMC_PREFIX}/lib-macos 34 + linux64
39 - ${SYSTEMC_PREFIX}/lib-macosx64 35 + bsd
40 - $ENV{SYSTEMC_PREFIX}/include 36 + bsd64
41 - $ENV{SYSTEMC_PREFIX}/lib 37 + macosx
42 - $ENV{SYSTEMC_PREFIX}/lib-linux 38 + macosx64
43 - $ENV{SYSTEMC_PREFIX}/lib-linux64 39 + macosxppc
44 - $ENV{SYSTEMC_PREFIX}/lib-macos 40 + macosxppc64
45 - $ENV{SYSTEMC_PREFIX}/lib-macosx64 41 + mingw
46 - ${CMAKE_INSTALL_PREFIX}/include 42 + mingw64
47 - ${CMAKE_INSTALL_PREFIX}/lib 43 + gccsparcOS5
48 - ${CMAKE_INSTALL_PREFIX}/lib-linux 44 + sparcOS5)
49 - ${CMAKE_INSTALL_PREFIX}/lib-linux64 45 +
50 - ${CMAKE_INSTALL_PREFIX}/lib-macos 46 +SYSTEMC_APPEND_TARGET(_SYSTEMC_PREFIX_SUFFIXES ${SYSTEMC_PREFIX}/lib- ${_SYSTEMC_TARGET_SUFFIXES})
51 - ${CMAKE_INSTALL_PREFIX}/lib-macosx64 47 +SYSTEMC_APPEND_TARGET(_SYSTEMC_HOME_SUFFIXES $ENV{SYSTEMC_HOME}/lib- ${_SYSTEMC_TARGET_SUFFIXES})
52 - ) 48 +SYSTEMC_APPEND_TARGET(_USR_SUFFIXES /usr/lib- ${_SYSTEMC_TARGET_SUFFIXES})
53 -# Hard-coded guesses should still go in PATHS. This ensures that the user 49 +SYSTEMC_APPEND_TARGET(_USR_LOCAL_SUFFIXES /usr/local/lib- ${_SYSTEMC_TARGET_SUFFIXES})
54 -# environment can always override hard guesses. 50 +
55 -SET(_SYSTEMC_PATHS 51 +set(_SYSTEMC_HINTS
56 - /usr/include/systemc 52 + ${SYSTEMC_PREFIX}/include
57 - /usr/lib 53 + ${SYSTEMC_PREFIX}/lib
58 - /usr/lib-linux 54 + ${_SYSTEMC_PREFIX_SUFFIXES}
59 - /usr/lib-linux64 55 + $ENV{SYSTEMC_HOME}/lib
60 - /usr/lib-macos 56 + $ENV{SYSTEMC_HOME}/include
61 - /usr/lib-macosx64 57 + ${_SYSTEMC_HOME_SUFFIXES})
62 - /usr/local/lib 58 +
63 - /usr/local/lib-linux 59 +set(_SYSTEMC_PATHS
64 - /usr/local/lib-linux64 60 + /usr/local/lib
65 - /usr/local/lib-macos 61 + ${_USR_LOCAL_SUFFIXES}
66 - /usr/local/lib-macosx64 62 + /usr/local/lib64
67 - ) 63 + /usr/local/include
68 -FIND_FILE(_SYSTEMC_VERSION_FILE 64 + /usr/local/systemc
69 - NAMES sc_ver.h 65 + /usr/local/systemc/include
70 - HINTS ${_SYSTEMC_HINTS} 66 + /usr/lib
71 - PATHS ${_SYSTEMC_PATHS} 67 + ${_USR_SUFFIXES}
72 - PATH_SUFFIXES sysc/kernel 68 + /usr/lib64
73 -) 69 + /usr/include
74 - 70 + /usr/systemc
75 -EXEC_PROGRAM("cat ${_SYSTEMC_VERSION_FILE} |grep '#define SC_API_VERSION_STRING' | cut -d '_' -f 7 " 71 + /usr/systemc/include)
76 - OUTPUT_VARIABLE SystemC_MAJOR) 72 +
77 -EXEC_PROGRAM("cat ${_SYSTEMC_VERSION_FILE} |grep '#define SC_API_VERSION_STRING' | cut -d '_' -f 8 " 73 +find_file(_SYSTEMC_VERSION_FILE
78 - OUTPUT_VARIABLE SystemC_MINOR) 74 + NAMES sc_ver.h
79 -EXEC_PROGRAM("cat ${_SYSTEMC_VERSION_FILE} |grep '#define SC_API_VERSION_STRING' | cut -d '_' -f 9 " 75 + HINTS ${_SYSTEMC_HINTS}
80 - OUTPUT_VARIABLE SystemC_REV) 76 + PATHS ${_SYSTEMC_PATHS}
81 - 77 + PATH_SUFFIXES sysc/kernel)
82 -set(SystemC_VERSION ${SystemC_MAJOR}.${SystemC_MINOR}.${SystemC_REV}) 78 +
83 - 79 +if(EXISTS ${_SYSTEMC_VERSION_FILE})
84 -if("${SystemC_MAJOR}" MATCHES "2") 80 + file (READ ${_SYSTEMC_VERSION_FILE} _SYSTEMC_VERSION_FILE_CONTENTS)
85 - set(SystemC_FOUND TRUE) 81 + string (REGEX MATCH
86 -endif("${SystemC_MAJOR}" MATCHES "2") 82 + "SC_API_VERSION_STRING[ \t]+sc_api_version_([0-9]+)_([0-9]+)_([0-9]+)"
87 - 83 + SC_API_VERSION_STRING ${_SYSTEMC_VERSION_FILE_CONTENTS})
88 -message(STATUS "SystemC version = ${SystemC_VERSION}") 84 +
89 - 85 + if(NOT "${SC_API_VERSION_STRING}" MATCHES "")
90 -FIND_PATH(SystemC_INCLUDE_DIRS 86 + # SystemC < 2.3.1
91 - NAMES systemc.h 87 + string (REGEX MATCHALL "([0-9]+)" _SystemC_VERSION
92 - HINTS ${_SYSTEMC_HINTS} 88 + ${SC_API_VERSION_STRING})
93 - PATHS ${_SYSTEMC_PATHS} 89 + list(GET _SystemC_VERSION 0 SystemC_VERSION_MAJOR)
94 -) 90 + list(GET _SystemC_VERSION 1 SystemC_VERSION_MINOR)
95 - 91 + list(GET _SystemC_VERSION 2 SystemC_VERSION_PATCH)
96 -FIND_PATH(SystemC_LIBRARY_DIRS 92 + else()
97 - NAMES libsystemc.a 93 + # SystemC >= 2.3.1
98 - HINTS ${_SYSTEMC_HINTS} 94 + string (REGEX MATCH "SC_VERSION_MAJOR[ \t]+([0-9]+)"
99 - PATHS ${_SYSTEMC_PATHS} 95 + SystemC_VERSION_MAJOR ${_SYSTEMC_VERSION_FILE_CONTENTS})
100 -) 96 + string (REGEX MATCH "([0-9]+)" SystemC_VERSION_MAJOR
101 - 97 + ${SystemC_VERSION_MAJOR})
102 -set(SystemC_LIBRARIES ${SystemC_LIBRARY_DIRS}/libsystemc.a) 98 + string (REGEX MATCH "SC_VERSION_MINOR[ \t]+([0-9]+)"
103 - 99 + SystemC_VERSION_MINOR ${_SYSTEMC_VERSION_FILE_CONTENTS})
104 -message(STATUS "SystemC library = ${SystemC_LIBRARIES}") 100 + string (REGEX MATCH "([0-9]+)" SystemC_VERSION_MINOR
  101 + ${SystemC_VERSION_MINOR})
  102 + string (REGEX MATCH "SC_VERSION_PATCH[ \t]+([0-9]+)"
  103 + SystemC_VERSION_PATCH ${_SYSTEMC_VERSION_FILE_CONTENTS})
  104 + string (REGEX MATCH "([0-9]+)" SystemC_VERSION_PATCH
  105 + ${SystemC_VERSION_PATCH})
  106 + endif()
  107 +
  108 + set(SystemC_VERSION "${SystemC_VERSION_MAJOR}.${SystemC_VERSION_MINOR}.${SystemC_VERSION_PATCH}")
  109 +
  110 + # Compatibility variable
  111 + set(SystemC_VERSION_STRING ${SystemC_VERSION})
  112 +
  113 + find_path(SystemC_INCLUDE_DIRS
  114 + NAMES systemc systemc.h
  115 + HINTS ${_SYSTEMC_HINTS}
  116 + PATHS ${_SYSTEMC_PATHS})
  117 +
  118 + # Static
  119 + set(_SystemC_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
  120 + if(WIN32)
  121 + set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
  122 + else()
  123 + set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
  124 + endif()
  125 +
  126 + find_library(SystemC_LIBRARIES_STATIC
  127 + NAMES systemc SystemC
  128 + HINTS ${_SYSTEMC_HINTS}
  129 + PATHS ${_SYSTEMC_PATHS})
  130 +
  131 + # Restore original CMAKE_FIND_LIBRARY_SUFFIXES
  132 + set(CMAKE_FIND_LIBRARY_SUFFIXES ${_SystemC_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
  133 +
  134 + # If SystemC_USE_STATIC_LIBS set to ON, force the use of the static libraries
  135 + if(SystemC_USE_STATIC_LIBS)
  136 + set(SystemC_LIBRARIES SystemC_LIBRARIES_STATIC)
  137 + else()
  138 + find_library(SystemC_LIBRARIES
  139 + NAMES systemc SystemC
  140 + HINTS ${_SYSTEMC_HINTS}
  141 + PATHS ${_SYSTEMC_PATHS})
  142 + endif()
  143 +
  144 + # Default
  145 + if(NOT TARGET SystemC::SystemC)
  146 + add_library(SystemC::SystemC UNKNOWN IMPORTED)
  147 + set_target_properties(SystemC::SystemC PROPERTIES
  148 + IMPORTED_LOCATION "${SystemC_LIBRARIES}")
  149 + endif()
  150 +
  151 + # Static
  152 + if(NOT TARGET SystemC::SystemC_STATIC)
  153 + add_library(SystemC::SystemC_STATIC STATIC IMPORTED)
  154 + set_target_properties(SystemC::SystemC_STATIC PROPERTIES
  155 + IMPORTED_LOCATION "${SystemC_LIBRARIES_STATIC}")
  156 + endif()
  157 +
  158 + if("${CMAKE_VERSION}" VERSION_GREATER 2.8.12)
  159 + get_filename_component(SystemC_LIBRARY_DIRS ${SystemC_LIBRARIES}
  160 + DIRECTORY)
  161 + else("${CMAKE_VERSION}" VERSION_GREATER 2.8.12)
  162 + get_filename_component(SystemC_LIBRARY_DIRS ${SystemC_LIBRARIES}
  163 + PATH)
  164 + endif()
  165 +endif()
  166 +
  167 +include(FindPackageHandleStandardArgs)
  168 +if("${CMAKE_VERSION}" VERSION_GREATER 2.8.10)
  169 + FIND_PACKAGE_HANDLE_STANDARD_ARGS(SystemC
  170 + FOUND_VAR SystemC_FOUND
  171 + REQUIRED_VARS SystemC_LIBRARIES SystemC_LIBRARY_DIRS SystemC_INCLUDE_DIRS
  172 + VERSION_VAR SystemC_VERSION)
  173 +else()
  174 + FIND_PACKAGE_HANDLE_STANDARD_ARGS(SystemC
  175 + REQUIRED_VARS SystemC_LIBRARIES SystemC_LIBRARY_DIRS SystemC_INCLUDE_DIRS
  176 + VERSION_VAR SystemC_VERSION)
  177 + set(SystemC_FOUND ${SYSTEMC_FOUND})
  178 +endif()
  179 +mark_as_advanced(SystemC_LIBRARIES SystemC_LIBRARY_DIRS SystemC_INCLUDE_DIRS)
1 -# - Find TLM 1 +# Find TLM
2 # This module finds if TLM is installed and determines where the 2 # This module finds if TLM is installed and determines where the
3 # include files and libraries are. This code sets the following 3 # include files and libraries are. This code sets the following
4 -# variables: (from kernel/sc_ver.h) 4 +# variables: (from tlm_version.h)
5 # 5 #
6 -# TLM_VERSION_STRING = Version of the package found, eg. "2.2.0"  
7 # TLM_VERSION_MAJOR = The major version of the package found. 6 # TLM_VERSION_MAJOR = The major version of the package found.
8 # TLM_VERSION_MINOR = The minor version of the package found. 7 # TLM_VERSION_MINOR = The minor version of the package found.
9 # TLM_VERSION_PATCH = The patch version of the package found. 8 # TLM_VERSION_PATCH = The patch version of the package found.
10 -# TLM_VERSION_DATE = The date of release (from TLM_VERSION) 9 +# TLM_VERSION = The full version string of the package found.
11 -# TLM_VERSION = This is set to: $major.$minor.$patch  
12 # 10 #
13 # The minimum required version of TLM can be specified using the 11 # The minimum required version of TLM can be specified using the
14 # standard CMake syntax, e.g. FIND_PACKAGE(TLM 2.2) 12 # standard CMake syntax, e.g. FIND_PACKAGE(TLM 2.2)
@@ -17,74 +15,61 @@ @@ -17,74 +15,61 @@
17 # 15 #
18 # TLM_FOUND - TRUE if all components are found. 16 # TLM_FOUND - TRUE if all components are found.
19 # TLM_INCLUDE_DIRS - Full paths to all include dirs. 17 # TLM_INCLUDE_DIRS - Full paths to all include dirs.
20 -# TLM_LIBRARIES - Full paths to all libraries.  
21 -# TLM_<component>_FOUND - TRUE if <component> is found.  
22 # 18 #
23 # Example Usages: 19 # Example Usages:
24 # FIND_PACKAGE(TLM) 20 # FIND_PACKAGE(TLM)
25 -# FIND_PACKAGE(TLM 2.3)  
26 -#  
27 21
28 #============================================================================= 22 #=============================================================================
29 -# Copyright 2012 GreenSocs 23 +# Copyright 2015 GreenSocs
30 -#  
31 #============================================================================= 24 #=============================================================================
32 25
33 -message(STATUS "Searching for TLM") 26 +set(_TLM_HINTS
  27 + ${TLM_PREFIX}
  28 + ${SYSTEMC_PREFIX}/include
  29 + $ENV{TLM_HOME}
  30 + $ENV{SYSTEMC_HOME}/include)
  31 +
  32 +set(_TLM_PATHS
  33 + /usr/local/include/tlm
  34 + /usr/local/include/systemc
  35 + /usr/include/tlm
  36 + /usr/include/systemc)
34 37
35 -# The HINTS option should only be used for values computed from the system. 38 +find_file(_TLM_VERSION_FILE
36 -SET(_TLM_HINTS 39 + NAMES tlm_version.h
37 - "[HKEY_LOCAL_MACHINE\\SOFTWARE\\TLM\\2.2;TLMHome]/include" 40 + HINTS ${_TLM_HINTS}
38 - $ENV{TLM_HOME} 41 + PATHS ${_TLM_PATHS}
39 - ${SYSTEMC_PREFIX}/include 42 + PATH_SUFFIXES tlm_h
40 - ${SYSTEMC_PREFIX}/lib 43 + tlm/tlm_h
41 - ${SYSTEMC_PREFIX}/lib-linux 44 + tlm_core/tlm_2)
42 - ${SYSTEMC_PREFIX}/lib-linux64  
43 - ${SYSTEMC_PREFIX}/lib-macos  
44 - ${SYSTEMC_PREFIX}/lib-macosx64  
45 - $ENV{SYSTEMC_PREFIX}/include  
46 - $ENV{SYSTEMC_PREFIX}/lib  
47 - $ENV{SYSTEMC_PREFIX}/lib-linux  
48 - $ENV{SYSTEMC_PREFIX}/lib-linux64  
49 - $ENV{SYSTEMC_PREFIX}/lib-macos  
50 - $ENV{SYSTEMC_PREFIX}/lib-macosx64  
51 - ${CMAKE_INSTALL_PREFIX}/include  
52 - ${CMAKE_INSTALL_PREFIX}/lib  
53 - ${CMAKE_INSTALL_PREFIX}/lib-linux  
54 - ${CMAKE_INSTALL_PREFIX}/lib-linux64  
55 - ${CMAKE_INSTALL_PREFIX}/lib-macos  
56 - ${CMAKE_INSTALL_PREFIX}/lib-macosx64  
57 - )  
58 -# Hard-coded guesses should still go in PATHS. This ensures that the user  
59 -# environment can always override hard guesses.  
60 -SET(_TLM_PATHS  
61 - /usr/include/TLM  
62 - /usr/include/systemc  
63 - /usr/lib  
64 - /usr/lib-linux  
65 - /usr/lib-linux64  
66 - /usr/lib-macos  
67 - /usr/lib-macosx64  
68 - /usr/local/lib  
69 - /usr/local/lib-linux  
70 - /usr/local/lib-linux64  
71 - /usr/local/lib-macos  
72 - /usr/local/lib-macosx64  
73 - )  
74 45
75 -FIND_PATH(TLM_INCLUDE_DIRS 46 +if(EXISTS ${_TLM_VERSION_FILE})
76 - NAMES tlm.h 47 + file (READ ${_TLM_VERSION_FILE} _TLM_VERSION_FILE_CONTENTS)
77 - HINTS ${_TLM_HINTS}  
78 - PATHS ${_TLM_PATHS}  
79 - PATH_SUFFIXES include/tlm  
80 -)  
81 48
82 -EXEC_PROGRAM("ls ${TLM_INCLUDE_DIRS}/tlm.h" 49 + string (REGEX MATCH "TLM_VERSION_MAJOR[ \t]+([0-9]+)"
83 - RETURN_VALUE ret) 50 + TLM_VERSION_MAJOR ${_TLM_VERSION_FILE_CONTENTS})
  51 + string (REGEX MATCH "([0-9]+)" TLM_VERSION_MAJOR
  52 + ${TLM_VERSION_MAJOR})
  53 + string (REGEX MATCH "TLM_VERSION_MINOR[ \t]+([0-9]+)"
  54 + TLM_VERSION_MINOR ${_TLM_VERSION_FILE_CONTENTS})
  55 + string (REGEX MATCH "([0-9]+)" TLM_VERSION_MINOR
  56 + ${TLM_VERSION_MINOR})
  57 + string (REGEX MATCH "TLM_VERSION_PATCH[ \t]+([0-9]+)"
  58 + TLM_VERSION_PATCH ${_TLM_VERSION_FILE_CONTENTS})
  59 + string (REGEX MATCH "([0-9]+)" TLM_VERSION_PATCH
  60 + ${TLM_VERSION_PATCH})
84 61
85 -if("${ret}" MATCHES "0") 62 + set(TLM_VERSION "${TLM_VERSION_MAJOR}.${TLM_VERSION_MINOR}.${TLM_VERSION_PATCH}")
86 - set(TLM_FOUND TRUE) 63 +
87 -endif("${ret}" MATCHES "0") 64 + find_path(TLM_INCLUDE_DIRS
  65 + NAMES tlm tlm.h
  66 + HINTS ${_TLM_HINTS}
  67 + PATHS ${_TLM_PATHS}
  68 + PATH_SUFFIXES tlm)
88 69
89 -message(STATUS "TLM library = ${TLM_INCLUDE_DIRS}/tlm.h") 70 +endif()
90 71
  72 +include(FindPackageHandleStandardArgs)
  73 +FIND_PACKAGE_HANDLE_STANDARD_ARGS(TLM
  74 + REQUIRED_VARS TLM_INCLUDE_DIRS
  75 + VERSION_VAR TLM_VERSION)