summaryrefslogtreecommitdiff
path: root/bot/CMakeLists.txt
blob: 261e4677fae8d714968645333a88d6f0f680442c (plain)
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
cmake_minimum_required(VERSION 3.10)
include(FetchContent)

# Creating symbolic links
create_symlink_if_exists("${CMAKE_SOURCE_DIR}/localization" "${CMAKE_CURRENT_BINARY_DIR}/localization")
create_symlink_if_exists("${CMAKE_SOURCE_DIR}/luamods" "${CMAKE_CURRENT_BINARY_DIR}/luamods")

if (EXISTS "${CMAKE_SOURCE_DIR}/.env")
  create_symlink_if_exists("${CMAKE_SOURCE_DIR}/.env" "${CMAKE_CURRENT_BINARY_DIR}/.env")
endif()

add_executable(Bot)

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
    target_compile_definitions(Bot PRIVATE DEBUG_MODE)
endif()

string(TIMESTAMP PROJECT_COMPILE_TIME "%s")

target_compile_definitions(Bot PRIVATE
  BOT_VERSION="${PROJECT_VERSION}"
  BOT_COMPILED_TIMESTAMP=${PROJECT_COMPILE_TIME}
)

set_target_properties(
  Bot PROPERTIES
  DESCRIPTION ${PROJECT_DESCRIPTION}
  OUTPUT_NAME "${PROJECT_NAME}-bot"
)

# BetterTTV Emote support
set(BUILD_BETTERTTV OFF BOOL "Enable BetterTTV emotes")
if (BUILD_BETTERTTV)
  message("-- Bulding BetterTTV parts")
  target_compile_definitions(Bot PRIVATE BUILD_BETTERTTV=1)
endif()

# TLS for websocket connections
set(USE_TLS ON CACHE BOOL "Enable TLS support")

file(GLOB_RECURSE SOURCE_FILES "src/*.cpp" "src/*.h" "src/*.hpp")

target_sources(Bot PRIVATE ${SOURCE_FILES})
target_include_directories(Bot PRIVATE src)

# DATABASE
option(USE_POSTGRES "Use PostgreSQL backend" OFF)
option(USE_MARIADB "Use MariaDB backend" ON)

if (USE_POSTGRES)
  FetchContent_Declare(
    pqxx
    GIT_REPOSITORY https://github.com/jtv/libpqxx.git
    GIT_TAG 7.10.1
  )
  FetchContent_MakeAvailable(pqxx)
  target_compile_definitions(Bot PRIVATE USE_POSTGRES)
  target_link_libraries(Bot PRIVATE pqxx)
endif()

# ev&doe it is mysql
if (USE_MARIADB)
  target_compile_definitions(Bot PRIVATE USE_MARIADB)

  # searching for mysql
  find_program(MYSQL_CONFIG_EXECUTABLE mysql_config REQUIRED)

  execute_process(COMMAND ${MYSQL_CONFIG_EXECUTABLE} --cflags
                  OUTPUT_VARIABLE MYSQL_CFLAGS
                  OUTPUT_STRIP_TRAILING_WHITESPACE)

  execute_process(COMMAND ${MYSQL_CONFIG_EXECUTABLE} --libs
                  OUTPUT_VARIABLE MYSQL_LIBS
                  OUTPUT_STRIP_TRAILING_WHITESPACE)

  target_compile_options(Bot PRIVATE ${MYSQL_CFLAGS})
  target_link_libraries(Bot PRIVATE ${MYSQL_LIBS})
endif()

# Getting libraries

# json
FetchContent_Declare(
  json
  URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz
)
FetchContent_MakeAvailable(json)

# http request maker
FetchContent_Declare(
  cpr
  GIT_REPOSITORY https://github.com/libcpr/cpr.git
  GIT_TAG 1.10.5
)
FetchContent_MakeAvailable(cpr)

# websockets
FetchContent_Declare(
  ixwebsocket
  GIT_REPOSITORY https://github.com/machinezone/IXWebSocket
  GIT_TAG v11.4.6
)
FetchContent_MakeAvailable(ixwebsocket)

set(SOL2_LUA_VERSION "5.4.8" CACHE STRING "The version of Lua used")
set(SOL2_BUILD_LUA FALSE CACHE BOOL "Always build Lua, do not search for it in the system")

FetchContent_Declare(
  sol
  GIT_REPOSITORY https://github.com/ThePhD/sol2.git
  GIT_TAG v3.5.0
)
FetchContent_MakeAvailable(sol)

# emotespp
FetchContent_Declare(
  emotespp
  GIT_REPOSITORY https://git.ilt.su/emotespp.git
  GIT_TAG master
)
FetchContent_MakeAvailable(emotespp)

target_link_libraries(Bot PRIVATE
    ixwebsocket::ixwebsocket
    nlohmann_json::nlohmann_json
    cpr::cpr
    lua
    sol2::sol2
    emotespp
)