Protobuf.cmake 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # Author:
  2. # Sven Czarnian <devel@svcz.de>
  3. # License:
  4. # Closed Source
  5. # Brief:
  6. # Defines the protobuf functions
  7. # Brief:
  8. # Proto-files are compiled into C++ files
  9. # Parameters:
  10. # PROTO_FILES - The proto-files with the message description
  11. # SOURCE_FILES - Contains the filenames and paths of the generated files
  12. FUNCTION(ProtobufCompile PROTO_FILES SOURCE_FILES)
  13. SET(GENERATED_FILES "")
  14. FOREACH (PROTO ${PROTO_FILES})
  15. # get the relevant information to configure the protoc-run
  16. GET_FILENAME_COMPONENT(FILENAME ${PROTO} NAME_WLE)
  17. GET_FILENAME_COMPONENT(DIRECTORY ${PROTO} DIRECTORY)
  18. # define the output files
  19. SET(CPP_FILE ${CMAKE_CURRENT_BINARY_DIR}/protobuf/${FILENAME}.pb.cc)
  20. SET(HPP_FILE ${CMAKE_CURRENT_BINARY_DIR}/protobuf/${FILENAME}.pb.h)
  21. # create the protoc-directory
  22. FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/protobuf)
  23. # define the protoc-command
  24. ADD_CUSTOM_COMMAND(
  25. OUTPUT ${CPP_FILE} ${HPP_FILE}
  26. DEPENDS protobuf
  27. COMMAND ${CMAKE_SOURCE_DIR}/external/bin/protoc.exe
  28. ARGS -I=${DIRECTORY} --cpp_out=${CMAKE_CURRENT_BINARY_DIR}/protobuf ${PROTO}
  29. WORKING_DIRECTORY "${CMAKE_INSTALL_PREFIX}/bin"
  30. COMMENT "Creating C++-sources for ${PROTO}"
  31. )
  32. # disable warnings
  33. IF (MSVC)
  34. SET_SOURCE_FILES_PROPERTIES(${CPP_FILE} PROPERTIES COMPILE_FLAGS "/wd4127 /wd5054 /wd4125 /wd4267")
  35. SET_SOURCE_FILES_PROPERTIES(${HPP_FILE} PROPERTIES COMPILE_FLAGS "/wd4127 /wd5054 /wd4125 /wd4267")
  36. ENDIF ()
  37. # add the generated files
  38. LIST(APPEND GENERATED_FILES ${CPP_FILE})
  39. LIST(APPEND GENERATED_FILES ${HPP_FILE})
  40. ENDFOREACH ()
  41. # set the output variables
  42. SET(${SOURCE_FILES} ${GENERATED_FILES} PARENT_SCOPE)
  43. ENDFUNCTION()