forked from limetext/lime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
274 lines (250 loc) · 9.77 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
cmake_minimum_required(VERSION 2.8)
include(FindGit)
include(ExternalProject)
if(WIN32)
set(EXESUFFIX ".exe")
set(PYTHON_PATH "C:\\Python3")
find_package(PythonInterp 3.3 QUIET)
if (NOT PYTHONINTERP_FOUND)
set(file python-3.3.2.msi)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(file python-3.3.2.amd64.msi)
endif()
if(NOT EXISTS ${PYTHON_PATH})
if(NOT EXISTS ${CMAKE_BINARY_DIR}/${file})
message("Downloading python ${file}")
file(DOWNLOAD http://python.org/ftp/python/3.3.2/${file} ${CMAKE_BINARY_DIR}/${file} SHOW_PROGRESS EXPECTED_MD5 0d9db9c2316562c62e1e4c347b6f9430)
endif()
find_program(MSIEXEC msiexec REQUIRED)
message("Installing python3 to ${PYTHON_PATH}")
execute_process(
COMMAND ${MSIEXEC} /i ${file} TARGETDIR=${PYTHON_PATH} /qb /log test.log
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
endif()
endif()
if(NOT EXISTS ${CMAKE_SOURCE_DIR}/3rdparty/libs/gopy/lib/cgo.go)
string(REPLACE "\\" "/" PYTHON_PATH ${PYTHON_PATH})
file(WRITE ${CMAKE_SOURCE_DIR}/3rdparty/libs/gopy/lib/cgo.go "package py
// #cgo CFLAGS: -I\"${PYTHON_PATH}/include\"
// #cgo LDFLAGS: -L\"${CMAKE_BINARY_DIR}\" -lpython33
import \"C\"
")
endif()
if(NOT EXISTS ${CMAKE_BINARY_DIR}/mingw-get.zip)
file(DOWNLOAD http://sourceforge.net/projects/mingw/files/Installer/mingw-get/mingw-get-0.6.2-beta-20131004-1/mingw-get-0.6.2-mingw32-beta-20131004-1-bin.zip/download ${CMAKE_BINARY_DIR}/mingw-get.zip SHOW_PROGRESS EXPECTED_MD5 971778e9330ae006aaeb2d63344be5f3)
endif()
if(NOT EXISTS ${CMAKE_BINARY_DIR}/dist/bin/mingw-get.exe)
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/dist)
execute_process(COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_BINARY_DIR}/dist ${CMAKE_COMMAND} -E tar xvfz ${CMAKE_BINARY_DIR}/mingw-get.zip)
endif()
if(NOT EXISTS ${CMAKE_BINARY_DIR}/dist/bin/gcc.exe)
execute_process(
COMMAND ${CMAKE_BINARY_DIR}/dist/bin/mingw-get.exe install gcc g++ mingw32-pexports
WORKING_DIR ${CMAKE_BINARY_DIR}/dist
)
endif()
set(SHELL_EXE ${CMAKE_BINARY_DIR}/dist/msys/1.0/bin/sh.exe)
if(NOT EXISTS ${SHELL_EXE})
execute_process(
COMMAND ${CMAKE_BINARY_DIR}/dist/bin/mingw-get.exe install sh msys-sed msys-grep msys-awk msys-make
WORKING_DIR ${CMAKE_BINARY_DIR}/dist
)
endif()
set(SHELL ${CMAKE_BINARY_DIR}/sh.bat)
file(WRITE ${SHELL} "set PATH=%PATH%;${CMAKE_BINARY_DIR}/dist/bin;${CMAKE_BINARY_DIR}/dist/msys/1.0/bin;/bin;/sbin;/usr/bin;/usr/sbin
${SHELL_EXE} %*
")
if(NOT EXISTS ${CMAKE_BINARY_DIR}/libpython33.a)
execute_process(COMMAND ${CMAKE_BINARY_DIR}/dist/bin/pexports ${PYTHON_PATH}/python33.dll OUTPUT_VARIABLE PY3_DATA)
file(WRITE ${CMAKE_BINARY_DIR}/py33.def ${PY3_DATA})
execute_process(COMMAND ${CMAKE_BINARY_DIR}/dist/bin/dlltool -D python33.dll -l ${CMAKE_BINARY_DIR}/libpython33.a -d ${CMAKE_BINARY_DIR}/py33.def)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${PYTHON_PATH}/python33.dll ${CMAKE_BINARY_DIR}/python33.dll)
endif()
ExternalProject_Add(
Oniguruma
URL http://www.geocities.jp/kosako3/oniguruma/archive/onig-5.9.5.tar.gz
URL_MD5 970f98a4cd10021b545d84e34c34aae4
CONFIGURE_COMMAND ${SHELL} <SOURCE_DIR>/configure --prefix=${CMAKE_BINARY_DIR}/dist
BUILD_COMMAND ${SHELL} -c "make"
INSTALL_COMMAND ${SHELL} -c "make install"
BUILD_IN_SOURCE 1
)
else()
ExternalProject_Add(
Python3
URL http://python.org/ftp/python/3.3.2/Python-3.3.2.tar.bz2
URL_MD5 7dffe775f3bea68a44f762a3490e5e28
CONFIGURE_COMMAND ./configure --prefix=${CMAKE_BINARY_DIR}/dist
# C code messing with sig calls and Go don't mix very well.
# See https://code.google.com/p/go/issues/detail?id=5287 for details
COMMAND cat pyconfig.h | sed s/\#define\ HAVE_SIGALTSTACK\ 1// > pyconfig.new && mv pyconfig.new pyconfig.h
BUILD_COMMAND make -j8
BUILD_IN_SOURCE 1
)
if(NOT EXISTS ${CMAKE_BINARY_DIR}/gopy_cgo.cmake)
file(WRITE ${CMAKE_BINARY_DIR}/gopy_cgo.cmake "
cmake_minimum_required(VERSION 2.8)
execute_process(COMMAND ${CMAKE_BINARY_DIR}/dist/bin/python3-config --cflags OUTPUT_VARIABLE PY_CFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${CMAKE_BINARY_DIR}/dist/bin/python3-config --ldflags OUTPUT_VARIABLE PY_LDFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${CMAKE_BINARY_DIR}/dist/bin/python3-config --libs OUTPUT_VARIABLE PY_LIBS OUTPUT_STRIP_TRAILING_WHITESPACE)
file(WRITE ${CMAKE_SOURCE_DIR}/3rdparty/libs/gopy/lib/cgo.go \"package py
// #cgo CFLAGS: \${PY_CFLAGS}
// #cgo LDFLAGS: \${PY_LDFLAGS} \${PY_LIBS}
import \\\"C\\\"
\")
")
endif()
add_custom_command(
OUTPUT ${CMAKE_SOURCE_DIR}/3rdparty/libs/gopy/lib/cgo.go
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}/gopy_cgo.cmake
DEPENDS Python3
DEPENDS ${CMAKE_BINARY_DIR}/gopy_cgo.cmake
)
ExternalProject_Add(
Oniguruma
URL http://www.geocities.jp/kosako3/oniguruma/archive/onig-5.9.5.tar.gz
URL_MD5 970f98a4cd10021b545d84e34c34aae4
CONFIGURE_COMMAND <SOURCE_DIR>/configure --prefix=${CMAKE_BINARY_DIR}/dist
)
endif()
if(NOT EXISTS ${CMAKE_SOURCE_DIR}/3rdparty/libs/rubex/cgo.go)
file(WRITE ${CMAKE_SOURCE_DIR}/3rdparty/libs/rubex/cgo.go "
package rubex
// #cgo CFLAGS: -I${CMAKE_BINARY_DIR}/dist/include
// #cgo LDFLAGS: ${CMAKE_BINARY_DIR}/dist/lib/libonig.a
import \"C\"
")
endif()
execute_process(
COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
find_program(GOEXE go)
if(NOT GOEXE)
set(GOARCH "386")
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(GOARCH "amd64")
endif()
string(TOLOWER ${CMAKE_SYSTEM_NAME} GOOS)
set(EXTENSION "tar.gz")
if(GOOS STREQUAL "windows")
set(EXTENSION "zip")
endif()
ExternalProject_Add(
Go
URL https://go.googlecode.com/files/go1.1.2.${GOOS}-${GOARCH}.${EXTENSION}
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
)
set(GOPATH ${CMAKE_SOURCE_DIR}/../..)
set(GOROOT ${CMAKE_BINARY_DIR}/Go-prefix/src/Go)
set(ENV{GOPATH} ${GOPATH})
set(ENV{GOROOT} ${GOROOT})
set(GOEXE ${CMAKE_BINARY_DIR}/Go-prefix/src/Go/bin/go${EXESUFFIX})
add_custom_command(OUTPUT ${GOEXE}
DEPENDS Go
)
endif()
if(EXISTS ${GOEXE})
foreach(var GOPATH GOROOT GOARCH GOOS)
execute_process(COMMAND ${GOEXE} env ${var} OUTPUT_VARIABLE ${var} OUTPUT_STRIP_TRAILING_WHITESPACE)
message("${var}: " ${${var}})
endforeach(var)
endif()
if(WIN32)
file(WRITE "${CMAKE_BINARY_DIR}/go.bat" "
set GOROOT=${GOROOT}
set GOPATH=${GOPATH}
set PATH=%PATH%;${CMAKE_BINARY_DIR}/dist/bin;${GOROOT}/bin;${CMAKE_BINARY_DIR}
${GOEXE} %*
")
set(GOCMD ${CMAKE_BINARY_DIR}/go.bat)
if(GOPATH)
string(REGEX REPLACE ";.*" "" GOPATH ${GOPATH})
endif()
else()
set(GOCMD PATH=$ENV{PATH}:${CMAKE_BINARY_DIR}/Go-prefix/src/Go/bin LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH}:${CMAKE_BINARY_DIR}/dist/lib GOROOT=${GOROOT} GOPATH=${GOPATH} ${GOEXE})
if(GOPATH)
string(REGEX REPLACE ":.*" "" GOPATH ${GOPATH})
endif()
endif()
set(GOPKG ${GOPATH}/pkg/${GOOS}_${GOARCH})
foreach(pkg code.google.com/p/log4go github.com/quarnster/parser github.com/quarnster/util/text)
add_custom_command(OUTPUT ${GOPKG}/${pkg}.a
COMMAND ${GOCMD} get ${pkg}
DEPENDS ${GOEXE} ${GODEPS}
)
endforeach()
add_custom_command(OUTPUT ${GOPATH}/bin/pegparser${EXESUFFIX}
COMMAND ${GOCMD} install github.com/quarnster/parser/pegparser
DEPENDS ${GOEXE}
DEPENDS ${GOPKG}/github.com/quarnster/parser.a
)
add_custom_command(OUTPUT ${GOPKG}/lime/3rdparty/libs/gopy/lib.a
COMMAND ${GOCMD} install lime/3rdparty/libs/gopy/lib
DEPENDS ${CMAKE_SOURCE_DIR}/3rdparty/libs/gopy/lib/cgo.go
)
macro(add_peg peg ignore testfile)
string(REPLACE ".peg" ".go" GOFILE ${peg})
get_filename_component(dir ${GOFILE} PATH)
add_custom_command(OUTPUT ${GOFILE}
COMMAND ${GOPATH}/bin/pegparser -peg=${peg} -outpath=${dir} -notest -ignore=${ignore} -testfile=${testfile}
DEPENDS ${GOPATH}/bin/pegparser${EXESUFFIX}
DEPENDS ${peg}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
VERBATIM
)
set(PEGDEPENDS ${PEGDEPENDS} ${GOFILE})
endmacro(add_peg)
add_peg(${CMAKE_SOURCE_DIR}/backend/loaders/json/json.peg "JsonFile,Values,Value,Null,Dictionary,Array,KeyValuePairs,KeyValuePair,QuotedText,Text,Integer,Float,Boolean,Spacing,Comment" "testdata/Default (OSX).sublime-keymap")
add_peg(${CMAKE_SOURCE_DIR}/backend/loaders/plist/plist.peg "Spacing,KeyValuePair,KeyTag,StringTag,Value,Values,PlistFile,Plist" "testdata/C.plist")
add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/backend/sublime/region.go
COMMAND ${GOCMD} run ${CMAKE_SOURCE_DIR}/tasks/build/gen_python_api.go
DEPENDS ${PEGDEPENDS}
DEPENDS ${CMAKE_SOURCE_DIR}/tasks/build/gen_python_api.go
DEPENDS ${CMAKE_SOURCE_DIR}/backend/command.go
DEPENDS ${CMAKE_SOURCE_DIR}/backend/commandhandler.go
DEPENDS ${CMAKE_SOURCE_DIR}/backend/editor.go
DEPENDS ${CMAKE_SOURCE_DIR}/backend/events.go
DEPENDS ${CMAKE_SOURCE_DIR}/backend/key.go
DEPENDS ${CMAKE_SOURCE_DIR}/backend/packages.go
DEPENDS ${CMAKE_SOURCE_DIR}/backend/view.go
DEPENDS ${CMAKE_SOURCE_DIR}/backend/window.go
)
add_custom_target(fix
COMMAND ${GOCMD} run ${CMAKE_SOURCE_DIR}/tasks/build/fix.go
DEPENDS ${PEGDEPENDS}
)
add_custom_target(lime
DEPENDS ${CMAKE_SOURCE_DIR}/backend/sublime/region.go
DEPENDS ${GOPATH}/pkg/${GOOS}_${GOARCH}/lime/3rdparty/libs/gopy/lib.a
DEPENDS Oniguruma
DEPENDS fix
)
add_custom_target(termbox ALL
COMMAND ${GOCMD} build
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/frontend/termbox
DEPENDS lime
)
add_custom_target(html ALL
COMMAND ${GOCMD} build
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/frontend/html
DEPENDS lime
)
file(GLOB_RECURSE TESTS ${CMAKE_SOURCE_DIR} "*_test.go")
foreach(testfile ${TESTS})
if(${testfile} MATCHES ".*._test.go")
if(NOT ${testfile} MATCHES "bundles|tasks")
get_filename_component(dir ${testfile} PATH)
string(REPLACE ${CMAKE_SOURCE_DIR} "lime" dir ${dir})
set(GO_TESTS ${GO_TESTS} ${dir})
endif()
endif()
endforeach(testfile)
add_custom_target(test
COMMAND ${GOCMD} test -i ${GO_TESTS}
COMMAND ${GOCMD} test -v ${GO_TESTS}
DEPENDS lime
)