-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
158 lines (142 loc) · 4.22 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
cmake_minimum_required(VERSION 3.20.5)
project(csworld CXX)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Dependencies
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
find_package(glfw3 CONFIG REQUIRED)
find_package(glm CONFIG REQUIRED)
find_package(flatbuffers CONFIG REQUIRED)
find_package(CURL REQUIRED)
find_package(Boost CONFIG REQUIRED COMPONENTS bind)
find_package(asio CONFIG REQUIRED)
find_package(SQLite3 REQUIRED)
function(escape_backslashes input_path output_path)
string(REPLACE "\\" "\\\\" escaped_path "${input_path}")
set(${output_path} "${escaped_path}" PARENT_SCOPE)
endfunction()
# Determine the platform.
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
set(OS_MAC 1)
set(OS_MACOSX 1) # For backwards compatibility.
set(OS_POSIX 1)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
set(OS_LINUX 1)
set(OS_POSIX 1)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
set(OS_WINDOWS 1)
else()
message(FATAL_ERROR "Unsupported target platform")
endif()
# Sources for common
file(GLOB PROJECT_SOURCE_FILES_COMMON
"common/*.cc"
"ext/*.c"
)
add_library(common STATIC ${PROJECT_SOURCE_FILES_COMMON})
target_include_directories(common PUBLIC
${CMAKE_SOURCE_DIR}/common
${CMAKE_SOURCE_DIR}/ext
)
# CEF
set(CEF_USE_SANDBOX OFF)
include(${CMAKE_SOURCE_DIR}/ext/cef-cmake/cmake/cef_cmake.cmake)
add_subdirectory(${CMAKE_SOURCE_DIR}/ext/cef-cmake)
set(CEF_SUBPROCESS_NAME "cef_subprocess")
if (OS_WINDOWS)
set(CEF_SUBPROCESS_NAME_WITH_EXT "${CEF_SUBPROCESS_NAME}.exe")
else()
set(CEF_SUBPROCESS_NAME_WITH_EXT "${CEF_SUBPROCESS_NAME}")
endif()
file(GLOB PROJECT_SOURCE_FILES_CEF_SUBPROCESS
"cef_subprocess/*.cc"
)
set(projectSourcesCefSubprocess
${PROJECT_SOURCE_FILES_CEF_SUBPROCESS}
)
add_executable(cef_subprocess ${projectSourcesCefSubprocess})
# Sources for client
file(GLOB PROJECT_SOURCE_FILES_CLIENT
"client/src/*.cc"
"client/src/**/*.cc"
"client/src/**/*.c"
)
set(projectSources
${PROJECT_SOURCE_FILES_CLIENT}
)
add_executable(client ${projectSources})
# Sources for server
file(GLOB PROJECT_SOURCE_FILES_SERVER
"server/src/*.cc"
)
set(projectSourcesServer
${PROJECT_SOURCE_FILES_SERVER}
)
add_executable(server ${projectSourcesServer})
# Compile C files as CPP
file(GLOB_RECURSE CFILES "${CMAKE_SOURCE_DIR}/*.c")
SET_SOURCE_FILES_PROPERTIES(${CFILES} PROPERTIES LANGUAGE CXX )
# Generate flatbuffer headers
file(GLOB FBS_FILES ${PROJECT_SOURCE_DIR}/fbs/*.fbs)
set(GENERATED_FILES ${PROJECT_SOURCE_DIR}/fbs/generated_fbs.stamp)
add_custom_command(
OUTPUT ${GENERATED_FILES}
COMMAND flatc -o ${PROJECT_SOURCE_DIR}/fbs --cpp ${FBS_FILES}
COMMAND ${CMAKE_COMMAND} -E touch ${GENERATED_FILES}
DEPENDS ${FBS_FILES}
COMMENT "Generating FlatBuffers files"
)
file(GLOB GENERATED_HEADERS ${PROJECT_SOURCE_DIR}/fbs/*_generated.h)
add_custom_target(
generate_fbs
DEPENDS ${GENERATED_HEADERS} ${GENERATED_FILES}
)
add_dependencies(client generate_fbs)
add_dependencies(server generate_fbs)
target_include_directories(client PRIVATE
${CMAKE_SOURCE_DIR}/client/src
${CMAKE_SOURCE_DIR}/ext
${CMAKE_SOURCE_DIR}/common
${CMAKE_SOURCE_DIR}/fbs
)
target_include_directories(cef_subprocess PRIVATE
)
target_include_directories(server PRIVATE
${CMAKE_SOURCE_DIR}/common
${CMAKE_SOURCE_DIR}/fbs
)
target_link_libraries(client PRIVATE
common
glfw
${GLEW_LIBRARIES}
${OPENGL_LIBRARIES}
SQLite::SQLite3
cefdll_wrapper
)
target_link_libraries(cef_subprocess PRIVATE
cefdll_wrapper
)
target_link_libraries(server PRIVATE
common
CURL::libcurl
)
target_compile_definitions(server PRIVATE
ASIO_HAS_BOOST_BIND
)
target_compile_definitions(cef_subprocess PRIVATE
UNICODE
)
target_compile_definitions(client PRIVATE
GLM_FORCE_LEFT_HANDED
GLM_ENABLE_EXPERIMENTAL
ASIO_HAS_BOOST_BIND
UNICODE
CEF_SUBPROCESS_NAME="${CEF_SUBPROCESS_NAME}"
CEF_SUBPROCESS_NAME_WITH_EXT="${CEF_SUBPROCESS_NAME_WITH_EXT}"
)
if(OS_WINDOWS AND MSVC)
set_target_properties(client PROPERTIES LINK_FLAGS "/SUBSYSTEM:WINDOWS")
set_target_properties(server PROPERTIES LINK_FLAGS "/SUBSYSTEM:CONSOLE")
set_target_properties(cef_subprocess PROPERTIES LINK_FLAGS "/SUBSYSTEM:WINDOWS")
endif()