Skip to content

Commit 120fbfd

Browse files
committed
Rewrite CMake
1 parent d454117 commit 120fbfd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+3189
-2609
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ lbuild/
1818
build_mariadb_32/
1919
build_mariadb_64/
2020
out/
21+
22+
# CPM package cache
23+
.cpm-cache/
24+
25+
# Compiler cache (sccache/ccache)
26+
.cache/
27+
2128
[Dd]ebug/
2229
[Rr]elease/
2330
x64/
@@ -126,6 +133,8 @@ UpgradeLog*.XML
126133
*.slo
127134
*.lo
128135
*.o
136+
*.lib
137+
*.exp
129138

130139
# Executables
131140
*.exe

.vscode/c_cpp_properties.json

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,16 @@
11
{
22
"configurations": [
33
{
4-
"name": "Win32",
4+
"name": "Default",
55
"includePath": [
66
"${workspaceFolder}/ext/**",
77
"${workspaceFolder}/src/**",
88
"${workspaceFolder}/build/_deps/**",
99
"${workspaceFolder}/build/generated/**"
1010
],
1111
"defines": [],
12-
"cStandard":"c23",
13-
"cppStandard": "c++23",
14-
"intelliSenseMode": "${default}"
15-
},
16-
{
17-
"name": "OSX",
18-
"includePath": [
19-
"${workspaceFolder}/ext/**",
20-
"${workspaceFolder}/src/**",
21-
"${workspaceFolder}/build/_deps/**",
22-
"${workspaceFolder}/build/generated/**"
23-
],
24-
"defines": [],
25-
"cStandard":"c23",
26-
"cppStandard": "c++23",
27-
"intelliSenseMode": "${default}",
28-
"compileCommands": "${workspaceFolder}/build/compile_commands.json"
29-
},
30-
{
31-
"name": "Linux",
32-
"includePath": [
33-
"${workspaceFolder}/ext/**",
34-
"${workspaceFolder}/src/**",
35-
"${workspaceFolder}/build/_deps/**",
36-
"${workspaceFolder}/build/generated/**"
37-
],
38-
"defines": [],
39-
"cStandard":"c23",
40-
"cppStandard": "c++23",
12+
"cStandard": "c17",
13+
"cppStandard": "c++20",
4114
"intelliSenseMode": "${default}",
4215
"compileCommands": "${workspaceFolder}/build/compile_commands.json"
4316
}

.vscode/extensions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
"ms-vscode.cpptools",
1515
"jeff-hykin.better-cpp-syntax"
1616
]
17-
}
17+
}

.vscode/settings.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
2-
"C_Cpp.default.cppStandard": "c++17",
2+
"C_Cpp.default.cppStandard": "c++20",
33
"C_Cpp.default.browse.limitSymbolsToIncludedHeaders": true,
44
"C_Cpp.intelliSenseEngine": "default",
5-
"C_Cpp.intelliSenseEngineFallback": "enabled",
65

76
"editor.bracketPairColorization.enabled": true,
87
"editor.inlayHints.enabled": "offUnlessPressed",

CMakeLists.txt

