git repos / blockattack-game

blame: CMakeLists.txt

normal view · raw

8895cf70 Poul Sander 2025-10-14 19:57 1
cmake_minimum_required(VERSION 3.5.1...4.1.0)
e566d265 sago007 2016-01-16 14:19 2
project (blockattack)
0ca01b16 Poul Sander 2025-12-17 19:25 3
0ca01b16 Poul Sander 2025-12-17 19:25 4
if(NOT CMAKE_BUILD_TYPE)
0ca01b16 Poul Sander 2025-12-17 19:25 5
    set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type" FORCE)
0ca01b16 Poul Sander 2025-12-17 19:25 6
endif()
0ca01b16 Poul Sander 2025-12-17 19:25 7
e566d265 sago007 2016-01-16 14:19 8
set(BIN_DIR ${blockattack_SOURCE_DIR}/Game)
e566d265 sago007 2016-01-16 14:19 9
34503a05 Poul Sander 2025-10-26 10:39 10
SET(CPACK_PACKAGE_VERSION "2.11.0-SNAPSHOT")
b1a99ae7 Poul Sander 2016-05-27 21:08 11
SET(CPACK_PACKAGE_VERSION_MAJOR "2")
34503a05 Poul Sander 2025-10-26 10:39 12
SET(CPACK_PACKAGE_VERSION_MINOR "11")
b1a99ae7 Poul Sander 2016-05-27 21:08 13
SET(CPACK_PACKAGE_VERSION_PATCH "0")
b1a99ae7 Poul Sander 2016-05-27 21:08 14
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Block Attack - Rise of the Blocks ${CPACK_PACKAGE_VERSION}")
b1a99ae7 Poul Sander 2016-05-27 21:08 15
SET(CPACK_PACKAGE_VENDOR "Poul Sander")
b1a99ae7 Poul Sander 2016-05-27 21:08 16
5614ab55 sago007 2016-01-17 13:44 17
# Define install paths
b1a99ae7 Poul Sander 2016-05-27 21:08 18
set(INSTALL_BIN_DIR "bin" CACHE STRING "Install executable in this directory")
b1a99ae7 Poul Sander 2016-05-27 21:08 19
set(INSTALL_DATA_DIR "share/blockattack" CACHE STRING "Install data to this directory")
b240dbfa Michael Straube 2017-01-09 18:25 20
set(INSTALL_MAN_DIR "share/man/man6" CACHE STRING "Install the man page to this directory")
b240dbfa Michael Straube 2017-01-09 18:25 21
set(INSTALL_APPLICATIONS_DIR "share/applications" CACHE STRING "Install the .desktop file to this directory")
b240dbfa Michael Straube 2017-01-09 18:25 22
set(INSTALL_ICONS_DIR "share/icons/hicolor" CACHE STRING "Install the icon in a subfolder in this directory")
9779d6e3 sago007 2016-04-30 11:35 23
set(INSTALL_LOCALE_DIR "${INSTALL_DATA_DIR}/locale/" CACHE STRING "Install translation to this dir")
28735382 sago007 2019-04-28 11:01 24
set(INSTALL_METAINFO_DIR "share/metainfo" CACHE STRING "Install appstream matedata to this directory")
2c2c318c sago007 2016-01-17 15:17 25
f8deb5b9 Poul Sander 2022-01-15 13:55 26
option(BLOCKATTACK_USE_EMBEDDED_FMT "Use the embedded version of {fmt}" ON)
c74066db Poul Sander 2022-02-16 12:14 27
option(BLOCKATTACK_USE_EMBEDDED_PLATFORM_FOLDERS "Use the embedded version of PlatformFolders" ON)
f8deb5b9 Poul Sander 2022-01-15 13:55 28
daad7b02 sago007 2016-01-19 19:33 29
# This sets up the exe icon for windows under mingw.
daad7b02 sago007 2016-01-19 19:33 30
# Taken from https://hansonry.wordpress.com/2010/12/15/windows-application-icon-using-mingw-and-cmake/
daad7b02 sago007 2016-01-19 19:33 31
set(RES_FILES "")
daad7b02 sago007 2016-01-19 19:33 32
if(MINGW)
daad7b02 sago007 2016-01-19 19:33 33
 set(RES_FILES "${blockattack_SOURCE_DIR}/source/code/winicon.rc")
