-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
173 lines (137 loc) · 6.33 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
165
166
167
168
169
170
171
172
173
cmake_minimum_required (VERSION 3.10)
project ("cc_mqtt311_cc_tools_qt_plugin")
# Build options:
option (OPT_WARN_AS_ERR "Treat warnings as errors" ON)
option (OPT_USE_CCACHE "Use ccache" OFF)
option (OPT_WITH_DEFAULT_SANITIZERS "Build with sanitizers" OFF)
option (OPT_INSTALL_DEFAULT_CONFIG "Install default plugin configuration" ON)
# Configuration variables:
# OPT_QT_MAJOR_VERSION - The major Qt version, defaults to 5
# OPT_CCACHE_EXECUTABLE - Custom ccache executable
######################################################################
if ("${OPT_QT_MAJOR_VERSION}" STREQUAL "")
set(OPT_QT_MAJOR_VERSION 5)
endif()
if ("${CMAKE_CXX_STANDARD}" STREQUAL "")
set(CMAKE_CXX_STANDARD 17)
endif()
if ("${CMAKE_CXX_STANDARD}" VERSION_LESS "17")
message (FATAL_ERROR "Use C++17 or later (instead of C++${CMAKE_CXX_STANDARD}) to compile this project.")
endif()
find_package(LibComms REQUIRED)
find_package(cc_mqtt311 REQUIRED)
find_package(cc_tools_qt REQUIRED)
find_package(Qt${OPT_QT_MAJOR_VERSION} REQUIRED COMPONENTS Widgets Core)
set (CMAKE_AUTOMOC ON)
set (CMAKE_AUTOUIC ON)
set (CMAKE_AUTORCC ON)
set (extra_opts)
if (OPT_WARN_AS_ERR)
list(APPEND extra_opts WARN_AS_ERR)
endif()
if (OPT_USE_CCACHE)
list(APPEND extra_opts USE_CCACHE)
if (NOT "${OPT_CCACHE_EXECUTABLE}" STREQUAL "")
list(APPEND extra_opts CCACHE_EXECUTABLE "${OPT_CCACHE_EXECUTABLE}")
endif()
endif()
if (OPT_WITH_DEFAULT_SANITIZERS)
list(APPEND extra_opts DEFAULT_SANITIZERS)
endif()
include(${LibComms_DIR}/CC_Compile.cmake)
cc_compile(${extra_opts})
cc_msvc_force_warn_opt(/W4)
include(GNUInstallDirs)
set (CORE_LIB_NAME "cc_tools_qt_plugin_cc_mqtt311_protocol_core")
######################################################################
function (cc_plugin_core)
set (name ${CORE_LIB_NAME})
set (src
cc_tools_qt_plugin/cc_mqtt311/field/BinData.cpp
cc_tools_qt_plugin/cc_mqtt311/field/Length.cpp
cc_tools_qt_plugin/cc_mqtt311/field/MsgId.cpp
cc_tools_qt_plugin/cc_mqtt311/field/PacketId.cpp
cc_tools_qt_plugin/cc_mqtt311/field/ProtocolName.cpp
cc_tools_qt_plugin/cc_mqtt311/field/Qos.cpp
cc_tools_qt_plugin/cc_mqtt311/field/String.cpp
cc_tools_qt_plugin/cc_mqtt311/field/Topic.cpp
cc_tools_qt_plugin/cc_mqtt311/message/Connack.cpp
cc_tools_qt_plugin/cc_mqtt311/message/Connect.cpp
cc_tools_qt_plugin/cc_mqtt311/message/Disconnect.cpp
cc_tools_qt_plugin/cc_mqtt311/message/Pingreq.cpp
cc_tools_qt_plugin/cc_mqtt311/message/Pingresp.cpp
cc_tools_qt_plugin/cc_mqtt311/message/Puback.cpp
cc_tools_qt_plugin/cc_mqtt311/message/Pubcomp.cpp
cc_tools_qt_plugin/cc_mqtt311/message/Publish.cpp
cc_tools_qt_plugin/cc_mqtt311/message/Pubrec.cpp
cc_tools_qt_plugin/cc_mqtt311/message/Pubrel.cpp
cc_tools_qt_plugin/cc_mqtt311/message/Suback.cpp
cc_tools_qt_plugin/cc_mqtt311/message/Subscribe.cpp
cc_tools_qt_plugin/cc_mqtt311/message/Unsuback.cpp
cc_tools_qt_plugin/cc_mqtt311/message/Unsubscribe.cpp
cc_tools_qt_plugin/cc_mqtt311/Message.cpp
cc_tools_qt_plugin/cc_mqtt311/frame/FrameTransportMessage.cpp
cc_tools_qt_plugin/cc_mqtt311/factory/AllMessagesDynMemMsgFactory.cpp
)
add_library (${name} STATIC ${src})
target_link_libraries (${name} PUBLIC cc::cc_mqtt311 cc::comms cc::cc_tools_qt Qt${OPT_QT_MAJOR_VERSION}::Widgets Qt${OPT_QT_MAJOR_VERSION}::Core)
target_include_directories (${name} PUBLIC ${PROJECT_SOURCE_DIR})
target_compile_options(${name} PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/bigobj /wd4127 /wd5054>
$<$<CXX_COMPILER_ID:GNU>:-ftemplate-depth=2048 -fconstexpr-depth=4096 -Wno-unused-local-typedefs>
$<$<CXX_COMPILER_ID:Clang>:-ftemplate-depth=2048 -fconstexpr-depth=4096 -fbracket-depth=2048 -Wno-unused-local-typedefs>
)
endfunction()
######################################################################
function (cc_plugin protocol has_config_widget)
string(TOLOWER "cc_tools_plugin_${protocol}" name)
if (NOT "${name}" MATCHES ".*_protocol$")
string(APPEND name "_protocol")
endif ()
set (meta_file "${CMAKE_CURRENT_SOURCE_DIR}/cc_tools_qt_plugin/cc_mqtt311/plugin/Plugin_${protocol}.json")
set (stamp_file "${CMAKE_CURRENT_BINARY_DIR}/${protocol}_refresh_stamp.txt")
if ((NOT EXISTS ${stamp_file}) OR (${meta_file} IS_NEWER_THAN ${stamp_file}))
execute_process(
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_SOURCE_DIR}/cc_tools_qt_plugin/cc_mqtt311/plugin/Plugin_${protocol}.h)
execute_process(
COMMAND ${CMAKE_COMMAND} -E touch ${stamp_file})
endif ()
set (src
cc_tools_qt_plugin/cc_mqtt311/plugin/Protocol_${protocol}.cpp
cc_tools_qt_plugin/cc_mqtt311/plugin/Plugin_${protocol}.cpp
cc_tools_qt_plugin/cc_mqtt311/plugin/Plugin_${protocol}.h
)
if (has_config_widget)
list (APPEND src cc_tools_qt_plugin/cc_mqtt311/plugin/ConfigWidget_${protocol}.cpp)
endif ()
set(extra_link_opts)
if (CMAKE_COMPILER_IS_GNUCC)
set(extra_link_opts "-Wl,--no-undefined")
endif ()
add_library (${name} MODULE ${src} ${moc})
target_link_libraries (${name} ${CORE_LIB_NAME} cc::cc_tools_qt Qt${OPT_QT_MAJOR_VERSION}::Widgets Qt${OPT_QT_MAJOR_VERSION}::Core ${extra_link_opts})
target_compile_options(${name} PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/bigobj /wd4127 /wd5054>
$<$<CXX_COMPILER_ID:GNU>:-ftemplate-depth=2048 -fconstexpr-depth=4096>
$<$<CXX_COMPILER_ID:Clang>:-ftemplate-depth=2048 -fconstexpr-depth=4096 -fbracket-depth=2048>
)
install (
TARGETS ${name}
DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/cc_tools_qt/plugin)
if (OPT_INSTALL_DEFAULT_CONFIG)
install (
FILES cc_tools_qt_plugin/cc_mqtt311/plugin/${protocol}.cfg
DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/cc_tools_qt)
endif()
endfunction()
######################################################################
if (TARGET cc::cc_tools_qt)
get_target_property(cc_inc cc::cc_tools_qt INTERFACE_INCLUDE_DIRECTORIES)
if (NOT cc_inc)
message (FATAL_ERROR "No include directories are specified for cc::cc_tools_qt")
endif ()
# Global include is required for "moc"
include_directories (${cc_inc})
endif ()
cc_plugin_core()
cc_plugin ("CC_MQTT_v3_1_1" FALSE)