blob: 224d729197d29ad75fa279a98dedeca826e9b9cd (
plain)
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
|
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
# build type has to be set before the project definition
SET(BUILD_TYPE_HELP "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug, Release, RelWithDebInfo, MinSizeRel.")
IF(DEFINED CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING ${BUILD_TYPE_HELP})
ELSE()
SET(CMAKE_BUILD_TYPE Release CACHE STRING ${BUILD_TYPE_HELP})
ENDIF()
PROJECT(uscxml)
#################################################
# General Setup
#################################################
# specify USCXML version
SET(USCXML_VERSION_MAJOR "2")
SET(USCXML_VERSION_MINOR "0")
SET(USCXML_VERSION_PATCH "0")
SET(USCXML_VERSION ${USCXML_VERSION_MAJOR}.${USCXML_VERSION_MINOR}.${USCXML_VERSION_PATCH})
# where do libraries and binaries go
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
# where to find more cmake scripts
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/contrib/cmake)
include("${CMAKE_MODULE_PATH}/USCXMLMacros.cmake")
# setup header include paths
include_directories(src)
include_directories(contrib/src)
include_directories(${CMAKE_BINARY_DIR})
include_directories(${PROJECT_SOURCE_DIR}/contrib/src/jsmn)
include_directories(${PROJECT_SOURCE_DIR}/contrib/src/evws)
if (WIN32)
include_directories(${PROJECT_SOURCE_DIR}/contrib/src/getopt)
include_directories(${PROJECT_SOURCE_DIR}/contrib/src/inttypes)
endif()
# various options
# OPTION(BUILD_MINIMAL "Build only features mandated by specification" OFF)
OPTION(BUILD_DM_ECMA "Build with ECMAScript datamodel" ON)
# OPTION(BUILD_DM_XPATH "Build with XPath datamodel" OFF)
# OPTION(BUILD_DM_PROLOG "Build with Prolog datamodel" OFF)
# OPTION(BUILD_DM_PROMELA "Build with Promela datamodel" OFF)
# OPTION(BUILD_DM_LUA "Build with Lua datamodel" OFF)
################################
# Compiler Features and Flags
# Check for C++11 support
# message("Your C++ compiler supports these C++ features:")
# foreach(i ${CMAKE_CXX_COMPILE_FEATURES})
# message("${i}")
# endforeach()
# http://stackoverflow.com/a/25836953/990120
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11_FLAG)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X_FLAG)
if(COMPILER_SUPPORTS_CXX11_FLAG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X_FLAG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
endif()
if(${CMAKE_CXX_COMPILER_ID} STREQUAL GNU)
elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL Clang)
elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
add_definitions("-D_SCL_SECURE_NO_WARNINGS")
add_definitions("-D_CRT_SECURE_NO_WARNINGS")
else()
message(STATUS "Unknown compiler: ${CMAKE_CXX_COMPILER_ID}")
endif()
set(CMAKE_COMPILER_STRING "${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")
# https://cmake.org/Bug/view.php?id=15361
set(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_CXX11_STANDARD_COMPILE_OPTION})
include(CheckCXXSourceCompiles)
check_cxx_source_compiles("
#include <thread>
int main(){ return 0; }
" CXX_HAS_THREADS)
check_cxx_source_compiles("
#include <memory>
int main(){ std::shared_ptr<void> foo(NULL); return 0; }
" CXX_HAS_SHARED_PTR)
check_cxx_source_compiles("
int main(){ int foo[10]; auto i = foo[0]; }
" CXX_HAS_AUTOTYPE)
check_cxx_source_compiles("
int main(){ []{}(); }
" CXX_HAS_LAMBDAS)
set(CXX_MISSING_FEATURES "")
if (NOT CXX_HAS_LAMBDAS)
set(CXX_MISSING_FEATURES "${CXX_MISSING_FEATURES} lambdas")
endif()
if(NOT CXX_HAS_THREADS)
set(CXX_MISSING_FEATURES "${CXX_MISSING_FEATURES} threads")
endif()
if(NOT CXX_HAS_AUTOTYPE)
set(CXX_MISSING_FEATURES "${CXX_MISSING_FEATURES} autotype")
endif()
if(NOT CXX_HAS_SHARED_PTR)
set(CXX_MISSING_FEATURES "${CXX_MISSING_FEATURES} shared_ptr")
endif()
if (CXX_MISSING_FEATURES)
message(FATAL_ERROR "Compiler is missing required C++11 features: ${CXX_MISSING_FEATURES}")
endif()
if (CMAKE_CROSSCOMPILING OR WIN32)
OPTION(BUILD_SHARED_LIBS "Build shared libraries" OFF)
else()
OPTION(BUILD_SHARED_LIBS "Build shared libraries" ON)
endif()
# built shared or static libraries?
if(BUILD_SHARED_LIBS)
add_definitions("-DUSCXML_EXPORT")
else()
add_definitions("-DUSCXML_STATIC")
endif()
#################################################
# Dependent Libraries
#################################################
################################
# Required
# CURL
find_package(CURL)
if (CURL_FOUND)
include_directories(${CURL_INCLUDE_DIRS})
list (APPEND USCXML_CORE_LIBS ${CURL_LIBRARIES})
include(CheckCXXSourceCompiles)
set(CMAKE_REQUIRED_INCLUDES ${CURL_INCLUDE_DIRS})
set(CMAKE_REQUIRED_LIBRARIES ${CURL_LIBRARIES})
check_cxx_source_compiles("
#include <curl/curl.h>
int main(){ return CURLOPT_MAIL_RCPT; }
" CURL_HAS_SMTP)
else()
message(STATUS "--> will download and compile")
include("${CMAKE_MODULE_PATH}/BuildLibCURL.cmake")
if (LIBCURL_BUILT)
include_directories(${LIBCURL_INCLUDE_DIR})
list (APPEND USCXML_CORE_LIBS ${LIBCURL_LIBRARY})
set(CURL_HAS_SMTP ON)
else()
message(FATAL_ERROR "Could neither find nor build CURL")
endif()
endif()
# XercesC
CheckHasModule(XercesC)
if (HAS_MODULE_XercesC)
find_package(XercesC)
else()
message(STATUS "Could NOT find XercesC (your CMake distribution does not include the FindXercesC module)")
endif()
if (XercesC_FOUND)
include_directories(${XercesC_INCLUDE_DIRS})
list (APPEND USCXML_CORE_LIBS ${XercesC_LIBRARIES})
else()
message(STATUS "--> will download and compile")
include("${CMAKE_MODULE_PATH}/BuildXercesC.cmake")
if (XercesC_BUILT)
include_directories(${XercesC_INCLUDE_DIRS})
list (APPEND USCXML_CORE_LIBS ${XercesC_LIBRARIES})
else()
message(FATAL_ERROR "Could neither find nor build XercesC")
endif()
endif()
# LibEvent
find_package(LibEvent)
if (LIBEVENT_FOUND)
include_directories(${LIBEVENT_INCLUDE_DIR})
list (APPEND USCXML_CORE_LIBS ${LIBEVENT_LIBRARIES})
else()
message(STATUS "--> will download and compile")
include("${CMAKE_MODULE_PATH}/BuildLibEvent.cmake")
if (LIBEVENT_BUILT)
include_directories(${LIBEVENT_INCLUDE_DIR})
list (APPEND USCXML_CORE_LIBS ${LIBEVENT_LIBRARIES})
else()
message(FATAL_ERROR "Could neither find nor build libevent")
endif()
endif()
if (UNIX)
list (APPEND USCXML_CORE_LIBS "pthread")
endif()
# uriparser
include("${CMAKE_MODULE_PATH}/BuildURIParser.cmake")
message(STATUS "Did not look for UriParser")
message(STATUS "--> will download and compile")
if (URIPARSER_BUILT)
include_directories(${URIPARSER_INCLUDE_DIR})
list (APPEND USCXML_CORE_LIBS ${URIPARSER_LIBRARY})
else()
message(FATAL_ERROR "Could not build uriparser")
endif()
################################
# Optional
# JavaScriptCore
find_package(JSC)
if (JSC_FOUND)
set(ECMA_FOUND ON)
if (NOT APPLE)
include_directories(${JSC_INCLUDE_DIR})
endif()
list (APPEND USCXML_OPT_LIBS ${JSC_LIBRARY})
endif()
find_package(V8)
if (V8_FOUND)
set(ECMA_FOUND ON)
include_directories(${V8_INCLUDE_DIR})
list (APPEND USCXML_OPT_LIBS ${V8_LIBRARY})
endif()
find_package(Lua)
if (LUA_FOUND)
include_directories (${LUA_INCLUDE_DIR})
include_directories(${PROJECT_SOURCE_DIR}/contrib/src/LuaBridge)
list (APPEND USCXML_OPT_LIBS ${LUA_LIBRARIES})
endif()
# if(APPLE)
# find_library(APP_SERVICES_LIBRARY ApplicationServices)
# find_library(COREFOUNDATION_LIBRARY CoreFoundation)
# find_library(FOUNDATION_LIBRARY Foundation)
# list (APPEND USCXML_CORE_LIBS ${APP_SERVICES_LIBRARY})
# list (APPEND USCXML_CORE_LIBS ${COREFOUNDATION_LIBRARY})
# list (APPEND USCXML_CORE_LIBS ${FOUNDATION_LIBRARY})
# endif()
add_subdirectory(src/uscxml)
add_library(uscxml ${USCXML_FILES})
set_property(TARGET uscxml PROPERTY CXX_STANDARD 11)
set_property(TARGET uscxml PROPERTY CXX_STANDARD_REQUIRED ON)
set_property(TARGET uscxml PROPERTY SOVERSION ${USCXML_VERSION})
add_dependencies(uscxml libevent xerces-c)
target_link_libraries(uscxml ${USCXML_OPT_LIBS} ${USCXML_CORE_LIBS})
add_library(uscxml_transform ${USCXML_TRANSFORM_FILES})
set_property(TARGET uscxml_transform PROPERTY CXX_STANDARD 11)
set_property(TARGET uscxml_transform PROPERTY CXX_STANDARD_REQUIRED ON)
set_property(TARGET uscxml_transform PROPERTY SOVERSION ${USCXML_VERSION})
target_link_libraries(uscxml_transform uscxml)
if (NOT CMAKE_CROSSCOMPILING)
enable_testing()
add_subdirectory(test)
endif()
if (WIN32)
add_executable(uscxml-browser apps/uscxml-browser.cpp ${PROJECT_SOURCE_DIR}/contrib/src/getopt/getopt.c)
add_executable(uscxml-transform apps/uscxml-transform.cpp ${PROJECT_SOURCE_DIR}/contrib/src/getopt/getopt.c)
else()
add_executable(uscxml-browser apps/uscxml-browser.cpp)
add_executable(uscxml-transform apps/uscxml-transform.cpp)
endif()
set_property(TARGET uscxml-browser PROPERTY CXX_STANDARD 11)
set_property(TARGET uscxml-browser PROPERTY CXX_STANDARD_REQUIRED ON)
set_property(TARGET uscxml-transform PROPERTY CXX_STANDARD 11)
set_property(TARGET uscxml-transform PROPERTY CXX_STANDARD_REQUIRED ON)
target_link_libraries(uscxml-browser uscxml)
target_link_libraries(uscxml-transform uscxml uscxml_transform)
############################################################
# Create config.h
############################################################
# determine path seperator
if (WIN32)
SET(PATH_SEPERATOR "\\\\")
else()
SET(PATH_SEPERATOR "/")
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Release")
set(CMAKE_BUILD_TYPE_RELEASE ON)
elseif(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_BUILD_TYPE_DEBUG ON)
endif()
# enable config.h style compile time options and add as "uscxml/config.h"
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/uscxml/config.h)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/test/ctest/CTestCustom.ctest.in ${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.ctest)
# get_cmake_property(_variableNames VARIABLES)
# foreach (_variableName ${_variableNames})
# message(STATUS "${_variableName}=${${_variableName}}")
# endforeach()
|