-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
179 lines (150 loc) · 6.54 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
169
170
171
172
173
174
175
176
177
178
179
cmake_minimum_required(VERSION 3.22.0)
#[[
李夫人
北方有佳人,绝世而独立。
一顾倾人城,再顾倾人国。
宁不知倾城与倾国,佳人难再得。
https://gitee.com/acgist/lifuren
https://github.com/acgist/lifuren
]]
# https://cmake.org/cmake/help/latest/
project(lifuren-project VERSION 1.0.0 LANGUAGES C CXX)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()
option(ENABLE_TEST "打开测试" ON)
option(ENABLE_FLTK "开启FLTK界面" ON)
option(ENABLE_REST "开启REST接口" ON)
option(BUILD_SHARED_LIBS "是否编译为共享库" OFF)
set(HEADER_DIR include/)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# https://cmake.org/cmake/help/latest/prop_tgt/C_STANDARD.html
# https://cmake.org/cmake/help/latest/prop_tgt/CXX_STANDARD.html
if(CMAKE_HOST_UNIX)
set(CMAKE_C_STANDARD 23)
set(CMAKE_CXX_STANDARD 23)
# https://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c2x -Wall -Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++23 -Wall -Wextra")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wno-unused-variable -Wno-unused-parameter -Wno-missing-field-initializers -O0 -g")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wno-unused-variable -Wno-unused-parameter -Wno-missing-field-initializers -O0 -g")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Wunused-variable -Wunused-parameter -Wmissing-field-initializers -O3")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wunused-variable -Wunused-parameter -Wmissing-field-initializers -O3")
if(BUILD_SHARED_LIBS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
endif()
elseif(CMAKE_HOST_WIN32)
if(MSVC)
# TODO: 使用C23/C++23
set(CMAKE_C_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
# https://learn.microsoft.com/zh-cn/cpp/build/reference/compiler-options-listed-by-category
# /wd4804 = 忽略告警
# /wd4819 = 忽略告警
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /std:c17 /std:c++20")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c17 /std:c++20")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /wd4804 /wd4819")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /wd4804 /wd4819")
# set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /O2 /Ob2")
# set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2 /Ob2")
add_compile_options("/utf-8")
add_compile_options("/Zc:__cplusplus")
else()
message(WARNING "需要安装MSVC")
endif()
else()
message(FATAL_ERROR "不支持的系统:${CMAKE_HOST_SYSTEM_NAME}")
endif()
message(STATUS "当前模式: ${CMAKE_BUILD_TYPE}")
if(CMAKE_BUILD_TYPE MATCHES "Debug")
add_definitions(-DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_DEBUG)
message(STATUS "C_FLAGS : ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_DEBUG}")
message(STATUS "C++FLAGS: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}")
else()
add_definitions(-DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_INFO)
message(STATUS "C_FLAGS : ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_RELEASE}")
message(STATUS "C++FLAGS: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}")
endif()
if(CMAKE_BUILD_TYPE MATCHES "Debug")
set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/install)
endif()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/Debug/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/Debug/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/Debug/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/Release/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/Release/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/Release/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/bin)
set(
CMAKE_PREFIX_PATH
${CMAKE_PREFIX_PATH}
deps/libtorch
)
# include_directories(
# deps/libtorch/include
# deps/libtorch/include/torch/csrc/api/include
# )
if(CMAKE_HOST_WIN32)
set(
CMAKE_PREFIX_PATH
${CMAKE_PREFIX_PATH}
deps/fltk
deps/faiss
deps/opencv
deps/spdlog
deps/yaml-cpp
deps/cpp-httplib
)
# include_directories(
# deps/fltk/include
# deps/faiss/include
# deps/opencv/include
# deps/spdlog/include
# deps/yaml-cpp/include
# deps/cpp-httplib/include
# )
if(CMAKE_BUILD_TYPE MATCHES "Debug")
set(FLTK_FLUID_EXECUTABLE deps/fltk/tools/fltk/debug)
file(GLOB FLTK_DLLS "deps/fltk/debug/bin/*.dll")
file(GLOB YAML_DLLS "deps/yaml-cpp/debug/bin/*.dll")
file(GLOB FAISS_DLLS "deps/faiss/debug/bin/*.dll")
file(GLOB SPDLOG_DLLS "deps/spdlog/debug/bin/*.dll")
file(GLOB OPENCV_DLLS "deps/opencv/x64/vc16/bin/opencv_world4100d.dll")
file(GLOB HTTPLIB_DLLS "deps/cpp-httplib/debug/bin/*.dll")
else()
set(FLTK_FLUID_EXECUTABLE deps/fltk/tools/fltk)
file(GLOB FLTK_DLLS "deps/fltk/bin/*.dll")
file(GLOB YAML_DLLS "deps/yaml-cpp/bin/*.dll")
file(GLOB FAISS_DLLS "deps/faiss/bin/*.dll")
file(GLOB SPDLOG_DLLS "deps/spdlog/bin/*.dll")
file(GLOB OPENCV_DLLS "deps/opencv/x64/vc16/bin/opencv_world4100.dll")
file(GLOB HTTPLIB_DLLS "deps/cpp-httplib/bin/*.dll")
endif()
file(GLOB TORCH_DLLS "deps/libtorch/lib/*.dll")
find_package(libpng REQUIRED)
find_package(libjpeg-turbo REQUIRED)
endif()
find_package(FLTK REQUIRED)
find_package(faiss REQUIRED)
find_package(Torch REQUIRED)
find_package(OpenCV REQUIRED)
find_package(OpenMP REQUIRED)
find_package(spdlog REQUIRED)
find_package(httplib REQUIRED)
find_package(yaml-cpp REQUIRED)
add_subdirectory(cv)
add_subdirectory(nlp)
add_subdirectory(boot)
add_subdirectory(core)
add_subdirectory(deps)
add_subdirectory(model)
add_subdirectory(client)
set(HELP "LICENSE" "README.md")
install(FILES ${HELP} DESTINATION ${CMAKE_INSTALL_PREFIX}/)
install(DIRECTORY DESTINATION ${CMAKE_INSTALL_PREFIX}/logs/)
install(DIRECTORY DESTINATION ${CMAKE_INSTALL_PREFIX}/model/)
install(DIRECTORY docs/resources/ DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
file(COPY docs/resources/ DESTINATION ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/bin FILES_MATCHING PATTERN "*.png" PATTERN "*.jpg" PATTERN "*.ico" PATTERN "*.jpeg")