-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
164 lines (145 loc) · 5.34 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
cmake_minimum_required(VERSION 3.16)
# 获取版本信息
file(READ ${CMAKE_SOURCE_DIR}/version aFunVersion)
file(READ ${CMAKE_SOURCE_DIR}/version-info aFunDescription)
project(aFun
VERSION ${aFunVersion}
DESCRIPTION ${aFunDescription}
LANGUAGES C CXX)
# CMake系统的相关设定
set(CMAKE_C_STANDARD 11)
set(C_EXTENSIONS OFF) # 启动编译器拓展
set(C_STANDARD_REQUIRED OFF)
set(CMAKE_CXX_STANDARD 20)
set(CXX_EXTENSIONS OFF) # 启动编译器拓展
set(CXX_STANDARD_REQUIRED OFF)
set(BUILD_SHARED_LIBS OFF) # 默认编译静态库 (该设定不可被修改)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Build type.")
if(CMAKE_BUILD_TYPE EQUAL Debug AND CMAKE_BUILD_TYPE EQUAL Release)
message(WARNING "Unknown build type.")
endif()
# 系统检查
include(CheckCCompilerFlag)
check_c_compiler_flag("-fPIC" fpic_enable) # 检查是否有fPIC选项
if (fpic_enable)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
endif()
unset(fpic_enable)
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-fPIC" fpic_enable) # 检查是否有fPIC选项
if (fpic_enable)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
endif()
unset(fpic_enable)
if (MSVC)
if(CMAKE_BUILD_TYPE EQUAL Debug)
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} /Debug /W4 /wd4251 /wd4275")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Debug /W4 /wd4251 /wd4275")
else()
set(CMAKE_C_FLAGS "/DWIN32 /D_WINDOWS /W4 /wd4251 /wd4275")
set(CMAKE_CXX_FLAGS "/DWIN32 /D_WINDOWS /GR /EHsc /W4 /wd4251 /wd4275")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /utf-8")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8")
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexec-charset=UTF-8 -Wall -Wextra -pedantic")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexec-charset=UTF-8 -Wall -Wextra -pedantic")
endif()
# 相关参数
set(PRINT_DIR_INFO ON CACHE BOOL "Print install and build dirs info.")
set(_print_dir ${PRINT_DIR_INFO})
include(tool)
include(directory)
if (_print_dir)
set(PRINT_DIR_INFO OFF CACHE BOOL "Print install and build dirs info." FORCE)
wi_set_install_dir(NAMES aFunlang) # 设置安装路径
else()
wi_set_install_dir_quiet(NAMES aFunlang) # 设置安装路径
endif()
include(filename)
# CMake对象属性的初始化值的相关设定
set(CMAKE_INSTALL_RPATH
"${CMAKE_INSTALL_PREFIX}/${INSTALL_LIBDIR}"
"${CMAKE_INSTALL_PREFIX}/${deps_install_dir}/${INSTALL_LIBDIR}") # INSTALL_RPATH 初始化值
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(CMAKE_MACOSX_RPATH TRUE)
include_directories(${CMAKE_SOURCE_DIR}/include ${CMAKE_BINARY_DIR}/${INSTALL_INCLUDEDIR}) # 添加默认的include路径
add_subdirectory(deps) # 安装依赖
include(deps) # 查找依赖
if (NOT DEPS_FOUND)
return()
endif()
#include(${CMAKE_CURRENT_LIST_DIR}/lang/hgt.cmake) # 安装lang库
add_subdirectory(src)
include(export_head)
#install(EXPORT aFunlang
# NAMESPACE "aFunlang::"
# DESTINATION ${INSTALL_CMAKEDIR}
# COMPONENT dev)
#
#include(CMakePackageConfigHelpers)
#write_basic_package_version_file(${CMAKE_BINARY_DIR}/cmake-tmp/aFunlangConfigVersion.cmake
# VERSION ${aFunVersion}
# COMPATIBILITY SameMinorVersion)
#
## 生成Config.cmake文件
#set(INSTALL_DIR ${CMAKE_INSTALL_PREFIX})
#set(BINDIR ${INSTALL_BINDIR})
#set(LIBDIR ${INSTALL_LIBDIR})
#set(CMAKEDIR ${INSTALL_CMAKEDIR})
#set(INCLUDEDIR ${INSTALL_INCLUDEDIR})
#
#if (MSVC)
# set(pthread_INSTALL_DIR ${deps_install_dir})
# set(pthread_CMAKEDIR pthread_cmake)
# set(path_var pthread_INSTALL_DIR pthread_CMAKEDIR)
#else()
# set(path_var)
#endif()
#if (WIN32 AND NOT CYGWIN) # cygwin 不需要编译 dl
# foreach(tgt dlfcn pcre2 fflags)
# set(${tgt}_INSTALL_DIR ${deps_install_dir})
# set(${tgt}_CMAKEDIR ${deps_install_dir}/${${tgt}_cmake})
# list(APPEND path_var ${tgt}_INSTALL_DIR ${tgt}_CMAKEDIR)
# endforeach()
#else()
# foreach(tgt pcre2 fflags)
# set(${tgt}_INSTALL_DIR ${deps_install_dir})
# set(${tgt}_CMAKEDIR ${deps_install_dir}/${${tgt}_cmake})
# list(APPEND path_var ${tgt}_INSTALL_DIR ${tgt}_CMAKEDIR)
# endforeach()
#
# set(dlfcn_INSTALL_DIR \"\") # 空字符串
# set(dlfcn_CMAKEDIR \"\") # 空字符串
#endif()
#
#configure_package_config_file(${PROJECT_SOURCE_DIR}/cmake/aFunlangConfig.cmake.in
# ${CMAKE_BINARY_DIR}/cmake-tmp/aFunlangConfig.cmake
# INSTALL_DESTINATION ${INSTALL_CMAKEDIR}
# PATH_VARS INSTALL_DIR BINDIR LIBDIR CMAKEDIR INCLUDEDIR ${path_var}
# INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}) # 指定安装目录 (用于生成相对路径)
#unset(INSTALL_DIR)
#unset(BINDIR)
#unset(LIBDIR)
#unset(CMAKEDIR)
#unset(INCLUDEDIR)
#foreach(tgt dlfcn pcre2 fflags)
# unset(${tgt}_INSTALL_DIR)
# unset(${tgt}_CMAKEDIR)
#endforeach()
#unset(path_var)
#
#install(FILES
# ${CMAKE_BINARY_DIR}/cmake-tmp/aFunlangConfig.cmake
# ${CMAKE_BINARY_DIR}/cmake-tmp/aFunlangConfigVersion.cmake
# DESTINATION ${INSTALL_CMAKEDIR})
#
set(BUILD_TEST FALSE CACHE BOOL "Enable run test program")
set(_build_test ${BUILD_TEST})
if (_build_test)
enable_testing()
endif()
add_subdirectory(test) # test的相关内容仍会被构建
#
include(info)