]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
1 | # |
2 | # Licensed to the Apache Software Foundation (ASF) under one | |
3 | # or more contributor license agreements. See the NOTICE file | |
4 | # distributed with this work for additional information | |
5 | # regarding copyright ownership. The ASF licenses this file | |
6 | # to you under the Apache License, Version 2.0 (the | |
7 | # "License"); you may not use this file except in compliance | |
8 | # with the License. You may obtain a copy of the License at | |
9 | # | |
10 | # http://www.apache.org/licenses/LICENSE-2.0 | |
11 | # | |
12 | # Unless required by applicable law or agreed to in writing, | |
13 | # software distributed under the License is distributed on an | |
14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
15 | # KIND, either express or implied. See the License for the | |
16 | # specific language governing permissions and limitations | |
17 | # under the License. | |
18 | # | |
19 | cmake_minimum_required(VERSION 2.8.12) | |
20 | ||
21 | project(thrift_compiler_tests) | |
22 | ||
23 | set(THRIFT_COMPILER_SOURCE_DIR | |
24 | ${CMAKE_CURRENT_SOURCE_DIR}/.. | |
25 | ) | |
26 | ||
27 | # don't generate ZERO_CHECK | |
28 | set(CMAKE_SUPPRESS_REGENERATION true) | |
29 | ||
30 | configure_file(${THRIFT_COMPILER_SOURCE_DIR}/src/thrift/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/thrift/version.h) | |
31 | if(MSVC) | |
32 | # The winflexbison generator outputs some macros that conflict with the Visual Studio 2010 copy of stdint.h | |
33 | # This might be fixed in later versions of Visual Studio, but an easy solution is to include stdint.h first | |
34 | if(HAVE_STDINT_H) | |
35 | add_definitions(-D__STDC_LIMIT_MACROS) | |
36 | add_definitions(/FI"stdint.h") | |
37 | endif(HAVE_STDINT_H) | |
38 | endif() | |
39 | ||
40 | find_package(FLEX REQUIRED) | |
41 | find_package(BISON REQUIRED) | |
42 | ||
43 | # create directory for thrifty and thriftl | |
44 | file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/thrift/) | |
45 | ||
46 | # Create flex and bison files and build the lib parse static library | |
47 | BISON_TARGET(thrifty ${THRIFT_COMPILER_SOURCE_DIR}/src/thrift/thrifty.yy ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.cc) | |
48 | FLEX_TARGET(thriftl ${THRIFT_COMPILER_SOURCE_DIR}/src/thrift/thriftl.ll ${CMAKE_CURRENT_BINARY_DIR}/thrift/thriftl.cc) | |
49 | ADD_FLEX_BISON_DEPENDENCY(thriftl thrifty) | |
50 | ||
51 | set(parse_SOURCES | |
52 | ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.cc | |
53 | ${CMAKE_CURRENT_BINARY_DIR}/thrift/thriftl.cc | |
54 | ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.hh | |
55 | ) | |
56 | ||
57 | add_library(parse STATIC ${parse_SOURCES}) | |
58 | ||
59 | # Thrift compiler tests | |
60 | set(thrift_compiler_tests | |
61 | ) | |
62 | ||
63 | # you can add some files manually there | |
64 | set(thrift_compiler_tests_manual_SOURCES | |
65 | # tests file to avoid main in every test file | |
66 | ${CMAKE_CURRENT_SOURCE_DIR}/tests_main.cc | |
67 | ) | |
68 | ||
69 | # set variable for tests sources - will be filled later | |
70 | set(thrift_compiler_tests_SOURCES | |
71 | ) | |
72 | ||
73 | set(thrift_compiler_SOURCES | |
74 | ${THRIFT_COMPILER_SOURCE_DIR}/src/thrift/logging.cc # we use logging instead of main to avoid breaking compillation (2 main v) | |
75 | ${THRIFT_COMPILER_SOURCE_DIR}/src/thrift/audit/t_audit.cpp | |
76 | ${THRIFT_COMPILER_SOURCE_DIR}/src/thrift/common.cc | |
77 | ${THRIFT_COMPILER_SOURCE_DIR}/src/thrift/generate/t_generator.cc | |
78 | ${THRIFT_COMPILER_SOURCE_DIR}/src/thrift/parse/t_typedef.cc | |
79 | ${THRIFT_COMPILER_SOURCE_DIR}/src/thrift/parse/parse.cc | |
80 | ${CMAKE_CURRENT_BINARY_DIR}/thrift/version.h | |
81 | ) | |
82 | ||
83 | # This macro adds an option THRIFT_COMPILER_${NAME} | |
84 | # that allows enabling or disabling certain languages | |
85 | macro(THRIFT_ADD_COMPILER name description initial) | |
86 | string(TOUPPER "THRIFT_COMPILER_${name}" enabler) | |
87 | set(src "${THRIFT_COMPILER_SOURCE_DIR}/src/thrift/generate/t_${name}_generator.cc") | |
88 | option(${enabler} ${description} ${initial}) | |
89 | if(${enabler}) | |
90 | list(APPEND thrift_compiler_SOURCES ${src}) | |
91 | file(GLOB thrift_compiler_tests_SOURCES | |
92 | "${CMAKE_CURRENT_SOURCE_DIR}/${name}/*.c*" | |
93 | "${CMAKE_CURRENT_SOURCE_DIR}/${name}/*.thrift" | |
94 | ) | |
95 | endif() | |
96 | endmacro() | |
97 | ||
98 | # The following compiler with unit tests can be enabled or disabled | |
99 | THRIFT_ADD_COMPILER(as3 "Enable compiler for ActionScript 3" OFF) | |
100 | THRIFT_ADD_COMPILER(c_glib "Enable compiler for C with Glib" OFF) | |
101 | THRIFT_ADD_COMPILER(cl "Enable compiler for Common LISP" OFF) | |
102 | THRIFT_ADD_COMPILER(cpp "Enable compiler for C++" OFF) | |
103 | THRIFT_ADD_COMPILER(csharp "Enable compiler for C#" OFF) | |
104 | THRIFT_ADD_COMPILER(d "Enable compiler for D" OFF) | |
105 | THRIFT_ADD_COMPILER(dart "Enable compiler for Dart" OFF) | |
106 | THRIFT_ADD_COMPILER(delphi "Enable compiler for Delphi" OFF) | |
107 | THRIFT_ADD_COMPILER(erl "Enable compiler for Erlang" OFF) | |
108 | THRIFT_ADD_COMPILER(go "Enable compiler for Go" OFF) | |
109 | THRIFT_ADD_COMPILER(gv "Enable compiler for GraphViz" OFF) | |
110 | THRIFT_ADD_COMPILER(haxe "Enable compiler for Haxe" OFF) | |
111 | THRIFT_ADD_COMPILER(hs "Enable compiler for Haskell" OFF) | |
112 | THRIFT_ADD_COMPILER(html "Enable compiler for HTML Documentation" OFF) | |
113 | THRIFT_ADD_COMPILER(java "Enable compiler for Java" OFF) | |
114 | THRIFT_ADD_COMPILER(javame "Enable compiler for Java ME" OFF) | |
115 | THRIFT_ADD_COMPILER(js "Enable compiler for JavaScript" OFF) | |
116 | THRIFT_ADD_COMPILER(json "Enable compiler for JSON" OFF) | |
117 | THRIFT_ADD_COMPILER(lua "Enable compiler for Lua" OFF) | |
118 | THRIFT_ADD_COMPILER(netcore "Enable compiler for .NET Core" ON) | |
119 | THRIFT_ADD_COMPILER(ocaml "Enable compiler for OCaml" OFF) | |
120 | THRIFT_ADD_COMPILER(perl "Enable compiler for Perl" OFF) | |
121 | THRIFT_ADD_COMPILER(php "Enable compiler for PHP" OFF) | |
122 | THRIFT_ADD_COMPILER(py "Enable compiler for Python 2.0" OFF) | |
123 | THRIFT_ADD_COMPILER(rb "Enable compiler for Ruby" OFF) | |
124 | THRIFT_ADD_COMPILER(rs "Enable compiler for Rust" OFF) | |
125 | THRIFT_ADD_COMPILER(st "Enable compiler for Smalltalk" OFF) | |
126 | THRIFT_ADD_COMPILER(swift "Enable compiler for Swift" OFF) | |
127 | THRIFT_ADD_COMPILER(xml "Enable compiler for XML" OFF) | |
128 | THRIFT_ADD_COMPILER(xsd "Enable compiler for XSD" OFF) | |
129 | ||
130 | # Thrift is looking for include files in the src directory | |
131 | # we also add the current binary directory for generated files | |
132 | include_directories(${CMAKE_CURRENT_BINARY_DIR} ${THRIFT_COMPILER_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/catch) | |
133 | ||
134 | add_library(thrift_compiler ${thrift_compiler_SOURCES}) | |
135 | ||
136 | #link parse lib to thrift_compiler lib | |
137 | target_link_libraries(thrift_compiler parse) | |
138 | ||
139 | # add tests executable | |
140 | add_executable(thrift_compiler_tests ${thrift_compiler_tests_manual_SOURCES} ${thrift_compiler_tests_SOURCES}) | |
141 | ||
142 | # if generates for Visual Studio set thrift_compiler_tests as default project | |
143 | if(MSVC) | |
144 | set_property(TARGET thrift_compiler_tests PROPERTY VS_STARTUP_PROJECT thrift_compiler_tests) | |
145 | endif() | |
146 | ||
147 | set_target_properties(thrift_compiler_tests PROPERTIES RUNTIME_OUTPUT_DIRECTORY bin/) | |
148 | set_target_properties(thrift_compiler_tests PROPERTIES OUTPUT_NAME thrift_compiler_tests) | |
149 | ||
150 | target_link_libraries(thrift_compiler_tests thrift_compiler) | |
151 | ||
152 | enable_testing() | |
153 | add_test(NAME ThriftTests COMMAND thrift_compiler_tests) |