-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathCMakeLists.txt
180 lines (154 loc) · 5.2 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
# SPDX-FileCopyrightText: 2021-2025 Graeme Gott <graeme@gottcode.org>
#
# SPDX-License-Identifier: GPL-3.0-or-later
cmake_minimum_required(VERSION 3.16)
# Configure project
project(tanglet VERSION 1.6.6 LANGUAGES CXX)
set(project_copyright "2009-2025 Graeme Gott")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
find_package(Qt6 REQUIRED COMPONENTS Core Gui LinguistTools Widgets)
find_package(ZLIB REQUIRED)
include(GNUInstallDirs)
add_compile_definitions(
QT_NO_KEYWORDS
$<$<CONFIG:DEBUG>:QT_STRICT_ITERATORS>
$<$<CONFIG:DEBUG>:QT_NO_NARROWING_CONVERSIONS_IN_CONNECT>
$<$<CONFIG:DEBUG>:QT_DISABLE_DEPRECATED_BEFORE=0x060800>
)
# Version number
include(cmake/AddVersionCompileDefinition.cmake)
add_version_compile_definition(src/main.cpp VERSIONSTR)
# Create program
qt_add_executable(tanglet
src/beveled_rect.cpp
src/board.cpp
src/clock.cpp
src/generator.cpp
src/gzip.cpp
src/language_dialog.cpp
src/language_settings.cpp
src/locale_dialog.cpp
src/letter.cpp
src/new_game_dialog.cpp
src/main.cpp
src/scores_dialog.cpp
src/solver.cpp
src/trie.cpp
src/view.cpp
src/window.cpp
src/word_counts.cpp
src/word_tree.cpp
icons/icons.qrc
${translations_QM}
)
target_link_libraries(tanglet PRIVATE
Qt6::Core
Qt6::Gui
Qt6::Widgets
ZLIB::ZLIB
)
# Create translations
file(GLOB translations_SRCS translations/*.ts)
qt_add_translations(tanglet
TS_FILES ${translations_SRCS}
QM_FILES_OUTPUT_VARIABLE translations_QM
LUPDATE_OPTIONS -no-obsolete -locations none
)
# Create word lists
add_subdirectory(tools)
file(GLOB languages wordlists/*)
foreach(lang_file ${languages})
get_filename_component(lang ${lang_file} NAME)
set(lang_source ${CMAKE_SOURCE_DIR}/gamedata/${lang})
# Create wordlist for ${lang}
set(wordlist_file ${lang_source}/words)
add_custom_command(
OUTPUT ${wordlist_file}
COMMAND "$<SHELL_PATH:$<TARGET_FILE:wordlist>>" -l ${lang} -o "$<SHELL_PATH:${wordlist_file}>" "$<SHELL_PATH:${lang_file}>"
DEPENDS ${lang_file} ${CMAKE_SOURCE_DIR}/tools/wordlist.cpp
WORKING_DIRECTORY ${CMAKE_PREFIX_PATH}/bin # needed for Windows to find Qt
VERBATIM
)
# Create dice for ${lang}
set(dice_file ${lang_source}/dice)
add_custom_command(
OUTPUT ${dice_file}
COMMAND "$<SHELL_PATH:$<TARGET_FILE:dice>>" -b -d -o "$<SHELL_PATH:${dice_file}>" "$<SHELL_PATH:${wordlist_file}>"
DEPENDS ${wordlist_file} ${CMAKE_SOURCE_DIR}/tools/dice.cpp
WORKING_DIRECTORY ${CMAKE_PREFIX_PATH}/bin # needed for Windows to find Qt
VERBATIM
)
# Add ${lang} as dependency of target
set(data_files ${wordlist_file} ${dice_file} ${lang_source}/language.ini)
if(EXISTS ${lang_source}/README)
list(APPEND data_files ${lang_source}/README)
endif()
target_sources(tanglet PRIVATE ${data_files})
# Install data for ${lang}
if(APPLE)
set_source_files_properties(
${data_files}
PROPERTIES
MACOSX_PACKAGE_LOCATION Resources/gamedata/${lang}
)
elseif(NOT WIN32)
install(FILES ${data_files} DESTINATION ${CMAKE_INSTALL_DATADIR}/tanglet/gamedata/${lang})
endif()
endforeach()
# Optimize build
option(ENABLE_LINK_TIME_OPTIMIZATION "Enable link time optimization" OFF)
if(ENABLE_LINK_TIME_OPTIMIZATION)
include(CheckIPOSupported)
check_ipo_supported(RESULT result)
if(result)
set_target_properties(tanglet PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
endif()
option(ENABLE_STRIP "Enable automatic stripping of builds" OFF)
if(ENABLE_STRIP)
add_custom_command(TARGET tanglet
POST_BUILD
COMMAND ${CMAKE_STRIP} $<TARGET_FILE:tanglet>
)
endif()
# Install
if(APPLE)
set(datadir "../Resources")
set_target_properties(tanglet PROPERTIES
OUTPUT_NAME Tanglet
MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/mac/Info.plist.in
)
include(cmake/BundleResources.cmake)
bundle_data(tanglet ${CMAKE_SOURCE_DIR}/icons/tanglet.icns Resources)
bundle_translations(tanglet "${translations_QM}")
elseif(WIN32)
set(datadir ".")
# Use Qt6 macro until CMake provides something
# https://bugreports.qt.io/browse/QTBUG-87618
set_target_properties(tanglet PROPERTIES
OUTPUT_NAME Tanglet
WIN32_EXECUTABLE TRUE
QT_TARGET_VERSION "${PROJECT_VERSION}"
QT_TARGET_COMPANY_NAME "Graeme Gott"
QT_TARGET_DESCRIPTION "Word finding game"
QT_TARGET_COPYRIGHT "\\xA9 ${project_copyright}"
QT_TARGET_PRODUCT_NAME "Tanglet"
QT_TARGET_RC_ICONS ${CMAKE_SOURCE_DIR}/icons/tanglet.ico
)
_qt_internal_generate_win32_rc_file(tanglet)
else()
file(RELATIVE_PATH datadir ${CMAKE_INSTALL_FULL_BINDIR} ${CMAKE_INSTALL_FULL_DATADIR}/tanglet)
target_sources(tanglet PRIVATE icons/icon.qrc)
install(TARGETS tanglet RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES ${translations_QM} DESTINATION ${CMAKE_INSTALL_DATADIR}/tanglet/translations)
install(FILES doc/tanglet.6 DESTINATION ${CMAKE_INSTALL_MANDIR}/man6 COMPONENT doc)
install(DIRECTORY icons/hicolor DESTINATION ${CMAKE_INSTALL_DATADIR}/icons)
install(FILES icons/tanglet.appdata.xml DESTINATION ${CMAKE_INSTALL_DATADIR}/metainfo)
install(FILES icons/tanglet.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)
install(FILES icons/tanglet.xml DESTINATION ${CMAKE_INSTALL_DATADIR}/mime/packages)
endif()
set_property(SOURCE src/main.cpp APPEND PROPERTY COMPILE_DEFINITIONS TANGLET_DATADIR="${datadir}")