forked from owent/libcopp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
executable file
·159 lines (128 loc) · 5.58 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
cmake_minimum_required(VERSION 3.7.0)
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.13")
cmake_policy(SET CMP0074 NEW)
endif()
enable_testing()
project(libcopp C CXX ASM)
set(LIBCOPP_VERSION_MAJOR "1")
set(LIBCOPP_VERSION_MINOR "3")
set(LIBCOPP_VERSION_PATCH "0")
set(LIBCOPP_VERSION "${LIBCOPP_VERSION_MAJOR}.${LIBCOPP_VERSION_MINOR}.${LIBCOPP_VERSION_PATCH}")
########################################################################
# CMake 模块 (递归包含模块, 带颜色输出模块, 平台检测模块)
set (PROJECT_CMAKE_MODULE_DIR "${CMAKE_CURRENT_LIST_DIR}/project/cmake")
include("${PROJECT_CMAKE_MODULE_DIR}/ProjectBuildOption.cmake")
include("${PROJECT_CMAKE_MODULE_DIR}/IncludeDirectoryRecurse.cmake")
include("${PROJECT_CMAKE_MODULE_DIR}/EchoWithColor.cmake")
include("${PROJECT_CMAKE_MODULE_DIR}/FindPlatform.cmake")
include("${PROJECT_CMAKE_MODULE_DIR}/ProjectTools.cmake")
#####################################################################
# 导入编译器和编译选项配置
include("${PROJECT_CMAKE_MODULE_DIR}/CompilerOption.cmake")
include("${PROJECT_CMAKE_MODULE_DIR}/TargetOption.cmake")
EchoWithColor(COLOR GREEN "-- Build Type: ${CMAKE_BUILD_TYPE}")
########################################################################
# 导入项目配置
unset (PROJECT_LIBCOPP_SYSLIB_LINK_NAMES)
## 导入所有 macro 定义
include("${CMAKE_CURRENT_LIST_DIR}/include/include.macro.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/src/libcopp.macro.cmake")
# feature detect
include(WriteCompilerDetectionHeader)
if (NOT EXISTS "${PROJECT_LIBCOPP_ROOT_INC_DIR}/libcopp/utils/config")
file(MAKE_DIRECTORY "${PROJECT_LIBCOPP_ROOT_INC_DIR}/libcopp/utils/config")
endif()
# generate check header
write_compiler_detection_header(
FILE "${PROJECT_LIBCOPP_ROOT_INC_DIR}/libcopp/utils/config/compiler_features.h"
PREFIX UTIL_CONFIG
COMPILERS GNU Clang AppleClang MSVC
FEATURES cxx_auto_type cxx_constexpr cxx_decltype cxx_decltype_auto cxx_defaulted_functions cxx_deleted_functions cxx_final cxx_override cxx_range_for cxx_noexcept cxx_nullptr cxx_rvalue_references cxx_static_assert cxx_thread_local cxx_variadic_templates cxx_lambdas
)
if (LIBCOTASK_ENABLE)
set(LIBCOTASK_MACRO_ENABLED 1)
endif ()
if (LIBCOTASK_AUTO_CLEANUP_MANAGER)
set(LIBCOTASK_MACRO_AUTO_CLEANUP_MANAGER 1)
endif ()
unset(LIBCOPP_SPECIFY_CXX_FLAGS)
find_package(Threads)
if (CMAKE_USE_PTHREADS_INIT)
list(APPEND PROJECT_LIBCOPP_SYSLIB_LINK_NAMES pthread)
set(THREAD_TLS_USE_PTHREAD 1)
if (THREADS_PREFER_PTHREAD_FLAG)
list(APPEND LIBCOPP_SPECIFY_CXX_FLAGS ${THREADS_PREFER_PTHREAD_FLAG})
add_compile_options(${THREADS_PREFER_PTHREAD_FLAG})
endif ()
endif ()
configure_file(
"${PROJECT_LIBCOPP_ROOT_INC_DIR}/libcopp/utils/config/libcopp_build_features.h.in"
"${PROJECT_LIBCOPP_ROOT_INC_DIR}/libcopp/utils/config/libcopp_build_features.h"
@ONLY
)
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
get_filename_component(CMAKE_CXX_COMPILER_WE ${CMAKE_CXX_COMPILER} NAME_WE CACHE)
if (NOT ${CMAKE_CXX_COMPILER_WE} STREQUAL "clang-cl")
if (COMPILER_STRICT_EXTRA_CFLAGS)
list(APPEND LIBCOPP_SPECIFY_CXX_FLAGS ${COMPILER_STRICT_EXTRA_CFLAGS})
endif ()
if (COMPILER_STRICT_CFLAGS)
list(APPEND LIBCOPP_SPECIFY_CXX_FLAGS ${COMPILER_STRICT_CFLAGS})
endif ()
endif ()
else ()
if (COMPILER_STRICT_EXTRA_CFLAGS)
list(APPEND LIBCOPP_SPECIFY_CXX_FLAGS ${COMPILER_STRICT_EXTRA_CFLAGS})
endif ()
if (COMPILER_STRICT_CFLAGS)
list(APPEND LIBCOPP_SPECIFY_CXX_FLAGS ${COMPILER_STRICT_CFLAGS})
endif ()
endif ()
string(REPLACE ";" " " LIBCOPP_SPECIFY_CXX_FLAGS "${LIBCOPP_SPECIFY_CXX_FLAGS}")
if (LIBCOPP_SPECIFY_CXX_FLAGS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LIBCOPP_SPECIFY_CXX_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBCOPP_SPECIFY_CXX_FLAGS}")
endif()
## 导入所有工程项目
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/src")
if (_VALGRIND_EXECUTABLE)
EchoWithColor(COLOR GREEN "-- Memcheck: valgrind found at ${_VALGRIND_EXECUTABLE}, enable target 'memcheck'")
add_custom_target(memcheck)
add_custom_target(callgrind)
endif()
if(PROJECT_ENABLE_SAMPLE)
add_custom_target(benchmark)
add_custom_target(run_sample)
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/sample")
endif()
if(PROJECT_ENABLE_UNITTEST)
add_custom_target(run_test)
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/test")
endif()
## 生成文档和导入配置
# Install configuration
set(CMAKE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake" CACHE STRING "Directory relative to CMAKE_INSTALL to install the cmake configuration files")
configure_file(
"${CMAKE_CURRENT_LIST_DIR}/docs/libcopp.doxyfile.in" "${CMAKE_CURRENT_LIST_DIR}/docs/libcopp.doxyfile"
@ONLY
NEWLINE_STYLE CRLF
)
include(CMakePackageConfigHelpers)
set(INCLUDE_INSTALL_DIR include)
file(MAKE_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/cmake")
configure_package_config_file(
"${CMAKE_CURRENT_LIST_DIR}/libcopp-config.cmake.in"
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/cmake/libcopp-config.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_CMAKEDIR}
PATH_VARS LIBCOPP_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/libcopp-config-version.cmake"
VERSION ${LIBCOPP_VERSION}
COMPATIBILITY SameMajorVersion
)
install(
FILES "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/cmake/libcopp-config.cmake" "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/cmake/libcopp-config-version.cmake"
DESTINATION ${CMAKE_INSTALL_CMAKEDIR}
)