forked from MillhioreBT/forgottenserver-downgrade
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
124 lines (100 loc) · 3.61 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
cmake_minimum_required(VERSION 3.16)
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
# Ensure to pick up the default triplet from the environment if any. This helps
# driving the vcpkg triplet in the same way either when starting vcpkg directly,
# or when letting CMake start vcpkg at configure/generate time.
# Note: this logic must happen before PROJECT command.
if (DEFINED ENV{VCPKG_DEFAULT_TRIPLET} AND NOT DEFINED VCPKG_TARGET_TRIPLET)
set(VCPKG_TARGET_TRIPLET "$ENV{VCPKG_DEFAULT_TRIPLET}" CACHE STRING "The vcpkg triplet")
endif()
project(tfs CXX)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
if (NOT WIN32)
add_compile_options(-Wall -Wextra -Wnon-virtual-dtor -Wold-style-cast -pedantic -Werror -pipe -fvisibility=hidden)
endif ()
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
add_compile_options(-fno-strict-aliasing)
endif ()
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_compile_options(-Wimplicit-fallthrough -Wmove)
endif ()
# Find packages.
find_package(cryptopp CONFIG)
if (CryptoPP_FOUND) # vcpkg-provided cmake package called CryptoPP
set(Crypto++_LIBRARIES "cryptopp::cryptopp")
else()
find_package(Crypto++ REQUIRED)
endif ()
find_package(fmt CONFIG)
if (NOT fmt_FOUND)
find_package(fmt 6.1.2 REQUIRED)
endif()
# Look for vcpkg-provided libmariadb first
# If we link to the file directly, we might miss its dependencies from vcpkg
find_package(unofficial-libmariadb CONFIG)
if (unofficial-libmariadb_FOUND)
set(MYSQL_CLIENT_LIBS "unofficial::libmariadb")
else ()
find_package(MySQL REQUIRED)
endif ()
find_package(Threads REQUIRED)
find_package(PugiXML CONFIG REQUIRED)
# Selects LuaJIT if user defines or auto-detected
if (DEFINED USE_LUAJIT AND NOT USE_LUAJIT)
set(FORCE_LUAJIT ${USE_LUAJIT})
else ()
find_package(LuaJIT)
set(FORCE_LUAJIT ${LuaJIT_FOUND})
endif ()
option(USE_LUAJIT "Use LuaJIT" ${FORCE_LUAJIT})
if (NOT FORCE_LUAJIT)
find_package(Lua REQUIRED)
endif ()
if (APPLE)
find_package(Iconv REQUIRED)
endif()
find_package(Boost 1.66.0 REQUIRED COMPONENTS system iostreams)
option(BUILD_TESTING "Build unit tests" OFF)
include_directories(${Boost_INCLUDE_DIRS} ${Crypto++_INCLUDE_DIR} ${LUA_INCLUDE_DIR} ${MYSQL_INCLUDE_DIR} ${PUGIXML_INCLUDE_DIR})
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_subdirectory(src)
add_executable(tfs ${tfs_MAIN})
target_link_libraries(tfs tfslib)
if (BUILD_TESTING)
message(STATUS "Building unit tests")
enable_testing()
add_subdirectory(src/tests)
endif()
### INTERPROCEDURAL_OPTIMIZATION ###
cmake_policy(SET CMP0069 NEW)
include(CheckIPOSupported)
check_ipo_supported(RESULT result OUTPUT error)
if (result)
message(STATUS "IPO / LTO enabled")
set_target_properties(tfs PROPERTIES INTERPROCEDURAL_OPTIMIZATION True)
else ()
message(STATUS "IPO / LTO not supported: <${error}>")
endif ()
### END INTERPROCEDURAL_OPTIMIZATION ###
### Git Version ###
# Define the two required variables before including
# the source code for watching a git repository.
option(SKIP_GIT "Skip checking for git updates" OFF)
if(NOT SKIP_GIT)
set(PRE_CONFIGURE_FILE "cmake/gitmetadata.h.in")
set(POST_CONFIGURE_FILE "${CMAKE_CURRENT_BINARY_DIR}/gitmetadata.h")
include(git_watcher)
if(Git_FOUND)
add_dependencies(tfs check_git)
target_include_directories(tfs PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
endif()
endif()
### END Git Version ###
# Option to disable unity builds
option(ENABLE_UNITY_BUILD "Enable unity build" ON)
if(ENABLE_UNITY_BUILD)
set_target_properties(tfslib PROPERTIES UNITY_BUILD ON)
endif()
target_precompile_headers(tfs PUBLIC src/otpch.h)