-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
168 lines (139 loc) · 5.38 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
158
159
160
161
162
163
164
165
166
167
168
cmake_minimum_required(VERSION 3.19)
project(Gaboot CXX)
set(SRC_DIR "${PROJECT_SOURCE_DIR}/src")
include(CheckIncludeFileCXX)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if (WIN32)
message("Windows detected, add windows toolchain from ${PROJECT_SOURCE_DIR}/conan/Windows/build/Release/generators/conan_toolchain.cmake")
include("${PROJECT_SOURCE_DIR}/conan/Windows/build/Release/generators/conan_toolchain.cmake")
elseif (UNIX)
message("Linux detected, add linux toolchain from ${PROJECT_SOURCE_DIR}/conan/Linux/build/Release/generators/conan_toolchain.cmake")
include("${PROJECT_SOURCE_DIR}/conan/Linux/build/Release/generators/conan_toolchain.cmake")
endif()
#include vcpkg dependencies
message("\nFetching packages")
find_package(Drogon CONFIG REQUIRED)
find_package(OpenSSL CONFIG REQUIRED)
find_package(OpenCV CONFIG REQUIRED)
#generate version file
include(scripts/git.cmake)
#include external dependencies
message("\nFetching modules")
include(scripts/bcrypt.cmake)
include(scripts/jwt.cmake)
include(scripts/cpr.cmake)
include(scripts/g3log.cmake)
include(scripts/fmtlib.cmake)
include(scripts/jsonvalidator.cmake)
include(scripts/dotenv.cmake)
# Gaboot
message(STATUS "Gaboot")
file(GLOB_RECURSE SRC_MAIN
"${SRC_DIR}/**.hpp"
"${SRC_DIR}/**.h"
"${SRC_DIR}/**.hxx"
"${SRC_DIR}/**.hh"
"${SRC_DIR}/**.cpp"
"${SRC_DIR}/**.cc"
"${SRC_DIR}/**.cxx"
"${SRC_DIR}/**.asm"
)
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
enable_language("RC")
set (ICON ${SRC_DIR}/gaboot_icon.rc)
endif()
if (MSVC)
add_compile_options(/bigobj)
add_compile_options(/utf-8)
else ()
#add_compile_options(-Wa,-mbig-obj)
add_compile_options(-finput-charset=UTF-8)
add_compile_options(-fexec-charset=UTF-8)
endif ()
set(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
# Specify the destination directory (out/build/windows-x64)
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(DESTINATION_DIR ${CMAKE_CURRENT_BINARY_DIR}/../Windows-x64)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(DESTINATION_DIR ${CMAKE_CURRENT_BINARY_DIR}/../Linux-x64)
endif()
# Add a custom command to copy .env and config.json to the build directory
if (EXISTS "${DESTINATION_DIR}/config.json" AND EXISTS "${DESTINATION_DIR}/.env")
add_custom_command(
OUTPUT ${DESTINATION_DIR}/.env
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SOURCE_DIR}/.env ${DESTINATION_DIR}/.env
DEPENDS ${SOURCE_DIR}/.env
COMMENT "Copying .env to build directory"
)
add_custom_command(
OUTPUT ${DESTINATION_DIR}/config.json
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SOURCE_DIR}/config.json ${DESTINATION_DIR}/config.json
DEPENDS ${SOURCE_DIR}/config.json
COMMENT "Copying config.json to build directory"
)
endif()
# Add a custom command to copy the folder and its contents
if (EXISTS "${SOURCE_DIR}/src/assets")
add_custom_target(copy_folder_to_build ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory "${SOURCE_DIR}/src/assets" "${DESTINATION_DIR}/assets"
COMMENT "Copying assets to build directory"
)
endif()
# Add a custom target to make sure the custom command is executed before building your main target
if (EXISTS "${DESTINATION_DIR}/config/config.json" AND EXISTS "${DESTINATION_DIR}/.env")
add_custom_target(CopyConfigFiles DEPENDS ${DESTINATION_DIR}/config.json ${DESTINATION_DIR}/.env)
endif()
# Compile main.cc as executable
add_executable(Gaboot "${SRC_DIR}/main.cc" ${VIEWSRC} ${ICON})
if (EXISTS "${DESTINATION_DIR}/config/config.json" AND EXISTS "${DESTINATION_DIR}/.env")
# Add dependencies to make sure the custom commands are executed before building YourTarget
add_dependencies(Gaboot CopyConfigFiles)
endif()
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_property(TARGET Gaboot PROPERTY CXX_STANDARD 20)
# set_property(TARGET Gaboot PROPERTY ISPC_INSTRUCTION_SETS avx2-i32x4)
source_group(TREE ${SRC_DIR} PREFIX "src" FILES ${SRC_MAIN})
target_include_directories(Gaboot PRIVATE
${SRC_DIR}
"${SRC_DIR}/module"
"${SRC_DIR}/util"
"${SRC_DIR}/middleware"
"${SRC_DIR}/interfaces"
"${SRC_DIR}/interfaces/payments"
${DROGON_INCLUDE_DIRS}
${openssl_INCLUDE_DIRS}
"${dotenv_SOURCE_DIR}/include/laserpants/dotenv"
"${fmtlib_SOURCE_DIR}/include"
"${jwt_SOURCE_DIR}/include"
"${nlohmann_json_SOURCE_DIR}/single_include"
"${bcrypt_SOURCE_DIR}/include"
"${jsonvalidator_SOURCE_DIR}/src"
"${SRC_DIR}/module/cart/models"
"${SRC_DIR}/module/category/models"
"${SRC_DIR}/module/customer/models"
"${SRC_DIR}/module/order/models"
"${SRC_DIR}/module/payment/models"
"${SRC_DIR}/module/product/models"
"${SRC_DIR}/module/wishlist/models"
"${SRC_DIR}/module/cart"
"${SRC_DIR}/module/category"
"${SRC_DIR}/module/customer"
"${SRC_DIR}/module/order"
"${SRC_DIR}/module/payment"
"${SRC_DIR}/module/product"
"${SRC_DIR}/module/wishlist"
"${SRC_DIR}/module/banner"
)
target_precompile_headers(Gaboot PRIVATE "${SRC_DIR}/pch.h")
target_link_libraries(Gaboot PRIVATE Drogon::Drogon bcrypt OpenSSL::SSL OpenSSL::Crypto cpr::cpr fmt::fmt nlohmann_json_schema_validator g3log opencv_core opencv_imgcodecs opencv_highgui)
# Warnings as errors
set_property(TARGET Gaboot PROPERTY COMPILE_WARNING_AS_ERROR ON)
target_sources(Gaboot PRIVATE ${SRC_MAIN})
add_compile_definitions(Gaboot
"_CRT_SECURE_NO_WARNINGS"
"NOMINMAX"
"WIN32_LEAN_AND_MEAN"
)
# Add unit test build
#add_subdirectory(test)