-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
81 lines (68 loc) · 2.6 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
cmake_minimum_required(VERSION 3.23)
project(webserver CXX)
set(CMAKE_CXX_STANDARD 20)
if (DEFINED PACKAGE_VERSION)
add_compile_definitions(VERSION="${PACKAGE_VERSION}")
endif ()
if (DEFINED APPNAME)
add_compile_definitions(APPNAME="${APPNAME}")
endif ()
add_compile_definitions(MG_ENABLE_OPENSSL=1)
if (NOT ("${CMAKE_BUILD_TYPE}" STREQUAL "Release"))
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")
message("Disabled optimization flags for use in profiler.")
else ()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Ofast")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Ofast")
message("Enabled optimization compiler flags.")
endif ()
set(resource_files
"error.html"
"favicon.ico"
"index.html"
"article.html"
"register.html"
)
# Creates C resources file from files in given directory
function(create_resources output)
# Create empty output file
file(WRITE ${output}
"#ifndef WEBSERVER_RESOURCES_HPP\n"
"#define WEBSERVER_RESOURCES_HPP\n"
"\n"
" #define LEN(name) name##_len\n"
"\n")
# Iterate through input files
foreach (bin ${resource_files})
message("[RC] Generating ${bin} resource...")
file(REAL_PATH ${bin} freal)
file(SIZE ${freal} fsize)
# Get short filename
string(REGEX MATCH "([^/]+)$" filename ${bin})
# Replace filename spaces & extension separator for C compatibility
string(REGEX REPLACE "\\.| |-" "_" filename ${filename})
# Read hex data from file
file(READ ${bin} filedata HEX)
if (NOT "${fsize}" STREQUAL "0")
# Convert hex data for C compatibility
string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," filedata ${filedata})
endif ()
# Append data to output file
file(APPEND ${output}
"\n"
"#ifndef RESOURCE_${filename}\n"
"#define RESOURCE_${filename}\n"
" static constexpr const unsigned char ${filename}[] = {${filedata} 0};\n"
" static constexpr const unsigned ${filename}_len = ${fsize};\n"
"#endif\n"
"\n")
endforeach ()
# Create empty output file
file(APPEND ${output} "\n#endif //WEBSERVER_RESOURCES_HPP")
endfunction()
create_resources("resources.hpp")
message(" [ compiler ] ${CMAKE_CXX_COMPILER}_${CMAKE_CXX_STANDARD} ${CMAKE_CXX_FLAGS}")
set(CMAKE_VERBOSE_MAKEFILE on)
add_executable(webserver main.cpp server.cpp config.cpp)
target_link_libraries(webserver pthread ssl crypto fineftp-server)