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
2c2c318c sago007 2016-01-17 15:17 44
#Setup SDL2
e566d265 sago007 2016-01-16 14:19 45
find_package(SDL2 REQUIRED)
e38af775 Poul Sander 2023-01-15 18:27 46
5614ab55 sago007 2016-01-17 13:44 47
2c2c318c sago007 2016-01-17 15:17 48
#Setup things that use pkg-config
5614ab55 sago007 2016-01-17 13:44 49
find_package(PkgConfig REQUIRED)
5614ab55 sago007 2016-01-17 13:44 50
pkg_search_module(SDL2MIXER REQUIRED SDL2_mixer)
5614ab55 sago007 2016-01-17 13:44 51
pkg_search_module(SDL2IMAGE REQUIRED SDL2_image)
5614ab55 sago007 2016-01-17 13:44 52
pkg_search_module(SDL2TTF REQUIRED SDL2_ttf)
5614ab55 sago007 2016-01-17 13:44 53
c8c45c95 Poul Sander 2020-08-15 15:40 54
d20eb8bb Poul Sander 2022-04-14 20:28 55
find_package(Intl REQUIRED)
d20eb8bb Poul Sander 2022-04-14 20:28 56
6b9ddfc4 Poul Sander 2025-02-22 10:16 57
find_package(Boost COMPONENTS program_options REQUIRED NO_MODULE)
c8b43ea3 sago007 2016-02-02 18:20 58
2c2c318c sago007 2016-01-17 15:17 59
#Find all sources but one
55dd2d96 Poul Sander 2025-12-04 17:25 60
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 61
#I am still trying to get BlockGame to compile as a source file
1f6aecf9 sago007 2016-02-20 12:53 62
#list(REMOVE_ITEM SOURCES "${blockattack_SOURCE_DIR}/source/code/BlockGame.cpp")
2c2c318c sago007 2016-01-17 15:17 63
2c2c318c sago007 2016-01-17 15:17 64
#Some messages to figure out what cmake does
e566d265 sago007 2016-01-16 14:19 65
message("${SOURCES}")
5614ab55 sago007 2016-01-17 13:44 66
message("${CMAKE_EXE_LINKER_FLAGS}")
2c2c318c sago007 2016-01-17 15:17 67
f8deb5b9 Poul Sander 2022-01-15 13:55 68
if (BLOCKATTACK_USE_EMBEDDED_FMT)
f8deb5b9 Poul Sander 2022-01-15 13:55 69
	message("Using embedded {fmt}")
47fd5c32 Poul Sander 2024-10-05 08:44 70
	add_subdirectory("source/misc/embedded_libs/fmt-11.0.2" EXCLUDE_FROM_ALL)
f8deb5b9 Poul Sander 2022-01-15 13:55 71
	message("Done processing {fmt}")
f8deb5b9 Poul Sander 2022-01-15 13:55 72
endif()
f8deb5b9 Poul Sander 2022-01-15 13:55 73
c74066db Poul Sander 2022-02-16 12:14 74
if (BLOCKATTACK_USE_EMBEDDED_PLATFORM_FOLDERS)
c74066db Poul Sander 2022-02-16 12:14 75
	message("Using embedded PlatformFolders")
c74066db Poul Sander 2022-02-16 12:14 76
	add_subdirectory("source/misc/embedded_libs/PlatformFolders-4.2.0" EXCLUDE_FROM_ALL)
c74066db Poul Sander 2022-02-16 12:14 77
	message("Done processing PlatformFolders")
c74066db Poul Sander 2022-02-16 12:14 78
endif()
c74066db Poul Sander 2022-02-16 12:14 79
7a956470 sago007 2016-02-14 17:09 80
2c2c318c sago007 2016-01-17 15:17 81
#building/compiling/linking
e35cd386 Poul Sander 2023-11-29 20:33 82
add_executable(blockattack ${GUI_TYPE} ${SOURCES} ${RES_FILES}
e35cd386 Poul Sander 2023-11-29 20:33 83
    source/code/menudef_themes.cpp
e35cd386 Poul Sander 2023-11-29 20:33 84
    source/code/menudef_themes.hpp)
