Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support to macOS app bundles #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@
!assets/**
!libs/**
!src/**

.DS_Store
11 changes: 9 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@ add_subdirectory(libs/rayfork)
add_executable(${CMAKE_PROJECT_NAME} src/platform.c src/game.c)
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE glad rayfork)
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE libs/rayfork libs/sokol)
target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC ASSETS_PATH="${CMAKE_CURRENT_SOURCE_DIR}/assets/") # This is useful to get an ASSETS_PATH in your IDE during development but you should comment this if you compile a release version and uncomment the next line
#target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC ASSETS_PATH="my-path-to-the-assets-directory") # Uncomment this line to setup the ASSETS_PATH macro to the final assets directory when you share the game

# Enable MacOS specific flags and link against it's specific libraries
if (APPLE)
file(GLOB ASSETS assets/*)
set_property(SOURCE "${ASSETS}" PROPERTY MACOSX_PACKAGE_LOCATION "Resources/assets")
target_sources(${CMAKE_PROJECT_NAME} PRIVATE "${ASSETS}")
target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC ASSETS_PATH="assets/")

target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC "-framework Cocoa" "-framework QuartzCore" "-framework OpenGL")
target_compile_options(${CMAKE_PROJECT_NAME} PUBLIC "-fobjc-arc" "-ObjC")
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES MACOSX_BUNDLE TRUE)
else()
target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC ASSETS_PATH="${CMAKE_CURRENT_SOURCE_DIR}/assets/") # This is useful to get an ASSETS_PATH in your IDE during development but you should comment this if you compile a release version and uncomment the next line
#target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC ASSETS_PATH="my-path-to-the-assets-directory") # Uncomment this line to setup the ASSETS_PATH macro to the final assets directory when you share the game
endif()
7 changes: 7 additions & 0 deletions src/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ static platform_input_state input_state;

static void sokol_on_init(void)
{
#ifdef RAYFORK_PLATFORM_MACOS
CFURLRef url = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
char path[PATH_MAX];
if (!CFURLGetFileSystemRepresentation(url, true, (UInt8 *) path, sizeof(path)) || chdir(path) != 0)
exit(-1);
CFRelease(url);
#endif
gladLoadGL();

game_init(RF_DEFAULT_GFX_BACKEND_INIT_DATA);
Expand Down