-
Notifications
You must be signed in to change notification settings - Fork 30
/
CMakeLists.txt
172 lines (147 loc) · 5.6 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
cmake_minimum_required(VERSION 3.2)
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.9)
project (QSyncthingTray LANGUAGES CXX)
set(QSYNCTHINGTRAY_VERSION 0.5.9)
set(QSYNCTHINGTRAY_COPYRIGHT_YEARS 2015-2017)
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
find_package(Qt5 5.6 COMPONENTS Widgets Network PrintSupport)
if (NOT Qt5_FOUND)
message(FATAL_ERROR
"Some components of Qt5 not found (see above messages for details. "
"Did you set CMAKE_PREFIX_PATH ?\n"
"Example: cmake -D CMAKE_PREFIX_PATH=/my/path/to/Qt5/5.7/clang_64 .."
)
endif ()
# Fill the template with information gathered from CMake.
configure_file(includes/config.template.h config.h @ONLY)
add_definitions(-DGLEW_STATIC)
# The Qt5Widgets_INCLUDES also includes the include directories for
# dependencies QtCore and QtGui
include_directories(${Qt5Widgets_INCLUDES})
# We need add -DQT_WIDGETS_LIB when using QtWidgets in Qt 5.
add_definitions(${Qt5Widgets_DEFINITIONS})
# ____ _ _ __
# | _ \| | __ _| |_ / _| ___ _ __ _ __ ___
# | |_) | |/ _` | __| |_ / _ \| '__| '_ ` _ \
# | __/| | (_| | |_| _| (_) | | | | | | | |
# |_| |_|\__,_|\__|_| \___/|_| |_| |_| |_|
#
set(qst_platform_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/includes/platforms)
set(qst_platform_HEADERS)
if(APPLE)
set(qst_platform_HEADERS
${qst_platform_HEADERS}
${qst_platform_ROOT}/darwin/macUtils.hpp
)
elseif(WIN32)
set(qst_platform_HEADERS
${qst_platform_HEADERS}
${qst_platform_ROOT}/windows/winUtils.hpp
)
elseif(UNIX)
set(qst_platform_HEADERS
${qst_platform_HEADERS}
${qst_platform_ROOT}/linux/posixUtils.hpp
)
endif()
set(qst_platform_HEADERS
${qst_platform_HEADERS}
)
source_group("Platforms" ${qst_platform_HEADERS} ${qst_PLATFORMS_SOURCES})
# ____ _ _
# | _ \ __ _| |_| |__ ___
# | |_) / _` | __| '_ \/ __|
# | __/ (_| | |_| | | \__ \
# |_| \__,_|\__|_| |_|___/
#
if (WIN32)
set(ICON_FILE "resources/windows_metafile.rc")
set(CMAKE_RC_COMPILER_INIT windres)
ENABLE_LANGUAGE(RC)
SET(CMAKE_RC_COMPILE_OBJECT "<CMAKE_RC_COMPILER> <FLAGS> -O coff <DEFINES> -i <SOURCE> -o <OBJECT>")
endif()
# qt5_wrap_ui(UI_HEADERS mainwindow.ui)
qt5_add_resources(UI_RESOURCES
resources/qsyncthing.qrc
resources/qsyncthingblueanim.qrc
resources/qsyncthingdarkanim.qrc)
include_directories(includes)
add_subdirectory(includes)
add_subdirectory(sources)
if(APPLE)
set(ICON_FILE resources/Syncthing.icns)
set_source_files_properties(${ICON_FILE} PROPERTIES
MACOSX_PACKAGE_LOCATION Resources)
FIND_LIBRARY(COCOA_LIBRARY Cocoa)
add_executable(QSyncthingTray MACOSX_BUNDLE ${ICON_FILE} ${UI_HEADERS} ${UI_RESOURCES}
${qst_platform_HEADERS} ${qst_PLATFORMS_SOURCES} ${qst_HEADERS} ${qst_SOURCES})
# Fill the Info.plist template with information gathered from CMake and
# copy it into the bundle.
set_target_properties(QSyncthingTray PROPERTIES
MACOSX_BUNDLE_INFO_PLIST ${PROJECT_SOURCE_DIR}/resources/Info.template.plist)
elseif(WIN32)
add_executable(QSyncthingTray WIN32 ${ICON_FILE} ${UI_HEADERS} ${UI_RESOURCES} ${qst_platform_HEADERS} ${qst_HEADERS} ${qst_SOURCES})
elseif(UNIX)
add_executable(QSyncthingTray ${UI_HEADERS} ${UI_RESOURCES} ${qst_platform_HEADERS} ${qst_HEADERS} ${qst_SOURCES})
endif()
if (APPLE)
target_link_libraries(
QSyncthingTray
${Qt5Core_QTMAIN_LIBRARIES}
${COCOA_LIBRARY}
Qt5::PrintSupport)
else()
target_link_libraries(
QSyncthingTray
${Qt5Core_QTMAIN_LIBRARIES}
Qt5::PrintSupport)
endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set_target_properties(QSyncthingTray PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:WINDOWS")
set_target_properties(QSyncthingTray PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS")
target_link_libraries(QSyncthingTray ${Qt5Widgets_LIBRARIES} Qt5::Widgets)
get_target_property(QtCore_location Qt5::Core LOCATION)
endif(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
if (${QST_BUILD_WEBKIT})
target_link_libraries(QSyncthingTray Qt5::Widgets Qt5::Network Qt5::WebKitWidgets)
target_compile_definitions(QSyncthingTray PRIVATE BUILD_WEBKIT=1)
elseif (${QST_BUILD_NATIVEBROWSER})
target_link_libraries(QSyncthingTray Qt5::Widgets Qt5::Network)
target_compile_definitions(QSyncthingTray PRIVATE BUILD_NATIVEBROWSER=1)
else()
find_package(Qt5 REQUIRED COMPONENTS WebEngineWidgets)
target_link_libraries(QSyncthingTray Qt5::Widgets Qt5::Network Qt5::WebEngineWidgets)
endif()
# Temporary solution/hack to generate package.
# Proper way will come after cmake cleanup.
get_target_property(qt5_qmake Qt5::qmake LOCATION)
get_filename_component(qt5_bin_dir ${qt5_qmake} DIRECTORY)
if(APPLE)
find_program(qt5_qtdeploy
NAMES macdeployqt
PATHS ${qt5_bin_dir})
if(NOT qt5_qtdeploy)
message(FATAL_ERROR "macdeployqt not found")
endif()
add_custom_target(create_package
COMMAND ${CMAKE_COMMAND} -E remove_directory QSyncthingTray.app
COMMAND ${CMAKE_COMMAND} -E remove QSyncthingTray.dmg
COMMAND ${CMAKE_COMMAND} --build . --config $<CONFIG>
COMMAND ${qt5_qtdeploy} QSyncthingTray.app -verbose=1 -dmg
COMMENT "Creating package")
elseif(WIN32)
find_program(qt5_qtdeploy
NAMES windeployqt
PATHS ${qt5_bin_dir})
if(NOT qt5_qtdeploy)
message(FATAL_ERROR "windeployqt not found")
endif()
add_custom_target(create_package
COMMAND ${CMAKE_COMMAND} --build . --config $<CONFIG>
COMMAND ${qt5_qtdeploy} --compiler-runtime $<CONFIG>/QSyncthingTray.exe
COMMENT "Creating package")
endif()