Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vcpkg target to provide API source only #332

Merged
merged 4 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ include(vcpkg)
option(NETREMOTE_VCPKG_BUILD_FOR_PORT "Enable building the project via a vcpkg port" OFF)

# Add options for vcpkg port file features.
option(NETREMOTE_EXCLUDE_PROTOCOL "Disable building the protocol" OFF)
option(NETREMOTE_EXCLUDE_API "Disable providing the protocol buffers + gRPC API source files" OFF)
option(NETREMOTE_EXCLUDE_API_BINDINGS "Disable building the API protocol buffers + gRPC bindings" OFF)
option(NETREMOTE_EXCLUDE_SERVER "Disable building the server" OFF)
option(NETREMOTE_EXCLUDE_TOOLS "Disable building the tools" OFF)
option(NETREMOTE_EXCLUDE_TESTS "Disable building the tests" OFF)
Expand Down Expand Up @@ -100,8 +101,8 @@ add_subdirectory(config)
add_subdirectory(packaging)
add_subdirectory(src)

if (NOT NETREMOTE_EXCLUDE_PROTOCOL)
add_subdirectory(protocol)
if (NOT NETREMOTE_EXCLUDE_API)
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()
37 changes: 25 additions & 12 deletions protocol/CMakeLists.txt → api/protocol/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,7 @@ 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(PROTO_DIR ${CMAKE_CURRENT_SOURCE_DIR}/protos)
set(PROTO_DIR_BINARY ${CMAKE_CURRENT_BINARY_DIR}/${NETREMOTE_PROTOCOL_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
)

# 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 @@ -48,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 @@ -71,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 @@ -92,5 +85,25 @@ install(
COMPONENT dev
FILE_SET HEADERS
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION "${NETREMOTE_DIR_INSTALL_PUBLIC_HEADER_BASE}/${PROTO_DIR_BINARY_SUFFIX}"
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 "")

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.
3 changes: 2 additions & 1 deletion packaging/vcpkg/ports/netremote/portfile.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ vcpkg_find_acquire_program(
vcpkg_check_features(
OUT_FEATURE_OPTIONS FEATURE_OPTIONS
INVERTED_FEATURES
protocol NETREMOTE_EXCLUDE_PROTOCOL
api NETREMOTE_EXCLUDE_API
api-bindings NETREMOTE_EXCLUDE_API_BINDINGS
server NETREMOTE_EXCLUDE_SERVER
tests NETREMOTE_EXCLUDE_TESTS
tools NETREMOTE_EXCLUDE_TOOLS
Expand Down
5 changes: 0 additions & 5 deletions src/windows/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
# Make public version of wil available.
set(WIL_BUILD_TESTS OFF CACHE INTERNAL "Turn off wil tests")
set(WIL_BUILD_PACKAGING OFF CACHE INTERNAL "Turn off wil packaging")

find_package(wil CONFIG REQUIRED)

# Add Windows-specific global compile definitions.
add_compile_definitions(
Expand Down
83 changes: 55 additions & 28 deletions vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,14 @@
"name": "netremote",
"version-string": "0.4.1",
"dependencies": [
{
"name": "sdbus-cpp",
"platform": "linux"
},
{
"name": "libsystemd",
"platform": "linux"
},
{
"name": "vcpkg-cmake",
"host": true
},
{
"name": "vcpkg-cmake-config",
"host": true
},
{
"name": "wil",
"platform": "windows"
},
"catch2",
"cli11",
"grpc",
"magic-enum",
"plog",
"protobuf",
"nlohmann-json"
}
],
"overrides": [
{
Expand All @@ -43,34 +24,80 @@
]
},
"features": {
"protocol": {
"description": "Enable building the client protocol",
"api": {
"description": "Provide the API protocol buffers + gRPC .proto source files"
},
"api-bindings": {
"description": "Provide the API protocol buffers + gRPC library bindings",
"dependencies": [
"grpc",
"protobuf"
"protobuf",
{
"name": "netremote",
"features": [
"api"
]
}
]
},
"server":{
"description": "Enable building the server",
"description": "Provide the server binary",
"dependencies": [
"netremote"
{
"name": "netremote",
"features": [
"api-bindings"
]
},
{
"name": "sdbus-cpp",
"platform": "linux"
},
{
"name": "libsystemd",
"platform": "linux"
},
"cli11",
"magic-enum",
"plog",
"nlohmann-json"
]
},
"tests":{
"description": "Enable building the tests",
"dependencies": [
"netremote"
"catch2",
"magic-enum",
"nlohmann-json",
"plog",
{
"name": "netremote",
"features": [
"api-bindings",
"server"
]
}
]
},
"tools":{
"description": "Enable building the tools",
"dependencies": [
"netremote"
{
"name": "netremote",
"features": [
"api-bindings",
"server"
]
}
]
}
},
"default-features": [
"protocol"
"api",
"api-bindings",
"server",
"tests",
"tools"
],
"builtin-baseline": "9224b3bbd8df24999d85720b1d005dd6f969ade0"
}