forked from nvdla/greenlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FindSystemC.cmake
175 lines (155 loc) · 6.5 KB
/
FindSystemC.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# 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_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_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)
#=============================================================================
# Copyright 2015 GreenSocs
#=============================================================================
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)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SystemC
FOUND_VAR SystemC_FOUND
REQUIRED_VARS SystemC_LIBRARIES SystemC_LIBRARY_DIRS SystemC_INCLUDE_DIRS
VERSION_VAR SystemC_VERSION)
if("${CMAKE_VERSION}" VERSION_LESS 2.8.11)
set(SystemC_FOUND ${SYSTEMC_FOUND})
endif()
mark_as_advanced(SystemC_LIBRARIES SystemC_LIBRARY_DIRS SystemC_INCLUDE_DIRS)