From 8611e1e0440b4fcd9106223cff18d9111fc6725c Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Wed, 18 Sep 2024 15:20:37 +0100 Subject: [PATCH 01/25] Fix libhttpclient builds, rearrange build scripts for easier console builds --- .gitmodules | 10 + CMakeLists.txt | 78 +----- CMakePresets.json | 42 +-- cmake/checkPresets.cmake | 9 + cmake/libhttpClient.cmake | 76 ++++++ cmake/platformSupport.cmake | 8 +- cmake/toolchains/msvc/VSWhere.cmake | 132 ++++++++++ cmake/toolchains/msvc/Windows.Kits.cmake | 155 +++++++++++ .../msvc/Windows.MSVC.toolchain.cmake | 247 ++++++++++++++++++ core/CMakeLists.txt | 2 +- impl/wsLibHttpClient/NWebsocketLibHC.h | 1 + impl/wsWslay/NWebsocketWslay.cpp | 2 +- impl/wsWslay/NWebsocketWslay.h | 2 +- interface/config.h.in | 2 +- .../realtime/NRtTransportInterface.h | 2 +- submodules/devkits | 1 + submodules/private | 1 + submodules/vcpkg | 1 + vcpkg.json | 3 +- 19 files changed, 664 insertions(+), 110 deletions(-) create mode 100644 .gitmodules create mode 100644 cmake/checkPresets.cmake create mode 100644 cmake/libhttpClient.cmake create mode 100644 cmake/toolchains/msvc/VSWhere.cmake create mode 100644 cmake/toolchains/msvc/Windows.Kits.cmake create mode 100644 cmake/toolchains/msvc/Windows.MSVC.toolchain.cmake create mode 160000 submodules/devkits create mode 160000 submodules/private create mode 160000 submodules/vcpkg diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..c8e7fb697 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,10 @@ +[submodule "submodules/vcpkg"] + path = submodules/vcpkg + url = https://github.com/microsoft/vcpkg +[submodule "submodules/private"] + path = submodules/private + url = https://github.com/heroiclabs/nakama-cpp-private +[submodule "submodules/devkits"] + path = submodules/devkits + url = https://github.com/heroiclabs/console-devkits.git + shallow = true diff --git a/CMakeLists.txt b/CMakeLists.txt index 056359318..2753d9df0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,7 @@ # I think we are constrained to the version that the latest android sdk uses, for Android builds. cmake_minimum_required(VERSION 3.22.1) include(version.cmake) +include(cmake/checkPresets.cmake) if (CMAKE_OSX_SYSROOT STREQUAL "iphonesimulator") # this hack seems to be required for now, otherwise CMake still thinks we are building for arm... @@ -12,9 +13,7 @@ if (ANDROID) endif() set(CMAKE_CONFIGURATION_TYPES "Debug;MinSizeRel") -set(VCPKG_OVERLAY_TRIPLETS "${CMAKE_CURRENT_SOURCE_DIR}/cmake/triplets") set(CMAKE_SUPPRESS_REGENERATION true) ## for Xcode -set(VCPKG_PREFER_SYSTEM_LIBS OFF) ## TODO figure out why vcpkg seems to toggle these on and prevent downloading from fetchcontent set(FETCHCONTENT_FULLY_DISCONNECTED OFF) @@ -83,13 +82,15 @@ endif() cmake_policy(SET CMP0012 NEW) ## force so that gradle doesn't stomp vcpkg toolchain with the android toolchain -set(CMAKE_TOOLCHAIN_FILE $ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake CACHE FILEPATH "Vcpkg toolchain file" FORCE) +set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_LIST_DIR}/submodules/vcpkg/scripts/buildsystems/vcpkg.cmake CACHE FILEPATH "Vcpkg toolchain file" FORCE) if (DEFINED ANDROID_ABI AND NOT DEFINED VCPKG_CHAINLOAD_TOOLCHAIN_FILE) # CmakePresets.json doesn't allow us to use cmake vars in values, so set it here set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE $ENV{ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake) endif() +include("submodules/devkits/cmake/platform-${VCPKG_TARGET_TRIPLET}.cmake" OPTIONAL) + project(nakama-sdk LANGUAGES CXX) include(cmake/platformSupport.cmake) @@ -98,6 +99,8 @@ include(cmake/linkerFlags.cmake) include(GNUInstallDirs) include(FetchContent) +include(InstallRequiredSystemLibraries) + set(CMAKE_CXX_STANDARD 17) option(LOGS_ENABLED "Enable log output" ON) @@ -147,74 +150,7 @@ endif() if(WS_IMPL STREQUAL "libhttpclient" OR HTTP_IMPL STREQUAL "libhttpclient") if (NOT LIBHTTPCLIENT_BUILTIN) - if (LINUX OR APPLE) - find_package(CURL CONFIG REQUIRED) - target_compile_definitions(CURL::libcurl INTERFACE CURL_STRICTER) - endif() - - if (ANDROID) - set(LIBHTTPCLIENT_SOURCE_SUBDIR Utilities/CMake/Android/libHttpClient) - set(LIBHTTPCLIENT_TARGET libHttpClient.Android) - else() - set(LIBHTTPCLIENT_SOURCE_SUBDIR Utilities/CMake) - - if(XDK) - if (WINRT) - set(LIBHTTPCLIENT_TARGET libHttpClient.XDK.WinRT) - else() - set(LIBHTTPCLIENT_TARGET libHttpClient.XDK.C) - endif() - elseif (BUILDWIN32) - set(LIBHTTPCLIENT_TARGET libHttpClient.Win32.C) - elseif (GDK) - set(LIBHTTPCLIENT_TARGET libHttpClient.GDK.C) - elseif (APPLE) - set(LIBHTTPCLIENT_TARGET libHttpClient.Apple.C) - elseif(DEFINED LINUX) - set(LIBHTTPCLIENT_TARGET libHttpClient.Linux.C) - else() - if (WINRT) - set(LIBHTTPCLIENT_TARGET libHttpClient.UWP.WinRT) - else() - set(LIBHTTPCLIENT_TARGET libHttpClient.UWP.C) - endif() - endif() - endif() - - # We build LIBHTTPCLIENT as OBJECT library so that its symbols - # wont be excluded due to '--exclude-libs ALL' linker flag. Although we - # dont expose libhttpclient in our API , we still want it's symbols exported - # in our ABI, because that is how JVM finds native code on Android platform. - list(APPEND NAKAMA_SDK_DEPS ${LIBHTTPCLIENT_TARGET}) - - set(LIBHTTPCLIENT_OBJECT_LIBRARY TRUE) - set(WAS_SHARED_LIBS ${BUILD_SHARED_LIBS}) - - ## force libhttpclient to build statically - set(BUILD_SHARED_LIBS OFF) - FetchContent_Declare( - libHttpClient - GIT_REPOSITORY https://github.com/heroiclabs/libHttpClient.git - GIT_TAG c535d5943516bb5d8f3a50858da617ebd0dd3f3f - SOURCE_SUBDIR ${LIBHTTPCLIENT_SOURCE_SUBDIR} - GIT_PROGRESS TRUE - GIT_SHALLOW TRUE - USES_TERMINAL_DOWNLOAD TRUE - ) - - FetchContent_MakeAvailable(libHttpClient) - if (${WAS_SHARED_LIBS}) - set(BUILD_SHARED_LIBS ON) - endif() - - if (NOT WS_IMPL STREQUAL "libhttpclient") - target_compile_definitions(${LIBHTTPCLIENT_TARGET} PRIVATE "HC_NOWEBSOCKETS") - else() - if (LIBHTTPCLIENT_FORCE_WEBSOCKETPP) - message(STATUS "Forcing libhttpclient to use websocketpp even on modern Windows platforms") - target_compile_definitions(${LIBHTTPCLIENT_TARGET} PRIVATE "HC_FORCE_WINSOCKETPP") - endif() - endif() + include(cmake/libhttpClient.cmake) endif() endif() diff --git a/CMakePresets.json b/CMakePresets.json index f614e00c0..d1b17d5f3 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -1,8 +1,8 @@ { - "version": 3, + "version": 6, "cmakeMinimumRequired": { "major": 3, - "minor": 21, + "minor": 29, "patch": 0 }, "configurePresets": [ @@ -12,9 +12,10 @@ "description": "No shipped websocket or http implementation.", "binaryDir": "build/${presetName}", "hidden": true, + "toolchainFile": "${sourceDir}/submodules/vcpkg/scripts/buildsystems/vcpkg.cmake", "cacheVariables": { - "LOGS_ENABLED": "ON", - "CMAKE_INSTALL_DEFAULT_COMPONENT_NAME": "nakama-sdk" + "CMAKE_INSTALL_DEFAULT_COMPONENT_NAME": "nakama-sdk", + "VCPKG_OVERLAY_TRIPLETS": "${sourceDir}/cmake/triplets;${sourceDir}/submodules/devkits/cmake/triplets" } }, { @@ -22,9 +23,9 @@ "inherits": [ "default" ], - "generator": "Visual Studio 17 2022", + "generator": "Ninja Multi-Config", "cacheVariables": { - "WindowsDesktop": "ON", + "CMAKE_SYSTEM_PROCESSOR": "AMD64", "VCPKG_HOST_TRIPLET": "x64-windows-static-heroic", "VCPKG_TARGET_TRIPLET": "x64-windows-static-heroic", "BUILD_WSLAY": "ON", @@ -44,9 +45,9 @@ "inherits": [ "default" ], - "generator": "Visual Studio 17 2022", + "generator": "Ninja Multi-Config", "cacheVariables": { - "WindowsDesktop": "ON", + "CMAKE_SYSTEM_PROCESSOR": "arm64", "VCPKG_HOST_TRIPLET": "arm64-windows-static-heroic", "VCPKG_TARGET_TRIPLET": "arm64-windows-static-heroic", "BUILD_WSLAY": "ON", @@ -61,29 +62,6 @@ }, "installDir": "out/win-arm64" }, - { - "name": "win-x86", - "inherits": [ - "default" - ], - "generator": "Visual Studio 17 2022", - "architecture": "Win32", - "cacheVariables": { - "WindowsDesktop": "ON", - "VCPKG_HOST_TRIPLET": "x86-windows-release", - "VCPKG_TARGET_TRIPLET": "x86-windows-release", - "BUILD_WSLAY": "ON", - "BUILD_CURL_IO": "ON", - "BUILD_CURL_HTTP": "ON", - "VCPKG_MANIFEST_FEATURES": "wslay;curl" - }, - "condition": { - "type": "equals", - "lhs": "${hostSystemName}", - "rhs": "Windows" - }, - "installDir": "out/win-x86" - }, { "name": "macosx-arm64-host_arm64", "inherits": [ @@ -406,4 +384,4 @@ "installDir": "out/android-x64" } ] -} \ No newline at end of file +} diff --git a/cmake/checkPresets.cmake b/cmake/checkPresets.cmake new file mode 100644 index 000000000..9deb1eeb4 --- /dev/null +++ b/cmake/checkPresets.cmake @@ -0,0 +1,9 @@ +if (EXISTS "${CMAKE_SOURCE_DIR}/CMakeUserPresets.json" AND EXISTS "${CMAKE_SOURCE_DIR}/submodules/private/CMakeUserPresets.json") + file(MD5 "${CMAKE_SOURCE_DIR}/CMakeUserPresets.json" LOCAL_USER_PRESETS_MD5) + file(MD5 "${CMAKE_SOURCE_DIR}/submodules/private/CMakeUserPresets.json" PRIVATE_USER_PRESETS_MD5) + if (NOT LOCAL_USER_PRESETS_MD5 STREQUAL PRIVATE_USER_PRESETS_MD5) + message(FATAL_ERROR "CMakeUserPresets.json from private repo was updated, but not copied to the project dir.") + endif() +endif() +unset(LOCAL_USER_PRESETS_MD5) +unset(PRIVATE_USER_PRESETS_MD5) diff --git a/cmake/libhttpClient.cmake b/cmake/libhttpClient.cmake new file mode 100644 index 000000000..4d3f891a3 --- /dev/null +++ b/cmake/libhttpClient.cmake @@ -0,0 +1,76 @@ +if (LINUX OR APPLE) + find_package(CURL CONFIG REQUIRED) + target_compile_definitions(CURL::libcurl INTERFACE CURL_STRICTER) +endif() + + +set(LIBHTTPCLIENT_OBJECT_LIBRARY TRUE) +set(WAS_SHARED_LIBS ${BUILD_SHARED_LIBS}) + +if (ANDROID) + set(LIBHTTPCLIENT_SOURCE_SUBDIR Utilities/CMake/Android/libHttpClient) +else() + set(LIBHTTPCLIENT_SOURCE_SUBDIR Utilities/CMake) +endif() + +## force libhttpclient to build statically +set(BUILD_SHARED_LIBS OFF) +FetchContent_Declare( + libHttpClient + GIT_REPOSITORY https://github.com/heroiclabs/libHttpClient.git + GIT_TAG c535d5943516bb5d8f3a50858da617ebd0dd3f3f + SOURCE_SUBDIR ${LIBHTTPCLIENT_SOURCE_SUBDIR} + GIT_PROGRESS TRUE + GIT_SHALLOW TRUE + GIT_SUBMODULES "" +) + +FetchContent_MakeAvailable(libHttpClient) +if (${WAS_SHARED_LIBS}) + set(BUILD_SHARED_LIBS ON) +endif() + +if (ANDROID) + set(LIBHTTPCLIENT_TARGET libHttpClient.Android) +else() + + if(XDK) + if (WINRT) + set(LIBHTTPCLIENT_TARGET libHttpClient.XDK.WinRT) + else() + set(LIBHTTPCLIENT_TARGET libHttpClient.XDK.C) + endif() + elseif (GDK) + set(LIBHTTPCLIENT_TARGET libHttpClient.GDK.C) + include(submodules/devkits/cmake/gdk-targets.cmake) + target_link_libraries(${LIBHTTPCLIENT_TARGET} PRIVATE GDK::XCurl) + elseif (BUILDWIN32) + set(LIBHTTPCLIENT_TARGET libHttpClient.Win32.C) + elseif (APPLE) + set(LIBHTTPCLIENT_TARGET libHttpClient.Apple.C) + elseif(DEFINED LINUX) + set(LIBHTTPCLIENT_TARGET libHttpClient.Linux.C) + else() + if (WINRT) + set(LIBHTTPCLIENT_TARGET libHttpClient.UWP.WinRT) + else() + set(LIBHTTPCLIENT_TARGET libHttpClient.UWP.C) + endif() + endif() +endif() + +# We build LIBHTTPCLIENT as OBJECT library so that its symbols +# wont be excluded due to '--exclude-libs ALL' linker flag. Although we +# dont expose libhttpclient in our API , we still want it's symbols exported +# in our ABI, because that is how JVM finds native code on Android platform. +list(APPEND NAKAMA_SDK_DEPS ${LIBHTTPCLIENT_TARGET}) + + +if (NOT WS_IMPL STREQUAL "libhttpclient") + target_compile_definitions(${LIBHTTPCLIENT_TARGET} PRIVATE "HC_NOWEBSOCKETS") +else() + if (LIBHTTPCLIENT_FORCE_WEBSOCKETPP) + message(STATUS "Forcing libhttpclient to use websocketpp even on modern Windows platforms") + target_compile_definitions(${LIBHTTPCLIENT_TARGET} PRIVATE "HC_FORCE_WINSOCKETPP") + endif() +endif() diff --git a/cmake/platformSupport.cmake b/cmake/platformSupport.cmake index 963fc9195..2976067f7 100644 --- a/cmake/platformSupport.cmake +++ b/cmake/platformSupport.cmake @@ -1,5 +1,9 @@ -# Various platform specific defines +# NDAed platforms might configure it already +if (__PLATFORM_SUPPORT_CONFIGURED) + return() +endif() +# Various platform specific defines if (CMAKE_SYSTEM_NAME STREQUAL Windows OR WindowsDesktop) set(WindowsDesktop ON) message("Configuring Windows Desktop build") @@ -35,3 +39,5 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") find_package(Threads REQUIRED) set(PTHREADS_LIB Threads::Threads) endif() + +set(__PLATFORM_SUPPORT_CONFIGURED ON) \ No newline at end of file diff --git a/cmake/toolchains/msvc/VSWhere.cmake b/cmake/toolchains/msvc/VSWhere.cmake new file mode 100644 index 000000000..c2ea310a9 --- /dev/null +++ b/cmake/toolchains/msvc/VSWhere.cmake @@ -0,0 +1,132 @@ +#---------------------------------------------------------------------------------------------------------------------- +# MIT License +# +# Copyright (c) 2021 Mark Schofield +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +#---------------------------------------------------------------------------------------------------------------------- +include_guard() + +#[[==================================================================================================================== + toolchain_validate_vs_files + --------------------------- + + Note: Not supported for consumption outside of the toolchain files. + + Validates the the specified folder exists and contains the specified files. + + toolchain_validate_vs_files( + > + > + ...> + ) + + If the folder or files are missing, then a FATAL_ERROR is reported. +====================================================================================================================]]# +function(toolchain_validate_vs_files) + set(OPTIONS) + set(ONE_VALUE_KEYWORDS FOLDER DESCRIPTION) + set(MULTI_VALUE_KEYWORDS FILES) + + cmake_parse_arguments(PARSE_ARGV 0 VS "${OPTIONS}" "${ONE_VALUE_KEYWORDS}" "${MULTI_VALUE_KEYWORDS}") + + if(NOT EXISTS ${VS_FOLDER}) + message(FATAL_ERROR "Folder not present - ${VS_FOLDER} - ensure that the ${VS_DESCRIPTION} are installed with Visual Studio.") + endif() + + foreach(FILE ${VS_FILES}) + if(NOT EXISTS "${VS_FOLDER}/${FILE}") + message(FATAL_ERROR "File not present - ${VS_FOLDER}/${FILE} - ensure that the ${VS_DESCRIPTION} are installed with Visual Studio.") + endif() + endforeach() +endfunction() + +#[[==================================================================================================================== + findVisualStudio + ---------------- + + Finds a Visual Studio instance, and sets CMake variables based on properties of the found instance. + + findVisualStudio( + [VERSION ] + [PRERELEASE ] + [PRODUCTS ] + [REQUIRES ...] + PROPERTIES + < > + ) +====================================================================================================================]]# +function(findVisualStudio) + set(OPTIONS) + set(ONE_VALUE_KEYWORDS VERSION PRERELEASE PRODUCTS) + set(MULTI_VALUE_KEYWORDS REQUIRES PROPERTIES) + + cmake_parse_arguments(PARSE_ARGV 0 FIND_VS "${OPTIONS}" "${ONE_VALUE_KEYWORDS}" "${MULTI_VALUE_KEYWORDS}") + + find_program(VSWHERE_PATH + NAMES vswhere vswhere.exe + HINTS "$ENV{ProgramFiles\(x86\)}/Microsoft Visual Studio/Installer" + ) + + if(VSWHERE_PATH STREQUAL "VSWHERE_PATH-NOTFOUND") + message(FATAL_ERROR "'vswhere' isn't found.") + endif() + + set(VSWHERE_COMMAND ${VSWHERE_PATH} -latest) + + if(FIND_VS_PRERELEASE) + list(APPEND VSWHERE_COMMAND -prerelease) + endif() + + if(FIND_VS_PRODUCTS) + list(APPEND VSWHERE_COMMAND -products ${FIND_VS_PRODUCTS}) + endif() + + if(FIND_VS_REQUIRES) + list(APPEND VSWHERE_COMMAND -requires ${FIND_VS_REQUIRES}) + endif() + + if(FIND_VS_VERSION) + list(APPEND VSWHERE_COMMAND -version "${FIND_VS_VERSION}") + endif() + + message(VERBOSE "findVisualStudio: VSWHERE_COMMAND = ${VSWHERE_COMMAND}") + + execute_process( + COMMAND ${VSWHERE_COMMAND} + OUTPUT_VARIABLE VSWHERE_OUTPUT + ) + + message(VERBOSE "findVisualStudio: VSWHERE_OUTPUT = ${VSWHERE_OUTPUT}") + + # Matches `VSWHERE_PROPERTY` in the `VSWHERE_OUTPUT` text in the format written by vswhere. + # The matched value is assigned to the variable `VARIABLE_NAME` in the parent scope. + function(getVSWhereProperty VSWHERE_OUTPUT VSWHERE_PROPERTY VARIABLE_NAME) + string(REGEX MATCH "${VSWHERE_PROPERTY}: [^\r\n]*" VSWHERE_VALUE "${VSWHERE_OUTPUT}") + string(REPLACE "${VSWHERE_PROPERTY}: " "" VSWHERE_VALUE "${VSWHERE_VALUE}") + set(${VARIABLE_NAME} "${VSWHERE_VALUE}" PARENT_SCOPE) + endfunction() + + while(FIND_VS_PROPERTIES) + list(POP_FRONT FIND_VS_PROPERTIES VSWHERE_PROPERTY) + list(POP_FRONT FIND_VS_PROPERTIES VSWHERE_CMAKE_VARIABLE) + getVSWhereProperty("${VSWHERE_OUTPUT}" ${VSWHERE_PROPERTY} VSWHERE_VALUE) + set(${VSWHERE_CMAKE_VARIABLE} ${VSWHERE_VALUE} PARENT_SCOPE) + endwhile() +endfunction() diff --git a/cmake/toolchains/msvc/Windows.Kits.cmake b/cmake/toolchains/msvc/Windows.Kits.cmake new file mode 100644 index 000000000..72228f386 --- /dev/null +++ b/cmake/toolchains/msvc/Windows.Kits.cmake @@ -0,0 +1,155 @@ +#---------------------------------------------------------------------------------------------------------------------- +# MIT License +# +# Copyright (c) 2021 Mark Schofield +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +#---------------------------------------------------------------------------------------------------------------------- +# +# | CMake Variable | Description | +# |-----------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------| +# | CMAKE_SYSTEM_VERSION | The version of the operating system for which CMake is to build. Defaults to the host version. | +# | CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE | The architecture of the tooling to use. Defaults to 'arm64' on ARM64 systems, otherwise 'x64'. | +# | CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION | The version of the Windows SDK to use. Defaults to the highest installed, that is no higher than CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION_MAXIMUM | +# | CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION_MAXIMUM | The maximum version of the Windows SDK to use, for example '10.0.19041.0'. Defaults to nothing | +# | CMAKE_WINDOWS_KITS_10_DIR | The location of the root of the Windows Kits 10 directory. | +# +# The following variables will be set: +# +# | CMake Variable | Description | +# |---------------------------------------------|-------------------------------------------------------------------------------------------------------| +# | CMAKE_MT | The path to the 'mt' tool. | +# | CMAKE_RC_COMPILER | The path to the 'rc' tool. | +# | CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION | The version of the Windows SDK to be used. | +# | MDMERGE_TOOL | The path to the 'mdmerge' tool. | +# | MIDL_COMPILER | The path to the 'midl' compiler. | +# | WINDOWS_KITS_BIN_PATH | The path to the folder containing the Windows Kits binaries. | +# | WINDOWS_KITS_INCLUDE_PATH | The path to the folder containing the Windows Kits include files. | +# | WINDOWS_KITS_LIB_PATH | The path to the folder containing the Windows Kits library files. | +# | WINDOWS_KITS_REFERENCES_PATH | The path to the folder containing the Windows Kits references. | +# +include_guard() + +if(NOT CMAKE_SYSTEM_VERSION) + set(CMAKE_SYSTEM_VERSION ${CMAKE_HOST_SYSTEM_VERSION}) +endif() + +if(NOT CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE) + if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL ARM64) + set(CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE arm64) + else() + set(CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE x64) + endif() +endif() + +if(NOT CMAKE_WINDOWS_KITS_10_DIR) + get_filename_component(CMAKE_WINDOWS_KITS_10_DIR "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v10.0;InstallationFolder]" ABSOLUTE CACHE) + if ("${CMAKE_WINDOWS_KITS_10_DIR}" STREQUAL "/registry") + unset(CMAKE_WINDOWS_KITS_10_DIR) + endif() +endif() + +if(NOT CMAKE_WINDOWS_KITS_10_DIR) + message(FATAL_ERROR "Unable to find an installed Windows SDK, and one wasn't specified.") +endif() + +# If a CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION wasn't specified, find the highest installed version that is no higher +# than the host version +if(NOT CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION) + file(GLOB WINDOWS_KITS_VERSIONS RELATIVE "${CMAKE_WINDOWS_KITS_10_DIR}/lib" "${CMAKE_WINDOWS_KITS_10_DIR}/lib/*") + list(FILTER WINDOWS_KITS_VERSIONS INCLUDE REGEX "10\\.0\\.") + list(SORT WINDOWS_KITS_VERSIONS COMPARE NATURAL ORDER DESCENDING) + while(WINDOWS_KITS_VERSIONS) + list(POP_FRONT WINDOWS_KITS_VERSIONS CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION) + if(NOT CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION_MAXIMUM) + message(VERBOSE "Windows.Kits: Defaulting version: ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}") + break() + endif() + + if(CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION VERSION_LESS_EQUAL CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION_MAXIMUM) + message(VERBOSE "Windows.Kits: Choosing version: ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}") + break() + endif() + + message(VERBOSE "Windows.Kits: Not suitable: ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}") + set(CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION) + endwhile() +endif() + +if(NOT CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION) + message(FATAL_ERROR "A Windows SDK could not be found.") +endif() + +list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION) + +set(WINDOWS_KITS_BIN_PATH "${CMAKE_WINDOWS_KITS_10_DIR}/bin/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}" CACHE PATH "" FORCE) +set(WINDOWS_KITS_INCLUDE_PATH "${CMAKE_WINDOWS_KITS_10_DIR}/include/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}" CACHE PATH "" FORCE) +set(WINDOWS_KITS_LIB_PATH "${CMAKE_WINDOWS_KITS_10_DIR}/lib/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}" CACHE PATH "" FORCE) +set(WINDOWS_KITS_REFERENCES_PATH "${CMAKE_WINDOWS_KITS_10_DIR}/References" CACHE PATH "" FORCE) +set(WINDOWS_KITS_PLATFORM_PATH "${CMAKE_WINDOWS_KITS_10_DIR}/Platforms/UAP/${CMAKE_SYSTEM_VERSION}/Platform.xml" CACHE PATH "" FORCE) + +if(NOT EXISTS ${WINDOWS_KITS_BIN_PATH}) + message(FATAL_ERROR "Windows SDK ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION} cannot be found: Folder '${WINDOWS_KITS_BIN_PATH}' does not exist.") +endif() + +if(NOT EXISTS ${WINDOWS_KITS_INCLUDE_PATH}) + message(FATAL_ERROR "Windows SDK ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION} cannot be found: Folder '${WINDOWS_KITS_INCLUDE_PATH}' does not exist.") +endif() + +if(NOT EXISTS ${WINDOWS_KITS_LIB_PATH}) + message(FATAL_ERROR "Windows SDK ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION} cannot be found: Folder '${WINDOWS_KITS_LIB_PATH}' does not exist.") +endif() + +set(CMAKE_MT "${WINDOWS_KITS_BIN_PATH}/${CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE}/mt.exe") +set(CMAKE_RC_COMPILER_INIT "${WINDOWS_KITS_BIN_PATH}/${CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE}/rc.exe") +set(CMAKE_RC_FLAGS_INIT "/nologo") + +set(MIDL_COMPILER "${WINDOWS_KITS_BIN_PATH}/${CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE}/midl.exe") +set(MDMERGE_TOOL "${WINDOWS_KITS_BIN_PATH}/${CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE}/mdmerge.exe") + +# Windows SDK +if(CMAKE_SYSTEM_PROCESSOR STREQUAL AMD64) + set(WINDOWS_KITS_TARGET_ARCHITECTURE x64) +elseif((CMAKE_SYSTEM_PROCESSOR STREQUAL ARM) + OR (CMAKE_SYSTEM_PROCESSOR STREQUAL ARM64) + OR (CMAKE_SYSTEM_PROCESSOR STREQUAL X86)) + set(WINDOWS_KITS_TARGET_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR}) +elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL x64) + message(WARNING "CMAKE_SYSTEM_PROCESSOR should be 'AMD64', not 'x64'. WindowsToolchain will stop recognizing 'x64' in a future release.") + set(WINDOWS_KITS_TARGET_ARCHITECTURE x64) +elseif((CMAKE_SYSTEM_PROCESSOR STREQUAL arm) + OR (CMAKE_SYSTEM_PROCESSOR STREQUAL arm64) + OR (CMAKE_SYSTEM_PROCESSOR STREQUAL x86)) + message(WARNING "CMAKE_SYSTEM_PROCESSOR (${CMAKE_SYSTEM_PROCESSOR}) should be upper-case. WindowsToolchain will stop recognizing non-upper-case forms in a future release.") + set(WINDOWS_KITS_TARGET_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR}) +else() + message(FATAL_ERROR "Unable identify Windows Kits architecture for CMAKE_SYSTEM_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR}") +endif() + +foreach(LANG C CXX RC) + list(APPEND CMAKE_${LANG}_STANDARD_INCLUDE_DIRECTORIES "${WINDOWS_KITS_INCLUDE_PATH}/ucrt") + list(APPEND CMAKE_${LANG}_STANDARD_INCLUDE_DIRECTORIES "${WINDOWS_KITS_INCLUDE_PATH}/shared") + list(APPEND CMAKE_${LANG}_STANDARD_INCLUDE_DIRECTORIES "${WINDOWS_KITS_INCLUDE_PATH}/um") + list(APPEND CMAKE_${LANG}_STANDARD_INCLUDE_DIRECTORIES "${WINDOWS_KITS_INCLUDE_PATH}/winrt") + list(APPEND CMAKE_${LANG}_STANDARD_INCLUDE_DIRECTORIES "${WINDOWS_KITS_INCLUDE_PATH}/cppwinrt") +endforeach() + +link_directories(BEFORE "${WINDOWS_KITS_LIB_PATH}/ucrt/${WINDOWS_KITS_TARGET_ARCHITECTURE}") +link_directories(BEFORE "${WINDOWS_KITS_LIB_PATH}/um/${WINDOWS_KITS_TARGET_ARCHITECTURE}") +link_directories(BEFORE "${WINDOWS_KITS_REFERENCES_PATH}/${WINDOWS_KITS_TARGET_ARCHITECTURE}") diff --git a/cmake/toolchains/msvc/Windows.MSVC.toolchain.cmake b/cmake/toolchains/msvc/Windows.MSVC.toolchain.cmake new file mode 100644 index 000000000..ac81c8d9f --- /dev/null +++ b/cmake/toolchains/msvc/Windows.MSVC.toolchain.cmake @@ -0,0 +1,247 @@ +#---------------------------------------------------------------------------------------------------------------------- +# MIT License +# +# Copyright (c) 2021 Mark Schofield +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +#---------------------------------------------------------------------------------------------------------------------- +# +# This CMake toolchain file configures a CMake, non-'Visual Studio Generator' build to use +# the MSVC compilers and tools. +# +# The following variables can be used to configure the behavior of this toolchain file: +# +# | CMake Variable | Description | +# |---------------------------------------------|--------------------------------------------------------------------------------------------------------------------------| +# | CMAKE_SYSTEM_PROCESSOR | The processor to compiler for. One of 'X86', 'AMD64', 'ARM', 'ARM64'. Defaults to ${CMAKE_HOST_SYSTEM_PROCESSOR}. | +# | CMAKE_SYSTEM_VERSION | The version of the operating system for which CMake is to build. Defaults to the host version. | +# | CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE | The architecture of the tooling to use. Defaults to 'arm64' on ARM64 systems, otherwise 'x64'. | +# | CMAKE_VS_PRODUCTS | One or more Visual Studio Product IDs to consider. Defaults to '*' | +# | CMAKE_VS_VERSION_PRERELEASE | Whether 'prerelease' versions of Visual Studio should be considered. Defaults to 'OFF' | +# | CMAKE_VS_VERSION_RANGE | A verson range for VS instances to find. For example, '[16.0,17.0)' will find versions '16.*'. Defaults to '[16.0,17.0)' | +# | CMAKE_WINDOWS_KITS_10_DIR | The location of the root of the Windows Kits 10 directory. | +# | VS_EXPERIMENTAL_MODULE | Whether experimental module support should be enabled. | +# | VS_INSTALLATION_PATH | The location of the root of the Visual Studio installation. If not specified VSWhere will be used to search for one. | +# | VS_PLATFORM_TOOLSET_VERSION | The version of the MSVC toolset to use. For example, 14.29.30133. Defaults to the highest available. | +# | VS_USE_SPECTRE_MITIGATION_ATLMFC_RUNTIME | Whether the compiler should link with the ATLMFC runtime that uses 'Spectre' mitigations. Defaults to 'OFF'. | +# | VS_USE_SPECTRE_MITIGATION_RUNTIME | Whether the compiler should link with a runtime that uses 'Spectre' mitigations. Defaults to 'OFF'. | +# +# The toolchain file will set the following variables: +# +# | CMake Variable | Description | +# |---------------------------------------------|-------------------------------------------------------------------------------------------------------| +# | CMAKE_C_COMPILER | The path to the C compiler to use. | +# | CMAKE_CXX_COMPILER | The path to the C++ compiler to use. | +# | CMAKE_MT | The path to the 'mt.exe' tool to use. | +# | CMAKE_RC_COMPILER | The path tp the 'rc.exe' tool to use. | +# | CMAKE_SYSTEM_NAME | Windows | +# | CMAKE_VS_PLATFORM_TOOLSET_VERSION | The version of the MSVC toolset being used - e.g. 14.29.30133. | +# | WIN32 | 1 | +# | MSVC | 1 | +# | MSVC_VERSION | The '' version of the C++ compiler being used. For example, '1929' | +# +# Other configuration: +# +# * If the 'CMAKE_CUDA_COMPILER' is set, and 'CMAKE_CUDA_HOST_COMPILER' is not set, and ENV{CUDAHOSTCXX} not defined +# then 'CMAKE_CUDA_HOST_COMPILER' is set to the value of 'CMAKE_CXX_COMPILER'. +# +# Resources: +# +# +cmake_minimum_required(VERSION 3.20) + +include_guard() + +if(NOT (CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)) + return() +endif() + +set(UNUSED ${CMAKE_TOOLCHAIN_FILE}) # Note: only to prevent cmake unused variable warninig +set(CMAKE_SYSTEM_NAME Windows) +list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES + CMAKE_CROSSCOMPILING + CMAKE_SYSTEM_PROCESSOR + CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE + CMAKE_VS_PRODUCTS + CMAKE_VS_VERSION_PRERELEASE + CMAKE_VS_VERSION_RANGE + VS_INSTALLATION_PATH + VS_INSTALLATION_VERSION + VS_PLATFORM_TOOLSET_VERSION +) +set(CMAKE_CROSSCOMPILING TRUE) +set(WIN32 1) +set(MSVC 1) + +include("${CMAKE_CURRENT_LIST_DIR}/VSWhere.cmake") + +if(NOT CMAKE_SYSTEM_PROCESSOR) + set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR}) +endif() + +if(NOT CMAKE_VS_VERSION_RANGE) + set(CMAKE_VS_VERSION_RANGE "[16.0,)") +endif() + +if(NOT CMAKE_VS_VERSION_PRERELEASE) + set(CMAKE_VS_VERSION_PRERELEASE OFF) +endif() + +if(NOT CMAKE_VS_PRODUCTS) + set(CMAKE_VS_PRODUCTS "*") +endif() + +if(NOT CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE) + if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL ARM64) + set(CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE arm64) + else() + set(CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE x64) + endif() +endif() + +if(NOT VS_USE_SPECTRE_MITIGATION_RUNTIME) + set(VS_USE_SPECTRE_MITIGATION_RUNTIME OFF) +endif() + +# Find Visual Studio +# +if(NOT VS_INSTALLATION_PATH) + findVisualStudio( + VERSION ${CMAKE_VS_VERSION_RANGE} + PRERELEASE ${CMAKE_VS_VERSION_PRERELEASE} + PRODUCTS ${CMAKE_VS_PRODUCTS} + PROPERTIES + installationVersion VS_INSTALLATION_VERSION + installationPath VS_INSTALLATION_PATH + ) +endif() + +message(VERBOSE "VS_INSTALLATION_VERSION = ${VS_INSTALLATION_VERSION}") +message(VERBOSE "VS_INSTALLATION_PATH = ${VS_INSTALLATION_PATH}") + +if(NOT VS_INSTALLATION_PATH) + message(FATAL_ERROR "Unable to find Visual Studio") +endif() + +cmake_path(NORMAL_PATH VS_INSTALLATION_PATH) + +set(VS_MSVC_PATH "${VS_INSTALLATION_PATH}/VC/Tools/MSVC") + +# Use 'VS_PLATFORM_TOOLSET_VERSION' to resolve 'CMAKE_VS_PLATFORM_TOOLSET_VERSION' +# +if(NOT VS_PLATFORM_TOOLSET_VERSION) + if(VS_TOOLSET_VERSION) + message(WARNING "Old versions of WindowsToolchain incorrectly used 'VS_TOOLSET_VERSION' to specify the VS toolset version. This functionality is being deprecated - please use 'VS_PLATFORM_TOOLSET_VERSION' instead.") + set(VS_PLATFORM_TOOLSET_VERSION ${VS_TOOLSET_VERSION}) + else() + file(GLOB VS_PLATFORM_TOOLSET_VERSIONS RELATIVE ${VS_MSVC_PATH} ${VS_MSVC_PATH}/*) + list(SORT VS_PLATFORM_TOOLSET_VERSIONS COMPARE NATURAL ORDER DESCENDING) + list(POP_FRONT VS_PLATFORM_TOOLSET_VERSIONS VS_PLATFORM_TOOLSET_VERSION) + unset(VS_PLATFORM_TOOLSET_VERSIONS) + endif() +endif() + +set(CMAKE_VS_PLATFORM_TOOLSET_VERSION ${VS_PLATFORM_TOOLSET_VERSION}) +set(VS_TOOLSET_PATH "${VS_INSTALLATION_PATH}/VC/Tools/MSVC/${CMAKE_VS_PLATFORM_TOOLSET_VERSION}") + +# Set the tooling variables, include_directories and link_directories +# + +# Map CMAKE_SYSTEM_PROCESSOR values to CMAKE_VS_PLATFORM_TOOLSET_ARCHITECTURE that identifies the tools that should +# be used to produce code for the CMAKE_SYSTEM_PROCESSOR. +if(CMAKE_SYSTEM_PROCESSOR STREQUAL AMD64) + set(CMAKE_VS_PLATFORM_TOOLSET_ARCHITECTURE x64) +elseif((CMAKE_SYSTEM_PROCESSOR STREQUAL ARM) + OR (CMAKE_SYSTEM_PROCESSOR STREQUAL ARM64) + OR (CMAKE_SYSTEM_PROCESSOR STREQUAL X86)) + set(CMAKE_VS_PLATFORM_TOOLSET_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR}) +elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL x64) + message(WARNING "CMAKE_SYSTEM_PROCESSOR should be 'AMD64', not 'x64'. WindowsToolchain will stop recognizing 'x64' in a future release.") + set(CMAKE_VS_PLATFORM_TOOLSET_ARCHITECTURE x64) +elseif((CMAKE_SYSTEM_PROCESSOR STREQUAL arm) + OR (CMAKE_SYSTEM_PROCESSOR STREQUAL arm64) + OR (CMAKE_SYSTEM_PROCESSOR STREQUAL x86)) + message(WARNING "CMAKE_SYSTEM_PROCESSOR (${CMAKE_SYSTEM_PROCESSOR}) should be upper-case. WindowsToolchain will stop recognizing non-upper-case forms in a future release.") + set(CMAKE_VS_PLATFORM_TOOLSET_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR}) +else() + message(FATAL_ERROR "Unable identify compiler architecture for CMAKE_SYSTEM_PROCESSOR ${CMAKE_SYSTEM_PROCESSOR}") +endif() + +set(CMAKE_CXX_COMPILER "${VS_TOOLSET_PATH}/bin/Host${CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE}/${CMAKE_VS_PLATFORM_TOOLSET_ARCHITECTURE}/cl.exe") +set(CMAKE_C_COMPILER "${VS_TOOLSET_PATH}/bin/Host${CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE}/${CMAKE_VS_PLATFORM_TOOLSET_ARCHITECTURE}/cl.exe") + +if(CMAKE_SYSTEM_PROCESSOR STREQUAL ARM) + set(CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT} /EHsc") +elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL arm) + message(WARNING "CMAKE_SYSTEM_PROCESSOR (${CMAKE_SYSTEM_PROCESSOR}) should be upper-case. WindowsToolchain will stop recognizing non-upper-case forms in a future release.") + set(CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT} /EHsc") +endif() + +# Compiler +foreach(LANG C CXX RC) + list(APPEND CMAKE_${LANG}_STANDARD_INCLUDE_DIRECTORIES "${VS_TOOLSET_PATH}/ATLMFC/include") + list(APPEND CMAKE_${LANG}_STANDARD_INCLUDE_DIRECTORIES "${VS_TOOLSET_PATH}/include") +endforeach() + +if(VS_USE_SPECTRE_MITIGATION_ATLMFC_RUNTIME) + # Ensure that the necessary folder and files are present before adding the 'link_directories' + toolchain_validate_vs_files( + DESCRIPTION "ATLMFC Spectre libraries" + FOLDER "${VS_TOOLSET_PATH}/ATLMFC/lib/spectre/${CMAKE_VS_PLATFORM_TOOLSET_ARCHITECTURE}" + FILES + atls.lib + ) + link_directories("${VS_TOOLSET_PATH}/ATLMFC/lib/spectre/${CMAKE_VS_PLATFORM_TOOLSET_ARCHITECTURE}") +else() + link_directories("${VS_TOOLSET_PATH}/ATLMFC/lib/${CMAKE_VS_PLATFORM_TOOLSET_ARCHITECTURE}") +endif() + +if(VS_USE_SPECTRE_MITIGATION_RUNTIME) + # Ensure that the necessary folder and files are present before adding the 'link_directories' + toolchain_validate_vs_files( + DESCRIPTION "Spectre libraries" + FOLDER "${VS_TOOLSET_PATH}/lib/spectre/${CMAKE_VS_PLATFORM_TOOLSET_ARCHITECTURE}" + FILES + msvcrt.lib vcruntime.lib vcruntimed.lib + ) + link_directories("${VS_TOOLSET_PATH}/lib/spectre/${CMAKE_VS_PLATFORM_TOOLSET_ARCHITECTURE}") +else() + link_directories("${VS_TOOLSET_PATH}/lib/${CMAKE_VS_PLATFORM_TOOLSET_ARCHITECTURE}") +endif() + +link_directories("${VS_TOOLSET_PATH}/lib/x86/store/references") + +# Module support +if(VS_EXPERIMENTAL_MODULE) + set(CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT} /experimental:module") + set(CMAKE_CXX_FLAGS_INIT "${CMAKE_CXX_FLAGS_INIT} /stdIfcDir \"${VS_TOOLSET_PATH}/ifc/${CMAKE_VS_PLATFORM_TOOLSET_ARCHITECTURE}\"") +endif() + +# Windows Kits +include("${CMAKE_CURRENT_LIST_DIR}/Windows.Kits.cmake") + +# CUDA support +# +# If a CUDA compiler is specified, and a host compiler wasn't specified, set 'CMAKE_CXX_COMPILER' +# as the host compiler. +if(CMAKE_CUDA_COMPILER) + if((NOT CMAKE_CUDA_HOST_COMPILER) AND (NOT DEFINED ENV{CUDAHOSTCXX})) + set(CMAKE_CUDA_HOST_COMPILER "${CMAKE_CXX_COMPILER}") + endif() +endif() diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 836fecadc..168363e22 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.22) +cmake_minimum_required(VERSION 3.29) project(nakama-sdk-cpp DESCRIPTION "Nakama C++ Client" LANGUAGES CXX) set(NAKAMA_GIT_TAG "master" CACHE STRING "nakama Git tag to fetch Proto files from") diff --git a/impl/wsLibHttpClient/NWebsocketLibHC.h b/impl/wsLibHttpClient/NWebsocketLibHC.h index 23846e03a..1737f15ee 100644 --- a/impl/wsLibHttpClient/NWebsocketLibHC.h +++ b/impl/wsLibHttpClient/NWebsocketLibHC.h @@ -39,6 +39,7 @@ namespace Nakama { void disconnect() override; bool send(const NBytes& data) override; + bool isConnecting() const override { return false; }; private: explicit NWebsocketLibHC(XTaskQueueHandle q); diff --git a/impl/wsWslay/NWebsocketWslay.cpp b/impl/wsWslay/NWebsocketWslay.cpp index 609e38390..43a3b93ba 100644 --- a/impl/wsWslay/NWebsocketWslay.cpp +++ b/impl/wsWslay/NWebsocketWslay.cpp @@ -343,7 +343,7 @@ namespace Nakama { } } - bool NWebsocketWslay::isConnecting() + bool NWebsocketWslay::isConnecting() const { return _state == State::Connecting || _state == State::Handshake_Receiving || _state == State::Handshake_Sending; } diff --git a/impl/wsWslay/NWebsocketWslay.h b/impl/wsWslay/NWebsocketWslay.h index f5cabed3f..c13b2dfb4 100644 --- a/impl/wsWslay/NWebsocketWslay.h +++ b/impl/wsWslay/NWebsocketWslay.h @@ -47,7 +47,7 @@ class NWebsocketWslay : public NRtTransportInterface bool send(const NBytes& data) override; protected: - bool isConnecting() override; + bool isConnecting() const override; private: static ssize_t recv_callback(wslay_event_context_ptr ctx, uint8_t* data, size_t len, int flags, void* user_data); diff --git a/interface/config.h.in b/interface/config.h.in index bf121f447..3fd50e18b 100644 --- a/interface/config.h.in +++ b/interface/config.h.in @@ -3,4 +3,4 @@ #cmakedefine optional_CONFIG_SELECT_OPTIONAL @optional_CONFIG_SELECT_OPTIONAL@ #define @HTTP_COMPILE_DEFINITION@ #define @WS_COMPILE_DEFINITION@ -#define @WS_IO_COMPILE_DEFINITION@ +#cmakedefine @WS_IO_COMPILE_DEFINITION@ diff --git a/interface/include/nakama-cpp/realtime/NRtTransportInterface.h b/interface/include/nakama-cpp/realtime/NRtTransportInterface.h index 2d6a06771..e6dfc4547 100644 --- a/interface/include/nakama-cpp/realtime/NRtTransportInterface.h +++ b/interface/include/nakama-cpp/realtime/NRtTransportInterface.h @@ -90,7 +90,7 @@ NAKAMA_NAMESPACE_BEGIN /** * @return True if connecting to server. */ - virtual bool isConnecting() = 0; + virtual bool isConnecting() const = 0; /** * Close the connection with the server. diff --git a/submodules/devkits b/submodules/devkits new file mode 160000 index 000000000..41367da13 --- /dev/null +++ b/submodules/devkits @@ -0,0 +1 @@ +Subproject commit 41367da131ca2a825484d7dba1fdaed43092d5ad diff --git a/submodules/private b/submodules/private new file mode 160000 index 000000000..607e1687f --- /dev/null +++ b/submodules/private @@ -0,0 +1 @@ +Subproject commit 607e1687f53ce232474445621a0a9a321f0e0e00 diff --git a/submodules/vcpkg b/submodules/vcpkg new file mode 160000 index 000000000..d07689ef1 --- /dev/null +++ b/submodules/vcpkg @@ -0,0 +1 @@ +Subproject commit d07689ef165f033de5c0710e4f67c193a85373e1 diff --git a/vcpkg.json b/vcpkg.json index 5f6177c64..74f9652e6 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -91,6 +91,7 @@ } }, "overrides": [ - { "name": "curl", "version": "8.0.1" } + { "name": "curl", "version": "8.0.1" }, + { "name": "vcpkg-cmake", "version": "2024-04-23" } ] } From fa907983d746aa1e685b76f7c51ab360dce9d69f Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Mon, 30 Sep 2024 12:07:09 +0100 Subject: [PATCH 02/25] Private build fixups --- vcpkg-configuration.json | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 vcpkg-configuration.json diff --git a/vcpkg-configuration.json b/vcpkg-configuration.json deleted file mode 100644 index 2bc0e9326..000000000 --- a/vcpkg-configuration.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "registries": - [ - { - "kind": "builtin", - "baseline": "b4f29c54450ddfc7efd2989cb9d32158ae291b40", - "packages": [] - }, - { - "kind": "git", - "repository": "https://github.com/heroiclabs/nakama-vcpkg-registry", - "baseline": "8a1b872ce6626dfdba5692ffa8c5170f7e40652c", - "reference": "master", - "packages": ["nakama-sdk", "wslay"] - } - ] -} \ No newline at end of file From 31e755fb9cc2b1296f44833dad0074c7633c0260 Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Tue, 1 Oct 2024 12:06:41 +0100 Subject: [PATCH 03/25] protobuf + abseil PS5 wip --- CMakeLists.txt | 10 ++- core/common/CMakeLists.txt | 4 +- core/common/StrUtil.cpp | 8 +- submodules/devkits | 2 +- submodules/private | 2 +- vcpkg.json | 179 ++++++++++++++++++------------------- 6 files changed, 107 insertions(+), 98 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2753d9df0..7105e97e8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -213,6 +213,7 @@ if (CREATE_JAR) install(FILES ${LIBNAKAMA_AAR} DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() +find_package(absl CONFIG REQUIRED) find_package(optional-lite CONFIG REQUIRED) # SDK API add_subdirectory(interface) @@ -273,8 +274,15 @@ elseif (APPLE) endif() add_library(nakama::sdk ALIAS nakama-sdk) +find_package(Threads REQUIRED) +set(PTHREADS_LIB Threads::Threads) target_link_libraries(nakama-sdk - PUBLIC nakama::sdk-interface ${PTHREADS_LIB}) + PUBLIC + nakama::sdk-interface + ${PTHREADS_LIB} + PRIVATE + absl::synchronization +) set(DEPENDENCY_LINK_SCOPE "") if (BUILD_SHARED_LIBS) diff --git a/core/common/CMakeLists.txt b/core/common/CMakeLists.txt index 3b7791305..f7b10e94f 100644 --- a/core/common/CMakeLists.txt +++ b/core/common/CMakeLists.txt @@ -18,6 +18,8 @@ file( #set(CMAKE_INCLUDE_CURRENT_DIR ON) #set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON) +find_package(absl CONFIG REQUIRED) +find_package(Threads REQUIRED) add_library(nakama-sdk-core-common OBJECT ${srcs}) @@ -28,7 +30,7 @@ target_link_libraries(nakama-sdk-core-common nakama::api-proto $<$:nakama::grpc-proto> PRIVATE - protobuf::libprotobuf # because of StrUtil::Base64Encode + absl::strings # because of StrUtil::Base64Encode ) target_include_directories(nakama-sdk-core-common PUBLIC diff --git a/core/common/StrUtil.cpp b/core/common/StrUtil.cpp index ef23b59aa..bca667e72 100644 --- a/core/common/StrUtil.cpp +++ b/core/common/StrUtil.cpp @@ -16,7 +16,7 @@ #include #include "StrUtil.h" -#include +#include #include @@ -28,7 +28,7 @@ std::string base64Encode(const Base64Buffer& buffer) { std::string base64str; - google::protobuf::Base64Escape((const unsigned char *)buffer.data(), static_cast(buffer.size()), &base64str, true); + absl::Base64Escape(buffer, &base64str); return base64str; } @@ -37,7 +37,7 @@ std::string base64EncodeUrl(const Base64Buffer& buffer) { std::string base64str; - google::protobuf::WebSafeBase64Escape((const unsigned char *)buffer.data(), static_cast(buffer.size()), &base64str, true); + absl::WebSafeBase64Escape(buffer, &base64str); return base64str; } @@ -46,7 +46,7 @@ Base64Buffer base64DecodeUrl(const std::string& base64str) { Base64Buffer buffer; - google::protobuf::WebSafeBase64Unescape(base64str, &buffer); + absl::WebSafeBase64Unescape(base64str, &buffer); return buffer; } diff --git a/submodules/devkits b/submodules/devkits index 41367da13..27cd863e7 160000 --- a/submodules/devkits +++ b/submodules/devkits @@ -1 +1 @@ -Subproject commit 41367da131ca2a825484d7dba1fdaed43092d5ad +Subproject commit 27cd863e7d8dbc2b2537d965ab6524ed1bccb848 diff --git a/submodules/private b/submodules/private index 607e1687f..3b3423083 160000 --- a/submodules/private +++ b/submodules/private @@ -1 +1 @@ -Subproject commit 607e1687f53ce232474445621a0a9a321f0e0e00 +Subproject commit 3b34230835c1e9c0e28e7d6f2f9f51e9e0fa1ce3 diff --git a/vcpkg.json b/vcpkg.json index 74f9652e6..e3f480eed 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -1,97 +1,96 @@ { - "builtin-baseline": "b4f29c54450ddfc7efd2989cb9d32158ae291b40", - "dependencies": [ - "protobuf", + "version-date": "2024-09-27", + "name": "nakama-sdk", + "builtin-baseline": "d07689ef165f033de5c0710e4f67c193a85373e1", + "dependencies": [ + "protobuf", + "rapidjson", + "optional-lite", + { + "name": "abseil", + "features": ["cxx17"] + } + ], + "features": { + "libhttpclient-ws": { + "description": "Websockets library that delegates to other implementations.", + "supports": "windows | android", + "dependencies": [ { - "name": "rapidjson", - "version>=": "2020-09-14#2" + "name": "websocketpp", + "default-features": false, + "platform": "windows" }, - "optional-lite" - ], - "features": { - "libhttpclient-ws": { - "description": "Websockets library that delegates to other implementations.", - "supports": "windows | android", - "dependencies": [ - { - "name": "websocketpp", - "default-features": false, - "platform": "windows" - }, - { - "name": "asio", - "platform": "windows" - }, - { - "name": "openssl", - "platform": "windows" - } - ] - }, - "libhttpclient-http": { - "description": "HTTP library that delegates to other implementations.", - "supports": "windows | android | osx | ios | linux" - }, - "wslay": { - "description": "Websockets library decoupled from IO and handshakes.", - "dependencies": [ - { - "name": "wslay" - } - ], - "supports": "osx | ios | linux | android" - }, - "logs": { - "description": "Whether or not logs are enabled." - }, - "curl": { - "description": "The libcurl networking library.", - "dependencies": [ - { - "name": "curl", - "default-features": false, - "features": [ - "ssl" - ] - } - ] - }, - "libcxx": { - "description": "An alternative C++ standard library, used by Unreal Engine.", - "dependencies": [ - { - "name": "llvm", - "default-features": false, - "features": [ - "libcxx" - ], - "platform": "linux" - } - ] - }, - "grpc": { - "description": "The grpc networking protocol.", - "dependencies": [ - "grpc" - ] + { + "name": "asio", + "platform": "windows" }, - "cpprestsdk": { - "description": "Maintenance-mode HTTP library.", - "dependencies": [ - { - "name": "cpprestsdk", - "default-features": false, - "features": [ - "websockets" - ], - "platform": "android" - } - ], - "supports": "android" + { + "name": "openssl", + "platform": "windows" + } + ] + }, + "libhttpclient-http": { + "description": "HTTP library that delegates to other implementations.", + "supports": "windows | android | osx | ios | linux" + }, + "wslay": { + "description": "Websockets library decoupled from IO and handshakes.", + "dependencies": [ + { + "name": "wslay" + } + ], + "supports": "osx | ios | linux | android" + }, + "logs": { + "description": "Whether or not logs are enabled." + }, + "curl": { + "description": "The libcurl networking library.", + "dependencies": [ + { + "name": "curl", + "default-features": false, + "features": [ + "ssl" + ] } + ] }, - "overrides": [ - { "name": "curl", "version": "8.0.1" }, - { "name": "vcpkg-cmake", "version": "2024-04-23" } - ] + "libcxx": { + "description": "An alternative C++ standard library, used by Unreal Engine.", + "dependencies": [ + { + "name": "llvm", + "default-features": false, + "features": [ + "libcxx" + ], + "platform": "linux" + } + ] + }, + "grpc": { + "description": "The grpc networking protocol.", + "dependencies": [ + "grpc" + ] + }, + "cpprestsdk": { + "description": "Maintenance-mode HTTP library.", + "dependencies": [ + { + "name": "cpprestsdk", + "default-features": false, + "features": [ + "websockets" + ], + "platform": "android" + } + ], + "supports": "android" + } + } } From bddecc1ba8448a217621ad0e3e2ce9b1681821ae Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Tue, 1 Oct 2024 15:45:50 +0100 Subject: [PATCH 04/25] All dependencies built --- CMakeLists.txt | 3 --- core/common/CMakeLists.txt | 4 +--- core/common/StrUtil.cpp | 8 ++++---- submodules/private | 2 +- vcpkg.json | 6 +----- 5 files changed, 7 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7105e97e8..8b6aab28b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -213,7 +213,6 @@ if (CREATE_JAR) install(FILES ${LIBNAKAMA_AAR} DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() -find_package(absl CONFIG REQUIRED) find_package(optional-lite CONFIG REQUIRED) # SDK API add_subdirectory(interface) @@ -280,8 +279,6 @@ target_link_libraries(nakama-sdk PUBLIC nakama::sdk-interface ${PTHREADS_LIB} - PRIVATE - absl::synchronization ) set(DEPENDENCY_LINK_SCOPE "") diff --git a/core/common/CMakeLists.txt b/core/common/CMakeLists.txt index f7b10e94f..3b7791305 100644 --- a/core/common/CMakeLists.txt +++ b/core/common/CMakeLists.txt @@ -18,8 +18,6 @@ file( #set(CMAKE_INCLUDE_CURRENT_DIR ON) #set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON) -find_package(absl CONFIG REQUIRED) -find_package(Threads REQUIRED) add_library(nakama-sdk-core-common OBJECT ${srcs}) @@ -30,7 +28,7 @@ target_link_libraries(nakama-sdk-core-common nakama::api-proto $<$:nakama::grpc-proto> PRIVATE - absl::strings # because of StrUtil::Base64Encode + protobuf::libprotobuf # because of StrUtil::Base64Encode ) target_include_directories(nakama-sdk-core-common PUBLIC diff --git a/core/common/StrUtil.cpp b/core/common/StrUtil.cpp index bca667e72..ef23b59aa 100644 --- a/core/common/StrUtil.cpp +++ b/core/common/StrUtil.cpp @@ -16,7 +16,7 @@ #include #include "StrUtil.h" -#include +#include #include @@ -28,7 +28,7 @@ std::string base64Encode(const Base64Buffer& buffer) { std::string base64str; - absl::Base64Escape(buffer, &base64str); + google::protobuf::Base64Escape((const unsigned char *)buffer.data(), static_cast(buffer.size()), &base64str, true); return base64str; } @@ -37,7 +37,7 @@ std::string base64EncodeUrl(const Base64Buffer& buffer) { std::string base64str; - absl::WebSafeBase64Escape(buffer, &base64str); + google::protobuf::WebSafeBase64Escape((const unsigned char *)buffer.data(), static_cast(buffer.size()), &base64str, true); return base64str; } @@ -46,7 +46,7 @@ Base64Buffer base64DecodeUrl(const std::string& base64str) { Base64Buffer buffer; - absl::WebSafeBase64Unescape(base64str, &buffer); + google::protobuf::WebSafeBase64Unescape(base64str, &buffer); return buffer; } diff --git a/submodules/private b/submodules/private index 3b3423083..400b99dba 160000 --- a/submodules/private +++ b/submodules/private @@ -1 +1 @@ -Subproject commit 3b34230835c1e9c0e28e7d6f2f9f51e9e0fa1ce3 +Subproject commit 400b99dbae1c7972a5de5a2851cf8734c91f13b4 diff --git a/vcpkg.json b/vcpkg.json index e3f480eed..e3c75ff10 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -5,11 +5,7 @@ "dependencies": [ "protobuf", "rapidjson", - "optional-lite", - { - "name": "abseil", - "features": ["cxx17"] - } + "optional-lite" ], "features": { "libhttpclient-ws": { From 7a989dd7e35335e53572e17c29d2f96293a2859f Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Tue, 1 Oct 2024 18:05:25 +0100 Subject: [PATCH 05/25] wslay port added --- CMakePresets.json | 1 + cmake/vcpkg-ports/wslay/msvc_compat.patch | 13 +++++ cmake/vcpkg-ports/wslay/msvc_compat2.patch | 19 ++++++++ cmake/vcpkg-ports/wslay/portfile.cmake | 47 +++++++++++++++++++ cmake/vcpkg-ports/wslay/vcpkg.json | 23 +++++++++ .../wslay => impl/wsWslay}/WslayIOInterface.h | 0 6 files changed, 103 insertions(+) create mode 100644 cmake/vcpkg-ports/wslay/msvc_compat.patch create mode 100644 cmake/vcpkg-ports/wslay/msvc_compat2.patch create mode 100644 cmake/vcpkg-ports/wslay/portfile.cmake create mode 100644 cmake/vcpkg-ports/wslay/vcpkg.json rename {interface/include/nakama-cpp/realtime/wslay => impl/wsWslay}/WslayIOInterface.h (100%) diff --git a/CMakePresets.json b/CMakePresets.json index d1b17d5f3..ecd8ead23 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -15,6 +15,7 @@ "toolchainFile": "${sourceDir}/submodules/vcpkg/scripts/buildsystems/vcpkg.cmake", "cacheVariables": { "CMAKE_INSTALL_DEFAULT_COMPONENT_NAME": "nakama-sdk", + "VCPKG_OVERLAY_PORTS": "${sourceDir}/cmake/vcpkg-ports", "VCPKG_OVERLAY_TRIPLETS": "${sourceDir}/cmake/triplets;${sourceDir}/submodules/devkits/cmake/triplets" } }, diff --git a/cmake/vcpkg-ports/wslay/msvc_compat.patch b/cmake/vcpkg-ports/wslay/msvc_compat.patch new file mode 100644 index 000000000..5286e9d2d --- /dev/null +++ b/cmake/vcpkg-ports/wslay/msvc_compat.patch @@ -0,0 +1,13 @@ +diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt +index 4af972e..92e8091 100644 +--- a/lib/CMakeLists.txt ++++ b/lib/CMakeLists.txt +@@ -8,8 +8,6 @@ set(PACKAGE_VERSION "1.0.1-DEV") + set(INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/includes) + set(GEN_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/includes) + +-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror -pedantic-errors -Wno-long-long") +- + include(CheckIncludeFile) + include(TestBigEndian) + check_include_file("arpa/inet.h" HAVE_ARPA_INET_H) diff --git a/cmake/vcpkg-ports/wslay/msvc_compat2.patch b/cmake/vcpkg-ports/wslay/msvc_compat2.patch new file mode 100644 index 000000000..6269e1b4c --- /dev/null +++ b/cmake/vcpkg-ports/wslay/msvc_compat2.patch @@ -0,0 +1,19 @@ +diff --git a/lib/includes/wslay/wslay.h b/lib/includes/wslay/wslay.h +index 7ab8501..82be717 100644 +--- a/lib/includes/wslay/wslay.h ++++ b/lib/includes/wslay/wslay.h +@@ -79,6 +79,14 @@ enum wslay_io_flags { + WSLAY_MSG_MORE = 1 + }; + ++#ifdef _MSC_VER ++#ifdef _WIN64 ++typedef int64_t ssize_t; ++#else ++typedef int32_t ssize_t; ++#endif ++#endif ++ + /* + * Callback function used by wslay_frame_send() function when it needs + * to send data. The implementation of this function must send at most diff --git a/cmake/vcpkg-ports/wslay/portfile.cmake b/cmake/vcpkg-ports/wslay/portfile.cmake new file mode 100644 index 000000000..d702263a5 --- /dev/null +++ b/cmake/vcpkg-ports/wslay/portfile.cmake @@ -0,0 +1,47 @@ +set(VERSION 1.1.1) + +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO tatsuhiro-t/wslay + REF release-${VERSION} + SHA512 b42c66c738a3f33bc7de30e8975f4fb2dc60a8baef44be8d254110c8915e14cdaa4cbdd6b29184a66061fe387ec0948e896cb174a1dd8c85a97b5feedfde162e + HEAD_REF master + PATCHES + msvc_compat.patch +# msvc_compat2.patch +) + +string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "static" BUILD_STATIC) +string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "dynamic" BUILD_SHARED) + +vcpkg_check_features( + OUT_FEATURE_OPTIONS FEATURE_OPTIONS + FEATURES + windows-use-msbuild WINDOWS_USE_MSBUILD +) + +if(WINDOWS_USE_MSBUILD) + set(WINDOWS_USE_MSBUILD_OPTION "WINDOWS_USE_MSBUILD") +else() + set(WINDOWS_USE_MSBUILD_OPTION "") +endif() + +vcpkg_cmake_configure( + SOURCE_PATH ${SOURCE_PATH} + ${WINDOWS_USE_MSBUILD_OPTION} + OPTIONS + -DWSLAY_STATIC=${BUILD_STATIC} + -DWSLAY_SHARED=${BUILD_SHARED} + + # On consoles system header files are using GNU extensions + -DCMAKE_C_FLAGS_INIT="-Wno-gnu-statement-expression" +) +vcpkg_cmake_install() + +vcpkg_cmake_config_fixup(CONFIG_PATH lib/cmake/${PORT}) + +file(REMOVE_RECURSE + ${CURRENT_PACKAGES_DIR}/debug/share +) + +file(INSTALL "${SOURCE_PATH}/COPYING" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright) diff --git a/cmake/vcpkg-ports/wslay/vcpkg.json b/cmake/vcpkg-ports/wslay/vcpkg.json new file mode 100644 index 000000000..89e3f8715 --- /dev/null +++ b/cmake/vcpkg-ports/wslay/vcpkg.json @@ -0,0 +1,23 @@ +{ + "name": "wslay", + "version": "1.1.1", + "port-version": 6, + "description": "websocket library", + "homepage": "https://tatsuhiro-t.github.io/wslay/", + "license": "MIT", + "dependencies": [ + { + "name": "vcpkg-cmake", + "host": true + }, + { + "name": "vcpkg-cmake-config", + "host": true + } + ], + "features": { + "windows-use-msbuild": { + "description": "Whether or not to compile the SDK with MSBuild on Windows machines." + } + } +} diff --git a/interface/include/nakama-cpp/realtime/wslay/WslayIOInterface.h b/impl/wsWslay/WslayIOInterface.h similarity index 100% rename from interface/include/nakama-cpp/realtime/wslay/WslayIOInterface.h rename to impl/wsWslay/WslayIOInterface.h From 075b46a6bcc6ce8f259e0a64679a766774185c4d Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Wed, 2 Oct 2024 18:21:27 +0100 Subject: [PATCH 06/25] NDAed platforms build refactor --- CMakeLists.txt | 265 ++++++++---------- CMakePresets.json | 255 ++--------------- cmake/compilerFlags.cmake | 3 +- cmake/libhttpClient.cmake | 3 +- core/CMakeLists.txt | 4 +- core/buildProtoFiles.cmake | 4 +- core/common/BaseClient.cpp | 10 +- core/common/BaseClient.h | 2 +- core/common/CMakeLists.txt | 5 +- core/core-grpc/CMakeLists.txt | 11 +- core/core-rest/CMakeLists.txt | 9 +- core/core-rt/CMakeLists.txt | 12 +- core/src/CMakeLists.txt | 3 +- core/src/roots_pem.cpp | 2 +- factory/CMakeLists.txt | 27 +- factory/ClientFactory.cpp | 22 +- factory/NWebsocketsFactory.cpp | 35 +-- impl/httpCppRest/CMakeLists.txt | 1 - impl/httpCurl/CMakeLists.txt | 2 - impl/httpLibHttpClient/CMakeLists.txt | 1 - impl/wsCppRest/CMakeLists.txt | 1 - impl/wsWslay/CMakeLists.txt | 16 +- impl/wsWslay/NWebsocketWslay.cpp | 2 +- impl/wsWslay/NWebsocketWslay.h | 6 +- impl/wsWslay/WslayIOInterface.h | 4 +- interface/CMakeLists.txt | 8 - interface/config.h.in | 6 +- interface/include/nakama-cpp/ClientFactory.h | 6 +- .../include/nakama-cpp/NClientInterface.h | 2 +- .../nakama-cpp/realtime/NWebsocketsFactory.h | 10 +- submodules/private | 2 +- 31 files changed, 233 insertions(+), 506 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b6aab28b..2f4890d97 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,48 @@ cmake_minimum_required(VERSION 3.22.1) include(version.cmake) include(cmake/checkPresets.cmake) +option(WITH_HTTP_CURL "Use CURL for HTTP transport" OFF) +option(WITH_HTTP_LIBHTTPC "Use libHttpClient for HTTP transport" OFF) +option(WITH_HTTP_CPPREST "Use CppRestSDK for HTTP transport" OFF) + +option(WITH_WS_WSLAY "Use wslay for WS transport" OFF) +option(WITH_WS_LIBHTTPC "Use libHttpClient for WS transport" OFF) +option(WITH_WS_CPPREST "Use CppRestSDK for WS transport" OFF) + +option(CFG_WSLAY_CURL_IO "Use CURL-based NetIO when wslay is enabled" ON) +option(CFG_LIBHTTPC_SYSTEM "Use system-installed libhttpc" OFF) +option(CFG_CURL_SYSTEM "Use system-installed libCURL" OFF) + +option(WITH_GRPC_CLIENT "Build gRPC Client" OFF) + +if (WITH_HTTP_CURL OR (WITH_WS_WSLAY AND CFG_WSLAY_CURL_IO)) + if (NOT CFG_CURL_SYSTEM) + list(APPEND VCPKG_MANIFEST_FEATURES "curl") + endif() +endif() + +if (WITH_HTTP_LIBHTTPC AND NOT CFG_LIBHTTPC_SYSTEM) + list(APPEND VCPKG_MANIFEST_FEATURES "libhttpclient-http") +endif() + +if (WITH_WS_LIBHTTPC AND NOT CFG_LIBHTTPC_SYSTEM) + list(APPEND VCPKG_MANIFEST_FEATURES "libhttpclient-ws") +endif() + +if (WITH_HTTP_CPPREST OR WITH_WS_CPPREST) + list(APPEND VCPKG_MANIFEST_FEATURES "cpprestsdk") +endif() + +if (WITH_HTTP_LIBHTTPC OR WITH_HTTP_CURL OR WITH_HTTP_CPPREST) + # This var goes into public config.h, so set it early + set(HAVE_DEFAULT_TRANSPORT_FACTORY ON) +endif() + +if (WITH_WS_LIBHTTPC OR WITH_WS_WSLAY OR WITH_WS_CPPREST) + # This var goes into public config.h, so set it early + set(HAVE_DEFAULT_RT_TRANSPORT_FACTORY ON) +endif() + if (CMAKE_OSX_SYSROOT STREQUAL "iphonesimulator") # this hack seems to be required for now, otherwise CMake still thinks we are building for arm... set(CMAKE_XCODE_ATTRIBUTE_EXCLUDED_ARCHS[sdk=iphonesimulator*] "arm64") @@ -21,63 +63,10 @@ set(FETCHCONTENT_UPDATES_DISCONNECTED OFF) # By default, assume user will not obtain optional-lite via third party mechanism. option(DISTRIBUTE_OPTIONAL_LITE "Distribute optional lite with the Nakama client." ON) -option(BUILD_SHARED_LIBS "Build a shared library." ON) option(FORCE_DLL_IMPORT_EXPORT "Force exporting and importing of symbols regardless of the platform." OFF) option(BUILD_APPLE_FRAMEWORK "Build frameworks instead of .dylib files for Apple." ON) -set(HTTP_IMPL "") -set(WS_IMPL "") -set(NAKAMA_SDK_DEPS "") - -if (WITH_LIBHTTPCLIENT_HTTP) - set(HTTP_IMPL "libhttpclient") -elseif (WITH_CPPRESTSDK) - set(HTTP_IMPL "cpprestsdk") -elseif (BUILD_CURL_HTTP OR BUILD_CURL_HTTP_SYSTEM) - set(HTTP_IMPL "curl") -endif() - -if (WITH_LIBHTTPCLIENT_WS) - set(WS_IMPL "libhttpclient") -elseif (BUILD_WSLAY) - set(WS_IMPL "wslay") -elseif (WITH_CPPRESTSDK) - set(WS_IMPL "cpprestsdk") -endif() - -set(HTTP_COMPILE_DEFINITION "") - -if(WITH_LIBHTTPCLIENT_HTTP) - set(HTTP_COMPILE_DEFINITION "BUILD_HTTP_LIBHTTPCLIENT") -elseif(WITH_CPPRESTSDK) - set(HTTP_COMPILE_DEFINITION "BUILD_HTTP_CPPRESTSDK") -elseif(BUILD_CURL_HTTP OR BUILD_CURL_HTTP_SYSTEM) - set(HTTP_COMPILE_DEFINITION "BUILD_HTTP_CURL") -else() - set(HTTP_COMPILE_DEFINITION "WITH_EXTERNAL_HTTP") -endif() - -set(WS_COMPILE_DEFINITION "") -set(WS_IO_COMPILE_DEFINITION "") - -if (WITH_LIBHTTPCLIENT_WS) - set(WS_COMPILE_DEFINITION BUILD_WEBSOCKET_LIBHTTPCLIENT) -elseif (BUILD_WSLAY) - set(WS_COMPILE_DEFINITION BUILD_WEBSOCKET_WSLAY) - - if (BUILD_CURL_IO OR BUILD_CURL_IO_SYSTEM) - set(WS_IO_COMPILE_DEFINITION BUILD_CURL_IO) - else() - # no IO baked in for Wslay -- we expect user to provide the IO. - set(WS_IO_COMPILE_DEFINITION BUILD_IO_EXTERNAL) - endif() -elseif (WITH_CPPRESTSDK) - set(WS_COMPILE_DEFINITION BUILD_WEBSOCKET_CPPRESTSDK) -else() - # no WS baked in -- we expect user to provide WS transport - set(WS_COMPILE_DEFINITION WITH_EXTERNAL_WS) - set(WS_IO_COMPILE_DEFINITION WITH_EXTERNAL_WS_IO) -endif() +set(NAKAMA_SDK_DEPS) cmake_policy(SET CMP0012 NEW) @@ -90,6 +79,7 @@ if (DEFINED ANDROID_ABI AND NOT DEFINED VCPKG_CHAINLOAD_TOOLCHAIN_FILE) endif() include("submodules/devkits/cmake/platform-${VCPKG_TARGET_TRIPLET}.cmake" OPTIONAL) +include("submodules/private/cmake/preproject-${VCPKG_TARGET_TRIPLET}.cmake" OPTIONAL) project(nakama-sdk LANGUAGES CXX) @@ -110,14 +100,6 @@ endif() option(ADDRESS_SANITIZER "Enable address sanitizer (broken on windows)" OFF) -# libhttpclient uses websocketpp when system winhttp doesn't provide one (< Windows 8) -# this flag allows us to force use of websocketpp so that it can be tested on current Windows versions -option(LIBHTTPCLIENT_FORCE_WEBSOCKETPP "Force use of websocketpp instead of winhttp in the libhttpclient" OFF) - -if (LIBHTTPCLIENT_FORCE_WEBSOCKETPP) - list(APPEND VCPKG_MANIFEST_FEATURES "websocketpp") -endif() - if(LOGS_ENABLED) add_compile_definitions(NLOGS_ENABLED) endif(LOGS_ENABLED) @@ -127,67 +109,81 @@ if (ADDRESS_SANITIZER) string(REPLACE /RTC1 "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG}) endif() -if(BUILD_SHARED_LIBS) - set(CMAKE_POSITION_INDEPENDENT_CODE ON) - add_compile_definitions(NAKAMA_SHARED_LIBRARY NAKAMA_SHARED_LIBRARY_EXPORTS) -endif() +add_compile_definitions(NAKAMA_SHARED_LIBRARY NAKAMA_SHARED_LIBRARY_EXPORTS) - -if(APPLE AND BUILD_SHARED_LIBS AND BUILD_APPLE_FRAMEWORK) +if(APPLE AND BUILD_APPLE_FRAMEWORK) # Just copy over headers into framework dir, because "official" way of doing it # via PUBLIC_HEADER property is full of bugs (see comment on PUBLIC_HEADER property below) set(CMAKE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_LIBDIR}/nakama-sdk.framework/Headers) endif() -if (BUILD_CURL_IO_SYSTEM OR BUILD_CURL_IO OR BUILD_CURL_HTTP_SYSTEM OR BUILD_CURL_HTTP) - if (BUILD_CURL_IO_SYSTEM OR BUILD_CURL_HTTP_SYSTEM) +if (WITH_HTTP_CURL OR (WITH_WS_WSLAY AND CFG_WSLAY_CURL_IO)) + if (CFG_CURL_SYSTEM) find_package(CURL REQUIRED) # system curl not guaranteed to contain a CMake config file. else() find_package(CURL CONFIG REQUIRED) endif() endif() -if(WS_IMPL STREQUAL "libhttpclient" OR HTTP_IMPL STREQUAL "libhttpclient") - if (NOT LIBHTTPCLIENT_BUILTIN) + +if(WITH_HTTP_LIBHTTPC OR WITH_WS_LIBHTTPC) + # build libHttpClient dependency if not using system + if (NOT CFG_LIBHTTPC_SYSTEM) include(cmake/libhttpClient.cmake) endif() endif() -if (HTTP_IMPL STREQUAL "cpprestsdk") +find_package(optional-lite CONFIG REQUIRED) +# SDK API +add_subdirectory(interface) + +# Implements API, but without concrete implementations of transports +add_subdirectory(core EXCLUDE_FROM_ALL) + +# Factories, that's where all messy ifdefs to select concrete implementations are +add_subdirectory(factory EXCLUDE_FROM_ALL) + +include("submodules/private/cmake/target-${VCPKG_TARGET_TRIPLET}.cmake" OPTIONAL RESULT_VARIABLE PRIVATE_TARGETS) + +if (WITH_HTTP_CPPREST) + set(HTTP_IMPL_LIB nakama-impl-http-cppRest) add_subdirectory(impl/httpCppRest EXCLUDE_FROM_ALL) -elseif(HTTP_IMPL STREQUAL "curl") +elseif(WITH_HTTP_CURL) + set(HTTP_IMPL_LIB nakama-impl-http-libcurl) add_subdirectory(impl/httpCurl EXCLUDE_FROM_ALL) +elseif(WITH_HTTP_LIBHTTPC) + set(HTTP_IMPL_LIB nakama-impl-http-libhttpclient) + add_subdirectory(impl/httpLibHttpClient EXCLUDE_FROM_ALL) +endif() +if (HTTP_IMPL_LIB) + target_link_libraries(nakama-sdk-client-factory INTERFACE ${HTTP_IMPL_LIB} $) endif() -add_library(nakama-ws-impl INTERFACE) -if(WS_IMPL STREQUAL "libhttpclient") +if(WITH_WS_LIBHTTPC) set(WS_IMPL_LIB nakama-impl-ws-libhttpclient) add_subdirectory(impl/wsLibHttpClient EXCLUDE_FROM_ALL) -elseif(WS_IMPL STREQUAL "wslay") - set(BUILD_WEBSOCKET_WSLAY ON) +elseif(WITH_WS_WSLAY) set(WS_IMPL_LIB nakama-impl-ws-wslay) add_subdirectory(impl/wsWslay EXCLUDE_FROM_ALL) -elseif(WS_IMPL STREQUAL "cpprestsdk") +elseif(WITH_WS_CPPREST) set(WS_IMPL_LIB nakama-impl-ws-cppRest) add_subdirectory(impl/wsCppRest EXCLUDE_FROM_ALL) endif() - -if(HTTP_IMPL STREQUAL "libhttpclient") - set(BUILD_HTTP_LIBHTTPCLIENT ON) - add_subdirectory(impl/httpLibHttpClient EXCLUDE_FROM_ALL) +if (WS_IMPL_LIB) + target_link_libraries(nakama-sdk-rtclient-factory INTERFACE ${WS_IMPL_LIB} $) endif() -if (ANDROID AND (HTTP_IMPL STREQUAL "curl" OR WS_IMPL STREQUAL "wslay")) +if (ANDROID AND (WITH_HTTP_CURL OR WITH_WS_WSLAY)) add_subdirectory(impl/android) set(CREATE_JAR TRUE) # we need the code for accessing native Android CA store. - if (HTTP_IMPL STREQUAL "curl") + if (TARGET nakama-impl-http-libcurl) target_link_libraries(nakama-impl-http-libcurl PUBLIC android-ca) endif() - if (WS_IMPL STREQUAL "wslay") - target_link_libraries(nakama-impl-ws-wslay INTERFACE android-ca) + if (TARGET nakama-impl-ws-wslay) + target_link_libraries(nakama-impl-ws-wslay PUBLIC android-ca) endif() list(APPEND NAKAMA_SDK_DEPS android-ca) @@ -213,16 +209,6 @@ if (CREATE_JAR) install(FILES ${LIBNAKAMA_AAR} DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() -find_package(optional-lite CONFIG REQUIRED) -# SDK API -add_subdirectory(interface) - -# Factories, that's where all messy ifdefs to select concrete implementations are -add_subdirectory(factory EXCLUDE_FROM_ALL) - -# Implements API, but without concrete implementations of transports -add_subdirectory(core EXCLUDE_FROM_ALL) - # create dummy file because pure "library of libraries" is not supported: https://gitlab.kitware.com/cmake/cmake/-/issues/23688 set(DUMMY_CPP "") set(DUMMY_H "") @@ -233,29 +219,39 @@ if (APPLE) set(DUMMY_H ${CMAKE_BINARY_DIR}/dummy.h) endif() + +# Use 'nakama::' ALIASes because it forces CMake to reference +# defined target and not to fallback to '-lname' when target doesn't exist, +# thus failing at configure time, rather than at link time should we make mistake +# in build scripts list(APPEND NAKAMA_SDK_DEPS - nakama-sdk-core-misc - nakama-sdk-core-rest - nakama-sdk-core-rt - nakama-sdk-core-common - nakama-sdk-client-factory - nakama-sdk-rtclient-factory + nakama::sdk-core-misc + nakama::sdk-core-rest + nakama::sdk-core-rt + nakama::sdk-core-common + nakama::sdk-client-factory + nakama::sdk-rtclient-factory ) - -if (BUILD_GRPC_CLIENT) - list(APPEND NAKAMA_SDK_DEPS nakama-sdk-core-grpc) +if (WITH_GRPC_CLIENT) + list(APPEND NAKAMA_SDK_DEPS nakama::sdk-core-grpc) endif() -set(NAKAMA_SDK_DEPS_OBJECTS "") - -foreach(lib ${NAKAMA_SDK_DEPS}) - # Append the TARGET_OBJECTS of the current library to the list - list(APPEND NAKAMA_SDK_DEPS_OBJECTS $) -endforeach() +add_library(nakama-sdk SHARED ${DUMMY_CPP} ${DUMMY_H}) +add_library(nakama::sdk ALIAS nakama-sdk) +target_link_libraries(nakama-sdk + PUBLIC + nakama::sdk-interface + PRIVATE + nakama::api-proto + $<$:nakama::grpc-proto> + ${NAKAMA_SDK_DEPS} +) +if (WITH_HTTP_CURL OR (WITH_WS_WSLAY AND CFG_WSLAY_CURL_IO)) + target_link_libraries(nakama-sdk PRIVATE CURL::libcurl) +endif() -add_library(nakama-sdk ${NAKAMA_SDK_DEPS_OBJECTS} ${DUMMY_CPP} ${DUMMY_H}) -if (BUILD_SHARED_LIBS AND APPLE AND BUILD_APPLE_FRAMEWORK) +if (APPLE AND BUILD_APPLE_FRAMEWORK) set_target_properties(nakama-sdk PROPERTIES FRAMEWORK TRUE FRAMEWORK_VERSION A @@ -272,29 +268,6 @@ elseif (APPLE) FRAMEWORK FALSE) endif() -add_library(nakama::sdk ALIAS nakama-sdk) -find_package(Threads REQUIRED) -set(PTHREADS_LIB Threads::Threads) -target_link_libraries(nakama-sdk - PUBLIC - nakama::sdk-interface - ${PTHREADS_LIB} -) - -set(DEPENDENCY_LINK_SCOPE "") -if (BUILD_SHARED_LIBS) - set(DEPENDENCY_LINK_SCOPE "PRIVATE") -else() # propogate the static dependencies - set(DEPENDENCY_LINK_SCOPE "PUBLIC") -endif() - -target_link_libraries(nakama-sdk - ${DEPENDENCY_LINK_SCOPE} - nakama-api-proto - $<$:nakama-grpc-proto> - ${HTTP_IMPL_LIB} ${WS_IMPL_LIB} -) - if (ADDRESS_SANITIZER) if (MSVC) @@ -310,18 +283,15 @@ if (ADDRESS_SANITIZER) endif() -# ensure we only perform a single 'target_link_libraries' to libcurl to prevent duplicate linkage for linkers that do not deduplicate. -if (BUILD_CURL_IO_SYSTEM OR BUILD_CURL_IO OR BUILD_CURL_HTTP_SYSTEM OR BUILD_CURL_HTTP) - target_link_libraries(nakama-sdk PRIVATE CURL::libcurl) -endif() - +#Install doesn't support ALIASes, transform them into 'flat' non alias names +list(TRANSFORM NAKAMA_SDK_DEPS REPLACE "::" "-" OUTPUT_VARIABLE NAKAMA_SDK_DEPS_TARGETS) install(TARGETS nakama-sdk nakama-sdk-interface nakama-api-proto ${HTTP_IMPL_LIB} ${WS_IMPL_LIB} - ${NAKAMA_SDK_DEPS} + ${NAKAMA_SDK_DEPS_TARGETS} EXPORT nakama-export FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT nakama-sdk LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT nakama-sdk @@ -331,7 +301,7 @@ install(TARGETS INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" ) -if(MSVC AND BUILD_SHARED_LIBS) +if(MSVC) install(FILES $ DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT nakama-sdk OPTIONAL) endif() @@ -339,15 +309,8 @@ endif() install(EXPORT nakama-export DESTINATION share/nakama-sdk) - include(CMakePackageConfigHelpers) -if(BUILD_SHARED_LIBS) - set(NAKAMA_SDK_BUILD_TYPE "SHARED") -else() - set(NAKAMA_SDK_BUILD_TYPE "STATIC") -endif() - configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/nakama-sdk-config.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/nakama-sdk-config.cmake" INSTALL_DESTINATION share/nakama-sdk diff --git a/CMakePresets.json b/CMakePresets.json index ecd8ead23..348c9268d 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -27,12 +27,9 @@ "generator": "Ninja Multi-Config", "cacheVariables": { "CMAKE_SYSTEM_PROCESSOR": "AMD64", - "VCPKG_HOST_TRIPLET": "x64-windows-static-heroic", "VCPKG_TARGET_TRIPLET": "x64-windows-static-heroic", - "BUILD_WSLAY": "ON", - "BUILD_CURL_IO": "ON", - "BUILD_CURL_HTTP": "ON", - "VCPKG_MANIFEST_FEATURES": "wslay;curl" + "WITH_WS_WSLAY": "ON", + "WITH_HTTP_CURL": "ON" }, "condition": { "type": "equals", @@ -44,40 +41,26 @@ { "name": "win-arm64", "inherits": [ - "default" + "default", "win-x64" ], - "generator": "Ninja Multi-Config", "cacheVariables": { - "CMAKE_SYSTEM_PROCESSOR": "arm64", - "VCPKG_HOST_TRIPLET": "arm64-windows-static-heroic", - "VCPKG_TARGET_TRIPLET": "arm64-windows-static-heroic", - "BUILD_WSLAY": "ON", - "BUILD_CURL_IO": "ON", - "BUILD_CURL_HTTP": "ON", - "VCPKG_MANIFEST_FEATURES": "wslay;curl" - }, - "condition": { - "type": "equals", - "lhs": "${hostSystemName}", - "rhs": "Windows" + "CMAKE_SYSTEM_PROCESSOR": "ARM64", + "VCPKG_TARGET_TRIPLET": "arm64-windows-static-heroic" }, "installDir": "out/win-arm64" }, { - "name": "macosx-arm64-host_arm64", + "name": "macosx-arm64", "inherits": [ "default" ], "installDir": "out/macosx-arm64", "generator": "Xcode", "cacheVariables": { - "VCPKG_HOST_TRIPLET": "arm64-osx-heroic", "VCPKG_TARGET_TRIPLET": "arm64-osx-heroic", "CMAKE_OSX_ARCHITECTURES": "arm64", - "BUILD_WSLAY": "ON", - "BUILD_CURL_IO": "ON", - "BUILD_CURL_HTTP": "ON", - "VCPKG_MANIFEST_FEATURES": "wslay;curl" + "WITH_WS_WSLAY": "ON", + "WITH_HTTP_CURL": "ON" }, "condition": { "type": "equals", @@ -86,83 +69,36 @@ } }, { - "name": "macosx-arm64-host_x64", + "name": "macosx-x64", "inherits": [ - "macosx-arm64-host_arm64" + "macosx-arm64" ], "cacheVariables": { - "VCPKG_HOST_TRIPLET": "x64-osx-heroic", - "CMAKE_OSX_ARCHITECTURES": "arm64" - }, - "installDir": "out/macosx-arm64" - }, - { - "name": "macosx-x64-host_x64", - "inherits": [ - "macosx-arm64-host_x64" - ], - "cacheVariables": { - "VCPKG_HOST_TRIPLET": "x64-osx-heroic", "VCPKG_TARGET_TRIPLET": "x64-osx-heroic", "CMAKE_OSX_ARCHITECTURES": "x86_64" }, "installDir": "out/macosx-x64" }, { - "name": "macosx-x64-host_arm64", - "inherits": [ - "macosx-x64-host_x64" - ], - "cacheVariables": { - "VCPKG_HOST_TRIPLET": "arm64-osx-heroic", - "CMAKE_OSX_ARCHITECTURES": "x86_64" - } - }, - { - "name": "ios-arm64-host_arm64", + "name": "ios-arm64", "inherits": [ - "macosx-arm64-host_arm64" + "macosx-arm64" ], "cacheVariables": { "VCPKG_TARGET_TRIPLET": "arm64-ios-heroic", - "CMAKE_SYSTEM_NAME": "iOS", - "BUILD_WSLAY": "ON", - "BUILD_CURL_IO": "ON" + "CMAKE_SYSTEM_NAME": "iOS" }, "installDir": "out/ios-arm64" }, { - "name": "ios-arm64-host_x64", - "inherits": [ - "ios-arm64-host_arm64" - ], - "installDir": "out/ios-arm64", - "cacheVariables": { - "VCPKG_TARGET_TRIPLET": "arm64-ios-heroic", - "VCPKG_HOST_TRIPLET": "x64-osx-heroic" - } - }, - { - "name": "iphonesimulator-x64-host_arm64", + "name": "iphonesimulator-x64", "inherits": [ - "macosx-x64-host_arm64" + "ios-arm64" ], "cacheVariables": { "VCPKG_TARGET_TRIPLET": "x64-iphonesimulator-heroic", - "CMAKE_SYSTEM_NAME": "iOS", "CMAKE_OSX_SYSROOT": "iphonesimulator", - "CMAKE_OSX_ARCHITECTURES": "x86_64", - "BUILD_WSLAY": "ON", - "BUILD_CURL": "ON" - } - }, - { - "name": "iphonesimulator-x64-host_x64", - "inherits": [ - "iphonesimulator-x64-host_arm64" - ], - "cacheVariables": { - "VCPKG_HOST_TRIPLET": "x64-osx-heroic" + "CMAKE_OSX_ARCHITECTURES": "x86_64" } }, { @@ -177,11 +113,9 @@ "ANDROID_ARM_NEON": "ON", "ANDROID_STL": "c++_shared", "ANDROID_PLATFORM": "android-21", - "BUILD_CURL_HTTP": "ON", - "BUILD_WSLAY": "ON", - "BUILD_CURL_IO": "ON", - "CMAKE_SYSTEM_NAME": "Android", - "VCPKG_MANIFEST_FEATURES": "curl;wslay" + "WITH_HTTP_CURL": "ON", + "WITH_WS_WSLAY": "ON", + "CMAKE_SYSTEM_NAME": "Android" }, "condition": { "type": "equals", @@ -190,111 +124,25 @@ } }, { - "name": "android-arm64-v8a-host_osx_x64", + "name": "android-arm64-v8a", "inherits": [ "android-default" ], - "generator": "Ninja Multi-Config", "cacheVariables": { - "VCPKG_HOST_TRIPLET": "x64-osx-heroic", "VCPKG_TARGET_TRIPLET": "arm64-android-heroic", "ANDROID_ABI": "arm64-v8a" }, - "condition": { - "type": "equals", - "lhs": "${hostSystemName}", - "rhs": "Darwin" - }, "installDir": "out/android-arm64-v8a" }, { - "name": "android-x64-host_osx_x64", + "name": "android-armeabi-v7a", "inherits": [ "android-default" ], - "generator": "Ninja Multi-Config", "cacheVariables": { - "VCPKG_HOST_TRIPLET": "x64-osx-heroic", - "VCPKG_TARGET_TRIPLET": "x64-android-heroic", - "ANDROID_ABI": "x86_64" - }, - "condition": { - "type": "equals", - "lhs": "${hostSystemName}", - "rhs": "Darwin" - }, - "installDir": "out/android-x64" - }, - { - "name": "android-armeabi-v7a-host_osx_x64", - "inherits": [ - "android-default" - ], - "generator": "Ninja Multi-Config", - "cacheVariables": { - "VCPKG_HOST_TRIPLET": "x64-osx-heroic", "VCPKG_TARGET_TRIPLET": "arm-neon-android-heroic", - "ANDROID_ABI": "armeabi-v7a" - }, - "condition": { - "type": "equals", - "lhs": "${hostSystemName}", - "rhs": "Darwin" - }, - "installDir": "out/android-armeabi-v7a" - }, - { - "name": "android-armeabi-v7a-host_osx_arm64", - "inherits": [ - "android-default" - ], - "generator": "Ninja Multi-Config", - "cacheVariables": { - "VCPKG_HOST_TRIPLET": "arm64-osx-heroic", - "VCPKG_TARGET_TRIPLET": "arm-neon-android-heroic", - "ANDROID_ABI": "armeabi-v7a" - }, - "condition": { - "type": "equals", - "lhs": "${hostSystemName}", - "rhs": "Darwin" - }, - "installDir": "out/android-armeabi-v7a" - }, - { - "name": "android-arm64-v8a-host_osx_arm64", - "inherits": [ - "android-default" - ], - "generator": "Ninja Multi-Config", - "cacheVariables": { - "VCPKG_HOST_TRIPLET": "arm64-osx-heroic", - "VCPKG_TARGET_TRIPLET": "arm64-android-heroic", - "ANDROID_ABI": "arm64-v8a" - }, - "condition": { - "type": "equals", - "lhs": "${hostSystemName}", - "rhs": "Darwin" - }, - "installDir": "out/android-arm64-v8a" - }, - { - "name": "android-x64-host_osx_arm64", - "inherits": [ - "android-default" - ], - "generator": "Ninja Multi-Config", - "cacheVariables": { - "VCPKG_HOST_TRIPLET": "arm64-osx-heroic", - "VCPKG_TARGET_TRIPLET": "x64-android-heroic", "ANDROID_ABI": "x86_64" }, - "condition": { - "type": "equals", - "lhs": "${hostSystemName}", - "rhs": "Darwin" - }, "installDir": "out/android-x64" }, { @@ -304,12 +152,9 @@ ], "generator": "Ninja Multi-Config", "cacheVariables": { - "VCPKG_HOST_TRIPLET": "x64-linux-heroic", "VCPKG_TARGET_TRIPLET": "x64-linux-heroic", - "BUILD_CURL_HTTP": "ON", - "BUILD_WSLAY": "ON", - "BUILD_CURL_IO": "ON", - "VCPKG_MANIFEST_FEATURES": "curl;wslay" + "WITH_HTTP_CURL": "ON", + "WITH_WS_WSLAY": "ON" }, "condition": { "type": "equals", @@ -329,60 +174,6 @@ "CXX": "/usr/bin/g++-11" }, "installDir": "out/ubuntu1804-amd64" - }, - { - "name": "android-armeabi-v7a-host_linux-x64", - "inherits": [ - "android-default" - ], - "generator": "Ninja Multi-Config", - "cacheVariables": { - "VCPKG_HOST_TRIPLET": "x64-linux-release", - "VCPKG_TARGET_TRIPLET": "arm-neon-android-heroic", - "ANDROID_ABI": "armeabi-v7a" - }, - "condition": { - "type": "equals", - "lhs": "${hostSystemName}", - "rhs": "Linux" - }, - "installDir": "out/android-armeabi-v7a" - }, - { - "name": "android-arm64-v8a-host_linux-x64", - "inherits": [ - "android-default" - ], - "generator": "Ninja Multi-Config", - "cacheVariables": { - "VCPKG_HOST_TRIPLET": "x64-linux-release", - "VCPKG_TARGET_TRIPLET": "arm64-android-heroic", - "ANDROID_ABI": "arm64-v8a" - }, - "condition": { - "type": "equals", - "lhs": "${hostSystemName}", - "rhs": "Linux" - }, - "installDir": "out/android-arm64-v8a" - }, - { - "name": "android-x64-host_linux-x64", - "inherits": [ - "android-default" - ], - "generator": "Ninja Multi-Config", - "cacheVariables": { - "VCPKG_HOST_TRIPLET": "x64-linux-release", - "VCPKG_TARGET_TRIPLET": "x64-android-heroic", - "ANDROID_ABI": "x86_64" - }, - "condition": { - "type": "equals", - "lhs": "${hostSystemName}", - "rhs": "Linux" - }, - "installDir": "out/android-x64" } ] } diff --git a/cmake/compilerFlags.cmake b/cmake/compilerFlags.cmake index adafd068c..5cf480db9 100644 --- a/cmake/compilerFlags.cmake +++ b/cmake/compilerFlags.cmake @@ -35,7 +35,6 @@ set(CMAKE_USER_MAKE_RULES_OVERRIDE "${CMAKE_CURRENT_LIST_FILE}") # Common compilation flags. Same file used by SDK code and to build vcpkg dependencies. include_guard() - # Minimize what's visible outside of shared lib set(CMAKE_CXX_VISIBILITY_PRESET hidden) set(CMAKE_C_VISIBILITY_PRESET hidden) @@ -52,4 +51,4 @@ if (NOT MSVC) else() string(APPEND CMAKE_C_FLAGS " /Gw /Gy") string(APPEND CMAKE_CXX_FLAGS " /Gw /Gy") -endif() \ No newline at end of file +endif() diff --git a/cmake/libhttpClient.cmake b/cmake/libhttpClient.cmake index 4d3f891a3..0638bae69 100644 --- a/cmake/libhttpClient.cmake +++ b/cmake/libhttpClient.cmake @@ -65,8 +65,7 @@ endif() # in our ABI, because that is how JVM finds native code on Android platform. list(APPEND NAKAMA_SDK_DEPS ${LIBHTTPCLIENT_TARGET}) - -if (NOT WS_IMPL STREQUAL "libhttpclient") +if (WITH_WS_LIBHTTPC) target_compile_definitions(${LIBHTTPCLIENT_TARGET} PRIVATE "HC_NOWEBSOCKETS") else() if (LIBHTTPCLIENT_FORCE_WEBSOCKETPP) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 168363e22..e72269cd7 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -18,8 +18,8 @@ add_subdirectory(core-rt EXCLUDE_FROM_ALL) add_subdirectory(core-rest EXCLUDE_FROM_ALL) ## for createRtClient() -target_link_libraries(nakama-sdk-core-rest PUBLIC nakama-sdk-core-rt factory) +target_link_libraries(nakama-sdk-core-rest PUBLIC nakama::sdk-core-rt) -if (BUILD_GRPC_CLIENT) +if (WITH_GRPC_CLIENT) add_subdirectory(core-grpc EXCLUDE_FROM_ALL) endif() diff --git a/core/buildProtoFiles.cmake b/core/buildProtoFiles.cmake index b6bcce04f..f7e05f819 100644 --- a/core/buildProtoFiles.cmake +++ b/core/buildProtoFiles.cmake @@ -37,7 +37,7 @@ protobuf_generate(TARGET nakama-api-proto message("done generating") -if (BUILD_GRPC_CLIENT) +if (WITH_GRPC_CLIENT) #### apigrpc.proto #### # apigrpc.proto references 'api.proto' using canonical name 'github.com/heroiclabs/nakama-common/api/api.proto' @@ -107,4 +107,4 @@ protobuf_generate(TARGET nakama-grpc-proto PROTOC_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR} PROTOC_OPTIONS "--grpc_out=${CMAKE_CURRENT_BINARY_DIR}" ) -endif(BUILD_GRPC_CLIENT) +endif(WITH_GRPC_CLIENT) diff --git a/core/common/BaseClient.cpp b/core/common/BaseClient.cpp index bf8ba8cda..f314d2ed0 100644 --- a/core/common/BaseClient.cpp +++ b/core/common/BaseClient.cpp @@ -16,17 +16,17 @@ #include -#include "nakama-cpp/NClientInterface.h" -#include "nakama-cpp/log/NLogger.h" -#include "nakama-cpp/realtime/NWebsocketsFactory.h" -#include "nakama-cpp/NException.h" +#include +#include +#include +#include #include "BaseClient.h" #include "../core-rt/NRtClient.h" namespace Nakama { -#if !defined(WITH_EXTERNAL_WS) && !defined(BUILD_IO_EXTERNAL) +#if defined(HAVE_DEFAULT_RT_TRANSPORT_FACTORY) NRtClientPtr BaseClient::createRtClient() { return createRtClient(createDefaultWebsocket(_platformParams)); diff --git a/core/common/BaseClient.h b/core/common/BaseClient.h index 8fe9a2aca..b464a1b2d 100644 --- a/core/common/BaseClient.h +++ b/core/common/BaseClient.h @@ -32,7 +32,7 @@ namespace Nakama { void setUserData(void* userData) override { _userData = userData; } void* getUserData() const override { return _userData; } -#if !defined(WITH_EXTERNAL_WS) && !defined(BUILD_IO_EXTERNAL) +#ifdef HAVE_DEFAULT_RT_TRANSPORT_FACTORY NRtClientPtr createRtClient() override; #endif diff --git a/core/common/CMakeLists.txt b/core/common/CMakeLists.txt index 3b7791305..c68d5c0c7 100644 --- a/core/common/CMakeLists.txt +++ b/core/common/CMakeLists.txt @@ -19,14 +19,15 @@ file( #set(CMAKE_INCLUDE_CURRENT_DIR ON) #set(CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON) -add_library(nakama-sdk-core-common OBJECT ${srcs}) + add_library(nakama-sdk-core-common OBJECT ${srcs}) + add_library(nakama::sdk-core-common ALIAS nakama-sdk-core-common) target_link_libraries(nakama-sdk-core-common PUBLIC nakama-sdk-interface # required for datahelper nakama::api-proto - $<$:nakama::grpc-proto> + $ PRIVATE protobuf::libprotobuf # because of StrUtil::Base64Encode ) diff --git a/core/core-grpc/CMakeLists.txt b/core/core-grpc/CMakeLists.txt index 1c94d927e..a99d2d5bc 100644 --- a/core/core-grpc/CMakeLists.txt +++ b/core/core-grpc/CMakeLists.txt @@ -12,8 +12,11 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) find_package(gRPC CONFIG REQUIRED) add_library(nakama-sdk-core-grpc OBJECT ${srcs}) +add_library(nakama::sdk-core-grpc ALIAS nakama-sdk-core-grpc) target_link_libraries(nakama-sdk-core-grpc - PUBLIC nakama-sdk-interface nakama-grpc-proto - PUBLIC nakama-sdk-core-common - nakama-sdk-core-rt - ) \ No newline at end of file + PUBLIC + nakama::sdk-core-rt + nakama::grpc-proto + nakama::sdk-core-common + nakama::sdk-interface + ) diff --git a/core/core-rest/CMakeLists.txt b/core/core-rest/CMakeLists.txt index 30a98298b..1369364de 100644 --- a/core/core-rest/CMakeLists.txt +++ b/core/core-rest/CMakeLists.txt @@ -1,5 +1,3 @@ -project(nakama-sdk-cpp-core-rest LANGUAGES CXX) - file( GLOB_RECURSE srcs LIST_DIRECTORIES false @@ -19,8 +17,9 @@ target_compile_definitions(nakama-sdk-core-rest PRIVATE RAPIDJSON_HAS_CXX11_RVALUE_REFS=1 ) target_link_libraries(nakama-sdk-core-rest - PUBLIC nakama-sdk-interface + PUBLIC + nakama::sdk-interface + nakama::sdk-core-common PRIVATE rapidjson - nakama-sdk-core-common - nakama-sdk-core-rt + nakama::sdk-core-rt ) diff --git a/core/core-rt/CMakeLists.txt b/core/core-rt/CMakeLists.txt index 8d4a910cb..9d389e907 100644 --- a/core/core-rt/CMakeLists.txt +++ b/core/core-rt/CMakeLists.txt @@ -1,5 +1,3 @@ -project(nakama-cpp-sdk-core-rt LANGUAGES CXX) - file( GLOB_RECURSE srcs LIST_DIRECTORIES false @@ -10,8 +8,12 @@ file( set(CMAKE_INCLUDE_CURRENT_DIR ON) add_library(nakama-sdk-core-rt OBJECT ${srcs}) +add_library(nakama::sdk-core-rt ALIAS nakama-sdk-core-rt) target_link_libraries(nakama-sdk-core-rt - PUBLIC nakama-sdk-interface nakama-api-proto - PUBLIC nakama-sdk-core-common - PRIVATE nakama::rtclient-factory # because of BaseClient.cpp + PUBLIC + nakama::sdk-interface + nakama::api-proto + nakama::sdk-core-common + PRIVATE + nakama::sdk-rtclient-factory # because of BaseClient.cpp ) diff --git a/core/src/CMakeLists.txt b/core/src/CMakeLists.txt index 29fd023d9..b4ba5574b 100644 --- a/core/src/CMakeLists.txt +++ b/core/src/CMakeLists.txt @@ -23,9 +23,10 @@ file( ) add_library(nakama-sdk-core-misc OBJECT ${_source_list}) +add_library(nakama::sdk-core-misc ALIAS nakama-sdk-core-misc) target_link_libraries(nakama-sdk-core-misc - PUBLIC nakama-sdk-interface + PUBLIC nakama::sdk-interface ) if(ANDROID) diff --git a/core/src/roots_pem.cpp b/core/src/roots_pem.cpp index 4bded2115..c235bf62e 100644 --- a/core/src/roots_pem.cpp +++ b/core/src/roots_pem.cpp @@ -1,6 +1,6 @@ // file generated by conv_roots_pem.py -#if defined(NAKAMA_SSL_ENABLED) && defined(BUILD_GRPC_CLIENT) +#if defined(NAKAMA_SSL_ENABLED) && defined(WITH_GRPC_CLIENT) #include "roots_pem.h" diff --git a/factory/CMakeLists.txt b/factory/CMakeLists.txt index 3db7fc25c..05ff6e0ed 100644 --- a/factory/CMakeLists.txt +++ b/factory/CMakeLists.txt @@ -1,18 +1,21 @@ add_library(nakama-sdk-client-factory OBJECT ClientFactory.cpp) -add_library(nakama::client-factory ALIAS nakama-sdk-client-factory) +add_library(nakama::sdk-client-factory ALIAS nakama-sdk-client-factory) target_link_libraries(nakama-sdk-client-factory - PRIVATE nakama-sdk-core-rest nakama-sdk-core-grpc ${HTTP_IMPL_LIB}) - -if (BUILD_GRPC_CLIENT) - target_compile_definitions(nakama-sdk-client-factory PRIVATE BUILD_GRPC_CLIENT) -endif() - -target_compile_definitions(nakama-sdk-client-factory PRIVATE HTTP_COMPILE_DEFINITION) + PRIVATE nakama::sdk-core-rest + $) +target_compile_definitions(nakama-sdk-client-factory PRIVATE + $<$:WITH_GRPC_CLIENT> + $<$:WITH_HTTP_CURL> + $<$:WITH_HTTP_LIBHTTPC> + $<$:WITH_HTTP_CPPREST> +) add_library(nakama-sdk-rtclient-factory OBJECT NWebsocketsFactory.cpp) -add_library(nakama::rtclient-factory ALIAS nakama-sdk-rtclient-factory) - +add_library(nakama::sdk-rtclient-factory ALIAS nakama-sdk-rtclient-factory) target_link_libraries(nakama-sdk-rtclient-factory - PUBLIC nakama-sdk-interface - PRIVATE ${WS_IMPL_LIB} + PUBLIC nakama::sdk-interface) +target_compile_definitions(nakama-sdk-rtclient-factory PRIVATE + $<$:WITH_WS_WLAY> + $<$:WITH_WS_LIBHTTPC> + $<$:WITH_WS_CPPREST> ) diff --git a/factory/ClientFactory.cpp b/factory/ClientFactory.cpp index ef796f0ed..6a24a8f9e 100644 --- a/factory/ClientFactory.cpp +++ b/factory/ClientFactory.cpp @@ -18,26 +18,26 @@ #include "nakama-cpp/log/NLogger.h" #include "nakama-cpp/NClientInterface.h" -#ifdef BUILD_GRPC_CLIENT +#ifdef WITH_GRPC_CLIENT #include "../core/core-grpc/GrpcClient.h" #endif #include "../core/core-rest/RestClient.h" -#ifdef BUILD_HTTP_LIBHTTPCLIENT +#ifdef WITH_HTTP_LIBHTTPC #include "../../impl/httpLibHttpClient/NHttpClientLibHC.h" -#elif defined(BUILD_HTTP_CPPRESTSDK) +#elif defined(WITH_HTTP_CPPREST) #include "../../impl/httpCppRest/NHttpClientCppRest.h" -#elif defined(BUILD_HTTP_CURL) +#elif defined(WITH_HTTP_CURL) #include "../../impl/httpCurl/NHttpClientLibCurl.h" #endif namespace Nakama { -#if !defined(WITH_EXTERNAL_HTTP) || defined(BUILD_GRPC_CLIENT) +#if !defined(WITH_PRIVATE_HTTP) || defined(WITH_GRPC_CLIENT) NClientPtr createDefaultClient(const NClientParameters& parameters) { - #if defined(BUILD_GRPC_CLIENT) + #if defined(WITH_GRPC_CLIENT) return createGrpcClient(parameters); #else return createRestClient(parameters, createDefaultHttpTransport(parameters.platformParams)); @@ -45,7 +45,7 @@ NClientPtr createDefaultClient(const NClientParameters& parameters) } #endif -#if BUILD_GRPC_CLIENT +#ifdef WITH_GRPC_CLIENT NClientPtr createGrpcClient(const NClientParameters& parameters) { @@ -67,16 +67,16 @@ NClientPtr createRestClient(const NClientParameters& parameters, NHttpTransportP return client; } -#ifndef WITH_EXTERNAL_HTTP +#ifndef WITH_PRIVATE_HTTP NHttpTransportPtr createDefaultHttpTransport(const NPlatformParameters& platformParams) { (void)platformParams; // silence unused variable warning on some platforms // Compilation error if no implementation is selected - #if defined(BUILD_HTTP_LIBHTTPCLIENT) + #if defined(WITH_HTTP_LIBHTTPC) return NHttpTransportPtr(new NHttpClientLibHC(platformParams)); - #elif defined(BUILD_HTTP_CPPRESTSDK) + #elif defined(WITH_HTTP_CPPREST) return NHttpTransportPtr(new NHttpClientCppRest(platformParams)); - #elif defined(BUILD_HTTP_CURL) + #elif defined(WITH_HTTP_CURL) return NHttpTransportPtr(new NHttpClientLibCurl(platformParams)); #else #error Could not find default http transport for platform. diff --git a/factory/NWebsocketsFactory.cpp b/factory/NWebsocketsFactory.cpp index 2b788aa1e..3772c6396 100644 --- a/factory/NWebsocketsFactory.cpp +++ b/factory/NWebsocketsFactory.cpp @@ -17,47 +17,34 @@ #include "nakama-cpp/realtime/NWebsocketsFactory.h" #include "nakama-cpp/log/NLogger.h" #include "nakama-cpp/NPlatformParams.h" +// Private builds provide their own factory +#if !defined(WITH_PRIVATE_WS) -#ifdef BUILD_WEBSOCKET_WSLAY -#include "nakama-cpp/realtime/wslay/WslayIOInterface.h" -#endif - -#if defined(BUILD_WEBSOCKET_LIBHTTPCLIENT) +#if defined(WITH_WS_LIBHTTPC) #include "../../impl/wsLibHttpClient/NWebsocketLibHC.h" -#elif defined(BUILD_WEBSOCKET_WSLAY) +#elif defined(WITH_WS_WSLAY) #include "NWebsocketWslay.h" - #if defined(BUILD_CURL_IO) + #if defined(CFG_WSLAY_CURL_IO) #include "WslayIOCurl.h" #endif -#elif defined(BUILD_WEBSOCKET_CPPRESTSDK) +#elif defined(WITH_WS_CPPREST) #include "NWebsocketCppRest.h" #endif namespace Nakama { -#if !defined(WITH_EXTERNAL_WS) && !defined(BUILD_IO_EXTERNAL) - -NRtTransportPtr createDefaultWebsocket(const NPlatformParameters& platformParams) +NRtTransportPtr createDefaultWebsocket([[maybe_unused]] const NPlatformParameters& platformParams) { - (void)platformParams; // silence unused variable warning on some platforms - #if defined(BUILD_WEBSOCKET_LIBHTTPCLIENT) + #if defined(WITH_WS_LIBHTTPC) return NRtTransportPtr(NWebsocketLibHC::New(platformParams)); - #elif defined(BUILD_WEBSOCKET_WSLAY) && defined(BUILD_CURL_IO) + #elif defined(WITH_WS_WSLAY) && defined(CFG_WSLAY_CURL_IO) return NRtTransportPtr(new NWebsocketWslay(std::move(std::unique_ptr(new WslayIOCurl())))); - #elif defined(BUILD_WEBSOCKET_CPPRESTSDK) + #elif defined(WITH_WS_CPPREST) return NRtTransportPtr(new NWebsocketCppRest()); #else #error Could not find default web socket transport or IO for platform. #endif } +} // namespace Nakama #endif - -#ifdef BUILD_WEBSOCKET_WSLAY -NRtTransportPtr createWslayWebsocket(std::unique_ptr io) -{ - return std::make_shared(std::move(io)); -} -#endif - -} // namespace Nakama diff --git a/impl/httpCppRest/CMakeLists.txt b/impl/httpCppRest/CMakeLists.txt index 20cd8982c..dd05962a1 100644 --- a/impl/httpCppRest/CMakeLists.txt +++ b/impl/httpCppRest/CMakeLists.txt @@ -14,4 +14,3 @@ target_link_libraries(nakama-impl-http-cppRest PRIVATE cpprestsdk::cpprest ) add_library(nakama::impl-http-cppRest ALIAS nakama-impl-http-cppRest) -set(HTTP_IMPL_LIB nakama-impl-http-cppRest PARENT_SCOPE) diff --git a/impl/httpCurl/CMakeLists.txt b/impl/httpCurl/CMakeLists.txt index 5ec457c39..a78c6be1e 100644 --- a/impl/httpCurl/CMakeLists.txt +++ b/impl/httpCurl/CMakeLists.txt @@ -14,5 +14,3 @@ target_include_directories(nakama-impl-http-libcurl PRIVATE ${CURL_INCLUDE_DIRS} target_link_libraries(nakama-impl-http-libcurl PUBLIC nakama-api-proto nakama::sdk-interface ) - -set(HTTP_IMPL_LIB nakama-impl-http-libcurl PARENT_SCOPE) diff --git a/impl/httpLibHttpClient/CMakeLists.txt b/impl/httpLibHttpClient/CMakeLists.txt index 0577a2a67..790ea0f8a 100644 --- a/impl/httpLibHttpClient/CMakeLists.txt +++ b/impl/httpLibHttpClient/CMakeLists.txt @@ -20,4 +20,3 @@ target_link_libraries(nakama-impl-http-libhttpclient # configure include paths PUBLIC ${LIBHTTPCLIENT_TARGET} ) -set(HTTP_IMPL_LIB nakama-impl-http-libhttpclient PARENT_SCOPE) diff --git a/impl/wsCppRest/CMakeLists.txt b/impl/wsCppRest/CMakeLists.txt index ddd4acf9b..260954aaf 100644 --- a/impl/wsCppRest/CMakeLists.txt +++ b/impl/wsCppRest/CMakeLists.txt @@ -16,4 +16,3 @@ target_link_libraries(nakama-impl-ws-cppRest PRIVATE cpprestsdk::cpprest OpenSSL::SSL ) add_library(nakama::impl-ws-cppRest ALIAS nakama-impl-ws-cppRest) -set(WS_IMPL_LIB nakama-impl-ws-cppRest PARENT_SCOPE) diff --git a/impl/wsWslay/CMakeLists.txt b/impl/wsWslay/CMakeLists.txt index 6ea3f5585..04cfd72b5 100644 --- a/impl/wsWslay/CMakeLists.txt +++ b/impl/wsWslay/CMakeLists.txt @@ -7,20 +7,20 @@ file( find_package(wslay CONFIG REQUIRED) add_library(nakama-impl-ws-wslay OBJECT ${srcs}) +add_library(nakama::impl-ws-wslay ALIAS nakama-impl-ws-wslay) -target_link_libraries(nakama-impl-ws-wslay PUBLIC - nakama-api-proto nakama::sdk-interface - nakama-sdk-core-common nakama-sdk-core-misc - wslay - ) +target_link_libraries(nakama-impl-ws-wslay + PUBLIC + nakama::sdk-interface + PRIVATE + nakama::sdk-core-common nakama::sdk-core-misc wslay +) target_include_directories(nakama-impl-ws-wslay INTERFACE "$" "$") -if (BUILD_CURL_IO OR BUILD_CURL_IO_SYSTEM) +if (CFG_WSLAY_CUR_IO) target_include_directories(nakama-impl-ws-wslay PRIVATE ${CURL_INCLUDE_DIRS}) endif() - -target_compile_definitions(nakama-impl-ws-wslay PUBLIC "WSLAY_NETIO_${WSLAY_NETIO}") diff --git a/impl/wsWslay/NWebsocketWslay.cpp b/impl/wsWslay/NWebsocketWslay.cpp index 43a3b93ba..31b1ad23a 100644 --- a/impl/wsWslay/NWebsocketWslay.cpp +++ b/impl/wsWslay/NWebsocketWslay.cpp @@ -5,7 +5,7 @@ #include "StrUtil.h" #include -#include "nakama-cpp/log/NLogger.h" +#include #include "NWebsocketWslay.h" #include #include diff --git a/impl/wsWslay/NWebsocketWslay.h b/impl/wsWslay/NWebsocketWslay.h index c13b2dfb4..5e15c5638 100644 --- a/impl/wsWslay/NWebsocketWslay.h +++ b/impl/wsWslay/NWebsocketWslay.h @@ -19,8 +19,8 @@ #include #include #include -#include "nakama-cpp/realtime/NRtTransportInterface.h" -#include +#include +#include "WslayIOInterface.h" namespace Nakama { @@ -74,4 +74,4 @@ class NWebsocketWslay : public NRtTransportInterface std::string::iterator _buf_iter; }; -} \ No newline at end of file +} diff --git a/impl/wsWslay/WslayIOInterface.h b/impl/wsWslay/WslayIOInterface.h index d6829587a..d8a757abb 100644 --- a/impl/wsWslay/WslayIOInterface.h +++ b/impl/wsWslay/WslayIOInterface.h @@ -1,6 +1,6 @@ #pragma once -#include "nakama-cpp/URLParts.h" +#include namespace Nakama { @@ -21,4 +21,4 @@ class WslayIOInterface { virtual NetIOAsyncResult connect_tick() = 0; }; -} \ No newline at end of file +} diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index efa16f389..9bcb95e6c 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -1,5 +1,3 @@ -cmake_minimum_required(VERSION 3.23) -project(nakama-sdk-core LANGUAGES CXX) include(GNUInstallDirs) file(GLOB CORE_HEADERS @@ -10,12 +8,6 @@ file(GLOB CORE_HEADERS include/nakama-cpp/data/realtime/rtdata/* ) -if (WS_IMPL STREQUAL "wslay") - file(GLOB WSLAY_HEADERS include/nakama-cpp/data/realtime/wslay/*) - list(APPEND CORE_HEADERS ${WSLAY_HEADERS}) -endif() - - add_library(nakama-sdk-interface INTERFACE ${CORE_HEADERS}) add_library(nakama::sdk-interface ALIAS nakama-sdk-interface) diff --git a/interface/config.h.in b/interface/config.h.in index 3fd50e18b..9f62ffbb5 100644 --- a/interface/config.h.in +++ b/interface/config.h.in @@ -1,6 +1,6 @@ #pragma once #cmakedefine optional_CONFIG_SELECT_OPTIONAL @optional_CONFIG_SELECT_OPTIONAL@ -#define @HTTP_COMPILE_DEFINITION@ -#define @WS_COMPILE_DEFINITION@ -#cmakedefine @WS_IO_COMPILE_DEFINITION@ +#cmakedefine WITH_GRPC_CLIENT +#cmakedefine HAVE_DEFAULT_TRANSPORT_FACTORY +#cmakedefine HAVE_DEFAULT_RT_TRANSPORT_FACTORY diff --git a/interface/include/nakama-cpp/ClientFactory.h b/interface/include/nakama-cpp/ClientFactory.h index c37d100ae..2d52d3c15 100644 --- a/interface/include/nakama-cpp/ClientFactory.h +++ b/interface/include/nakama-cpp/ClientFactory.h @@ -63,11 +63,11 @@ NAKAMA_NAMESPACE_BEGIN * * @param parameters the client parameters */ -#if !defined(WITH_EXTERNAL_HTTP) || defined(BUILD_GRPC_CLIENT) +#if defined(HAVE_DEFAULT_TRANSPORT_FACTORY) || defined(WITH_GRPC_CLIENT) NAKAMA_API NClientPtr createDefaultClient(const NClientParameters& parameters); #endif -#ifdef BUILD_GRPC_CLIENT +#ifdef WITH_GRPC_CLIENT /** * Creates the gRPC client to interact with Nakama server. * @@ -87,7 +87,7 @@ NAKAMA_NAMESPACE_BEGIN /** * Creates default HTTP transport using C++ REST SDK. */ -#ifndef WITH_EXTERNAL_HTTP +#ifdef HAVE_DEFAULT_TRANSPORT_FACTORY NAKAMA_API NHttpTransportPtr createDefaultHttpTransport(const NPlatformParameters& platformParams); #endif diff --git a/interface/include/nakama-cpp/NClientInterface.h b/interface/include/nakama-cpp/NClientInterface.h index 9f662875b..4f95c5695 100644 --- a/interface/include/nakama-cpp/NClientInterface.h +++ b/interface/include/nakama-cpp/NClientInterface.h @@ -94,7 +94,7 @@ NAKAMA_NAMESPACE_BEGIN */ virtual void tick() = 0; -#if !defined(WITH_EXTERNAL_WS) && !defined(BUILD_IO_EXTERNAL) +#if defined(HAVE_DEFAULT_RT_TRANSPORT_FACTORY) /** * Create a new real-time client with parameters from client. * @return a new NRtClient instance. diff --git a/interface/include/nakama-cpp/realtime/NWebsocketsFactory.h b/interface/include/nakama-cpp/realtime/NWebsocketsFactory.h index 43f1c426e..c41439d06 100644 --- a/interface/include/nakama-cpp/realtime/NWebsocketsFactory.h +++ b/interface/include/nakama-cpp/realtime/NWebsocketsFactory.h @@ -21,23 +21,15 @@ #include #include -#if defined BUILD_WEBSOCKET_WSLAY -#include -#endif - NAKAMA_NAMESPACE_BEGIN /** * Create default websocket transport. * */ -#if !defined(WITH_EXTERNAL_WS) && !defined(BUILD_IO_EXTERNAL) +#ifdef HAVE_DEFAULT_RT_TRANSPORT_FACTORY NAKAMA_API NRtTransportPtr createDefaultWebsocket(const NPlatformParameters& platformParameters); #endif -#if defined BUILD_WEBSOCKET_WSLAY - NAKAMA_API NRtTransportPtr createWslayWebsocket(std::unique_ptr io); -#endif - NAKAMA_NAMESPACE_END diff --git a/submodules/private b/submodules/private index 400b99dba..3eafd339d 160000 --- a/submodules/private +++ b/submodules/private @@ -1 +1 @@ -Subproject commit 400b99dbae1c7972a5de5a2851cf8734c91f13b4 +Subproject commit 3eafd339d7684c15ae8bfd6c0d022b24ff9352af From 786ee21bd223475e0ad78feaf505babdfc4f032c Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Thu, 3 Oct 2024 09:32:39 +0100 Subject: [PATCH 07/25] Fix private builds factory methods --- CMakeLists.txt | 2 +- cmake/compilerFlags.cmake | 20 +------------------- factory/ClientFactory.cpp | 2 +- interface/CMakeLists.txt | 4 ---- interface/config.h.in | 1 + interface/include/nakama-cpp/NExport.h | 5 ++++- submodules/private | 2 +- 7 files changed, 9 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f4890d97..c2990bb96 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -250,7 +250,6 @@ if (WITH_HTTP_CURL OR (WITH_WS_WSLAY AND CFG_WSLAY_CURL_IO)) target_link_libraries(nakama-sdk PRIVATE CURL::libcurl) endif() - if (APPLE AND BUILD_APPLE_FRAMEWORK) set_target_properties(nakama-sdk PROPERTIES FRAMEWORK TRUE @@ -305,6 +304,7 @@ if(MSVC) install(FILES $ DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT nakama-sdk OPTIONAL) endif() + ## use share directory for export files (at least a vcpkg convention) install(EXPORT nakama-export DESTINATION share/nakama-sdk) diff --git a/cmake/compilerFlags.cmake b/cmake/compilerFlags.cmake index 5cf480db9..0806390b7 100644 --- a/cmake/compilerFlags.cmake +++ b/cmake/compilerFlags.cmake @@ -1,7 +1,3 @@ -# This file has 2 purposes: -# - included from toolchain file -# - acts as CMAKE_USER_MAKE_RULES_OVERRIDE to override default compiler flags for vcpkg - # vcpkg doesn't allow us to select MinSizeRel, only Release and Debug are available, so we # set -Os flag in release builds to get smaller binaries if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") @@ -15,25 +11,11 @@ endif() string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_DEBUG_INIT "${CMAKE_C_FLAGS_DEBUG_INIT}") string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_DEBUG_INIT "${CMAKE_CXX_FLAGS_DEBUG_INIT}") -# Editing _INIT has effect when this file is used as part of toolchain -string(REPLACE "/Ob1" "/Ob2" CMAKE_CXX_FLAGS_MINSIZEREL_INIT "${CMAKE_CXX_FLAGS_MINSIZEREL_INIT}") -string(REPLACE "/Ob1" "/Ob2" CMAKE_C_FLAGS_MINSIZEREL_INIT "${CMAKE_C_FLAGS_MINSIZEREL_INIT}") - # Editing non _INIT flags has effect when this file is included from CMakeLists.txt directly string(REPLACE "/Ob1" "/Ob2" CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL}") string(REPLACE "/Ob1" "/Ob2" CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL}") -# When used as toolchain CMAKE_CXX_COMPILER_ID is still empty (toolchain is loaded too early -# for it it be set) so checks above wont work as expected. To make them work we set -# CMAKE_USER_MAKE_RULES_OVERRIDE so that CMake includes this file again, but -# very late this time. -# Note that all of it should come above include_guard() ,otherwise reinclusion -# wont work. -set(CMAKE_USER_MAKE_RULES_OVERRIDE "${CMAKE_CURRENT_LIST_FILE}") - -# Common compilation flags. Same file used by SDK code and to build vcpkg dependencies. -include_guard() # Minimize what's visible outside of shared lib set(CMAKE_CXX_VISIBILITY_PRESET hidden) @@ -42,7 +24,7 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_VISIBILITY_INLINES_HIDDEN ON) if (NOT CMAKE_BUILD_TYPE STREQUAL Debug) - set(CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE) + set(CMAKE_INTERPROCEDURAL_OPTIMIZATION OFF) endif() if (NOT MSVC) diff --git a/factory/ClientFactory.cpp b/factory/ClientFactory.cpp index 6a24a8f9e..b66f0797a 100644 --- a/factory/ClientFactory.cpp +++ b/factory/ClientFactory.cpp @@ -34,7 +34,7 @@ namespace Nakama { -#if !defined(WITH_PRIVATE_HTTP) || defined(WITH_GRPC_CLIENT) +#if defined(HAVE_DEFAULT_TRANSPORT_FACTORY) || defined(WITH_GRPC_CLIENT) NClientPtr createDefaultClient(const NClientParameters& parameters) { #if defined(WITH_GRPC_CLIENT) diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 9bcb95e6c..a370c331b 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -15,10 +15,6 @@ add_library(nakama::sdk-interface ALIAS nakama-sdk-interface) set(optional_CONFIG_SELECT_OPTIONAL optional_OPTIONAL_NONSTD) target_compile_definitions(nakama-sdk-interface INTERFACE optional_CONFIG_SELECT_OPTIONAL=${optional_CONFIG_SELECT_OPTIONAL}) -if (FORCE_DLL_IMPORT_EXPORT) - target_compile_definitions(nakama-sdk-interface INTERFACE FORCE_DLL_IMPORT_EXPORT) -endif() - # Create configure file with all configure_file(config.h.in nakama-cpp/config.h) diff --git a/interface/config.h.in b/interface/config.h.in index 9f62ffbb5..8ae5dc85b 100644 --- a/interface/config.h.in +++ b/interface/config.h.in @@ -4,3 +4,4 @@ #cmakedefine WITH_GRPC_CLIENT #cmakedefine HAVE_DEFAULT_TRANSPORT_FACTORY #cmakedefine HAVE_DEFAULT_RT_TRANSPORT_FACTORY +#cmakedefine FORCE_DLL_IMPORT_EXPORT diff --git a/interface/include/nakama-cpp/NExport.h b/interface/include/nakama-cpp/NExport.h index 35908c9c5..303c5eb2f 100644 --- a/interface/include/nakama-cpp/NExport.h +++ b/interface/include/nakama-cpp/NExport.h @@ -18,6 +18,9 @@ #undef NAKAMA_API +// That's where FORCE_DLL_IMPORT_EXPORT might be defined on some platforms +#include + #if defined _WIN32 || defined __CYGWIN__ || defined FORCE_DLL_IMPORT_EXPORT #ifdef NAKAMA_SHARED_LIBRARY_EXPORTS #define NAKAMA_API __declspec(dllexport) @@ -26,7 +29,7 @@ #endif #elif __GNUC__ >= 4 #ifdef NAKAMA_SHARED_LIBRARY_EXPORTS - #define NAKAMA_API __attribute__((visibility("default"))) + #define NAKAMA_API __attribute__((visibility("protected"))) #else #define NAKAMA_API #endif diff --git a/submodules/private b/submodules/private index 3eafd339d..43b5ffc7a 160000 --- a/submodules/private +++ b/submodules/private @@ -1 +1 @@ -Subproject commit 3eafd339d7684c15ae8bfd6c0d022b24ff9352af +Subproject commit 43b5ffc7a9f0f30c311f8ba6e78ce1218a0f7b8e From 6d76efee2b8ef2f868e9e15643e1719bae55792d Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Thu, 3 Oct 2024 11:25:19 +0100 Subject: [PATCH 08/25] Sync protobuf verion in public and private builds --- CMakeLists.txt | 4 ---- core/CMakeLists.txt | 3 --- core/buildProtoFiles.cmake | 2 -- submodules/private | 2 +- vcpkg.json | 5 ++++- 5 files changed, 5 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c2990bb96..4954628fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,10 +57,6 @@ endif() set(CMAKE_CONFIGURATION_TYPES "Debug;MinSizeRel") set(CMAKE_SUPPRESS_REGENERATION true) ## for Xcode -## TODO figure out why vcpkg seems to toggle these on and prevent downloading from fetchcontent -set(FETCHCONTENT_FULLY_DISCONNECTED OFF) -set(FETCHCONTENT_UPDATES_DISCONNECTED OFF) - # By default, assume user will not obtain optional-lite via third party mechanism. option(DISTRIBUTE_OPTIONAL_LITE "Distribute optional lite with the Nakama client." ON) option(FORCE_DLL_IMPORT_EXPORT "Force exporting and importing of symbols regardless of the platform." OFF) diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index e72269cd7..0e35d447c 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -1,6 +1,3 @@ -cmake_minimum_required(VERSION 3.29) -project(nakama-sdk-cpp DESCRIPTION "Nakama C++ Client" LANGUAGES CXX) - set(NAKAMA_GIT_TAG "master" CACHE STRING "nakama Git tag to fetch Proto files from") set(NAKAMA_COMMON_GIT_TAG "master" CACHE STRING "nakama-common Git tag to fetch Proto files from") diff --git a/core/buildProtoFiles.cmake b/core/buildProtoFiles.cmake index f7e05f819..51cc42cb5 100644 --- a/core/buildProtoFiles.cmake +++ b/core/buildProtoFiles.cmake @@ -1,6 +1,4 @@ # Fetch proto files from nakama and nakama-common and builds them -include(FetchContent) - set(NAKAMA_COMMON ${CMAKE_CURRENT_BINARY_DIR}/nakama-common-master) set(NAKAMA ${CMAKE_CURRENT_BINARY_DIR}/nakama-master) diff --git a/submodules/private b/submodules/private index 43b5ffc7a..cf5c94d52 160000 --- a/submodules/private +++ b/submodules/private @@ -1 +1 @@ -Subproject commit 43b5ffc7a9f0f30c311f8ba6e78ce1218a0f7b8e +Subproject commit cf5c94d521f1b87e56aed707b691c02f6853252f diff --git a/vcpkg.json b/vcpkg.json index e3c75ff10..a824b7ece 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -88,5 +88,8 @@ ], "supports": "android" } - } + }, + "overrides": [ + {"name": "protobuf", "version": "3.21.12", "port-version": 4} + ] } From cc9ae3c893ff3652461e640a16f33b282931a7fb Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Thu, 3 Oct 2024 11:25:53 +0100 Subject: [PATCH 09/25] Remove unnecesasry compile definition --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4954628fa..e63394312 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -105,7 +105,7 @@ if (ADDRESS_SANITIZER) string(REPLACE /RTC1 "" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG}) endif() -add_compile_definitions(NAKAMA_SHARED_LIBRARY NAKAMA_SHARED_LIBRARY_EXPORTS) +add_compile_definitions(NAKAMA_SHARED_LIBRARY_EXPORTS) if(APPLE AND BUILD_APPLE_FRAMEWORK) # Just copy over headers into framework dir, because "official" way of doing it From aa3b2fcc4df884d1d91063073ab47ab58f843771 Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Thu, 3 Oct 2024 14:00:51 +0100 Subject: [PATCH 10/25] libhttpclient build fixes --- .gitmodules | 4 ++++ CMakeLists.txt | 8 +++++-- cmake/libhttpClient.cmake | 18 ++++------------ impl/httpLibHttpClient/CMakeLists.txt | 1 + impl/httpLibHttpClient/NHttpClientLibHC.cpp | 24 ++++++++++++++++----- impl/httpLibHttpClient/NHttpClientLibHC.h | 4 +++- submodules/devkits | 2 +- submodules/libHttpClient | 1 + submodules/private | 2 +- 9 files changed, 40 insertions(+), 24 deletions(-) create mode 160000 submodules/libHttpClient diff --git a/.gitmodules b/.gitmodules index c8e7fb697..0907663bc 100644 --- a/.gitmodules +++ b/.gitmodules @@ -8,3 +8,7 @@ path = submodules/devkits url = https://github.com/heroiclabs/console-devkits.git shallow = true +[submodule "submodules/libHttpClient"] + path = submodules/libHttpClient + url = https://github.com/heroiclabs/libHttpClient.git + branch = luke/additional-cmake-fixes diff --git a/CMakeLists.txt b/CMakeLists.txt index e63394312..8391201da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -153,7 +153,9 @@ elseif(WITH_HTTP_LIBHTTPC) add_subdirectory(impl/httpLibHttpClient EXCLUDE_FROM_ALL) endif() if (HTTP_IMPL_LIB) - target_link_libraries(nakama-sdk-client-factory INTERFACE ${HTTP_IMPL_LIB} $) + target_link_libraries(nakama-sdk-client-factory + PUBLIC ${HTTP_IMPL_LIB} + INTERFACE $) endif() if(WITH_WS_LIBHTTPC) @@ -167,7 +169,9 @@ elseif(WITH_WS_CPPREST) add_subdirectory(impl/wsCppRest EXCLUDE_FROM_ALL) endif() if (WS_IMPL_LIB) - target_link_libraries(nakama-sdk-rtclient-factory INTERFACE ${WS_IMPL_LIB} $) + target_link_libraries(nakama-sdk-rtclient-factory + PUBLIC ${WS_IMPL_LIB} + INTERFACE $) endif() if (ANDROID AND (WITH_HTTP_CURL OR WITH_WS_WSLAY)) diff --git a/cmake/libhttpClient.cmake b/cmake/libhttpClient.cmake index 0638bae69..90f292f01 100644 --- a/cmake/libhttpClient.cmake +++ b/cmake/libhttpClient.cmake @@ -15,20 +15,10 @@ endif() ## force libhttpclient to build statically set(BUILD_SHARED_LIBS OFF) -FetchContent_Declare( - libHttpClient - GIT_REPOSITORY https://github.com/heroiclabs/libHttpClient.git - GIT_TAG c535d5943516bb5d8f3a50858da617ebd0dd3f3f - SOURCE_SUBDIR ${LIBHTTPCLIENT_SOURCE_SUBDIR} - GIT_PROGRESS TRUE - GIT_SHALLOW TRUE - GIT_SUBMODULES "" -) -FetchContent_MakeAvailable(libHttpClient) -if (${WAS_SHARED_LIBS}) - set(BUILD_SHARED_LIBS ON) -endif() +add_subdirectory("${CMAKE_SOURCE_DIR}/submodules/libHttpClient/${LIBHTTPCLIENT_SOURCE_SUBDIR}") + +set(BUILD_SHARED_LIBS ${WAS_SHARED_LIBS}) if (ANDROID) set(LIBHTTPCLIENT_TARGET libHttpClient.Android) @@ -65,7 +55,7 @@ endif() # in our ABI, because that is how JVM finds native code on Android platform. list(APPEND NAKAMA_SDK_DEPS ${LIBHTTPCLIENT_TARGET}) -if (WITH_WS_LIBHTTPC) +if (NOT WITH_WS_LIBHTTPC) target_compile_definitions(${LIBHTTPCLIENT_TARGET} PRIVATE "HC_NOWEBSOCKETS") else() if (LIBHTTPCLIENT_FORCE_WEBSOCKETPP) diff --git a/impl/httpLibHttpClient/CMakeLists.txt b/impl/httpLibHttpClient/CMakeLists.txt index 790ea0f8a..bb2fed0bf 100644 --- a/impl/httpLibHttpClient/CMakeLists.txt +++ b/impl/httpLibHttpClient/CMakeLists.txt @@ -8,6 +8,7 @@ file( set(CMAKE_INCLUDE_CURRENT_DIR ON) add_library(nakama-impl-http-libhttpclient OBJECT ${srcs}) +add_library(nakama::impl-http-libhttpclient ALIAS nakama-impl-http-libhttpclient) if (APPLE) target_compile_definitions(nakama-impl-http-libhttpclient INTERFACE "HC_APPLE_POSIX") diff --git a/impl/httpLibHttpClient/NHttpClientLibHC.cpp b/impl/httpLibHttpClient/NHttpClientLibHC.cpp index 99c8ffa85..184191f18 100644 --- a/impl/httpLibHttpClient/NHttpClientLibHC.cpp +++ b/impl/httpLibHttpClient/NHttpClientLibHC.cpp @@ -1,10 +1,24 @@ -// -// Created by yamlcoder on 17/03/2022. -// +/* + * Copyright 2022 The Nakama Authors + * + * 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 "NHttpClientLibHC.h" #include #include -#include "NHttpClientLibHC.h" + namespace Nakama { HC_DEFINE_TRACE_AREA(httpTransportLibHC, HCTraceLevel::Error); @@ -263,4 +277,4 @@ void NHttpClientLibHC::cancelAllRequests() { XTaskQueueDispatch(m_queue.get(), XTaskQueuePort::Completion, 50); } } -} \ No newline at end of file +} diff --git a/impl/httpLibHttpClient/NHttpClientLibHC.h b/impl/httpLibHttpClient/NHttpClientLibHC.h index 55f771110..aae254ec2 100644 --- a/impl/httpLibHttpClient/NHttpClientLibHC.h +++ b/impl/httpLibHttpClient/NHttpClientLibHC.h @@ -16,9 +16,11 @@ #pragma once -#include #include #include + +#include + #include namespace Nakama { diff --git a/submodules/devkits b/submodules/devkits index 27cd863e7..34ca8250f 160000 --- a/submodules/devkits +++ b/submodules/devkits @@ -1 +1 @@ -Subproject commit 27cd863e7d8dbc2b2537d965ab6524ed1bccb848 +Subproject commit 34ca8250fb930baa4c24a7124ffc3447241646a2 diff --git a/submodules/libHttpClient b/submodules/libHttpClient new file mode 160000 index 000000000..86aa4757a --- /dev/null +++ b/submodules/libHttpClient @@ -0,0 +1 @@ +Subproject commit 86aa4757ae757c08e2de4ef375210d430ec31609 diff --git a/submodules/private b/submodules/private index cf5c94d52..b77ef053a 160000 --- a/submodules/private +++ b/submodules/private @@ -1 +1 @@ -Subproject commit cf5c94d521f1b87e56aed707b691c02f6853252f +Subproject commit b77ef053a923749f85709a278bef47c7393a3167 From 1b7892ed9af47a3ec69d78adca866428b9ae6033 Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Fri, 4 Oct 2024 12:35:06 +0100 Subject: [PATCH 11/25] Windows: align project and vcpkg deps on toolchain used. Fix wslay builds. --- CMakeLists.txt | 13 +++++++--- CMakePresets.json | 1 + cmake/toolchains/vcpkg-msvc.cmake | 25 +++++++++++++++++++ .../arm64-windows-static-heroic.cmake | 5 ++-- .../triplets/x64-windows-static-heroic.cmake | 5 ++-- cmake/vcpkg-ports/wslay/portfile.cmake | 18 +------------ cmake/vcpkg-ports/wslay/vcpkg.json | 7 +----- factory/CMakeLists.txt | 3 ++- impl/wsWslay/CMakeLists.txt | 17 ++++++++----- impl/wsWslay/WslayIOCurl.h | 12 +++++---- submodules/private | 2 +- 11 files changed, 62 insertions(+), 46 deletions(-) create mode 100644 cmake/toolchains/vcpkg-msvc.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 8391201da..3af365b61 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,10 @@ option(CFG_CURL_SYSTEM "Use system-installed libCURL" OFF) option(WITH_GRPC_CLIENT "Build gRPC Client" OFF) +if (WITH_WS_WSLAY) + list(APPEND VCPKG_MANIFEST_FEATURES "wslay") +endif() + if (WITH_HTTP_CURL OR (WITH_WS_WSLAY AND CFG_WSLAY_CURL_IO)) if (NOT CFG_CURL_SYSTEM) list(APPEND VCPKG_MANIFEST_FEATURES "curl") @@ -74,6 +78,7 @@ if (DEFINED ANDROID_ABI AND NOT DEFINED VCPKG_CHAINLOAD_TOOLCHAIN_FILE) set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE $ENV{ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake) endif() +include("cmake/triplets/${VCPKG_TARGET_TRIPLET}.cmake" OPTIONAL) include("submodules/devkits/cmake/platform-${VCPKG_TARGET_TRIPLET}.cmake" OPTIONAL) include("submodules/private/cmake/preproject-${VCPKG_TARGET_TRIPLET}.cmake" OPTIONAL) @@ -154,7 +159,7 @@ elseif(WITH_HTTP_LIBHTTPC) endif() if (HTTP_IMPL_LIB) target_link_libraries(nakama-sdk-client-factory - PUBLIC ${HTTP_IMPL_LIB} + PRIVATE ${HTTP_IMPL_LIB} INTERFACE $) endif() @@ -170,7 +175,7 @@ elseif(WITH_WS_CPPREST) endif() if (WS_IMPL_LIB) target_link_libraries(nakama-sdk-rtclient-factory - PUBLIC ${WS_IMPL_LIB} + PRIVATE ${WS_IMPL_LIB} INTERFACE $) endif() @@ -178,11 +183,11 @@ if (ANDROID AND (WITH_HTTP_CURL OR WITH_WS_WSLAY)) add_subdirectory(impl/android) set(CREATE_JAR TRUE) # we need the code for accessing native Android CA store. - if (TARGET nakama-impl-http-libcurl) + if (TARGET nakama::impl-http-libcurl) target_link_libraries(nakama-impl-http-libcurl PUBLIC android-ca) endif() - if (TARGET nakama-impl-ws-wslay) + if (TARGET nakama::impl-ws-wslay) target_link_libraries(nakama-impl-ws-wslay PUBLIC android-ca) endif() diff --git a/CMakePresets.json b/CMakePresets.json index 348c9268d..5353e535e 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -28,6 +28,7 @@ "cacheVariables": { "CMAKE_SYSTEM_PROCESSOR": "AMD64", "VCPKG_TARGET_TRIPLET": "x64-windows-static-heroic", + "VCPKG_CHAINLOAD_TOOLCHAIN_FILE": "${sourceDir}/cmake/toolchains/vcpkg-msvc.cmake", "WITH_WS_WSLAY": "ON", "WITH_HTTP_CURL": "ON" }, diff --git a/cmake/toolchains/vcpkg-msvc.cmake b/cmake/toolchains/vcpkg-msvc.cmake new file mode 100644 index 000000000..044b992bf --- /dev/null +++ b/cmake/toolchains/vcpkg-msvc.cmake @@ -0,0 +1,25 @@ +# wrapper toolchain, which translates VCPKG_ vars into CMake vars +if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64") + set(CMAKE_SYSTEM_PROCESSOR "AMD64") +elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64") + set(CMAKE_SYSTEM_PROCESSOR "ARM64") +else() + message(FATAL_ERROR "Unsupported arch ${VCPKG_TARGET_ARCHITECTURE}") +endif() + +if(DEFINED VCPKG_CMAKE_SYSTEM_VERSION) + set(CMAKE_SYSTEM_VERSION "${VCPKG_CMAKE_SYSTEM_VERSION}" CACHE STRING "" FORCE) +elseif(NOT DEFINED CMAKE_SYSTEM_VERSION) + message(FATAL_ERROR "BUG: We should align vcpkg dependencies and our project on Windows SDK version. Include triplet vars in main project") +endif() + +list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES + VCPKG_CRT_LINKAGE VCPKG_TARGET_ARCHITECTURE + VCPKG_C_FLAGS VCPKG_CXX_FLAGS + VCPKG_C_FLAGS_DEBUG VCPKG_CXX_FLAGS_DEBUG + VCPKG_C_FLAGS_RELEASE VCPKG_CXX_FLAGS_RELEASE + VCPKG_LINKER_FLAGS VCPKG_LINKER_FLAGS_RELEASE VCPKG_LINKER_FLAGS_DEBUG + VCPKG_PLATFORM_TOOLSET CMAKE_SYSTEM_VERSION +) + +include("${CMAKE_CURRENT_LIST_DIR}/msvc/Windows.MSVC.toolchain.cmake") diff --git a/cmake/triplets/arm64-windows-static-heroic.cmake b/cmake/triplets/arm64-windows-static-heroic.cmake index aaa82bc49..e1b3d6114 100644 --- a/cmake/triplets/arm64-windows-static-heroic.cmake +++ b/cmake/triplets/arm64-windows-static-heroic.cmake @@ -1,9 +1,8 @@ set(VCPKG_TARGET_ARCHITECTURE arm64) set(VCPKG_CRT_LINKAGE dynamic) set(VCPKG_LIBRARY_LINKAGE static) -set(CMAKE_GENERATOR Visual Studio 17 2022) +set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${CMAKE_CURRENT_LIST_DIR}/../toolchains/vcpkg-msvc.cmake") +set(VCPKG_CMAKE_SYSTEM_VERSION "10.0.22621.0") string(APPEND VCPKG_C_FLAGS_RELEASE " /O1 /Ob2 /Gw /Gy") string(APPEND VCPKG_CXX_FLAGS_RELEASE " /O1 /Ob2 /Gw /Gy") - -list(APPEND VCPKG_KEEP_ENV_VARS "PATH" "Path") diff --git a/cmake/triplets/x64-windows-static-heroic.cmake b/cmake/triplets/x64-windows-static-heroic.cmake index f51a82afd..6b795ed4e 100644 --- a/cmake/triplets/x64-windows-static-heroic.cmake +++ b/cmake/triplets/x64-windows-static-heroic.cmake @@ -1,9 +1,8 @@ set(VCPKG_TARGET_ARCHITECTURE x64) set(VCPKG_CRT_LINKAGE dynamic) set(VCPKG_LIBRARY_LINKAGE static) -set(CMAKE_GENERATOR Visual Studio 17 2022) +set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${CMAKE_CURRENT_LIST_DIR}/../toolchains/vcpkg-msvc.cmake") +set(VCPKG_CMAKE_SYSTEM_VERSION "10.0.22621.0") string(APPEND VCPKG_C_FLAGS_RELEASE " /O1 /Ob2 /Gw /Gy") string(APPEND VCPKG_CXX_FLAGS_RELEASE " /O1 /Ob2 /Gw /Gy") - -list(APPEND VCPKG_KEEP_ENV_VARS "PATH" "Path") diff --git a/cmake/vcpkg-ports/wslay/portfile.cmake b/cmake/vcpkg-ports/wslay/portfile.cmake index d702263a5..2b4813427 100644 --- a/cmake/vcpkg-ports/wslay/portfile.cmake +++ b/cmake/vcpkg-ports/wslay/portfile.cmake @@ -8,33 +8,17 @@ vcpkg_from_github( HEAD_REF master PATCHES msvc_compat.patch -# msvc_compat2.patch + msvc_compat2.patch ) string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "static" BUILD_STATIC) string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "dynamic" BUILD_SHARED) -vcpkg_check_features( - OUT_FEATURE_OPTIONS FEATURE_OPTIONS - FEATURES - windows-use-msbuild WINDOWS_USE_MSBUILD -) - -if(WINDOWS_USE_MSBUILD) - set(WINDOWS_USE_MSBUILD_OPTION "WINDOWS_USE_MSBUILD") -else() - set(WINDOWS_USE_MSBUILD_OPTION "") -endif() - vcpkg_cmake_configure( SOURCE_PATH ${SOURCE_PATH} - ${WINDOWS_USE_MSBUILD_OPTION} OPTIONS -DWSLAY_STATIC=${BUILD_STATIC} -DWSLAY_SHARED=${BUILD_SHARED} - - # On consoles system header files are using GNU extensions - -DCMAKE_C_FLAGS_INIT="-Wno-gnu-statement-expression" ) vcpkg_cmake_install() diff --git a/cmake/vcpkg-ports/wslay/vcpkg.json b/cmake/vcpkg-ports/wslay/vcpkg.json index 89e3f8715..177028a18 100644 --- a/cmake/vcpkg-ports/wslay/vcpkg.json +++ b/cmake/vcpkg-ports/wslay/vcpkg.json @@ -14,10 +14,5 @@ "name": "vcpkg-cmake-config", "host": true } - ], - "features": { - "windows-use-msbuild": { - "description": "Whether or not to compile the SDK with MSBuild on Windows machines." - } - } + ] } diff --git a/factory/CMakeLists.txt b/factory/CMakeLists.txt index 05ff6e0ed..fcee0e009 100644 --- a/factory/CMakeLists.txt +++ b/factory/CMakeLists.txt @@ -15,7 +15,8 @@ add_library(nakama::sdk-rtclient-factory ALIAS nakama-sdk-rtclient-factory) target_link_libraries(nakama-sdk-rtclient-factory PUBLIC nakama::sdk-interface) target_compile_definitions(nakama-sdk-rtclient-factory PRIVATE - $<$:WITH_WS_WLAY> + $<$:WITH_WS_WSLAY> + $<$:CFG_WSLAY_CURL_IO> $<$:WITH_WS_LIBHTTPC> $<$:WITH_WS_CPPREST> ) diff --git a/impl/wsWslay/CMakeLists.txt b/impl/wsWslay/CMakeLists.txt index 04cfd72b5..60db446db 100644 --- a/impl/wsWslay/CMakeLists.txt +++ b/impl/wsWslay/CMakeLists.txt @@ -1,5 +1,5 @@ file( - GLOB_RECURSE srcs + GLOB srcs LIST_DIRECTORIES false "${CMAKE_CURRENT_SOURCE_DIR}/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" @@ -17,10 +17,15 @@ target_link_libraries(nakama-impl-ws-wslay ) target_include_directories(nakama-impl-ws-wslay INTERFACE - "$" - "$") - + $ # for WslayIOInterface.h +) -if (CFG_WSLAY_CUR_IO) - target_include_directories(nakama-impl-ws-wslay PRIVATE ${CURL_INCLUDE_DIRS}) +if (CFG_WSLAY_CURL_IO) + # Even though WslayIOCUrl is in this lib, it is a header and gets compiled + # in the factory lib where it #include'd. + # So we need to CMake INTERFACE anything might be required to compile + target_link_libraries(nakama-impl-ws-wslay INTERFACE + CURL::libcurl + nakama::sdk-core-common # for StrUtil.h + ) endif() diff --git a/impl/wsWslay/WslayIOCurl.h b/impl/wsWslay/WslayIOCurl.h index 5b0b37828..7d6b63908 100644 --- a/impl/wsWslay/WslayIOCurl.h +++ b/impl/wsWslay/WslayIOCurl.h @@ -1,10 +1,12 @@ #pragma once +#include "StrUtil.h" +#include "WslayIOInterface.h" +#include + +#include + #include #include -#include -#include -#include "StrUtil.h" -#include "nakama-cpp/realtime/wslay/WslayIOInterface.h" #if __ANDROID__ #include "AndroidCA.h" @@ -152,4 +154,4 @@ class WslayIOCurl : public WslayIOInterface { std::unique_ptr _curl_url; }; -NAKAMA_NAMESPACE_END \ No newline at end of file +NAKAMA_NAMESPACE_END diff --git a/submodules/private b/submodules/private index b77ef053a..ba960b0a9 160000 --- a/submodules/private +++ b/submodules/private @@ -1 +1 @@ -Subproject commit b77ef053a923749f85709a278bef47c7393a3167 +Subproject commit ba960b0a98cbaaa3c9e199a6c39d0bf6d6b3faa8 From 23cdd44b94a908a1856ee6b55c73cdd61837cf19 Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Fri, 4 Oct 2024 22:12:21 +0100 Subject: [PATCH 12/25] Update to latest libHttpClient and provide build script for it. Also simplify bunch of build instructions --- CMakeLists.txt | 29 ++++------------- README.md | 17 ++-------- cmake/libHttpClient/CMakeLists.txt | 52 ++++++++++++++++++++++++++++++ cmake/libhttpClient.cmake | 15 ++++----- cmake/platformSupport.cmake | 10 ++---- core/buildProtoFiles.cmake | 10 ++---- core/common/CMakeLists.txt | 5 ++- impl/android/CMakeLists.txt | 4 +-- impl/wsWslay/CMakeLists.txt | 4 +-- interface/CMakeLists.txt | 8 ++--- nakama-sdk-preconfig.cmake.in | 1 - submodules/libHttpClient | 2 +- submodules/private | 2 +- vcpkg.json | 23 ++----------- 14 files changed, 83 insertions(+), 99 deletions(-) create mode 100644 cmake/libHttpClient/CMakeLists.txt delete mode 100644 nakama-sdk-preconfig.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 3af365b61..68bace08a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,12 +27,8 @@ if (WITH_HTTP_CURL OR (WITH_WS_WSLAY AND CFG_WSLAY_CURL_IO)) endif() endif() -if (WITH_HTTP_LIBHTTPC AND NOT CFG_LIBHTTPC_SYSTEM) - list(APPEND VCPKG_MANIFEST_FEATURES "libhttpclient-http") -endif() - -if (WITH_WS_LIBHTTPC AND NOT CFG_LIBHTTPC_SYSTEM) - list(APPEND VCPKG_MANIFEST_FEATURES "libhttpclient-ws") +if ((WITH_WS_LIBHTTPC OR WITH_HTTP_LIBHTTPC) AND NOT CFG_LIBHTTPC_SYSTEM) + list(APPEND VCPKG_MANIFEST_FEATURES "libhttpclient") endif() if (WITH_HTTP_CPPREST OR WITH_WS_CPPREST) @@ -90,8 +86,6 @@ include(cmake/linkerFlags.cmake) include(GNUInstallDirs) include(FetchContent) -include(InstallRequiredSystemLibraries) - set(CMAKE_CXX_STANDARD 17) option(LOGS_ENABLED "Enable log output" ON) @@ -145,7 +139,7 @@ add_subdirectory(core EXCLUDE_FROM_ALL) # Factories, that's where all messy ifdefs to select concrete implementations are add_subdirectory(factory EXCLUDE_FROM_ALL) -include("submodules/private/cmake/target-${VCPKG_TARGET_TRIPLET}.cmake" OPTIONAL RESULT_VARIABLE PRIVATE_TARGETS) +include("submodules/private/cmake/target-${VCPKG_TARGET_TRIPLET}.cmake" OPTIONAL) if (WITH_HTTP_CPPREST) set(HTTP_IMPL_LIB nakama-impl-http-cppRest) @@ -287,20 +281,14 @@ if (ADDRESS_SANITIZER) endif() -#Install doesn't support ALIASes, transform them into 'flat' non alias names -list(TRANSFORM NAKAMA_SDK_DEPS REPLACE "::" "-" OUTPUT_VARIABLE NAKAMA_SDK_DEPS_TARGETS) install(TARGETS nakama-sdk nakama-sdk-interface - nakama-api-proto - ${HTTP_IMPL_LIB} - ${WS_IMPL_LIB} - ${NAKAMA_SDK_DEPS_TARGETS} EXPORT nakama-export - FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT nakama-sdk - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT nakama-sdk - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT nakama-sdk - RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT nakama-sdk + FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR} FILE_SET HEADERS COMPONENT headers INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" ) @@ -323,11 +311,8 @@ configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/nakama-sdk-config.cmak NO_CHECK_REQUIRED_COMPONENTS_MACRO ) -## for any variables that need to be read by consuming packages before their project() call, since find_package must be done after project() -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/nakama-sdk-preconfig.cmake.in ${CMAKE_BINARY_DIR}/nakama-sdk-preconfig.cmake) install(FILES - ${CMAKE_CURRENT_BINARY_DIR}/nakama-sdk-preconfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/nakama-sdk-config.cmake DESTINATION share/nakama-sdk ) diff --git a/README.md b/README.md index 5cd358762..2ee39dadf 100644 --- a/README.md +++ b/README.md @@ -178,8 +178,6 @@ Note: to use logging macros you have to define `NLOGS_ENABLED`. Nakama C++ client has built-in support for WebSocket. This is available on all supported platforms. -Client will default to use the Websocket transport provided by [C++ REST SDK](https://github.com/microsoft/cpprestsdk). - You can use a custom Websocket transport by implementing the [NRtTransportInterface](https://github.com/heroiclabs/nakama-cpp/blob/master/include/nakama-cpp/realtime/NRtTransportInterface.h): ```cpp @@ -212,14 +210,9 @@ Then you will need to load our native library from Java by calling `System.loadL # How to build -## Prerequisite - -You should download vcpkg (https://github.com/microsoft/vcpkg) somewhere on your machine set your $VCPKG_ROOT environment variable to point to the -repository. - ### Windows -- [CMake >= 3.22](https://cmake.org/download/) +- [CMake >= 3.29](https://cmake.org/download/) - [Ninja](https://ninja-build.org/) - [Build Tools for Visual Studio 2022](https://visualstudio.microsoft.com/downloads/) @@ -299,10 +292,6 @@ Your NDK is typically located within your SDK:`/ndk/` Our prebuilt libraries target Android NDK 25.1.8937393. -### Windows 32-Bit - -We support native 32-bit builds. Keep in mind that when building from source, you must run your command -in a 32-bit (e.g., C:\Windows\System32\cmd.exe) environment. ### Build modifiers @@ -317,15 +306,13 @@ Supported build modifiers are: websocketpp transport and uses it if Windows doesn't support websocket natively (< Windows 8). You can set this build modifier to force use of websocketpp transport, so that it can be tested without installing Windows 7. If you -- `WITH_LIBCXX`: dynamically link with libc++ instead of libstdc++ on Linux platform. - - `LIBCXX_STATIC`: link libc++ statically - `ADDRESS_SANITIZER`: instrument library with [AddressSanitizer](https://github.com/google/sanitizers/wiki/AddressSanitizer) Build modifiers are CMake variables passed at configure time using `-D` switch. Example use: ``` -cmake --preset linux-amd64 -DWITH_LIBCXX=ON +cmake --preset linux-amd64 -DADDRESS_SANITIZER=ON ``` ## Release diff --git a/cmake/libHttpClient/CMakeLists.txt b/cmake/libHttpClient/CMakeLists.txt new file mode 100644 index 000000000..bdddd7f8d --- /dev/null +++ b/cmake/libHttpClient/CMakeLists.txt @@ -0,0 +1,52 @@ +# Upstream libHttpClient stopped offering CMake based builds +# This file recreates same experience by (pooorly) reading upstream .vcxproj +set(LHC_ROOT "${CMAKE_SOURCE_DIR}/submodules/libHttpClient") + +include(CMakePrintHelpers) + +# Reads ClInclude from $1 and returns list of absolute paths in $2 +function(vcxproj_read_file_list) + cmake_path(GET ARGV0 PARENT_PATH BASEDIR) + file(READ "${ARGV0}" RAW) + STRING(REGEX MATCHALL [=[<(ClInclude|ClCompile) Include="[^"]+"]=] CLINCLUDES_RAW "${RAW}") + list(TRANSFORM CLINCLUDES_RAW REPLACE [=[<(ClInclude|ClCompile) Include="\$\(MSBuildThisFileDirectory\)([^"]+)"]=] "\\2" OUTPUT_VARIABLE CLINCLUDES) + foreach (P ${CLINCLUDES}) + cmake_path(ABSOLUTE_PATH P BASE_DIRECTORY "${BASEDIR}" NORMALIZE) + list(APPEND OUT "${P}") + endforeach () + set(${ARGV1} ${OUT} PARENT_SCOPE) +endfunction() + +vcxproj_read_file_list("${LHC_ROOT}/Build/libHttpClient.Common/libHttpClient.Common.vcxitems" COMMON_FILES) +vcxproj_read_file_list("${LHC_ROOT}/Build/libHttpClient.XAsync/libHttpClient.XAsync.vcxitems" XASYNC_FILES) +vcxproj_read_file_list("${LHC_ROOT}/Build/libHttpClient.Win32.Shared/libHttpClient.Win32.Shared.vcxitems" WIN32_SHARED_FILES) + +if (GDK) +elseif (WIN32) + set(FILES ${COMMON_FILES} ${XASYNC_FILES} ${WIN32_SHARED_FILES}) +else() + message(FATAL_ERROR "libHTTPClient is supported only on Windows-based platforms") +endif() + +find_package(ZLIB REQUIRED) + +add_library(libHttpClient OBJECT ${FILES}) +target_include_directories(libHttpClient + PUBLIC + ${LHC_ROOT}/Include + PRIVATE + ${LHC_ROOT}/Source + ${LHC_ROOT}/Source/Common +) +if (NOT WITH_WS_LIBHTTPC) + target_compile_definitions(libHttpClient PUBLIC "HC_NOWEBSOCKETS") +endif() +target_link_libraries(libHttpClient PRIVATE + ZLIB::ZLIB + "Appnotify.lib" + "winhttp.lib" + "crypt32.lib" +) + +#set_target_properties(libHttpClient PROPERTIES LINKER_LANGUAGE CXX) + diff --git a/cmake/libhttpClient.cmake b/cmake/libhttpClient.cmake index 90f292f01..d3bfcad82 100644 --- a/cmake/libhttpClient.cmake +++ b/cmake/libhttpClient.cmake @@ -8,15 +8,16 @@ set(LIBHTTPCLIENT_OBJECT_LIBRARY TRUE) set(WAS_SHARED_LIBS ${BUILD_SHARED_LIBS}) if (ANDROID) - set(LIBHTTPCLIENT_SOURCE_SUBDIR Utilities/CMake/Android/libHttpClient) -else() - set(LIBHTTPCLIENT_SOURCE_SUBDIR Utilities/CMake) + set(LIBHTTPCLIENT_SOURCE_SUBDIR "Build/libHttpClient.Android") + return() endif() +add_subdirectory(cmake/libHttpClient) + ## force libhttpclient to build statically set(BUILD_SHARED_LIBS OFF) -add_subdirectory("${CMAKE_SOURCE_DIR}/submodules/libHttpClient/${LIBHTTPCLIENT_SOURCE_SUBDIR}") +#add_subdirectory("${CMAKE_SOURCE_DIR}/submodules/libHttpClient/${LIBHTTPCLIENT_SOURCE_SUBDIR}") set(BUILD_SHARED_LIBS ${WAS_SHARED_LIBS}) @@ -48,6 +49,7 @@ else() endif() endif() endif() +set(LIBHTTPCLIENT_TARGET "libHttpClient") # We build LIBHTTPCLIENT as OBJECT library so that its symbols # wont be excluded due to '--exclude-libs ALL' linker flag. Although we @@ -57,9 +59,4 @@ list(APPEND NAKAMA_SDK_DEPS ${LIBHTTPCLIENT_TARGET}) if (NOT WITH_WS_LIBHTTPC) target_compile_definitions(${LIBHTTPCLIENT_TARGET} PRIVATE "HC_NOWEBSOCKETS") -else() - if (LIBHTTPCLIENT_FORCE_WEBSOCKETPP) - message(STATUS "Forcing libhttpclient to use websocketpp even on modern Windows platforms") - target_compile_definitions(${LIBHTTPCLIENT_TARGET} PRIVATE "HC_FORCE_WINSOCKETPP") - endif() endif() diff --git a/cmake/platformSupport.cmake b/cmake/platformSupport.cmake index 2976067f7..0af9b628f 100644 --- a/cmake/platformSupport.cmake +++ b/cmake/platformSupport.cmake @@ -5,15 +5,9 @@ endif() # Various platform specific defines if (CMAKE_SYSTEM_NAME STREQUAL Windows OR WindowsDesktop) - set(WindowsDesktop ON) - message("Configuring Windows Desktop build") - # Sets minimual Windows version we are targeting - # https://docs.microsoft.com/en-us/windows/win32/WinProg/using-the-windows-headers - add_compile_definitions(NTDDI_VERSION=NTDDI_WIN7 _WIN32_WINNT=_WIN32_WINNT_WIN7) - set(BUILDWIN32 ON) # libhttpclient + add_compile_definitions(_UNICODE UNICODE) set(CMAKE_INSTALL_BINDIR ${CMAKE_INSTALL_LIBDIR}) # place .dll where .lib is so that multiplatform archives can be created elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin) - set(Darwin) message("Configuring Apple MacOSX build") # when changing, dont forget also set it in {arm64,x64}-osx-heroic vcpkg triplet # NOTE: we can't use CMAKE_SYSTEM_PROCESSOR here because it is always arm64 on M1 silicon for some reason @@ -40,4 +34,4 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") set(PTHREADS_LIB Threads::Threads) endif() -set(__PLATFORM_SUPPORT_CONFIGURED ON) \ No newline at end of file +set(__PLATFORM_SUPPORT_CONFIGURED ON) diff --git a/core/buildProtoFiles.cmake b/core/buildProtoFiles.cmake index 51cc42cb5..dac3a1b61 100644 --- a/core/buildProtoFiles.cmake +++ b/core/buildProtoFiles.cmake @@ -22,10 +22,7 @@ add_library(nakama-api-proto OBJECT ${NAKAMA_API_PROTO_FILES}) add_library(nakama::api-proto ALIAS nakama-api-proto) target_link_libraries(nakama-api-proto PRIVATE protobuf::libprotobuf) -target_include_directories(nakama-api-proto PUBLIC - $ - $ -) +target_include_directories(nakama-api-proto PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) protobuf_generate(TARGET nakama-api-proto LANGUAGE cpp @@ -70,10 +67,7 @@ target_link_libraries(nakama-grpc-proto PUBLIC -Wl,--exclude-libs=ALL gRPC::grpc++ ) -target_include_directories(nakama-grpc-proto PUBLIC - $ - $ - ) +target_include_directories(nakama-grpc-proto PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) install(TARGETS nakama-grpc-proto diff --git a/core/common/CMakeLists.txt b/core/common/CMakeLists.txt index c68d5c0c7..110c38f75 100644 --- a/core/common/CMakeLists.txt +++ b/core/common/CMakeLists.txt @@ -32,9 +32,8 @@ target_link_libraries(nakama-sdk-core-common protobuf::libprotobuf # because of StrUtil::Base64Encode ) -target_include_directories(nakama-sdk-core-common PUBLIC - $ - $ +target_include_directories(nakama-sdk-core-common + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ) diff --git a/impl/android/CMakeLists.txt b/impl/android/CMakeLists.txt index e52b403e8..869da7055 100644 --- a/impl/android/CMakeLists.txt +++ b/impl/android/CMakeLists.txt @@ -6,9 +6,7 @@ file( ) add_library(android-ca OBJECT ${srcs}) -target_include_directories(android-ca PUBLIC - "$" - "$") +target_include_directories(android-ca PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_link_libraries(android-ca PRIVATE android nakama-sdk-core-misc diff --git a/impl/wsWslay/CMakeLists.txt b/impl/wsWslay/CMakeLists.txt index 60db446db..eace2160b 100644 --- a/impl/wsWslay/CMakeLists.txt +++ b/impl/wsWslay/CMakeLists.txt @@ -16,8 +16,8 @@ target_link_libraries(nakama-impl-ws-wslay nakama::sdk-core-common nakama::sdk-core-misc wslay ) -target_include_directories(nakama-impl-ws-wslay INTERFACE - $ # for WslayIOInterface.h +target_include_directories(nakama-impl-ws-wslay + INTERFACE ${CMAKE_CURRENT_SOURCE_DIR} # for WslayIOInterface.h ) if (CFG_WSLAY_CURL_IO) diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index a370c331b..951a05477 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -1,11 +1,7 @@ include(GNUInstallDirs) -file(GLOB CORE_HEADERS - include/nakama-cpp/* - include/nakama-cpp/data/* - include/nakama-cpp/data/log/* - include/nakama-cpp/data/realtime/* - include/nakama-cpp/data/realtime/rtdata/* +file(GLOB_RECURSE CORE_HEADERS + include/*.h ) add_library(nakama-sdk-interface INTERFACE ${CORE_HEADERS}) diff --git a/nakama-sdk-preconfig.cmake.in b/nakama-sdk-preconfig.cmake.in deleted file mode 100644 index e705c6c7b..000000000 --- a/nakama-sdk-preconfig.cmake.in +++ /dev/null @@ -1 +0,0 @@ -set(NAKAMA_SDK_BUILD_TYPE "@NAKAMA_SDK_BUILD_TYPE@") diff --git a/submodules/libHttpClient b/submodules/libHttpClient index 86aa4757a..9aa521a60 160000 --- a/submodules/libHttpClient +++ b/submodules/libHttpClient @@ -1 +1 @@ -Subproject commit 86aa4757ae757c08e2de4ef375210d430ec31609 +Subproject commit 9aa521a60cb306ae23970039fbca8ff647bb95e0 diff --git a/submodules/private b/submodules/private index ba960b0a9..d57390d26 160000 --- a/submodules/private +++ b/submodules/private @@ -1 +1 @@ -Subproject commit ba960b0a98cbaaa3c9e199a6c39d0bf6d6b3faa8 +Subproject commit d57390d26c272d61b30f02f8c81c8857c9234fa8 diff --git a/vcpkg.json b/vcpkg.json index a824b7ece..252c3cd7c 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -8,29 +8,12 @@ "optional-lite" ], "features": { - "libhttpclient-ws": { - "description": "Websockets library that delegates to other implementations.", - "supports": "windows | android", + "libhttpclient": { + "description": "libhttpclient dependencies", "dependencies": [ - { - "name": "websocketpp", - "default-features": false, - "platform": "windows" - }, - { - "name": "asio", - "platform": "windows" - }, - { - "name": "openssl", - "platform": "windows" - } + {"name": "zlib"} ] }, - "libhttpclient-http": { - "description": "HTTP library that delegates to other implementations.", - "supports": "windows | android | osx | ios | linux" - }, "wslay": { "description": "Websockets library decoupled from IO and handshakes.", "dependencies": [ From 1df408748a5576f9084140cbd8336ed40cab5039 Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Fri, 4 Oct 2024 22:36:30 +0100 Subject: [PATCH 13/25] switch to upstream libhttpclient --- .gitmodules | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index 0907663bc..57a23f60b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,5 +10,4 @@ shallow = true [submodule "submodules/libHttpClient"] path = submodules/libHttpClient - url = https://github.com/heroiclabs/libHttpClient.git - branch = luke/additional-cmake-fixes + url = https://github.com/microsoft/libHttpClient.git From 2461989c347c0e61d034e34bda07166285569467 Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Sat, 5 Oct 2024 08:43:17 +0100 Subject: [PATCH 14/25] Use aliases where possible for safety, cleanup libhttpclient build scripts --- CMakeLists.txt | 15 +++---- cmake/libhttpClient.cmake | 62 ++++++----------------------- impl/wsLibHttpClient/CMakeLists.txt | 1 + 3 files changed, 22 insertions(+), 56 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 68bace08a..a0ce6d30c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -142,13 +142,13 @@ add_subdirectory(factory EXCLUDE_FROM_ALL) include("submodules/private/cmake/target-${VCPKG_TARGET_TRIPLET}.cmake" OPTIONAL) if (WITH_HTTP_CPPREST) - set(HTTP_IMPL_LIB nakama-impl-http-cppRest) + set(HTTP_IMPL_LIB nakama::impl-http-cppRest) add_subdirectory(impl/httpCppRest EXCLUDE_FROM_ALL) elseif(WITH_HTTP_CURL) - set(HTTP_IMPL_LIB nakama-impl-http-libcurl) + set(HTTP_IMPL_LIB nakama::impl-http-libcurl) add_subdirectory(impl/httpCurl EXCLUDE_FROM_ALL) elseif(WITH_HTTP_LIBHTTPC) - set(HTTP_IMPL_LIB nakama-impl-http-libhttpclient) + set(HTTP_IMPL_LIB nakama::impl-http-libhttpclient) add_subdirectory(impl/httpLibHttpClient EXCLUDE_FROM_ALL) endif() if (HTTP_IMPL_LIB) @@ -158,13 +158,13 @@ if (HTTP_IMPL_LIB) endif() if(WITH_WS_LIBHTTPC) - set(WS_IMPL_LIB nakama-impl-ws-libhttpclient) + set(WS_IMPL_LIB nakama::impl-ws-libhttpclient) add_subdirectory(impl/wsLibHttpClient EXCLUDE_FROM_ALL) elseif(WITH_WS_WSLAY) - set(WS_IMPL_LIB nakama-impl-ws-wslay) + set(WS_IMPL_LIB nakama::impl-ws-wslay) add_subdirectory(impl/wsWslay EXCLUDE_FROM_ALL) elseif(WITH_WS_CPPREST) - set(WS_IMPL_LIB nakama-impl-ws-cppRest) + set(WS_IMPL_LIB nakama::impl-ws-cppRest) add_subdirectory(impl/wsCppRest EXCLUDE_FROM_ALL) endif() if (WS_IMPL_LIB) @@ -242,7 +242,8 @@ target_link_libraries(nakama-sdk nakama::sdk-interface PRIVATE nakama::api-proto - $<$:nakama::grpc-proto> + $ + $<$:$> ${NAKAMA_SDK_DEPS} ) if (WITH_HTTP_CURL OR (WITH_WS_WSLAY AND CFG_WSLAY_CURL_IO)) diff --git a/cmake/libhttpClient.cmake b/cmake/libhttpClient.cmake index d3bfcad82..4528bc2cb 100644 --- a/cmake/libhttpClient.cmake +++ b/cmake/libhttpClient.cmake @@ -3,60 +3,24 @@ if (LINUX OR APPLE) target_compile_definitions(CURL::libcurl INTERFACE CURL_STRICTER) endif() - -set(LIBHTTPCLIENT_OBJECT_LIBRARY TRUE) -set(WAS_SHARED_LIBS ${BUILD_SHARED_LIBS}) - if (ANDROID) + ## force libhttpclient to build statically + set(WAS_SHARED_LIBS ${BUILD_SHARED_LIBS}) + set(BUILD_SHARED_LIBS OFF) set(LIBHTTPCLIENT_SOURCE_SUBDIR "Build/libHttpClient.Android") - return() -endif() - -add_subdirectory(cmake/libHttpClient) - -## force libhttpclient to build statically -set(BUILD_SHARED_LIBS OFF) - -#add_subdirectory("${CMAKE_SOURCE_DIR}/submodules/libHttpClient/${LIBHTTPCLIENT_SOURCE_SUBDIR}") - -set(BUILD_SHARED_LIBS ${WAS_SHARED_LIBS}) - -if (ANDROID) + add_subdirectory("${CMAKE_SOURCE_DIR}/submodules/libHttpClient/${LIBHTTPCLIENT_SOURCE_SUBDIR}") + set(BUILD_SHARED_LIBS ${WAS_SHARED_LIBS}) set(LIBHTTPCLIENT_TARGET libHttpClient.Android) -else() - - if(XDK) - if (WINRT) - set(LIBHTTPCLIENT_TARGET libHttpClient.XDK.WinRT) - else() - set(LIBHTTPCLIENT_TARGET libHttpClient.XDK.C) - endif() - elseif (GDK) - set(LIBHTTPCLIENT_TARGET libHttpClient.GDK.C) - include(submodules/devkits/cmake/gdk-targets.cmake) - target_link_libraries(${LIBHTTPCLIENT_TARGET} PRIVATE GDK::XCurl) - elseif (BUILDWIN32) - set(LIBHTTPCLIENT_TARGET libHttpClient.Win32.C) - elseif (APPLE) - set(LIBHTTPCLIENT_TARGET libHttpClient.Apple.C) - elseif(DEFINED LINUX) - set(LIBHTTPCLIENT_TARGET libHttpClient.Linux.C) - else() - if (WINRT) - set(LIBHTTPCLIENT_TARGET libHttpClient.UWP.WinRT) - else() - set(LIBHTTPCLIENT_TARGET libHttpClient.UWP.C) - endif() - endif() +else () + add_subdirectory(cmake/libHttpClient) + set(LIBHTTPCLIENT_TARGET libHttpClient) endif() -set(LIBHTTPCLIENT_TARGET "libHttpClient") -# We build LIBHTTPCLIENT as OBJECT library so that its symbols -# wont be excluded due to '--exclude-libs ALL' linker flag. Although we -# dont expose libhttpclient in our API , we still want it's symbols exported -# in our ABI, because that is how JVM finds native code on Android platform. -list(APPEND NAKAMA_SDK_DEPS ${LIBHTTPCLIENT_TARGET}) +if (GDK) + include(submodules/devkits/cmake/gdk-targets.cmake) + target_link_libraries(libHttpClient PRIVATE GDK::XCurl) +endif() if (NOT WITH_WS_LIBHTTPC) - target_compile_definitions(${LIBHTTPCLIENT_TARGET} PRIVATE "HC_NOWEBSOCKETS") + target_compile_definitions(libHttpClient PRIVATE "HC_NOWEBSOCKETS") endif() diff --git a/impl/wsLibHttpClient/CMakeLists.txt b/impl/wsLibHttpClient/CMakeLists.txt index b54a765bf..0a543467a 100644 --- a/impl/wsLibHttpClient/CMakeLists.txt +++ b/impl/wsLibHttpClient/CMakeLists.txt @@ -8,6 +8,7 @@ file( set(CMAKE_INCLUDE_CURRENT_DIR ON) add_library(nakama-impl-ws-libhttpclient OBJECT ${srcs}) +add_library(nakama::impl-ws-libhttpclient ALIAS nakama-impl-ws-libhttpclient) target_link_libraries(nakama-impl-ws-libhttpclient PUBLIC nakama-api-proto nakama::sdk-interface # libhttpclient is OBJECT library, so this link wont create From 8a0f854fa27355bc431ff585f1bac3eb91b36db4 Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Sat, 5 Oct 2024 08:55:23 +0100 Subject: [PATCH 15/25] GDK support for libhttpclient transport --- cmake/libHttpClient/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmake/libHttpClient/CMakeLists.txt b/cmake/libHttpClient/CMakeLists.txt index bdddd7f8d..9894787bc 100644 --- a/cmake/libHttpClient/CMakeLists.txt +++ b/cmake/libHttpClient/CMakeLists.txt @@ -20,8 +20,10 @@ endfunction() vcxproj_read_file_list("${LHC_ROOT}/Build/libHttpClient.Common/libHttpClient.Common.vcxitems" COMMON_FILES) vcxproj_read_file_list("${LHC_ROOT}/Build/libHttpClient.XAsync/libHttpClient.XAsync.vcxitems" XASYNC_FILES) vcxproj_read_file_list("${LHC_ROOT}/Build/libHttpClient.Win32.Shared/libHttpClient.Win32.Shared.vcxitems" WIN32_SHARED_FILES) +vcxproj_read_file_list("${LHC_ROOT}/Build/libHttpClient.GDK.Shared/libHttpClient.GDK.Shared.vcxitems" GDK_SHARED_FILES) if (GDK) + set(FILES ${COMMON_FILES} ${GDK_SHARED_FILES}) elseif (WIN32) set(FILES ${COMMON_FILES} ${XASYNC_FILES} ${WIN32_SHARED_FILES}) else() From 057834a4c7677eb981ddbb6d9dd2bf143cd81820 Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Sat, 5 Oct 2024 09:06:04 +0100 Subject: [PATCH 16/25] Use winhttp (via libhttpclient) on Windows --- CMakeLists.txt | 1 - CMakePresets.json | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a0ce6d30c..053525a0d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -110,7 +110,6 @@ if(APPLE AND BUILD_APPLE_FRAMEWORK) # Just copy over headers into framework dir, because "official" way of doing it # via PUBLIC_HEADER property is full of bugs (see comment on PUBLIC_HEADER property below) set(CMAKE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_LIBDIR}/nakama-sdk.framework/Headers) - endif() if (WITH_HTTP_CURL OR (WITH_WS_WSLAY AND CFG_WSLAY_CURL_IO)) diff --git a/CMakePresets.json b/CMakePresets.json index 5353e535e..ba15e0134 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -29,8 +29,8 @@ "CMAKE_SYSTEM_PROCESSOR": "AMD64", "VCPKG_TARGET_TRIPLET": "x64-windows-static-heroic", "VCPKG_CHAINLOAD_TOOLCHAIN_FILE": "${sourceDir}/cmake/toolchains/vcpkg-msvc.cmake", - "WITH_WS_WSLAY": "ON", - "WITH_HTTP_CURL": "ON" + "WITH_WS_LIBHTTPC": "ON", + "WITH_HTTP_LIBHTTPC": "ON" }, "condition": { "type": "equals", From 00017e78ab1e4623afd4fe795a38ab412d87d65b Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Sun, 6 Oct 2024 10:39:15 +0100 Subject: [PATCH 17/25] Mac OSX Universal binary --- .gitmodules | 1 + CMakePresets.json | 21 +++------ README.md | 45 ++++++------------- ...eroic.cmake => universal-osx-heroic.cmake} | 2 +- cmake/triplets/x64-osx-heroic.cmake | 11 ----- impl/httpCppRest/CMakeLists.txt | 1 + impl/httpCurl/CMakeLists.txt | 1 + impl/httpCurl/NHttpClientLibCurl.cpp | 2 +- interface/include/nakama-cpp/NExport.h | 2 +- 9 files changed, 25 insertions(+), 61 deletions(-) rename cmake/triplets/{arm64-osx-heroic.cmake => universal-osx-heroic.cmake} (88%) delete mode 100644 cmake/triplets/x64-osx-heroic.cmake diff --git a/.gitmodules b/.gitmodules index 57a23f60b..b6f986f87 100644 --- a/.gitmodules +++ b/.gitmodules @@ -11,3 +11,4 @@ [submodule "submodules/libHttpClient"] path = submodules/libHttpClient url = https://github.com/microsoft/libHttpClient.git + fetchRecurseSubmodules = false diff --git a/CMakePresets.json b/CMakePresets.json index ba15e0134..2f8c97c5f 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -51,15 +51,15 @@ "installDir": "out/win-arm64" }, { - "name": "macosx-arm64", + "name": "macosx-universal", "inherits": [ "default" ], - "installDir": "out/macosx-arm64", + "installDir": "out/macosx-universal", "generator": "Xcode", "cacheVariables": { - "VCPKG_TARGET_TRIPLET": "arm64-osx-heroic", - "CMAKE_OSX_ARCHITECTURES": "arm64", + "VCPKG_TARGET_TRIPLET": "universal-osx-heroic", + "CMAKE_OSX_ARCHITECTURES": "arm64;x86_64", "WITH_WS_WSLAY": "ON", "WITH_HTTP_CURL": "ON" }, @@ -69,21 +69,10 @@ "rhs": "Darwin" } }, - { - "name": "macosx-x64", - "inherits": [ - "macosx-arm64" - ], - "cacheVariables": { - "VCPKG_TARGET_TRIPLET": "x64-osx-heroic", - "CMAKE_OSX_ARCHITECTURES": "x86_64" - }, - "installDir": "out/macosx-x64" - }, { "name": "ios-arm64", "inherits": [ - "macosx-arm64" + "macosx-universal" ], "cacheVariables": { "VCPKG_TARGET_TRIPLET": "arm64-ios-heroic", diff --git a/README.md b/README.md index 2ee39dadf..d42a9348e 100644 --- a/README.md +++ b/README.md @@ -210,6 +210,16 @@ Then you will need to load our native library from Java by calling `System.loadL # How to build +First, clone the repository. It uses some submodules that are not publicly available and are needed to build +`nakama-sdk` on NDAed platforms. It is not an error if `./submodules/devkits` and `./submodules/private` are +not available. To clone cleanly use following commands: + +``` +git clone --filter=blob:none https://github.com/heroiclabs/nakama-cpp +cd nakama-cpp +git submodule update --filter=blob:none --init ':!submodules/devkits' ':!submodules/private' +``` + ### Windows - [CMake >= 3.29](https://cmake.org/download/) @@ -292,6 +302,10 @@ Your NDK is typically located within your SDK:`/ndk/` Our prebuilt libraries target Android NDK 25.1.8937393. +### Mac OSX Universal binary + +Mac OSX preset is `macosx-universal` builds Framework with universal binaries +for x86_64 and arm64 architectures. ### Build modifiers @@ -302,10 +316,6 @@ a way to alter build behaviour of any preset with a build modifiers mechanism. Supported build modifiers are: -- `LIBHTTPCLIENT_FORCE_WEBSOCKETPP`: On Windows platforms libhttpclient always includes - websocketpp transport and uses it if Windows doesn't support websocket natively (< Windows 8). - You can set this build modifier to force use of websocketpp transport, so that it can be tested without - installing Windows 7. If you - `ADDRESS_SANITIZER`: instrument library with [AddressSanitizer](https://github.com/google/sanitizers/wiki/AddressSanitizer) Build modifiers are CMake variables passed at configure time using `-D` switch. @@ -326,31 +336,6 @@ You should see dynamic library and headers in the `./out` directory. This is you It is safe to combine (overlay) multiple platforms releases in the same directory structure, because binary artifacts paths won't clash and include files are identical on all platforms. -### MacOSX Universal binary - -Currently, our dependency manager can't build non-CMake based projects as universal binary. -Watch [this PR](https://github.com/microsoft/vcpkg/pull/22898) for a proper fix. Until then -building universal binaries requires building shared libs for `arm64` and `x86_64` architectures -and gluing them together with [lipo](https://developer.apple.com/documentation/apple-silicon/building-a-universal-macos-binary/) -tool. - -To build universal binary first compile individual shared lib for arm64 and x86_64. Following commands are for M1, -adjust preset names if you are on Intel CPU: - -``` -cmake --preset macosx-x64-host_arm64 -cmake --build build/macosx-x64-host_arm64 --config MinSizeRel --target install - -cmake --preset macosx-arm64-host_arm64 -cmake --build build/macosx-arm64-host_arm64 --config MinSizeRel --target install -``` - -``` -cp -r out/macosx-x64 out/macosx-universal -lipo -create -output out/macosx-universal/nakama-sdk.framework/Versions/A/nakama-sdk out/macosx-{arm64,x64}/nakama-sdk.framework/nakama-sdk -``` - -You can then archive and release `out/osx-universal` directory. ## Transports @@ -366,7 +351,6 @@ Android | libcurl | Linux | libhttpclient->curl | MacOS | libhttpclient -> OS | iOS | libhttpclient -> OS | -Windows 7 | libhttpclient -> websocketpp | Websockets: @@ -377,7 +361,6 @@ Android | wslay | Linux | wslay | MacOS | wslay | iOS | wslay | -Windows 7 | libhttpclient -> websocketpp | # How to integrate the SDK diff --git a/cmake/triplets/arm64-osx-heroic.cmake b/cmake/triplets/universal-osx-heroic.cmake similarity index 88% rename from cmake/triplets/arm64-osx-heroic.cmake rename to cmake/triplets/universal-osx-heroic.cmake index df4f8ee84..a90cdc7de 100644 --- a/cmake/triplets/arm64-osx-heroic.cmake +++ b/cmake/triplets/universal-osx-heroic.cmake @@ -4,7 +4,7 @@ set(VCPKG_LIBRARY_LINKAGE static) set(VCPKG_BUILD_TYPE release) set(VCPKG_CMAKE_SYSTEM_NAME Darwin) -set(VCPKG_OSX_ARCHITECTURES arm64) +set(VCPKG_OSX_ARCHITECTURES "arm64;x86_64") # HeroicLabs additions to standard triplets: set(VCPKG_OSX_DEPLOYMENT_TARGET "11") diff --git a/cmake/triplets/x64-osx-heroic.cmake b/cmake/triplets/x64-osx-heroic.cmake deleted file mode 100644 index 94de10433..000000000 --- a/cmake/triplets/x64-osx-heroic.cmake +++ /dev/null @@ -1,11 +0,0 @@ -set(VCPKG_TARGET_ARCHITECTURE x64) -set(VCPKG_CRT_LINKAGE dynamic) -set(VCPKG_LIBRARY_LINKAGE static) -set(VCPKG_BUILD_TYPE release) - -set(VCPKG_CMAKE_SYSTEM_NAME Darwin) -set(VCPKG_OSX_ARCHITECTURES x86_64) - -# Heroic Labs additions to standard triplets: -set(VCPKG_OSX_DEPLOYMENT_TARGET "10.15") -include(${CMAKE_CURRENT_LIST_DIR}/feature-visibility-hidden.cmake) \ No newline at end of file diff --git a/impl/httpCppRest/CMakeLists.txt b/impl/httpCppRest/CMakeLists.txt index dd05962a1..e00db89ef 100644 --- a/impl/httpCppRest/CMakeLists.txt +++ b/impl/httpCppRest/CMakeLists.txt @@ -9,6 +9,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) find_package(cpprestsdk CONFIG REQUIRED) add_library(nakama-impl-http-cppRest OBJECT ${srcs}) +add_library(nakama::impl-http-cppRest ALIAS nakama-impl-http-cppRest) target_link_libraries(nakama-impl-http-cppRest PUBLIC nakama-api-proto nakama::sdk-interface PRIVATE cpprestsdk::cpprest diff --git a/impl/httpCurl/CMakeLists.txt b/impl/httpCurl/CMakeLists.txt index a78c6be1e..d4e4e211a 100644 --- a/impl/httpCurl/CMakeLists.txt +++ b/impl/httpCurl/CMakeLists.txt @@ -8,6 +8,7 @@ file( set(CMAKE_INCLUDE_CURRENT_DIR ON) add_library(nakama-impl-http-libcurl OBJECT ${srcs}) +add_library(nakama::impl-http-libcurl ALIAS nakama-impl-http-libcurl) target_include_directories(nakama-impl-http-libcurl PRIVATE ${CURL_INCLUDE_DIRS}) diff --git a/impl/httpCurl/NHttpClientLibCurl.cpp b/impl/httpCurl/NHttpClientLibCurl.cpp index 3326e4f1e..d379bdd25 100644 --- a/impl/httpCurl/NHttpClientLibCurl.cpp +++ b/impl/httpCurl/NHttpClientLibCurl.cpp @@ -279,7 +279,7 @@ void NHttpClientLibCurl::tick() } else { - response->statusCode = response_code; + response->statusCode = static_cast(response_code); if (curl_code != CURLE_OK) { diff --git a/interface/include/nakama-cpp/NExport.h b/interface/include/nakama-cpp/NExport.h index 303c5eb2f..16723e98b 100644 --- a/interface/include/nakama-cpp/NExport.h +++ b/interface/include/nakama-cpp/NExport.h @@ -29,7 +29,7 @@ #endif #elif __GNUC__ >= 4 #ifdef NAKAMA_SHARED_LIBRARY_EXPORTS - #define NAKAMA_API __attribute__((visibility("protected"))) + #define NAKAMA_API __attribute__((visibility("default"))) #else #define NAKAMA_API #endif From 3e9e2c5d961d7b6b0e1368c96ad86d00377a7311 Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Mon, 7 Oct 2024 08:59:17 +0100 Subject: [PATCH 18/25] Update CHANGELOG.md --- CHANGELOG.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c59481b7..aaddd2c91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,22 @@ All notable changes to this project are documented below. The format is based on [keep a changelog](http://keepachangelog.com/) and this project uses [semantic versioning](http://semver.org/). +### [unreleased] + +## Fixed +- Fixed libHttpClient builds + +## Changed + +- Removed support for Windows 7 +- Updated dependencies: + * Discontinued the use of the libHttpClient fork in favor of the upstream version. +- Significant improvements in the build process across all platforms: + * The `VCPKG_ROOT` setup is no longer required; it is now included as a submodule within the project. + * Private NDAed platforms are now built within the same build tree. + * Transport implementation selection has been streamlined with the introduction of `WITH_HTTP_*` and `WITH_WS_*` build options. + * macOS now natively builds universal binaries, eliminating the need for a manual `lipo` step. + ### [2.8.5] - [2024-05-23] ### Fixed - Fixed initialization of shared pointer in `authenticateSteamAsync`. From 6d468a2db2d28053b10dfe0b1b2496aecf46c047 Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Mon, 7 Oct 2024 11:02:49 +0100 Subject: [PATCH 19/25] Fix iOS builds --- CMakePresets.json | 3 ++- cmake/platformSupport.cmake | 2 +- cmake/triplets/arm64-ios-heroic.cmake | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakePresets.json b/CMakePresets.json index 2f8c97c5f..8e65e3337 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -76,7 +76,8 @@ ], "cacheVariables": { "VCPKG_TARGET_TRIPLET": "arm64-ios-heroic", - "CMAKE_SYSTEM_NAME": "iOS" + "CMAKE_SYSTEM_NAME": "iOS", + "CMAKE_OSX_ARCHITECTURES": "arm64" }, "installDir": "out/ios-arm64" }, diff --git a/cmake/platformSupport.cmake b/cmake/platformSupport.cmake index 0af9b628f..b37576338 100644 --- a/cmake/platformSupport.cmake +++ b/cmake/platformSupport.cmake @@ -24,7 +24,7 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL iOS) message("Configuring Apple iOS build") # Don't forget to edit ./cmake/triplets too! # Value is picked based on https://developer.apple.com/support/app-store/ numbers - set(CMAKE_OSX_DEPLOYMENT_TARGET "11") + set(CMAKE_OSX_DEPLOYMENT_TARGET "12") set(CMAKE_OSX_ARCHITECTURES "arm64") elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") message("Configuring Linux build") diff --git a/cmake/triplets/arm64-ios-heroic.cmake b/cmake/triplets/arm64-ios-heroic.cmake index 4a689f0f2..8353cb0f0 100644 --- a/cmake/triplets/arm64-ios-heroic.cmake +++ b/cmake/triplets/arm64-ios-heroic.cmake @@ -5,7 +5,7 @@ set(VCPKG_CMAKE_SYSTEM_NAME iOS) # HeroicLabs additions to standard triplets: set(VCPKG_BUILD_TYPE release) -set(VCPKG_OSX_DEPLOYMENT_TARGET "11") +set(VCPKG_OSX_DEPLOYMENT_TARGET "12") set(VCPKG_OSX_ARCHITECTURES "arm64") include(${CMAKE_CURRENT_LIST_DIR}/feature-visibility-hidden.cmake) From df0cca0ef8084acfa1f96160decdb988ff842bd7 Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Mon, 7 Oct 2024 13:04:42 +0100 Subject: [PATCH 20/25] Fix iphonesimulator builds --- CMakeLists.txt | 5 --- CMakePresets.json | 31 +++++++------------ ...ake => arm64-iphonesimulator-heroic.cmake} | 8 ++--- 3 files changed, 16 insertions(+), 28 deletions(-) rename cmake/triplets/{x64-iphonesimulator-heroic.cmake => arm64-iphonesimulator-heroic.cmake} (60%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 053525a0d..70fc75dc4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,11 +45,6 @@ if (WITH_WS_LIBHTTPC OR WITH_WS_WSLAY OR WITH_WS_CPPREST) set(HAVE_DEFAULT_RT_TRANSPORT_FACTORY ON) endif() -if (CMAKE_OSX_SYSROOT STREQUAL "iphonesimulator") - # this hack seems to be required for now, otherwise CMake still thinks we are building for arm... - set(CMAKE_XCODE_ATTRIBUTE_EXCLUDED_ARCHS[sdk=iphonesimulator*] "arm64") -endif() - if (ANDROID) SET(ANDROID_USE_LEGACY_TOOLCHAIN_FILE FALSE) endif() diff --git a/CMakePresets.json b/CMakePresets.json index 8e65e3337..3dbd412c1 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -17,7 +17,8 @@ "CMAKE_INSTALL_DEFAULT_COMPONENT_NAME": "nakama-sdk", "VCPKG_OVERLAY_PORTS": "${sourceDir}/cmake/vcpkg-ports", "VCPKG_OVERLAY_TRIPLETS": "${sourceDir}/cmake/triplets;${sourceDir}/submodules/devkits/cmake/triplets" - } + }, + "installDir": "out/${presetName}" }, { "name": "win-x64", @@ -36,8 +37,7 @@ "type": "equals", "lhs": "${hostSystemName}", "rhs": "Windows" - }, - "installDir": "out/win-x64" + } }, { "name": "win-arm64", @@ -47,15 +47,13 @@ "cacheVariables": { "CMAKE_SYSTEM_PROCESSOR": "ARM64", "VCPKG_TARGET_TRIPLET": "arm64-windows-static-heroic" - }, - "installDir": "out/win-arm64" + } }, { "name": "macosx-universal", "inherits": [ "default" ], - "installDir": "out/macosx-universal", "generator": "Xcode", "cacheVariables": { "VCPKG_TARGET_TRIPLET": "universal-osx-heroic", @@ -78,18 +76,16 @@ "VCPKG_TARGET_TRIPLET": "arm64-ios-heroic", "CMAKE_SYSTEM_NAME": "iOS", "CMAKE_OSX_ARCHITECTURES": "arm64" - }, - "installDir": "out/ios-arm64" + } }, { - "name": "iphonesimulator-x64", + "name": "iphonesimulator-arm64", "inherits": [ "ios-arm64" ], "cacheVariables": { - "VCPKG_TARGET_TRIPLET": "x64-iphonesimulator-heroic", - "CMAKE_OSX_SYSROOT": "iphonesimulator", - "CMAKE_OSX_ARCHITECTURES": "x86_64" + "VCPKG_TARGET_TRIPLET": "arm64-iphonesimulator-heroic", + "CMAKE_OSX_SYSROOT": "iphonesimulator" } }, { @@ -122,8 +118,7 @@ "cacheVariables": { "VCPKG_TARGET_TRIPLET": "arm64-android-heroic", "ANDROID_ABI": "arm64-v8a" - }, - "installDir": "out/android-arm64-v8a" + } }, { "name": "android-armeabi-v7a", @@ -132,9 +127,8 @@ ], "cacheVariables": { "VCPKG_TARGET_TRIPLET": "arm-neon-android-heroic", - "ANDROID_ABI": "x86_64" - }, - "installDir": "out/android-x64" + "ANDROID_ABI": "armeabi-v7a" + } }, { "name": "linux-amd64", @@ -151,8 +145,7 @@ "type": "equals", "lhs": "${hostSystemName}", "rhs": "Linux" - }, - "installDir": "out/linux-amd64" + } }, { "name": "ubuntu1804-amd64", diff --git a/cmake/triplets/x64-iphonesimulator-heroic.cmake b/cmake/triplets/arm64-iphonesimulator-heroic.cmake similarity index 60% rename from cmake/triplets/x64-iphonesimulator-heroic.cmake rename to cmake/triplets/arm64-iphonesimulator-heroic.cmake index 4f519776a..e3f53857e 100644 --- a/cmake/triplets/x64-iphonesimulator-heroic.cmake +++ b/cmake/triplets/arm64-iphonesimulator-heroic.cmake @@ -1,12 +1,12 @@ -set(VCPKG_TARGET_ARCHITECTURE x64) +set(VCPKG_TARGET_ARCHITECTURE arm64) set(VCPKG_CRT_LINKAGE dynamic) set(VCPKG_LIBRARY_LINKAGE static) set(VCPKG_CMAKE_SYSTEM_NAME iOS) -# Heroic Labs additions to standard triplets: +# HeroicLabs additions to standard triplets: set(VCPKG_BUILD_TYPE release) -set(VCPKG_OSX_DEPLOYMENT_TARGET "11") -set(VCPKG_OSX_ARCHITECTURES "x86_64") +set(VCPKG_OSX_DEPLOYMENT_TARGET "12") +set(VCPKG_OSX_ARCHITECTURES "arm64") set(VCPKG_OSX_SYSROOT iphonesimulator) include(${CMAKE_CURRENT_LIST_DIR}/feature-visibility-hidden.cmake) From 3ed4c240a57e09008b3c2077bcb7039b9bfd7119 Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Mon, 7 Oct 2024 14:45:35 +0100 Subject: [PATCH 21/25] Fix Linux builds --- CMakePresets.json | 8 ++++++-- README.md | 5 +++++ cmake/linkerFlags.cmake | 2 ++ cmake/triplets/x64-linux-heroic.cmake | 2 ++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CMakePresets.json b/CMakePresets.json index 3dbd412c1..344e7452a 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -2,7 +2,7 @@ "version": 6, "cmakeMinimumRequired": { "major": 3, - "minor": 29, + "minor": 28, "patch": 0 }, "configurePresets": [ @@ -139,7 +139,11 @@ "cacheVariables": { "VCPKG_TARGET_TRIPLET": "x64-linux-heroic", "WITH_HTTP_CURL": "ON", - "WITH_WS_WSLAY": "ON" + "WITH_WS_WSLAY": "ON", + "CFG_CURL_SYSTEM": "ON" + }, + "environment": { + "VCPKG_FORCE_SYSTEM_BINARIES": "1" }, "condition": { "type": "equals", diff --git a/README.md b/README.md index d42a9348e..8d92d3df8 100644 --- a/README.md +++ b/README.md @@ -232,6 +232,11 @@ git submodule update --filter=blob:none --init ':!submodules/devkits' ':!submodu - Ninja - gcc-c++/clang++ +Fedora: +``` +sudo dnf install cmake ninja-build libcurl-devel gcc g++ +``` + #### Ubuntu 18.04 Fresh Ubuntu 18.04 setup: diff --git a/cmake/linkerFlags.cmake b/cmake/linkerFlags.cmake index c01f200fb..7469083cd 100644 --- a/cmake/linkerFlags.cmake +++ b/cmake/linkerFlags.cmake @@ -5,4 +5,6 @@ if(MSVC) ) elseif(CMAKE_CXX_COMPILER_ID MATCHES "^Apple") add_link_options(-Wl,-dead_strip) +else() + add_link_options(-Wl,--gc-sections) endif() diff --git a/cmake/triplets/x64-linux-heroic.cmake b/cmake/triplets/x64-linux-heroic.cmake index d7f3e2b25..8f9594aef 100644 --- a/cmake/triplets/x64-linux-heroic.cmake +++ b/cmake/triplets/x64-linux-heroic.cmake @@ -4,3 +4,5 @@ set(VCPKG_LIBRARY_LINKAGE static) set(VCPKG_CMAKE_SYSTEM_NAME Linux) set(VCPKG_BUILD_TYPE release) + +include(${CMAKE_CURRENT_LIST_DIR}/feature-visibility-hidden.cmake) From d60494db5b9d86f56d5cc2a759765f744b93d8e0 Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Mon, 7 Oct 2024 16:30:51 +0100 Subject: [PATCH 22/25] Accurately list transports in README.md --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 8d92d3df8..682d858ea 100644 --- a/README.md +++ b/README.md @@ -349,13 +349,13 @@ transports, `libhttpclient` itself can use different implementations depending o HTTP: -Platform | Transport | - --- |---------------------------| -Windows | libhttpclient -> winhttp | -Android | libcurl | -Linux | libhttpclient->curl | -MacOS | libhttpclient -> OS | -iOS | libhttpclient -> OS | +Platform | Transport | + --- |--------------------------| +Windows | libhttpclient -> winhttp | +Android | libcurl | +Linux | libcurl (system from OS) | +MacOS | libcurl | +iOS | libcurl | Websockets: From 806b83db1a20e4ffea9690f26d2f4b1a9586853c Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Tue, 8 Oct 2024 12:50:26 +0100 Subject: [PATCH 23/25] submodules update --- submodules/devkits | 2 +- submodules/private | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/submodules/devkits b/submodules/devkits index 34ca8250f..4a72cf0f2 160000 --- a/submodules/devkits +++ b/submodules/devkits @@ -1 +1 @@ -Subproject commit 34ca8250fb930baa4c24a7124ffc3447241646a2 +Subproject commit 4a72cf0f2d1ccce1b52993352b59b27d4a66ab9e diff --git a/submodules/private b/submodules/private index d57390d26..6696e22fe 160000 --- a/submodules/private +++ b/submodules/private @@ -1 +1 @@ -Subproject commit d57390d26c272d61b30f02f8c81c8857c9234fa8 +Subproject commit 6696e22febc38eae13af592bd63f185ecd8553c1 From a0e298ef07b639ac97a412b0c38a64a39435c404 Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Wed, 9 Oct 2024 12:57:38 +0100 Subject: [PATCH 24/25] Update windows build instructions, lock windows SDK version for consistency --- README.md | 24 ++++++++++++++++++------ cmake/toolchains/vcpkg-msvc.cmake | 1 + 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 682d858ea..e40fbf0a3 100644 --- a/README.md +++ b/README.md @@ -222,15 +222,32 @@ git submodule update --filter=blob:none --init ':!submodules/devkits' ':!submodu ### Windows +Use following command from powershell to install minimal set of required dependencies +``` +winget install Git.Git Ninja-build.Ninja Kitware.CMake + +winget install Microsoft.VisualStudio.2022.BuildTools --override ("--wait " + + "--passive " + + "--add Microsoft.VisualStudio.Component.VC.Tools.ARM " + + "--add Microsoft.VisualStudio.Component.VC.Tools.ARM64 " + + "--add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 " + + "--add Microsoft.VisualStudio.Component.Windows11SDK.22621 ") +``` + + +- Git - [CMake >= 3.29](https://cmake.org/download/) - [Ninja](https://ninja-build.org/) - [Build Tools for Visual Studio 2022](https://visualstudio.microsoft.com/downloads/) +- Windows 11 SDK v.22000 + ### Linux - CMake - Ninja - gcc-c++/clang++ +- libcurl-dev (Debian/Ubuntu) or libcurl-devel (RPM based distros) Fedora: ``` @@ -390,7 +407,7 @@ Our SDK integrates with vcpkg by providing itself and a few dependencies through "repository": "https://github.com/heroiclabs/nakama-vcpkg-registry", "baseline": "", "reference": "", - "packages": ["nakama-sdk", "wslay"] + "packages": ["nakama-sdk"] } ] } @@ -400,10 +417,5 @@ Then you can add it as you would any other vcpkg port in your `vcpkg.json`: "dependencies": [ { "name": "nakama-sdk" - "features": [, ] }] ``` - -vcpkg does not currently allow us to provide default features per platform, so you must specify your desired transports/features in your own vcpkg.json. - -For an example, look at how our [cocos-2d-x client](https://github.com/heroiclabs/nakama-cocos2d-x.git) does this. Also see our [our built-in transports](#transports) for each platform that we represent with vcpkg features. If you do not specify a transport for the platform, the client will expect you to pass in your own at runtime. diff --git a/cmake/toolchains/vcpkg-msvc.cmake b/cmake/toolchains/vcpkg-msvc.cmake index 044b992bf..dcec07743 100644 --- a/cmake/toolchains/vcpkg-msvc.cmake +++ b/cmake/toolchains/vcpkg-msvc.cmake @@ -9,6 +9,7 @@ endif() if(DEFINED VCPKG_CMAKE_SYSTEM_VERSION) set(CMAKE_SYSTEM_VERSION "${VCPKG_CMAKE_SYSTEM_VERSION}" CACHE STRING "" FORCE) + set(CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION "${VCPKG_CMAKE_SYSTEM_VERSION}") elseif(NOT DEFINED CMAKE_SYSTEM_VERSION) message(FATAL_ERROR "BUG: We should align vcpkg dependencies and our project on Windows SDK version. Include triplet vars in main project") endif() From 55d0880cc78edbce33457ff6d67f73fbda1c02d0 Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Wed, 9 Oct 2024 14:50:01 +0100 Subject: [PATCH 25/25] Submodules update --- submodules/devkits | 2 +- submodules/private | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/submodules/devkits b/submodules/devkits index 4a72cf0f2..22b8a08d1 160000 --- a/submodules/devkits +++ b/submodules/devkits @@ -1 +1 @@ -Subproject commit 4a72cf0f2d1ccce1b52993352b59b27d4a66ab9e +Subproject commit 22b8a08d15bd0eb95cbb4e146e7718aa7b34c278 diff --git a/submodules/private b/submodules/private index 6696e22fe..c261b901a 160000 --- a/submodules/private +++ b/submodules/private @@ -1 +1 @@ -Subproject commit 6696e22febc38eae13af592bd63f185ecd8553c1 +Subproject commit c261b901a72800444ba24a1ae653b22ce87b3703