forked from owent/libcopp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
executable file
·115 lines (91 loc) · 3.88 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
cmake_minimum_required(VERSION 3.7.0)
enable_testing()
project(libcopp C CXX ASM)
set(LIBCOPP_VERSION_MAJOR "1")
set(LIBCOPP_VERSION_MINOR "1")
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}")
########################################################################
# 导入项目配置
## 导入所有 macro 定义
include_macro_recurse(${CMAKE_CURRENT_LIST_DIR})
# 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 (PROJECT_DISABLE_MT)
set(PROJECT_DISABLE_MT 1)
else()
unset(PROJECT_DISABLE_MT)
endif()
if (LIBCOTASK_ENABLE)
set(LIBCOTASK_MACRO_ENABLED 1)
endif ()
configure_file(
"${PROJECT_LIBCOPP_ROOT_INC_DIR}/libcopp/utils/config/build_feature.h.in"
"${PROJECT_LIBCOPP_ROOT_INC_DIR}/libcopp/utils/config/build_feature.h"
@ONLY
)
## 导入所有工程项目
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()
## 生成文档和导入配置
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)
set(LIB_INSTALL_DIR "lib${PLATFORM_SUFFIX}")
file(MAKE_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/cmake")
configure_package_config_file(
"${CMAKE_CURRENT_LIST_DIR}/LibcoppConfig.cmake.in"
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/cmake/LibcoppConfig.cmake"
INSTALL_DESTINATION "lib${PLATFORM_SUFFIX}/cmake"
PATH_VARS LIBCOPP_VERSION INCLUDE_INSTALL_DIR LIB_INSTALL_DIR PROJECT_SOURCE_DIR
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
write_basic_package_version_file(
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/cmake/LibcoppConfigVersion.cmake"
VERSION ${LIBCOPP_VERSION}
COMPATIBILITY SameMajorVersion
)
install(
FILES "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/cmake/LibcoppConfig.cmake" "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/cmake/LibcoppConfigVersion.cmake"
DESTINATION "lib${PLATFORM_SUFFIX}/cmake"
)