daad7b02 sago007 2016-01-19 19:33 34
 set(CMAKE_RC_COMPILER_INIT windres)
daad7b02 sago007 2016-01-19 19:33 35
 ENABLE_LANGUAGE(RC)
daad7b02 sago007 2016-01-19 19:33 36
 SET(CMAKE_RC_COMPILE_OBJECT
daad7b02 sago007 2016-01-19 19:33 37
 "<CMAKE_RC_COMPILER> <FLAGS> -O coff <DEFINES> -i <SOURCE> -o <OBJECT>")
daad7b02 sago007 2016-01-19 19:33 38
endif(MINGW)
daad7b02 sago007 2016-01-19 19:33 39
daad7b02 sago007 2016-01-19 19:33 40
if (WIN32)
6b427a55 Poul Sander 2019-02-13 17:49 41
      SET(GUI_TYPE WIN32)
344e2b89 sago007 2016-01-18 21:33 42
endif()
e566d265 sago007 2016-01-16 14:19 43
d20eb8bb Poul Sander 2022-04-14 20:28 44
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
d20eb8bb Poul Sander 2022-04-14 20:28 45
    set(MACOSX TRUE)
d20eb8bb Poul Sander 2022-04-14 20:28 46
endif()
d20eb8bb Poul Sander 2022-04-14 20:28 47
d609b85b Poul Sander 2025-12-04 20:11 48
# Setup SDL2 and extensions
e566d265 sago007 2016-01-16 14:19 49
find_package(SDL2 REQUIRED)
e38af775 Poul Sander 2023-01-15 18:27 50
d609b85b Poul Sander 2025-12-04 20:11 51
# Try modern CMake approach first, fallback to pkg-config for cross-compilation (e.g., MXE)
d609b85b Poul Sander 2025-12-04 20:11 52
find_package(SDL2_image QUIET)
d609b85b Poul Sander 2025-12-04 20:11 53
find_package(SDL2_mixer QUIET)
d609b85b Poul Sander 2025-12-04 20:11 54
find_package(SDL2_ttf QUIET)
5614ab55 sago007 2016-01-17 13:44 55
ff3c3984 Poul Sander 2025-12-06 20:57 56
set(SDL2_USE_PKGCONFIG OFF)
d609b85b Poul Sander 2025-12-04 20:11 57
if(NOT SDL2_image_FOUND OR NOT SDL2_mixer_FOUND OR NOT SDL2_ttf_FOUND)
ff3c3984 Poul Sander 2025-12-06 20:57 58
	set(SDL2_USE_PKGCONFIG ON)
d609b85b Poul Sander 2025-12-04 20:11 59
	find_package(PkgConfig REQUIRED)
ff3c3984 Poul Sander 2025-12-06 20:57 60
	# When using pkg-config, always search for all SDL2 extensions
ff3c3984 Poul Sander 2025-12-06 20:57 61
	pkg_search_module(SDL2_image REQUIRED SDL2_image)
ff3c3984 Poul Sander 2025-12-06 20:57 62
	pkg_search_module(SDL2_mixer REQUIRED SDL2_mixer)
ff3c3984 Poul Sander 2025-12-06 20:57 63
	pkg_search_module(SDL2_ttf REQUIRED SDL2_ttf)
d609b85b Poul Sander 2025-12-04 20:11 64
endif()
5614ab55 sago007 2016-01-17 13:44 65
c8c45c95 Poul Sander 2020-08-15 15:40 66
d20eb8bb Poul Sander 2022-04-14 20:28 67
find_package(Intl REQUIRED)
d20eb8bb Poul Sander 2022-04-14 20:28 68
6b9ddfc4 Poul Sander 2025-02-22 10:16 69
find_package(Boost COMPONENTS program_options REQUIRED NO_MODULE)
c8b43ea3 sago007 2016-02-02 18:20 70
2c2c318c sago007 2016-01-17 15:17 71
#Find all sources but one
55dd2d96 Poul Sander 2025-12-04 17:25 72
file(GLOB SOURCES CONFIGURE_DEPENDS "source/code/*.cpp" "source/code/*.inc" "source/code/*.h*" "source/code/*/*.cpp" "source/code/*/*.h*" "source/code/Libs/*.c" "source/code/Libs/*.h*" "source/code/Libs/*/*.cpp" "source/code/Libs/*/*/*.cpp")
e566d265 sago007 2016-01-16 14:19 73
#I am still trying to get BlockGame to compile as a source file
1f6aecf9 sago007 2016-02-20 12:53 74
#list(REMOVE_ITEM SOURCES "${blockattack_SOURCE_DIR}/source/code/BlockGame.cpp")
2c2c318c sago007 2016-01-17 15:17 75
2c2c318c sago007 2016-01-17 15:17 76
#Some messages to figure out what cmake does
e566d265 sago007 2016-01-16 14:19 77
message("${SOURCES}")
5614ab55 sago007 2016-01-17 13:44 78
message("${CMAKE_EXE_LINKER_FLAGS}")
2c2c318c sago007 2016-01-17 15:17 79
f8deb5b9 Poul Sander 2022-01-15 13:55 80
if (BLOCKATTACK_USE_EMBEDDED_FMT)
f8deb5b9 Poul Sander 2022-01-15 13:55 81
	message("Using embedded {fmt}")
