1 # Configure for Qt4 |
1 if(APPLE AND EXISTS /usr/local/opt/qt5) |
2 set(QT_MIN_VERSION "4.5.0") |
2 # Special treatment for OS X users who |
|
3 # install Qt5 via Homebrew. |
|
4 # Homebrew installs Qt5 (up to at least 5.9.1) in |
|
5 # /usr/local/qt5, ensure it can be found by CMake since |
|
6 # it is not in the default /usr/local prefix. |
|
7 list(APPEND CMAKE_PREFIX_PATH "/usr/local/opt/qt5") |
|
8 endif() |
|
9 |
|
10 find_package(Qt5 COMPONENTS Core Widgets Gui Network) |
|
11 |
|
12 include_directories(${Qt5Core_PRIVATE_INCLUDE_DIRS}) |
|
13 |
3 include(CheckLibraryExists) |
14 include(CheckLibraryExists) |
4 |
15 |
5 set(QT_USE_QTCORE TRUE) |
16 find_package(SDL2 REQUIRED) |
6 set(QT_USE_QTGUI TRUE) |
17 find_package(SDL2_mixer 2 REQUIRED) #audio in SDLInteraction |
7 set(QT_USE_QTNETWORK TRUE) |
18 include_directories(${SDL2_INCLUDE_DIR}) |
8 set(QT_USE_QTSVG FALSE) |
19 include_directories(${SDL2_MIXER_INCLUDE_DIRS}) |
9 set(QT_USE_QTXML FALSE) |
20 |
10 set(QT_USE_QTOPENGL FALSE) |
21 if(LIBAV_FOUND) |
11 set(QT_USE_QTMAIN TRUE) |
22 add_definitions(-DVIDEOREC -D__STDC_CONSTANT_MACROS) |
12 |
23 include_directories(${LIBAV_INCLUDE_DIR}) |
13 find_package(Qt4 REQUIRED) |
24 list(APPEND HW_LINK_LIBS ${LIBAV_LIBRARIES}) |
14 if (NOT CROSSAPPLE) |
25 endif() |
15 include(${QT_USE_FILE}) |
26 |
16 endif() |
27 # server messages localization |
17 |
28 file(GLOB ServerSources ${CMAKE_SOURCE_DIR}/gameServer/*.hs) |
18 # Check if we need zlib |
29 foreach(hsfile ${ServerSources}) |
19 check_library_exists("${QT_QTCORE_LIBRARY}" inflateInit2_ ${QT_LIBRARY_DIR} QT_PROVIDES_ZLIB_FUNCTIONS) |
30 file(READ ${hsfile} hs) |
20 |
31 string(REGEX MATCHALL "loc *\"[^\n\"]+\"" locs ${hs}) |
21 if(NOT QT_PROVIDES_ZLIB_FUNCTIONS) |
32 foreach(str ${locs}) |
22 find_package(ZLIB REQUIRED) |
33 string(REGEX REPLACE "loc *\"([^\n\"]+)\"" "QT_TRANSLATE_NOOP(\"server\", \"\\1\")" s ${str}) |
23 |
34 list(APPEND serverlocs ${s}) |
24 set(HW_LINK_LIBS ${ZLIB_LIBRARIES} ${HW_LINK_LIBS}) |
35 endforeach(str) |
25 endif() |
36 endforeach(hsfile) |
26 |
37 |
27 |
38 list(REMOVE_DUPLICATES serverlocs) |
28 # Configure for SDL |
39 list(GET serverlocs 0 firstline) |
29 find_package(SDL REQUIRED) |
40 list(REMOVE_AT serverlocs 0) |
30 find_package(SDL_mixer REQUIRED) |
41 set(locsout "const char * serverMessages[] = {\n") |
31 if(NOT NOVIDEOREC) |
42 foreach(l ${serverlocs}) |
32 find_package(FFMPEG) |
43 list(APPEND locsout ${l} ",\n") |
33 endif() |
44 endforeach(l) |
34 |
45 list(APPEND locsout ${firstline} "\n}\\;\n") |
35 include_directories(.) |
46 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/servermessages.h ${locsout}) |
|
47 |
|
48 |
|
49 # Credits localization |
|
50 file(GLOB CreditsCSV ${CMAKE_SOURCE_DIR}/QTfrontend/res/credits.csv) |
|
51 foreach(csvfile ${CreditsCSV}) |
|
52 # Load credits.csv |
|
53 file(READ ${csvfile} csv) |
|
54 |
|
55 # Match first line of CSV file |
|
56 string(REGEX MATCH "(E|S|U),\"[^\n\"]+\"" loc_top ${csv}) |
|
57 string(REGEX REPLACE "(E|S|U),\"([^\n\"]+)\"" "\nQT_TRANSLATE_NOOP(\"credits\", \"\\2\")" s ${loc_top}) |
|
58 list(APPEND csvlocs ${s}) |
|
59 |
|
60 # Match remaining lines of CSV file |
|
61 string(REGEX MATCHALL "\n(E|S|U),\"[^\n\"]+\"" locs ${csv}) |
|
62 foreach(str ${locs}) |
|
63 string(REGEX REPLACE "(E|S|U),\"([^\n\"]+)\"" "QT_TRANSLATE_NOOP(\"credits\", \"\\2\")" s ${str}) |
|
64 list(APPEND csvlocs ${s}) |
|
65 endforeach(str) |
|
66 endforeach(csvfile) |
|
67 |
|
68 list(REMOVE_DUPLICATES csvlocs) |
|
69 list(GET csvlocs 0 firstline) |
|
70 list(REMOVE_AT csvlocs 0) |
|
71 set(locsout "const char * creditsMessages[] = {") |
|
72 foreach(l ${csvlocs}) |
|
73 list(APPEND locsout ${l} ",") |
|
74 endforeach(l) |
|
75 list(APPEND locsout ${firstline} "\n}\\;\n") |
|
76 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/creditsmessages.h ${locsout}) |
|
77 |
|
78 |
|
79 include_directories(${CMAKE_CURRENT_BINARY_DIR}) |
|
80 include_directories(${CMAKE_CURRENT_SOURCE_DIR}) |
36 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/model) |
81 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/model) |
37 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/net) |
82 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/net) |
38 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/ui) |
83 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/ui) |
39 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/ui/dialog) |
84 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/ui/dialog) |
40 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/ui/page) |
85 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/ui/page) |
41 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/ui/widget) |
86 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/ui/widget) |
42 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/util) |
87 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/util) |
43 include_directories(${SDL_INCLUDE_DIR}) |
88 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/util/platform) |
44 include_directories(${SDLMIXER_INCLUDE_DIR}) |
89 include_directories(BEFORE ${PHYSFS_INCLUDE_DIR}) |
45 include_directories(${FFMPEG_INCLUDE_DIR}) |
90 include_directories(BEFORE ${PHYSLAYER_INCLUDE_DIR}) |
46 include_directories(${CMAKE_SOURCE_DIR}/misc/quazip) |
91 include_directories(${LUA_INCLUDE_DIR}) #brought by physlayer hwpacksmounter.h |
|
92 |
47 if(UNIX) |
93 if(UNIX) |
48 # HACK: in freebsd cannot find iconv.h included via SDL.h |
94 # HACK: in freebsd cannot find iconv.h included via SDL.h |
49 include_directories("/usr/local/include") |
95 include_directories("/usr/local/include") |
50 endif(UNIX) |
96 endif(UNIX) |
51 |
97 |
52 |
98 #only the cocoa version of qt supports building 64 bit apps |
53 if(WIN32 AND NOT UNIX) |
99 if(APPLE AND (CMAKE_OSX_ARCHITECTURES MATCHES "x86_64*") AND (NOT QT_MAC_USE_COCOA)) |
54 set(HEDGEWARS_BINDIR ".") |
100 message(FATAL_ERROR "Building the 64 bit version of Hedgewars *requires* the Cocoa variant of QT on Mac OS X") |
55 set(HEDGEWARS_DATADIR "../share/") |
101 endif() |
56 add_definitions(-DUSE_XFIRE) |
102 #endif() |
57 else() |
|
58 set(HEDGEWARS_BINDIR ${CMAKE_INSTALL_PREFIX}) |
|
59 if(DEFINED DATA_INSTALL_DIR) |
|
60 set(HEDGEWARS_DATADIR ${DATA_INSTALL_DIR}) |
|
61 else() |
|
62 set(HEDGEWARS_DATADIR ${CMAKE_INSTALL_PREFIX}/share/) |
|
63 endif() |
|
64 #only the cocoa version of qt supports building 64 bit apps |
|
65 if(APPLE AND (CMAKE_OSX_ARCHITECTURES MATCHES "x86_64*") AND (NOT QT_MAC_USE_COCOA)) |
|
66 message(FATAL_ERROR "Building the 64 bit version of Hedgewars *requires* the Cocoa variant of QT on Mac OS X") |
|
67 endif() |
|
68 endif() |
|
69 |
|
70 |
103 |
71 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/hwconsts.cpp.in ${CMAKE_CURRENT_BINARY_DIR}/hwconsts.cpp) |
104 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/hwconsts.cpp.in ${CMAKE_CURRENT_BINARY_DIR}/hwconsts.cpp) |
72 |
105 |
73 file(GLOB NetCpp net/*.cpp) |
106 file(GLOB NetCpp net/*.cpp) |
74 file(GLOB ModelCpp model/*.cpp) |
107 file(GLOB ModelCpp model/*.cpp) |
75 file(GLOB_RECURSE UIcpp ui/*.cpp) |
108 file(GLOB_RECURSE UIcpp ui/*.cpp) |
76 file(GLOB UtilCpp util/*.cpp) |
109 file(GLOB UtilCpp util/*.cpp) |
77 |
110 |
78 if(${FFMPEG_FOUND}) |
111 list(APPEND hwfr_src |
79 add_definitions(-DVIDEOREC -D__STDC_CONSTANT_MACROS) |
|
80 endif() |
|
81 |
|
82 set(hwfr_src |
|
83 ${ModelCpp} |
112 ${ModelCpp} |
84 ${NetCpp} |
113 ${NetCpp} |
85 ${UIcpp} |
114 ${UIcpp} |
86 ${UtilCpp} |
115 ${UtilCpp} |
87 achievements.cpp |
116 achievements.cpp |
141 binds.h |
167 binds.h |
142 ui_hwform.h |
168 ui_hwform.h |
143 hwconsts.h |
169 hwconsts.h |
144 sdlkeys.h |
170 sdlkeys.h |
145 campaign.h |
171 campaign.h |
|
172 mission.h |
|
173 ${CMAKE_CURRENT_BINARY_DIR}/servermessages.h |
|
174 ${CMAKE_CURRENT_BINARY_DIR}/creditsmessages.h |
146 ) |
175 ) |
147 |
176 |
148 set(hwfr_rez hedgewars.qrc) |
177 set(hwfr_rez hedgewars.qrc) |
149 |
178 |
150 qt4_add_resources(hwfr_rez_src ${hwfr_rez}) |
179 if(BUILD_ENGINE_LIBRARY) |
151 |
180 add_definitions(-DHWLIBRARY=1) |
152 qt4_wrap_cpp(hwfr_moc_srcs ${hwfr_moc_hdrs}) |
181 set(hwlibname "${EXECUTABLE_OUTPUT_PATH}/${CMAKE_SHARED_LIBRARY_PREFIX}hwengine${CMAKE_SHARED_LIBRARY_SUFFIX}") |
153 |
182 list(APPEND HW_LINK_LIBS ${hwlibname}) |
154 |
183 |
155 if(APPLE OR CROSSAPPLE) |
184 if(LIBAV_FOUND) |
156 set(hwfr_src ${hwfr_src} InstallController.cpp CocoaInitializer.mm M3Panel.mm M3InstallController.m NSWorkspace_RBAdditions.m) |
185 # add_subdirectory(avwrapper) |
157 set(HW_LINK_LIBS IOKit ${HW_LINK_LIBS}) |
186 list(APPEND HW_LINK_LIBS avwrapper) |
158 |
187 endif() |
159 if(NOT NOAUTOUPDATE) |
188 endif() |
160 find_package(Sparkle) |
189 |
161 if(SPARKLE_FOUND) |
190 qt5_add_resources(hwfr_rez_src ${hwfr_rez}) |
162 add_definitions(-DSPARKLE_ENABLED) |
191 |
163 set(hwfr_src ${hwfr_src} AutoUpdater.cpp SparkleAutoUpdater.mm) |
192 qt5_wrap_cpp(hwfr_moc_srcs ${hwfr_moc_hdrs}) |
164 set(HW_LINK_LIBS ${SPARKLE_LIBRARY} ${HW_LINK_LIBS}) |
193 |
165 endif() |
194 |
166 endif() |
195 if(APPLE) |
167 endif() |
196 find_library(iokit_framework NAMES IOKit) |
168 |
197 list(APPEND HW_LINK_LIBS ${iokit_framework}) |
169 |
198 list(APPEND hwfr_src util/platform/CocoaInitializer.mm |
170 add_executable(hedgewars WIN32 |
199 util/platform/InstallController.cpp |
|
200 util/platform/M3Panel.mm |
|
201 util/platform/M3InstallController.m |
|
202 util/platform/NSWorkspace_RBAdditions.m |
|
203 ) |
|
204 include(${CMAKE_MODULE_PATH}/utils.cmake) |
|
205 find_package_or_disable_msg(Sparkle NOAUTOUPDATE "Autoupdater will not be built.") |
|
206 if(SPARKLE_FOUND) |
|
207 add_definitions(-DSPARKLE_ENABLED) |
|
208 list(APPEND hwfr_src util/platform/AutoUpdater.cpp |
|
209 util/platform/SparkleAutoUpdater.mm) |
|
210 list(APPEND HW_LINK_LIBS ${SPARKLE_LIBRARY}) |
|
211 endif() |
|
212 endif() |
|
213 |
|
214 #when debugging, always prompt a console to see fronted messages |
|
215 #TODO: check it doesn't interfere on UNIX |
|
216 if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") |
|
217 set(console_access "WIN32") |
|
218 endif(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") |
|
219 |
|
220 add_executable(hedgewars ${console_access} |
171 ${hwfr_src} |
221 ${hwfr_src} |
172 ${hwfr_moc_srcs} |
222 ${hwfr_moc_srcs} |
173 ${hwfr_hdrs} |
223 ${hwfr_hdrs} |
174 ${hwfr_rez_src} |
224 ${hwfr_rez_src} |
175 ) |
225 ) |
176 |
226 |
177 |
227 list(APPEND HW_LINK_LIBS |
178 set(HW_LINK_LIBS |
228 physfs physlayer |
179 quazip |
229 Qt5::Core Qt5::Widgets Qt5::Gui Qt5::Network |
180 ${QT_LIBRARIES} |
230 ) |
181 ${SDL_LIBRARY} |
231 |
182 ${SDLMIXER_LIBRARY} |
232 list(APPEND HW_LINK_LIBS |
183 ${FFMPEG_LIBRARIES} |
233 ${SDL2_LIBRARY} |
184 ${HW_LINK_LIBS} |
234 ${SDL2_MIXER_LIBRARIES} |
185 ) |
235 ) |
186 |
236 |
187 if(WIN32 AND NOT UNIX) |
237 if(WIN32 AND NOT UNIX) |
188 if(NOT SDL_LIBRARY) |
238 if(NOT SDL2_LIBRARY) |
189 set(HW_LINK_LIBS ${HW_LINK_LIBS} SDL) |
239 list(APPEND HW_LINK_LIBS SDL2) |
190 endif() |
240 endif() |
191 |
241 |
192 set(HW_LINK_LIBS |
242 list(APPEND HW_LINK_LIBS |
193 ${HW_LINK_LIBS} |
|
194 ole32 |
243 ole32 |
195 oleaut32 |
244 oleaut32 |
196 winspool |
245 winspool |
197 uuid |
246 uuid |
198 ) |
247 ) |
199 endif() |
248 endif() |
200 |
249 |
201 |
250 if(CMAKE_CXX_COMPILER MATCHES "clang*") |
202 if (CROSSAPPLE) |
251 list(APPEND HW_LINK_LIBS stdc++ m) |
203 add_dependencies(hedgewars quazip) |
252 if(NOT APPLE) |
204 else() |
253 list(APPEND HW_LINK_LIBS atomic) |
205 target_link_libraries(hedgewars ${HW_LINK_LIBS}) |
254 endif() |
206 endif() |
255 endif() |
207 |
256 |
208 |
257 if(WIN32 AND VCPKG_TOOLCHAIN) |
209 install(PROGRAMS "${EXECUTABLE_OUTPUT_PATH}/hedgewars${CMAKE_EXECUTABLE_SUFFIX}" DESTINATION ${target_dir}) |
258 list(APPEND HW_LINK_LIBS Qt5::WinMain) |
210 |
259 endif() |
|
260 |
|
261 target_link_libraries(hedgewars ${HW_LINK_LIBS}) |
|
262 |
|
263 |
|
264 install(PROGRAMS "${EXECUTABLE_OUTPUT_PATH}/hedgewars${CMAKE_EXECUTABLE_SUFFIX}" DESTINATION ${target_binary_install_dir}) |
|
265 |