cmake fix

This commit is contained in:
2025-11-30 14:32:52 +01:00
parent 33994ec9db
commit dd0ac54ee5
3 changed files with 80 additions and 4 deletions

View File

@ -29,7 +29,7 @@ find_package(SDL3_image CONFIG REQUIRED)
find_package(cpr CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
add_executable(tetris
set(TETRIS_SOURCES
src/main.cpp
src/gameplay/core/Game.cpp
src/core/GravityManager.cpp
@ -58,12 +58,24 @@ add_executable(tetris
src/states/PlayingState.cpp
)
if(APPLE)
add_executable(tetris MACOSX_BUNDLE ${TETRIS_SOURCES})
else()
add_executable(tetris ${TETRIS_SOURCES})
endif()
if (WIN32)
# Embed the application icon into the executable
set_source_files_properties(src/app_icon.rc PROPERTIES LANGUAGE RC)
target_sources(tetris PRIVATE src/app_icon.rc)
endif()
if(APPLE)
set_target_properties(tetris PROPERTIES
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_SOURCE_DIR}/cmake/MacBundleInfo.plist.in"
)
endif()
if (WIN32)
# Ensure favicon.ico is available in the build directory for the resource compiler
set(FAVICON_SRC "${CMAKE_SOURCE_DIR}/assets/favicon/favicon.ico")
@ -88,6 +100,32 @@ if (WIN32)
)
endif()
if(APPLE)
set(_mac_copy_commands)
if(EXISTS "${CMAKE_SOURCE_DIR}/assets")
list(APPEND _mac_copy_commands
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/assets" "$<TARGET_FILE_DIR:tetris>/assets"
)
endif()
if(EXISTS "${CMAKE_SOURCE_DIR}/fonts")
list(APPEND _mac_copy_commands
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/fonts" "$<TARGET_FILE_DIR:tetris>/fonts"
)
endif()
if(EXISTS "${CMAKE_SOURCE_DIR}/FreeSans.ttf")
list(APPEND _mac_copy_commands
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/FreeSans.ttf" "$<TARGET_FILE_DIR:tetris>/FreeSans.ttf"
)
endif()
if(_mac_copy_commands)
add_custom_command(TARGET tetris POST_BUILD
${_mac_copy_commands}
COMMENT "Copying game assets into macOS bundle"
)
endif()
endif()
endif()
target_link_libraries(tetris PRIVATE SDL3::SDL3 SDL3_ttf::SDL3_ttf SDL3_image::SDL3_image cpr::cpr nlohmann_json::nlohmann_json)
if (WIN32)