-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
121 lines (98 loc) · 4.1 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
cmake_minimum_required(VERSION 3.5)
# 添加版本号
set(MO_VERSION_MAJOR 0) # 主版本号
set(MO_VERSION_MINOR 0) # 子版本号
set(MO_VERSION_PATCH 1) # 阶段版本号
string(TIMESTAMP MO_VERSION_TIME %y%m%d) # 日期版本号
set(MO_VERSION_ALPHABET "alpha") # 希腊字母版本号
set(MO_VERSION ${MO_VERSION_MAJOR}.${MO_VERSION_MINOR}.${MO_VERSION_PATCH}.${MO_VERSION_TIME})
# 工程名称
project(pluginbase VERSION ${MO_VERSION})
message(STATUS "${PROJECT_NAME} v${MO_VERSION}")
option(USE_THIRD_PARTY_LIBS "Use of third party libraries" ON)
# 加入一个配置头文件,用于处理 CMake 对源码的设置
configure_file(
"${PROJECT_SOURCE_DIR}/config.h.in"
"${PROJECT_BINARY_DIR}/config.h"
)
# 设置输出路径
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) # 静态库的文件夹位置
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) # 动态库的文件夹位置
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}) # 可执行软件的文件夹位置
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
# 这个就是定义各个版本对应的后缀,例如d,debug版本后缀
set(CMAKE_DEBUG_POSTFIX "d")
set(CMAKE_RELEASE_POSTFIX "")
set(CMAKE_RELWITHDEBINFO_POSTFIX "rd")
set(CMAKE_MINSIZEREL_POSTFIX "s")
INCLUDE_DIRECTORIES(${PROJECT_BINARY_DIR})
add_definitions(-DNODE_EDITOR_SHARED)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(USE_THIRD_PARTY_LIBS)
add_subdirectory(3rdparty)
else()
include_directories("./include/")
endif()
# qt
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets) # 识别是Qt6还是Qt5
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
message(STATUS "QT_VERSION : ${QT_VERSION}, QT_DIR : ${QT_DIR}")
file(GLOB_RECURSE CPP_SOURCE_FILES src/*.cpp src/*.cxx src/*.cc)
file(GLOB_RECURSE CPP_INCLUDE_FILES src/*.hpp src/*.h)
file(GLOB_RECURSE RESOURCES src/*.qrc src/*.rc)
set(PROJECT_SOURCES ${CPP_SOURCE_FILES} ${CPP_INCLUDE_FILES} ${RESOURCES})
add_library(${PROJECT_NAME} SHARED ${PROJECT_SOURCES})
# 支持动态库和静态库同时存在
set_target_properties(${PROJECT_NAME} PROPERTIES CLEAN_DIRECT_OUTPUT 1)
target_include_directories(${PROJECT_NAME}
PUBLIC
$<INSTALL_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/models>
)
if(USE_THIRD_PARTY_LIBS)
target_link_libraries(${PROJECT_NAME}
PRIVATE
QtNodes
Qt${QT_VERSION_MAJOR}::Widgets
)
else()
target_link_libraries(${PROJECT_NAME}
PRIVATE
debug "${CMAKE_CURRENT_SOURCE_DIR}/lib/QtNodesd.lib"
optimized "${CMAKE_CURRENT_SOURCE_DIR}/lib/QtNodes.lib"
Qt${QT_VERSION_MAJOR}::Widgets
)
endif()
target_compile_options(${PROJECT_NAME}
PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4 /wd4127 /EHsc /utf-8>
$<$<C_COMPILER_ID:MSVC>:/utf-8>
$<$<CXX_COMPILER_ID:GNU>:-Wall -Wextra>
$<$<CXX_COMPILER_ID:AppleClang>:-Wall -Wextra -Werror>
)
if(NOT "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
# Clang-Cl on MSVC identifies as "Clang" but behaves more like MSVC:
target_compile_options(${PROJECT_NAME}
PRIVATE
$<$<CXX_COMPILER_ID:Clang>:-Wall -Wextra>
)
endif()
install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION CMAKE_RUNTIME_OUTPUT_DIRECTORY
LIBRARY DESTINATION CMAKE_LIBRARY_OUTPUT_DIRECTORY
ARCHIVE DESTINATION CMAKE_ARCHIVE_OUTPUT_DIRECTORY
BUNDLE DESTINATION CMAKE_RUNTIME_OUTPUT_DIRECTORY
)