forked from AdrianTM/custom-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
199 lines (173 loc) · 5.94 KB
/
CMakeLists.txt
File metadata and controls
199 lines (173 loc) · 5.94 KB
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
# **********************************************************************
# * Copyright (C) 2017-2025 MX Authors
# *
# * Authors: Adrian
# * MX Linux <http://mxlinux.org>
# *
# * This file is part of custom-toolbox.
# *
# * custom-toolbox is free software: you can redistribute it and/or modify
# * it under the terms of the GNU General Public License as published by
# * the Free Software Foundation, either version 3 of the License, or
# * (at your option) any later version.
# *
# * custom-toolbox is distributed in the hope that it will be useful,
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# * GNU General Public License for more details.
# *
# * You should have received a copy of the GNU General Public License
# * along with custom-toolbox. If not, see <http://www.gnu.org/licenses/>.
# **********************************************************************/
cmake_minimum_required(VERSION 3.16)
set(PROJECT_VERSION_FROM_CHANGELOG "")
if(DEFINED PROJECT_VERSION_OVERRIDE AND NOT "${PROJECT_VERSION_OVERRIDE}" STREQUAL "")
set(PROJECT_VERSION_FROM_CHANGELOG "${PROJECT_VERSION_OVERRIDE}")
message(STATUS "Using version override: ${PROJECT_VERSION_FROM_CHANGELOG}")
else()
# Try dpkg-parsechangelog first (Debian/Ubuntu)
execute_process(
COMMAND dpkg-parsechangelog -SVersion
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE PROJECT_VERSION_FROM_CHANGELOG
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE DPKG_RESULT
ERROR_QUIET
)
if(DPKG_RESULT EQUAL 0 AND NOT "${PROJECT_VERSION_FROM_CHANGELOG}" STREQUAL "")
message(STATUS "Using version from debian/changelog: ${PROJECT_VERSION_FROM_CHANGELOG}")
elseif(EXISTS ${CMAKE_SOURCE_DIR}/debian/changelog)
file(READ ${CMAKE_SOURCE_DIR}/debian/changelog PROJECT_CHANGELOG_CONTENT)
string(REGEX MATCH "^[^\\(]*\\(([^)]+)\\)" _match "${PROJECT_CHANGELOG_CONTENT}")
if(_match)
set(PROJECT_VERSION_FROM_CHANGELOG "${CMAKE_MATCH_1}")
message(STATUS "Using version parsed from debian/changelog: ${PROJECT_VERSION_FROM_CHANGELOG}")
else()
message(WARNING "Could not parse version from debian/changelog, defaulting to 0.0.0")
set(PROJECT_VERSION_FROM_CHANGELOG "0.0.0")
endif()
else()
message(WARNING "Could not determine version automatically, defaulting to 0.0.0")
set(PROJECT_VERSION_FROM_CHANGELOG "0.0.0")
endif()
endif()
# Option to use clang for testing builds - needs to be early so project() picks it up
option(USE_CLANG "Use clang compiler" OFF)
if(USE_CLANG)
set(CMAKE_C_COMPILER clang CACHE STRING "C compiler" FORCE)
set(CMAKE_CXX_COMPILER clang++ CACHE STRING "C++ compiler" FORCE)
message(STATUS "Using clang compiler")
endif()
project(custom-toolbox
VERSION ${PROJECT_VERSION_FROM_CHANGELOG}
DESCRIPTION "Custom Toolbox - Program for creating custom launchers for MX Linux"
LANGUAGES CXX
)
# Set C++ standard
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Enable compile commands export for IDEs and tools
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Optimize for Ninja builds
if(CMAKE_GENERATOR STREQUAL "Ninja")
# Enable colored output for Ninja
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(-fdiagnostics-color=always)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_compile_options(-fcolor-diagnostics)
endif()
endif()
# Find Qt6 components
find_package(Qt6 REQUIRED COMPONENTS
Core
Gui
Widgets
LinguistTools
)
# Enable automatic MOC, UIC, and RCC processing
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
# Define source files
set(SOURCES
src/main.cpp
src/mainwindow.cpp
src/flatbutton.cpp
src/about.cpp
)
set(HEADERS
src/mainwindow.h
src/flatbutton.h
src/about.h
src/common.h
)
set(UI_FILES
src/mainwindow.ui
)
set(RESOURCE_FILES
images.qrc
)
# Get all translation files
file(GLOB TRANSLATION_FILES "translations/*.ts")
# Create the executable
add_executable(custom-toolbox
${SOURCES}
${HEADERS}
${UI_FILES}
${RESOURCE_FILES}
)
# Link Qt6 libraries
target_link_libraries(custom-toolbox
Qt6::Core
Qt6::Gui
Qt6::Widgets
)
# Set compiler flags
target_compile_options(custom-toolbox PRIVATE
-Wpedantic
-pedantic
-Werror=return-type
-Werror=switch
-Werror=uninitialized
-Werror
)
# Add compiler-specific flags
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR USE_CLANG)
target_compile_options(custom-toolbox PRIVATE -Werror=return-stack-address)
else()
target_compile_options(custom-toolbox PRIVATE -Werror=return-local-addr)
endif()
# Set compile definitions
target_compile_definitions(custom-toolbox PRIVATE
QT_DEPRECATED_WARNINGS
VERSION="${PROJECT_VERSION}"
)
# Release-specific optimizations
if(CMAKE_BUILD_TYPE STREQUAL "Release")
target_compile_definitions(custom-toolbox PRIVATE NDEBUG)
target_compile_options(custom-toolbox PRIVATE -O3)
# Add LTO - different flags for different compilers
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR USE_CLANG)
target_compile_options(custom-toolbox PRIVATE -flto=thin)
target_link_options(custom-toolbox PRIVATE -flto=thin)
else()
target_compile_options(custom-toolbox PRIVATE -flto=auto)
target_link_options(custom-toolbox PRIVATE -flto=auto)
endif()
endif()
# Handle translations
qt6_add_translations(custom-toolbox
TS_FILES ${TRANSLATION_FILES}
LRELEASE_OPTIONS -compress -nounfinished -removeidentical -silent
QM_FILES_OUTPUT_VARIABLE qm_files
)
# Set target properties
set_target_properties(custom-toolbox PROPERTIES
OUTPUT_NAME "custom-toolbox"
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
)
# Install target (required by Debian build system)
# Other files are handled by debian/install
install(TARGETS custom-toolbox
RUNTIME DESTINATION bin
)