Lines changed: 44 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -1,151 +1,46 @@
1-
cmake_minimum_required(VERSION 3.20)
2-
project(server C CXX)
3-
4-
# https://cmake.org/cmake/help/latest/policy/CMP0069.html
5-
cmake_policy(SET CMP0069 NEW)
6-
set(CMAKE_POLICY_DEFAULT_CMP0069 NEW)
7-
8-
set(CMAKE_CXX_STANDARD 20)
9-
set(CMAKE_CXX_STANDARD_REQUIRED ON)
10-
set(CMAKE_CXX_EXTENSIONS OFF)
11-
set(LINKER_LANGUAGE CXX)
12-
set(USE_FOLDERS ON)
13-
14-
# Generate compile_commands.json to make it easier to work with clang based tools
15-
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
16-
1+
# Initial entry point for CMake. This file sets up the `cmake/` directory,
2+
# and then forwards you to `cmake/ProjectSettings.cmake` for further configuration.
3+
#
4+
# If you're developing locally, you should build as Debug so you get the best
5+
# debugging experience.
6+
#
7+
# If you're running for performance (like for a live server) your best best is probably
8+
# to build as RelWithDebInfo so you get optimizations, but also debug symbols.
9+
#
10+
# Windows:
11+
# Ideally you'll use Ninja as your generator with -G Ninja, but if you leave it blank your system
12+
# will pick one for you.
13+
#
14+
# Quickstart:
15+
#
16+
# cmake -S . -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo
17+
# cmake --build build --config RelWithDebInfo --parallel
18+
#
19+
# Preferred:
20+
#
21+
# Start x64 developer prompt:
22+
# "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
23+
#
24+
# Debug configure and build:
25+
# cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug
26+
# cmake --build build --config Debug --parallel
27+
#
28+
# RelWithDebInfo configure and build:
29+
# cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo
30+
# cmake --build build --config RelWithDebInfo --parallel
31+
#
32+
# Linux:
33+
# TODO
34+
#
35+
# MacOS:
36+
# As with Linux
37+
#
38+
39+
cmake_minimum_required(VERSION 3.28)
40+
41+
# Set CMake policies BEFORE project()
1742
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
18-
include(Cache)
19-
include(CPM)
20-
include(Platform)
21-
include(StandardProjectSettings)
22-
include(CompilerWarnings)
23-
include(Sanitizers)
24-
include(Valgrind)
25-
include(Git)
26-
27-
message(STATUS "CMAKE_VERSION: ${CMAKE_VERSION}")
28-
message(STATUS "CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}")
29-
message(STATUS "CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}")
30-
message(STATUS "CMAKE_CXX_COMPILER_ID: ${CMAKE_CXX_COMPILER_ID}")
31-
message(STATUS "CMAKE_CXX_COMPILER_VERSION: ${CMAKE_CXX_COMPILER_VERSION}")
32-
message(STATUS "CMAKE_CXX_STANDARD: ${CMAKE_CXX_STANDARD}")
33-
message(STATUS "CMAKE_GENERATOR: ${CMAKE_GENERATOR}")
34-
message(STATUS "CMAKE_GENERATOR_PLATFORM: ${CMAKE_GENERATOR_PLATFORM}")
35-
message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
36-
string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_UPPER)
37-
message(STATUS "CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}")
38-
message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
39-
if ("${CMAKE_BUILD_TYPE_UPPER}" STREQUAL "DEBUG")
40-
message(STATUS "CMAKE_CXX_FLAGS_DEBUG: ${CMAKE_CXX_FLAGS_DEBUG}")
41-
elseif ("${CMAKE_BUILD_TYPE_UPPER}" STREQUAL "MINSIZEREL")
42-
message(STATUS "CMAKE_CXX_FLAGS_MINSIZEREL: ${CMAKE_CXX_FLAGS_MINSIZEREL}")
43-
elseif ("${CMAKE_BUILD_TYPE_UPPER}" STREQUAL "RELEASE")
44-
message(STATUS "CMAKE_CXX_FLAGS_RELEASE: ${CMAKE_CXX_FLAGS_RELEASE}")
45-
elseif ("${CMAKE_BUILD_TYPE_UPPER}" STREQUAL "RELWITHDEBINFO")
46-
message(STATUS "CMAKE_CXX_FLAGS_RELWITHDEBINFO: ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
47-
else()
48-
message(FATAL_ERROR "Did not recognise CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} to print out compiler flags.")
49-
endif()
50-
message(STATUS "CMAKE_EXE_LINKER_FLAGS: ${CMAKE_EXE_LINKER_FLAGS}")
51-
52-
# set(CMAKE_VERBOSE_MAKEFILE ON)
53-
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
54-
55-
# Find Threads (pthread)
56-
set(THREADS_PREFER_PTHREAD_FLAG ON)
57-
find_package(Threads REQUIRED)
58-
link_libraries(${CMAKE_THREAD_LIBS_INIT})
59-
60-
# Find Python (defines ${Python_EXECUTABLE})
61-
find_package(Python REQUIRED)
62-
message(STATUS "Python_EXECUTABLE: ${Python_EXECUTABLE}")
63-
message(STATUS "Python_VERSION: ${Python_VERSION}")
64-
if(NOT ${Python_VERSION_MAJOR} EQUAL 3)
65-
message(FATAL_ERROR "Python 3 is required")
66-
endif()
67-
68-
# Find MariaDB
69-
find_package(MariaDB REQUIRED)
70-
find_package(MariaDBCPP REQUIRED)
71-
72-
# Find ZMQ
73-
find_package(ZeroMQ REQUIRED)
74-
75-
# Find LuaJIT
76-
find_package(LuaJIT REQUIRED)
77-
78-
# Find OpenSSL libcrypto
79-
find_package(OpenSSLlibcrypto REQUIRED)
80-
81-
# Find OpenSSL libssl
82-
find_package(OpenSSLlibssl REQUIRED)
83-
84-
if(UNIX AND NOT APPLE)
85-
find_package(Binutils REQUIRED)
86-
endif()
87-
88-
# Link this 'library' to set the c++ standard / compile-time options requested
89-
add_library(project_options INTERFACE)
90-
target_compile_features(project_options INTERFACE cxx_std_17)
91-
92-
# Link this 'library' to use the warnings specified in CompilerWarnings.cmake
93-
add_library(project_warnings INTERFACE)
94-
set_project_warnings(project_warnings)
95-
96-
# Globally define SOL_ALL_SAFETIES_ON so sol can be included anywhere
97-
# If SOL_NO_CHECK_NUMBER_PRECISION is defined, turns off number precision and integer
98-
# precision fitting when pushing numbers into sol
99-
# RC_FAST_MATH informs recastnavigation to not try to use infinity because we use -ffast-math
100-
# add_compile_definitions() comes with CMake 3.12
101-
add_definitions(
102-
-DSOL_ALL_SAFETIES_ON=1
103-
-DSOL_NO_CHECK_NUMBER_PRECISION=1
104-
-DSOL_DEFAULT_PASS_ON_ERROR=1
105-
-DSOL_PRINT_ERRORS=0
106-
-DRC_FAST_MATH=1
107-
-DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_DEBUG
108-
)
109-
110-
# For external libs
111-
set(CMAKE_WARN_DEPRECATED OFF CACHE BOOL "" FORCE)
112-
113-
option(PCH_ENABLE "Enable precompiled headers." ON)
114-
message(STATUS "PCH_ENABLE: ${PCH_ENABLE}")
115-
116-
# Tracy flags
117-
option(TRACY_ENABLE "Enable Tracy profiling." OFF)
118-
if(ENABLE_TRACY OR TRACY_ENABLED OR TRACY) # Also handle close flags
119-
set(TRACY_ENABLE ON)
120-
endif()
121-
message(STATUS "TRACY_ENABLE: ${TRACY_ENABLE}")
122-
123-
add_subdirectory(ext)
124-
125-
include(ClangTidy)
126-
include(Fuzzing)
127-
128-
message(STATUS "Configuring src/common/version.cpp")
129-
configure_file(${CMAKE_SOURCE_DIR}/src/common/version.cpp.in
130-
${CMAKE_SOURCE_DIR}/src/common/version.cpp)
131-
132-
# Generate IPC stubs
133-
set_property(
134-
DIRECTORY
135-
APPEND
136-
PROPERTY CMAKE_CONFIGURE_DEPENDS ${CMAKE_SOURCE_DIR}/tools/generate_ipc_stubs.py
137-
)
138-
message(STATUS "Generating IPC stubs")
139-
message(STATUS "Calling: ${Python_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/generate_ipc_stubs.py ${CMAKE_BINARY_DIR}")
140-
execute_process(
141-
COMMAND ${Python_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/generate_ipc_stubs.py ${CMAKE_BINARY_DIR}
142-
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
143-
RESULT_VARIABLE IPC_EXIT_CODE
144-
)
145-
if (NOT IPC_EXIT_CODE EQUAL 0)
146-
message(FATAL_ERROR "Failed to generate IPC stubs")
147-
endif()
148-
149-
include_directories(${CMAKE_BINARY_DIR}/generated) # Globally include the build/generated directory
43+
include(CMakePolicies)
15044

151-
add_subdirectory(src)
45+
project(server C CXX) # cmake/ProjectSettings.cmake
46+
include(ProjectSettings)

cmake/CMakePolicies.cmake

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#
2+
# CMake policy configuration
3+
#
4+
# Must be included before project() call in CMakeLists.txt
5+
#
6+
7+
# CMP0069: Enable Link Time Optimization (LTO) support
8+
# https://cmake.org/cmake/help/latest/policy/CMP0069.html
9+
cmake_policy(SET CMP0069 NEW)
10+
set(CMAKE_POLICY_DEFAULT_CMP0069 NEW)
11+
12+
# # CMP0091: MSVC runtime library flags selected by abstraction
13+
# # https://cmake.org/cmake/help/latest/policy/CMP0091.html
14+
# # Enables CMAKE_MSVC_RUNTIME_LIBRARY variable
15+
# if(POLICY CMP0091)
16+
# cmake_policy(SET CMP0091 NEW)
17+
# set(CMAKE_POLICY_DEFAULT_CMP0091 NEW)
18+
# endif()
19+
20+
# # CMP0141: MSVC debug information format specified by abstraction
21+
# # https://cmake.org/cmake/help/latest/policy/CMP0141.html
22+
# # Enables CMAKE_MSVC_DEBUG_INFORMATION_FORMAT variable
23+
# if(POLICY CMP0141)
24+
# cmake_policy(SET CMP0141 NEW)
25+
# set(CMAKE_POLICY_DEFAULT_CMP0141 NEW)
26+
# endif()

cmake/CPM.cmake

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,37 @@
1+
#
2+
# CPM.cmake is a cross-platform CMake script that adds dependency management capabilities to CMake.
3+
#
4+
# From get_cpm.cmake:
5+
# https://github.com/cpm-cmake/CPM.cmake
6+
#
7+
8+
#
19
# SPDX-License-Identifier: MIT
210
#
311
# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors
12+
#
413

5-
set(CPM_DOWNLOAD_VERSION 0.40.2)
6-
set(CPM_HASH_SUM "c8cdc32c03816538ce22781ed72964dc864b2a34a310d3b7104812a5ca2d835d")
14+
set(CPM_DOWNLOAD_VERSION 0.42.0)
15+
set(CPM_HASH_SUM "2020b4fc42dba44817983e06342e682ecfc3d2f484a581f11cc5731fbe4dce8a")
16+
17+
# Use a persistent location outside build directory to survive clean rebuilds
18+
if(NOT DEFINED CPM_SOURCE_CACHE AND NOT DEFINED ENV{CPM_SOURCE_CACHE})
19+
set(CPM_SOURCE_CACHE "${CMAKE_SOURCE_DIR}/.cpm-cache" CACHE PATH "Directory to store CPM package sources")
20+
elseif(DEFINED ENV{CPM_SOURCE_CACHE} AND NOT CPM_SOURCE_CACHE)
21+
set(CPM_SOURCE_CACHE "$ENV{CPM_SOURCE_CACHE}" CACHE PATH "Directory to store CPM package sources")
22+
endif()
23+
24+
# Create the cache directory if it doesn't exist
25+
if(CPM_SOURCE_CACHE)
26+
file(MAKE_DIRECTORY "${CPM_SOURCE_CACHE}")
27+
endif()
728

829
if(CPM_SOURCE_CACHE)
9-
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
30+
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
1031
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
11-
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
32+
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
1233
else()
13-
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
34+
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
1435
endif()
1536

1637
# Expand relative path. This is important if the provided path contains a tilde (~)

0 commit comments

Comments
 (0)