|
| 1 | +import sys |
| 2 | +import glob |
| 3 | + |
| 4 | +APP_NAME = "MyGame" |
| 5 | +APP_ID = "com.cfrankb.creepspreadiii" |
| 6 | +APP_VERSION = "1.0" |
| 7 | +APP_LONGVERSION = "1.0.0" |
| 8 | +APP_LONGNAME = "Creepspread III" |
| 9 | +BUNDLE_NAME = APP_LONGNAME.replace(" ", "") |
| 10 | + |
| 11 | +paths = ["src/*.cpp", "src/**/*.cpp", "src/**/**/*.cpp"] |
| 12 | + |
| 13 | +src = [] |
| 14 | +for pattern in paths: |
| 15 | + for f in glob.glob(pattern): |
| 16 | + src.append(f) |
| 17 | + |
| 18 | + |
| 19 | +CMAKEFILE_TEMPLATE = f""" |
| 20 | +cmake_minimum_required(VERSION 3.16) |
| 21 | +project({APP_NAME}) |
| 22 | +
|
| 23 | +set(CMAKE_CXX_STANDARD 17) |
| 24 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 25 | +
|
| 26 | +# Enable macOS bundle |
| 27 | +set(MACOSX_BUNDLE_BUNDLE_NAME "{BUNDLE_NAME}") |
| 28 | +set(MACOSX_BUNDLE_GUI_IDENTIFIER "{APP_ID}") |
| 29 | +set(MACOSX_BUNDLE_SHORT_VERSION_STRING "{APP_VERSION}") |
| 30 | +set(MACOSX_BUNDLE_LONG_VERSION_STRING "{APP_LONGVERSION}") |
| 31 | +set(MACOSX_BUNDLE TRUE) |
| 32 | +
|
| 33 | +#add_subdirectory(SDL) |
| 34 | +#add_subdirectory(SDL_mixer) |
| 35 | +
|
| 36 | +#find_package(SDL3 REQUIRED) |
| 37 | +#find_package(SDL3_mixer REQUIRED) |
| 38 | +add_subdirectory(external/SDL3) |
| 39 | +add_subdirectory(external/SDL3_mixer) |
| 40 | +
|
| 41 | +find_library(XMP_LIBRARY xmp) |
| 42 | +find_library(ZLIB_LIBRARY z) |
| 43 | +find_library(OGG_LIBRARY ogg) |
| 44 | +find_library(VORBIS_LIBRARY vorbisfile) |
| 45 | +
|
| 46 | +add_executable({APP_NAME} MACOSX_BUNDLE |
| 47 | + {'\n\t'.join(src) + '\n'}) |
| 48 | +
|
| 49 | +#target_link_libraries(MyGame PRIVATE SDL3::SDL3 SDL3_mixer::SDL3_mixer) |
| 50 | +
|
| 51 | +target_link_libraries({APP_NAME} |
| 52 | + PRIVATE SDL3::SDL3 SDL3_mixer::SDL3_mixer |
| 53 | + #SDL3::SDL3 |
| 54 | + #SDL3_mixer::SDL3_mixer |
| 55 | + PUBLIC ${{XMP_LIBRARY}} |
| 56 | + ${{ZLIB_LIBRARY}} |
| 57 | + ${{OGG_LIBRARY}} |
| 58 | + ${{VORBIS_LIBRARY}} |
| 59 | +) |
| 60 | +
|
| 61 | +# Copy entire assets directory into Resources |
| 62 | +set(ASSETS_DIR "${{CMAKE_SOURCE_DIR}}/data") # modified |
| 63 | +file(GLOB_RECURSE ASSET_FILES RELATIVE ${{ASSETS_DIR}} "${{ASSETS_DIR}}/*") |
| 64 | +
|
| 65 | +foreach(asset IN LISTS ASSET_FILES) |
| 66 | + set(source "${{ASSETS_DIR}}/${{asset}}") |
| 67 | + set(destination "Resources/${{asset}}") |
| 68 | + set_source_files_properties(${{source}} PROPERTIES MACOSX_PACKAGE_LOCATION ${{destination}}) |
| 69 | + list(APPEND RESOURCE_FILES ${{source}}) |
| 70 | +endforeach() |
| 71 | +
|
| 72 | +# Add assets to the bundle |
| 73 | +target_sources({APP_NAME} PRIVATE ${{RESOURCE_FILES}}) |
| 74 | +
|
| 75 | +""" |
| 76 | + |
| 77 | +PLIST_TEMPLATE = f"""<?xml version="1.0" encoding="UTF-8"?> |
| 78 | +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" |
| 79 | + "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
| 80 | +<plist version="1.0"> |
| 81 | +<dict> |
| 82 | + <key>CFBundleExecutable</key> |
| 83 | + <string>{APP_NAME}</string> |
| 84 | + <key>CFBundleIdentifier</key> |
| 85 | + <string>{APP_ID}</string> |
| 86 | + <key>CFBundleName</key> |
| 87 | + <string>{APP_LONGNAME}</string> |
| 88 | + <key>CFBundleVersion</key> |
| 89 | + <string>{APP_VERSION}</string> |
| 90 | + <key>CFBundlePackageType</key> |
| 91 | + <string>APPL</string> |
| 92 | +</dict> |
| 93 | +</plist>""" |
| 94 | + |
| 95 | + |
| 96 | +argv = sys.argv |
| 97 | +filename = argv[1] if len(argv) > 1 else "CMakeLists.txt" |
| 98 | + |
| 99 | +with open(filename, "w") as tfile: |
| 100 | + tfile.write(CMAKEFILE_TEMPLATE.strip() + "\n") |
| 101 | + |
| 102 | +with open("packages/data/macos/Info.plist", "w") as tfile: |
| 103 | + tfile.write(PLIST_TEMPLATE.strip() + "\n") |
| 104 | + |
| 105 | +""" |
| 106 | +MyGame.app/ |
| 107 | +├── Contents/ |
| 108 | +│ ├── MacOS/ |
| 109 | +│ │ └── MyGame ← your compiled binary |
| 110 | +│ ├── Resources/ |
| 111 | +│ │ ├── assets/ ← images, sounds, etc. |
| 112 | +│ │ └── config/ ← game settings, levels |
| 113 | +│ └── Info.plist ← metadata |
| 114 | +""" |
0 commit comments