From 553c35437df29e4239362819a195b015a49b0d8b Mon Sep 17 00:00:00 2001 From: Dmitry Sazonov Date: Mon, 25 Mar 2019 16:11:03 +0300 Subject: [PATCH] CMake build scripts for cpp sdk and cpp-simple example --- build/build-image/Dockerfile | 5 + cloudbuild.yaml | 10 +- examples/cpp-simple/CMakeLists.txt | 50 ++++ sdks/cpp/CMakeLists.txt | 247 ++++++++++++++++++ sdks/cpp/Makefile | 76 ++---- sdks/cpp/build_scripts/build.sh | 21 ++ .../build_scripts/msvs_2017_x64_release.bat | 22 ++ sdks/cpp/build_scripts/nmake_release.bat | 22 ++ sdks/cpp/cmake/Fetch_gRPC.cmake | 54 ++++ sdks/cpp/cmake/agonesConfig.cmake.in | 10 + sdks/cpp/cmake/agones_global.h.in | 24 ++ sdks/cpp/{ => include/agones}/sdk.grpc.pb.h | 15 ++ sdks/cpp/include/agones/sdk.h | 73 ++++++ sdks/cpp/{ => include/agones}/sdk.pb.h | 62 ++--- .../{ => include}/google/api/annotations.pb.h | 8 +- sdks/cpp/{ => include}/google/api/http.pb.h | 24 +- sdks/cpp/sdk.h | 64 ----- sdks/cpp/sources.cmake | 27 ++ sdks/cpp/{ => src/agones}/sdk.cc | 48 ++-- sdks/cpp/{ => src/agones}/sdk.grpc.pb.cc | 0 sdks/cpp/{ => src/agones}/sdk.pb.cc | 20 +- .../api => src/google}/annotations.pb.cc | 0 .../cpp/{google/api => src/google}/http.pb.cc | 6 +- .../content/en/docs/Guides/Client SDKs/cpp.md | 61 ++++- 24 files changed, 739 insertions(+), 210 deletions(-) create mode 100644 examples/cpp-simple/CMakeLists.txt create mode 100644 sdks/cpp/CMakeLists.txt create mode 100644 sdks/cpp/build_scripts/build.sh create mode 100644 sdks/cpp/build_scripts/msvs_2017_x64_release.bat create mode 100644 sdks/cpp/build_scripts/nmake_release.bat create mode 100644 sdks/cpp/cmake/Fetch_gRPC.cmake create mode 100644 sdks/cpp/cmake/agonesConfig.cmake.in create mode 100644 sdks/cpp/cmake/agones_global.h.in rename sdks/cpp/{ => include/agones}/sdk.grpc.pb.h (98%) create mode 100644 sdks/cpp/include/agones/sdk.h rename sdks/cpp/{ => include/agones}/sdk.pb.h (95%) rename sdks/cpp/{ => include}/google/api/annotations.pb.h (94%) rename sdks/cpp/{ => include}/google/api/http.pb.h (98%) delete mode 100644 sdks/cpp/sdk.h create mode 100644 sdks/cpp/sources.cmake rename sdks/cpp/{ => src/agones}/sdk.cc (69%) rename sdks/cpp/{ => src/agones}/sdk.grpc.pb.cc (100%) rename sdks/cpp/{ => src/agones}/sdk.pb.cc (99%) rename sdks/cpp/{google/api => src/google}/annotations.pb.cc (100%) rename sdks/cpp/{google/api => src/google}/http.pb.cc (99%) diff --git a/build/build-image/Dockerfile b/build/build-image/Dockerfile index 16b05890aa..73358c9fb0 100644 --- a/build/build-image/Dockerfile +++ b/build/build-image/Dockerfile @@ -138,3 +138,8 @@ RUN echo "export EDITOR=nano" >> /root/.bashrc # code generation scripts COPY *.sh /root/ RUN chmod +x /root/*.sh + +RUN wget https://github.com/Kitware/CMake/releases/download/v3.14.0/cmake-3.14.0-Linux-x86_64.sh && mkdir /opt/cmake && \ + sh ./cmake-3.14.0-Linux-x86_64.sh --skip-license --prefix=/opt/cmake && export PATH=$PATH:/opt/cmake/bin + +WORKDIR /go \ No newline at end of file diff --git a/cloudbuild.yaml b/cloudbuild.yaml index 6c129dafbd..61d2cd42ea 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -131,14 +131,8 @@ steps: waitFor: - build - tests - dir: "sdks/cpp/bin" + dir: "sdks/cpp/.build" args: ['cp', '*.tar.gz', 'gs://agones-artifacts/cpp-sdk'] -- name: 'gcr.io/cloud-builders/gsutil' - waitFor: - - build - - tests - dir: "sdks/cpp/bin" - args: ['cp', '*.zip', 'gs://agones-artifacts/cpp-sdk'] - name: 'gcr.io/cloud-builders/gsutil' waitFor: - build @@ -151,4 +145,4 @@ timeout: "1h" images: ['gcr.io/$PROJECT_ID/agones-controller', 'gcr.io/$PROJECT_ID/agones-sdk', 'gcr.io/$PROJECT_ID/agones-ping'] logsBucket: "gs://agones-build-logs" options: - machineType: 'N1_HIGHCPU_8' + machineType: 'N1_HIGHCPU_8' \ No newline at end of file diff --git a/examples/cpp-simple/CMakeLists.txt b/examples/cpp-simple/CMakeLists.txt new file mode 100644 index 0000000000..044e81ee38 --- /dev/null +++ b/examples/cpp-simple/CMakeLists.txt @@ -0,0 +1,50 @@ +# Copyright 2019 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required (VERSION 3.13.0) + +project(cpp-simple CXX) + +# Settings +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED TRUE) +set(CMAKE_CXX_EXTENSIONS OFF) +set(CMAKE_INCLUDE_CURRENT_DIR ON) +set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON) +set_property(GLOBAL PROPERTY USE_FOLDERS ON) +set(CMAKE_DEBUG_POSTFIX "d") + +find_package(agones CONFIG REQUIRED) + +if(WIN32) + # Windows + add_definitions(-D_WIN32_WINNT=0x0600) + set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT cpp-simple) +elseif(APPLE) + # Mac OS +elseif(UNIX AND NOT APPLE) + # Linux +endif() + + +include_directories(${agones_INCLUDE_DIRS}) +set(SRC_FILES "server.cc") + +# Executable +add_executable(${PROJECT_NAME} ${SRC_FILES}) +target_link_libraries(${PROJECT_NAME} PUBLIC agones) + +if (MSVS) + target_compile_options(${PROJECT_NAME} PUBLIC /wd4101 /wd4146 /wd4251 /wd4661) +endif() \ No newline at end of file diff --git a/sdks/cpp/CMakeLists.txt b/sdks/cpp/CMakeLists.txt new file mode 100644 index 0000000000..65645a1eb0 --- /dev/null +++ b/sdks/cpp/CMakeLists.txt @@ -0,0 +1,247 @@ +# Copyright 2018 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required (VERSION 3.13.0) + +project(agones VERSION 0.9.0 HOMEPAGE_URL https://github.com/GoogleCloudPlatform/agones LANGUAGES C CXX) + +# Build options +option(AGONES_BUILD_SHARED "Build Agones C++ SDK as dynamic library" OFF) +option(AGONES_FORCE_GRPC_VERSION "Build Agones C++ SDK only with officially supported gRPC version" ON) +option(AGONES_CREATE_PACKAGE "Generate CMake installation step and package files for Agones C++ SDK" ON) + +# Currently we doesn't support build time generation of proto/grpc files, +# so gRPC version should be strict +set(AGONES_FORCE_GRPC_VERSION ON) + +# Settings +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") + +set_property(GLOBAL PROPERTY USE_FOLDERS ON) + +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED TRUE) +set(CMAKE_CXX_EXTENSIONS OFF) +set(CMAKE_INCLUDE_CURRENT_DIR ON) +set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON) +set(CMAKE_DEBUG_POSTFIX "d") +set(AGONES_GRPC_VERSION "1.16.1") + +if (AGONES_BUILD_SHARED) + add_compile_definitions( + PROTOBUF_USE_DLLS + LIBPROTOBUF_EXPORTS + ) +endif() + +# --> Connecting gRPC +macro(validate_path IN_PATH OUT_RESULT) + set(${OUT_RESULT} FALSE) + if (NOT IS_DIRECTORY ${${IN_PATH}}) + file(TO_CMAKE_PATH "$ENV{${IN_PATH}}" ${IN_PATH}) + else() + file(TO_CMAKE_PATH "${${IN_PATH}}" ${IN_PATH}) + endif() + if (IS_DIRECTORY ${${IN_PATH}}) + set(${OUT_RESULT} TRUE) + endif() +endmacro(validate_path) + +set(GRPC_IS_INSTALLED FALSE) +set(GRPC_PATH_FOUND FALSE) +validate_path(grpc_SOURCE_DIR GRPC_PATH_FOUND) +if (GRPC_PATH_FOUND) + # Checking if we use gRPC package or gRPC source folder + # Usually it should be findXXX.cmake or xxxConfig.cmake files, but for gRPC we need to check gRPCTargets.cmake too + if (EXISTS ${grpc_SOURCE_DIR}/gRPCTargets.cmake) + set(GRPC_IS_INSTALLED TRUE) + find_package(gRPC CONFIG REQUIRED) + endif() +else() + # Download gRPC, if necessary + include(Fetch_gRPC) +endif() + +add_subdirectory(${grpc_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/grpc EXCLUDE_FROM_ALL) + +# Check gRPC version +get_directory_property(GRPC_VERSION DIRECTORY ${grpc_SOURCE_DIR} DEFINITION PACKAGE_VERSION) +if (NOT GRPC_VERSION STREQUAL AGONES_GRPC_VERSION) + set(GRPC_VERSION_SEVERITY WARNING) + if (AGONES_FORCE_GRPC_VERSION) + set(GRPC_VERSION_SEVERITY FATAL_ERROR) + endif() + message(${GRPC_VERSION_SEVERITY} "Agones SDK currently supports only \"${AGONES_GRPC_VERSION}\" version. Building with \"${GRPC_VERSION}\" may cause unexpected problems.") +endif() + +# Configuring +set(AGONES_DEPENDENCIES libprotobuf grpc++_unsecure) +set(AGONES_GRPC_TARGETS address_sorting c-ares gpr grpc_unsecure grpc++_unsecure libprotobuf zlibstatic) +foreach(THIRDPARTY_TARGET ${AGONES_GRPC_TARGETS}) + set_property(TARGET ${THIRDPARTY_TARGET} PROPERTY FOLDER third_party) +endforeach() +# <-- Connecting gRPC + +# Platform specific stuff +if (WIN32) + # Windows + add_compile_definitions( + _WIN32_WINNT=0x0600 + WINDOWS + ) +elseif (APPLE) + # Mac OS +elseif (UNIX AND NOT APPLE) + # Linux +endif() + +if (MSVS) + set(OPT_DISABLE_COMPILER_WARNINGS /wd4101 /wd4146 /wd4251 /wd4661) + target_compile_options(libprotobuf PUBLIC ${OPT_DISABLE_COMPILER_WARNINGS}) + target_compile_options(${PROJECT_NAME} PUBLIC ${OPT_DISABLE_COMPILER_WARNINGS}) +else() + set(OPT_DISABLE_COMPILER_WARNINGS -wd4101 -wd4146 -wd4251 -wd4661) +endif() + +# Agones SDK +include(./sources.cmake) + +set(AGONES_BUILD_TYPE STATIC) +if (AGONES_BUILD_SHARED) + set(AGONES_BUILD_TYPE SHARED) +endif() + +add_library(${PROJECT_NAME} ${AGONES_BUILD_TYPE} ${ALL_FILES}) +target_link_libraries(${PROJECT_NAME} PRIVATE ${AGONES_DEPENDENCIES}) + +target_include_directories(${PROJECT_NAME} PUBLIC + $ + $ + $ +) + +# Fix compiler warnings +# https://github.com/protocolbuffers/protobuf/blob/master/cmake/README.md#notes-on-compiler-warnings + +# Export header +include(GenerateExportHeader) +set(EXPORT_HEADER "${PROJECT_NAME}_export.h") +generate_export_header(${PROJECT_NAME} EXPORT_FILE_NAME ${EXPORT_HEADER} DEFINE_NO_DEPRECATED) + +# Global header +set(GLOBAL_HEADER "${PROJECT_NAME}_global.h") +set(GLOBAL_CONFIG_CONTENT "") +if (AGONES_BUILD_SHARED) + set(GLOBAL_CONFIG_CONTENT "\ +// Dynamic linkage require macro for protobuf\n\ +#ifndef PROTOBUF_USE_DLLS\n\ +#define PROTOBUF_USE_DLLS\n\ +#endif\n" + ) +endif() +configure_file(cmake/${GLOBAL_HEADER}.in ${GLOBAL_HEADER} @ONLY) + +if(MSVC) + add_definitions(/FI"${GLOBAL_HEADER}") +else() + # GCC or Clang + add_definitions(-include ${GLOBAL_HEADER}) +endif() + +# CMake package generation +include(CMakePackageConfigHelpers) + +if (AGONES_CREATE_PACKAGE) + set(_INCLUDE_DIRS "include") + set(_CMAKE_CONFIG_DESTINATION "cmake") + + # If gRPC is built from source (not from package), then we need to redistribute gRPC and it dependencies + if (NOT GRPC_IS_INSTALLED) + # gRPC headers + install(DIRECTORY ${grpc_SOURCE_DIR}/include/ DESTINATION ${_INCLUDE_DIRS}) + # Protobuf headers + install(DIRECTORY ${grpc_SOURCE_DIR}/third_party/protobuf/src/ DESTINATION ${_INCLUDE_DIRS} FILES_MATCHING PATTERN "*.h") + # gRPC and it dependencies + if (NOT AGONES_BUILD_SHARED) + install(TARGETS ${AGONES_GRPC_TARGETS} EXPORT gRPC + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + RUNTIME DESTINATION bin + INCLUDES DESTINATION ${_INCLUDE_DIRS} + ) + endif() + endif() + + # Config for find_package + configure_package_config_file( + cmake/${PROJECT_NAME}Config.cmake.in + ${PROJECT_NAME}Config.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX}/${_CMAKE_CONFIG_DESTINATION} + PATH_VARS _INCLUDE_DIRS PROJECT_VERSION + NO_SET_AND_CHECK_MACRO + ) + # Build artifacts + install(TARGETS ${PROJECT_NAME} ${AGONES_GRPC_TARGETS} EXPORT ${PROJECT_NAME} + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + RUNTIME DESTINATION bin + INCLUDES DESTINATION ${_INCLUDE_DIRS} + ) + install(EXPORT ${PROJECT_NAME} DESTINATION ${_CMAKE_CONFIG_DESTINATION} FILE ${PROJECT_NAME}Targets.cmake) + # Package config + install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake + DESTINATION ${_CMAKE_CONFIG_DESTINATION} + ) + # Agones header files + install( + FILES ${HEADER_FILES} "${CMAKE_CURRENT_BINARY_DIR}/${EXPORT_HEADER}" "${CMAKE_CURRENT_BINARY_DIR}/${GLOBAL_HEADER}" + DESTINATION include/${PROJECT_NAME} + ) + # Google header files + install( + FILES ${GOOGLE_HEADER_FILES} + DESTINATION include/google/api + ) + # PDB file + if (AGONES_BUILD_SHARED) + install(FILES $ DESTINATION bin CONFIGURATIONS Debug OPTIONAL) + install(FILES $ DESTINATION bin CONFIGURATIONS Debug OPTIONAL) + endif() + + unset(_INCLUDE_DIRS) + unset(_CMAKE_CONFIG_DESTINATION) +else() # Package is created with absolute pathes in build folder + # Use agones and thirdparty include directories + set(_INCLUDE_DIRS + "${CMAKE_CURRENT_LIST_DIR}/include" + "${grpc_SOURCE_DIR}/include" + "${grpc_SOURCE_DIR}/third_party/protobuf/src" + ) + set(_CMAKE_CONFIG_DESTINATION "${CMAKE_BINARY_DIR}") + + configure_package_config_file( + cmake/${PROJECT_NAME}Config.cmake.in + "${CMAKE_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + INSTALL_DESTINATION ${_CMAKE_CONFIG_DESTINATION} + PATH_VARS _INCLUDE_DIRS PROJECT_VERSION + NO_SET_AND_CHECK_MACRO + ) + export(TARGETS ${PROJECT_NAME} ${AGONES_GRPC_TARGETS} FILE "${CMAKE_BINARY_DIR}/${PROJECT_NAME}Targets.cmake") + # Register SDK local artifacts in system https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html#package-registry-example + #export(PACKAGE ${PROJECT_NAME}) + + unset(_INCLUDE_DIRS) + unset(_CMAKE_CONFIG_DESTINATION) +endif(AGONES_CREATE_PACKAGE) diff --git a/sdks/cpp/Makefile b/sdks/cpp/Makefile index 928dbc32fe..62f399cf01 100644 --- a/sdks/cpp/Makefile +++ b/sdks/cpp/Makefile @@ -1,4 +1,4 @@ -# Copyright 2017 Google Inc. All Rights Reserved. +# Copyright 2019 Google Inc. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,66 +16,24 @@ # Makefile for testing and building the C++ SDK # -# __ __ _ _ _ -# \ \ / /_ _ _ __(_) __ _| |__ | | ___ ___ -# \ \ / / _` | '__| |/ _` | '_ \| |/ _ \ __| -# \ V / (_| | | | | (_| | |_) | | __\__ \ -# \_/ \__,_|_| |_|\__,_|_.__/|_|\___|___/ -# - -CXX = g++ -CPPFLAGS += -I/usr/local/include -I$(build_path) -pthread -fPIC -CXXFLAGS += -std=c++11 -LDFLAGS += -L/usr/local/lib -lgrpc++_unsecure -lgrpc -lprotobuf -lpthread -ldl - -# Directory that this Makefile is in. mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST))) -build_path := $(dir $(mkfile_path)) - -# _____ _ -# |_ _|_ _ _ __ __ _ ___| |_ ___ -# | |/ _` | '__/ _` |/ _ \ __/ __| -# | | (_| | | | (_| | __/ |_\__ \ -# |_|\__,_|_| \__, |\___|\__|___/ -# |___/ - -# build the library -build: ensure-bin libagonessdk - -# install into /usr/local in the appropriate places -# make sure to install protoc and grpc from source first to build dependencies +source_path := $(dir $(mkfile_path)) +build_path := $(source_path)/.build +package_path := $(build_path)/.install +install_path := /opt/local + +build: + -mkdir $(build_path) + apt-get install + cd $(build_path) && /opt/cmake/bin/cmake .. -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles" -Wno-dev -DCMAKE_INSTALL_PREFIX=.install + cd $(build_path) && /opt/cmake/bin/cmake --build . --target install + install: - cp $(build_path)/bin/libagonessdk.* /usr/local/lib - -mkdir -p /usr/local/include/agones - cp $(build_path)/*.h /usr/local/include/agones/ - -mkdir -p /usr/local/include/google/api - cp -r $(build_path)/google/api/*.h /usr/local/include/google/api/ - ldconfig - -# make the .so build -libagonessdk: google/api/annotations.pb.o google/api/http.pb.o sdk.grpc.pb.o sdk.pb.o sdk.o - $(CXX) $^ $(LDFLAGS) -shared -o $(build_path)/bin/$@.so - ar rcs $(build_path)/bin/$@.a $^ - -# make sure the bin directory exists -ensure-bin: - -mkdir $(build_path)/bin - -# build dev and runtime tarballs + cp -r $(build_path)/.install $(install_path) + archive: VERSION = "dev" archive: - -rm $(build_path)/bin/agonessdk-$(VERSION)-src.zip - -rm $(build_path)/bin/agonessdk-$(VERSION)-dev-linux-arch_64.tar.gz - -rm $(build_path)/bin/agonessdk-$(VERSION)-runtime-linux-arch_64.tar.gz - cp /usr/local/lib/libgrpc.so.6 $(build_path)/bin/ - cp /usr/local/lib/libprotobuf.so.* $(build_path)/bin/ - cp /usr/local/lib/libagonessdk.so $(build_path)/bin/ - cp /usr/local/lib/libgpr.so.6 $(build_path)/bin/ - cp /usr/local/lib/libgrpc_unsecure.so.6 $(build_path)/bin/ - cd $(build_path)/bin && tar cvf agonessdk-$(VERSION)-runtime-linux-arch_64.tar.gz --exclude='*.zip' --exclude='*.tar.gz' * - cd /usr/local && tar cvf $(build_path)/bin/agonessdk-$(VERSION)-dev-linux-arch_64.tar.gz lib include - cd $(build_path) && zip ./bin/agonessdk-$(VERSION)-src.zip Makefile *.md *.cc *.h - + cd $(package_path) && tar cvf $(build_path)/agonessdk-$(VERSION)-linux-arch_64.tar.gz * + clean: - -rm -r $(build_path)/bin - -find -name '*.o' -delete + -rm -r $(build_path) \ No newline at end of file diff --git a/sdks/cpp/build_scripts/build.sh b/sdks/cpp/build_scripts/build.sh new file mode 100644 index 0000000000..a622eddfd4 --- /dev/null +++ b/sdks/cpp/build_scripts/build.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# Copyright 2018 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http:#www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cd .. +mkdir -p .build +cd .build +cmake .. -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles" -Wno-dev -DCMAKE_INSTALL_PREFIX=./install +cmake --build . --target install diff --git a/sdks/cpp/build_scripts/msvs_2017_x64_release.bat b/sdks/cpp/build_scripts/msvs_2017_x64_release.bat new file mode 100644 index 0000000000..704ae77a16 --- /dev/null +++ b/sdks/cpp/build_scripts/msvs_2017_x64_release.bat @@ -0,0 +1,22 @@ +@echo off +REM Copyright 2018 Google Inc. All Rights Reserved. +REM +REM Licensed under the Apache License, Version 2.0 (the "License"); +REM you may not use this file except in compliance with the License. +REM You may obtain a copy of the License at +REM +REM http://www.apache.org/licenses/LICENSE-2.0 +REM +REM Unless required by applicable law or agreed to in writing, software +REM distributed under the License is distributed on an "AS IS" BASIS, +REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +REM See the License for the specific language governing permissions and +REM limitations under the License. + +pushd .. +if not exist ".build" md ".build" +pushd ".build" +cmake .. -G "Visual Studio 15 2017 Win64" -DCMAKE_INSTALL_PREFIX=./install -Wno-dev +cmake --build . --config Release --target INSTALL +popd +popd diff --git a/sdks/cpp/build_scripts/nmake_release.bat b/sdks/cpp/build_scripts/nmake_release.bat new file mode 100644 index 0000000000..9b3a069280 --- /dev/null +++ b/sdks/cpp/build_scripts/nmake_release.bat @@ -0,0 +1,22 @@ +@echo off +REM Copyright 2018 Google Inc. All Rights Reserved. +REM +REM Licensed under the Apache License, Version 2.0 (the "License"); +REM you may not use this file except in compliance with the License. +REM You may obtain a copy of the License at +REM +REM http://www.apache.org/licenses/LICENSE-2.0 +REM +REM Unless required by applicable law or agreed to in writing, software +REM distributed under the License is distributed on an "AS IS" BASIS, +REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +REM See the License for the specific language governing permissions and +REM limitations under the License. + +pushd .. +if not exist ".build" md ".build" +pushd ".build" +cmake .. -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=./install -Wno-dev +cmake --build . --target INSTALL +popd +popd diff --git a/sdks/cpp/cmake/Fetch_gRPC.cmake b/sdks/cpp/cmake/Fetch_gRPC.cmake new file mode 100644 index 0000000000..bbae132730 --- /dev/null +++ b/sdks/cpp/cmake/Fetch_gRPC.cmake @@ -0,0 +1,54 @@ +# Copyright 2019 Google Inc. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required (VERSION 3.12.0) + +include(FetchContent) + +set(GRPC_GIT_REPO "https://github.com/grpc/grpc.git") +set(GRPC_GIT_TAG "v${AGONES_GRPC_VERSION}") + +FetchContent_Declare( + grpc + GIT_REPOSITORY "${GRPC_GIT_REPO}" + GIT_TAG "${GRPC_GIT_TAG}" + PREFIX grpc + SOURCE_DIR "grpc/.src" + BINARY_DIR "grpc/.bin" + INSTALL_DIR "grpc/.install" + SUBBUILD_DIR "grpc/.subbuild" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "" +) +FetchContent_GetProperties(grpc) +if (NOT grpc_POPULATED) + message("Fetching gRPC ${AGONES_GRPC_VERSION}") + FetchContent_Populate( + grpc + QUIET + GIT_REPOSITORY "${GRPC_GIT_REPO}" + GIT_TAG "${GRPC_GIT_TAG}" + PREFIX grpc + SOURCE_DIR "grpc/.src" + BINARY_DIR "grpc/.bin" + INSTALL_DIR "grpc/.install" + SUBBUILD_DIR "grpc/.subbuild" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "" + ) +endif() diff --git a/sdks/cpp/cmake/agonesConfig.cmake.in b/sdks/cpp/cmake/agonesConfig.cmake.in new file mode 100644 index 0000000000..64c1e609ac --- /dev/null +++ b/sdks/cpp/cmake/agonesConfig.cmake.in @@ -0,0 +1,10 @@ +set(agones_VERSION 0.9.0) + +@PACKAGE_INIT@ + +set(agones_INCLUDE_DIRS @PACKAGE__INCLUDE_DIRS@) + +include(CMakeFindDependencyMacro) +include("${CMAKE_CURRENT_LIST_DIR}/agonesTargets.cmake") + +check_required_components(agones) \ No newline at end of file diff --git a/sdks/cpp/cmake/agones_global.h.in b/sdks/cpp/cmake/agones_global.h.in new file mode 100644 index 0000000000..b8b1b0d082 --- /dev/null +++ b/sdks/cpp/cmake/agones_global.h.in @@ -0,0 +1,24 @@ +// Copyright 2019 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// This code was autogenerated. Do not edit directly. + +#ifndef AGONES_CPP_AGONES_CONFIG_H_ +#define AGONES_CPP_AGONES_CONFIG_H_ + +#include "agones_export.h" + +@GLOBAL_CONFIG_CONTENT@ + +#endif // AGONES_CPP_AGONES_CONFIG_H_ diff --git a/sdks/cpp/sdk.grpc.pb.h b/sdks/cpp/include/agones/sdk.grpc.pb.h similarity index 98% rename from sdks/cpp/sdk.grpc.pb.h rename to sdks/cpp/include/agones/sdk.grpc.pb.h index 453e77839b..93fa49c7ee 100644 --- a/sdks/cpp/sdk.grpc.pb.h +++ b/sdks/cpp/include/agones/sdk.grpc.pb.h @@ -1,3 +1,18 @@ +// Copyright 2018 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// This code was autogenerated. Do not edit directly. // Generated by the gRPC C++ plugin. // If you make any local change, they will be lost. // source: sdk.proto diff --git a/sdks/cpp/include/agones/sdk.h b/sdks/cpp/include/agones/sdk.h new file mode 100644 index 0000000000..e3291e587c --- /dev/null +++ b/sdks/cpp/include/agones/sdk.h @@ -0,0 +1,73 @@ +// Copyright 2017 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +#ifndef AGONES_CPP_SDK_H_ +#define AGONES_CPP_SDK_H_ + +#include "agones_global.h" + +#include "sdk.grpc.pb.h" + +namespace agones { + + class SDKImpl; + + // The Agones SDK + class SDK + { + public: + // Creates a new instance of the SDK. + // Does not connect to anything. + AGONES_EXPORT SDK(); + AGONES_EXPORT ~SDK(); + SDK( const SDK& ) = delete; + SDK& operator=( const SDK& ) = delete; + + // Must be called before any other functions on the SDK. + // This will attempt to do a handshake with the sdk server, timing out + // after 30 seconds. + // Returns true if the connection was successful, false if not. + AGONES_EXPORT bool Connect(); + + // Marks the Game Server as ready to receive connections + AGONES_EXPORT grpc::Status Ready(); + + // Send Health ping. This is a synchronous request. + AGONES_EXPORT bool Health(); + + // Retrieve the current GameServer data + AGONES_EXPORT grpc::Status GameServer(stable::agones::dev::sdk::GameServer* response); + + // Marks the Game Server as ready to shutdown + AGONES_EXPORT grpc::Status Shutdown(); + + // SetLabel sets a metadata label on the `GameServer` with the prefix + // stable.agones.dev/sdk- + AGONES_EXPORT grpc::Status SetLabel(std::string key, std::string value); + + // SetAnnotation sets a metadata annotation on the `GameServer` with the prefix + // stable.agones.dev/sdk- + AGONES_EXPORT grpc::Status SetAnnotation(std::string key, std::string value); + + // Watch the GameServer configuration, and fire the callback + // when an update occurs. + // This is a blocking function, and as such you will likely want to run it inside a thread. + AGONES_EXPORT grpc::Status WatchGameServer(const std::function& callback); + + private: + std::unique_ptr pimpl_; + }; +} +#endif // AGONES_CPP_SDK_H_ diff --git a/sdks/cpp/sdk.pb.h b/sdks/cpp/include/agones/sdk.pb.h similarity index 95% rename from sdks/cpp/sdk.pb.h rename to sdks/cpp/include/agones/sdk.pb.h index 37f751792e..ef71002082 100644 --- a/sdks/cpp/sdk.pb.h +++ b/sdks/cpp/include/agones/sdk.pb.h @@ -50,11 +50,11 @@ #include #include "google/api/annotations.pb.h" // @@protoc_insertion_point(includes) -#define PROTOBUF_INTERNAL_EXPORT_protobuf_sdk_2eproto +#define PROTOBUF_INTERNAL_EXPORT_protobuf_sdk_2eproto AGONES_EXPORT namespace protobuf_sdk_2eproto { // Internal implementation detail -- do not use these members. -struct TableStruct { +struct AGONES_EXPORT TableStruct { static const ::google::protobuf::internal::ParseTableField entries[]; static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; static const ::google::protobuf::internal::ParseTable schema[10]; @@ -62,7 +62,7 @@ struct TableStruct { static const ::google::protobuf::internal::SerializationTable serialization_table[]; static const ::google::protobuf::uint32 offsets[]; }; -void AddDescriptors(); +void AGONES_EXPORT AddDescriptors(); } // namespace protobuf_sdk_2eproto namespace stable { namespace agones { @@ -70,50 +70,50 @@ namespace dev { namespace sdk { class Empty; class EmptyDefaultTypeInternal; -extern EmptyDefaultTypeInternal _Empty_default_instance_; +AGONES_EXPORT extern EmptyDefaultTypeInternal _Empty_default_instance_; class GameServer; class GameServerDefaultTypeInternal; -extern GameServerDefaultTypeInternal _GameServer_default_instance_; +AGONES_EXPORT extern GameServerDefaultTypeInternal _GameServer_default_instance_; class GameServer_ObjectMeta; class GameServer_ObjectMetaDefaultTypeInternal; -extern GameServer_ObjectMetaDefaultTypeInternal _GameServer_ObjectMeta_default_instance_; +AGONES_EXPORT extern GameServer_ObjectMetaDefaultTypeInternal _GameServer_ObjectMeta_default_instance_; class GameServer_ObjectMeta_AnnotationsEntry_DoNotUse; class GameServer_ObjectMeta_AnnotationsEntry_DoNotUseDefaultTypeInternal; -extern GameServer_ObjectMeta_AnnotationsEntry_DoNotUseDefaultTypeInternal _GameServer_ObjectMeta_AnnotationsEntry_DoNotUse_default_instance_; +AGONES_EXPORT extern GameServer_ObjectMeta_AnnotationsEntry_DoNotUseDefaultTypeInternal _GameServer_ObjectMeta_AnnotationsEntry_DoNotUse_default_instance_; class GameServer_ObjectMeta_LabelsEntry_DoNotUse; class GameServer_ObjectMeta_LabelsEntry_DoNotUseDefaultTypeInternal; -extern GameServer_ObjectMeta_LabelsEntry_DoNotUseDefaultTypeInternal _GameServer_ObjectMeta_LabelsEntry_DoNotUse_default_instance_; +AGONES_EXPORT extern GameServer_ObjectMeta_LabelsEntry_DoNotUseDefaultTypeInternal _GameServer_ObjectMeta_LabelsEntry_DoNotUse_default_instance_; class GameServer_Spec; class GameServer_SpecDefaultTypeInternal; -extern GameServer_SpecDefaultTypeInternal _GameServer_Spec_default_instance_; +AGONES_EXPORT extern GameServer_SpecDefaultTypeInternal _GameServer_Spec_default_instance_; class GameServer_Spec_Health; class GameServer_Spec_HealthDefaultTypeInternal; -extern GameServer_Spec_HealthDefaultTypeInternal _GameServer_Spec_Health_default_instance_; +AGONES_EXPORT extern GameServer_Spec_HealthDefaultTypeInternal _GameServer_Spec_Health_default_instance_; class GameServer_Status; class GameServer_StatusDefaultTypeInternal; -extern GameServer_StatusDefaultTypeInternal _GameServer_Status_default_instance_; +AGONES_EXPORT extern GameServer_StatusDefaultTypeInternal _GameServer_Status_default_instance_; class GameServer_Status_Port; class GameServer_Status_PortDefaultTypeInternal; -extern GameServer_Status_PortDefaultTypeInternal _GameServer_Status_Port_default_instance_; +AGONES_EXPORT extern GameServer_Status_PortDefaultTypeInternal _GameServer_Status_Port_default_instance_; class KeyValue; class KeyValueDefaultTypeInternal; -extern KeyValueDefaultTypeInternal _KeyValue_default_instance_; +AGONES_EXPORT extern KeyValueDefaultTypeInternal _KeyValue_default_instance_; } // namespace sdk } // namespace dev } // namespace agones } // namespace stable namespace google { namespace protobuf { -template<> ::stable::agones::dev::sdk::Empty* Arena::CreateMaybeMessage<::stable::agones::dev::sdk::Empty>(Arena*); -template<> ::stable::agones::dev::sdk::GameServer* Arena::CreateMaybeMessage<::stable::agones::dev::sdk::GameServer>(Arena*); -template<> ::stable::agones::dev::sdk::GameServer_ObjectMeta* Arena::CreateMaybeMessage<::stable::agones::dev::sdk::GameServer_ObjectMeta>(Arena*); -template<> ::stable::agones::dev::sdk::GameServer_ObjectMeta_AnnotationsEntry_DoNotUse* Arena::CreateMaybeMessage<::stable::agones::dev::sdk::GameServer_ObjectMeta_AnnotationsEntry_DoNotUse>(Arena*); -template<> ::stable::agones::dev::sdk::GameServer_ObjectMeta_LabelsEntry_DoNotUse* Arena::CreateMaybeMessage<::stable::agones::dev::sdk::GameServer_ObjectMeta_LabelsEntry_DoNotUse>(Arena*); -template<> ::stable::agones::dev::sdk::GameServer_Spec* Arena::CreateMaybeMessage<::stable::agones::dev::sdk::GameServer_Spec>(Arena*); -template<> ::stable::agones::dev::sdk::GameServer_Spec_Health* Arena::CreateMaybeMessage<::stable::agones::dev::sdk::GameServer_Spec_Health>(Arena*); -template<> ::stable::agones::dev::sdk::GameServer_Status* Arena::CreateMaybeMessage<::stable::agones::dev::sdk::GameServer_Status>(Arena*); -template<> ::stable::agones::dev::sdk::GameServer_Status_Port* Arena::CreateMaybeMessage<::stable::agones::dev::sdk::GameServer_Status_Port>(Arena*); -template<> ::stable::agones::dev::sdk::KeyValue* Arena::CreateMaybeMessage<::stable::agones::dev::sdk::KeyValue>(Arena*); +template<> AGONES_EXPORT ::stable::agones::dev::sdk::Empty* Arena::CreateMaybeMessage<::stable::agones::dev::sdk::Empty>(Arena*); +template<> AGONES_EXPORT ::stable::agones::dev::sdk::GameServer* Arena::CreateMaybeMessage<::stable::agones::dev::sdk::GameServer>(Arena*); +template<> AGONES_EXPORT ::stable::agones::dev::sdk::GameServer_ObjectMeta* Arena::CreateMaybeMessage<::stable::agones::dev::sdk::GameServer_ObjectMeta>(Arena*); +template<> AGONES_EXPORT ::stable::agones::dev::sdk::GameServer_ObjectMeta_AnnotationsEntry_DoNotUse* Arena::CreateMaybeMessage<::stable::agones::dev::sdk::GameServer_ObjectMeta_AnnotationsEntry_DoNotUse>(Arena*); +template<> AGONES_EXPORT ::stable::agones::dev::sdk::GameServer_ObjectMeta_LabelsEntry_DoNotUse* Arena::CreateMaybeMessage<::stable::agones::dev::sdk::GameServer_ObjectMeta_LabelsEntry_DoNotUse>(Arena*); +template<> AGONES_EXPORT ::stable::agones::dev::sdk::GameServer_Spec* Arena::CreateMaybeMessage<::stable::agones::dev::sdk::GameServer_Spec>(Arena*); +template<> AGONES_EXPORT ::stable::agones::dev::sdk::GameServer_Spec_Health* Arena::CreateMaybeMessage<::stable::agones::dev::sdk::GameServer_Spec_Health>(Arena*); +template<> AGONES_EXPORT ::stable::agones::dev::sdk::GameServer_Status* Arena::CreateMaybeMessage<::stable::agones::dev::sdk::GameServer_Status>(Arena*); +template<> AGONES_EXPORT ::stable::agones::dev::sdk::GameServer_Status_Port* Arena::CreateMaybeMessage<::stable::agones::dev::sdk::GameServer_Status_Port>(Arena*); +template<> AGONES_EXPORT ::stable::agones::dev::sdk::KeyValue* Arena::CreateMaybeMessage<::stable::agones::dev::sdk::KeyValue>(Arena*); } // namespace protobuf } // namespace google namespace stable { @@ -123,7 +123,7 @@ namespace sdk { // =================================================================== -class Empty : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:stable.agones.dev.sdk.Empty) */ { +class AGONES_EXPORT Empty : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:stable.agones.dev.sdk.Empty) */ { public: Empty(); virtual ~Empty(); @@ -219,7 +219,7 @@ class Empty : public ::google::protobuf::Message /* @@protoc_insertion_point(cla }; // ------------------------------------------------------------------- -class KeyValue : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:stable.agones.dev.sdk.KeyValue) */ { +class AGONES_EXPORT KeyValue : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:stable.agones.dev.sdk.KeyValue) */ { public: KeyValue(); virtual ~KeyValue(); @@ -387,7 +387,7 @@ class GameServer_ObjectMeta_LabelsEntry_DoNotUse : public ::google::protobuf::in // ------------------------------------------------------------------- -class GameServer_ObjectMeta : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:stable.agones.dev.sdk.GameServer.ObjectMeta) */ { +class AGONES_EXPORT GameServer_ObjectMeta : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:stable.agones.dev.sdk.GameServer.ObjectMeta) */ { public: GameServer_ObjectMeta(); virtual ~GameServer_ObjectMeta(); @@ -595,7 +595,7 @@ class GameServer_ObjectMeta : public ::google::protobuf::Message /* @@protoc_ins }; // ------------------------------------------------------------------- -class GameServer_Spec_Health : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:stable.agones.dev.sdk.GameServer.Spec.Health) */ { +class AGONES_EXPORT GameServer_Spec_Health : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:stable.agones.dev.sdk.GameServer.Spec.Health) */ { public: GameServer_Spec_Health(); virtual ~GameServer_Spec_Health(); @@ -719,7 +719,7 @@ class GameServer_Spec_Health : public ::google::protobuf::Message /* @@protoc_in }; // ------------------------------------------------------------------- -class GameServer_Spec : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:stable.agones.dev.sdk.GameServer.Spec) */ { +class AGONES_EXPORT GameServer_Spec : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:stable.agones.dev.sdk.GameServer.Spec) */ { public: GameServer_Spec(); virtual ~GameServer_Spec(); @@ -830,7 +830,7 @@ class GameServer_Spec : public ::google::protobuf::Message /* @@protoc_insertion }; // ------------------------------------------------------------------- -class GameServer_Status_Port : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:stable.agones.dev.sdk.GameServer.Status.Port) */ { +class AGONES_EXPORT GameServer_Status_Port : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:stable.agones.dev.sdk.GameServer.Status.Port) */ { public: GameServer_Status_Port(); virtual ~GameServer_Status_Port(); @@ -948,7 +948,7 @@ class GameServer_Status_Port : public ::google::protobuf::Message /* @@protoc_in }; // ------------------------------------------------------------------- -class GameServer_Status : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:stable.agones.dev.sdk.GameServer.Status) */ { +class AGONES_EXPORT GameServer_Status : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:stable.agones.dev.sdk.GameServer.Status) */ { public: GameServer_Status(); virtual ~GameServer_Status(); @@ -1089,7 +1089,7 @@ class GameServer_Status : public ::google::protobuf::Message /* @@protoc_inserti }; // ------------------------------------------------------------------- -class GameServer : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:stable.agones.dev.sdk.GameServer) */ { +class AGONES_EXPORT GameServer : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:stable.agones.dev.sdk.GameServer) */ { public: GameServer(); virtual ~GameServer(); diff --git a/sdks/cpp/google/api/annotations.pb.h b/sdks/cpp/include/google/api/annotations.pb.h similarity index 94% rename from sdks/cpp/google/api/annotations.pb.h rename to sdks/cpp/include/google/api/annotations.pb.h index 4c27070704..8fca6ee29b 100644 --- a/sdks/cpp/google/api/annotations.pb.h +++ b/sdks/cpp/include/google/api/annotations.pb.h @@ -46,11 +46,11 @@ #include "google/api/http.pb.h" #include // @@protoc_insertion_point(includes) -#define PROTOBUF_INTERNAL_EXPORT_protobuf_google_2fapi_2fannotations_2eproto +#define PROTOBUF_INTERNAL_EXPORT_protobuf_google_2fapi_2fannotations_2eproto AGONES_EXPORT namespace protobuf_google_2fapi_2fannotations_2eproto { // Internal implementation detail -- do not use these members. -struct TableStruct { +struct AGONES_EXPORT TableStruct { static const ::google::protobuf::internal::ParseTableField entries[]; static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; static const ::google::protobuf::internal::ParseTable schema[1]; @@ -58,7 +58,7 @@ struct TableStruct { static const ::google::protobuf::internal::SerializationTable serialization_table[]; static const ::google::protobuf::uint32 offsets[]; }; -void AddDescriptors(); +void AGONES_EXPORT AddDescriptors(); } // namespace protobuf_google_2fapi_2fannotations_2eproto namespace google { namespace api { @@ -73,7 +73,7 @@ namespace api { // =================================================================== static const int kHttpFieldNumber = 72295728; -extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MethodOptions, +AGONES_EXPORT extern ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MethodOptions, ::google::protobuf::internal::MessageTypeTraits< ::google::api::HttpRule >, 11, false > http; diff --git a/sdks/cpp/google/api/http.pb.h b/sdks/cpp/include/google/api/http.pb.h similarity index 98% rename from sdks/cpp/google/api/http.pb.h rename to sdks/cpp/include/google/api/http.pb.h index 582b146845..b9c24c7457 100644 --- a/sdks/cpp/google/api/http.pb.h +++ b/sdks/cpp/include/google/api/http.pb.h @@ -46,11 +46,11 @@ #include // IWYU pragma: export #include // @@protoc_insertion_point(includes) -#define PROTOBUF_INTERNAL_EXPORT_protobuf_google_2fapi_2fhttp_2eproto +#define PROTOBUF_INTERNAL_EXPORT_protobuf_google_2fapi_2fhttp_2eproto AGONES_EXPORT namespace protobuf_google_2fapi_2fhttp_2eproto { // Internal implementation detail -- do not use these members. -struct TableStruct { +struct AGONES_EXPORT TableStruct { static const ::google::protobuf::internal::ParseTableField entries[]; static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; static const ::google::protobuf::internal::ParseTable schema[3]; @@ -58,26 +58,26 @@ struct TableStruct { static const ::google::protobuf::internal::SerializationTable serialization_table[]; static const ::google::protobuf::uint32 offsets[]; }; -void AddDescriptors(); +void AGONES_EXPORT AddDescriptors(); } // namespace protobuf_google_2fapi_2fhttp_2eproto namespace google { namespace api { class CustomHttpPattern; class CustomHttpPatternDefaultTypeInternal; -extern CustomHttpPatternDefaultTypeInternal _CustomHttpPattern_default_instance_; +AGONES_EXPORT extern CustomHttpPatternDefaultTypeInternal _CustomHttpPattern_default_instance_; class Http; class HttpDefaultTypeInternal; -extern HttpDefaultTypeInternal _Http_default_instance_; +AGONES_EXPORT extern HttpDefaultTypeInternal _Http_default_instance_; class HttpRule; class HttpRuleDefaultTypeInternal; -extern HttpRuleDefaultTypeInternal _HttpRule_default_instance_; +AGONES_EXPORT extern HttpRuleDefaultTypeInternal _HttpRule_default_instance_; } // namespace api } // namespace google namespace google { namespace protobuf { -template<> ::google::api::CustomHttpPattern* Arena::CreateMaybeMessage<::google::api::CustomHttpPattern>(Arena*); -template<> ::google::api::Http* Arena::CreateMaybeMessage<::google::api::Http>(Arena*); -template<> ::google::api::HttpRule* Arena::CreateMaybeMessage<::google::api::HttpRule>(Arena*); +template<> AGONES_EXPORT ::google::api::CustomHttpPattern* Arena::CreateMaybeMessage<::google::api::CustomHttpPattern>(Arena*); +template<> AGONES_EXPORT ::google::api::Http* Arena::CreateMaybeMessage<::google::api::Http>(Arena*); +template<> AGONES_EXPORT ::google::api::HttpRule* Arena::CreateMaybeMessage<::google::api::HttpRule>(Arena*); } // namespace protobuf } // namespace google namespace google { @@ -85,7 +85,7 @@ namespace api { // =================================================================== -class Http : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.api.Http) */ { +class AGONES_EXPORT Http : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.api.Http) */ { public: Http(); virtual ~Http(); @@ -216,7 +216,7 @@ class Http : public ::google::protobuf::Message /* @@protoc_insertion_point(clas }; // ------------------------------------------------------------------- -class HttpRule : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.api.HttpRule) */ { +class AGONES_EXPORT HttpRule : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.api.HttpRule) */ { public: HttpRule(); virtual ~HttpRule(); @@ -589,7 +589,7 @@ class HttpRule : public ::google::protobuf::Message /* @@protoc_insertion_point( }; // ------------------------------------------------------------------- -class CustomHttpPattern : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.api.CustomHttpPattern) */ { +class AGONES_EXPORT CustomHttpPattern : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.api.CustomHttpPattern) */ { public: CustomHttpPattern(); virtual ~CustomHttpPattern(); diff --git a/sdks/cpp/sdk.h b/sdks/cpp/sdk.h deleted file mode 100644 index 44bd72b583..0000000000 --- a/sdks/cpp/sdk.h +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2017 Google Inc. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include -#include "sdk.grpc.pb.h" - -namespace agones { - - // The Agones SDK - class SDK { - public: - // Creates a new instance of the SDK. - // Does not connect to anything. - SDK(); - - // Must be called before any other functions on the SDK. - // This will attempt to do a handshake with the sdk server, timing out - // after 30 seconds. - // Returns true if the connection was successful, false if not. - bool Connect(); - - // Marks the Game Server as ready to receive connections - grpc::Status Ready(); - - // Send Health ping. This is a synchronous request. - bool Health(); - - // Retrieve the current GameServer data - grpc::Status GameServer(stable::agones::dev::sdk::GameServer* response); - - // Marks the Game Server as ready to shutdown - grpc::Status Shutdown(); - - // SetLabel sets a metadata label on the `GameServer` with the prefix - // stable.agones.dev/sdk- - grpc::Status SetLabel(std::string key, std::string value); - - // SetAnnotation sets a metadata annotation on the `GameServer` with the prefix - // stable.agones.dev/sdk- - grpc::Status SetAnnotation(std::string key, std::string value); - - // Watch the GameServer configuration, and fire the callback - // when an update occurs. - // This is a blocking function, and as such you will likely want to run it inside a thread. - grpc::Status WatchGameServer(const std::function callback); - - - private: - std::shared_ptr channel; - std::unique_ptr stub; - std::unique_ptr< ::grpc::ClientWriter< ::stable::agones::dev::sdk::Empty>> health; - }; -} diff --git a/sdks/cpp/sources.cmake b/sdks/cpp/sources.cmake new file mode 100644 index 0000000000..24a09f9596 --- /dev/null +++ b/sdks/cpp/sources.cmake @@ -0,0 +1,27 @@ +set(SOURCE_FILES + src/agones/sdk.cc + src/agones/sdk.grpc.pb.cc + src/agones/sdk.pb.cc + + src/google/annotations.pb.cc + src/google/http.pb.cc +) + +set(HEADER_FILES + include/agones/sdk.h + include/agones/sdk.grpc.pb.h + include/agones/sdk.pb.h +) + +set(GOOGLE_HEADER_FILES + include/google/api/annotations.pb.h + include/google/api/http.pb.h +) + +set(ALL_FILES + ${SOURCE_FILES} + ${HEADER_FILES} + ${GOOGLE_HEADER_FILES} + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_export.h" + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_global.h" +) diff --git a/sdks/cpp/sdk.cc b/sdks/cpp/src/agones/sdk.cc similarity index 69% rename from sdks/cpp/sdk.cc rename to sdks/cpp/src/agones/sdk.cc index bda1748ff0..a38f335ab2 100644 --- a/sdks/cpp/sdk.cc +++ b/sdks/cpp/src/agones/sdk.cc @@ -12,27 +12,43 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "sdk.h" -#include "sdk.pb.h" +#include "agones/sdk.h" +#include + + +namespace{ + const int kPort = 59357; + +} namespace agones { - const int port = 59357; + class SDKImpl final { + public: + std::shared_ptr channel_; + std::unique_ptr stub_; + std::unique_ptr> health_; + }; + + SDK::SDK() + : pimpl_{std::make_unique()} { + pimpl_->channel_ = grpc::CreateChannel("localhost:" + std::to_string(kPort), grpc::InsecureChannelCredentials()); + } - SDK::SDK() { - channel = grpc::CreateChannel("localhost:" + std::to_string(port), grpc::InsecureChannelCredentials()); + SDK::~SDK() + { } bool SDK::Connect() { - if (!channel->WaitForConnected(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(30, GPR_TIMESPAN)))) { + if (!pimpl_->channel_->WaitForConnected(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(30, GPR_TIMESPAN)))) { return false; } - stub = stable::agones::dev::sdk::SDK::NewStub(channel); + pimpl_->stub_ = stable::agones::dev::sdk::SDK::NewStub( pimpl_->channel_); // make the health connection stable::agones::dev::sdk::Empty response; - health = stub->Health(new grpc::ClientContext(), &response); + pimpl_->health_ = pimpl_->stub_->Health(new grpc::ClientContext(), &response); return true; } @@ -43,12 +59,12 @@ namespace agones { stable::agones::dev::sdk::Empty request; stable::agones::dev::sdk::Empty response; - return stub->Ready(context, request, &response); + return pimpl_->stub_->Ready(context, request, &response); } bool SDK::Health() { stable::agones::dev::sdk::Empty request; - return health->Write(request); + return pimpl_->health_->Write(request); } grpc::Status SDK::GameServer(stable::agones::dev::sdk::GameServer* response) { @@ -56,15 +72,15 @@ namespace agones { context->set_deadline(gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_seconds(30, GPR_TIMESPAN))); stable::agones::dev::sdk::Empty request; - return stub->GetGameServer(context, request, response); + return pimpl_->stub_->GetGameServer(context, request, response); } - grpc::Status SDK::WatchGameServer(const std::function callback) { + grpc::Status SDK::WatchGameServer(const std::function& callback) { grpc::ClientContext *context = new grpc::ClientContext(); stable::agones::dev::sdk::Empty request; stable::agones::dev::sdk::GameServer gameServer; - std::unique_ptr> reader = stub->WatchGameServer(context, request); + std::unique_ptr> reader = pimpl_->stub_->WatchGameServer(context, request); while (reader->Read(&gameServer)) { callback(gameServer); } @@ -77,7 +93,7 @@ namespace agones { stable::agones::dev::sdk::Empty request; stable::agones::dev::sdk::Empty response; - return stub->Shutdown(context, request, &response); + return pimpl_->stub_->Shutdown(context, request, &response); } grpc::Status SDK::SetLabel(std::string key, std::string value) { @@ -90,7 +106,7 @@ namespace agones { stable::agones::dev::sdk::Empty response; - return stub->SetLabel(context, request, &response); + return pimpl_->stub_->SetLabel(context, request, &response); } grpc::Status SDK::SetAnnotation(std::string key, std::string value) { @@ -103,6 +119,6 @@ namespace agones { stable::agones::dev::sdk::Empty response; - return stub->SetAnnotation(context, request, &response); + return pimpl_->stub_->SetAnnotation(context, request, &response); } } \ No newline at end of file diff --git a/sdks/cpp/sdk.grpc.pb.cc b/sdks/cpp/src/agones/sdk.grpc.pb.cc similarity index 100% rename from sdks/cpp/sdk.grpc.pb.cc rename to sdks/cpp/src/agones/sdk.grpc.pb.cc diff --git a/sdks/cpp/sdk.pb.cc b/sdks/cpp/src/agones/sdk.pb.cc similarity index 99% rename from sdks/cpp/sdk.pb.cc rename to sdks/cpp/src/agones/sdk.pb.cc index 54924583d4..bbd01720bf 100644 --- a/sdks/cpp/sdk.pb.cc +++ b/sdks/cpp/src/agones/sdk.pb.cc @@ -113,7 +113,7 @@ static void InitDefaultsEmpty() { ::stable::agones::dev::sdk::Empty::InitAsDefaultInstance(); } -::google::protobuf::internal::SCCInfo<0> scc_info_Empty = +AGONES_EXPORT ::google::protobuf::internal::SCCInfo<0> scc_info_Empty = {{ATOMIC_VAR_INIT(::google::protobuf::internal::SCCInfoBase::kUninitialized), 0, InitDefaultsEmpty}, {}}; static void InitDefaultsKeyValue() { @@ -127,7 +127,7 @@ static void InitDefaultsKeyValue() { ::stable::agones::dev::sdk::KeyValue::InitAsDefaultInstance(); } -::google::protobuf::internal::SCCInfo<0> scc_info_KeyValue = +AGONES_EXPORT ::google::protobuf::internal::SCCInfo<0> scc_info_KeyValue = {{ATOMIC_VAR_INIT(::google::protobuf::internal::SCCInfoBase::kUninitialized), 0, InitDefaultsKeyValue}, {}}; static void InitDefaultsGameServer_ObjectMeta_AnnotationsEntry_DoNotUse() { @@ -140,7 +140,7 @@ static void InitDefaultsGameServer_ObjectMeta_AnnotationsEntry_DoNotUse() { ::stable::agones::dev::sdk::GameServer_ObjectMeta_AnnotationsEntry_DoNotUse::InitAsDefaultInstance(); } -::google::protobuf::internal::SCCInfo<0> scc_info_GameServer_ObjectMeta_AnnotationsEntry_DoNotUse = +AGONES_EXPORT ::google::protobuf::internal::SCCInfo<0> scc_info_GameServer_ObjectMeta_AnnotationsEntry_DoNotUse = {{ATOMIC_VAR_INIT(::google::protobuf::internal::SCCInfoBase::kUninitialized), 0, InitDefaultsGameServer_ObjectMeta_AnnotationsEntry_DoNotUse}, {}}; static void InitDefaultsGameServer_ObjectMeta_LabelsEntry_DoNotUse() { @@ -153,7 +153,7 @@ static void InitDefaultsGameServer_ObjectMeta_LabelsEntry_DoNotUse() { ::stable::agones::dev::sdk::GameServer_ObjectMeta_LabelsEntry_DoNotUse::InitAsDefaultInstance(); } -::google::protobuf::internal::SCCInfo<0> scc_info_GameServer_ObjectMeta_LabelsEntry_DoNotUse = +AGONES_EXPORT ::google::protobuf::internal::SCCInfo<0> scc_info_GameServer_ObjectMeta_LabelsEntry_DoNotUse = {{ATOMIC_VAR_INIT(::google::protobuf::internal::SCCInfoBase::kUninitialized), 0, InitDefaultsGameServer_ObjectMeta_LabelsEntry_DoNotUse}, {}}; static void InitDefaultsGameServer_ObjectMeta() { @@ -167,7 +167,7 @@ static void InitDefaultsGameServer_ObjectMeta() { ::stable::agones::dev::sdk::GameServer_ObjectMeta::InitAsDefaultInstance(); } -::google::protobuf::internal::SCCInfo<2> scc_info_GameServer_ObjectMeta = +AGONES_EXPORT ::google::protobuf::internal::SCCInfo<2> scc_info_GameServer_ObjectMeta = {{ATOMIC_VAR_INIT(::google::protobuf::internal::SCCInfoBase::kUninitialized), 2, InitDefaultsGameServer_ObjectMeta}, { &protobuf_sdk_2eproto::scc_info_GameServer_ObjectMeta_AnnotationsEntry_DoNotUse.base, &protobuf_sdk_2eproto::scc_info_GameServer_ObjectMeta_LabelsEntry_DoNotUse.base,}}; @@ -183,7 +183,7 @@ static void InitDefaultsGameServer_Spec_Health() { ::stable::agones::dev::sdk::GameServer_Spec_Health::InitAsDefaultInstance(); } -::google::protobuf::internal::SCCInfo<0> scc_info_GameServer_Spec_Health = +AGONES_EXPORT ::google::protobuf::internal::SCCInfo<0> scc_info_GameServer_Spec_Health = {{ATOMIC_VAR_INIT(::google::protobuf::internal::SCCInfoBase::kUninitialized), 0, InitDefaultsGameServer_Spec_Health}, {}}; static void InitDefaultsGameServer_Spec() { @@ -197,7 +197,7 @@ static void InitDefaultsGameServer_Spec() { ::stable::agones::dev::sdk::GameServer_Spec::InitAsDefaultInstance(); } -::google::protobuf::internal::SCCInfo<1> scc_info_GameServer_Spec = +AGONES_EXPORT ::google::protobuf::internal::SCCInfo<1> scc_info_GameServer_Spec = {{ATOMIC_VAR_INIT(::google::protobuf::internal::SCCInfoBase::kUninitialized), 1, InitDefaultsGameServer_Spec}, { &protobuf_sdk_2eproto::scc_info_GameServer_Spec_Health.base,}}; @@ -212,7 +212,7 @@ static void InitDefaultsGameServer_Status_Port() { ::stable::agones::dev::sdk::GameServer_Status_Port::InitAsDefaultInstance(); } -::google::protobuf::internal::SCCInfo<0> scc_info_GameServer_Status_Port = +AGONES_EXPORT ::google::protobuf::internal::SCCInfo<0> scc_info_GameServer_Status_Port = {{ATOMIC_VAR_INIT(::google::protobuf::internal::SCCInfoBase::kUninitialized), 0, InitDefaultsGameServer_Status_Port}, {}}; static void InitDefaultsGameServer_Status() { @@ -226,7 +226,7 @@ static void InitDefaultsGameServer_Status() { ::stable::agones::dev::sdk::GameServer_Status::InitAsDefaultInstance(); } -::google::protobuf::internal::SCCInfo<1> scc_info_GameServer_Status = +AGONES_EXPORT ::google::protobuf::internal::SCCInfo<1> scc_info_GameServer_Status = {{ATOMIC_VAR_INIT(::google::protobuf::internal::SCCInfoBase::kUninitialized), 1, InitDefaultsGameServer_Status}, { &protobuf_sdk_2eproto::scc_info_GameServer_Status_Port.base,}}; @@ -241,7 +241,7 @@ static void InitDefaultsGameServer() { ::stable::agones::dev::sdk::GameServer::InitAsDefaultInstance(); } -::google::protobuf::internal::SCCInfo<3> scc_info_GameServer = +AGONES_EXPORT ::google::protobuf::internal::SCCInfo<3> scc_info_GameServer = {{ATOMIC_VAR_INIT(::google::protobuf::internal::SCCInfoBase::kUninitialized), 3, InitDefaultsGameServer}, { &protobuf_sdk_2eproto::scc_info_GameServer_ObjectMeta.base, &protobuf_sdk_2eproto::scc_info_GameServer_Spec.base, diff --git a/sdks/cpp/google/api/annotations.pb.cc b/sdks/cpp/src/google/annotations.pb.cc similarity index 100% rename from sdks/cpp/google/api/annotations.pb.cc rename to sdks/cpp/src/google/annotations.pb.cc diff --git a/sdks/cpp/google/api/http.pb.cc b/sdks/cpp/src/google/http.pb.cc similarity index 99% rename from sdks/cpp/google/api/http.pb.cc rename to sdks/cpp/src/google/http.pb.cc index 30212e834e..9beef12614 100644 --- a/sdks/cpp/google/api/http.pb.cc +++ b/sdks/cpp/src/google/http.pb.cc @@ -75,7 +75,7 @@ static void InitDefaultsHttp() { ::google::api::Http::InitAsDefaultInstance(); } -::google::protobuf::internal::SCCInfo<1> scc_info_Http = +AGONES_EXPORT ::google::protobuf::internal::SCCInfo<1> scc_info_Http = {{ATOMIC_VAR_INIT(::google::protobuf::internal::SCCInfoBase::kUninitialized), 1, InitDefaultsHttp}, { &protobuf_google_2fapi_2fhttp_2eproto::scc_info_HttpRule.base,}}; @@ -90,7 +90,7 @@ static void InitDefaultsHttpRule() { ::google::api::HttpRule::InitAsDefaultInstance(); } -::google::protobuf::internal::SCCInfo<1> scc_info_HttpRule = +AGONES_EXPORT ::google::protobuf::internal::SCCInfo<1> scc_info_HttpRule = {{ATOMIC_VAR_INIT(::google::protobuf::internal::SCCInfoBase::kUninitialized), 1, InitDefaultsHttpRule}, { &protobuf_google_2fapi_2fhttp_2eproto::scc_info_CustomHttpPattern.base,}}; @@ -105,7 +105,7 @@ static void InitDefaultsCustomHttpPattern() { ::google::api::CustomHttpPattern::InitAsDefaultInstance(); } -::google::protobuf::internal::SCCInfo<0> scc_info_CustomHttpPattern = +AGONES_EXPORT ::google::protobuf::internal::SCCInfo<0> scc_info_CustomHttpPattern = {{ATOMIC_VAR_INIT(::google::protobuf::internal::SCCInfoBase::kUninitialized), 0, InitDefaultsCustomHttpPattern}, {}}; void InitDefaults() { diff --git a/site/content/en/docs/Guides/Client SDKs/cpp.md b/site/content/en/docs/Guides/Client SDKs/cpp.md index 974c39ea09..43c8088161 100644 --- a/site/content/en/docs/Guides/Client SDKs/cpp.md +++ b/site/content/en/docs/Guides/Client SDKs/cpp.md @@ -11,7 +11,7 @@ Check the [Client SDK Documentation]({{< relref "_index.md" >}}) for more detail ## Download Download the source from the [Releases Page](https://github.com/GoogleCloudPlatform/agones/releases) -or {{< ghlink href="sdks/rust" >}}directly from Github{{< /ghlink >}}. +or {{< ghlink href="sdks/cpp" >}}directly from Github{{< /ghlink >}}. ## Usage @@ -117,9 +117,9 @@ sdk->WatchGameServer([](stable::agones::dev::sdk::GameServer gameserver){ std::cout << "GameServer Update, state: " << gameserver.status().state() << std::endl; }); ``` - +{{% feature expiryVersion="0.9.0" %}} For more information, you can also read the [SDK Overview]({{< relref "_index.md" >}}), check out -{{< ghlink href="sdks/cpp/sdk.h" >}}sdk.h{{< /ghlink >}} and also look at the +{{< ghlink href="sdks/cpp/include/agones/sdk.h" >}}sdk.h{{< /ghlink >}} and also look at the {{< ghlink href="examples/cpp-simple" >}}C++ example{{< / >}}. ### Failure @@ -153,3 +153,58 @@ If you wish to compile from source, you will need to compile and install the fol If you are building a server on Windows or macOS, and need a development build to run on that platform, at this time you will need to compile from source. Windows and macOS libraries for the C++ SDK for easier cross platform development are planned and will be provided in the near future. +{{% /feature %}} +{{% feature publishVersion="0.9.0" %}} +For more information, you can also read the [SDK Overview]({{< relref "_index.md" >}}), check out +{{< ghlink href="sdks/cpp/include/agones/sdk.h" >}}sdk.h{{< /ghlink >}} and also look at the +{{< ghlink href="examples/cpp-simple" >}}C++ example{{< / >}}. + +### Failure +When running on Agones, the above functions should only fail under exceptional circumstances, so please +file a bug if it occurs. + +### Building the Libraries from source +CMake is used to build SDK for all platforms. It is possible to build SDK as a static or dynamic library. + +## Prerequisites +* CMake >= 3.13.0 +* Git +* C++14 compiler + +## Options +Following options are available +- **AGONES_BUILD_SHARED** (default is OFF) - build sdk as a shared library. +- **AGONES_CREATE_PACKAGE** (default is ON) - create an "install" step, to create a cmake package. + +## Windows +Building with Visual Studio: +``` +md .build +cd .build +cmake .. -G "Visual Studio 15 2017 Win64" -Wno-dev +cmake --build . --config Release +``` +Building with NMake +``` +md .build +cd .build +cmake .. -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -Wno-dev +cmake --build . +``` + +## Linux / MacOS +``` +mkdir -p .build +cd .build +cmake .. -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles" -Wno-dev +cmake --build . +``` + +## Remarks +CMake option `-Wno-dev` is specified to suppress [CMP0048](https://cmake.org/cmake/help/v3.13/policy/CMP0048.html) deprecation warning for gRPC depencency. + +### Using SDK +In CMake-based projects it's enough to specify a folder where SDK is installed with `CMAKE_PREFIX_PATH` and use `find_package(agones CONFIG REQUIRED)` command. For example: {{< ghlink href="examples/cpp-simple" >}}cpp-simple{{< / >}}. +If **AGONES_CREATE_PACKAGE** option is off, then `CMAKE_PREFIX_PATH` should be set to a path where SDK is built (usualy `agones/sdks/cpp/.build`). +It maybe useful to disable some [protobuf warnings](https://github.com/protocolbuffers/protobuf/blob/master/cmake/README.md#notes-on-compiler-warnings) in your project. +{{% /feature %}}