forked from gdslang/gdsl-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
187 lines (167 loc) · 6.53 KB
/
CMakeLists.txt
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
176
177
178
179
180
181
182
183
184
185
186
187
cmake_minimum_required (VERSION 2.8)
project (gdsl)
set(GDSL_MAJOR_VERSION 1)
set(GDSL_MINOR_VERSION 1)
set(GDSL_PATCH_VERSION 0)
set(GDSL_VERSION
${GDSL_MAJOR_VERSION}.${GDSL_MINOR_VERSION}.${GDSL_PATCH_VERSION})
# Offer the user the choice of overriding the installation directories
set(INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries")
set(INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables")
set(INSTALL_INCLUDE_DIR include CACHE PATH
"Installation directory for header files")
if(WIN32 AND NOT CYGWIN)
set(DEF_INSTALL_CMAKE_DIR CMake)
else()
set(DEF_INSTALL_CMAKE_DIR lib/CMake/gdsl)
endif()
set(INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH
"Installation directory for CMake files")
# Make relative paths absolute (needed later on)
foreach(p LIB BIN INCLUDE CMAKE)
set(var INSTALL_${p}_DIR)
if(NOT IS_ABSOLUTE "${${var}}")
set(${var} "${CMAKE_INSTALL_PREFIX}/${${var}}")
endif()
endforeach()
file(GLOB_RECURSE COMPILER_SOURCES
"detail/**.ml"
)
add_custom_command(COMMAND mlton -output ${CMAKE_BINARY_DIR}/gdslc ${CMAKE_CURRENT_SOURCE_DIR}/gdslc.mlb
OUTPUT ${CMAKE_BINARY_DIR}/gdslc
DEPENDS gdslc.mlb ${COMPILER_SOURCES}
)
add_custom_target(gdsl-compiler DEPENDS ${CMAKE_BINARY_DIR}/gdslc)
macro(frontend fend sources)
set(sources_merged ${sources} ${ARGN})
list(APPEND FRONTENDS ${fend})
add_custom_command(COMMAND ${CMAKE_BINARY_DIR}/gdslc --maxIter=42
--runtime=${CMAKE_CURRENT_SOURCE_DIR}/detail/codegen
--outname=gdsl-${fend}-rreil
${sources_merged}
OUTPUT gdsl-${fend}-rreil.c gdsl-${fend}-rreil.h
DEPENDS gdsl-compiler ${sources_merged}
)
add_library(gdsl_${fend}_rreil SHARED gdsl-${fend}-rreil.c)
set_target_properties(gdsl_${fend}_rreil PROPERTIES C_STANDARD 11)
target_include_directories(gdsl_${fend}_rreil PUBLIC #${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}> # <prefix>/include/
)
string(TOUPPER ${fend} FEND)
target_compile_definitions(gdsl_${fend}_rreil PUBLIC "USE_${FEND}_RREIL")
list(APPEND EXPORT_LIBRARIES gdsl_${fend}_rreil)
install(TARGETS gdsl_${fend}_rreil
# IMPORTANT: Add the library to the "export-set"
EXPORT gdslTargets
RUNTIME DESTINATION "${INSTALL_BIN_DIR}" COMPONENT bin
LIBRARY DESTINATION "${INSTALL_LIB_DIR}" COMPONENT lib
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}" COMPONENT lib
PUBLIC_HEADER DESTINATION "${INSTALL_INCLUDE_DIR}/"
COMPONENT dev)
endmacro(frontend)
set(GDSL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/specifications)
set(FRONTEND_SRCS_COMMON
${GDSL_DIR}/basis/prelude.ml
${GDSL_DIR}/basis/bbtree.ml
${GDSL_DIR}/basis/tree-set.ml
${GDSL_DIR}/rreil/rreil.ml
${GDSL_DIR}/rreil/rreil-examples.ml
${GDSL_DIR}/rreil/rreil-cif.ml
${GDSL_DIR}/rreil/rreil-pretty.ml
${GDSL_DIR}/rreil/fmap.ml
${GDSL_DIR}/rreil/rreil-opt.ml
${GDSL_DIR}/rreil/rreil-translator.ml
${GDSL_DIR}/rreil/rreil-liveness.ml
${GDSL_DIR}/rreil/rreil-forward-subst.ml
${GDSL_DIR}/rreil/forward-subst/delayed-forward-subst/inline.ml
${GDSL_DIR}/rreil/forward-subst/delayed-forward-subst/substitute.ml
${GDSL_DIR}/rreil/forward-subst/delayed-forward-subst/substmap.ml
${GDSL_DIR}/rreil/forward-subst/forward-subst/inline.ml
${GDSL_DIR}/rreil/forward-subst/forward-subst/substitute.ml
${GDSL_DIR}/rreil/forward-subst/forward-subst/substmap.ml
${GDSL_DIR}/rreil/forward-subst/forward-subst/simplify-expressions.ml
${GDSL_DIR}/rreil/rreil-cleanup.ml
${GDSL_DIR}/asm/asm.ml
${GDSL_DIR}/asm/asm-pretty.ml
${GDSL_DIR}/asm/asm-cif.ml
)
frontend(x86 ${FRONTEND_SRCS_COMMON}
${GDSL_DIR}/x86/x86.ml
${GDSL_DIR}/x86/x86-equals.ml
${GDSL_DIR}/x86/x86-traverse.ml
${GDSL_DIR}/x86/x86-pretty.ml
${GDSL_DIR}/x86/x86-asm.ml
${GDSL_DIR}/x86/x86-semantics-mapping.ml
${GDSL_DIR}/x86/x86-semantics-mapping-pretty.ml
${GDSL_DIR}/x86/x86-rreil-translator.ml
${GDSL_DIR}/x86/x86-rreil-translator-a-l.ml
${GDSL_DIR}/x86/x86-rreil-translator-m-z.ml
${GDSL_DIR}/x86/x86-liveness.ml
${GDSL_DIR}/x86-tester/x86-pretty-simple.ml
)
frontend(avr ${FRONTEND_SRCS_COMMON}
${GDSL_DIR}/avr/avr.ml
${GDSL_DIR}/avr/avr-traverse.ml
${GDSL_DIR}/avr/avr-pretty.ml
${GDSL_DIR}/avr/avr-asm.ml
${GDSL_DIR}/avr/avr-rreil-pretty.ml
${GDSL_DIR}/avr/avr-rreil-registermapping.ml
${GDSL_DIR}/avr/avr-rreil-translator.ml
${GDSL_DIR}/avr/avr-liveness.ml
)
frontend(arm7 ${FRONTEND_SRCS_COMMON}
${GDSL_DIR}/arm7/arm7.ml
${GDSL_DIR}/arm7/arm7-pretty.ml
${GDSL_DIR}/arm7/arm7-asm.ml
${GDSL_DIR}/arm7/arm7-rreil-registermapping.ml
${GDSL_DIR}/arm7/arm7-rreil-translator.ml
${GDSL_DIR}/arm7/arm7-rreil-pretty.ml
${GDSL_DIR}/arm7/arm7-liveness.ml
)
frontend(mips ${FRONTEND_SRCS_COMMON}
${GDSL_DIR}/mips/mips.ml
${GDSL_DIR}/mips/mips-pretty.ml
${GDSL_DIR}/mips/mips-rreil-pretty.ml
${GDSL_DIR}/mips/mips-rreil-registermapping.ml
${GDSL_DIR}/mips/mips-rreil-translator.ml
${GDSL_DIR}/mips/mips-liveness.ml
${GDSL_DIR}/mips/mips-asm.ml
${GDSL_DIR}/mips/mips-traverse.ml
${GDSL_DIR}/mips/mips_r6.ml
${GDSL_DIR}/mips/mips-pretty_r6.ml
${GDSL_DIR}/mips/mips-rreil-translator_r6.ml
${GDSL_DIR}/mips/mips-asm_r6.ml
${GDSL_DIR}/mips/mips-traverse_r6.ml
)
add_subdirectory(libs)
add_subdirectory(tools)
# Add all targets to the build-tree export set
export(TARGETS ${EXPORT_LIBRARIES}
FILE "${PROJECT_BINARY_DIR}/gdslTargets.cmake")
# Export the package for use from the build-tree
# (this registers the build-tree with a global CMake-registry)
export(PACKAGE gdsl)
# Create the gdslConfig.cmake and gdslConfigVersion files
file(RELATIVE_PATH REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR}"
"${INSTALL_INCLUDE_DIR}")
# ... for the build tree
set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}" "${PROJECT_BINARY_DIR}")
configure_file(gdslConfig.cmake.in
"${PROJECT_BINARY_DIR}/gdslConfig.cmake" @ONLY)
# ... for the install tree
set(CONF_INCLUDE_DIRS "\${FOOBAR_CMAKE_DIR}/${REL_INCLUDE_DIR}")
configure_file(gdslConfig.cmake.in
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/gdslConfig.cmake" @ONLY)
# ... for both
configure_file(gdslConfigVersion.cmake.in
"${PROJECT_BINARY_DIR}/gdslConfigVersion.cmake" @ONLY)
# Install the gdslConfig.cmake and gdslConfigVersion.cmake
install(FILES
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/gdslConfig.cmake"
"${PROJECT_BINARY_DIR}/gdslConfigVersion.cmake"
DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev)
# Install the export set for use with the install-tree
install(EXPORT gdslTargets DESTINATION
"${INSTALL_CMAKE_DIR}" COMPONENT dev)