-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
104 lines (89 loc) · 3.43 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
cmake_minimum_required(VERSION 3.12)
project(QtStudy)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# cmake modules
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
include(${PROJECT_SOURCE_DIR}/cmake/CMakeHelper.cmake)
###############################################################################
# Options
###############################################################################
# Qt folder
if(UNIX)
option(UseSystemQt "Use Qt in system" ON)
if(NOT ${UseSystemQt})
set(QtFolder "/opt;$ENV{HOME}/Programs;$ENV{HOME}/opt" CACHE PATH "Qt install folder")
else()
set(QtFolder "/usr/lib/x86_64-linux-gnu/cmake" CACHE PATH "Qt system folder")
endif()
elseif(WIN32)
set(QtFolder "D:/Programs/Qt" CACHE PATH "Qt install folder")
endif()
# set cmake path for windows
if(WIN32)
set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH};D:/usr/lib/cmake")
endif()
###############################################################################
# Libraries
###############################################################################
# setting before find libraries
FindAddQtPath(${QtFolder})
# find packages
find_package(Gflags REQUIRED) # gflags
find_package(Glog REQUIRED) # glog
find_package(fmt REQUIRED) # fmt
# dependency include directories and dependency libraries
list(APPEND DEPEND_INCLUDES
${GFLAGS_INCLUDE_DIRS}
${GLOG_INCLUDE_DIRS}
)
list(APPEND DEPEND_LIBS
${GFLAGS_LIBRARIES}
${GLOG_LIBRARIES}
fmt::fmt-header-only
)
# Qt
find_package(QT NAMES Qt6 Qt5 COMPONENTS Core)
message(STATUS "Qt Version: ${QT_VERSION}")
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Widgets Gui Qml Quick OpenGL OpenGLWidgets Network Charts
PrintSupport
REQUIRED
)
list(APPEND DEPEND_LIBS Qt::Core Qt::Widgets Qt::Qml Qt::Quick Qt::OpenGL Qt::OpenGLWidgets Qt::Network Qt::Charts
Qt::PrintSupport
)
else()
find_package(Qt5 COMPONENTS Core Widgets Gui Qml Quick OpenGL Network Charts PrintSupport REQUIRED)
list(APPEND DEPEND_LIBS Qt::Core Qt::Widgets Qt::Gui Qt::Qml Qt::Quick Qt::OpenGL Qt::Network Qt::Charts
Qt::PrintSupport
)
endif()
###############################################################################
# Project Setting
###############################################################################
# default built type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RELEASE)
endif()
message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
# build setting
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Qt build setting
set(CMAKE_AUTOMOC ON) # instruct cmake to run moc automacically when needed
set(CMAKE_AUTOUIC ON) # create code from a list of Qt designer ui files
set(CMAKE_AUTORCC ON) # create code from a resource files
###############################################################################
# Project
###############################################################################
# third party
list(APPEND DEPEND_INCLUDES
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/QCustomPlot/include
${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/ads/include
)
add_subdirectory(3rdparty)
# add modules
add_subdirectory(modules)