-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
171 lines (154 loc) · 6.41 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
cmake_minimum_required(VERSION 3.12)
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
message(FATAL_ERROR "Please create a build directory. Building inside the oceanpop directory directly would prevent the asset directory from being build correctly.")
endif()
project(oceanpop)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
file(GLOB_RECURSE SRC src/*.cpp)
if(WIN32)
add_executable(${CMAKE_PROJECT_NAME} WIN32 ${SRC} ${CMAKE_CURRENT_SOURCE_DIR}/platform/windows/appicon.rc)
else()
add_executable(${CMAKE_PROJECT_NAME} ${SRC})
endif()
set(BUILD_STATIC_DEFAULT OFF)
if(WIN32 OR VITA OR PSP)
set(BUILD_STATIC_DEFAULT ON)
endif()
option(BUILD_STATIC "Build a static binary" ${BUILD_STATIC_DEFAULT})
# Find libraries
include(FindPkgConfig)
pkg_search_module(SDL2 REQUIRED sdl2)
pkg_search_module(SDL2_IMAGE REQUIRED SDL2_image)
pkg_search_module(SDL2_MIXER REQUIRED SDL2_mixer)
pkg_search_module(SDL2_TTF REQUIRED SDL2_ttf)
pkg_search_module(JSONCPP REQUIRED jsoncpp)
pkg_search_module(TINYGETTEXT QUIET tinygettext)
# Enable translation support by default if the tinygettext library is found
set(TRANSLATION_SUPPORT_DEFAULT OFF)
if(TINYGETTEXT_FOUND)
message("-- Found tinygettext library")
set(TRANSLATION_SUPPORT_DEFAULT ON)
endif()
option(TRANSLATION_SUPPORT "Add support for loading translations, requires tinygettext" ${TRANSLATION_SUPPORT_DEFAULT})
# Link libraries
if(BUILD_STATIC)
set(CMAKE_CXX_FLAGS "-static ${CMAKE_CXX_FLAGS}")
target_link_libraries(${PROJECT_NAME} PRIVATE
${SDL2_STATIC_LIBRARIES}
${SDL2_IMAGE_STATIC_LIBRARIES}
${SDL2_MIXER_STATIC_LIBRARIES}
${SDL2_TTF_STATIC_LIBRARIES}
${JSONCPP_STATIC_LIBRARIES}
)
else()
target_link_libraries(${PROJECT_NAME} PRIVATE
${SDL2_LIBRARIES}
${SDL2_IMAGE_LIBRARIES}
${SDL2_MIXER_LIBRARIES}
${SDL2_TTF_LIBRARIES}
${JSONCPP_LIBRARIES}
)
endif()
include_directories(
${PROJECT_SOURCE_DIR}/include
${SDL2_INCLUDE_DIRS}
${SDL2_IMAGE_INCLUDE_DIRS}
${SDL2_MIXER_INCLUDE_DIRS}
${SDL2_TTF_INCLUDE_DIRS}
${JSONCPP_INCLUDE_DIRS}
)
if(TRANSLATION_SUPPORT)
message("-- Building with translation support")
if(BUILD_STATIC)
target_link_libraries(${PROJECT_NAME} PRIVATE ${TINYGETTEXT_STATIC_LIBRARIES})
else()
target_link_libraries(${PROJECT_NAME} PRIVATE ${TINYGETTEXT_LIBRARIES})
endif()
add_compile_definitions(TRANSLATION_SUPPORT=1)
else()
message("-- Building without translation support")
endif()
# Set asset paths
set(ASSETS_FONTS "${CMAKE_SOURCE_DIR}/assets/fonts")
set(ASSETS_IMAGES "${CMAKE_SOURCE_DIR}/assets/images")
set(ASSETS_LEVELS "${CMAKE_SOURCE_DIR}/assets/levels")
set(ASSETS_SOUNDS "${CMAKE_SOURCE_DIR}/assets/sounds")
set(ASSETS_MUSIC "${CMAKE_SOURCE_DIR}/assets/music")
set(ASSETS_BACKGROUNDS "${CMAKE_SOURCE_DIR}/assets/backgrounds")
if(TRANSLATION_SUPPORT)
set(ASSETS_LANGUAGES "${CMAKE_SOURCE_DIR}/assets/languages")
endif()
if(PSP)
set(ASSETS_BACKGROUNDS "${CMAKE_CURRENT_SOURCE_DIR}/platform/psp/assets/backgrounds")
elseif(VITA)
set(ASSETS_BACKGROUNDS "${CMAKE_SOURCE_DIR}/platform/vita/assets/backgrounds")
elseif(CMAKE_SYSTEM_NAME MATCHES "NintendoWii")
set(ASSETS_BACKGROUNDS "${CMAKE_SOURCE_DIR}/platform/wii/assets/backgrounds")
endif()
# Copy assets
if(NOT VITA)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/assets)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${ASSETS_BACKGROUNDS} ${CMAKE_CURRENT_BINARY_DIR}/assets/backgrounds)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${ASSETS_FONTS} ${CMAKE_CURRENT_BINARY_DIR}/assets/fonts)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${ASSETS_IMAGES} ${CMAKE_CURRENT_BINARY_DIR}/assets/images)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${ASSETS_LEVELS} ${CMAKE_CURRENT_BINARY_DIR}/assets/levels)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${ASSETS_MUSIC} ${CMAKE_CURRENT_BINARY_DIR}/assets/music)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${ASSETS_SOUNDS} ${CMAKE_CURRENT_BINARY_DIR}/assets/sounds)
if(TRANSLATION_SUPPORT)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${ASSETS_LANGUAGES} ${CMAKE_CURRENT_BINARY_DIR}/assets/languages)
endif()
endif()
# Platform specific install
if (VITA)
include("$ENV{VITASDK}/share/vita.cmake" REQUIRED)
vita_create_self(${CMAKE_PROJECT_NAME}.self ${CMAKE_PROJECT_NAME})
vita_create_vpk(${CMAKE_PROJECT_NAME}.vpk "OPOP00001" ${CMAKE_PROJECT_NAME}.self
VERSION "01.00"
NAME OceanPop
FILE platform/vita/sce_sys sce_sys
FILE README.md README.md
FILE LICENSE.txt LICENSE.txt
FILE "${ASSETS_BACKGROUNDS}" assets/backgrounds
FILE "${ASSETS_FONTS}" assets/fonts
FILE "${ASSETS_IMAGES}" assets/images
FILE "${ASSETS_LEVELS}" assets/levels
FILE "${ASSETS_MUSIC}" assets/music
FILE "${ASSETS_SOUNDS}" assets/sounds
)
elseif(PLATFORM_PSP)
create_pbp_file(
TARGET ${CMAKE_PROJECT_NAME}
ICON_PATH ${CMAKE_SOURCE_DIR}/platform/psp/icon.png
BACKGROUND_PATH NULL
PREVIEW_PATH NULL
TITLE OceanPop
)
elseif(CMAKE_SYSTEM_NAME MATCHES "NintendoWii")
ogc_create_dol(oceanpop)
elseif(win32)
# Nothing here yet
else()
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/assets DESTINATION share/${PROJECT_NAME})
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/platform/unix/io.github.sharkwouter.oceanpop.desktop DESTINATION share/applications)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/platform/unix/io.github.sharkwouter.oceanpop.metainfo.xml DESTINATION share/metainfo)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/platform/unix/icons/128x128/io.github.sharkwouter.oceanpop.png DESTINATION share/icons/hicolor/128x128/apps)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/README.md DESTINATION share/doc/${PROJECT_NAME})
endif()