-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
68 lines (55 loc) · 1.94 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
# 要求最低Cmake版本
cmake_minimum_required(VERSION 3.15.0)
# 项目名称
set(UseProjectName "endecode")
project(${UseProjectName})
# C++标准
set(CMAKE_CXX_STANDARD 11)
# 条件编译
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
add_compile_options("/utf-8")
elseif()
endif()
# 开启使用文件夹功能,将所有默认目标放入到名为 CMakePredefinedTargets 的文件夹中
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMakePredefinedTargets")
# 设置根目录
set(ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(BUILD_DIR ${CMAKE_BINARY_DIR})
# 为多种构建类型设置输出目录
set(CONFIGURATION_TYPES "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
foreach(CONFIGURATION_TYPE ${CONFIGURATION_TYPES})
string(TOUPPER ${CONFIGURATION_TYPE} TYPE)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${TYPE} ${BUILD_DIR}/lib) # .lib and .a
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${TYPE} ${BUILD_DIR}/lib) # .so and .dylib
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${TYPE} ${BUILD_DIR}/bin) # .exe and .dll
endforeach()
# 后缀
set(CMAKE_RELEASE_POSTFIX "")
set(CMAKE_DEBUG_POSTFIX "d")
set(CMAKE_MINSIZEREL_POSTFIX "m")
set(CMAKE_RELWITHDEBINFO_POSTFIX "rd")
# 选项
option(BUILD_SINGLE_LIBRARY "Build as a single shared library" OFF)
option(BUILD_VCPKG "Build use vcpkg" OFF)
option(BUILD_TEST "Build test executable" OFF)
# vcpkg
if(BUILD_VCPKG)
include(${ROOT_DIR}/cmake/module_vcpkg.cmake)
add_compile_definitions(ENABLE_GMP)
endif(BUILD_VCPKG)
# 算法库
include(${ROOT_DIR}/cmake/module.cmake)
add_subdirectory(src)
# 测试程序
if(BUILD_TEST)
include(${ROOT_DIR}/cmake/module_gtest.cmake)
add_subdirectory(test)
endif()
# 拷贝资源文件
add_custom_target(
"CopyTask" ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory "${ROOT_DIR}/resources" "${BUILD_DIR}/bin/"
COMMENT "Copying resources"
)
set_property(TARGET "CopyTask" PROPERTY FOLDER "CMakePredefinedTargets")