e38af775 Poul Sander 2023-01-15 18:27 85
55dd2d96 Poul Sander 2025-12-04 17:25 86
# Modern target-based compiler settings
55dd2d96 Poul Sander 2025-12-04 17:25 87
target_compile_features(blockattack PRIVATE cxx_std_17)
55dd2d96 Poul Sander 2025-12-04 17:25 88
target_compile_options(blockattack PRIVATE
e020b763 Poul Sander 2025-12-04 19:29 89
	$<$<CXX_COMPILER_ID:GNU,Clang>:-Wall -Wextra>
55dd2d96 Poul Sander 2025-12-04 17:25 90
	$<$<CONFIG:Debug>:-g>
55dd2d96 Poul Sander 2025-12-04 17:25 91
	$<$<AND:$<BOOL:${WIN32}>,$<CXX_COMPILER_ID:GNU>>:-march=i686>
55dd2d96 Poul Sander 2025-12-04 17:25 92
)
55dd2d96 Poul Sander 2025-12-04 17:25 93
target_compile_definitions(blockattack PRIVATE
55dd2d96 Poul Sander 2025-12-04 17:25 94
	$<$<CONFIG:Debug>:DEBUG>
55dd2d96 Poul Sander 2025-12-04 17:25 95
	$<$<AND:$<BOOL:${WIN32}>,$<NOT:$<BOOL:${_WIN32_WINNT}>>>:_WIN32_WINNT=0x0601>
55dd2d96 Poul Sander 2025-12-04 17:25 96
	$<$<AND:$<BOOL:${WIN32}>,$<NOT:$<BOOL:${WINVER}>>>:WINVER=0x0601>
55dd2d96 Poul Sander 2025-12-04 17:25 97
)
55dd2d96 Poul Sander 2025-12-04 17:25 98
55dd2d96 Poul Sander 2025-12-04 17:25 99
# Platform-specific definitions for data and locale directories
55dd2d96 Poul Sander 2025-12-04 17:25 100
if (NOT WIN32 AND NOT STANDALONE)
55dd2d96 Poul Sander 2025-12-04 17:25 101
	if (IS_ABSOLUTE ${INSTALL_DATA_DIR})
55dd2d96 Poul Sander 2025-12-04 17:25 102
		target_compile_definitions(blockattack PRIVATE SHAREDIR="${INSTALL_DATA_DIR}")
55dd2d96 Poul Sander 2025-12-04 17:25 103
	else()
55dd2d96 Poul Sander 2025-12-04 17:25 104
		target_compile_definitions(blockattack PRIVATE SHAREDIR="${CMAKE_INSTALL_PREFIX}/${INSTALL_DATA_DIR}")
55dd2d96 Poul Sander 2025-12-04 17:25 105
	endif()
55dd2d96 Poul Sander 2025-12-04 17:25 106
	if (IS_ABSOLUTE ${INSTALL_LOCALE_DIR})
55dd2d96 Poul Sander 2025-12-04 17:25 107
		target_compile_definitions(blockattack PRIVATE LOCALEDIR="${INSTALL_LOCALE_DIR}")
55dd2d96 Poul Sander 2025-12-04 17:25 108
	else()
55dd2d96 Poul Sander 2025-12-04 17:25 109
		target_compile_definitions(blockattack PRIVATE LOCALEDIR="${CMAKE_INSTALL_PREFIX}/${INSTALL_LOCALE_DIR}")
55dd2d96 Poul Sander 2025-12-04 17:25 110
	endif()
55dd2d96 Poul Sander 2025-12-04 17:25 111
endif()
55dd2d96 Poul Sander 2025-12-04 17:25 112
55dd2d96 Poul Sander 2025-12-04 17:25 113
target_include_directories(blockattack SYSTEM PRIVATE "source/code/Libs/imgui")
e38af775 Poul Sander 2023-01-15 18:27 114
target_include_directories(blockattack PRIVATE "source/code/Libs/include")
e38af775 Poul Sander 2023-01-15 18:27 115
target_include_directories(blockattack PRIVATE "source/code/Libs/include/cereal/external")  #Contains rapidjson
e38af775 Poul Sander 2023-01-15 18:27 116
target_include_directories(blockattack PRIVATE ${SDL2_INCLUDE_DIRS})
e38af775 Poul Sander 2023-01-15 18:27 117
target_include_directories(blockattack PRIVATE ${SDL2MIXER_INCLUDE_DIRS})
e38af775 Poul Sander 2023-01-15 18:27 118
target_include_directories(blockattack PRIVATE ${SDL2IMAGE_INCLUDE_DIRS})
e38af775 Poul Sander 2023-01-15 18:27 119
target_include_directories(blockattack PRIVATE ${SDL2TTF_INCLUDE_DIRS})
e38af775 Poul Sander 2023-01-15 18:27 120
target_include_directories(blockattack PRIVATE ${Intl_INCLUDE_DIRS})
e38af775 Poul Sander 2023-01-15 18:27 121
e38af775 Poul Sander 2023-01-15 18:27 122
target_link_libraries(blockattack PRIVATE ${SDL2_LIBRARIES})
e38af775 Poul Sander 2023-01-15 18:27 123
target_link_libraries(blockattack PRIVATE fmt)
e38af775 Poul Sander 2023-01-15 18:27 124
target_link_libraries(blockattack PRIVATE platform_folders)
e38af775 Poul Sander 2023-01-15 18:27 125
target_link_libraries(blockattack PRIVATE physfs)
d20eb8bb Poul Sander 2022-04-14 20:28 126
if (MACOSX)
e38af775 Poul Sander 2023-01-15 18:27 127
	target_link_libraries(blockattack PRIVATE intl)
