blob: 606bfcd5bc5cac8ca7e7da1a13efd139d2515ca9 [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
Pascal Bach42be4e82014-04-23 18:19:06 +020025# Read the version information from the Autoconf file
26file (STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/../../configure.ac" CONFIGURE_AC REGEX "AC_INIT\\(.*\\)" )
Pascal Bach6eb015a2014-04-17 16:19:07 +020027
28# The following variable is used in the version.h.in file
Pascal Bach42be4e82014-04-23 18:19:06 +020029string(REGEX REPLACE "AC_INIT\\(\\[.*\\], \\[([0-9]+\\.[0-9]+\\.[0-9]+(-dev)?)\\]\\)" "\\1" PACKAGE_VERSION ${CONFIGURE_AC})
30message(STATUS "Thrift package version: ${PACKAGE_VERSION}")
31
32# These are internal to CMake
33string(REGEX REPLACE "([0-9]+\\.[0-9]+\\.[0-9]+)(-dev)?" "\\1" thrift_VERSION ${PACKAGE_VERSION})
34string(REGEX REPLACE "([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" thrift_VERSION_MAJOR ${thrift_VERSION})
35string(REGEX REPLACE "[0-9]+\\.([0-9])+\\.[0-9]+" "\\1" thrift_VERSION_MINOR ${thrift_VERSION})
36string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" thrift_VERSION_PATCH ${thrift_VERSION})
37message(STATUS "Thrift version: ${thrift_VERSION} (${thrift_VERSION_MAJOR}.${thrift_VERSION_MINOR}.${thrift_VERSION_PATCH})")
Pascal Bach6eb015a2014-04-17 16:19:07 +020038
39# Windows has a different header
Pascal Bach569863a2014-06-10 13:15:40 +020040if(MSVC)
Pascal Bach6eb015a2014-04-17 16:19:07 +020041 set(FLEX_FLAGS "--wincompat") # Don't use unistd.h on windows
42 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/windows/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h)
43else()
44 set(FLEX_FLAGS " ")
45 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h)
46endif()
47
48find_package(FLEX REQUIRED)
49find_package(BISON REQUIRED)
50
51# Create flex and bison files and build the lib parse static library
52BISON_TARGET(thrifty ${CMAKE_CURRENT_SOURCE_DIR}/src/thrifty.yy ${CMAKE_CURRENT_BINARY_DIR}/thrifty.cc)
53FLEX_TARGET(thriftl ${CMAKE_CURRENT_SOURCE_DIR}/src/thriftl.ll ${CMAKE_CURRENT_BINARY_DIR}/thriftl.cc COMPILE_FLAGS ${FLEX_FLAGS})
54ADD_FLEX_BISON_DEPENDENCY(thriftl thrifty)
55
56# HACK: Work around the fact that bison crates a .hh file but we need a .h file
57add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/thrifty.h
58 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/thrifty.hh ${CMAKE_CURRENT_BINARY_DIR}/thrifty.h
59 DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/thrifty.hh
60 )
61
62set(libparse_SOURCES
63 ${CMAKE_CURRENT_BINARY_DIR}/thrifty.cc
64 ${CMAKE_CURRENT_BINARY_DIR}/thriftl.cc
65 ${CMAKE_CURRENT_BINARY_DIR}/thrifty.h
66)
67
68add_library(libparse STATIC ${libparse_SOURCES})
69
70# Create the thrift compiler
71set( thrift_SOURCES
72 src/main.cc
73 src/md5.c
74 src/generate/t_generator.cc
75 src/generate/t_generator_registry.h
76 src/globals.h
77 src/main.h
78 src/platform.h
79 src/md5.h
80 src/parse/t_doc.h
81 src/parse/t_type.h
82 src/parse/t_base_type.h
83 src/parse/t_enum.h
84 src/parse/t_enum_value.h
85 src/parse/t_typedef.h
86 src/parse/t_typedef.cc
87 src/parse/t_container.h
88 src/parse/t_list.h
89 src/parse/t_set.h
90 src/parse/t_map.h
91 src/parse/t_struct.h
92 src/parse/t_field.h
93 src/parse/t_service.h
94 src/parse/t_function.h
95 src/parse/t_program.h
96 src/parse/t_scope.h
97 src/parse/t_const.h
98 src/parse/t_const_value.h
99 src/parse/parse.cc
100 src/generate/t_generator.h
101 src/generate/t_oop_generator.h
102 src/generate/t_html_generator.h
103 src/windows/config.h
104 version.h
105)
106
107# This macro adds an option THRIFT_COMPILER_${NAME}
108# that allows enabling or disabling certain languages
109macro(THRIFT_ADD_COMPILER name description initial)
110 string(TOUPPER "THRIFT_COMPILER_${name}" enabler)
111 set(src "src/generate/t_${name}_generator.cc")
112 option(${enabler} ${description} ${initial})
113 if(${enabler})
114 list(APPEND thrift_SOURCES ${src})
115 endif()
116endmacro()
117
118# The following compiler can be enabled or disabled
119THRIFT_ADD_COMPILER(c_glib "Enable compiler for C with Glib" ON)
120THRIFT_ADD_COMPILER(cpp "Enable compiler for C++" ON)
121THRIFT_ADD_COMPILER(java "Enable compiler for Java" ON)
122THRIFT_ADD_COMPILER(as3 "Enable compiler for ActionScript 3" ON)
123THRIFT_ADD_COMPILER(csharp "Enable compiler for C#" ON)
124THRIFT_ADD_COMPILER(py "Enable compiler for Python 2.0" ON)
125THRIFT_ADD_COMPILER(rb "Enable compiler for Ruby" ON)
126THRIFT_ADD_COMPILER(perl "Enable compiler for Perl" ON)
127THRIFT_ADD_COMPILER(php "Enable compiler for PHP" ON)
128THRIFT_ADD_COMPILER(erl "Enable compiler for Erlang" ON)
129THRIFT_ADD_COMPILER(cocoa "Enable compiler for Cocoa Objective-C" ON)
130THRIFT_ADD_COMPILER(st "Enable compiler for Smalltalk" ON)
131THRIFT_ADD_COMPILER(ocaml "Enable compiler for OCaml" ON)
132THRIFT_ADD_COMPILER(hs "Enable compiler for Haskell" ON)
133THRIFT_ADD_COMPILER(xsd "Enable compiler for XSD" ON)
134THRIFT_ADD_COMPILER(html "Enable compiler for HTML Documentation" ON)
135THRIFT_ADD_COMPILER(js "Enable compiler for JavaScript" ON)
Roger Meier1a74d9c2014-10-12 23:35:43 +0200136THRIFT_ADD_COMPILER(json "Enable compiler for JSON" ON)
Pascal Bach6eb015a2014-04-17 16:19:07 +0200137THRIFT_ADD_COMPILER(javame "Enable compiler for Java ME" ON)
138THRIFT_ADD_COMPILER(delphi "Enable compiler for Delphi" ON)
139THRIFT_ADD_COMPILER(go "Enable compiler for Go" ON)
140THRIFT_ADD_COMPILER(d "Enable compiler for D" ON)
141THRIFT_ADD_COMPILER(lua "Enable compiler for Lua" ON)
142
143# Thrift is looking for include files in the src directory
144# we also add the current binary directory for generated files
145include_directories(${CMAKE_CURRENT_BINARY_DIR} src)
146
147add_executable(thrift ${thrift_SOURCES})
Pascal Bach42be4e82014-04-23 18:19:06 +0200148
Pascal Bach6eb015a2014-04-17 16:19:07 +0200149target_link_libraries(thrift libparse)
150
Roger Meier87202602014-08-15 22:16:02 +0200151install(TARGETS thrift DESTINATION bin)
152
Roger Meier311f7152014-08-17 22:24:30 +0200153# mingw32 does not support c++0x features
154if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
Roger Meierec300e32014-10-13 02:13:35 +0200155 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
Roger Meier311f7152014-08-17 22:24:30 +0200156endif()
157
Roger Meierec300e32014-10-13 02:13:35 +0200158if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
159 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic")
160endif()
161
162
Roger Meier87202602014-08-15 22:16:02 +0200163# create a Distribution Package for the Apache Thrift Compiler
164set(CPACK_PACKAGE_NAME "Apache Thrift")
165set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Apache Thrift Compiler")
166set(CPACK_PACKAGE_VENDOR "Apache Software Foundation" )
167set(CPACK_PACKAGE_CONTACT "dev@thrift.apache.org")
168set(CPACK_PACKAGE_VERSION ${thrift_VERSION})
169set(CPACK_PACKAGE_VERSION_MAJOR ${thrift_VERSION_MAJOR} )
170set(CPACK_PACKAGE_VERSION_MINOR ${thrift_VERSION_MINOR} )
171set(CPACK_PACKAGE_VERSION_PATCH ${thrift_VERSION_PATCH} )
172set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/../../LICENSE")
173
174if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
175 set(CPACK_GENERATOR "NSIS")
176 set(CPACK_NSIS_HELP_LINK "http://thrift.apache.org")
177 set(CPACK_NSIS_MENU_LINKS
178 "http://thrift.apache.org" "Apache Thrift - Web Site"
179 "https://issues.apache.org/jira/browse/THRIFT" "Apache Thrift - Issues")
180 set(CPACK_NSIS_CONTACT ${CPACK_PACKAGE_CONTACT})
181 set(CPACK_NSIS_MODIFY_PATH "ON")
182 set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME})
183else()
184 set(CPACK_GENERATOR "DEB" )
185 set(CPACK_DEBIAN_PACKAGE_MAINTAINER ${CPACK_PACKAGE_CONTACT})
Pascal Bach6eb015a2014-04-17 16:19:07 +0200186endif()
Roger Meier87202602014-08-15 22:16:02 +0200187include(CPack)