-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
210 lines (180 loc) · 6.68 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
project(swig)
cmake_minimum_required(VERSION 2.8)
include(ExternalProject)
# TODO: you need to clone the swig repository manually
# TODO: this should be extracted from the SWIG repos
set(SWIG_VERSION 3.0.0)
if (NOT SWIG_ROOT)
set(SWIG_ROOT ${PROJECT_SOURCE_DIR}/swig)
endif()
# Project wide configuration variables
# ------------------------------------
set(SWIG_SOURCE_DIR "${SWIG_ROOT}/Source" CACHE INTERNAL "Path of swig sources" FORCE)
# Options
# -------
# Configure
# ---------
LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/lib)
include(CheckIncludeFiles)
include(CheckIncludeFile)
include(CheckTypeSize)
include(CheckSymbolExists)
include(CheckLibraryExists)
include(CheckCSourceCompiles)
# HACK: didn't get the bool check working for Visual Studio 2008
if(MSVC)
set(HAVE_BOOL 1)
else()
set(CMAKE_EXTRA_INCLUDE_FILES stdbool.h)
check_type_size("bool" HAVE_BOOL)
set(CMAKE_EXTRA_INCLUDE_FILES)
endif()
check_include_file("inttypes.h" HAVE_INTTYPES_H)
check_include_file("memory.h" HAVE_MEMORY_H)
check_include_file("stddef.h" HAVE_STDDEF_H)
check_include_file("stdint.h" HAVE_STDINT_H)
check_include_file("stdlib.h" HAVE_STDLIB_H)
check_include_file("string.h" HAVE_STRING_H)
check_include_file("strings.h" HAVE_STRINGS_H)
check_include_file("sys/stat.h" HAVE_SYS_STAT_H)
check_include_file("sys/types.h" HAVE_SYS_TYPES_H)
check_include_file("unistd.h" HAVE_UNISTD_H)
check_include_files( "stdlib.h;stdarg.h;string.h;float.h" HAVE_STDC_HEADERS )
check_library_exists(dl dlopen "" HAVE_LIBDL)
configure_file(
${SWIG_ROOT}/Tools/swigconfig.h.cmake
${CMAKE_CURRENT_BINARY_DIR}/Source/Include/swigconfig.h
)
# PCRE
#if (NOT WIN32)
find_package(PCRE)
#endif()
# Compiler flags
# --------------
include_directories(
"${SWIG_SOURCE_DIR}/CParse"
"${SWIG_SOURCE_DIR}/Include"
"${SWIG_SOURCE_DIR}/DOH"
"${SWIG_SOURCE_DIR}/Swig"
"${SWIG_SOURCE_DIR}/Preprocessor"
"${SWIG_SOURCE_DIR}/Modules"
"${PROJECT_BINARY_DIR}/Source/Include"
)
if (PCRE)
include_directories(
"${PCRE_INCLUDE_DIRS}"
)
endif()
# Pre-Build
# ---------
# Copy Lib directory into the build dist folder
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/Dist)
file(COPY ${SWIG_ROOT}/Lib DESTINATION ${PROJECT_BINARY_DIR}/Dist)
# add the command to generate the source code (depends on bison)
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/Source/CParse)
add_custom_command (
OUTPUT ${PROJECT_BINARY_DIR}/Source/CParse/parser.c
DEPENDS ${SWIG_SOURCE_DIR}/CParse/parser.y
COMMAND bison -o ${PROJECT_BINARY_DIR}/Source/CParse/parser.c --defines=${PROJECT_BINARY_DIR}/Source/Include/parser.h ${SWIG_SOURCE_DIR}/CParse/parser.y
)
set_property(SOURCE ${PROJECT_BINARY_DIR}/Source/CParse/parser.c PROPERTY GENERATED 1)
set_property(SOURCE ${PROJECT_BINARY_DIR}/Source/CParse/parser.h PROPERTY GENERATED 1)
# generate swigwarn.swg
file(READ ${SWIG_SOURCE_DIR}/Include/swigwarn.h SWIG_WARN_H)
string(REGEX REPLACE "#define WARN([^ \\t]*)[ \\t]*([0-9]+)" "%define SWIGWARN\\1 \\2 %enddef" SWIG_WARN_SWG ${SWIG_WARN_H})
file(WRITE ${PROJECT_BINARY_DIR}/Dist/Lib/swigwarn.swg ${SWIG_WARN_SWG})
set_property(SOURCE ${PROJECT_BINARY_DIR}/Dist/Lib/swigwarn.swg PROPERTY GENERATED 1)
# Libraries
# ---------
add_library(cparse
"${SWIG_SOURCE_DIR}/CParse/cscanner.c"
"${SWIG_SOURCE_DIR}/CParse/templ.c"
"${SWIG_SOURCE_DIR}/CParse/util.c"
"${PROJECT_BINARY_DIR}/Source/CParse/parser.c"
"${PROJECT_BINARY_DIR}/Source/CParse/parser.h"
)
add_library(preprocessor
"${SWIG_SOURCE_DIR}/Preprocessor/cpp.c"
"${SWIG_SOURCE_DIR}/Preprocessor/expr.c"
)
add_library(doh
"${SWIG_SOURCE_DIR}/DOH/base.c"
"${SWIG_SOURCE_DIR}/DOH/file.c"
"${SWIG_SOURCE_DIR}/DOH/fio.c"
"${SWIG_SOURCE_DIR}/DOH/hash.c"
"${SWIG_SOURCE_DIR}/DOH/list.c"
"${SWIG_SOURCE_DIR}/DOH/memory.c"
"${SWIG_SOURCE_DIR}/DOH/string.c"
"${SWIG_SOURCE_DIR}/DOH/void.c"
)
add_library(core
"${SWIG_SOURCE_DIR}/Swig/cwrap.c"
"${SWIG_SOURCE_DIR}/Swig/deprecate.c"
"${SWIG_SOURCE_DIR}/Swig/error.c"
"${SWIG_SOURCE_DIR}/Swig/fragment.c"
"${SWIG_SOURCE_DIR}/Swig/getopt.c"
"${SWIG_SOURCE_DIR}/Swig/include.c"
"${SWIG_SOURCE_DIR}/Swig/misc.c"
"${SWIG_SOURCE_DIR}/Swig/naming.c"
"${SWIG_SOURCE_DIR}/Swig/parms.c"
"${SWIG_SOURCE_DIR}/Swig/scanner.c"
"${SWIG_SOURCE_DIR}/Swig/stype.c"
"${SWIG_SOURCE_DIR}/Swig/symbol.c"
"${SWIG_SOURCE_DIR}/Swig/tree.c"
"${SWIG_SOURCE_DIR}/Swig/typemap.c"
"${SWIG_SOURCE_DIR}/Swig/typeobj.c"
"${SWIG_SOURCE_DIR}/Swig/typesys.c"
"${SWIG_SOURCE_DIR}/Swig/wrapfunc.c"
)
add_library(modules
"${SWIG_SOURCE_DIR}/Modules/allegrocl.cxx"
"${SWIG_SOURCE_DIR}/Modules/allocate.cxx"
"${SWIG_SOURCE_DIR}/Modules/browser.cxx"
"${SWIG_SOURCE_DIR}/Modules/cffi.cxx"
"${SWIG_SOURCE_DIR}/Modules/chicken.cxx"
"${SWIG_SOURCE_DIR}/Modules/clisp.cxx"
"${SWIG_SOURCE_DIR}/Modules/contract.cxx"
"${SWIG_SOURCE_DIR}/Modules/csharp.cxx"
"${SWIG_SOURCE_DIR}/Modules/d.cxx"
"${SWIG_SOURCE_DIR}/Modules/directors.cxx"
"${SWIG_SOURCE_DIR}/Modules/emit.cxx"
"${SWIG_SOURCE_DIR}/Modules/go.cxx"
"${SWIG_SOURCE_DIR}/Modules/guile.cxx"
"${SWIG_SOURCE_DIR}/Modules/java.cxx"
"${SWIG_SOURCE_DIR}/Modules/javascript.cxx"
"${SWIG_SOURCE_DIR}/Modules/lang.cxx"
"${SWIG_SOURCE_DIR}/Modules/lua.cxx"
"${SWIG_SOURCE_DIR}/Modules/modula3.cxx"
"${SWIG_SOURCE_DIR}/Modules/module.cxx"
"${SWIG_SOURCE_DIR}/Modules/mzscheme.cxx"
"${SWIG_SOURCE_DIR}/Modules/ocaml.cxx"
"${SWIG_SOURCE_DIR}/Modules/octave.cxx"
"${SWIG_SOURCE_DIR}/Modules/overload.cxx"
"${SWIG_SOURCE_DIR}/Modules/perl5.cxx"
"${SWIG_SOURCE_DIR}/Modules/php.cxx"
"${SWIG_SOURCE_DIR}/Modules/pike.cxx"
"${SWIG_SOURCE_DIR}/Modules/python.cxx"
"${SWIG_SOURCE_DIR}/Modules/r.cxx"
"${SWIG_SOURCE_DIR}/Modules/ruby.cxx"
"${SWIG_SOURCE_DIR}/Modules/s-exp.cxx"
"${SWIG_SOURCE_DIR}/Modules/tcl8.cxx"
"${SWIG_SOURCE_DIR}/Modules/typepass.cxx"
"${SWIG_SOURCE_DIR}/Modules/uffi.cxx"
"${SWIG_SOURCE_DIR}/Modules/utils.cxx"
"${SWIG_SOURCE_DIR}/Modules/xml.cxx"
"${PROJECT_BINARY_DIR}/Source/Include/swigconfig.h"
"${SWIG_SOURCE_DIR}/Include/swigwarn.h"
)
add_executable(swig
"${SWIG_SOURCE_DIR}/Modules/main.cxx"
"${SWIG_SOURCE_DIR}/Modules/swigmain.cxx"
)
target_link_libraries(swig cparse preprocessor doh core modules ${PCRE_LIBRARIES})
# copy binary into Dist folder
get_property(_SWIG_EXECUTABLE TARGET swig PROPERTY LOCATION)
get_filename_component(_SWIG_EXE_NAME ${_SWIG_EXECUTABLE} NAME)
set(_SWIG_EXE_DIST ${PROJECT_BINARY_DIR}/Dist/${_SWIG_EXE_NAME})
add_custom_command(TARGET swig POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${_SWIG_EXECUTABLE} ${_SWIG_EXE_DIST}
)
set(SWIG_EXECUTABLE ${_SWIG_EXE_DIST} CACHE INTERNAL "swig executable")