blob: 5275a922a0fcf030983808bbee5bb01f3edca670 [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
23project(thrift-compiler)
24
25# TODO: Where to get correct version information
26set(thrift_VERSION_MAJOR 0)
27set(thrift_VERSION_MINOR 9)
28set(thrift_VERSION_PATCH 2)
29set(thrift_VERSION "${thrift_VERSION_MAJOR}.${thrift_VERSION_MINOR}.${thrift_VERSION_PATCH}")
30
31# The following variable is used in the version.h.in file
32set(PACKAGE_VERSION ${thrift_VERSION})
33
34# Windows has a different header
35if(WIN32)
36 set(FLEX_FLAGS "--wincompat") # Don't use unistd.h on windows
37 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/windows/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h)
38else()
39 set(FLEX_FLAGS " ")
40 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h)
41endif()
42
43find_package(FLEX REQUIRED)
44find_package(BISON REQUIRED)
45
46# Create flex and bison files and build the lib parse static library
47BISON_TARGET(thrifty ${CMAKE_CURRENT_SOURCE_DIR}/src/thrifty.yy ${CMAKE_CURRENT_BINARY_DIR}/thrifty.cc)
48FLEX_TARGET(thriftl ${CMAKE_CURRENT_SOURCE_DIR}/src/thriftl.ll ${CMAKE_CURRENT_BINARY_DIR}/thriftl.cc COMPILE_FLAGS ${FLEX_FLAGS})
49ADD_FLEX_BISON_DEPENDENCY(thriftl thrifty)
50
51# HACK: Work around the fact that bison crates a .hh file but we need a .h file
52add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/thrifty.h
53 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/thrifty.hh ${CMAKE_CURRENT_BINARY_DIR}/thrifty.h
54 DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/thrifty.hh
55 )
56
57set(libparse_SOURCES
58 ${CMAKE_CURRENT_BINARY_DIR}/thrifty.cc
59 ${CMAKE_CURRENT_BINARY_DIR}/thriftl.cc
60 ${CMAKE_CURRENT_BINARY_DIR}/thrifty.h
61)
62
63add_library(libparse STATIC ${libparse_SOURCES})
64
65# Create the thrift compiler
66set( thrift_SOURCES
67 src/main.cc
68 src/md5.c
69 src/generate/t_generator.cc
70 src/generate/t_generator_registry.h
71 src/globals.h
72 src/main.h
73 src/platform.h
74 src/md5.h
75 src/parse/t_doc.h
76 src/parse/t_type.h
77 src/parse/t_base_type.h
78 src/parse/t_enum.h
79 src/parse/t_enum_value.h
80 src/parse/t_typedef.h
81 src/parse/t_typedef.cc
82 src/parse/t_container.h
83 src/parse/t_list.h
84 src/parse/t_set.h
85 src/parse/t_map.h
86 src/parse/t_struct.h
87 src/parse/t_field.h
88 src/parse/t_service.h
89 src/parse/t_function.h
90 src/parse/t_program.h
91 src/parse/t_scope.h
92 src/parse/t_const.h
93 src/parse/t_const_value.h
94 src/parse/parse.cc
95 src/generate/t_generator.h
96 src/generate/t_oop_generator.h
97 src/generate/t_html_generator.h
98 src/windows/config.h
99 version.h
100)
101
102# This macro adds an option THRIFT_COMPILER_${NAME}
103# that allows enabling or disabling certain languages
104macro(THRIFT_ADD_COMPILER name description initial)
105 string(TOUPPER "THRIFT_COMPILER_${name}" enabler)
106 set(src "src/generate/t_${name}_generator.cc")
107 option(${enabler} ${description} ${initial})
108 if(${enabler})
109 list(APPEND thrift_SOURCES ${src})
110 endif()
111endmacro()
112
113# The following compiler can be enabled or disabled
114THRIFT_ADD_COMPILER(c_glib "Enable compiler for C with Glib" ON)
115THRIFT_ADD_COMPILER(cpp "Enable compiler for C++" ON)
116THRIFT_ADD_COMPILER(java "Enable compiler for Java" ON)
117THRIFT_ADD_COMPILER(as3 "Enable compiler for ActionScript 3" ON)
118THRIFT_ADD_COMPILER(csharp "Enable compiler for C#" ON)
119THRIFT_ADD_COMPILER(py "Enable compiler for Python 2.0" ON)
120THRIFT_ADD_COMPILER(rb "Enable compiler for Ruby" ON)
121THRIFT_ADD_COMPILER(perl "Enable compiler for Perl" ON)
122THRIFT_ADD_COMPILER(php "Enable compiler for PHP" ON)
123THRIFT_ADD_COMPILER(erl "Enable compiler for Erlang" ON)
124THRIFT_ADD_COMPILER(cocoa "Enable compiler for Cocoa Objective-C" ON)
125THRIFT_ADD_COMPILER(st "Enable compiler for Smalltalk" ON)
126THRIFT_ADD_COMPILER(ocaml "Enable compiler for OCaml" ON)
127THRIFT_ADD_COMPILER(hs "Enable compiler for Haskell" ON)
128THRIFT_ADD_COMPILER(xsd "Enable compiler for XSD" ON)
129THRIFT_ADD_COMPILER(html "Enable compiler for HTML Documentation" ON)
130THRIFT_ADD_COMPILER(js "Enable compiler for JavaScript" ON)
131THRIFT_ADD_COMPILER(javame "Enable compiler for Java ME" ON)
132THRIFT_ADD_COMPILER(delphi "Enable compiler for Delphi" ON)
133THRIFT_ADD_COMPILER(go "Enable compiler for Go" ON)
134THRIFT_ADD_COMPILER(d "Enable compiler for D" ON)
135THRIFT_ADD_COMPILER(lua "Enable compiler for Lua" ON)
136
137# Thrift is looking for include files in the src directory
138# we also add the current binary directory for generated files
139include_directories(${CMAKE_CURRENT_BINARY_DIR} src)
140
141add_executable(thrift ${thrift_SOURCES})
142target_link_libraries(thrift libparse)
143
144if(NOT WIN32)
145 install(TARGETS thrift DESTINATION bin)
146endif()