-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathCMakeLists.txt
213 lines (171 loc) · 7.41 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
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# =============================================================================
# Initialization
# =============================================================================
cmake_minimum_required(VERSION 3.10)
# Set the project name and version
project(
wxMP3gain
VERSION 4.2.0.0
DESCRIPTION "wxMP3gain is a free front-end for the MP3gain."
HOMEPAGE_URL "https://github.com/cfgnunes/wxmp3gain"
)
# Specify the C++ standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# Define a lowercase project name
string(TOLOWER ${CMAKE_PROJECT_NAME} CMAKE_BIN_NAME)
# =============================================================================
# Project dependencies
# =============================================================================
# -----------------------------------------------------------------------------
# wxWidgets
# -----------------------------------------------------------------------------
if(WIN32)
set(wxWidgets_ROOT_DIR "C:/wxMSW-3.2.4_gcc810_Dev")
set(wxWidgets_LIB_DIR "C:/wxMSW-3.2.4_gcc810_Dev/lib/gcc810_dll")
set(wxWidgets_CONFIGURATION mwsu)
endif()
find_package(wxWidgets REQUIRED)
include(${wxWidgets_USE_FILE})
# -----------------------------------------------------------------------------
# Gettext
# -----------------------------------------------------------------------------
find_package(Gettext)
# =============================================================================
# Set some default paths
# =============================================================================
# Set a folder for the data
set(CMAKE_DATA_DIR "data")
# Set a folder for the documentation
set(CMAKE_DOC_DIR "doc")
# =============================================================================
# Configure templates
# =============================================================================
# Set some strings for the templates: author
set(CMAKE_PROJECT_AUTHOR "Cristiano Fraga G. Nunes")
# Set some strings for the templates: e-mail
set(CMAKE_PROJECT_EMAIL "[email protected]")
# Set some strings for the templates: PPA distro
set(CMAKE_PROJECT_S_DESCRIPTION "Free front-end for the MP3gain.")
# Get the current year
string(TIMESTAMP CMAKE_CURRENT_YEAR "%Y")
# Strings for Debian packaging
if(UNIX)
# Get the current timestamp
string(TIMESTAMP CMAKE_CURRENT_TIMESTAMP "%a, %d %b %Y %H:%M:%S" UTC)
# Set 'distro'
set(CMAKE_DEBIAN_NAME "noble")
# Set 'build depends'
set(CMAKE_DEBIAN_BUILD_DEPENDS "debhelper (>= 10), libwxgtk3.2-dev | libwxgtk3.0-gtk3-dev | libwxgtk3.0-dev | libwxgtk2.8-dev, cmake")
# Set 'depends'
set(CMAKE_DEBIAN_DEPENDS "\${shlibs:Depends}, \${misc:Depends}, mp3gain (>= 1.5.1)")
endif()
# Header template
configure_file(
"${PROJECT_SOURCE_DIR}/src/Constants.hpp.in"
"${PROJECT_SOURCE_DIR}/src/Constants.hpp"
)
configure_file(
"${PROJECT_SOURCE_DIR}/debian/changelog.in"
"${PROJECT_SOURCE_DIR}/debian/changelog"
)
configure_file(
"${PROJECT_SOURCE_DIR}/debian/control.in"
"${PROJECT_SOURCE_DIR}/debian/control"
)
configure_file(
"${PROJECT_SOURCE_DIR}/debian/menu/app.desktop.in"
"${PROJECT_SOURCE_DIR}/debian/menu/app.desktop"
)
configure_file(
"${PROJECT_SOURCE_DIR}/packaging/windows/installer.iss.in"
"${PROJECT_SOURCE_DIR}/packaging/windows/installer.iss"
)
# =============================================================================
# Build process
# =============================================================================
# -----------------------------------------------------------------------------
# Translation files
# -----------------------------------------------------------------------------
# Set the source files
file(GLOB PO_FILES
po/*.po
)
# Compile translation files
if(GETTEXT_FOUND)
foreach(PO_FILE ${PO_FILES})
# Remove path and extension of 'PO_FILE'
get_filename_component(PO_NAME ${PO_FILE} NAME_WE)
# Compile each '.po' file to '.gmo' file
GETTEXT_PROCESS_PO_FILES(${PO_NAME} ALL PO_FILES "po/${PO_NAME}.po")
# Define the files location during install process
if(WIN32)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/${PO_NAME}.gmo"
DESTINATION "data/po/${PO_NAME}/"
RENAME "${CMAKE_BIN_NAME}.mo"
)
else()
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/${PO_NAME}.gmo"
DESTINATION "share/${CMAKE_BIN_NAME}/data/po/${PO_NAME}/"
RENAME "${CMAKE_BIN_NAME}.mo"
)
endif()
endforeach()
else()
message(WARNING "gettext tools not found. Translations will not be built.")
endif()
# -----------------------------------------------------------------------------
# Source files
# -----------------------------------------------------------------------------
# Set compiler parameters
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ansi -s -Wall -Wextra -Wpedantic")
# Set the source files
file(GLOB SRC_FILES
src/*.c*
src/*.h*
src/ui/*.c*
src/ui/*.h*
)
# Compile the main executable
if(WIN32)
set(SRC_FILES ${SRC_FILES} packaging/windows/resource.rc)
# Add the executable with a WinMain entry point on Windows.
# See https://cmake.org/cmake/help/latest/prop_tgt/WIN32_EXECUTABLE.html
add_executable(${CMAKE_BIN_NAME} WIN32 ${SRC_FILES})
else()
add_executable(${CMAKE_BIN_NAME} ${SRC_FILES})
endif()
target_link_libraries(${CMAKE_BIN_NAME} ${wxWidgets_LIBRARIES})
# =============================================================================
# Install process
# =============================================================================
# Define the file locations during install process
if(WIN32)
install(TARGETS ${CMAKE_BIN_NAME} DESTINATION "/")
install(DIRECTORY "${CMAKE_DATA_DIR}" DESTINATION "/")
install(FILES "${CMAKE_DOC_DIR}/CHANGELOG.md" DESTINATION "/" RENAME "Changelog.txt")
install(FILES "${CMAKE_DOC_DIR}/COPYING" DESTINATION "/" RENAME "License.txt")
install(FILES "${CMAKE_DOC_DIR}/README.md" DESTINATION "/" RENAME "Readme.txt")
install(FILES "C:/wxMSW-3.2.4_gcc810_Dev/lib/gcc810_dll/wxmsw32u_core_gcc810.dll" DESTINATION "/")
install(FILES "C:/wxMSW-3.2.4_gcc810_Dev/lib/gcc810_dll/wxbase32u_gcc810.dll" DESTINATION "/")
else()
install(TARGETS ${CMAKE_BIN_NAME} DESTINATION "bin")
install(DIRECTORY "${CMAKE_DATA_DIR}/" DESTINATION "share/${CMAKE_BIN_NAME}/${CMAKE_DATA_DIR}")
install(DIRECTORY "${CMAKE_DOC_DIR}/" DESTINATION "share/${CMAKE_DOC_DIR}/${CMAKE_BIN_NAME}")
install(FILES "debian/menu/icon32x32.png" DESTINATION "share/icons/hicolor/32x32/apps/" RENAME "${CMAKE_BIN_NAME}.png")
install(FILES "debian/menu/icon48x48.png" DESTINATION "share/icons/hicolor/48x48/apps/" RENAME "${CMAKE_BIN_NAME}.png")
install(FILES "debian/menu/icon64x64.png" DESTINATION "share/icons/hicolor/64x64/apps/" RENAME "${CMAKE_BIN_NAME}.png")
install(FILES "debian/menu/icon128x128.png" DESTINATION "share/icons/hicolor/128x128/apps/" RENAME "${CMAKE_BIN_NAME}.png")
install(FILES "debian/menu/app.desktop" DESTINATION "share/applications/" RENAME "${CMAKE_BIN_NAME}.desktop")
endif()
# =============================================================================
# Custom targets
# =============================================================================
# Define the 'run' target
add_custom_target(run
COMMAND ${CMAKE_BIN_NAME}
DEPENDS ${CMAKE_BIN_NAME}
WORKING_DIRECTORY ../${CMAKE_PROJECT_DIR}
)