Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
0.14.0, 0.15.0
-
None
-
None
Description
While upgrading the Thrift version that we use, I noticed that starting with version 0.14.0 Thrift does not generate a well-defined set of output files for C++, which makes it difficult to build generic build system tooling around it. I tracked the issue down to THRIFT-5168.
Our current cmake helper function, where I prefixed the lines that were added to workaround this issue with a +:
function(target_thrift_source _target) set(_single_args "THRIFT_FILE" "BINARY_DIR" ) set(_multi_args "SERVICES;CXX_OPTIONS" ) cmake_parse_arguments(tts "" "${_single_args}" "${_multi_args}" ${ARGN}) foreach(_required_arg THRIFT_FILE) if(NOT tts_${_required_arg}) message(FATAL_ERROR "target_thrift_source called without ${_required_arg}") endif() endforeach() if(NOT tts_BINARY_DIR) set(tts_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/thrift_generated") endif() get_filename_component(_thriftfile_abs_path "${tts_THRIFT_FILE}" ABSOLUTE) get_filename_component(_working_directory "${_thriftfile_abs_path}" DIRECTORY) get_filename_component(_thriftfile_name "${tts_THRIFT_FILE}" NAME_WE) set(_output_files "${tts_BINARY_DIR}/${_thriftfile_name}_types.h" "${tts_BINARY_DIR}/${_thriftfile_name}_types.cpp" "${tts_BINARY_DIR}/${_thriftfile_name}_constants.h" "${tts_BINARY_DIR}/${_thriftfile_name}_constants.cpp" ) foreach(_service IN LISTS tts_SERVICES) list(APPEND _output_files "${tts_BINARY_DIR}/${_service}.h" "${tts_BINARY_DIR}/${_service}.cpp" ) endforeach() set(thrift_CXX_OPTIONS "moveable_types,no_skeleton") foreach(_opt IN LISTS tts_CXX_OPTIONS) string(APPEND thrift_CXX_OPTIONS ",${_opt}") endforeach() + set(_touch_commands) + foreach(_file IN LISTS _output_files) + list(APPEND _touch_commands COMMAND "${CMAKE_COMMAND}" -E touch "${_file}") + endforeach() add_custom_command( OUTPUT ${_output_files} COMMAND "${CMAKE_COMMAND}" -E make_directory "${tts_BINARY_DIR}" COMMAND Thrift::compiler -out "${tts_BINARY_DIR}" --gen cpp:${thrift_CXX_OPTIONS} "${_thriftfile_abs_path}" + ${_touch_commands} MAIN_DEPENDENCY "${_thriftfile_abs_path}" DEPENDS "${_thriftfile_abs_path}" WORKING_DIRECTORY "${_working_directory}" ) target_include_directories("${_target}" PRIVATE "${tts_BINARY_DIR}") target_sources("${_target}" PRIVATE ${_output_files} ${tts_THRIFT_FILE} ) endfunction()