47fd5c32 Poul Sander 2024-10-05 08:44 82
	add_subdirectory("source/misc/embedded_libs/fmt-11.0.2" EXCLUDE_FROM_ALL)
f8deb5b9 Poul Sander 2022-01-15 13:55 83
	message("Done processing {fmt}")
f8deb5b9 Poul Sander 2022-01-15 13:55 84
endif()
f8deb5b9 Poul Sander 2022-01-15 13:55 85
c74066db Poul Sander 2022-02-16 12:14 86
if (BLOCKATTACK_USE_EMBEDDED_PLATFORM_FOLDERS)
c74066db Poul Sander 2022-02-16 12:14 87
	message("Using embedded PlatformFolders")
c74066db Poul Sander 2022-02-16 12:14 88
	add_subdirectory("source/misc/embedded_libs/PlatformFolders-4.2.0" EXCLUDE_FROM_ALL)
c74066db Poul Sander 2022-02-16 12:14 89
	message("Done processing PlatformFolders")
c74066db Poul Sander 2022-02-16 12:14 90
endif()
c74066db Poul Sander 2022-02-16 12:14 91
7a956470 sago007 2016-02-14 17:09 92
2c2c318c sago007 2016-01-17 15:17 93
#building/compiling/linking
e35cd386 Poul Sander 2023-11-29 20:33 94
add_executable(blockattack ${GUI_TYPE} ${SOURCES} ${RES_FILES}
e35cd386 Poul Sander 2023-11-29 20:33 95
    source/code/menudef_themes.cpp
e35cd386 Poul Sander 2023-11-29 20:33 96
    source/code/menudef_themes.hpp)
e38af775 Poul Sander 2023-01-15 18:27 97
55dd2d96 Poul Sander 2025-12-04 17:25 98
# Modern target-based compiler settings
55dd2d96 Poul Sander 2025-12-04 17:25 99
target_compile_features(blockattack PRIVATE cxx_std_17)
55dd2d96 Poul Sander 2025-12-04 17:25 100
target_compile_options(blockattack PRIVATE
e020b763 Poul Sander 2025-12-04 19:29 101
	$<$<CXX_COMPILER_ID:GNU,Clang>:-Wall -Wextra>
55dd2d96 Poul Sander 2025-12-04 17:25 102
	$<$<CONFIG:Debug>:-g>
55dd2d96 Poul Sander 2025-12-04 17:25 103
	$<$<AND:$<BOOL:${WIN32}>,$<CXX_COMPILER_ID:GNU>>:-march=i686>
55dd2d96 Poul Sander 2025-12-04 17:25 104
)
55dd2d96 Poul Sander 2025-12-04 17:25 105
target_compile_definitions(blockattack PRIVATE
55dd2d96 Poul Sander 2025-12-04 17:25 106
	$<$<CONFIG:Debug>:DEBUG>
55dd2d96 Poul Sander 2025-12-04 17:25 107
	$<$<AND:$<BOOL:${WIN32}>,$<NOT:$<BOOL:${_WIN32_WINNT}>>>:_WIN32_WINNT=0x0601>
55dd2d96 Poul Sander 2025-12-04 17:25 108
	$<$<AND:$<BOOL:${WIN32}>,$<NOT:$<BOOL:${WINVER}>>>:WINVER=0x0601>
55dd2d96 Poul Sander 2025-12-04 17:25 109
)
55dd2d96 Poul Sander 2025-12-04 17:25 110
55dd2d96 Poul Sander 2025-12-04 17:25 111
# Platform-specific definitions for data and locale directories
55dd2d96 Poul Sander 2025-12-04 17:25 112
if (NOT WIN32 AND NOT STANDALONE)
55dd2d96 Poul Sander 2025-12-04 17:25 113
	if (IS_ABSOLUTE ${INSTALL_DATA_DIR})
