-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCMakeLists.txt
263 lines (207 loc) · 10.2 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
cmake_minimum_required(VERSION 2.8)
IF(DEFINED CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "Choose the type of build, options are: None Debug Release.")
ELSE()
SET(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build, options are: None Debug Release.")
ENDIF()
project(seec)
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
message(FATAL_ERROR "In-source builds are not allowed.")
endif()
#--------------------------------------------------------------------------------
# Cached variables.
#--------------------------------------------------------------------------------
set(BUNDLE_PREFIX "/Applications" CACHE PATH "Where to install application bundles (Mac OS X).")
set(MAN_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/share/man/" CACHE PATH "Where to install man pages.")
set(LLVM_INSTALL_OVERRIDE "" CACHE PATH "Override LLVM install location.")
set(ICU_INSTALL "/usr/local" CACHE PATH "Root of ICU install.")
set(WX_INSTALL "/usr/local" CACHE PATH "Root of wxWidgets install.")
set(WX_TOOLCHAIN "" CACHE STRING "Build of wxWidgets to use.")
set(MULTIARCH "" CACHE STRING "Architecture to build for multiarch systems.")
option(SEEC_USER_ACTION_RECORDING "Support user action recording." OFF)
# find MULTIARCH automatically if we can.
if(MULTIARCH STREQUAL "")
if(EXISTS /usr/bin/dpkg-architecture)
execute_process(COMMAND /usr/bin/dpkg-architecture -qDEB_HOST_MULTIARCH
OUTPUT_VARIABLE THE_MULTIARCH)
string(STRIP ${THE_MULTIARCH} MULTIARCH)
endif(EXISTS /usr/bin/dpkg-architecture)
endif(MULTIARCH STREQUAL "")
#--------------------------------------------------------------------------------
# find LLVM
#--------------------------------------------------------------------------------
set(Clang_DIR "${LLVM_DIR}/../clang")
find_package(LLVM REQUIRED CONFIG)
find_package(Clang REQUIRED)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
set(LLVM_INSTALL "${LLVM_DIR}/../../../")
if(NOT "${LLVM_INSTALL_OVERRIDE}" STREQUAL "")
message(STATUS "Using LLVM_INSTALL_OVERRIDE ${LLVM_INSTALL_OVERRIDE}")
set(LLVM_INSTALL "${LLVM_INSTALL_OVERRIDE}")
endif()
include_directories(BEFORE "${LLVM_INSTALL}/include")
message(STATUS "LLVM include ${LLVM_INSTALL}/include")
add_definitions(${LLVM_DEFINITIONS})
# Copy Clang resources into our resources build directory:
file(COPY ${LLVM_INSTALL}/lib/clang DESTINATION ${CMAKE_BINARY_DIR}/resources/)
INSTALL(DIRECTORY ${CMAKE_BINARY_DIR}/resources/clang DESTINATION lib/seec/resources)
#--------------------------------------------------------------------------------
# find ICU
#--------------------------------------------------------------------------------
if( NOT EXISTS ${ICU_INSTALL}/include/${MULTIARCH}/unicode/unistr.h )
if ( NOT EXISTS ${ICU_INSTALL}/include/unicode/unistr.h )
message(FATAL_ERROR "ICU_INSTALL (${ICU_INSTALL}) is not a valid ICU installation.")
else()
message("Using ICU at ${ICU_INSTALL}")
include_directories(${ICU_INSTALL}/include )
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${ICU_INSTALL}/lib")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -L${ICU_INSTALL}/lib")
endif()
else()
message("Using ICU at ${ICU_INSTALL} for architecture ${MULTIARCH}")
include_directories(${ICU_INSTALL}/include/${MULTIARCH} )
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${ICU_INSTALL}/lib/${MULTIARCH}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -L${ICU_INSTALL}/lib/${MULTIARCH}")
endif()
if(EXISTS ${ICU_INSTALL}/bin64)
set(ICU_GENRB "${ICU_INSTALL}/bin64/genrb")
set(ICU_ICUPKG "${ICU_INSTALL}/bin64/icupkg")
else()
set(ICU_GENRB "${ICU_INSTALL}/bin/genrb")
set(ICU_ICUPKG "${ICU_INSTALL}/sbin/icupkg")
endif(EXISTS ${ICU_INSTALL}/bin64)
#--------------------------------------------------------------------------------
# find wxWidgets
#--------------------------------------------------------------------------------
if( (NOT "${WX_TOOLCHAIN}" STREQUAL "") AND (EXISTS ${WX_INSTALL}/lib/wx/config/${WX_TOOLCHAIN}) )
set(WX_CONFIG_BIN "${WX_INSTALL}/lib/wx/config/${WX_TOOLCHAIN}")
else()
if( EXISTS ${WX_INSTALL}/bin/wx-config )
set(WX_CONFIG_BIN "${WX_INSTALL}/bin/wx-config")
endif()
endif()
if( NOT EXISTS ${WX_CONFIG_BIN} )
message(FATAL_ERROR "WX_INSTALL (${WX_INSTALL}) is not a valid wxWidgets installation.")
endif()
message("using WX_CONFIG_BIN at ${WX_CONFIG_BIN}")
EXEC_PROGRAM(sh
ARGS "${WX_CONFIG_BIN} --prefix=${WX_INSTALL} --cflags"
OUTPUT_VARIABLE WX_C_FLAGS
)
string(STRIP ${WX_C_FLAGS} WX_C_FLAGS)
EXEC_PROGRAM(sh
ARGS "${WX_CONFIG_BIN} --prefix=${WX_INSTALL} --cxxflags"
OUTPUT_VARIABLE WX_CXX_FLAGS
)
string(STRIP ${WX_CXX_FLAGS} WX_CXX_FLAGS)
#--------------------------------------------------------------------------------
# setup compiler options
#--------------------------------------------------------------------------------
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
if (SEEC_USER_ACTION_RECORDING)
add_definitions(-DSEEC_USER_ACTION_RECORDING)
endif (SEEC_USER_ACTION_RECORDING)
add_definitions(-DWXINTL_NO_GETTEXT_MACRO)
# needed when compiling with mingw-w64 under msys2
set(SEEC_CXX_STD "-std=c++11")
if (WIN32)
set(SEEC_CXX_STD "-std=gnu++11")
endif (WIN32)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LLVM_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LLVM_CXX_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-strict-aliasing -std=c99")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-strict-aliasing ${SEEC_CXX_STD} -fvisibility-inlines-hidden")
if (NOT ${LLVM_ENABLE_RTTI})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
endif (NOT ${LLVM_ENABLE_RTTI})
if (NOT ${LLVM_ENABLE_EH})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")
endif (NOT ${LLVM_ENABLE_EH})
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -stdlib=libc++")
endif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -g")
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g -O0")
set (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -O3")
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3")
#--------------------------------------------------------------------------------
# Set build variables
#--------------------------------------------------------------------------------
set_property(GLOBAL PROPERTY SEEC_RESOURCE_FILES "")
#--------------------------------------------------------------------------------
# macro for generating ICU resources
# adapted from: http://www.cmake.org/pipermail/cmake/2009-March/027433.html
# note that, for icupkg to work correctly, resources must be specified BEFORE
# any other resource that they depend upon. e.g. en_AU en root.
#--------------------------------------------------------------------------------
macro(icu_resources package)
# build directory for this package's resources
set(${package}_res_dir ${CMAKE_BINARY_DIR}/resources/${package})
# destination package (.dat file)
set(${package}_icu_dat ${${package}_res_dir}/${package}.dat)
set(${package}_icu_commands "")
set(${package}_icu_depends "")
set(${package}_icu_byproducts "")
# build individual resources using genrb
foreach(resource ${ARGN})
# destination resource (.res file)
set(${package}_icu_${resource}_res ${${package}_res_dir}/${resource}.res)
set(${package}_icu_commands ${${package}_icu_commands}
COMMAND ${ICU_GENRB}
ARGS -e UTF-8 -d ${${package}_res_dir} -s ${CMAKE_SOURCE_DIR}/resources/${package} ${resource}.txt
COMMAND ${ICU_ICUPKG}
ARGS -d ${${package}_res_dir} -a ${resource}.res ${package}.dat ${package}.dat)
set(${package}_icu_depends ${${package}_icu_depends} ${CMAKE_SOURCE_DIR}/resources/${package}/${resource}.txt)
set(${package}_icu_byproducts ${${package}_icu_byproducts} ${package}_icu_${resource}_res)
endforeach(resource)
# create empty package if necessary
add_custom_command(OUTPUT ${${package}_icu_dat}
COMMAND ${ICU_ICUPKG}
ARGS -d ${${package}_res_dir} new ${package}.dat
${${package}_icu_commands}
DEPENDS
${${package}_icu_depends}
BYPRODUCTS
${${package}_icu_byproducts}
COMMENT "Create ICU resources package ${package}.dat"
)
# custom target to require packaging each resource (depends on stamp files)
add_custom_target(icu_resources_${package} ALL DEPENDS ${${package}_icu_dat})
# add the package (.dat file) to the list of resource files.
set_property(GLOBAL APPEND PROPERTY SEEC_RESOURCE_FILES "${${package}_icu_dat}")
# install the package (.dat file)
INSTALL(FILES ${${package}_icu_dat} DESTINATION lib/seec/resources)
endmacro(icu_resources)
#--------------------------------------------------------------------------------
# Setup the build for the various SeeC components
#--------------------------------------------------------------------------------
include_directories( BEFORE ${PROJECT_SOURCE_DIR}/include )
include_directories( ${PROJECT_SOURCE_DIR}/external/type_safe/include )
include_directories( ${PROJECT_SOURCE_DIR}/external/type_safe/external/debug_assert )
if (CMAKE_BUILD_TYPE MATCHES Debug)
message(STATUS "Build: Debug")
message(STATUS "C flags: ${CMAKE_C_FLAGS_DEBUG}")
message(STATUS "C++ flags: ${CMAKE_CXX_FLAGS_DEBUG}")
elseif (CMAKE_BUILD_TYPE MATCHES Release)
message(STATUS "Build: Release")
message(STATUS "C flags: ${CMAKE_C_FLAGS_RELEASE}")
message(STATUS "C++ flags: ${CMAKE_CXX_FLAGS_RELEASE}")
else ()
message(STATUS "Build: Default")
message(STATUS "C flags: ${CMAKE_C_FLAGS}")
message(STATUS "C++ flags: ${CMAKE_CXX_FLAGS}")
endif ()
message(STATUS "LD flags (bin): ${CMAKE_EXE_LINKER_FLAGS}")
message(STATUS "LD flags (so): ${CMAKE_SHARED_LINKER_FLAGS}")
message(STATUS "Will build SeeC resources.")
add_subdirectory(resources)
message(STATUS "Will build SeeC libraries.")
add_subdirectory(lib)
option(SEEC_BUILD_TOOLS "Build the SeeC tools." ON)
if(SEEC_BUILD_TOOLS)
message(STATUS "Will build SeeC tools.")
add_subdirectory(tools)
endif(SEEC_BUILD_TOOLS)