CompileProto.cmake 1.5 KB

12345678910111213141516171819202122232425262728293031323334
  1. # Licensed to the Apache Software Foundation (ASF) under one or more
  2. # contributor license agreements. See the NOTICE file distributed with
  3. # this work for additional information regarding copyright ownership.
  4. # The ASF licenses this file to You under the Apache License, Version 2.0
  5. # (the "License"); you may not use this file except in compliance with
  6. # the License. You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. function(compile_proto OUT_HDRS OUT_SRCS DESTDIR HDR_OUTPUT_DIR PROTO_DIR PROTO_FILES)
  16. foreach(P ${PROTO_FILES})
  17. string(REPLACE .proto .pb.h HDR ${P})
  18. set(HDR_RELATIVE ${HDR})
  19. set(HDR ${DESTDIR}/${HDR})
  20. string(REPLACE .proto .pb.cc SRC ${P})
  21. set(SRC ${DESTDIR}/${SRC})
  22. list(APPEND HDRS ${HDR})
  23. list(APPEND SRCS ${SRC})
  24. add_custom_command(
  25. OUTPUT ${HDR} ${SRC}
  26. COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} ${PROTOC_FLAGS} -I${PROTO_DIR} --cpp_out=${DESTDIR} ${PROTO_DIR}/${P}
  27. COMMAND ${CMAKE_COMMAND} -E copy ${HDR} ${HDR_OUTPUT_DIR}/${HDR_RELATIVE}
  28. DEPENDS ${PROTO_DIR}/${P}
  29. )
  30. endforeach()
  31. set(${OUT_HDRS} ${HDRS} PARENT_SCOPE)
  32. set(${OUT_SRCS} ${SRCS} PARENT_SCOPE)
  33. endfunction()