d20eb8bb Poul Sander 2022-04-14 20:28 128
endif()
e38af775 Poul Sander 2023-01-15 18:27 129
target_link_libraries(blockattack PRIVATE ${SDL2MIXER_LIBRARIES} ${SDL2IMAGE_LIBRARIES} ${SDL2TTF_LIBRARIES})
e38af775 Poul Sander 2023-01-15 18:27 130
target_link_libraries(blockattack PRIVATE ${Boost_LIBRARIES} )
e38af775 Poul Sander 2023-01-15 18:27 131
set_target_properties(blockattack PROPERTIES RUNTIME_OUTPUT_DIRECTORY Game)
2c2c318c sago007 2016-01-17 15:17 132
2c2c318c sago007 2016-01-17 15:17 133
#Installing
2c2c318c sago007 2016-01-17 15:17 134
install(TARGETS blockattack RUNTIME DESTINATION ${INSTALL_BIN_DIR} )
2c2c318c sago007 2016-01-17 15:17 135
install(FILES Game/blockattack.data DESTINATION ${INSTALL_DATA_DIR} )
ffe60429 Poul Sander 2022-01-15 10:52 136
install(FILES Game/mods/1.3.0.bricks.data DESTINATION "${INSTALL_DATA_DIR}/mods" )
2c2c318c sago007 2016-01-17 15:17 137
install(FILES man/blockattack.6.gz DESTINATION ${INSTALL_MAN_DIR} )
2c2c318c sago007 2016-01-17 15:17 138
install(FILES source/misc/blockattack.desktop DESTINATION ${INSTALL_APPLICATIONS_DIR} )
28735382 sago007 2019-04-28 11:01 139
install(FILES source/misc/net.blockattack.game.metainfo.xml DESTINATION ${INSTALL_METAINFO_DIR} )
8642f439 Pino Toscano 2021-04-21 18:43 140
install(FILES source/misc/icons/blockattack16.png DESTINATION "${INSTALL_ICONS_DIR}/16x16/apps" RENAME blockattack.png )
8642f439 Pino Toscano 2021-04-21 18:43 141
install(FILES source/misc/icons/blockattack48.png DESTINATION "${INSTALL_ICONS_DIR}/48x48/apps" RENAME blockattack.png )
8642f439 Pino Toscano 2021-04-21 18:43 142
install(FILES source/misc/icons/blockattack128.png DESTINATION "${INSTALL_ICONS_DIR}/128x128/apps" RENAME blockattack.png )
8642f439 Pino Toscano 2021-04-21 18:43 143
install(FILES source/misc/icons/blockattack256.png DESTINATION "${INSTALL_ICONS_DIR}/256x256/apps" RENAME blockattack.png )
8642f439 Pino Toscano 2021-04-21 18:43 144
install(FILES source/misc/icons/blockattack64.png DESTINATION "${INSTALL_ICONS_DIR}/64x64/apps" RENAME blockattack.png )
8642f439 Pino Toscano 2021-04-21 18:43 145
install(FILES source/misc/icons/blockattack32.png DESTINATION "${INSTALL_ICONS_DIR}/32x32/apps" RENAME blockattack.png )
b1a99ae7 Poul Sander 2016-05-27 21:08 146
install(DIRECTORY source/misc/translation/locale/ DESTINATION "${INSTALL_LOCALE_DIR}")
1970-01-01 00:00 147