55dd2d96 Poul Sander 2025-12-04 17:25 114
		target_compile_definitions(blockattack PRIVATE SHAREDIR="${INSTALL_DATA_DIR}")
55dd2d96 Poul Sander 2025-12-04 17:25 115
	else()
55dd2d96 Poul Sander 2025-12-04 17:25 116
		target_compile_definitions(blockattack PRIVATE SHAREDIR="${CMAKE_INSTALL_PREFIX}/${INSTALL_DATA_DIR}")
55dd2d96 Poul Sander 2025-12-04 17:25 117
	endif()
55dd2d96 Poul Sander 2025-12-04 17:25 118
	if (IS_ABSOLUTE ${INSTALL_LOCALE_DIR})
55dd2d96 Poul Sander 2025-12-04 17:25 119
		target_compile_definitions(blockattack PRIVATE LOCALEDIR="${INSTALL_LOCALE_DIR}")
55dd2d96 Poul Sander 2025-12-04 17:25 120
	else()
55dd2d96 Poul Sander 2025-12-04 17:25 121
		target_compile_definitions(blockattack PRIVATE LOCALEDIR="${CMAKE_INSTALL_PREFIX}/${INSTALL_LOCALE_DIR}")
55dd2d96 Poul Sander 2025-12-04 17:25 122
	endif()
55dd2d96 Poul Sander 2025-12-04 17:25 123
endif()
55dd2d96 Poul Sander 2025-12-04 17:25 124
55dd2d96 Poul Sander 2025-12-04 17:25 125
target_include_directories(blockattack SYSTEM PRIVATE "source/code/Libs/imgui")
e38af775 Poul Sander 2023-01-15 18:27 126
target_include_directories(blockattack PRIVATE "source/code/Libs/include")
e38af775 Poul Sander 2023-01-15 18:27 127
target_include_directories(blockattack PRIVATE "source/code/Libs/include/cereal/external")  #Contains rapidjson
ff3c3984 Poul Sander 2025-12-06 20:57 128
if(SDL2_USE_PKGCONFIG)
d609b85b Poul Sander 2025-12-04 20:11 129
	target_include_directories(blockattack PRIVATE ${SDL2_image_INCLUDE_DIRS})
d609b85b Poul Sander 2025-12-04 20:11 130
	target_include_directories(blockattack PRIVATE ${SDL2_mixer_INCLUDE_DIRS})
d609b85b Poul Sander 2025-12-04 20:11 131
	target_include_directories(blockattack PRIVATE ${SDL2_ttf_INCLUDE_DIRS})
ff3c3984 Poul Sander 2025-12-06 20:57 132
	# Add library directories for pkg-config-based libraries
ff3c3984 Poul Sander 2025-12-06 20:57 133
	target_link_directories(blockattack PRIVATE ${SDL2_image_LIBRARY_DIRS})
ff3c3984 Poul Sander 2025-12-06 20:57 134
	target_link_directories(blockattack PRIVATE ${SDL2_mixer_LIBRARY_DIRS})
ff3c3984 Poul Sander 2025-12-06 20:57 135
	target_link_directories(blockattack PRIVATE ${SDL2_ttf_LIBRARY_DIRS})
d609b85b Poul Sander 2025-12-04 20:11 136
endif()
e38af775 Poul Sander 2023-01-15 18:27 137
target_include_directories(blockattack PRIVATE ${Intl_INCLUDE_DIRS})
e38af775 Poul Sander 2023-01-15 18:27 138
d609b85b Poul Sander 2025-12-04 20:11 139
target_link_libraries(blockattack PRIVATE
d609b85b Poul Sander 2025-12-04 20:11 140
	SDL2::SDL2
d609b85b Poul Sander 2025-12-04 20:11 141
	fmt
d609b85b Poul Sander 2025-12-04 20:11 142
	platform_folders
d609b85b Poul Sander 2025-12-04 20:11 143
	physfs
d609b85b Poul Sander 2025-12-04 20:11 144
	${Boost_LIBRARIES}
d609b85b Poul Sander 2025-12-04 20:11 145
)
d609b85b Poul Sander 2025-12-04 20:11 146
d609b85b Poul Sander 2025-12-04 20:11 147
# Link SDL2 extensions - use imported targets if available, otherwise use pkg-config variables
ff3c3984 Poul Sander 2025-12-06 20:57 148
if(SDL2_USE_PKGCONFIG)
ff3c3984 Poul Sander 2025-12-06 20:57 149
	target_link_libraries(blockattack PRIVATE ${SDL2_image_LINK_LIBRARIES} ${SDL2_mixer_LINK_LIBRARIES} ${SDL2_ttf_LINK_LIBRARIES})
