-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
159 lines (130 loc) · 5.61 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
cmake_minimum_required(VERSION 3.1.0)
file(READ version.txt VERSION)
# Basic information about project
project(tom-ui
LANGUAGES CXX
VERSION ${VERSION}
DESCRIPTION "Tom Time Tracker"
HOMEPAGE_URL "https://github.com/jansorg/tom-ui")
# Set additional project information
set(COMPANY "Joachim Ansorg")
set(COPYRIGHT "Copyright (c) 2019-2022 Joachim Ansorg. All rights reserved.")
set(IDENTIFIER "dev.tomtime.tomui")
set(CPACK_PACKAGE_CONTACT "[email protected]")
set(CPACK_PACKAGE_NAME "tom-ui")
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
set(CPACK_DEBIAN_PACKAGE_DEPENDS "tom (>= ${VERSION})")
set(RESOURCE_FILES resources/resources.qrc source/settingsDialog/SettingsDialog.cpp source/settingsDialog/SettingsDialog.h source/settingsDialog/ApplicationSettingsPage.cpp source/settingsDialog/ApplicationSettingsPage.h source/settingsDialog/ApplicationShortcutsPage.cpp source/settingsDialog/ApplicationShortcutsPage.h source/settingsDialog/GlobalShortcutsPage.cpp source/settingsDialog/GlobalShortcutsPage.h source/GlobalShortcuts.cpp source/GlobalShortcuts.h source/GlobalShortcut.cpp source/GlobalShortcut.h)
include(GNUInstallDirs)
set(CMAKE_MODULE_PATH cmake)
option(ENABLE_REPORTS "Enable Webkit component to preview reports" ON)
# Include Qt basic functions
include(cmake/QtCommon.cmake)
# Set PROJECT_VERSION_PATCH and PROJECT_VERSION_TWEAK to 0 if not present, needed by add_project_meta
fix_project_version()
add_project_meta(META_FILES_TO_INCLUDE)
find_package(Qt5 5.9.0
COMPONENTS
Core
Widgets
Svg
LinguistTools
Test
REQUIRED)
find_package(X11)
configure_file(
"source/version.h.in"
"${PROJECT_BINARY_DIR}/version.h"
)
file(GLOB_RECURSE CODE_FILES source/*.cpp source/*.h qxt/qxtglobalshortcut.cpp)
add_definitions(-DQXT_STATIC)
set(TS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/translations/tom_de.ts)
file(GLOB_RECURSE TS_SOURCES "source/*.cpp" "source/*.h" "source/*.ui")
add_custom_target(translations)
foreach (_ts_file ${TS_FILES})
# generate a sensible name for this translation file
get_filename_component(_ts_name ${_ts_file} NAME_WE)
# call lupdate ourselves
add_custom_command(
OUTPUT "${_ts_file}"
DEPENDS ${TS_SOURCES}
COMMAND ${Qt5_LUPDATE_EXECUTABLE} -recursive ${CMAKE_CURRENT_SOURCE_DIR} -ts ${_ts_file}
)
# create a target that depends on the generated files
add_custom_target(translate_${_ts_name} DEPENDS ${_ts_file})
# attach the custom target for this ts file to the parent target
add_dependencies(translations translate_${_ts_name})
endforeach ()
# generate qm files
qt5_add_translation(QM_FILES ${TS_FILES})
configure_file(translations/translations.qrc ${CMAKE_CURRENT_BINARY_DIR} COPYONLY)
if (Q_OS_MAC OR APPLE)
file(GLOB CODE_FILES ${CODE_FILES} qxt/qxtglobalshortcut_mac.cpp)
FIND_LIBRARY(CARBON_LIBRARY Carbon)
FIND_LIBRARY(COCOA_LIBRARY Cocoa)
LIST(APPEND TOM_LIBS ${CARBON_LIBRARY} ${COCOA_LIBRARY})
elseif (X11_FOUND)
file(GLOB CODE_FILES ${CODE_FILES} qxt/qxtglobalshortcut_x11.cpp)
list(APPEND TOM_LIBS ${X11_LIBRARIES})
elseif (Q_WS_WIN OR WIN32)
file(GLOB CODE_FILES ${CODE_FILES} qxt/qxtglobalshortcut_win.cpp)
else ()
message(WARNING "Building on unsupported platfom!")
set(USE_QXT FALSE)
endif ()
include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS})
if (WIN32)
add_compile_options()
else()
add_compile_options(-std=c++14 -Wall -Wextra -pedantic)
endif()
if (CMAKE_BUILD_TYPE EQUAL "release")
add_compile_options(-O3)
else()
add_compile_options(-g3 -O0)
endif ()
add_executable(${PROJECT_NAME} ${OS_BUNDLE} # Expands to WIN32 or MACOS_BUNDLE depending on OS
${CODE_FILES} ${META_FILES_TO_INCLUDE} ${RESOURCE_FILES} ${QM_FILES} ${CMAKE_CURRENT_BINARY_DIR}/translations.qrc)
if (APPLE)
set_target_properties(${PROJECT_NAME} PROPERTIES
MACOSX_BUNDLE_INFO_PLIST ${PROJECT_SOURCE_DIR}/cmake/Info.plist.in
MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_DESCRIPTION})
endif ()
#enable_testing(true)
#include_directories(test)
target_include_directories(${PROJECT_NAME} PRIVATE source)
target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_BINARY_DIR})
# add Qt5::Test to use model tester
target_link_libraries(${PROJECT_NAME} Qt5::Widgets Qt5::Svg ${TOM_LIBS})
if (ENABLE_REPORTS)
find_package(Qt5 OPTIONAL_COMPONENTS WebEngineWidgets)
target_link_libraries(${PROJECT_NAME} Qt5::WebEngineWidgets)
add_compile_definitions(TOM_REPORTS=true)
endif ()
if (UNIX)
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
install(FILES resources/tom-ui.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications )
install(FILES resources/icons/tom.svg DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/scalable/apps)
elseif (APPLE)
install(TARGETS ${PROJECT_NAME} DESTINATION .)
set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR})
install(CODE "
include(BundleUtilities)
fixup_bundle(${CMAKE_INSTALL_PREFIX}/tom-ui.app \"\" \"\")
" COMPONENT Runtime)
elseif (WIN32)
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
endif ()
if(WIN32)
# Prepare the InnoSetup configuration script
configure_file(deployment/setup.iss.in "${CMAKE_CURRENT_BINARY_DIR}/setup.iss")
# The MSVC 2015 runtime requires CMake 3.6+
if((MSVC_VERSION VERSION_EQUAL 1900 OR MSVC_VERSION VERSION_GREATER 1900)
AND CMAKE_VERSION VERSION_LESS "3.6")
message(WARNING "MSVC 2015+ runtime requires CMake 3.6+")
endif()
# Ensure the C/C++ runtime is installed
set(CMAKE_INSTALL_UCRT_LIBRARIES TRUE)
include(InstallRequiredSystemLibraries)
endif()
INCLUDE(CPack)