mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-04 00:36:14 +00:00
Modernize CMakeLists, automatically update submodules
CMake will now find packages in a modern way (include(Find*)), and will also ensure that submodules are updated, unless told otherwise. Also removed some apple-specific workarounds, we will need to look at that again.
This commit is contained in:
parent
b2f27c21be
commit
d86efabb1a
130
CMakeLists.txt
130
CMakeLists.txt
@ -1,4 +1,5 @@
|
|||||||
cmake_minimum_required(VERSION 3.0)
|
# 3.4 is required for imported targets.
|
||||||
|
cmake_minimum_required(VERSION 3.4 FATAL_ERROR)
|
||||||
|
|
||||||
message(STATUS "You can find build instructions and a list of dependencies in the README at \
|
message(STATUS "You can find build instructions and a list of dependencies in the README at \
|
||||||
https://github.com/BeamMP/BeamMP-Server")
|
https://github.com/BeamMP/BeamMP-Server")
|
||||||
@ -8,7 +9,22 @@ project(BeamMP-Server
|
|||||||
HOMEPAGE_URL https://beammp.com
|
HOMEPAGE_URL https://beammp.com
|
||||||
LANGUAGES CXX C)
|
LANGUAGES CXX C)
|
||||||
|
|
||||||
|
find_package(Git REQUIRED)
|
||||||
|
# Update submodules as needed
|
||||||
|
option(GIT_SUBMODULE "Check submodules during build" ON)
|
||||||
|
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()
|
||||||
|
|
||||||
|
|
||||||
set(HTTPLIB_REQUIRE_OPENSSL ON)
|
set(HTTPLIB_REQUIRE_OPENSSL ON)
|
||||||
|
set(SENTRY_BUILD_SHARED_LIBS OFF)
|
||||||
|
|
||||||
include_directories("${PROJECT_SOURCE_DIR}/deps/asio/asio/include")
|
include_directories("${PROJECT_SOURCE_DIR}/deps/asio/asio/include")
|
||||||
include_directories("${PROJECT_SOURCE_DIR}/deps/rapidjson/include")
|
include_directories("${PROJECT_SOURCE_DIR}/deps/rapidjson/include")
|
||||||
@ -21,26 +37,40 @@ include_directories("${PROJECT_SOURCE_DIR}/deps")
|
|||||||
|
|
||||||
add_compile_definitions(CPPHTTPLIB_OPENSSL_SUPPORT)
|
add_compile_definitions(CPPHTTPLIB_OPENSSL_SUPPORT)
|
||||||
|
|
||||||
|
# ------------------------ APPLE ---------------------------------
|
||||||
if(APPLE)
|
if(APPLE)
|
||||||
set(LUA_INCLUDE_DIR /usr/local/Cellar/lua@5.3/5.3.6/include/lua5.3)
|
set(LUA_INCLUDE_DIR /usr/local/Cellar/lua@5.3/5.3.6/include/lua5.3)
|
||||||
set(LUA_LIBRARIES lua)
|
set(LUA_LIBRARIES lua)
|
||||||
include_directories(/usr/local/opt/openssl@1.1/include)
|
include_directories(/usr/local/opt/openssl@1.1/include)
|
||||||
link_directories(/usr/local/Cellar/lua@5.3/5.3.6/lib)
|
link_directories(/usr/local/Cellar/lua@5.3/5.3.6/lib)
|
||||||
link_directories(/usr/local/opt/openssl@1.1/lib)
|
link_directories(/usr/local/opt/openssl@1.1/lib)
|
||||||
endif()
|
# ------------------------ WINDOWS ---------------------------------
|
||||||
|
elseif (WIN32)
|
||||||
if (WIN32)
|
|
||||||
# this has to happen before sentry, so that crashpad on windows links with these settings.
|
# this has to happen before sentry, so that crashpad on windows links with these settings.
|
||||||
message(STATUS "MSVC -> forcing use of statically-linked runtime.")
|
message(STATUS "MSVC -> forcing use of statically-linked runtime.")
|
||||||
STRING(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
|
STRING(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
|
||||||
STRING(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
|
STRING(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
|
||||||
endif()
|
if (MSVC)
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
|
||||||
|
set(SENTRY_BUILD_RUNTIMESTATIC ON)
|
||||||
|
endif ()
|
||||||
|
set(VcpkgRoot ${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET})
|
||||||
|
include_directories(${VcpkgRoot}/include)
|
||||||
|
link_directories(${VcpkgRoot}/lib)
|
||||||
|
# ------------------------ LINUX ---------------------------------
|
||||||
|
elseif (UNIX)
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -static-libstdc++ -static-libgcc")
|
||||||
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g")
|
||||||
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -fno-builtin")
|
||||||
|
if (SANITIZE)
|
||||||
|
message(STATUS "sanitize is ON")
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined,thread")
|
||||||
|
endif (SANITIZE)
|
||||||
|
endif ()
|
||||||
|
|
||||||
include_directories("include/sentry-native/include")
|
include_directories("include/sentry-native/include")
|
||||||
set(SENTRY_BUILD_SHARED_LIBS OFF)
|
|
||||||
if (MSVC)
|
# ------------------------ SENTRY ---------------------------------
|
||||||
set(SENTRY_BUILD_RUNTIMESTATIC ON)
|
|
||||||
endif()
|
|
||||||
message(STATUS "Checking for Sentry URL")
|
message(STATUS "Checking for Sentry URL")
|
||||||
# this is set by the build system.
|
# this is set by the build system.
|
||||||
# IMPORTANT: if you're building from source, just leave this empty
|
# IMPORTANT: if you're building from source, just leave this empty
|
||||||
@ -50,41 +80,15 @@ if (NOT DEFINED BEAMMP_SECRET_SENTRY_URL)
|
|||||||
set(BEAMMP_SECRET_SENTRY_URL "")
|
set(BEAMMP_SECRET_SENTRY_URL "")
|
||||||
set(SENTRY_BACKEND none)
|
set(SENTRY_BACKEND none)
|
||||||
else()
|
else()
|
||||||
string(LENGTH ${BEAMMP_SECRET_SENTRY_URL} URL_LEN)
|
|
||||||
message(STATUS "Sentry URL is length ${URL_LEN}")
|
|
||||||
set(SENTRY_BACKEND breakpad)
|
set(SENTRY_BACKEND breakpad)
|
||||||
endif()
|
endif()
|
||||||
add_subdirectory("deps/sentry-native")
|
add_subdirectory("deps/sentry-native")
|
||||||
|
|
||||||
if (MSVC)
|
# ------------------------ C++ SETUP ---------------------------------
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj")
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
message(STATUS "Setting compiler flags")
|
|
||||||
if (WIN32)
|
|
||||||
|
|
||||||
#-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static
|
|
||||||
set(VcpkgRoot ${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET})
|
|
||||||
include_directories(${VcpkgRoot}/include)
|
|
||||||
link_directories(${VcpkgRoot}/lib)
|
|
||||||
elseif (UNIX)
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -static-libstdc++")
|
|
||||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g")
|
|
||||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2 -fno-builtin")
|
|
||||||
if (SANITIZE)
|
|
||||||
message(STATUS "sanitize is ON")
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined,thread")
|
|
||||||
endif (SANITIZE)
|
|
||||||
endif ()
|
|
||||||
|
|
||||||
|
|
||||||
message(STATUS "Adding local source dependencies")
|
|
||||||
# this has to happen before -DDEBUG since it wont compile properly with -DDEBUG
|
|
||||||
add_subdirectory(deps)
|
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
|
||||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
|
# ------------------------ DEPENDENCIES ------------------------------
|
||||||
|
add_subdirectory(deps)
|
||||||
|
|
||||||
add_executable(BeamMP-Server
|
add_executable(BeamMP-Server
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
@ -116,12 +120,10 @@ target_include_directories(BeamMP-Server PUBLIC
|
|||||||
"${CMAKE_CURRENT_SOURCE_DIR}/include"
|
"${CMAKE_CURRENT_SOURCE_DIR}/include"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/commandline")
|
"${CMAKE_CURRENT_SOURCE_DIR}/commandline")
|
||||||
|
|
||||||
if (APPLE)
|
include(FindLua)
|
||||||
message(STATUS "NOT looking for Lua on APPLE")
|
include(FindOpenSSL)
|
||||||
else()
|
include(FindThreads)
|
||||||
message(STATUS "Looking for Lua")
|
include(FindZLIB)
|
||||||
find_package(Lua REQUIRED VERSION 5.3)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
target_include_directories(BeamMP-Server PUBLIC
|
target_include_directories(BeamMP-Server PUBLIC
|
||||||
${LUA_INCLUDE_DIR}
|
${LUA_INCLUDE_DIR}
|
||||||
@ -130,39 +132,17 @@ target_include_directories(BeamMP-Server PUBLIC
|
|||||||
"include/sentry-native/include"
|
"include/sentry-native/include"
|
||||||
"include/curl/include")
|
"include/curl/include")
|
||||||
|
|
||||||
message(STATUS "Looking for SSL")
|
target_link_libraries(BeamMP-Server
|
||||||
|
OpenSSL::SSL
|
||||||
if (APPLE)
|
OpenSSL::Crypto
|
||||||
set(OPENSSL_LIBRARIES ssl crypto)
|
sol2::sol2
|
||||||
else()
|
fmt::fmt
|
||||||
find_package(OpenSSL REQUIRED)
|
Threads::Threads
|
||||||
endif()
|
|
||||||
|
|
||||||
target_link_libraries(BeamMP-Server sol2::sol2 ${LUA_LIBRARIES} fmt::fmt)
|
|
||||||
message(STATUS "CURL IS ${CURL_LIBRARIES}")
|
|
||||||
|
|
||||||
if (UNIX)
|
|
||||||
target_link_libraries(BeamMP-Server
|
|
||||||
z
|
|
||||||
pthread
|
|
||||||
${LUA_LIBRARIES}
|
|
||||||
crypto
|
|
||||||
${OPENSSL_LIBRARIES}
|
|
||||||
commandline
|
|
||||||
sentry
|
|
||||||
ssl)
|
|
||||||
elseif (WIN32)
|
|
||||||
include(FindLua)
|
|
||||||
message(STATUS "Looking for libz")
|
|
||||||
find_package(ZLIB REQUIRED)
|
|
||||||
message(STATUS "Looking for RapidJSON")
|
|
||||||
find_package(RapidJSON CONFIG REQUIRED)
|
|
||||||
target_include_directories(BeamMP-Server PRIVATE ${RAPIDJSON_INCLUDE_DIRS})
|
|
||||||
target_link_libraries(BeamMP-Server
|
|
||||||
ws2_32
|
|
||||||
ZLIB::ZLIB
|
ZLIB::ZLIB
|
||||||
${LUA_LIBRARIES}
|
${LUA_LIBRARIES}
|
||||||
${OPENSSL_LIBRARIES}
|
|
||||||
commandline
|
commandline
|
||||||
sentry)
|
sentry)
|
||||||
|
|
||||||
|
if (WIN32)
|
||||||
|
target_link_libraries(BeamMP-Server wsock32 ws2_32)
|
||||||
endif ()
|
endif ()
|
||||||
|
@ -148,6 +148,10 @@ void RegisterThread(const std::string& str);
|
|||||||
#define _function_name std::string(__func__)
|
#define _function_name std::string(__func__)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
#define DEBUG
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(DEBUG)
|
#if defined(DEBUG)
|
||||||
|
|
||||||
// if this is defined, we will show the full function signature infront of
|
// if this is defined, we will show the full function signature infront of
|
||||||
|
Loading…
x
Reference in New Issue
Block a user