blob: ddbe9ea4970366539c86feddbe82e96e618e508b [file] [log] [blame]
Pascal Bach6eb015a2014-04-17 16:19:07 +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#
19
20
21cmake_minimum_required(VERSION 2.8)
22
Pascal Bach6eb015a2014-04-17 16:19:07 +020023# Windows has a different header
Pascal Bach569863a2014-06-10 13:15:40 +020024if(MSVC)
Pascal Bach6eb015a2014-04-17 16:19:07 +020025 set(FLEX_FLAGS "--wincompat") # Don't use unistd.h on windows
26 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/windows/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h)
27else()
28 set(FLEX_FLAGS " ")
29 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h)
30endif()
31
32find_package(FLEX REQUIRED)
33find_package(BISON REQUIRED)
34
35# Create flex and bison files and build the lib parse static library
36BISON_TARGET(thrifty ${CMAKE_CURRENT_SOURCE_DIR}/src/thrifty.yy ${CMAKE_CURRENT_BINARY_DIR}/thrifty.cc)
37FLEX_TARGET(thriftl ${CMAKE_CURRENT_SOURCE_DIR}/src/thriftl.ll ${CMAKE_CURRENT_BINARY_DIR}/thriftl.cc COMPILE_FLAGS ${FLEX_FLAGS})
38ADD_FLEX_BISON_DEPENDENCY(thriftl thrifty)
39
40# HACK: Work around the fact that bison crates a .hh file but we need a .h file
41add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/thrifty.h
42 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/thrifty.hh ${CMAKE_CURRENT_BINARY_DIR}/thrifty.h
43 DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/thrifty.hh
44 )
45
46set(libparse_SOURCES
47 ${CMAKE_CURRENT_BINARY_DIR}/thrifty.cc
48 ${CMAKE_CURRENT_BINARY_DIR}/thriftl.cc
49 ${CMAKE_CURRENT_BINARY_DIR}/thrifty.h
50)
51
52add_library(libparse STATIC ${libparse_SOURCES})
53
54# Create the thrift compiler
55set( thrift_SOURCES
56 src/main.cc
57 src/md5.c
58 src/generate/t_generator.cc
59 src/generate/t_generator_registry.h
60 src/globals.h
61 src/main.h
62 src/platform.h
63 src/md5.h
64 src/parse/t_doc.h
65 src/parse/t_type.h
66 src/parse/t_base_type.h
67 src/parse/t_enum.h
68 src/parse/t_enum_value.h
69 src/parse/t_typedef.h
70 src/parse/t_typedef.cc
71 src/parse/t_container.h
72 src/parse/t_list.h
73 src/parse/t_set.h
74 src/parse/t_map.h
75 src/parse/t_struct.h
76 src/parse/t_field.h
77 src/parse/t_service.h
78 src/parse/t_function.h
79 src/parse/t_program.h
80 src/parse/t_scope.h
81 src/parse/t_const.h
82 src/parse/t_const_value.h
83 src/parse/parse.cc
84 src/generate/t_generator.h
85 src/generate/t_oop_generator.h
86 src/generate/t_html_generator.h
87 src/windows/config.h
88 version.h
89)
90
91# This macro adds an option THRIFT_COMPILER_${NAME}
92# that allows enabling or disabling certain languages
93macro(THRIFT_ADD_COMPILER name description initial)
94 string(TOUPPER "THRIFT_COMPILER_${name}" enabler)
95 set(src "src/generate/t_${name}_generator.cc")
96 option(${enabler} ${description} ${initial})
97 if(${enabler})
98 list(APPEND thrift_SOURCES ${src})
99 endif()
100endmacro()
101
102# The following compiler can be enabled or disabled
103THRIFT_ADD_COMPILER(c_glib "Enable compiler for C with Glib" ON)
104THRIFT_ADD_COMPILER(cpp "Enable compiler for C++" ON)
105THRIFT_ADD_COMPILER(java "Enable compiler for Java" ON)
106THRIFT_ADD_COMPILER(as3 "Enable compiler for ActionScript 3" ON)
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200107THRIFT_ADD_COMPILER(haxe "Enable compiler for Haxe" ON)
Pascal Bach6eb015a2014-04-17 16:19:07 +0200108THRIFT_ADD_COMPILER(csharp "Enable compiler for C#" ON)
109THRIFT_ADD_COMPILER(py "Enable compiler for Python 2.0" ON)
110THRIFT_ADD_COMPILER(rb "Enable compiler for Ruby" ON)
111THRIFT_ADD_COMPILER(perl "Enable compiler for Perl" ON)
112THRIFT_ADD_COMPILER(php "Enable compiler for PHP" ON)
113THRIFT_ADD_COMPILER(erl "Enable compiler for Erlang" ON)
114THRIFT_ADD_COMPILER(cocoa "Enable compiler for Cocoa Objective-C" ON)
115THRIFT_ADD_COMPILER(st "Enable compiler for Smalltalk" ON)
116THRIFT_ADD_COMPILER(ocaml "Enable compiler for OCaml" ON)
117THRIFT_ADD_COMPILER(hs "Enable compiler for Haskell" ON)
118THRIFT_ADD_COMPILER(xsd "Enable compiler for XSD" ON)
119THRIFT_ADD_COMPILER(html "Enable compiler for HTML Documentation" ON)
120THRIFT_ADD_COMPILER(js "Enable compiler for JavaScript" ON)
Roger Meier1a74d9c2014-10-12 23:35:43 +0200121THRIFT_ADD_COMPILER(json "Enable compiler for JSON" ON)
Pascal Bach6eb015a2014-04-17 16:19:07 +0200122THRIFT_ADD_COMPILER(javame "Enable compiler for Java ME" ON)
123THRIFT_ADD_COMPILER(delphi "Enable compiler for Delphi" ON)
124THRIFT_ADD_COMPILER(go "Enable compiler for Go" ON)
125THRIFT_ADD_COMPILER(d "Enable compiler for D" ON)
126THRIFT_ADD_COMPILER(lua "Enable compiler for Lua" ON)
127
128# Thrift is looking for include files in the src directory
129# we also add the current binary directory for generated files
130include_directories(${CMAKE_CURRENT_BINARY_DIR} src)
131
Pascal Bachd5f87e12014-12-12 15:59:17 +0100132add_executable(thrift-compiler ${thrift_SOURCES})
133set_target_properties(thrift-compiler PROPERTIES OUTPUT_NAME thrift)
Pascal Bach42be4e82014-04-23 18:19:06 +0200134
Pascal Bachd5f87e12014-12-12 15:59:17 +0100135target_link_libraries(thrift-compiler libparse)
Pascal Bach6eb015a2014-04-17 16:19:07 +0200136
Pascal Bachd5f87e12014-12-12 15:59:17 +0100137install(TARGETS thrift-compiler DESTINATION "${BIN_INSTALL_DIR}")