| 1 |
########################################################################### |
| 2 |
# fheroes2: https://github.com/ihhub/fheroes2 # |
| 3 |
# Copyright (C) 2022 - 2025 # |
| 4 |
# # |
| 5 |
# This program is free software; you can redistribute it and/or modify # |
| 6 |
# it under the terms of the GNU General Public License as published by # |
| 7 |
# the Free Software Foundation; either version 2 of the License, or # |
| 8 |
# (at your option) any later version. # |
| 9 |
# # |
| 10 |
# This program is distributed in the hope that it will be useful, # |
| 11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of # |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
| 13 |
# GNU General Public License for more details. # |
| 14 |
# # |
| 15 |
# You should have received a copy of the GNU General Public License # |
| 16 |
# along with this program; if not, write to the # |
| 17 |
# Free Software Foundation, Inc., # |
| 18 |
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # |
| 19 |
########################################################################### |
| 20 |
|
| 21 |
cmake_minimum_required(VERSION 3.24) |
| 22 |
cmake_policy(SET CMP0074 NEW) |
| 23 |
|
| 24 |
file(STRINGS ${CMAKE_SOURCE_DIR}/version.txt FHEROES2_VERSION LIMIT_COUNT 1 REGEX "^[0-9]+\.[0-9]+\.[0-9]+$") |
| 25 |
|
| 26 |
project(fheroes2 VERSION ${FHEROES2_VERSION} LANGUAGES C CXX) |
| 27 |
|
| 28 |
set(CMAKE_CXX_STANDARD 17) |
| 29 |
set(CMAKE_CXX_EXTENSIONS OFF) |
| 30 |
|
| 31 |
include(CMakeDependentOption) |
| 32 |
include(GNUInstallDirs) |
| 33 |
|
| 34 |
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) |
| 35 |
|
| 36 |
# |
| 37 |
# Compile-time options |
| 38 |
# |
| 39 |
option(ENABLE_IMAGE "Enable the use of SDL_image (requires libpng)" OFF) |
| 40 |
option(ENABLE_TOOLS "Enable the build of additional tools" OFF) |
| 41 |
|
| 42 |
# Available only on macOS |
| 43 |
cmake_dependent_option(MACOS_APP_BUNDLE "Create a Mac app bundle" OFF "APPLE" OFF) |
| 44 |
|
| 45 |
# Should not be available if we are creating a Mac app bundle |
| 46 |
cmake_dependent_option(GET_HOMM2_DEMO "Fetch and install the HoMM II demo data" OFF "NOT MACOS_APP_BUNDLE" OFF) |
| 47 |
|
| 48 |
set(USE_SDL_VERSION SDL2 CACHE STRING "Version of the SDL library used") |
| 49 |
set(FHEROES2_DATA ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME} CACHE STRING "Path to the fheroes2 data directory (relative to CMAKE_INSTALL_PREFIX)") |
| 50 |
|
| 51 |
# For ComboBox in CMake GUI |
| 52 |
set_property(CACHE USE_SDL_VERSION PROPERTY STRINGS SDL2) |
| 53 |
|
| 54 |
# |
| 55 |
# Library & feature detection |
| 56 |
# |
| 57 |
find_package(${USE_SDL_VERSION} REQUIRED) |
| 58 |
find_package(${USE_SDL_VERSION}_mixer REQUIRED) |
| 59 |
find_package(ZLIB REQUIRED) |
| 60 |
find_package(Threads) |
| 61 |
|
| 62 |
if(ENABLE_IMAGE) |
| 63 |
find_package(${USE_SDL_VERSION}_image REQUIRED) |
| 64 |
find_package(PNG REQUIRED) |
| 65 |
endif(ENABLE_IMAGE) |
| 66 |
|
| 67 |
# |
| 68 |
# Source files |
| 69 |
# |
| 70 |
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) |
| 71 |
|
| 72 |
add_subdirectory(src) |
| 73 |
|
| 74 |
# |
| 75 |
# Translation files |
| 76 |
# |
| 77 |
if(NOT WIN32) |
| 78 |
find_program(MAKE_EXECUTABLE make) |
| 79 |
|
| 80 |
add_custom_target( |
| 81 |
translations |
| 82 |
ALL |
| 83 |
COMMAND ${MAKE_EXECUTABLE} |
| 84 |
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/files/lang |
| 85 |
) |
| 86 |
endif(NOT WIN32) |
| 87 |
|
| 88 |
# |
| 89 |
# macOS app bundle |
| 90 |
# |
| 91 |
if(MACOS_APP_BUNDLE) |
| 92 |
add_custom_target( |
| 93 |
app_bundle_fh2m_maps |
| 94 |
ALL |
| 95 |
COMMAND mkdir -p ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PROJECT_NAME}.app/Contents/Resources/maps |
| 96 |
COMMAND cp *.fh2m ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PROJECT_NAME}.app/Contents/Resources/maps |
| 97 |
DEPENDS fheroes2 |
| 98 |
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/maps |
| 99 |
) |
| 100 |
add_custom_target( |
| 101 |
app_bundle_h2d_files |
| 102 |
ALL |
| 103 |
COMMAND mkdir -p ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PROJECT_NAME}.app/Contents/Resources/h2d |
| 104 |
COMMAND cp *.h2d ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PROJECT_NAME}.app/Contents/Resources/h2d |
| 105 |
DEPENDS fheroes2 |
| 106 |
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/files/data |
| 107 |
) |
| 108 |
add_custom_target( |
| 109 |
app_bundle_translations |
| 110 |
ALL |
| 111 |
COMMAND mkdir -p ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PROJECT_NAME}.app/Contents/Resources/translations |
| 112 |
COMMAND cp *.mo ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PROJECT_NAME}.app/Contents/Resources/translations |
| 113 |
DEPENDS translations |
| 114 |
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/files/lang |
| 115 |
) |
| 116 |
add_custom_target( |
| 117 |
run_dylibbundler |
| 118 |
ALL |
| 119 |
COMMAND dylibbundler -od -b -x ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PROJECT_NAME}.app/Contents/MacOS/${PROJECT_NAME} -d ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PROJECT_NAME}.app/Contents/libs |
| 120 |
DEPENDS fheroes2 app_bundle_fh2m_maps app_bundle_h2d_files app_bundle_translations |
| 121 |
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} |
| 122 |
) |
| 123 |
endif(MACOS_APP_BUNDLE) |
| 124 |
|
| 125 |
# |
| 126 |
# Installation of auxiliary files |
| 127 |
# |
| 128 |
if(NOT MACOS_APP_BUNDLE) |
| 129 |
install( |
| 130 |
DIRECTORY files/data/ |
| 131 |
DESTINATION ${FHEROES2_DATA}/files/data |
| 132 |
FILES_MATCHING |
| 133 |
PATTERN *.h2d |
| 134 |
) |
| 135 |
install( |
| 136 |
DIRECTORY maps/ |
| 137 |
DESTINATION ${FHEROES2_DATA}/maps |
| 138 |
FILES_MATCHING |
| 139 |
PATTERN *.fh2m |
| 140 |
) |
| 141 |
install( |
| 142 |
FILES docs/README.txt LICENSE changelog.txt |
| 143 |
DESTINATION ${CMAKE_INSTALL_DOCDIR} |
| 144 |
) |
| 145 |
|
| 146 |
if(GET_HOMM2_DEMO) |
| 147 |
include(FetchContent) |
| 148 |
|
| 149 |
set(FETCHCONTENT_QUIET OFF) |
| 150 |
|
| 151 |
FetchContent_Declare( |
| 152 |
demodata |
| 153 |
URL https://archive.org/download/HeroesofMightandMagicIITheSuccessionWars_1020/h2demo.zip |
| 154 |
URL_HASH SHA256=12048c8b03875c81e69534a3813aaf6340975e77b762dc1b79a4ff5514240e3c |
| 155 |
) |
| 156 |
FetchContent_MakeAvailable(demodata) |
| 157 |
|
| 158 |
file(COPY ${demodata_SOURCE_DIR}/DATA/ DESTINATION data PATTERN *.*) |
| 159 |
file(COPY ${demodata_SOURCE_DIR}/MAPS/ DESTINATION maps PATTERN *.*) |
| 160 |
|
| 161 |
install( |
| 162 |
DIRECTORY ${demodata_SOURCE_DIR}/DATA/ |
| 163 |
DESTINATION ${FHEROES2_DATA}/data |
| 164 |
FILES_MATCHING |
| 165 |
PATTERN *.* |
| 166 |
) |
| 167 |
install( |
| 168 |
DIRECTORY ${demodata_SOURCE_DIR}/MAPS/ |
| 169 |
DESTINATION ${FHEROES2_DATA}/maps |
| 170 |
FILES_MATCHING |
| 171 |
PATTERN *.* |
| 172 |
) |
| 173 |
endif(GET_HOMM2_DEMO) |
| 174 |
|
| 175 |
if(WIN32) |
| 176 |
install( |
| 177 |
FILES script/demo/download_demo_version.bat script/demo/download_demo_version.ps1 |
| 178 |
DESTINATION ${CMAKE_INSTALL_DOCDIR}/demo |
| 179 |
) |
| 180 |
install( |
| 181 |
FILES script/homm2/extract_homm2_resources.bat script/homm2/extract_homm2_resources.ps1 |
| 182 |
DESTINATION ${CMAKE_INSTALL_DOCDIR}/homm2 |
| 183 |
) |
| 184 |
install( |
| 185 |
FILES script/homm2/resource_extraction_toolset.bat script/homm2/resource_extraction_toolset.ps1 |
| 186 |
DESTINATION ${CMAKE_INSTALL_DOCDIR}/homm2 |
| 187 |
) |
| 188 |
else(WIN32) |
| 189 |
install( |
| 190 |
DIRECTORY files/lang/ |
| 191 |
DESTINATION ${FHEROES2_DATA}/files/lang |
| 192 |
FILES_MATCHING |
| 193 |
PATTERN *.mo |
| 194 |
) |
| 195 |
install( |
| 196 |
FILES script/demo/download_demo_version.sh |
| 197 |
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ |
| 198 |
DESTINATION ${CMAKE_INSTALL_DOCDIR}/demo |
| 199 |
) |
| 200 |
install( |
| 201 |
FILES script/homm2/extract_homm2_resources.sh |
| 202 |
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ |
| 203 |
DESTINATION ${CMAKE_INSTALL_DOCDIR}/homm2 |
| 204 |
) |
| 205 |
install( |
| 206 |
FILES script/packaging/common/fheroes2.metainfo.xml |
| 207 |
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/metainfo |
| 208 |
) |
| 209 |
install( |
| 210 |
FILES src/resources/fheroes2.png |
| 211 |
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/128x128/apps |
| 212 |
) |
| 213 |
install( |
| 214 |
FILES script/packaging/common/fheroes2.desktop |
| 215 |
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/applications |
| 216 |
) |
| 217 |
endif(WIN32) |
| 218 |
endif(NOT MACOS_APP_BUNDLE) |