generate_protobuf.cmake 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. function(generate_single_protobuf target_name gen_dst protobuf_name executable)
  2. file(MAKE_DIRECTORY ${gen_dst})
  3. # Copied from myprotobuf.cmake.
  4. if (PROTOBUF_GENERATE_CPP_APPEND_PATH)
  5. # Create an include path for each file specified
  6. set(FIL ${cld3_src}/${protobuf_name})
  7. get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
  8. get_filename_component(ABS_PATH ${ABS_FIL} PATH)
  9. list(FIND _protobuf_include_path ${ABS_PATH} _contains_already)
  10. if (${_contains_already} EQUAL -1)
  11. list(APPEND _protobuf_include_path -I ${ABS_PATH})
  12. endif()
  13. else()
  14. set(_protobuf_include_path -I ${cld3_src})
  15. endif()
  16. if (DEFINED PROTOBUF_IMPORT_DIRS)
  17. foreach (DIR ${PROTOBUF_IMPORT_DIRS})
  18. get_filename_component(ABS_PATH ${DIR} ABSOLUTE)
  19. list(FIND _protobuf_include_path ${ABS_PATH} _contains_already)
  20. if (${_contains_already} EQUAL -1)
  21. list(APPEND _protobuf_include_path -I ${ABS_PATH})
  22. endif()
  23. endforeach()
  24. endif()
  25. #
  26. get_filename_component(protobuf_name_we ${protobuf_name} NAME_WE)
  27. set(gen_timestamp ${gen_dst}/${protobuf_name}.timestamp)
  28. set(gen_files
  29. ${gen_dst}/${protobuf_name_we}.pb.cc
  30. ${gen_dst}/${protobuf_name_we}.pb.h
  31. )
  32. set(gen_src ${cld3_src}/${protobuf_name})
  33. add_custom_command(
  34. OUTPUT
  35. ${gen_timestamp}
  36. BYPRODUCTS
  37. ${gen_files}
  38. COMMAND
  39. ${executable}
  40. --cpp_out
  41. ${gen_dst}
  42. ${_protobuf_include_path}
  43. ${gen_src}
  44. COMMAND
  45. echo 1> ${gen_timestamp}
  46. COMMENT "Generating protobuf ${protobuf_name} (${target_name})"
  47. DEPENDS
  48. ${executable}
  49. ${gen_src}
  50. VERBATIM
  51. )
  52. generate_target(${target_name} ${protobuf_name} ${gen_timestamp} "${gen_files}" ${gen_dst})
  53. endfunction()