-
Notifications
You must be signed in to change notification settings - Fork 63
/
CMakeLists.txt
executable file
·128 lines (104 loc) · 4.55 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
cmake_minimum_required(VERSION 3.16.0)
cmake_policy(SET CMP0022 NEW)
cmake_policy(SET CMP0048 NEW)
cmake_policy(SET CMP0054 NEW)
cmake_policy(SET CMP0067 NEW)
cmake_policy(SET CMP0074 NEW)
cmake_policy(SET CMP0077 NEW)
cmake_policy(SET CMP0091 NEW)
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.19.0")
cmake_policy(SET CMP0111 NEW)
endif()
# MSVC RTTI flag /GR should not be not added to CMAKE_CXX_FLAGS by default. @see
# https://cmake.org/cmake/help/latest/policy/CMP0117.html
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.20.0")
cmake_policy(SET CMP0117 NEW)
endif()
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.22.0")
cmake_policy(SET CMP0128 NEW)
endif()
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.27.0")
cmake_policy(SET CMP0144 NEW)
endif()
enable_testing()
project(
libatbus
VERSION "2.3.1"
HOMEPAGE_URL "https://github.com/atframework/libatbus"
LANGUAGES C CXX)
if(NOT DEFINED __COMPILER_OPTION_LOADED)
if(MSVC)
string(REGEX REPLACE "/EHsc" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REGEX REPLACE "/GR-?" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
else()
string(REGEX REPLACE "-f(no-)?exceptions" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REGEX REPLACE "-f(no-)?rtti" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
endif()
endif()
set(LIBATBUS_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}")
set(LIBATBUS_VERSION_MINOR "${PROJECT_VERSION_MINOR}")
set(LIBATBUS_VERSION_PATCH "${PROJECT_VERSION_PATCH}")
set(LIBATBUS_VERSION "${PROJECT_VERSION}")
include("${CMAKE_CURRENT_LIST_DIR}/project/cmake/ProjectBuildOption.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/third_party/Repository.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/atframework/Repository.cmake")
unset(PROJECT_LIBATBUS_PRIVATE_COMPILE_OPTIONS)
# ######################################################################################################################
# 导入项目配置 导入所有 macro 定义
include("${CMAKE_CURRENT_LIST_DIR}/include/include.macro.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/src/libatbus.macro.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/tools/tools.macro.cmake")
# 导入工程项目
set(PROJECT_LIBATBUS_PUBLIC_LINK_NAMES
${ATFRAMEWORK_ATFRAME_UTILS_LINK_NAME} ${ATFRAMEWORK_CMAKE_TOOLSET_THIRD_PARTY_PROTOBUF_LINK_NAME}
${ATFRAMEWORK_CMAKE_TOOLSET_THIRD_PARTY_LIBUV_LINK_NAME})
if(COMPILER_STRICT_EXTRA_CFLAGS)
list(APPEND PROJECT_LIBATBUS_PRIVATE_COMPILE_OPTIONS ${COMPILER_STRICT_EXTRA_CFLAGS})
endif()
if(COMPILER_STRICT_CFLAGS)
list(APPEND PROJECT_LIBATBUS_PRIVATE_COMPILE_OPTIONS ${COMPILER_STRICT_CFLAGS})
endif()
if(COMPILER_STRICT_RECOMMEND_EXTRA_CFLAGS)
list(APPEND PROJECT_LIBATBUS_PRIVATE_COMPILE_OPTIONS ${COMPILER_STRICT_RECOMMEND_EXTRA_CFLAGS})
endif()
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/src")
if(PROJECT_ENABLE_SAMPLE)
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/sample")
endif()
if(PROJECT_ENABLE_UNITTEST OR BUILD_TESTING)
atframework_atframe_utils_populate()
include("${ATFRAMEWORK_ATFRAME_UTILS_REPO_DIR}/test/test.utils-macro.cmake")
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/test")
endif()
if(PROJECT_ENABLE_TOOLS)
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/tools")
endif()
# 生成文档和导入配置
# Install configuration
set(CMAKE_INSTALL_CMAKEDIR
"${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
CACHE STRING "Directory relative to CMAKE_INSTALL to install the cmake configuration files")
include(CMakePackageConfigHelpers)
set(INCLUDE_INSTALL_DIR include)
file(MAKE_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/cmake/${PROJECT_NAME}")
configure_package_config_file(
"${CMAKE_CURRENT_LIST_DIR}/libatbus-config.cmake.in"
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/cmake/${PROJECT_NAME}/libatbus-config.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_CMAKEDIR}
PATH_VARS LIBATBUS_VERSION INCLUDE_INSTALL_DIR CMAKE_INSTALL_LIBDIR PROJECT_SOURCE_DIR
NO_CHECK_REQUIRED_COMPONENTS_MACRO)
write_basic_package_version_file(
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/cmake/${PROJECT_NAME}/libatbus-config-version.cmake"
VERSION ${LIBATBUS_VERSION}
COMPATIBILITY SameMajorVersion)
install(FILES "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/cmake/${PROJECT_NAME}/libatbus-config.cmake"
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/cmake/${PROJECT_NAME}/libatbus-config-version.cmake"
DESTINATION ${CMAKE_INSTALL_CMAKEDIR})
export(
EXPORT ${PROJECT_LIBATBUS_EXPORT_NAME}
NAMESPACE atframework::
FILE "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/cmake/${PROJECT_NAME}/${PROJECT_LIBATBUS_EXPORT_NAME}.cmake")
install(
EXPORT ${PROJECT_LIBATBUS_EXPORT_NAME}
NAMESPACE "atframework::"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")