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# 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 30# 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) 32if(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/generate/validator_parser.cc 80 ${THRIFT_COMPILER_SOURCE_DIR}/src/thrift/generate/validator_parser.h 81 ${THRIFT_COMPILER_SOURCE_DIR}/src/thrift/parse/t_typedef.cc 82 ${THRIFT_COMPILER_SOURCE_DIR}/src/thrift/parse/parse.cc 83 ${THRIFT_COMPILER_SOURCE_DIR}/src/thrift/version.h 84) 85 86# This macro adds an option THRIFT_COMPILER_${NAME} 87# that allows enabling or disabling certain languages 88macro(THRIFT_ADD_COMPILER name description initial) 89 string(TOUPPER "THRIFT_COMPILER_${name}" enabler) 90 set(src "${THRIFT_COMPILER_SOURCE_DIR}/src/thrift/generate/t_${name}_generator.cc") 91 option(${enabler} ${description} ${initial}) 92 if(${enabler}) 93 list(APPEND thrift_compiler_SOURCES ${src}) 94 file(GLOB thrift_compiler_tests_SOURCES 95 "${CMAKE_CURRENT_SOURCE_DIR}/${name}/*.c*" 96 "${CMAKE_CURRENT_SOURCE_DIR}/${name}/*.thrift" 97 ) 98 endif() 99endmacro() 100 101# This macro adds an option THRIFT_VALIDATOR_COMPILER_${NAME} 102# that allows enabling or disabling certain languages 103macro(THRIFT_ADD_VALIDATOR_COMPILER name description initial) 104 string(TOUPPER "THRIFT_VALIDATOR_COMPILER_${name}" enabler) 105 set(src "${THRIFT_COMPILER_SOURCE_DIR}/src/thrift/generate/${name}_validator_generator.cc") 106 list(APPEND "${THRIFT_COMPILER_SOURCE_DIR}/src/thrift/generate/${name}_validator_generator.h") 107 option(${enabler} ${description} ${initial}) 108 if(${enabler}) 109 list(APPEND thrift-compiler_SOURCES ${src}) 110 endif() 111endmacro() 112 113# The following compiler with unit tests can be enabled or disabled 114THRIFT_ADD_COMPILER(c_glib "Enable compiler for C with Glib" OFF) 115THRIFT_ADD_COMPILER(cl "Enable compiler for Common LISP" OFF) 116THRIFT_ADD_COMPILER(cpp "Enable compiler for C++" OFF) 117THRIFT_ADD_COMPILER(d "Enable compiler for D" OFF) 118THRIFT_ADD_COMPILER(dart "Enable compiler for Dart" OFF) 119THRIFT_ADD_COMPILER(delphi "Enable compiler for Delphi" OFF) 120THRIFT_ADD_COMPILER(erl "Enable compiler for Erlang" OFF) 121THRIFT_ADD_COMPILER(go "Enable compiler for Go" OFF) 122THRIFT_ADD_COMPILER(gv "Enable compiler for GraphViz" OFF) 123THRIFT_ADD_COMPILER(haxe "Enable compiler for Haxe" OFF) 124THRIFT_ADD_COMPILER(html "Enable compiler for HTML Documentation" OFF) 125THRIFT_ADD_COMPILER(java "Enable compiler for Java" OFF) 126THRIFT_ADD_COMPILER(javame "Enable compiler for Java ME" OFF) 127THRIFT_ADD_COMPILER(js "Enable compiler for JavaScript" OFF) 128THRIFT_ADD_COMPILER(json "Enable compiler for JSON" OFF) 129THRIFT_ADD_COMPILER(lua "Enable compiler for Lua" OFF) 130THRIFT_ADD_COMPILER(netstd "Enable compiler for .NET Standard" ON) 131THRIFT_ADD_COMPILER(ocaml "Enable compiler for OCaml" ON) 132THRIFT_ADD_COMPILER(perl "Enable compiler for Perl" OFF) 133THRIFT_ADD_COMPILER(php "Enable compiler for PHP" OFF) 134THRIFT_ADD_COMPILER(py "Enable compiler for Python 2.0" OFF) 135THRIFT_ADD_COMPILER(rb "Enable compiler for Ruby" OFF) 136THRIFT_ADD_COMPILER(rs "Enable compiler for Rust" OFF) 137THRIFT_ADD_COMPILER(st "Enable compiler for Smalltalk" OFF) 138THRIFT_ADD_COMPILER(swift "Enable compiler for Swift" OFF) 139THRIFT_ADD_COMPILER(xml "Enable compiler for XML" OFF) 140THRIFT_ADD_COMPILER(xsd "Enable compiler for XSD" OFF) 141 142# The following compiler can be enabled or disabled by enabling or disabling certain languages 143THRIFT_ADD_VALIDATOR_COMPILER(go "Enable validator compiler for Go" ON) 144 145# Thrift is looking for include files in the src directory 146# we also add the current binary directory for generated files 147include_directories(${CMAKE_CURRENT_BINARY_DIR} ${THRIFT_COMPILER_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/catch) 148 149add_library(thrift_compiler ${thrift_compiler_SOURCES}) 150 151#link parse lib to thrift_compiler lib 152target_link_libraries(thrift_compiler parse) 153 154# add tests executable 155add_executable(thrift_compiler_tests ${thrift_compiler_tests_manual_SOURCES} ${thrift_compiler_tests_SOURCES}) 156 157# if generates for Visual Studio set thrift_compiler_tests as default project 158if(MSVC) 159 set_property(TARGET thrift_compiler_tests PROPERTY VS_STARTUP_PROJECT thrift_compiler_tests) 160endif() 161 162set_target_properties(thrift_compiler_tests PROPERTIES RUNTIME_OUTPUT_DIRECTORY bin/) 163set_target_properties(thrift_compiler_tests PROPERTIES OUTPUT_NAME thrift_compiler_tests) 164 165target_link_libraries(thrift_compiler_tests thrift_compiler) 166 167enable_testing() 168add_test(NAME ThriftTests COMMAND thrift_compiler_tests) 169