d609b85b Poul Sander 2025-12-04 20:11 150
else()
ff3c3984 Poul Sander 2025-12-06 20:57 151
	target_link_libraries(blockattack PRIVATE SDL2_image::SDL2_image SDL2_mixer::SDL2_mixer SDL2_ttf::SDL2_ttf)
d609b85b Poul Sander 2025-12-04 20:11 152
endif()
d609b85b Poul Sander 2025-12-04 20:11 153
d20eb8bb Poul Sander 2022-04-14 20:28 154
if (MACOSX)
e38af775 Poul Sander 2023-01-15 18:27 155
	target_link_libraries(blockattack PRIVATE intl)
d20eb8bb Poul Sander 2022-04-14 20:28 156
endif()
e38af775 Poul Sander 2023-01-15 18:27 157
set_target_properties(blockattack PROPERTIES RUNTIME_OUTPUT_DIRECTORY Game)
2c2c318c sago007 2016-01-17 15:17 158
2c2c318c sago007 2016-01-17 15:17 159
#Installing
0ca01b16 Poul Sander 2025-12-17 19:25 160
include(CPack)
2c2c318c sago007 2016-01-17 15:17 161
install(TARGETS blockattack RUNTIME DESTINATION ${INSTALL_BIN_DIR} )
2c2c318c sago007 2016-01-17 15:17 162
install(FILES Game/blockattack.data DESTINATION ${INSTALL_DATA_DIR} )
ffe60429 Poul Sander 2022-01-15 10:52 163
install(FILES Game/mods/1.3.0.bricks.data DESTINATION "${INSTALL_DATA_DIR}/mods" )
2c2c318c sago007 2016-01-17 15:17 164
install(FILES man/blockattack.6.gz DESTINATION ${INSTALL_MAN_DIR} )
2c2c318c sago007 2016-01-17 15:17 165
install(FILES source/misc/blockattack.desktop DESTINATION ${INSTALL_APPLICATIONS_DIR} )
28735382 sago007 2019-04-28 11:01 166
install(FILES source/misc/net.blockattack.game.metainfo.xml DESTINATION ${INSTALL_METAINFO_DIR} )
8642f439 Pino Toscano 2021-04-21 18:43 167
install(FILES source/misc/icons/blockattack16.png DESTINATION "${INSTALL_ICONS_DIR}/16x16/apps" RENAME blockattack.png )
8642f439 Pino Toscano 2021-04-21 18:43 168
install(FILES source/misc/icons/blockattack48.png DESTINATION "${INSTALL_ICONS_DIR}/48x48/apps" RENAME blockattack.png )
8642f439 Pino Toscano 2021-04-21 18:43 169
install(FILES source/misc/icons/blockattack128.png DESTINATION "${INSTALL_ICONS_DIR}/128x128/apps" RENAME blockattack.png )
8642f439 Pino Toscano 2021-04-21 18:43 170
install(FILES source/misc/icons/blockattack256.png DESTINATION "${INSTALL_ICONS_DIR}/256x256/apps" RENAME blockattack.png )
8642f439 Pino Toscano 2021-04-21 18:43 171
install(FILES source/misc/icons/blockattack64.png DESTINATION "${INSTALL_ICONS_DIR}/64x64/apps" RENAME blockattack.png )
8642f439 Pino Toscano 2021-04-21 18:43 172
install(FILES source/misc/icons/blockattack32.png DESTINATION "${INSTALL_ICONS_DIR}/32x32/apps" RENAME blockattack.png )
b1a99ae7 Poul Sander 2016-05-27 21:08 173
install(DIRECTORY source/misc/translation/locale/ DESTINATION "${INSTALL_LOCALE_DIR}")
1970-01-01 00:00 174