mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-06-22 16:41:06 +00:00
switch to vcpkg+cmake build system
This commit is contained in:
@@ -2,9 +2,6 @@ name: CMake Linux Build
|
|||||||
|
|
||||||
on: [push]
|
on: [push]
|
||||||
|
|
||||||
env:
|
|
||||||
BUILD_TYPE: Release
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
linux-build:
|
linux-build:
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
@@ -15,32 +12,19 @@ jobs:
|
|||||||
submodules: "recursive"
|
submodules: "recursive"
|
||||||
|
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
env:
|
run: ./scripts/debian/1-install-deps.sh
|
||||||
beammp_sentry_url: ${{ secrets.BEAMMP_SECRET_SENTRY_URL }}
|
|
||||||
run: |
|
|
||||||
echo ${#beammp_sentry_url}
|
|
||||||
sudo apt-get update
|
|
||||||
sudo apt-get install -y libz-dev rapidjson-dev liblua5.3 libssl-dev libwebsocketpp-dev libcurl4-openssl-dev cmake g++-10 libboost1.74-all-dev
|
|
||||||
|
|
||||||
- name: Create Build Environment
|
- name: Create Build Environment
|
||||||
run: cmake -E make_directory ${{github.workspace}}/build-linux
|
|
||||||
|
|
||||||
- name: Configure CMake
|
|
||||||
shell: bash
|
|
||||||
working-directory: ${{github.workspace}}/build-linux
|
working-directory: ${{github.workspace}}/build-linux
|
||||||
env:
|
run: ./scripts/debian/2-configure.sh
|
||||||
beammp_sentry_url: ${{ secrets.BEAMMP_SECRET_SENTRY_URL }}
|
|
||||||
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_CXX_COMPILER=g++-10 -DBEAMMP_SECRET_SENTRY_URL="$beammp_sentry_url"
|
|
||||||
|
|
||||||
- name: Build Server
|
- name: Build Server
|
||||||
working-directory: ${{github.workspace}}/build-linux
|
working-directory: ${{github.workspace}}/build-linux
|
||||||
shell: bash
|
run: ./scripts/debian/3-build.sh
|
||||||
run: cmake --build . --config $BUILD_TYPE -t BeamMP-Server --parallel
|
|
||||||
|
|
||||||
- name: Build Tests
|
- name: Build Tests
|
||||||
working-directory: ${{github.workspace}}/build-linux
|
working-directory: ${{github.workspace}}/build-linux
|
||||||
shell: bash
|
run: ./scripts/debian/3-build-tests.sh
|
||||||
run: cmake --build . --config $BUILD_TYPE -t BeamMP-Server-tests --parallel
|
|
||||||
|
|
||||||
- name: Archive server artifact
|
- name: Archive server artifact
|
||||||
uses: actions/upload-artifact@v2
|
uses: actions/upload-artifact@v2
|
||||||
@@ -65,10 +49,7 @@ jobs:
|
|||||||
path: ${{github.workspace}}
|
path: ${{github.workspace}}
|
||||||
|
|
||||||
- name: Install Runtime Dependencies
|
- name: Install Runtime Dependencies
|
||||||
shell: bash
|
run: ./scripts/debian/4-install-runtime-deps.sh
|
||||||
run: |
|
|
||||||
sudo apt-get update
|
|
||||||
sudo apt-get install -y liblua5.3-0 libssl3 curl
|
|
||||||
|
|
||||||
- name: Test
|
- name: Test
|
||||||
working-directory: ${{github.workspace}}
|
working-directory: ${{github.workspace}}
|
||||||
@@ -28,7 +28,7 @@ jobs:
|
|||||||
body: |
|
body: |
|
||||||
Files included in this release:
|
Files included in this release:
|
||||||
- `BeamMP-Server.exe` is the windows build
|
- `BeamMP-Server.exe` is the windows build
|
||||||
- `BeamMP-Server-linux` is a ubuntu build, so you need the dependencies listed in README.md to run it. For any other distros please build from source as described in README.md.
|
- `BeamMP-Server-linux` is a ubuntu build. You will need to install `liblua5.3-0`.
|
||||||
|
|
||||||
upload-release-files-linux:
|
upload-release-files-linux:
|
||||||
name: Upload Linux Release Files
|
name: Upload Linux Release Files
|
||||||
@@ -37,27 +37,24 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
with:
|
with:
|
||||||
submodules: 'recursive'
|
submodules: "recursive"
|
||||||
|
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: |
|
run: ./scripts/debian/1-install-deps.sh
|
||||||
sudo apt-get update
|
|
||||||
sudo apt-get install -y libz-dev rapidjson-dev liblua5.3 libssl-dev libwebsocketpp-dev libcurl4-openssl-dev libboost-dev libboost1.74-all-dev libboost1.74-dev
|
|
||||||
|
|
||||||
- name: Create Build Environment
|
- name: Create Build Environment
|
||||||
run: cmake -E make_directory ${{github.workspace}}/build-linux
|
|
||||||
|
|
||||||
- name: Configure CMake
|
|
||||||
shell: bash
|
|
||||||
working-directory: ${{github.workspace}}/build-linux
|
working-directory: ${{github.workspace}}/build-linux
|
||||||
env:
|
run: ./scripts/debian/2-configure.sh
|
||||||
beammp_sentry_url: ${{ secrets.BEAMMP_SECRET_SENTRY_URL }}
|
|
||||||
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_CXX_COMPILER=g++-10 -DBEAMMP_SECRET_SENTRY_URL="$beammp_sentry_url"
|
|
||||||
|
|
||||||
- name: Build
|
- name: Build Server
|
||||||
working-directory: ${{github.workspace}}/build-linux
|
working-directory: ${{github.workspace}}/build-linux
|
||||||
shell: bash
|
run: ./scripts/debian/3-build.sh
|
||||||
run: cmake --build . --config $BUILD_TYPE
|
|
||||||
|
- name: Archive server artifact
|
||||||
|
uses: actions/upload-artifact@v2
|
||||||
|
with:
|
||||||
|
name: BeamMP-Server-linux
|
||||||
|
path: ${{github.workspace}}/build-linux/BeamMP-Server
|
||||||
|
|
||||||
- name: Upload Release Asset
|
- name: Upload Release Asset
|
||||||
id: upload-release-asset
|
id: upload-release-asset
|
||||||
|
|||||||
+160
-236
@@ -1,262 +1,186 @@
|
|||||||
# 3.4 is required for imported targets.
|
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
|
||||||
cmake_minimum_required(VERSION 3.4 FATAL_ERROR)
|
|
||||||
|
|
||||||
message(STATUS "You can find build instructions and a list of dependencies in the README at \
|
include(cmake/Vcpkg.cmake) # needs to happen before project()
|
||||||
https://github.com/BeamMP/BeamMP-Server")
|
|
||||||
|
|
||||||
project(BeamMP-Server
|
project(
|
||||||
DESCRIPTION "Server for BeamMP - The Multiplayer Mod for BeamNG.drive"
|
"BeamMP-Server" # replace this
|
||||||
HOMEPAGE_URL https://beammp.com
|
VERSION 3.3.0
|
||||||
LANGUAGES CXX C)
|
)
|
||||||
|
|
||||||
find_package(Git REQUIRED)
|
include(cmake/StandardSettings.cmake)
|
||||||
# Update submodules as needed
|
include(cmake/StaticAnalyzers.cmake)
|
||||||
option(GIT_SUBMODULE "Check submodules during build" ON)
|
include(cmake/Git.cmake)
|
||||||
if(GIT_SUBMODULE)
|
|
||||||
message(STATUS "Submodule update")
|
|
||||||
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
|
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
|
||||||
RESULT_VARIABLE GIT_SUBMOD_RESULT)
|
|
||||||
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
|
|
||||||
message(FATAL_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
|
# below are options which should be changed
|
||||||
|
|
||||||
set(HTTPLIB_REQUIRE_OPENSSL ON)
|
### SETTINGS ###
|
||||||
set(SENTRY_BUILD_SHARED_LIBS OFF)
|
|
||||||
|
|
||||||
add_compile_definitions(CPPHTTPLIB_OPENSSL_SUPPORT=1)
|
# add all headers (.h, .hpp) to this
|
||||||
|
set(PRJ_HEADERS
|
||||||
option(WIN32_STATIC_RUNTIME "Build statically-linked runtime on windows (don't touch unless you know what you're doing)" ON)
|
include/ArgsParser.h
|
||||||
|
|
||||||
# ------------------------ APPLE ---------------------------------
|
|
||||||
if(APPLE)
|
|
||||||
if(IS_DIRECTORY /opt/homebrew/Cellar/lua@5.3/5.3.6)
|
|
||||||
set(LUA_INCLUDE_DIR /opt/homebrew/Cellar/lua@5.3/5.3.6/include/lua5.3)
|
|
||||||
link_directories(/opt/homebrew/Cellar/lua@5.3/5.3.6/lib)
|
|
||||||
else()
|
|
||||||
set(LUA_INCLUDE_DIR /usr/local/Cellar/lua@5.3/5.3.6/include/lua5.3)
|
|
||||||
link_directories(/usr/local/Cellar/lua@5.3/5.3.6/lib)
|
|
||||||
endif()
|
|
||||||
set(LUA_LIBRARIES lua)
|
|
||||||
if(IS_DIRECTORY /opt/homebrew/opt/openssl@1.1)
|
|
||||||
include_directories(/opt/homebrew/opt/openssl@1.1/include)
|
|
||||||
link_directories(/opt/homebrew/opt/openssl@1.1/lib)
|
|
||||||
else()
|
|
||||||
include_directories(/usr/local/opt/openssl@1.1/include)
|
|
||||||
link_directories(/usr/local/opt/openssl@1.1/lib)
|
|
||||||
endif()
|
|
||||||
# ------------------------ WINDOWS ---------------------------------
|
|
||||||
elseif (WIN32)
|
|
||||||
if (WIN32_STATIC_RUNTIME)
|
|
||||||
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
|
|
||||||
endif()
|
|
||||||
# ------------------------ UNIX ------------------------------------
|
|
||||||
elseif (UNIX)
|
|
||||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g")
|
|
||||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
|
|
||||||
option(SANITIZE "Turns on thread and UB sanitizers" OFF)
|
|
||||||
if (SANITIZE)
|
|
||||||
message(STATUS "sanitize is ON")
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize={address,thread,undefined}")
|
|
||||||
endif (SANITIZE)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
set(BUILD_SHARED_LIBS OFF)
|
|
||||||
# ------------------------ SENTRY ---------------------------------
|
|
||||||
message(STATUS "Checking for Sentry URL")
|
|
||||||
# this is set by the build system.
|
|
||||||
# IMPORTANT: if you're building from source, just leave this empty
|
|
||||||
if (NOT DEFINED BEAMMP_SECRET_SENTRY_URL)
|
|
||||||
message(WARNING "No sentry URL configured. Sentry logging is disabled for this build. \
|
|
||||||
This is not an error, and if you're building the BeamMP-Server yourself, this is expected and can be ignored.")
|
|
||||||
set(BEAMMP_SECRET_SENTRY_URL "")
|
|
||||||
set(SENTRY_BACKEND none)
|
|
||||||
else()
|
|
||||||
set(SENTRY_BACKEND breakpad)
|
|
||||||
endif()
|
|
||||||
add_subdirectory("deps/sentry-native")
|
|
||||||
|
|
||||||
# ------------------------ C++ SETUP ---------------------------------
|
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
|
||||||
|
|
||||||
# ------------------------ DEPENDENCIES ------------------------------
|
|
||||||
message(STATUS "Adding local source dependencies")
|
|
||||||
# this has to happen before -DDEBUG since it wont compile properly with -DDEBUG
|
|
||||||
add_subdirectory(deps)
|
|
||||||
|
|
||||||
# ------------------------ VARIABLES ---------------------------------
|
|
||||||
|
|
||||||
include(FindLua)
|
|
||||||
include(FindOpenSSL)
|
|
||||||
include(FindThreads)
|
|
||||||
include(FindZLIB)
|
|
||||||
|
|
||||||
find_package(Boost 1.70 REQUIRED COMPONENTS system)
|
|
||||||
|
|
||||||
set(BeamMP_Sources
|
|
||||||
include/TConsole.h src/TConsole.cpp
|
|
||||||
include/TServer.h src/TServer.cpp
|
|
||||||
include/Compat.h src/Compat.cpp
|
|
||||||
include/Common.h src/Common.cpp
|
|
||||||
include/Client.h src/Client.cpp
|
|
||||||
include/VehicleData.h src/VehicleData.cpp
|
|
||||||
include/TConfig.h src/TConfig.cpp
|
|
||||||
include/TLuaEngine.h src/TLuaEngine.cpp
|
|
||||||
include/TLuaPlugin.h src/TLuaPlugin.cpp
|
|
||||||
include/TResourceManager.h src/TResourceManager.cpp
|
|
||||||
include/THeartbeatThread.h src/THeartbeatThread.cpp
|
|
||||||
include/Http.h src/Http.cpp
|
|
||||||
include/TSentry.h src/TSentry.cpp
|
|
||||||
include/TPPSMonitor.h src/TPPSMonitor.cpp
|
|
||||||
include/TNetwork.h src/TNetwork.cpp
|
|
||||||
include/LuaAPI.h src/LuaAPI.cpp
|
|
||||||
include/TScopedTimer.h src/TScopedTimer.cpp
|
|
||||||
include/SignalHandling.h src/SignalHandling.cpp
|
|
||||||
include/ArgsParser.h src/ArgsParser.cpp
|
|
||||||
include/TPluginMonitor.h src/TPluginMonitor.cpp
|
|
||||||
include/Environment.h
|
|
||||||
include/BoostAliases.h
|
include/BoostAliases.h
|
||||||
|
include/Client.h
|
||||||
|
include/Common.h
|
||||||
|
include/Compat.h
|
||||||
|
include/Cryptography.h
|
||||||
|
include/CustomAssert.h
|
||||||
|
include/Defer.h
|
||||||
|
include/Environment.h
|
||||||
|
include/Http.h
|
||||||
|
include/IThreaded.h
|
||||||
|
include/Json.h
|
||||||
|
include/LuaAPI.h
|
||||||
|
include/RWMutex.h
|
||||||
|
include/SignalHandling.h
|
||||||
|
include/TConfig.h
|
||||||
|
include/TConsole.h
|
||||||
|
include/THeartbeatThread.h
|
||||||
|
include/TLuaEngine.h
|
||||||
|
include/TLuaPlugin.h
|
||||||
|
include/TNetwork.h
|
||||||
|
include/TPluginMonitor.h
|
||||||
|
include/TPPSMonitor.h
|
||||||
|
include/TResourceManager.h
|
||||||
|
include/TScopedTimer.h
|
||||||
|
include/TServer.h
|
||||||
|
include/VehicleData.h
|
||||||
|
)
|
||||||
|
# add all source files (.cpp) to this, except the one with main()
|
||||||
|
set(PRJ_SOURCES
|
||||||
|
src/ArgsParser.cpp
|
||||||
|
src/Client.cpp
|
||||||
|
src/Common.cpp
|
||||||
|
src/Compat.cpp
|
||||||
|
src/Http.cpp
|
||||||
|
src/LuaAPI.cpp
|
||||||
|
src/SignalHandling.cpp
|
||||||
|
src/TConfig.cpp
|
||||||
|
src/TConsole.cpp
|
||||||
|
src/THeartbeatThread.cpp
|
||||||
|
src/TLuaEngine.cpp
|
||||||
|
src/TLuaPlugin.cpp
|
||||||
|
src/TNetwork.cpp
|
||||||
|
src/TPluginMonitor.cpp
|
||||||
|
src/TPPSMonitor.cpp
|
||||||
|
src/TResourceManager.cpp
|
||||||
|
src/TScopedTimer.cpp
|
||||||
|
src/TServer.cpp
|
||||||
|
src/VehicleData.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(BeamMP_Includes
|
find_package(Lua REQUIRED)
|
||||||
${LUA_INCLUDE_DIR}
|
|
||||||
${CURL_INCLUDE_DIRS}
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/deps/cpp-httplib"
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/deps/commandline"
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/deps/json/single_include"
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/deps/sol2/include"
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/deps/rapidjson/include"
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/deps/asio/asio/include"
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/deps"
|
|
||||||
)
|
|
||||||
|
|
||||||
set(BeamMP_Definitions
|
# set the source file containing main()
|
||||||
SECRET_SENTRY_URL="${BEAMMP_SECRET_SENTRY_URL}"
|
set(PRJ_MAIN src/main.cpp)
|
||||||
)
|
# set the source file containing the test's main
|
||||||
|
set(PRJ_TEST_MAIN test/test_main.cpp)
|
||||||
if (WIN32)
|
# set include paths not part of libraries
|
||||||
list(APPEND BeamMP_Definitions _WIN32_WINNT=0x0601)
|
set(PRJ_INCLUDE_DIRS ${LUA_INCLUDE_DIR})
|
||||||
list(APPEND BeamMP_Definitions _CRT_SECURE_NO_WARNINGS)
|
# set compile features (e.g. standard version)
|
||||||
endif()
|
set(PRJ_COMPILE_FEATURES cxx_std_20)
|
||||||
if (UNIX)
|
# set #defines (test enable/disable not included here)
|
||||||
set(BeamMP_CompileOptions
|
set(PRJ_DEFINITIONS CPPHTTPLIB_OPENSSL_SUPPORT)
|
||||||
-Wall
|
# add all libraries used by the project (WARNING: also set them in vcpkg.json!)
|
||||||
-Wextra
|
set(PRJ_LIBRARIES
|
||||||
-Wpedantic
|
|
||||||
|
|
||||||
-Werror=uninitialized
|
|
||||||
-Werror=float-equal
|
|
||||||
-Werror=pointer-arith
|
|
||||||
-Werror=double-promotion
|
|
||||||
-Werror=write-strings
|
|
||||||
-Werror=cast-qual
|
|
||||||
-Werror=init-self
|
|
||||||
-Werror=cast-align
|
|
||||||
-Werror=unreachable-code
|
|
||||||
-Werror=strict-aliasing -fstrict-aliasing
|
|
||||||
-Werror=redundant-decls
|
|
||||||
-Werror=missing-declarations
|
|
||||||
-Werror=missing-field-initializers
|
|
||||||
-Werror=write-strings
|
|
||||||
-Werror=ctor-dtor-privacy
|
|
||||||
-Werror=switch-enum
|
|
||||||
-Werror=switch-default
|
|
||||||
-Werror=old-style-cast
|
|
||||||
-Werror=overloaded-virtual
|
|
||||||
-Werror=overloaded-virtual
|
|
||||||
-Werror=missing-include-dirs
|
|
||||||
-Werror=unused-result
|
|
||||||
|
|
||||||
-fstack-protector
|
|
||||||
-Wzero-as-null-pointer-constant
|
|
||||||
)
|
|
||||||
else()
|
|
||||||
|
|
||||||
set(BeamMP_CompileOptions
|
|
||||||
/bigobj
|
|
||||||
/INCREMENTAL:NO /NODEFAULTLIB:MSVCRT /NODEFAULTLIB:LIBCMT
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set(BeamMP_Libraries
|
|
||||||
Boost::boost
|
|
||||||
Boost::system
|
|
||||||
doctest::doctest
|
|
||||||
OpenSSL::SSL
|
|
||||||
OpenSSL::Crypto
|
|
||||||
sol2::sol2
|
|
||||||
fmt::fmt
|
fmt::fmt
|
||||||
|
doctest::doctest
|
||||||
Threads::Threads
|
Threads::Threads
|
||||||
ZLIB::ZLIB
|
|
||||||
${LUA_LIBRARIES}
|
|
||||||
commandline
|
commandline
|
||||||
sentry
|
toml11::toml11
|
||||||
|
rapidjson
|
||||||
|
sol2
|
||||||
|
httplib::httplib
|
||||||
|
libzip::zip
|
||||||
|
OpenSSL::SSL OpenSSL::Crypto
|
||||||
|
${LUA_LIBRARIES}
|
||||||
)
|
)
|
||||||
|
|
||||||
if (WIN32)
|
# add dependency find_package calls and similar here
|
||||||
set(BeamMP_PlatformLibs wsock32 ws2_32)
|
find_package(fmt CONFIG REQUIRED)
|
||||||
endif ()
|
find_package(OpenSSL REQUIRED)
|
||||||
|
find_package(doctest CONFIG REQUIRED)
|
||||||
|
find_package(Boost REQUIRED)
|
||||||
|
find_package(httplib CONFIG REQUIRED)
|
||||||
|
find_package(libzip CONFIG REQUIRED)
|
||||||
|
find_package(RapidJSON CONFIG REQUIRED)
|
||||||
|
find_package(sol2 CONFIG REQUIRED)
|
||||||
|
find_package(toml11 CONFIG REQUIRED)
|
||||||
|
|
||||||
# ------------------------ BEAMMP SERVER -----------------------------
|
add_subdirectory(deps/commandline)
|
||||||
|
|
||||||
add_executable(BeamMP-Server
|
include_directories(include)
|
||||||
src/main.cpp
|
|
||||||
${BeamMP_Sources}
|
|
||||||
)
|
|
||||||
|
|
||||||
target_compile_definitions(BeamMP-Server PRIVATE
|
# to enable multithreading and the Threads::Threads dependency
|
||||||
${BeamMP_Definitions}
|
include(FindThreads)
|
||||||
DOCTEST_CONFIG_DISABLE
|
|
||||||
)
|
|
||||||
|
|
||||||
target_compile_options(BeamMP-Server PRIVATE
|
### END SETTINGS ###
|
||||||
${BeamMP_CompileOptions}
|
|
||||||
)
|
|
||||||
|
|
||||||
target_include_directories(BeamMP-Server PRIVATE
|
# DONT change anything beyond this point unless you've read the cmake bible and
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/include"
|
# swore on it not to bonk up the ci/cd pipelines with your changes.
|
||||||
)
|
|
||||||
|
|
||||||
target_include_directories(BeamMP-Server SYSTEM PRIVATE
|
####################
|
||||||
${BeamMP_Includes}
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_libraries(BeamMP-Server
|
|
||||||
${BeamMP_Libraries}
|
|
||||||
${BeamMP_PlatformLibs}
|
|
||||||
)
|
|
||||||
|
|
||||||
# ------------------------ BEAMMP SERVER TESTS -----------------------
|
# enables compile_commands.json for clang-related tools (such as the clang LS)
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|
||||||
option(BUILD_TESTS "Build BeamMP-Server tests" ON)
|
# build debug builds by default (if not specified otherwise)
|
||||||
|
if(NOT CMAKE_BUILD_TYPE)
|
||||||
if(BUILD_TESTS)
|
set(CMAKE_BUILD_TYPE "Debug")
|
||||||
add_executable(BeamMP-Server-tests
|
endif()
|
||||||
test/test_main.cpp
|
|
||||||
${BeamMP_Sources}
|
if(UNIX)
|
||||||
)
|
# this will allow to use same _DEBUG macro available in both Linux as well as Windows - MSCV environment. Easy to put Debug specific code.
|
||||||
|
add_compile_options("$<$<CONFIG:DEBUG>:-D_DEBUG>")
|
||||||
target_compile_definitions(BeamMP-Server-tests PRIVATE
|
endif(UNIX)
|
||||||
${BeamMP_Definitions}
|
|
||||||
)
|
if (WIN32)
|
||||||
|
add_compile_options("-D_WIN32_WINNT=0x0601")
|
||||||
target_compile_options(BeamMP-Server-tests PRIVATE
|
endif(WIN32)
|
||||||
${BeamMP_CompileOptions}
|
|
||||||
)
|
|
||||||
|
include(cmake/CompilerWarnings.cmake)
|
||||||
target_include_directories(BeamMP-Server-tests PRIVATE
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/include"
|
# set MT library for msvc - this is required (says documentation)
|
||||||
)
|
# linux/mac/etc should simply ignore this by default.
|
||||||
|
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
|
||||||
target_include_directories(BeamMP-Server-tests SYSTEM PRIVATE
|
|
||||||
${BeamMP_Includes}
|
set(PRJ_DEFINITIONS ${PRJ_DEFINITIONS}
|
||||||
)
|
PRJ_VERSION_MAJOR=${PROJECT_VERSION_MAJOR}
|
||||||
|
PRJ_VERSION_MINOR=${PROJECT_VERSION_MINOR}
|
||||||
target_link_libraries(BeamMP-Server-tests
|
PRJ_VERSION_PATCH=${PROJECT_VERSION_PATCH}
|
||||||
${BeamMP_Libraries}
|
)
|
||||||
${BeamMP_PlatformLibs}
|
|
||||||
)
|
add_executable(${PROJECT_NAME} ${PRJ_HEADERS} ${PRJ_SOURCES} ${PRJ_MAIN})
|
||||||
|
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||||
|
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
|
||||||
|
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
|
||||||
|
MACOSX_BUNDLE TRUE
|
||||||
|
WIN32_EXECUTABLE TRUE
|
||||||
|
)
|
||||||
|
target_include_directories(${PROJECT_NAME} PRIVATE ${PRJ_INCLUDE_DIRS})
|
||||||
|
target_link_libraries(${PROJECT_NAME} ${PRJ_LIBRARIES})
|
||||||
|
target_compile_features(${PROJECT_NAME} PRIVATE ${PRJ_COMPILE_FEATURES})
|
||||||
|
target_compile_definitions(${PROJECT_NAME} PRIVATE ${PRJ_DEFINITIONS} ${PRJ_WARNINGS}
|
||||||
|
DOCTEST_CONFIG_DISABLE # disables all test code in the final executable
|
||||||
|
)
|
||||||
|
|
||||||
|
if(MSVC)
|
||||||
|
target_link_options(${PROJECT_NAME} PRIVATE "/SUBSYSTEM:CONSOLE")
|
||||||
|
endif(MSVC)
|
||||||
|
|
||||||
|
# setup all warnings (from cmake/CompilerWarnings.cmake)
|
||||||
|
set_project_warnings(${PROJECT_NAME})
|
||||||
|
|
||||||
|
if(${PROJECT_NAME}_ENABLE_UNIT_TESTING)
|
||||||
|
message(STATUS "Unit tests are enabled and will be built as '${PROJECT_NAME}-tests'")
|
||||||
|
add_executable(${PROJECT_NAME}-tests ${PRJ_HEADERS} ${PRJ_SOURCES} ${PRJ_TEST_MAIN})
|
||||||
|
target_link_libraries(${PROJECT_NAME}-tests ${PRJ_LIBRARIES})
|
||||||
|
target_compile_features(${PROJECT_NAME}-tests PRIVATE ${PRJ_COMPILE_FEATURES})
|
||||||
|
target_compile_definitions(${PROJECT_NAME}-tests PRIVATE ${PRJ_DEFINITIONS} ${PRJ_WARNINGS})
|
||||||
|
set_project_warnings(${PROJECT_NAME}-tests)
|
||||||
|
if(MSVC)
|
||||||
|
target_link_options(${PROJECT_NAME}-tests PRIVATE "/SUBSYSTEM:CONSOLE")
|
||||||
|
endif(MSVC)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,115 @@
|
|||||||
|
# from here:
|
||||||
|
#
|
||||||
|
# https://github.com/lefticus/cppbestpractices/blob/master/02-Use_the_Tools_Available.md
|
||||||
|
# Courtesy of Jason Turner
|
||||||
|
# License here: https://github.com/cpp-best-practices/cppbestpractices/blob/master/LICENSE
|
||||||
|
#
|
||||||
|
# This version has been modified by the owners of the current respository.
|
||||||
|
# Modifications have mostly been marked with "modified" or similar, though this is not
|
||||||
|
# strictly required.
|
||||||
|
|
||||||
|
function(set_project_warnings project_name)
|
||||||
|
set(MSVC_WARNINGS
|
||||||
|
/W4 # Baseline reasonable warnings
|
||||||
|
/w14242 # 'identifier': conversion from 'type1' to 'type1', possible loss
|
||||||
|
# of data
|
||||||
|
/w14254 # 'operator': conversion from 'type1:field_bits' to
|
||||||
|
# 'type2:field_bits', possible loss of data
|
||||||
|
/w14263 # 'function': member function does not override any base class
|
||||||
|
# virtual member function
|
||||||
|
/w14265 # 'classname': class has virtual functions, but destructor is not
|
||||||
|
# virtual instances of this class may not be destructed correctly
|
||||||
|
/w14287 # 'operator': unsigned/negative constant mismatch
|
||||||
|
/we4289 # nonstandard extension used: 'variable': loop control variable
|
||||||
|
# declared in the for-loop is used outside the for-loop scope
|
||||||
|
/w14296 # 'operator': expression is always 'boolean_value'
|
||||||
|
/w14311 # 'variable': pointer truncation from 'type1' to 'type2'
|
||||||
|
/w14545 # expression before comma evaluates to a function which is missing
|
||||||
|
# an argument list
|
||||||
|
/w14546 # function call before comma missing argument list
|
||||||
|
/w14547 # 'operator': operator before comma has no effect; expected
|
||||||
|
# operator with side-effect
|
||||||
|
/w14549 # 'operator': operator before comma has no effect; did you intend
|
||||||
|
# 'operator'?
|
||||||
|
/w14555 # expression has no effect; expected expression with side- effect
|
||||||
|
/w14619 # pragma warning: there is no warning number 'number'
|
||||||
|
/w14640 # Enable warning on thread un-safe static member initialization
|
||||||
|
/w14826 # Conversion from 'type1' to 'type_2' is sign-extended. This may
|
||||||
|
# cause unexpected runtime behavior.
|
||||||
|
/w14905 # wide string literal cast to 'LPSTR'
|
||||||
|
/w14906 # string literal cast to 'LPWSTR'
|
||||||
|
/w14928 # illegal copy-initialization; more than one user-defined
|
||||||
|
# conversion has been implicitly applied
|
||||||
|
/permissive- # standards conformance mode for MSVC compiler.
|
||||||
|
)
|
||||||
|
|
||||||
|
set(CLANG_WARNINGS
|
||||||
|
-Wall
|
||||||
|
-Wextra # reasonable and standard
|
||||||
|
-Wshadow # warn the user if a variable declaration shadows one from a
|
||||||
|
# parent context
|
||||||
|
-Wnon-virtual-dtor # warn the user if a class with virtual functions has a
|
||||||
|
# non-virtual destructor. This helps catch hard to
|
||||||
|
# track down memory errors
|
||||||
|
-Wold-style-cast # warn for c-style casts
|
||||||
|
-Wcast-align # warn for potential performance problem casts
|
||||||
|
-Wunused # warn on anything being unused
|
||||||
|
-Woverloaded-virtual # warn if you overload (not override) a virtual
|
||||||
|
# function
|
||||||
|
-Wpedantic # warn if non-standard C++ is used
|
||||||
|
-Wconversion # warn on type conversions that may lose data
|
||||||
|
-Wsign-conversion # warn on sign conversions
|
||||||
|
-Wnull-dereference # warn if a null dereference is detected
|
||||||
|
-Wdouble-promotion # warn if float is implicit promoted to double
|
||||||
|
-Wformat=2 # warn on security issues around functions that format output
|
||||||
|
# (ie printf)
|
||||||
|
# modified; added more errors / warnings
|
||||||
|
# some have been set to be errors, but the option _WARNINGS_AS_ERRORS
|
||||||
|
# (see below) should still be used in strict pipelines.
|
||||||
|
-Werror=uninitialized
|
||||||
|
-Werror=float-equal
|
||||||
|
-Werror=write-strings
|
||||||
|
-Werror=strict-aliasing -fstrict-aliasing
|
||||||
|
-Werror=missing-declarations
|
||||||
|
-Werror=missing-field-initializers
|
||||||
|
-Werror=ctor-dtor-privacy
|
||||||
|
-Werror=switch-enum
|
||||||
|
-Wswitch-default
|
||||||
|
-Werror=unused-result
|
||||||
|
-Werror=implicit-fallthrough
|
||||||
|
-Werror=return-type
|
||||||
|
-Wmissing-include-dirs
|
||||||
|
)
|
||||||
|
|
||||||
|
if (${PROJECT_NAME}_WARNINGS_AS_ERRORS)
|
||||||
|
set(CLANG_WARNINGS ${CLANG_WARNINGS} -Werror)
|
||||||
|
set(MSVC_WARNINGS ${MSVC_WARNINGS} /WX)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(GCC_WARNINGS
|
||||||
|
${CLANG_WARNINGS}
|
||||||
|
-Wmisleading-indentation # warn if indentation implies blocks where blocks
|
||||||
|
# do not exist
|
||||||
|
-Wduplicated-cond # warn if if / else chain has duplicated conditions
|
||||||
|
-Wduplicated-branches # warn if if / else branches have duplicated code
|
||||||
|
-Wlogical-op # warn about logical operations being used where bitwise were
|
||||||
|
# probably wanted
|
||||||
|
# -Wuseless-cast # warn if you perform a cast to the same type (modified: removed)
|
||||||
|
)
|
||||||
|
|
||||||
|
if(MSVC)
|
||||||
|
set(PRJ_WARNINGS ${MSVC_WARNINGS})
|
||||||
|
elseif(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
|
||||||
|
set(PRJ_WARNINGS ${CLANG_WARNINGS})
|
||||||
|
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||||
|
set(PRJ_WARNINGS ${GCC_WARNINGS})
|
||||||
|
else()
|
||||||
|
message(AUTHOR_WARNING "No compiler warnings set for '${CMAKE_CXX_COMPILER_ID}' compiler.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
target_compile_options(${project_name} PUBLIC ${PRJ_WARNINGS})
|
||||||
|
|
||||||
|
if(NOT TARGET ${project_name})
|
||||||
|
message(AUTHOR_WARNING "${project_name} is not a target, thus no compiler warning were added.")
|
||||||
|
endif()
|
||||||
|
endfunction()
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
find_package(Git)
|
||||||
|
if(${PROJECT_NAME}_CHECKOUT_GIT_SUBMODULES)
|
||||||
|
if(Git_FOUND)
|
||||||
|
message(STATUS "Git found, submodule update and init")
|
||||||
|
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
RESULT_VARIABLE GIT_SUBMOD_RESULT)
|
||||||
|
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
|
||||||
|
message(SEND_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules. This may result in missing dependencies.")
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
message(SEND_ERROR "git required for checking out submodules, but not found. Submodules will not be checked out - this may result in missing dependencies.")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(Git_FOUND)
|
||||||
|
|
||||||
|
else()
|
||||||
|
message(STATUS "Git not found - the version will not include a git hash.")
|
||||||
|
set(PRJ_GIT_HASH "unknown")
|
||||||
|
endif()
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
# Modified, original version from https://github.com/filipdutescu/modern-cpp-template (Unlicense)
|
||||||
|
|
||||||
|
option(${PROJECT_NAME}_WARNINGS_AS_ERRORS "Treat compiler warnings as errors." OFF)
|
||||||
|
option(${PROJECT_NAME}_CHECKOUT_GIT_SUBMODULES "If git is found, initialize all submodules." ON)
|
||||||
|
option(${PROJECT_NAME}_ENABLE_UNIT_TESTING "Enable unit tests for the projects (from the `test` subfolder)." ON)
|
||||||
|
option(${PROJECT_NAME}_ENABLE_CLANG_TIDY "Enable static analysis with Clang-Tidy." OFF)
|
||||||
|
option(${PROJECT_NAME}_ENABLE_CPPCHECK "Enable static analysis with Cppcheck." OFF)
|
||||||
|
# TODO Implement code coverage
|
||||||
|
# option(${PROJECT_NAME}_ENABLE_CODE_COVERAGE "Enable code coverage through GCC." OFF)
|
||||||
|
option(${PROJECT_NAME}_ENABLE_DOXYGEN "Enable Doxygen documentation builds of source." OFF)
|
||||||
|
|
||||||
|
# Generate compile_commands.json for clang based tools
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|
||||||
|
# Export all symbols when building a shared library
|
||||||
|
if(BUILD_SHARED_LIBS)
|
||||||
|
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS OFF)
|
||||||
|
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
|
||||||
|
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
option(${PROJECT_NAME}_ENABLE_LTO "Enable Interprocedural Optimization, aka Link Time Optimization (LTO)." OFF)
|
||||||
|
if(${PROJECT_NAME}_ENABLE_LTO)
|
||||||
|
include(CheckIPOSupported)
|
||||||
|
check_ipo_supported(RESULT result OUTPUT output)
|
||||||
|
if(result)
|
||||||
|
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
|
||||||
|
else()
|
||||||
|
message(SEND_ERROR "IPO is not supported: ${output}.")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
option(${PROJECT_NAME}_ENABLE_CCACHE "Enable the usage of Ccache, in order to speed up rebuild times." ON)
|
||||||
|
find_program(CCACHE_FOUND ccache)
|
||||||
|
if(CCACHE_FOUND)
|
||||||
|
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
|
||||||
|
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
option(${PROJECT_NAME}_ENABLE_SANITIZER "Enable sanitizer to detect memory errors, undefined behavior, etc. (slows down the executable)." OFF)
|
||||||
|
if(${PROJECT_NAME}_ENABLE_SANITIZER)
|
||||||
|
add_compile_options(-fsanitize=address,undefined)
|
||||||
|
add_link_options(-fsanitize=address,undefined)
|
||||||
|
endif()
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
if(${PROJECT_NAME}_ENABLE_CLANG_TIDY)
|
||||||
|
find_program(CLANGTIDY clang-tidy)
|
||||||
|
if(CLANGTIDY)
|
||||||
|
set(CMAKE_CXX_CLANG_TIDY ${CLANGTIDY} -extra-arg=-Wno-unknown-warning-option)
|
||||||
|
message("Clang-Tidy finished setting up.")
|
||||||
|
else()
|
||||||
|
message(SEND_ERROR "Clang-Tidy requested but executable not found.")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(${PROJECT_NAME}_ENABLE_CPPCHECK)
|
||||||
|
find_program(CPPCHECK cppcheck)
|
||||||
|
if(CPPCHECK)
|
||||||
|
set(CMAKE_CXX_CPPCHECK ${CPPCHECK} --suppress=missingInclude --enable=all
|
||||||
|
--inline-suppr --inconclusive)
|
||||||
|
message("Cppcheck finished setting up.")
|
||||||
|
else()
|
||||||
|
message(SEND_ERROR "Cppcheck requested but executable not found.")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
if(NOT CMAKE_TOOLCHAIN_FILE)
|
||||||
|
if(NOT EXISTS ${CMAKE_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake)
|
||||||
|
find_package(Git)
|
||||||
|
if(Git_FOUND)
|
||||||
|
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive vcpkg
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
RESULT_VARIABLE GIT_SUBMOD_RESULT)
|
||||||
|
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
|
||||||
|
message(SEND_ERROR "Checking out vcpkg in source tree failed with ${GIT_SUBMOD_RESULT}.")
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "Could not find git or vcpkg.cmake. Please either, install git and re-run cmake (or run `git submodule update --init --recursive`), or install vcpkg and add `-DCMAKE_TOOLCHAIN_FILE=<path-to-vcpkg>/scripts/buildsystems/vcpkg.cmake` to your cmake invocation. Please try again after making those changes.")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake)
|
||||||
|
if (WIN32)
|
||||||
|
set(VCPKG_TARGET_TRIPLET x64-windows-static)
|
||||||
|
endif(WIN32)
|
||||||
|
endif()
|
||||||
|
|
||||||
Executable
+10
@@ -0,0 +1,10 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
apt-get update -y
|
||||||
|
apt-get upgrade -y
|
||||||
|
|
||||||
|
apt-get install -y liblua5.3-0 liblua5.3-dev
|
||||||
|
apt-get install -y curl zip unzip tar
|
||||||
|
apt-get install -y cmake make git g++
|
||||||
Executable
+5
@@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
cmake . -B bin -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-O3 -s -Wl,-z,norelro -Wl,--hash-style=gnu -Wl,--build-id=none -Wl,-z,noseparate-code -ffunction-sections -fdata-sections -Wl,--gc-sections" -DBeamMP-Server_ENABLE_LTO=ON || cat "$SOURCE"/server/bin/vcpkg-bootstrap.log
|
||||||
Executable
+5
@@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
cmake --build bin --parallel -t BeamMP-Server-tests
|
||||||
Executable
+5
@@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
cmake --build bin --parallel -t BeamMP-Server
|
||||||
Executable
+9
@@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
apt-get update -y
|
||||||
|
apt-get upgrade -y
|
||||||
|
|
||||||
|
apt-get install -y liblua5.3-0 curl
|
||||||
|
|
||||||
+41
@@ -0,0 +1,41 @@
|
|||||||
|
{
|
||||||
|
"name": "server",
|
||||||
|
"version-string": "0.1.0",
|
||||||
|
"dependencies": [
|
||||||
|
{
|
||||||
|
"name": "fmt",
|
||||||
|
"version>=": "9.0.0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "doctest",
|
||||||
|
"version>=": "2.4.9"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "boost-asio",
|
||||||
|
"version>=": "1.80.0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "boost-variant",
|
||||||
|
"version>=": "1.80.0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "boost-spirit",
|
||||||
|
"version>=": "1.80.0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "boost-uuid",
|
||||||
|
"version>=": "1.80.0"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "cpp-httplib",
|
||||||
|
"version>=": "0.12.2"
|
||||||
|
},
|
||||||
|
"toml11",
|
||||||
|
"libzip",
|
||||||
|
"rapidjson",
|
||||||
|
"nlohmann-json",
|
||||||
|
"openssl",
|
||||||
|
"sol2"
|
||||||
|
],
|
||||||
|
"builtin-baseline": "19af97cba8ca48474e4ad15a24ed50271a9ecdac"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user