-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
93 lines (81 loc) · 2.95 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
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules")
project(proj VERSION 0.1.0.0)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/bin")
set(THIRDPARTY_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/3rdparty")
set(THIRDPARTY_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/deps")
# ccache
find_program(CCACHE_FOUND ccache)
if(CCACHE_FOUND)
message(STATUS "Found CCache")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
endif(CCACHE_FOUND)
set(CMAKE_CXX_STANDARD 20)
# always generate PIC code, no matter static or shared library
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# dependencies
# boost
find_package(Boost REQUIRED COMPONENTS ALL)
message(STATUS "${Boost_LIBRARIES}")
add_library(depends::boost INTERFACE IMPORTED GLOBAL)
target_link_libraries(depends::boost INTERFACE Boost::boost Boost::json Boost::url)
# spdlog
find_package(spdlog REQUIRED)
add_library(depends::spdlog INTERFACE IMPORTED GLOBAL)
target_link_libraries(depends::spdlog INTERFACE spdlog::spdlog)
# zlib
find_package(ZLIB REQUIRED)
add_library(depends::zlib INTERFACE IMPORTED GLOBAL)
target_link_libraries(depends::zlib INTERFACE ZLIB::ZLIB)
# openssl
if(APPLE AND NOT DEFINED ENV{OPENSSL_ROOT_DIR})
find_program(HOMEBREW brew)
if(NOT HOMEBREW STREQUAL "HOMEBREW-NOTFOUND")
execute_process(
COMMAND brew --prefix openssl OUTPUT_VARIABLE OPENSSL_ROOT_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
endif()
find_package(OpenSSL REQUIRED)
add_library(depends::openssl INTERFACE IMPORTED GLOBAL)
target_link_libraries(depends::openssl INTERFACE OpenSSL::SSL OpenSSL::Crypto)
if(WIN32)
target_link_libraries(depends::openssl INTERFACE ws2_32)
endif()
# threads
find_package(Threads REQUIRED)
add_library(depends::threads INTERFACE IMPORTED GLOBAL)
target_link_libraries(depends::threads INTERFACE Threads::Threads)
# options
option(PROJ_OPTION "..." ON)
configure_file(cmake/version.h.in include/version.h)
file(GLOB_RECURSE PROJ_CORE_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
# message(STATUS ${PROJ_CORE_SOURCE_FILES})
add_library(proj-core)
target_sources(proj-core PRIVATE ${PROJ_CORE_SOURCE_FILES})
target_include_directories(proj-core
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_BINARY_DIR}/include
)
target_link_libraries(proj-core
PUBLIC
depends::boost
depends::spdlog
depends::zlib
depends::openssl
depends::threads
)
# if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# target_compile_options(proj-core PUBLIC -stdlib=libc++)
# target_link_options(proj-core PUBLIC -stdlib=libc++)
# elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
# target_compile_definitions(
# proj-core PUBLIC BOOST_ALL_NO_LIB _CRT_SECURE_NO_WARNINGS
# _WIN32_WINNT=0x0601
# )
# target_compile_options(proj-core PUBLIC /bigobj /O2)
# endif()
add_subdirectory(utils)