-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvrtlmod-config.cmake.in
145 lines (123 loc) · 4.36 KB
/
vrtlmod-config.cmake.in
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
####################################################################################################
# Copyright 2022 Chair of EDA, Technical University of Munich
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
####################################################################################################
######################################################################
# \file: vrtlmod-config.cmake
# \date: February, 2021
# \brief: CMake configuration file for vrtlmod
# \details: Include in CMakeLists.txt with `find_package(vrtlmod)`. This adds a vrtlmod function to CMake.
# `vrtlmod()`
#######################################################################
cmake_minimum_required(VERSION 3.15)
# Prefer VRTLMOD_ROOT from environment
if (DEFINED ENV{VRTLMOD_ROOT})
set(VRTLMOD_ROOT "$ENV{VRTLMOD_ROOT}" CACHE PATH "VRTLMOD_ROOT")
endif()
set(VRTLMOD_ROOT "${CMAKE_CURRENT_LIST_DIR}" CACHE PATH "VRTLMOD_ROOT")
if (NOT VRTLMOD_ROOT)
message(FATAL_ERROR "VRTLMOD_ROOT cannot be detected.")
endif()
find_program(VRTLMOD NAMES vrtlmod
HINTS ${VRTLMOD_ROOT} "@CMAKE_INSTALL_PREFIX@" ENV VRTLMOD_ROOT
NO_CMAKE_PATH
NO_CMAKE_ENVIRONMENT_PATH
NO_CMAKE_SYSTEM_PATH
PATH_SUFFIXES bin
)
if (NOT VRTLMOD)
message(FATAL_ERROR "Cannot find vrtlmod executable.")
endif()
set(vrtlmod_FOUND 1)
function(vrtlmod)
set(options
SILENT
SYSTEMC
VERBOSE
)
set(oneValueArgs
OUT_DIR
WHITELIST_XML
CLANG_INCLUDE_DIR
SYSTEMC_INCLUDE_DIRS
)
set(multiValueArgs
INCLUDE_DIRS
SOURCES
OUTPUT
)
cmake_parse_arguments(VRTLMOD "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
# REQUIRED
message("sources: ${VRTLMOD_SOURCES}")
if(NOT VRTLMOD_SOURCES)
message(FATAL_ERROR "Need to specify a source file list vrtlmod(SOURCES)")
else()
set(SOURCES ${VRTLMOD_SOURCES})
endif()
if(NOT VRTLMOD_OUTPUT)
message(FATAL_ERROR "Need to specify an output for dependency")
else()
set(OUTPUT ${VRTLMOD_OUTPUT})
endif()
if(NOT VRTLMOD_OUT_DIR)
message(FATAL_ERROR "Need to specify an output directory [OUT_DIR]")
else()
set(OUT_DIR "--out=${VRTLMOD_OUT_DIR}")
endif()
if(VRTLMOD_WHITELIST_XML)
set(WHITELIST_XML "--wl-regxml=${VRTLMOD_WHITELIST_XML}")
endif()
# OPTIONAL
if(VRTLMOD_CLANG_INCLUDE_DIR)
set(CLANG_INCLUDE_DIRS "${VRTLMOD_CLANG_INCLUDE_DIR}")
else()
set(CLANG_INCLUDE_DIRS "@CLANG_INCLUDE_DIRS@")
endif()
if(VRTLMOD_SYSTEMC_INCLUDE_DIRS)
set(SYSTEMC_INCLUDE_DIRS "${VRTLMOD_SYSTEMC_INCLUDE_DIRS}")
else()
set(SYSTEMC_INCLUDE_DIRS "@SYSTEMC_INCLUDE_DIRS@")
endif()
if(VRTLMOD_SILENT)
set(SILENT --silent)
endif()
if(VRTLMOD_VERBOSE OR ${CMAKE_VERBOSE_MAKEFILE} EQUAL True)
set(VERBOSE -v)
endif()
if(VRTLMOD_SYSTEMC)
set(SYSTEMC --systemc)
endif()
set(INCLUDE_DIRS ${SYSTEMC_INCLUDE_DIRS} ${CLANG_INCLUDE_DIRS} ${VRTLMOD_INCLUDE_DIRS})
list(TRANSFORM INCLUDE_DIRS PREPEND "-I")
set(VRTLMOD_ARGS
${SYSTEMC}
${WHITELIST_XML}
${SILENT}
${VERBOSE}
${OUT_DIR}
${SOURCES}
)
set(CLANG_ARGS ${VERBOSE} -Wno-null-character -xc++ -stdlib=libstdc++ -std=c++${CMAKE_CXX_STANDARD} ${INCLUDE_DIRS})
set(ARGS_FILE ${CMAKE_CURRENT_BINARY_DIR}/vrtlmod-args.txt)
string(REPLACE ";" " " COMMAND_SPACES "${VRTLMOD} ${VRTLMOD_ARGS} -- clang++ ${CLANG_ARGS}")
file(WRITE ${ARGS_FILE} "${COMMAND_SPACES}")
add_custom_command(
OUTPUT ${OUTPUT}
DEPENDS ${SOURCES}
COMMAND ${VRTLMOD} ${VRTLMOD_ARGS} -- clang++ ${CLANG_ARGS}
COMMENT "executing vrtlmod: .. ${COMMAND_SPACES}"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
set(${SOURCES} ${OUTSOURCES} PARENT_SCOPE)
endfunction()