Skip to content
9 changes: 6 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ option(OPTIONS_ENABLE_CCACHE "Enable ccache" OFF)
option(OPTIONS_ENABLE_SCCACHE "Use sccache to speed up compilation process" OFF)
option(OPTIONS_ENABLE_IPO "Check and Enable interprocedural optimization (IPO/LTO)" ON)

if(CMAKE_BASE_NAME STREQUAL "em++")
set(WASM ON)
message(STATUS "WASM: ON")
endif()

# *****************************************************************************
# Options Code
# *****************************************************************************
Expand Down Expand Up @@ -105,9 +110,7 @@ add_subdirectory(src/protobuf)
# Src
add_subdirectory(src)

option(OTCLIENT_BUILD_TESTS "Build unit tests" ON)

if(OTCLIENT_BUILD_TESTS)
if(NOT WASM)
enable_testing()
add_subdirectory(tests)
log_option_enabled("Build tests")
Expand Down
16 changes: 16 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,18 @@
"ASAN_ENABLED": "ON",
"BUILD_STATIC_LIBRARY": "OFF"
}
},
{
"name": "wasm-debug",
"displayName": "WASM - Debug",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/${presetName}",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"VCPKG_TARGET_TRIPLET": "wasm32-emscripten",
"CMAKE_BUILD_TYPE": "Debug",
"WASM": "ON"
}
}
],
"buildPresets": [
Expand Down Expand Up @@ -183,6 +195,10 @@
{
"name": "macos-debug",
"configurePreset": "macos-debug"
},
{
"name": "wasm-debug",
"configurePreset": "wasm-debug"
}
]
}
7 changes: 6 additions & 1 deletion browser/overlay-ports/abseil/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ if(NOT VCPKG_TARGET_IS_WINDOWS)
vcpkg_check_linkage(ONLY_STATIC_LIBRARY)
endif()

set(ABSEIL_PATCHES)
if(NOT VCPKG_TARGET_IS_EMSCRIPTEN)
list(APPEND ABSEIL_PATCHES use_pthread.patch)
endif()

vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO abseil/abseil-cpp
REF "${VERSION}"
SHA512 bd2cca8f007f2eee66f51c95a979371622b850ceb2ce3608d00ba826f7c494a1da0fba3c1427728f2c173fe50d59b701da35c2c9fdad2752a5a49746b1c8ef31
HEAD_REF master
PATCHES
use_pthread.patch
${ABSEIL_PATCHES}
)

# With ABSL_PROPAGATE_CXX_STD=ON abseil automatically detect if it is being
Expand Down
16 changes: 11 additions & 5 deletions browser/overlay-ports/protobuf/portfile.cmake
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
set(PROTOBUF_PATCHES
fix-static-build.patch
fix-default-proto-file-path.patch
fix-utf8-range.patch
fix-arm64-msvc.patch
)
if(NOT VCPKG_TARGET_IS_EMSCRIPTEN)
list(APPEND PROTOBUF_PATCHES use_pthread.patch)
endif()

vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO protocolbuffers/protobuf
REF "v${VERSION}"
SHA512 ce81add9d978a6b63d4205715eac5084e81a6753da1f6c6bad6493e60253215901bffc4a60d704a873333f2b9f94fd86cb7eb5b293035f2268c12692bd808bac
HEAD_REF master
PATCHES
use_pthread.patch
fix-static-build.patch
fix-default-proto-file-path.patch
fix-utf8-range.patch
fix-arm64-msvc.patch
${PROTOBUF_PATCHES}
)

string(COMPARE EQUAL "${TARGET_TRIPLET}" "${HOST_TRIPLET}" protobuf_BUILD_PROTOC_BINARIES)
Expand Down
19 changes: 11 additions & 8 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ project(otclient)
# *****************************************************************************
# Options
# *****************************************************************************
if(CMAKE_BASE_NAME STREQUAL "em++")
set(WASM ON)
message(STATUS "WASM: ON")
endif()

option(TOGGLE_FRAMEWORK_GRAPHICS "Use Graphics " ON)
option(TOGGLE_FRAMEWORK_SOUND "Use SOUND " ON)
Expand Down Expand Up @@ -124,12 +120,22 @@ find_package(OpenSSL QUIET)
find_package(PhysFS REQUIRED)
find_package(ZLIB REQUIRED)
find_package(phmap REQUIRED)

if(WASM)
if(NOT TARGET Threads::Threads)
add_library(Threads::Threads INTERFACE IMPORTED)
endif()
set(CMAKE_THREAD_LIBS_INIT "")
set(Threads_FOUND TRUE)
else()
find_package(Threads REQUIRED)
endif()

find_package(absl CONFIG REQUIRED)
find_package(Protobuf REQUIRED)
find_package(LibLZMA REQUIRED)
find_package(nlohmann_json REQUIRED)
find_package(asio REQUIRED)
find_package(Threads REQUIRED)
find_package(STDUUID CONFIG REQUIRED)
find_package(pugixml CONFIG REQUIRED)
find_package(ZLIB REQUIRED)
Expand Down Expand Up @@ -643,9 +649,6 @@ elseif(WASM)
${HTTPLIB_LIBRARY}

protobuf::libprotobuf protobuf
absl::log_internal_check_op

Threads::Threads
asio::asio
# OpenAL::OpenAL (using emscripten openal api)
LibLZMA::LibLZMA
Expand Down
10 changes: 6 additions & 4 deletions src/protobuf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ if(APPLE)
endif(APPLE)

find_package(Protobuf REQUIRED)
find_package(Threads)
if(NOT WASM)
find_package(Threads)
endif()

if(EXISTS ${PROTOBUF_PROTOC_EXECUTABLE})
message(STATUS "Found Protobuf Compiler: ${PROTOBUF_PROTOC_EXECUTABLE}")
Expand Down Expand Up @@ -58,9 +60,9 @@ if(PROTOBUF_FOUND)
target_compile_definitions(${PROJECT_NAME} PUBLIC _DISABLE_VECTOR_ANNOTATION _DISABLE_STRING_ANNOTATION)
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_BINARY_DIR})

if(CMAKE_BASE_NAME STREQUAL "em++")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
endif()
if(CMAKE_BASE_NAME STREQUAL "em++" AND NOT WASM)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
endif()

protobuf_generate(TARGET ${PROJECT_NAME} LANGUAGE cpp)
endif(PROTOBUF_FOUND)
12 changes: 9 additions & 3 deletions vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
"libvorbis",
"nlohmann-json",
"openal-soft",
"openssl",
{
"name": "openssl",
"platform": "!wasm32"
},
"parallel-hashmap",
"physfs",
"protobuf",
Expand All @@ -23,7 +26,10 @@
"bshoshany-thread-pool",
"fmt",
"utfcpp",
"gtest",
{
"name": "gtest",
"platform": "!wasm32"
},
{
"name": "luajit",
"platform": "!android & !wasm32"
Expand All @@ -41,5 +47,5 @@
"platform": "windows"
}
],
"builtin-baseline":"b322364f06308bdd24823f9d8f03fe0cc86fd46f"
"builtin-baseline": "b322364f06308bdd24823f9d8f03fe0cc86fd46f"
}
Loading