CMakeLists.txt 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Append nanopb path to CMAKE_MODULE_PATH for finding the nanopb package
  2. cmake_minimum_required(VERSION 3.16)
  3. include(../../tools/protoc_utils/protobuf_utils.cmake)
  4. configure_env()
  5. file(GLOB_RECURSE PROTO_FILES *.proto)
  6. # set(NANOPB_OPTIONS "-I${CMAKE_CURRENT_SOURCE_DIR}")
  7. nanopb_generate_cpp(PROTO_SRCS PROTO_HDRS RELPATH ${CMAKE_CURRENT_SOURCE_DIR} ${PROTO_FILES})
  8. # Create a custom target to generate the proto files
  9. set_source_files_properties(${PROTO_SRCS} ${PROTO_HDRS} PROPERTIES GENERATED TRUE)
  10. add_custom_target(generate_system_proto ALL DEPENDS ${PROTO_SRCS} ${PROTO_HDRS})
  11. add_library(platform_protobuf STATIC ${PROTO_SRCS} ${PROTO_HDRS})
  12. add_dependencies(platform_protobuf generate_system_proto)
  13. # target_compile_definitions(platform_protobuf PUBLIC PB_ENABLE_MALLOC PB_FIELD_32BIT)
  14. # target_compile_definitions(__idf_tools PUBLIC PB_ENABLE_MALLOC PB_FIELD_32BIT)
  15. target_include_directories(platform_protobuf PUBLIC "include" ${CMAKE_CURRENT_BINARY_DIR} ${NANOPB_INCLUDE_DIRS} ${EXTRA_INCLUDES})
  16. target_link_libraries(__idf_platform_config PRIVATE platform_protobuf)
  17. target_include_directories(__idf_platform_config PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/proto)
  18. # Add nanopb includes
  19. set(CMAKE_INCLUDE_GLOBAL_DIRS ON)
  20. # include_directories("${CMAKE_CURRENT_BINARY_DIR}" "${NANOPB_INCLUDE_DIRS}")
  21. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I")
  22. idf_build_set_property(INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR} APPEND)
  23. foreach(PATH_ENTRY ${NANOPB_INCLUDE_DIRS})
  24. idf_build_set_property(INCLUDE_DIRECTORIES ${PATH_ENTRY} APPEND)
  25. endforeach()
  26. set(NANOPB_GENERATOR_SOURCE_DIR "${NANOPB_GENERATOR_SOURCE_DIR}" PARENT_SCOPE)
  27. set(PROTO_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/proto;${NANOPB_GENERATOR_SOURCE_DIR}/proto" PARENT_SCOPE)
  28. set(PROTO_FILES "${PROTO_FILES}" PARENT_SCOPE)
  29. set(PROTO_SRCS "${PROTO_SRCS}" PARENT_SCOPE)
  30. set(PROTO_HDRS "${PROTO_HDRS}" PARENT_SCOPE)