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