-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
154 lines (121 loc) · 5.16 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
cmake_minimum_required(VERSION 3.10)
# Projektname und Version
project(FastReader VERSION 1.0)
# Setze den Standard-C++-Standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
option(FLATPAK_BUILD "Enable Flatpak-specific build settings" OFF)
option(FLATPAK_ID "Define the Flatpak ID" "")
# Füge die Executable hinzu
if(FLATPAK_BUILD)
set(EXECUTABLE_OUTPUT_PATH "/app/bin")
else()
set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}")
endif()
# Füge die Executable hinzu
if(FLATPAK_BUILD)
set(EXECUDABLE_NAME "fast-reader")
else()
set(EXECUDABLE_NAME "FastReader")
endif()
add_executable(${EXECUDABLE_NAME} src/FastReader.cpp)
if(FLATPAK_BUILD AND NOT FLATPAK_ID)
message(FATAL_ERROR "FLATPAK_ID must be set!")
endif()
if(FLATPAK_BUILD)
add_compile_definitions(LOCALEDIRR="/app/share/locale")
add_compile_definitions(ICON_NAME="${FLATPAK_ID}")
else()
add_compile_definitions(LOCALEDIRR="locale")
endif()
# Finde GTK4 und libconfig und füge deren Abhängigkeiten hinzu
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK4 REQUIRED gtk4)
pkg_check_modules(LIBCONFIG REQUIRED libconfig)
target_include_directories(${EXECUDABLE_NAME} PRIVATE ${GTK4_INCLUDE_DIRS} ${LIBCONFIG_INCLUDE_DIRS})
target_link_directories(${EXECUDABLE_NAME} PRIVATE ${GTK4_LIBRARY_DIRS} ${LIBCONFIG_LIBRARY_DIRS})
target_link_libraries(${EXECUDABLE_NAME} PRIVATE ${GTK4_LIBRARIES} ${LIBCONFIG_LIBRARIES})
# Nachrichtenkompilierung
find_program(MSGFMT_EXECUTABLE msgfmt REQUIRED)
# Übersetzungsverzeichnisse definieren
if(FLATPAK_BUILD)
set(LOCALE_DIR "/app/share/locale")
else()
set(LOCALE_DIR "${CMAKE_BINARY_DIR}/locale")
endif()
# Funktion zum Kompilieren der Übersetzungen
function(compile_po_files lang)
file(MAKE_DIRECTORY "${LOCALE_DIR}/${lang}/LC_MESSAGES")
set(PO_FILE "${CMAKE_SOURCE_DIR}/src/locale/${lang}/LC_MESSAGES/FastReader.po")
set(MO_FILE "${LOCALE_DIR}/${lang}/LC_MESSAGES/FastReader.mo")
# Füge die Kompilierung als benutzerdefinierten Befehl hinzu
add_custom_command(
OUTPUT ${MO_FILE}
COMMAND ${MSGFMT_EXECUTABLE} ${PO_FILE} -o ${MO_FILE}
DEPENDS ${PO_FILE}
COMMENT "Compiling ${lang} translations"
VERBATIM
)
# Füge die .mo-Dateien als Abhängigkeiten für das Ziel hinzu
add_custom_target("${lang}_mo" ALL DEPENDS ${MO_FILE})
# Installation der .mo-Dateien
install(FILES ${MO_FILE}
DESTINATION "${LOCALE_DIR}/${lang}/LC_MESSAGES")
endfunction()
function(copy_icon)
if(FLATPAK_BUILD)
set(ASSETS_TARGET_DIR "/app/share/icons/hicolor/scalable/apps")
set(DESTINATION_ICON "${ASSETS_TARGET_DIR}/${FLATPAK_ID}.svg")
else()
set(ASSETS_TARGET_DIR "${CMAKE_BINARY_DIR}/assets/hicolor/scalable/apps")
set(DESTINATION_ICON "${ASSETS_TARGET_DIR}/fastreader.svg")
endif()
file(MAKE_DIRECTORY ${ASSETS_TARGET_DIR})
set(SOURCE_ICON "${CMAKE_SOURCE_DIR}/src/assets/fastreader.svg")
file(COPY ${SOURCE_ICON} DESTINATION ${ASSETS_TARGET_DIR})
file(RENAME "${ASSETS_TARGET_DIR}/fastreader.svg" "${DESTINATION_ICON}")
add_custom_target(icon ALL DEPENDS ${DESTINATION_ICON})
install(FILES ${DESTINATION_ICON} DESTINATION ${ASSETS_TARGET_DIR})
endfunction()
function(copy_metainfo)
if(FLATPAK_BUILD)
set(ASSETS_TARGET_DIR "/app/share/metainfo")
set(SOURCE_METAINFO "${CMAKE_SOURCE_DIR}/src/assets/metainfo.xml")
set(DESTINATION_METAINFO "${ASSETS_TARGET_DIR}/${FLATPAK_ID}.metainfo.xml")
file(MAKE_DIRECTORY ${ASSETS_TARGET_DIR})
# Kopiere die Metainformationen mit dem neuen Namen
file(COPY ${SOURCE_METAINFO} DESTINATION ${ASSETS_TARGET_DIR})
file(RENAME "${ASSETS_TARGET_DIR}/metainfo.xml" "${DESTINATION_METAINFO}")
add_custom_target(metainfo ALL DEPENDS ${DESTINATION_METAINFO})
install(FILES ${DESTINATION_METAINFO} DESTINATION ${ASSETS_TARGET_DIR})
endif()
endfunction()
function(generate_desktop_file)
set(DESKTOP_FILE_IN "${CMAKE_SOURCE_DIR}/src/assets/fastreader.desktop.in")
if(FLATPAK_BUILD)
set(DESKTOP_FILE_DIRR "/app/share/applications")
set(DESKTOP_FILE_TEMP "${DESKTOP_FILE_DIRR}/tmp/${FLATPAK_ID}.desktop")
set(EXEC_COMMAND "fast-reader")
set(ICON_NAME "${FLATPAK_ID}")
else()
set(DESKTOP_FILE_DIRR "${CMAKE_BINARY_DIR}")
set(DESKTOP_FILE_TEMP "${DESKTOP_FILE_DIRR}/tmp/fastreader.desktop")
set(EXEC_COMMAND "\"${CMAKE_BINARY_DIR}/FastReader\"")
set(ICON_NAME "${CMAKE_BINARY_DIR}/assets/hicolor/scalable/apps/fastreader.svg")
endif()
configure_file(${DESKTOP_FILE_IN} ${DESKTOP_FILE_TEMP} @ONLY)
file(
COPY ${DESKTOP_FILE_TEMP}
DESTINATION ${DESKTOP_FILE_DIRR}
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
file(REMOVE_RECURSE "${DESKTOP_FILE_DIRR}/tmp")
add_custom_target(desktopfile ALL DEPENDS ${DESKTOP_FILE_IN})
endfunction()
# Kompiliere die Übersetzungen für Deutsch und Englisch
compile_po_files(de)
compile_po_files(en)
compile_po_files(it) #Thangs to https://github.com/albanobattistella
copy_icon()
copy_metainfo()
generate_desktop_file()