blob: 57b4c09f3b040726a166c291aac50c7f543d1e34 [file] [log] [blame]
Volodymyr Gotra54993292017-12-18 02:08:09 +02001#
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#
19cmake_minimum_required(VERSION 2.8.12)
20
21project(thrift_compiler_tests)
22
23set(THRIFT_COMPILER_SOURCE_DIR
24 ${CMAKE_CURRENT_SOURCE_DIR}/..
25)
26
27# don't generate ZERO_CHECK
28set(CMAKE_SUPPRESS_REGENERATION true)
29
Jens Geyer71997412019-10-19 21:22:59 +020030# version.h now handled via veralign.sh
31#configure_file(${THRIFT_COMPILER_SOURCE_DIR}/src/thrift/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/thrift/version.h)
Volodymyr Gotra54993292017-12-18 02:08:09 +020032if(MSVC)
33 # The winflexbison generator outputs some macros that conflict with the Visual Studio 2010 copy of stdint.h
34 # This might be fixed in later versions of Visual Studio, but an easy solution is to include stdint.h first
35 if(HAVE_STDINT_H)
36 add_definitions(-D__STDC_LIMIT_MACROS)
37 add_definitions(/FI"stdint.h")
38 endif(HAVE_STDINT_H)
39endif()
40
41find_package(FLEX REQUIRED)
42find_package(BISON REQUIRED)
43
44# create directory for thrifty and thriftl
45file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/thrift/)
46
47# Create flex and bison files and build the lib parse static library
48BISON_TARGET(thrifty ${THRIFT_COMPILER_SOURCE_DIR}/src/thrift/thrifty.yy ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.cc)
49FLEX_TARGET(thriftl ${THRIFT_COMPILER_SOURCE_DIR}/src/thrift/thriftl.ll ${CMAKE_CURRENT_BINARY_DIR}/thrift/thriftl.cc)
50ADD_FLEX_BISON_DEPENDENCY(thriftl thrifty)
51
52set(parse_SOURCES
53 ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.cc
54 ${CMAKE_CURRENT_BINARY_DIR}/thrift/thriftl.cc
55 ${CMAKE_CURRENT_BINARY_DIR}/thrift/thrifty.hh
56)
57
58add_library(parse STATIC ${parse_SOURCES})
59
60# Thrift compiler tests
61set(thrift_compiler_tests
62)
63
64# you can add some files manually there
65set(thrift_compiler_tests_manual_SOURCES
66 # tests file to avoid main in every test file
67 ${CMAKE_CURRENT_SOURCE_DIR}/tests_main.cc
68)
69
70# set variable for tests sources - will be filled later
71set(thrift_compiler_tests_SOURCES
72)
73
74set(thrift_compiler_SOURCES
75 ${THRIFT_COMPILER_SOURCE_DIR}/src/thrift/logging.cc # we use logging instead of main to avoid breaking compillation (2 main v)
76 ${THRIFT_COMPILER_SOURCE_DIR}/src/thrift/audit/t_audit.cpp
77 ${THRIFT_COMPILER_SOURCE_DIR}/src/thrift/common.cc
78 ${THRIFT_COMPILER_SOURCE_DIR}/src/thrift/generate/t_generator.cc
79 ${THRIFT_COMPILER_SOURCE_DIR}/src/thrift/parse/t_typedef.cc
80 ${THRIFT_COMPILER_SOURCE_DIR}/src/thrift/parse/parse.cc
Jens Geyer71997412019-10-19 21:22:59 +020081 ${THRIFT_COMPILER_SOURCE_DIR}/thrift/version.h
Volodymyr Gotra54993292017-12-18 02:08:09 +020082)
83
84# This macro adds an option THRIFT_COMPILER_${NAME}
85# that allows enabling or disabling certain languages
86macro(THRIFT_ADD_COMPILER name description initial)
87 string(TOUPPER "THRIFT_COMPILER_${name}" enabler)
88 set(src "${THRIFT_COMPILER_SOURCE_DIR}/src/thrift/generate/t_${name}_generator.cc")
89 option(${enabler} ${description} ${initial})
90 if(${enabler})
91 list(APPEND thrift_compiler_SOURCES ${src})
92 file(GLOB thrift_compiler_tests_SOURCES
93 "${CMAKE_CURRENT_SOURCE_DIR}/${name}/*.c*"
94 "${CMAKE_CURRENT_SOURCE_DIR}/${name}/*.thrift"
95 )
96 endif()
97endmacro()
98
99# The following compiler with unit tests can be enabled or disabled
James E. King III234fb472019-01-13 23:19:18 -0500100THRIFT_ADD_COMPILER(c_glib "Enable compiler for C with Glib" OFF)
101THRIFT_ADD_COMPILER(cl "Enable compiler for Common LISP" OFF)
102THRIFT_ADD_COMPILER(cpp "Enable compiler for C++" OFF)
James E. King III234fb472019-01-13 23:19:18 -0500103THRIFT_ADD_COMPILER(d "Enable compiler for D" OFF)
104THRIFT_ADD_COMPILER(dart "Enable compiler for Dart" OFF)
105THRIFT_ADD_COMPILER(delphi "Enable compiler for Delphi" OFF)
Volodymyr Gotra54993292017-12-18 02:08:09 +0200106THRIFT_ADD_COMPILER(erl "Enable compiler for Erlang" OFF)
James E. King III234fb472019-01-13 23:19:18 -0500107THRIFT_ADD_COMPILER(go "Enable compiler for Go" OFF)
108THRIFT_ADD_COMPILER(gv "Enable compiler for GraphViz" OFF)
109THRIFT_ADD_COMPILER(haxe "Enable compiler for Haxe" OFF)
Volodymyr Gotra54993292017-12-18 02:08:09 +0200110THRIFT_ADD_COMPILER(hs "Enable compiler for Haskell" OFF)
Volodymyr Gotra54993292017-12-18 02:08:09 +0200111THRIFT_ADD_COMPILER(html "Enable compiler for HTML Documentation" OFF)
James E. King III234fb472019-01-13 23:19:18 -0500112THRIFT_ADD_COMPILER(java "Enable compiler for Java" OFF)
113THRIFT_ADD_COMPILER(javame "Enable compiler for Java ME" OFF)
Volodymyr Gotra54993292017-12-18 02:08:09 +0200114THRIFT_ADD_COMPILER(js "Enable compiler for JavaScript" OFF)
115THRIFT_ADD_COMPILER(json "Enable compiler for JSON" OFF)
Volodymyr Gotra54993292017-12-18 02:08:09 +0200116THRIFT_ADD_COMPILER(lua "Enable compiler for Lua" OFF)
Jens Geyer3f3567a2019-10-19 18:27:35 +0200117THRIFT_ADD_COMPILER(netstd "Enable compiler for .NET Standard" ON)
James E. King III234fb472019-01-13 23:19:18 -0500118THRIFT_ADD_COMPILER(ocaml "Enable compiler for OCaml" OFF)
119THRIFT_ADD_COMPILER(perl "Enable compiler for Perl" OFF)
120THRIFT_ADD_COMPILER(php "Enable compiler for PHP" OFF)
121THRIFT_ADD_COMPILER(py "Enable compiler for Python 2.0" OFF)
122THRIFT_ADD_COMPILER(rb "Enable compiler for Ruby" OFF)
Volodymyr Gotra54993292017-12-18 02:08:09 +0200123THRIFT_ADD_COMPILER(rs "Enable compiler for Rust" OFF)
James E. King III234fb472019-01-13 23:19:18 -0500124THRIFT_ADD_COMPILER(st "Enable compiler for Smalltalk" OFF)
125THRIFT_ADD_COMPILER(swift "Enable compiler for Swift" OFF)
Volodymyr Gotra54993292017-12-18 02:08:09 +0200126THRIFT_ADD_COMPILER(xml "Enable compiler for XML" OFF)
James E. King III234fb472019-01-13 23:19:18 -0500127THRIFT_ADD_COMPILER(xsd "Enable compiler for XSD" OFF)
Volodymyr Gotra54993292017-12-18 02:08:09 +0200128
129# Thrift is looking for include files in the src directory
130# we also add the current binary directory for generated files
131include_directories(${CMAKE_CURRENT_BINARY_DIR} ${THRIFT_COMPILER_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/catch)
132
133add_library(thrift_compiler ${thrift_compiler_SOURCES})
134
135#link parse lib to thrift_compiler lib
136target_link_libraries(thrift_compiler parse)
137
138# add tests executable
139add_executable(thrift_compiler_tests ${thrift_compiler_tests_manual_SOURCES} ${thrift_compiler_tests_SOURCES})
140
141# if generates for Visual Studio set thrift_compiler_tests as default project
142if(MSVC)
143 set_property(TARGET thrift_compiler_tests PROPERTY VS_STARTUP_PROJECT thrift_compiler_tests)
144endif()
145
146set_target_properties(thrift_compiler_tests PROPERTIES RUNTIME_OUTPUT_DIRECTORY bin/)
147set_target_properties(thrift_compiler_tests PROPERTIES OUTPUT_NAME thrift_compiler_tests)
148
149target_link_libraries(thrift_compiler_tests thrift_compiler)
150
151enable_testing()
James E. King III234fb472019-01-13 23:19:18 -0500152add_test(NAME ThriftTests COMMAND thrift_compiler_tests)