-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
244 lines (228 loc) · 5.3 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# CMakeLists.txt for ICI.
#
# By default this builds the ICI dynamic library and corresponding
# ici.h file, and a ici executable linked against the dynamic
# library.
#
# Alternatively, if the ICI_BUILD_SHARED_LIB option is disabled
# (set to OFF) no library is built.
#
# There is no 'install' support as yet.
#
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
project(ici LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 14)
option(ICI_BUILD_DYNAMIC_LIB "Build the ICI dynamic library" ON)
option(ICI_BUILD_STATIC_LIB "Build the ICI static library" OFF)
option(ICI_VEC_USE_IPP "Use Intel IPP for vec arithmetic" ON)
option(ICI_TUNE_NATIVE "Tune optimization for the host CPU" ON)
# Use IPP_ROOT environment variable to find IPP
cmake_policy(SET CMP0074 NEW)
set(ICI_SOURCES
alloc.cc
aplfuncs.cc
archiver.cc
arith.cc
array.cc
buf.cc
call.cc
catcher.cc
cfunc.cc
cfunco.cc
channel.cc
compile.cc
conf.cc
control.cc
crc.cc
crc32c.cc
debug.cc
debugger.cc
error.cc
events.cc
exec.cc
exerror.cc
file.cc
findpath.cc
float.cc
forall.cc
ftype.cc
func.cc
handle.cc
icimain.cc
init.cc
int.cc
lex.cc
load.cc
map.cc
mark.cc
mem.cc
method.cc
mkvar.cc
net.cc
null.cc
object.cc
oofuncs.cc
op.cc
parse.cc
pc.cc
pcre.cc
profile.cc
ptr.cc
ref.h
refuncs.cc
regexp.cc
repl.cc
set.cc
sfile.cc
signals.cc
smash.cc
src.cc
sstring.cc
string.cc
strtol.cc
study.cc
sys.cc
syserr.cc
thread.cc
type.cc
types.cc
unary.cc
uninit.cc
userop.cc
vec.cc
alloc.h
archiver.h
array.h
binop.h
buf.h
catcher.h
cfunc.h
channel.h
chartables.i
debugger.h
error.h
exec.h
file.h
float.h
forall.h
ftype.h
func.h
fwd.h
handle.h
icistr-setup.h
int.h
internal.h
load-w32.h
map.h
mark.h
mem.h
method.h
null.h
object.h
op.h
parse.h
pc.h
pcre.h
primes.h
profile.h
ptr.h
re.h
repl.h
set.h
src.h
sstring.h
str.h
type.h
types.h
vec.h
vecops.h
wrap.h
userop.h)
if(WIN32)
set(ICI_SOURCES "${ICI_SOURCES} win32err.cc win32timezone.cc")
endif()
# Explicitly disable any optimization for debug builds (some compilers
# optimize by default, e.g. icc)
#
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g" CACHE STRING "" FORCE)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if (ICI_TUNE_NATIVE)
if (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
add_compile_options("-mtune=native")
endif()
endif()
# If we're using IPP we need to "find" it. To do that we have a
# custom cmake module, FindIPP.cmake. To locate FindIPP.cmake cmake
# uses a _module path_ and we add our 'etc' directory to that path as
# our file resides there. That's not enough.
#
# To allow rebuilds to work we have to, (a) force the modified value
# of CMAKE_MODULE_PATH to be set in cmake's cache file and, (b) use
# an absolute path for our 'etc' directory so it can be found.
#
if(ICI_VEC_USE_IPP)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/etc" CACHE PATH "" FORCE)
find_package(IPP REQUIRED)
cmake_policy(SET CMP0042 NEW)
set(CMAKE_BUILD_RPATH ${IPP_LIBRARIES_PATH})
endif(ICI_VEC_USE_IPP)
# Building...
#
if(ICI_BUILD_DYNAMIC_LIB)
set(ICI_TARGET "ici")
add_library(ici SHARED ${ICI_SOURCES})
add_executable(ici_exe etc/main.cc)
target_link_libraries(ici_exe PUBLIC ici)
elseif(ICI_BUILD_STATIC_LIB)
set(ICI_TARGET "ici_exe")
add_library(ici STATIC ${ICI_SOURCES})
add_executable(ici_exe etc/main.cc)
target_link_libraries(ici_exe PUBLIC ici)
else()
set(ICI_TARGET "ici_exe")
add_executable(ici_exe etc/main.cc ${ICI_SOURCES})
endif()
# The executable target can't be called 'ici' since that's the name
# of the library. Instead we call it 'ici_exe'. Doing that, however,
# results in the executable file being named 'ici_exe[.exe]' which we
# don't want so we have to set the 'OUTPUT_NAME' property of the
# ici_exe target to the file name we want.
#
if(WIN32)
set_target_properties(ici_exe PROPERTIES OUTPUT_NAME ici.exe)
else()
set_target_properties(ici_exe PROPERTIES OUTPUT_NAME ici)
endif()
# Required libraries:
#
# - Linux and FreeBSD need -lpthread
# - Linux glibc still has dlopen et al in libdl
#
if("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "FreeBSD")
target_link_libraries(ici_exe PUBLIC -lpthread)
endif()
if ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Linux")
target_link_libraries(ici_exe PUBLIC -ldl -lpthread)
endif()
# And if we're using IPP we need to include its options
# and libraries.
#
if(ICI_VEC_USE_IPP)
target_compile_definitions(${ICI_TARGET} PUBLIC ICI_VEC_USE_IPP)
target_include_directories(${ICI_TARGET} PUBLIC ${IPP_INCLUDE_DIRS})
target_link_libraries(${ICI_TARGET} PUBLIC ${IPP_LIBRARIES})
endif()
# To create ici.h we use the, just built, ici executable to
# run mk-ici-h.ici which creates ici.h from the ICI headers.
# To run that specific executable we need to use the actual
# OUTPUT_NAME property of ici_exe.
#
# Also mk-ici-h.ici needs to be told the specific config
# header file used so we figure that out too (fwd.h does
# something similar).
#
add_custom_command(TARGET ici_exe POST_BUILD
COMMENT "[----] Creating ici.h"
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/etc/mk-ici-dot-h.sh
${ici_BINARY_DIR}/ici ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}
)