Skip to content

Commit

Permalink
Rename protcol -> api and separate api and protocol bits.
Browse files Browse the repository at this point in the history
  • Loading branch information
abeltrano committed Aug 3, 2024
1 parent c27495f commit feb2bb2
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 52 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ add_subdirectory(packaging)
add_subdirectory(src)

if (NOT NETREMOTE_EXCLUDE_API)
add_subdirectory(protocol)
add_subdirectory(api)
endif()

if (NOT NETREMOTE_EXCLUDE_TESTS)
Expand Down
26 changes: 26 additions & 0 deletions api/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

set(PROTO_DIR ${CMAKE_CURRENT_LIST_DIR}/protos)

# List of all protocol buffer files defining the API.
set(PROTO_FILES
${PROTO_DIR}/NetRemoteDataStream.proto
${PROTO_DIR}/NetRemoteDataStreamingService.proto
${PROTO_DIR}/NetRemoteNetwork.proto
${PROTO_DIR}/NetRemoteService.proto
${PROTO_DIR}/NetRemoteWifi.proto
${PROTO_DIR}/Network8021x.proto
${PROTO_DIR}/NetworkCore.proto
${PROTO_DIR}/WifiCore.proto
)

# Install the .proto files for consumers that wish to build them themselves.
install(
FILES
${PROTO_FILES}
DESTINATION "${NETREMOTE_DIR_INSTALL_PUBLIC_HEADER_BASE}/api"
)

# Include the API bindings (protocol) if they are not excluded.
if (NOT NETREMOTE_EXCLUDE_API_BINDINGS)
add_subdirectory(protocol)
endif()
83 changes: 32 additions & 51 deletions protocol/CMakeLists.txt → api/protocol/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,35 +1,9 @@

set(NETREMOTE_PROTOCOL_PUBLIC_INCLUDE ${CMAKE_CURRENT_LIST_DIR}/include)

set(NETREMOTE_PROTOCOL_PUBLIC_INCLUDE_SUFFIX microsoft/net/remote/protocol)
set(NETREMOTE_PROTOCOL_PUBLIC_INCLUDE_PREFIX ${NETREMOTE_PROTOCOL_PUBLIC_INCLUDE}/${NETREMOTE_PROTOCOL_PUBLIC_INCLUDE_SUFFIX})

set(NETREMOTE_API_PUBLIC_INCLUDE_SUFFIX microsoft/net/remote/api)
set(NETREMOTE_API_PUBLIC_INCLUDE_PREFIX ${NETREMOTE_PROTOCOL_PUBLIC_INCLUDE}/${NETREMOTE_API_PUBLIC_INCLUDE_SUFFIX})

set(PROTO_DIR ${NETREMOTE_API_PUBLIC_INCLUDE_PREFIX})
set(PROTO_DIR_BINARY ${CMAKE_CURRENT_BINARY_DIR}/${NETREMOTE_API_PUBLIC_INCLUDE_SUFFIX})

set(PROTO_FILES
${PROTO_DIR}/NetRemoteDataStream.proto
${PROTO_DIR}/NetRemoteDataStreamingService.proto
${PROTO_DIR}/NetRemoteNetwork.proto
${PROTO_DIR}/NetRemoteService.proto
${PROTO_DIR}/NetRemoteWifi.proto
${PROTO_DIR}/Network8021x.proto
${PROTO_DIR}/NetworkCore.proto
${PROTO_DIR}/WifiCore.proto
)

add_library(${PROJECT_NAME}-api INTERFACE "")
target_sources(${PROJECT_NAME}-api
PUBLIC
FILE_SET HEADERS
BASE_DIRS
${NETREMOTE_PROTOCOL_PUBLIC_INCLUDE}
FILES
${NETREMOTE_PROTOCOL_PUBLIC_INCLUDE_PREFIX}/NetRemoteProtocol.hxx
)
set(PROTO_DIR_BINARY ${CMAKE_CURRENT_BINARY_DIR}/${NETREMOTE_PROTOCOL_PUBLIC_INCLUDE_SUFFIX})

# Create a list of the generated headers. The below code isn't used because
# we've encountered intermittent errors when building with external vcpkg (eg.
Expand Down Expand Up @@ -63,7 +37,9 @@ set(PROTO_HEADERS_GENERATED_GRPC
${PROTO_DIR_BINARY}/WifiCore.grpc.pb.h
)

# Define a static library containing pre-built protocol buffer and gRPC bindings.
add_library(${PROJECT_NAME}-protocol STATIC "")
add_library(${PROJECT_NAME}-api-bindings ALIAS ${PROJECT_NAME}-protocol)

target_sources(${PROJECT_NAME}-protocol
PRIVATE
Expand All @@ -86,13 +62,15 @@ target_link_libraries(${PROJECT_NAME}-protocol
gRPC::grpc++_unsecure
)

# Generate C++ headers and sources (<source>.pb.[h|cc]) of the protocol buffer data types.
protobuf_generate(TARGET ${PROJECT_NAME}-protocol
LANGUAGE cpp
IMPORT_DIRS ${PROTO_DIR}
PROTOC_OUT_DIR ${PROTO_DIR_BINARY}
PROTOC_OUT_FILES ${PROTO_FILES}
)

# Generate C++ headers and sources with gRPC support (<source>.grpc.pb.[h|cc]) of the protocol buffer data types.
protobuf_generate(TARGET ${PROJECT_NAME}-protocol
LANGUAGE grpc
GENERATE_EXTENSIONS .grpc.pb.h .grpc.pb.cc
Expand All @@ -101,28 +79,31 @@ protobuf_generate(TARGET ${PROJECT_NAME}-protocol
PROTOC_OUT_DIR ${PROTO_DIR_BINARY}
)

if (NOT NETREMOTE_EXCLUDE_API)
install(
FILES
${PROTO_FILES}
DESTINATION "${NETREMOTE_DIR_INSTALL_PUBLIC_HEADER_BASE}/api"
)
install(
TARGETS ${PROJECT_NAME}-api
EXPORT ${PROJECT_NAME}
COMPONENT dev
FILE_SET HEADERS
PUBLIC_HEADER DESTINATION "${NETREMOTE_DIR_INSTALL_PUBLIC_HEADER_BASE}"
)
endif()
install(
TARGETS ${PROJECT_NAME}-protocol
EXPORT ${PROJECT_NAME}
COMPONENT dev
FILE_SET HEADERS
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION "${NETREMOTE_DIR_INSTALL_PUBLIC_HEADER_BASE}"
)

# Define a header-only (interface) library containing public protocol information.
add_library(${PROJECT_NAME}-api INTERFACE "")

if (NOT NETREMOTE_EXCLUDE_API_BINDINGS)
install(
TARGETS ${PROJECT_NAME}-protocol
EXPORT ${PROJECT_NAME}
COMPONENT dev
FILE_SET HEADERS
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION "${NETREMOTE_DIR_INSTALL_PUBLIC_HEADER_BASE}"
)
endif()
target_sources(${PROJECT_NAME}-api
PUBLIC
FILE_SET HEADERS
BASE_DIRS
${NETREMOTE_PROTOCOL_PUBLIC_INCLUDE}
FILES
${NETREMOTE_PROTOCOL_PUBLIC_INCLUDE_PREFIX}/NetRemoteProtocol.hxx
)

install(
TARGETS ${PROJECT_NAME}-api
EXPORT ${PROJECT_NAME}
COMPONENT dev
FILE_SET HEADERS
PUBLIC_HEADER DESTINATION "${NETREMOTE_DIR_INSTALL_PUBLIC_HEADER_BASE}"
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit feb2bb2

Please sign in to comment.