forked from shidasan/konoha2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
352 lines (305 loc) · 10.4 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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
include(CheckTypeSize)
include(CheckIncludeFiles)
include(CheckSymbolExists)
include(CheckLibraryExists)
cmake_minimum_required(VERSION 2.6)
project(konoha2)
set(VERSION_MAJOR "2")
set(VERSION_MINOR "0")
set(VERSION_PATCH "0")
set(PACKAGE_NAME ${PROJECT_NAME})
set(PACKAGE_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
set(PACKAGE_STRING ${CMAKE_PROJECT_NAME}-${PACKAGE_VERSION})
set(SO_VERSION ${VERSION_MAJOR}.${VERSION_MINOR})
set(PACKAGE_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(K_CONFIG_ARCH ${CMAKE_SYSTEM})
set(K_CONFIG_OS ${CMAKE_SYSTEM_NAME})
set(K_CONFIG_CPU ${CMAKE_SYSTEM_PROCESSOR})
set(K_PREFIX ${CMAKE_INSTALL_PREFIX})
if(UNIX)
set(K_OSDLLEXT ".so")
endif(UNIX)
if(APPLE)
set(K_OSDLLEXT ".dylib")
endif(APPLE)
if(CYGWIN)
set(K_OSDLLEXT ".so")
endif(CYGWIN)
if(MSVC)
set(K_OSDLLEXT ".dll")
endif(MSVC)
if(MINGW)
set(K_OSDLLEXT ".dll")
endif(MINGW)
set(INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_BINARY_DIR})
include_directories(${INCLUDE_DIRS})
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" )
endif()
string(TOUPPER ${CMAKE_BUILD_TYPE} uppercase_CMAKE_BUILD_TYPE)
option(USE_X86_32 off)
set(KONOHA_CFLAGS "")
if(USE_X86_32)
set(KONOHA_CFLAGS "-m32")
endif(USE_X86_32)
SET(CMAKE_C_FLAGS "-Wall ${KONOHA_CFLAGS}")
SET(CMAKE_CXX_FLAGS "-Wall ${KONOHA_CFLAGS}")
SET(CMAKE_C_FLAGS_RELEASE "-Wall -O2 -g")
SET(CMAKE_C_FLAGS_DEBUG "-O0 -g3")
SET(CMAKE_C_FLAGS_COMPRESSED "-Os -g0")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
SET(CMAKE_CXX_FLAGS_COMPRESSED "${CMAKE_C_FLAGS_COMPRESSED}")
if(${CMAKE_BUILD_TYPE} STREQUAL "Compressed")
set(K_NODEBUG 1)
endif()
set(RUNTIME
src/konoha/konoha2.c
)
set(KONOHA_GC_MODULE "" CACHE STRING "konoha gc module")
if(KONOHA_GC_MODULE)
set(GC module/${KONOHA_GC_MODULE}gc/${KONOHA_GC_MODULE}gc.c)
else(KONOHA_GC_MODULE)
set(GC src/gc/gc.c)
endif(KONOHA_GC_MODULE)
set(KONOHA_LOGGER_MODULE "" CACHE STRING "konoha logger module")
if(KONOHA_LOGGER_MODULE)
if("${KONOHA_LOGGER_MODULE}" MATCHES "logpool")
set(LOGGER_MODULE_LIBS logpool)
endif()
set(LOGGER module/${KONOHA_LOGGER_MODULE}/${KONOHA_LOGGER_MODULE}.c)
else(KONOHA_LOGGER_MODULE)
set(LOGGER src/logger/logger.c)
endif(KONOHA_LOGGER_MODULE)
set(PARSER
src/sugar/sugar.c
)
set(KONOHA_VM_MODULE "" CACHE STRING "konoha vm module")
if(KONOHA_VM_MODULE)
set(VM module/${KONOHA_VM_MODULE}vm/${KONOHA_VM_MODULE}asm.c)
else(KONOHA_VM_MODULE)
set(VM src/vm/asm.c)
endif(KONOHA_VM_MODULE)
set(PACKAGES
sugar
konoha
konoha.math
konoha.string
konoha.float
## konoha.int
llvm
konoha.pcre
konoha.hashmap
## konoha.io
konoha.while
konoha.class
konoha.assignment
konoha.i
## konoha.assert
posix.process
posix.file
posix.fd
konoha.socket
konoha.rope
## konoha.subproc
## konoha.mpi
konoha.bytes
## konoha.curl
## konoha.json
ijit
python
)
find_library(HAVE_LIBDL NAMES dl)
find_library(HAVE_LIBM NAMES m)
check_type_size("void *" SIZEOF_VOIDP)
check_type_size(long SIZEOF_LONG)
check_type_size(int SIZEOF_INT)
check_type_size(float SIZEOF_FLOAT)
check_type_size(double SIZEOF_DOUBLE)
check_include_files(dlfcn.h HAVE_DLFCN_H)
check_include_files(iconv.h HAVE_ICONV_H)
FIND_FILE(HAS_DOTGIT .git PATHS "${CMAKE_CURRENT_SOURCE_DIR}")
if("${HAS_DOTGIT}" MATCHES ".git")
find_package(Git)
if(GIT_EXECUTABLE)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse -q --short=8 HEAD
OUTPUT_VARIABLE GIT_SHA1
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(K_REVISION "0x${GIT_SHA1}")
set(K_REVISION_PREFIX "git:")
endif(GIT_EXECUTABLE)
else()
find_package(Subversion)
if(Subversion_FOUND)
set(_PATH)
get_filename_component(_PATH ${CMAKE_CURRENT_SOURCE_DIR} REALPATH)
Subversion_WC_INFO(${_PATH} ER)
set(K_REVISION ${ER_WC_REVISION})
set(K_REVISION_PREFIX "svn:")
endif(Subversion_FOUND)
endif()
add_definitions(-DHAVE_CONFIG_H)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake
${CMAKE_CURRENT_BINARY_DIR}/config.h)
set(ExtraLibs)
if(HAVE_LIBDL)
set(ExtraLibs ${ExtraLibs} ${HAVE_LIBDL})
endif(HAVE_LIBDL)
if(LOGGER_MODULE_LIBS)
set(ExtraLibs ${ExtraLibs} ${LOGGER_MODULE_LIBS})
endif(LOGGER_MODULE_LIBS)
macro(POP _STR _DELIM _RESULT)
string(REPLACE ${_DELIM} ";" _tmp ${_STR})
list(REVERSE _tmp)
list(GET _tmp 0 ${_RESULT})
endmacro()
# for jenkins coverage test
option(TEST_COVERAGE "Coverage Test" OFF)
if(TEST_COVERAGE)
include(CTest)
message(STATUS "TEST_COVERAGE = ${TEST_COVERAGE}")
add_definitions(-fprofile-arcs -ftest-coverage)
set(ExtraLibs ${ExtraLibs} -fprofile-arcs -ftest-coverage)
endif(TEST_COVERAGE)
# for .k script test
enable_testing()
set(TEST_BIN ${CMAKE_CURRENT_BINARY_DIR}/konoha)
set(PARENT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
file(GLOB_RECURSE test_files ${CMAKE_CURRENT_SOURCE_DIR}/test/*.k)
foreach(f ${test_files})
string(REPLACE // / f ${f})
string(REPLACE ${CMAKE_CURRENT_SOURCE_DIR}/test/ "" test_name ${f})
add_test(${test_name} ${TEST_BIN} --test-with ${f})
set_tests_properties(${test_name} PROPERTIES TIMEOUT 10)
endforeach(f ${test_files})
add_library(konoha2 SHARED ${RUNTIME} ${GC} ${LOGGER} ${PARSER} ${VM})
target_link_libraries(konoha2 ${ExtraLibs})
set(ExtraLibs ${ExtraLibs} konoha2)
add_executable(konoha2_bin src/tool/command.c)
target_link_libraries(konoha2_bin ${ExtraLibs})
set_target_properties(konoha2_bin PROPERTIES OUTPUT_NAME konoha)
# package
macro(PKGNAME _STR _RESULT)
set(_tmp)
POP(${_STR} "/" _tmp)
POP(${_tmp} "." ${_RESULT})
endmacro()
macro(create_package_project _PKGNAME)
project(${_PKGNAME})
if(TEST_COVERAGE)
add_definitions(-fprofile-arcs -ftest-coverage)
set(PACKAGE_EXTRA_LIBRARY ${PACKAGE_EXTRA_LIBRARY} -fprofile-arcs -ftest-coverage)
endif(TEST_COVERAGE)
file(GLOB_RECURSE test_files ${CMAKE_CURRENT_SOURCE_DIR}/test/*.k)
foreach(f ${test_files})
string(REPLACE // / f ${f})
string(REPLACE ${PARENT_SOURCE_DIR}/package/ "" test_name ${f})
string(REPLACE /test "" test_name ${test_name})
add_test(${test_name} ${TEST_BIN} --test-with ${f})
set_tests_properties(${test_name} PROPERTIES TIMEOUT 10)
if (PACKAGE_ENV)
set_tests_properties(${test_name} PROPERTIES ENVIRONMENT ${PACKAGE_ENV})
endif (PACKAGE_ENV)
endforeach(f ${test_files})
set(CMAKE_BUILD_TYPE ${KONOHA_BUILD_TYPE})
PKGNAME(${_PKGNAME} _PACKAGE_NAME)
set(LIB "${_PACKAGE_NAME}_glue")
set(_PACKAGE_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
set(_PACKAGE_STRING ${CMAKE_PROJECT_NAME}-${_PACKAGE_VERSION})
set(_KONOHA_PACKAGE_DIR konoha2/package/${KONOHA_VERSION}/${PROJECT_NAME})
set(CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}
"${CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${PACKAGE_C_FLAGS}")
set(CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}
"${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${PACKAGE_CXX_FLAGS}")
set(_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_BINARY_DIR}
${KONOHA_INCLUDE_DIRS}
${_PACKAGE_INCLUDE_DIR})
include_directories(${_INCLUDE_DIRS})
list(LENGTH PACKAGE_SOURCE_CODE LEN)
if(${LEN} GREATER 0)
add_library(${LIB} SHARED ${PACKAGE_SOURCE_CODE})
set_target_properties(${LIB} PROPERTIES PREFIX "")
target_link_libraries(${LIB} konoha2)
if(PACKAGE_EXTRA_LIBRARY)
target_link_libraries(${LIB} ${PACKAGE_EXTRA_LIBRARY})
endif(PACKAGE_EXTRA_LIBRARY)
install(TARGETS ${LIB} DESTINATION ${_KONOHA_PACKAGE_DIR})
endif(${LEN} GREATER 0)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PACKAGE_SCRIPT_CODE} DESTINATION ${_KONOHA_PACKAGE_DIR})
endmacro(create_package_project)
macro(add_konoha_package PKGNAME)
set(__BUILD true)
foreach(arg ${ARGN})
if (NOT ${arg})
set(__BUILD false)
endif (NOT ${arg})
endforeach(arg ${ARGN})
if (__BUILD)
create_package_project(${PKGNAME})
endif (__BUILD)
endmacro(add_konoha_package)
foreach(dir ${PACKAGES})
set(dir "${CMAKE_CURRENT_SOURCE_DIR}/package/${dir}")
if(IS_DIRECTORY ${dir} AND EXISTS ${dir}/CMakeLists.txt)
add_subdirectory(${dir})
endif()
endforeach()
#add_executable(test_konoha src/tool/test_konoha.c)
#target_link_libraries(test_konoha ${ExtraLibs})
#macro(add_konoha_test scr)
#set(TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/test/parser)
#set(TEST_BIN ${CMAKE_CURRENT_BINARY_DIR}/test_konoha)
#add_test(${scr} ${TEST_BIN} ${TEST_DIR}
# ${CMAKE_CURRENT_BINARY_DIR} ${scr})
#endmacro(add_konoha_test scr)
#file(GLOB test_files "${CMAKE_CURRENT_SOURCE_DIR}/test/parser/*.k")
#foreach(f ${test_files})
# set(_tmp)
# POP(${f} "/" _tmp)
# add_konoha_test(${_tmp})
#endforeach()
macro(add_clib_test test_name)
add_executable(${test_name} ${ARGN})
target_link_libraries(${test_name} ${ExtraLibs})
add_test(Clib/Release/${test_name} ${test_name})
endmacro(add_clib_test sources)
add_clib_test(test_sizeof ./test/src/test_sizeof.c)
add_clib_test(test_Kmalloc ./test/src/test_Kmalloc.c)
#add_clib_test(test_vm_add0 ./test/src/vm/test_add0.c)
#add_clib_test(test_vm_int ./test/src/vm/test_int.c)
add_clib_test(test_Karray ./test/src/test_Karray.c)
add_clib_test(test_gc ./test/src/test_gc.c)
add_clib_test(test_Kwb ./test/src/test_Kwb.c)
add_clib_test(test_map ./test/src/test_map.c)
add_clib_test(test_string ./test/src/test_string.c)
add_clib_test(test_cpp ./test/src/test_cpp.cpp)
macro(add_builtin_test test_name args)
add_test(Builtin/${test_name} ${TEST_BIN} ${args})
endmacro(add_builtin_test test_name args)
add_builtin_test(Release/Logger --builtin-test=test_logger)
add_builtin_test(Release/Kwb --builtin-test=test_kwb)
add_builtin_test(Release/Kvproto --builtin-test=test_kvproto)
install(TARGETS konoha2 konoha2_bin
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib${LIB_SUFFIX}
)
install(DIRECTORY include/ DESTINATION include
FILES_MATCHING
PATTERN "*.h"
PATTERN ".svn" EXCLUDE
)
MESSAGE(STATUS)
MESSAGE(STATUS "---------------------------------------------------------------------------" )
MESSAGE(STATUS "CMAKE_BUILD_TYPE = ${uppercase_CMAKE_BUILD_TYPE}")
MESSAGE(STATUS "CMAKE_C_COMPILER = ${CMAKE_C_COMPILER}")
MESSAGE(STATUS "CMAKE_CXX_COMPILER = ${CMAKE_CXX_COMPILER}")
MESSAGE(STATUS "CMAKE_C_FLAGS = ${CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}}")
MESSAGE(STATUS "CMAKE_CXX_FLAGS = ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}}")
MESSAGE(STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}")
MESSAGE(STATUS "Change a value with: cmake -D<Variable>=<Value>" )
MESSAGE(STATUS "---------------------------------------------------------------------------" )
MESSAGE(STATUS)