forked from GENIVI/CANdevStudio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
205 lines (173 loc) · 5.91 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
cmake_minimum_required(VERSION 3.0.0)
project(CANdevStudio CXX)
set(VERSION_MAJOR 0)
set(VERSION_MINOR 3)
set(VERSION_PATCH 0)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 14)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
option(WITH_COVERAGE "Build with coverage" OFF)
option(WITH_TOOLS "Build tools directory" OFF)
option(DEV_BUILD "Development build will include GIT hash and branch to versioning" ON)
option(STANDALONE "Builds self containing package including Qt libs" OFF)
if(NOT CMAKE_INSTALL_LIBDIR)
set(CMAKE_INSTALL_LIBDIR lib)
endif()
message(STATUS "CMAKE_INSTALL_LIBDIR: '${CMAKE_INSTALL_LIBDIR}'")
if(UNIX)
option(WITH_TESTS "Build with test" ON)
if(STANDALONE)
set(INSTALL_DEST_LIB CANdevStudio)
set(INSTALL_DEST_BIN CANdevStudio)
set(INSTALL_DEST_PLUG CANdevStudio/canbus)
else()
set(INSTALL_DEST_LIB ${CMAKE_INSTALL_LIBDIR}/CANdevStudio)
set(INSTALL_DEST_BIN bin)
set(INSTALL_DEST_PLUG ${CMAKE_INSTALL_LIBDIR}/qt/plugins/canbus)
endif()
else()
option(WITH_TESTS "Build with test" OFF)
set(GUI_TYPE WIN32)
set(INSTALL_DEST_LIB CANdevStudio)
set(INSTALL_DEST_BIN CANdevStudio)
endif()
set(QT_REQUIRED_VERSION "5.6")
find_package(Qt5Core ${QT_REQUIRED_VERSION} REQUIRED)
find_package(Qt5SerialBus ${QT_REQUIRED_VERSION} REQUIRED)
find_package(Qt5Widgets ${QT_REQUIRED_VERSION} REQUIRED)
find_package(Qt5Test ${QT_REQUIRED_VERSION} REQUIRED)
find_package(Qt5Svg ${QT_REQUIRED_VERSION} REQUIRED)
message(STATUS "Qt Version found: ${Qt5Core_VERSION}")
set_property(TARGET Qt5::SerialBus PROPERTY INTERFACE_COMPILE_FEATURES "")
set_property(TARGET Qt5::Core PROPERTY INTERFACE_COMPILE_FEATURES "")
if(NOT MSVC)
add_definitions(-Wall -Wextra)
else()
add_definitions( /bigobj)
endif()
include(CompilerVersion)
if(WITH_COVERAGE)
include(CodeCoverage)
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_COVERAGE})
set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS_COVERAGE})
setup_target_for_coverage(NAME coverage EXECUTABLE ctest DEPENDENCIES candevice_test)
endif()
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(SPDLOG_BUILD_TESTING CACHE FORCE OFF)
set(BUILD_EXAMPLES CACHE FORCE OFF)
# Version handling
if(EXISTS "${CMAKE_SOURCE_DIR}/.git" AND DEV_BUILD)
execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND git log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
else()
set(GIT_BRANCH "")
set(GIT_COMMIT_HASH "")
endif()
message(STATUS "Git current branch: ${GIT_BRANCH}")
message(STATUS "Git commit hash: ${GIT_COMMIT_HASH}")
message(STATUS "Generating version.h")
configure_file(
${CMAKE_SOURCE_DIR}/src/common/version.h.in
${CMAKE_BINARY_DIR}/generated/version.h
)
# end of version Handling
if(WITH_TESTS OR WITH_COVERAGE)
enable_testing()
endif()
add_subdirectory(3rdParty)
add_subdirectory(src/common)
add_subdirectory(src/components)
add_subdirectory(src/gui)
if(WITH_TOOLS)
find_package(Boost COMPONENTS system filesystem REQUIRED)
add_subdirectory(tools)
endif()
if(STANDALONE)
if(UNIX)
set(SYS_LIBS
libQt5Core.so.5
libQt5Gui.so.5
libQt5Network.so.5
libQt5SerialBus.so.5
libQt5SerialPort.so.5
libQt5Svg.so.5
libQt5Widgets.so.5
libQt5OpenGL.so.5
libQt5XcbQpa.so.5
libQt5DBus.so.5
libQt5Core.so.${Qt5Core_VERSION}
libQt5Gui.so.${Qt5Core_VERSION}
libQt5Network.so.${Qt5Core_VERSION}
libQt5SerialBus.so.${Qt5Core_VERSION}
libQt5SerialPort.so.${Qt5Core_VERSION}
libQt5Svg.so.${Qt5Core_VERSION}
libQt5Widgets.so.${Qt5Core_VERSION}
libQt5OpenGL.so.${Qt5Core_VERSION}
libQt5XcbQpa.so.${Qt5Core_VERSION}
libQt5DBus.so.${Qt5Core_VERSION}
)
install(PROGRAMS files/CANdevStudio.sh DESTINATION ${INSTALL_DEST_BIN})
else()
set(SYS_LIBS
libgcc_s_dw2-1.dll
libstdc++-6.dll
libwinpthread-1.dll
Qt5Core.dll
Qt5Gui.dll
Qt5Network.dll
Qt5SerialBus.dll
Qt5SerialPort.dll
Qt5Svg.dll
Qt5Widgets.dll
)
endif()
get_target_property(QtCore_location Qt5::Core LOCATION)
get_filename_component(QtPath ${QtCore_location} DIRECTORY)
foreach(SYS_LIB ${SYS_LIBS})
set(SYS_LIBS_ABS ${SYS_LIBS_ABS} ${QtPath}/${SYS_LIB})
endforeach()
install(PROGRAMS ${SYS_LIBS_ABS}
DESTINATION ${INSTALL_DEST_LIB}
)
# execute the command "qmake -query QT_INSTALL_PLUGINS" to get the path of plugins dir.
if(NOT QT_QMAKE_EXECUTABLE)
set(QT_QMAKE_EXECUTABLE qmake)
endif()
execute_process(COMMAND ${QT_QMAKE_EXECUTABLE} -query QT_INSTALL_PLUGINS
OUTPUT_VARIABLE QT_PLUGINS_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(QT_PLUGINS_DIR)
message(STATUS "Qt5 plugin directory: " "${QT_PLUGINS_DIR}")
else()
message(WARNING "Qt5 plugin directory cannot be detected.")
if(WIN32)
set(QT_PLUGINS_DIR C:/Qt/${Qt5Core_VERSION}/mingw53_32/plugins)
message(WARNING "Setting to default Appveyor path: ${QT_PLUGINS_DIR}")
endif()
endif()
install(DIRECTORY
${QT_PLUGINS_DIR}/platforms
${QT_PLUGINS_DIR}/platforminputcontexts
${QT_PLUGINS_DIR}/imageformats
${QT_PLUGINS_DIR}/canbus
${QT_PLUGINS_DIR}/generic
${QT_PLUGINS_DIR}/iconengines
DESTINATION ${INSTALL_DEST_LIB}
USE_SOURCE_PERMISSIONS
)
endif()
include("packaging.cmake")