1 # Copyright 2012 Cloudera Inc.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Helper function to generate build rules. For each input thrift file, this function will
16 # generate a rule that maps the input file to the output c++ file.
17 # Thrift will generate multiple output files for each input (including java files) and
18 # ideally, we'd specify all of the outputs for dependency tracking.
19 # Unfortunately, it's not easy to figure out all the output files without parsing the
20 # thrift input. (TODO: can thrift tells us what the java output files will be?)
21 # The list of output files is used for build dependency tracking so it's not necessary to
22 # capture all the output files.
24 # To call this function, pass it the output file list followed by the input thrift files:
25 # i.e. HS2_THRIFT_GEN(OUTPUT_FILES, ${THRIFT_FILES})
27 # cmake seems to be case sensitive for some keywords. Changing the first IF check to lower
28 # case makes it not work. TODO: investigate this
29 function(HS2_THRIFT_GEN VAR)
31 message(SEND_ERROR "Error: THRIFT_GEN called without any src files")
38 get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
40 get_filename_component(FIL_WE ${FIL} NAME_WE)
42 set(GEN_DIR "${OUTPUT_DIR}/arrow/dbi/hiveserver2")
44 # All the output files we can determine based on filename.
45 # - Does not include .skeleton.cpp files
46 # - Does not include java output files
48 "${GEN_DIR}/${FIL_WE}_types.cpp" "${GEN_DIR}/${FIL_WE}_types.h"
49 "${GEN_DIR}/${FIL_WE}_constants.cpp" "${GEN_DIR}/${FIL_WE}_constants.h")
50 list(APPEND ${VAR} ${OUTPUT_BE_FILE})
52 # BeeswaxService thrift generation
53 # It depends on hive_meta_store, which in turn depends on fb303.
54 # The java dependency is handled by maven.
55 # We need to generate C++ src file for the parent dependencies using the "-r" option.
62 if(FIL STREQUAL "beeswax.thrift")
70 endif(FIL STREQUAL "beeswax.thrift")
72 # Be able to include generated ErrorCodes.thrift file
73 set(CPP_ARGS ${CPP_ARGS} -I ${CMAKE_CURRENT_BINARY_DIR})
75 add_custom_command(OUTPUT ${OUTPUT_BE_FILE}
76 COMMAND ${THRIFT_COMPILER} ${CPP_ARGS} ${FIL}
78 COMMENT "Running thrift compiler on ${FIL}"
79 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
86 endfunction(HS2_THRIFT_GEN)
88 message("Using Thrift compiler: ${THRIFT_COMPILER}")
90 set(OUTPUT_DIR ${ARROW_BINARY_DIR}/src)
91 file(MAKE_DIRECTORY ${OUTPUT_DIR})
93 add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ErrorCodes.thrift
94 COMMAND python generate_error_codes.py ${CMAKE_CURRENT_BINARY_DIR}
95 DEPENDS generate_error_codes.py
96 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
99 ${CMAKE_CURRENT_BINARY_DIR}/ErrorCodes.thrift
107 set_source_files_properties(Status.thrift
108 PROPERTIES OBJECT_DEPENDS
109 ${CMAKE_CURRENT_BINARY_DIR}/ErrorCodes.thrift)
111 # Create a build command for each of the thrift src files and generate
112 # a list of files they produce
113 hs2_thrift_gen(THRIFT_ALL_FILES ${SRC_FILES})
115 # Add a custom target that generates all the thrift files
116 add_custom_target(hs2-thrift-cpp ALL DEPENDS ${THRIFT_ALL_FILES})
118 add_custom_target(hs2-thrift-generated-files-error
119 DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ErrorCodes.thrift)
120 add_dependencies(hs2-thrift-cpp hs2-thrift-generated-files-error)