-
Notifications
You must be signed in to change notification settings - Fork 67
/
CMakeLists.txt
147 lines (123 loc) · 4.29 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
cmake_minimum_required(VERSION 3.10)
project(spotify-qt LANGUAGES CXX VERSION 3.12)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
# C++11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Optional D-Bus support
option(USE_DBUS "Use D-Bus integration" ON)
# Optional KCrash support
option(USE_KCRASH "Use KCrash integration" ON)
# LTO support
option(USE_LTO "Use link time optimization" OFF)
# Prefer new OpenGL
if (POLICY CMP0072)
cmake_policy(SET CMP0072 NEW)
endif ()
# Set target macOS version
if (APPLE)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15")
endif ()
# Find Qt
include(cmake/FindQt.cmake)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Widgets Network Gui Svg REQUIRED)
if (USE_DBUS)
find_package(Qt${QT_VERSION_MAJOR} OPTIONAL_COMPONENTS DBus QUIET)
endif ()
# Find KCRash
if (USE_KCRASH)
find_package(KF5Crash QUIET)
endif ()
# Create main executable
if (ANDROID)
add_library(spotify-qt SHARED res.qrc)
elseif (MSVC)
add_executable(spotify-qt WIN32 res.qrc
${CMAKE_CURRENT_SOURCE_DIR}/res/app/app.rc)
elseif (APPLE)
set(APP_ICNS ${CMAKE_CURRENT_SOURCE_DIR}/res/app/spotify-qt.icns)
add_executable(spotify-qt MACOSX_BUNDLE res.qrc ${APP_ICNS})
# Load properties from Info.plist file
set_target_properties(spotify-qt PROPERTIES
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/res/app/Info.plist)
# Copy icon file to Resources folder
set_source_files_properties(${APP_ICNS} PROPERTIES
MACOSX_PACKAGE_LOCATION "Resources")
else ()
add_executable(spotify-qt res.qrc)
endif ()
# Collect source files
add_subdirectory(src)
# Headers are in src/
target_include_directories(spotify-qt PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src")
# Get version from Git
find_package(Git QUIET)
if (GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_COMMIT
OUTPUT_STRIP_TRAILING_WHITESPACE)
target_compile_definitions(spotify-qt PRIVATE GIT_COMMIT="${GIT_COMMIT}")
endif ()
# App related definitions
target_compile_definitions(spotify-qt PRIVATE APP_VERSION="v${PROJECT_VERSION}")
target_compile_definitions(spotify-qt PRIVATE APP_NAME="${PROJECT_NAME}")
target_compile_definitions(spotify-qt PRIVATE APP_ICON="${PROJECT_NAME}")
target_compile_definitions(spotify-qt PRIVATE ORG_NAME="kraxarn")
target_compile_definitions(spotify-qt PRIVATE PKG_NAME="com.kraxarn")
target_compile_definitions(spotify-qt PRIVATE BUILD_TYPE="${CMAKE_BUILD_TYPE}")
# Install icons and desktop shortcut on unix-like
if (UNIX)
install(FILES res/logo/spotify-qt.svg DESTINATION share/icons/hicolor/scalable/apps)
install(FILES res/app/spotify-qt.desktop DESTINATION share/applications)
endif ()
if (APPLE)
# macOS bundling
install(TARGETS spotify-qt BUNDLE DESTINATION bin)
else ()
# Binary for other targets
install(TARGETS spotify-qt RUNTIME DESTINATION bin)
endif ()
# Don't show console window under windows
if (WIN32 AND NOT MSVC)
target_link_options(spotify-qt PRIVATE -mwindows)
endif ()
# IPO / LTO
if (USE_LTO)
include(CheckIPOSupported)
check_ipo_supported(RESULT ipo_supported OUTPUT ipo_error)
if (ipo_supported AND CMAKE_BUILD_TYPE STREQUAL "Release")
set_property(TARGET ${PROJECT_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
elseif (ipo_supported)
message(STATUS "LTO is only supported in Release builds")
else ()
message(STATUS "LTO error: ${ipo_error}")
endif ()
endif ()
# Link Qt
target_link_libraries(spotify-qt PRIVATE
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Widgets
Qt${QT_VERSION_MAJOR}::Network
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::Svg)
# spotify-qt-lib
set(LIB_QT_IMPL ON)
add_subdirectory(lib)
target_link_libraries(spotify-qt PRIVATE spotify-qt-lib)
# Enable all compiler warnings under GCC/Clang
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(spotify-qt PRIVATE -Wall -Wextra)
endif ()
# D-Bus support is optional
if (Qt${QT_VERSION_MAJOR}DBus_FOUND)
target_compile_definitions(spotify-qt PRIVATE USE_DBUS)
target_link_libraries(spotify-qt PRIVATE Qt${QT_VERSION_MAJOR}::DBus)
endif ()
# KCrash support
if (KF5Crash_FOUND AND NOT USE_QT6)
target_compile_definitions(spotify-qt PRIVATE USE_KCRASH)
target_link_libraries(spotify-qt PRIVATE KF5::Crash)
endif ()