-
Notifications
You must be signed in to change notification settings - Fork 59
/
CMakeLists.txt
executable file
·612 lines (490 loc) · 20.9 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
CMAKE_MINIMUM_REQUIRED(VERSION 3.20)
cmake_policy(SET CMP0048 NEW)
set(ENABLE_VCPKG OFF CACHE BOOL "choose ON to enable")
set(ENABLE_BOOST OFF CACHE BOOL "choose ON to enable")
set(ENABLE_GD OFF CACHE BOOL "choose ON to enable")
set(ENABLE_WIN_VCPKG OFF CACHE BOOL "choose ON to enable")
if(ENABLE_VCPKG)
set(vcpkg_root $ENV{VCPKG_ROOT})
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND vcpkg_root)
set(CMAKE_TOOLCHAIN_FILE "${vcpkg_root}/scripts/buildsystems/vcpkg.cmake")
endif()
endif()
macro(auto_enable_vcpkg_feature opt feature)
if(${opt})
list(FIND VCPKG_MANIFEST_FEATURES ${feature} index)
if(index EQUAL -1)
message(STATUS "Auto append features: ${feature}")
list(APPEND VCPKG_MANIFEST_FEATURES ${feature})
endif()
endif()
endmacro()
if(ENABLE_VCPKG)
auto_enable_vcpkg_feature(ENABLE_GD "gd")
auto_enable_vcpkg_feature(ENABLE_BOOST "boost")
endif()
PROJECT(Paozhu_web_framework)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(mode "CMAKE_BUILD_TYPE")
set(BOOST_OPEN " ")
set(GD_OPEN " ")
if(ENABLE_BOOST STREQUAL "ON")
message("ENABLE_BOOST")
set(BOOST_OPEN " -DENABLE_BOOST ")
endif()
if(ENABLE_GD STREQUAL "ON")
message("ENABLE_GD")
set(GD_OPEN " -DENABLE_GD ")
endif()
set(sys_so_path "/usr/lib64")
if (IS_DIRECTORY "/usr/lib/x86_64-linux-gnu")
set(sys_so_path "/usr/lib/x86_64-linux-gnu")
endif()
if (CMAKE_SYSTEM_NAME MATCHES "Windows")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_WIN32_WINNT=0x0601")
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8 /EHsc")
endif ()
if(${mode} AND (CMAKE_BUILD_TYPE STREQUAL "Debug"))
if(CMAKE_SYSTEM_NAME MATCHES "Windows")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DASIO_STANDALONE -DDEBUG ${BOOST_OPEN} ${GD_OPEN}")
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fsanitize=address")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pthread -g")
endif ()
else()
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pthread -g -fsanitize=address -DASIO_STANDALONE -DDEBUG ${BOOST_OPEN} ${GD_OPEN} -I/usr/local/include -I/usr/local/mysql/include -I/usr/include -I/usr/include/mysql " )
endif ()
message("Debug mode:${CMAKE_CXX_FLAGS_DEBUG}")
elseif(${mode} AND (CMAKE_BUILD_TYPE STREQUAL "Release"))
if (CMAKE_SYSTEM_NAME MATCHES "Windows")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DASIO_STANDALONE ${BOOST_OPEN} ${GD_OPEN} -O3")
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pthread")
endif ()
else ()
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall -Wextra -O3")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -DASIO_STANDALONE ${BOOST_OPEN} ${GD_OPEN} -I/usr/local/include -I/usr/local/mysql/include -I/usr/include -I/usr/include/mysql " )
file(MAKE_DIRECTORY /usr/local/etc/paozhu)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/conf/ DESTINATION /usr/local/etc/paozhu/)
endif ()
message("Release mode:${CMAKE_CXX_FLAGS_RELEASE}")
else()
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wextra")
message("Debug mode:${CMAKE_CXX_FLAGS_DEBUG}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pthread -g -fsanitize=address -DASIO_STANDALONE -DDEBUG ${BOOST_OPEN} ${GD_OPEN} -I/usr/local/include -I/usr/local/mysql/include -I/usr/include -I/usr/include/mysql " )
if(NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
endif ()
endif()
file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/temp)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/log)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/bin)
set(USE_STANDALONE_ASIO ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
message(STATUS "SOURCE dir ${CMAKE_CURRENT_SOURCE_DIR}")
set(CMAKE_BUILD_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/build)
set(CMAKE_CACHEFILE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/build)
set(CMAKE_CURRENT_BINARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/build)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/common)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/controller)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/vendor/httpcli)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/viewsrc/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/websockets/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/bin/paozhu_pre)
file(REMOVE_RECURSE ${CMAKE_CURRENT_SOURCE_DIR}/bin/paozhu_pre)
endif()
set(PAOZHU_PRE paozhu_pre)
add_executable(${PAOZHU_PRE} ${CMAKE_CURRENT_SOURCE_DIR}/vendor/httpcli/autopickmethod.cpp ${CMAKE_CURRENT_SOURCE_DIR}/vendor/httpserver/src/md5.cpp)
file(GLOB_RECURSE orm_list ${CMAKE_CURRENT_SOURCE_DIR}/orm/*.cpp)
file(GLOB_RECURSE source_list ${CMAKE_CURRENT_SOURCE_DIR}/models/*.cpp)
file(GLOB_RECURSE FRAMEWORK_CPP_PATH ${CMAKE_CURRENT_SOURCE_DIR}/vendor/httpserver/*.cpp)
file(GLOB_RECURSE common_list ${CMAKE_CURRENT_SOURCE_DIR}/common/*.cpp)
file(GLOB_RECURSE controller_list ${CMAKE_CURRENT_SOURCE_DIR}/controller/src/*.cpp)
file(GLOB_RECURSE viewsrc_list ${CMAKE_CURRENT_SOURCE_DIR}/viewsrc/view/*.cpp)
file(GLOB_RECURSE reflect_list ${CMAKE_CURRENT_SOURCE_DIR}/libs/*.cpp)
file(GLOB_RECURSE src_list ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
foreach(cppfile IN LISTS controller_list)
string(REGEX REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/controller/src/" "" cppfilename ${cppfile})
string(FIND ${cppfilename} "/" strpos)
if(${strpos} GREATER_EQUAL "0" )
string(REGEX MATCHALL "([A-Za-z0-9._-]+)/" npaths ${cppfilename} )
set(fullpaths "")
string(APPEND fullpaths "${CMAKE_CURRENT_SOURCE_DIR}/controller/include/")
foreach(onepathname ${npaths})
string(REPLACE "/" "" toucpath ${onepathname})
string(APPEND fullpaths ${toucpath})
if (IS_DIRECTORY "${fullpaths}")
else()
message("mkdir ${fullpaths}")
file(MAKE_DIRECTORY "${fullpaths}")
endif()
string(APPEND fullpaths "/")
endforeach()
endif()
string(REGEX REPLACE ".cpp" "" cppbasename ${cppfilename})
# message(${cppbasename})
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/controller/include/${cppbasename}.h")
else()
file(TOUCH "${CMAKE_CURRENT_SOURCE_DIR}/controller/include/${cppbasename}.h")
endif()
endforeach()
function(include_sub_directories_recursively root_dir)
if (IS_DIRECTORY ${root_dir}) # 当前路径是一个目录吗,是的话就加入到包含目录
# if (${root_dir} MATCHES "include")
message("include dir: " ${root_dir})
include_directories(${root_dir})
# endif()
endif()
file(GLOB ALL_SUB RELATIVE ${root_dir} ${root_dir}/*) # 获得当前目录下的所有文件,让如ALL_SUB列表中
foreach(sub ${ALL_SUB})
if (IS_DIRECTORY ${root_dir}/${sub})
include_sub_directories_recursively(${root_dir}/${sub}) # 对子目录递归调用,包含
endif()
endforeach()
endfunction()
include_sub_directories_recursively(${CMAKE_CURRENT_SOURCE_DIR}/vendor/httpserver)
include_sub_directories_recursively(${CMAKE_CURRENT_SOURCE_DIR}/orm)
include_sub_directories_recursively(${CMAKE_CURRENT_SOURCE_DIR}/models)
include_sub_directories_recursively(${CMAKE_CURRENT_SOURCE_DIR}/controller/include)
include_sub_directories_recursively(${CMAKE_CURRENT_SOURCE_DIR}/libs)
include_sub_directories_recursively(${CMAKE_CURRENT_SOURCE_DIR}/include)
include_sub_directories_recursively(${CMAKE_CURRENT_SOURCE_DIR}/common)
add_executable(paozhu_cli ${CMAKE_CURRENT_SOURCE_DIR}/vendor/httpcli/http_cli.cpp)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
if(${mode} AND (CMAKE_BUILD_TYPE STREQUAL "Release"))
add_executable(paozhu ${CMAKE_CURRENT_SOURCE_DIR}/test/testdaemon.cpp ${common_list} ${viewsrc_list} ${FRAMEWORK_CPP_PATH} ${orm_list} ${reflect_list} ${src_list} ${source_list} ${controller_list})
else()
add_executable(paozhu ${CMAKE_CURRENT_SOURCE_DIR}/test/test.cpp ${common_list} ${viewsrc_list} ${FRAMEWORK_CPP_PATH} ${orm_list} ${reflect_list} ${src_list} ${source_list} ${controller_list})
endif()
if (ENABLE_WIN_VCPKG STREQUAL "ON")
else()
add_custom_command(
TARGET paozhu_pre POST_BUILD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
COMMAND echo "-- controls method --"
COMMAND ${PAOZHU_PRE} ${CMAKE_CURRENT_SOURCE_DIR}/
)
endif()
if (ENABLE_VCPKG)
add_compile_definitions(ENABLE_VCPKG)
find_package(asio CONFIG REQUIRED)
target_link_libraries(paozhu asio::asio)
if (ENABLE_BOOST)
add_compile_definitions(ENABLE_BOOST)
set(Boost_NO_WARN_NEW_VERSIONS ON)
find_package(Boost REQUIRED COMPONENTS filesystem coroutine)
target_link_libraries(paozhu Boost::boost Boost::filesystem Boost::coroutine)
endif ()
find_package(OpenSSL REQUIRED)
target_link_libraries(paozhu OpenSSL::Crypto OpenSSL::SSL)
find_package(ZLIB REQUIRED)
target_link_libraries(paozhu ZLIB::ZLIB)
# find_package(libmysql REQUIRED)
find_package(unofficial-libmariadb CONFIG REQUIRED)
find_path(MYSQL_ROOT_DIR mysql)
# target_link_libraries(paozhu ${MYSQL_LIBRARIES})
# target_link_libraries(paozhu_cli ${MYSQL_LIBRARIES})
target_link_libraries(paozhu unofficial::libmariadb)
target_link_libraries(paozhu_cli unofficial::libmariadb)
target_include_directories(paozhu PUBLIC ${MYSQL_ROOT_DIR}/mysql)
target_include_directories(paozhu_cli PUBLIC ${MYSQL_ROOT_DIR}/mysql)
if (ENABLE_GD STREQUAL "ON")
find_package(PkgConfig)
pkg_check_modules(LIBGD REQUIRED IMPORTED_TARGET gdlib)
target_link_libraries(paozhu PkgConfig::LIBGD)
find_path(QRENCODE_INCLUDE_DIR NAMES qrencode.h)
find_library(QRENCODE_LIBRARY_RELEASE qrencode)
# find_library(QRENCODE_LIBRARY_DEBUG qrencoded)
# set(QRENCODE_LIBRARIES optimized ${QRENCODE_LIBRARY_RELEASE} debug ${QRENCODE_LIBRARY_DEBUG})
target_include_directories(paozhu PRIVATE ${QRENCODE_INCLUDE_DIR})
target_link_libraries(paozhu ${QRENCODE_LIBRARY_RELEASE})
# MESSAGE(STATUS ${QRENCODE_LIBRARY_RELEASE})
# warning: Fixed an issue where ports/libqrencode would not automatically
# copy dll files to the bin directory
if (CMAKE_SYSTEM_NAME MATCHES "Windows")
set(PATH_TO_QRENCODE_DLL "")
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
set(PATH_TO_QRENCODE_DLL "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/bin/qrencode.dll")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(PATH_TO_QRENCODE_DLL "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/libqrencode.dll")
endif ()
message(STATUS "Selected libqrencode.dll: ${PATH_TO_QRENCODE_DLL}")
add_custom_command(
TARGET paozhu POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${PATH_TO_QRENCODE_DLL} ${CMAKE_CURRENT_SOURCE_DIR}/bin/
)
endif ()
find_package(PNG REQUIRED)
target_link_libraries(paozhu PNG::PNG)
find_package(Freetype REQUIRED)
target_link_libraries(paozhu Freetype::Freetype)
endif ()
find_package(unofficial-brotli CONFIG REQUIRED)
target_link_libraries(paozhu unofficial::brotli::brotlidec unofficial::brotli::brotlienc)
else ()
if(USE_STANDALONE_ASIO)
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
set(ASIO_PATH "/usr/local/opt/asio/include" "/usr/local/include" "/opt/homebrew/opt/asio" ${CMAKE_CURRENT_SOURCE_DIR}/asio)
else()
set(ASIO_PATH ${CMAKE_CURRENT_SOURCE_DIR}/asio "/usr/include")
endif()
target_compile_definitions(paozhu INTERFACE ASIO_STANDALONE)
find_path(ASIO_PATH asio.hpp)
message(state " Standalone Asio found: " ${ASIO_PATH})
if(NOT ASIO_PATH)
message(FATAL_ERROR "Standalone Asio not found")
else()
target_include_directories(paozhu INTERFACE ${ASIO_PATH})
endif()
include_directories(${ASIO_PATH})
endif()
if(ENABLE_BOOST STREQUAL "ON")
message("---ENABLE_BOOST-----")
find_package(Boost REQUIRED
COMPONENTS system filesystem)
if(Boost_FOUND)
add_compile_definitions(ENABLE_BOOST)
include_directories("${Boost_INCLUDE_DIRS}/boost")
MESSAGE( STATUS "Boost_INCLUDE_DIRS = ${Boost_INCLUDE_DIRS}")
MESSAGE( STATUS "Boost_LIBRARIES = ${Boost_LIBRARY_DIRS}")
MESSAGE( STATUS "Boost_LIB_VERSION = ${Boost_LIB_VERSION}")
link_directories(${Boost_LIBRARY_DIRS})
target_link_libraries (paozhu ${Boost_LIBRARIES})
endif()
endif()
find_package(OpenSSL REQUIRED)
if(OPENSSL_FOUND)
message(STATUS "OPENSSL_VERSION = ${OPENSSL_VERSION}")
message(STATUS "OPENSSL_SSL_LIBRARY = ${OPENSSL_SSL_LIBRARY}")
message(STATUS "OPENSSL_CRYPTO_LIBRARY = ${OPENSSL_CRYPTO_LIBRARY}")
message(STATUS "OPENSSL_INCLUDE_DIR = ${OPENSSL_INCLUDE_DIR}")
INCLUDE_DIRECTORIES("${OPENSSL_INCLUDE_DIR}")
target_link_libraries (paozhu ${OPENSSL_SSL_LIBRARY})
target_link_libraries (paozhu ${OPENSSL_CRYPTO_LIBRARY})
endif()
find_package(ZLIB REQUIRED)
if(ZLIB_FOUND)
message(STATUS "Zlib Found! ${ZLIB_LIBRARIES}")
include_directories(${ZLIB_INCLUDE_DIR})
set(zlib_library ${ZLIB_LIBRARIES})
target_link_libraries(paozhu z)
endif()
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
if (IS_DIRECTORY "/usr/local/mysql/include")
MESSAGE( STATUS "/usr/local/mysql")
set(MYSQL_INCLUDE_DIR "/usr/local/mysql/include")
include_sub_directories_recursively(/usr/local/mysql/include)
endif()
if (IS_DIRECTORY "/usr/local/opt/mysql-client")
MESSAGE( STATUS "/usr/local/opt/mysql-client")
set(MYSQL_INCLUDE_DIR "/usr/local/opt/mysql-client/include")
include_sub_directories_recursively(/usr/local/opt/mysql-client/include)
endif()
if (IS_DIRECTORY "/opt/homebrew/opt/mysql")
MESSAGE( STATUS "/opt/homebrew/opt/mysql")
set(MYSQL_INCLUDE_DIR "/opt/homebrew/opt/mysql/include")
include_sub_directories_recursively(/opt/homebrew/opt/mysql/include)
endif()
if (IS_DIRECTORY "/opt/homebrew/opt/mysql-client")
MESSAGE( STATUS "/opt/homebrew/opt/mysql-client")
set(MYSQL_INCLUDE_DIR "/opt/homebrew/opt/mysql-client/include")
include_sub_directories_recursively(/opt/homebrew/opt/mysql-client/include)
endif()
MESSAGE( STATUS "MYSQL_ROOT_DIR = ${MYSQL_ROOT_DIR} ")
else()
find_path(MYSQL_ROOT_DIR mysql)
endif()
FIND_PATH(MYSQL_INCLUDE_DIR NAMES mysql.h
PATHS /usr/local/include/mysql /usr/include/mysql /opt/homebrew/opt/mysql/include /usr/local/opt/mysql-client/include /opt/homebrew/opt/mysql-client/include
)
MESSAGE( STATUS "MYSQL_ROOT_DIR = ${MYSQL_ROOT_DIR} ")
find_package_handle_standard_args(mysql REQUIRED_VARS MYSQL_ROOT_DIR)
if(NOT MYSQL_INCLUDE_DIR)
message(STATUS "Could not find \"mysql.h\" from searching ")
endif()
SET(MYSQL_NAMES mysqlclient)
FIND_LIBRARY(MYSQL_LIBRARY
NAMES ${MYSQL_NAMES}
PATHS /usr/lib /usr/local/lib /usr/local/mysql/lib /usr/local/opt/mysql/lib /opt/homebrew/opt/mysql/lib /opt/homebrew/opt/mysql-client/lib
PATH_SUFFIXES mysql
)
IF (MYSQL_INCLUDE_DIR AND MYSQL_LIBRARY)
SET(MYSQL_FOUND TRUE)
SET( MYSQL_LIBRARIES ${MYSQL_LIBRARY} )
ELSE (MYSQL_INCLUDE_DIR AND MYSQL_LIBRARY)
SET(MYSQL_FOUND FALSE)
SET( MYSQL_LIBRARIES )
ENDIF (MYSQL_INCLUDE_DIR AND MYSQL_LIBRARY)
IF (MYSQL_FOUND)
IF (NOT MYSQL_FIND_QUIETLY)
MESSAGE(STATUS "Found MySQL: ${MYSQL_LIBRARY}")
ENDIF (NOT MYSQL_FIND_QUIETLY)
ELSE (MYSQL_FOUND)
IF (MYSQL_FIND_REQUIRED)
MESSAGE(STATUS "Looked for MySQL libraries named ${MYSQL_NAMES}.")
MESSAGE(FATAL_ERROR "Could NOT find MySQL library")
ENDIF (MYSQL_FIND_REQUIRED)
ENDIF (MYSQL_FOUND)
target_include_directories(paozhu PUBLIC ${MYSQL_INCLUDE_DIR})
target_link_libraries(paozhu ${MYSQL_LIBRARY})
target_include_directories(paozhu_cli PUBLIC ${MYSQL_INCLUDE_DIR})
target_link_libraries(paozhu_cli ${MYSQL_LIBRARY})
if(ENABLE_GD STREQUAL "ON")
message("---ENABLE_GD-----")
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
if (IS_DIRECTORY "/usr/local/opt/gd/lib")
MESSAGE( STATUS "/usr/local/opt/gd/lib")
set(GD_ROOT_DIR "/usr/local/opt/gd/lib")
include_sub_directories_recursively(/usr/local/opt/gd/include)
endif()
if (IS_DIRECTORY "/opt/homebrew/opt/gd/lib")
MESSAGE( STATUS "/opt/homebrew/opt/gd/lib")
set(GD_ROOT_DIR "/opt/homebrew/opt/gd/lib")
include_sub_directories_recursively(/opt/homebrew/opt/gd/include)
endif()
else()
set(GD_ROOT_DIR "${sys_so_path}")
endif()
set(find_gdname gd)
find_library(GD_LIB_DIR
NAMES ${find_gdname}
PATHS "${GD_ROOT_DIR}"
NO_DEFAULT_PATH
)
if(NOT GD_LIB_DIR)
message(FATAL_ERROR
"GD Graphics Library NOT FOUND! please install . "
)
endif()
message(STATUS "GD Graphics Library at: ${GD_LIB_DIR}")
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
if (IS_DIRECTORY "/usr/local/opt/qrencode/lib")
MESSAGE( STATUS "/usr/local/opt/qrencode/lib")
set(QR_ROOT_DIR "/usr/local/opt/qrencode/lib")
include_sub_directories_recursively(/usr/local/opt/qrencode/include)
endif()
if (IS_DIRECTORY "/opt/homebrew/opt/qrencode/lib")
MESSAGE( STATUS "/opt/homebrew/opt/qrencode/lib")
set(QR_ROOT_DIR "/opt/homebrew/opt/qrencode/lib")
include_sub_directories_recursively(/opt/homebrew/opt/qrencode/include)
endif()
else()
set(QR_ROOT_DIR "${sys_so_path}")
endif()
set(find_qrname qrencode)
find_library(QR_LIB_DIR
NAMES ${find_qrname}
PATHS "${QR_ROOT_DIR}"
NO_DEFAULT_PATH
)
if(NOT QR_LIB_DIR)
message(FATAL_ERROR
"qrencode Library NOT FOUND! please install . "
)
endif()
message(STATUS "qrencode at: ${QR_LIB_DIR}")
INCLUDE_DIRECTORIES("${GD_ROOT_DIR}/include")
INCLUDE_DIRECTORIES("${QR_ROOT_DIR}/include")
link_directories("${QR_ROOT_DIR}/lib")
link_directories("${GD_ROOT_DIR}/lib")
target_link_libraries(paozhu ${GD_LIB_DIR})
target_link_libraries(paozhu ${QR_LIB_DIR})
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
if (IS_DIRECTORY "/usr/local/opt/libpng/lib")
MESSAGE( STATUS "/usr/local/opt/libpng/lib")
set(PNG_ROOT_DIR "/usr/local/opt/libpng/lib")
include_sub_directories_recursively(/usr/local/opt/libpng/include)
endif()
if (IS_DIRECTORY "/opt/homebrew/opt/libpng/lib")
MESSAGE( STATUS "/opt/homebrew/opt/libpng/lib")
set(PNG_ROOT_DIR "/opt/homebrew/opt/libpng/lib")
include_sub_directories_recursively(/opt/homebrew/opt/libpng/include)
endif()
else()
set(PNG_ROOT_DIR "${sys_so_path}")
endif()
find_library(PNG_LIB_DIR
NAMES png
PATHS "${PNG_ROOT_DIR}"
NO_DEFAULT_PATH
)
target_link_libraries(paozhu ${PNG_LIB_DIR})
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
if (IS_DIRECTORY "/usr/local/opt/freetype/lib")
MESSAGE( STATUS "/usr/local/opt/freetype/lib")
set(FREETYPE_ROOT_DIR "/usr/local/opt/freetype/lib")
include_sub_directories_recursively(/usr/local/opt/freetype/include)
endif()
if (IS_DIRECTORY "/opt/homebrew/opt/freetype/lib")
MESSAGE( STATUS "/opt/homebrew/opt/freetype/lib")
set(FREETYPE_ROOT_DIR "/opt/homebrew/opt/freetype/lib")
include_sub_directories_recursively(/opt/homebrew/opt/freetype/include)
endif()
else()
set(FREETYPE_ROOT_DIR "${sys_so_path}")
endif()
find_library(FREETYPE_LIB_DIR
NAMES freetype
PATHS "${FREETYPE_ROOT_DIR}"
NO_DEFAULT_PATH
)
target_link_libraries(paozhu ${FREETYPE_LIB_DIR})
#end ENABLE_GD
endif()
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
if (IS_DIRECTORY "/usr/local/opt/brotli/lib")
set(BROTLI_ROOT_DIR "/usr/local/opt/brotli/lib")
INCLUDE_DIRECTORIES("/usr/local/opt/brotli/include")
endif()
# set(BROTLI_ROOT_DIR "/usr/local/opt/brotli/lib")
if (IS_DIRECTORY "/opt/homebrew/opt/brotli/lib")
set(BROTLI_ROOT_DIR "/opt/homebrew/opt/brotli/lib")
INCLUDE_DIRECTORIES("/opt/homebrew/opt/brotli/include")
endif()
else()
set(BROTLI_ROOT_DIR "${sys_so_path}")
endif()
#find_package(Brotli COMPONENTS encoder decoder common REQUIRED)
message(STATUS "Brotli at: ${BROTLI_ROOT_DIR}")
set(find_brname brotlienc)
set(find_brdename brotlidec)
find_library(BR_LIB_DIR
NAMES ${find_brname}
PATHS "${BROTLI_ROOT_DIR}"
NO_DEFAULT_PATH
)
find_library(BRDEC_LIB_DIR
NAMES ${find_brdename}
PATHS "${BROTLI_ROOT_DIR}"
NO_DEFAULT_PATH
)
INCLUDE_DIRECTORIES("${BROTLI_ROOT_DIR}/include")
link_directories("${BROTLI_ROOT_DIR}/lib")
if(NOT BR_LIB_DIR)
message(FATAL_ERROR
"Brotli Library NOT FOUND! please install . "
)
endif()
message(STATUS "Brotli at: ${BR_LIB_DIR}")
target_link_libraries(paozhu ${BR_LIB_DIR})
if(NOT BRDEC_LIB_DIR)
message(FATAL_ERROR
"Brotli Library NOT FOUND! please install . "
)
endif()
message(STATUS "Brotli at: ${BRDEC_LIB_DIR}")
target_link_libraries(paozhu ${BRDEC_LIB_DIR})
message("Compile framework mode")
target_link_libraries(paozhu m dl)
endif ()
if (CMAKE_SYSTEM_NAME MATCHES "Windows")
target_link_libraries(paozhu ws2_32)
target_link_libraries(paozhu_cli ws2_32)
endif ()