Skip to content

Commit

Permalink
CMake configuration for building halley projects into macOS .app bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoxon committed Jan 28, 2019
1 parent 6cc261c commit 7d57310
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
32 changes: 31 additions & 1 deletion cmake/HalleyProject.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ if (APPLE)
mark_as_advanced(CARBON_LIBRARY COCOA_LIBRARY COREAUDIO_LIBRARY AUDIOTOOLBOX_LIBRARY AUDIOUNIT_LIBRARY FORCEFEEDBACK_LIBRARY IOKIT_LIBRARY COREVIDEO_LIBRARY)

set(EXTRA_LIBS ${EXTRA_LIBS} ${CARBON_LIBRARY} ${COCOA_LIBRARY} ${COREAUDIO_LIBRARY} ${AUDIOTOOLBOX_LIBRARY} ${AUDIOUNIT_LIBRARY} ${FORCEFEEDBACK_LIBRARY} ${IOKIT_LIBRARY} ${COREVIDEO_LIBRARY} iconv)

if (BUILD_MACOSX_BUNDLE)
add_definitions(-DHALLEY_MACOSX_BUNDLE)
endif()
endif(APPLE)

# From http://stackoverflow.com/questions/31422680/how-to-set-visual-studio-filters-for-nested-sub-directory-using-cmake
Expand Down Expand Up @@ -347,6 +351,9 @@ function(halleyProject name sources headers genDefinitions targetDir)
if (HOTRELOAD)
add_library(${name} SHARED ${proj_sources} ${proj_headers})
add_definitions(-DHALLEY_SHARED_LIBRARY)
elseif (BUILD_MACOSX_BUNDLE)
add_executable(${name} MACOSX_BUNDLE ${proj_sources} ${proj_headers})
add_definitions(-DHALLEY_EXECUTABLE)
else()
add_executable(${name} WIN32 ${proj_sources} ${proj_headers})
add_definitions(-DHALLEY_EXECUTABLE)
Expand Down Expand Up @@ -386,10 +393,16 @@ function(halleyProject name sources headers genDefinitions targetDir)
else ()
target_link_libraries(${name} ${HALLEY_PROJECT_LIBS})
endif ()

if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "WindowsStore")
set_target_properties(${name} PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
endif ()

if (BUILD_MACOSX_BUNDLE)
add_custom_command(TARGET ${name} POST_BUILD
COMMAND "cp" "-R" "${CMAKE_CURRENT_SOURCE_DIR}/assets/" "$<TARGET_FILE_DIR:${name}>/../Resources"
)
endif ()
endfunction(halleyProject)

function(halleyProjectCodegen name sources headers genDefinitions targetDir)
Expand All @@ -401,3 +414,20 @@ function(halleyProjectCodegen name sources headers genDefinitions targetDir)
add_dependencies(${PROJECT_NAME}-codegen halley-cmd)
endif ()
endfunction(halleyProjectCodegen)

function(halleyProjectBundleProperties name icon app_title copyright)
if (BUILD_MACOSX_BUNDLE)
get_filename_component(icon_name ${icon} NAME)

set_target_properties(${name} PROPERTIES
MACOSX_BUNDLE_BUNDLE_NAME "${app_title}"
MACOSX_BUNDLE_COPYRIGHT "${copyright}"
MACOSX_BUNDLE_GUI_IDENTIFIER "${app_title}"
MACOSX_BUNDLE_ICON_FILE "${icon_name}"
)

add_custom_command(TARGET ${name} POST_BUILD
COMMAND "cp" "${CMAKE_CURRENT_SOURCE_DIR}/${icon}" "$<TARGET_FILE_DIR:${name}>/../Resources/"
)
endif ()
endfunction(halleyProjectBundleProperties)
4 changes: 4 additions & 0 deletions src/plugins/sdl/src/system_sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ void SystemSDL::deInit()

Path SystemSDL::getAssetsPath(const Path& gamePath) const
{
#if defined(HALLEY_MACOSX_BUNDLE)
return gamePath / ".." / "Resources";
#else
return gamePath / ".." / "assets";
#endif
}

Path SystemSDL::getUnpackedAssetsPath(const Path& gamePath) const
Expand Down

0 comments on commit 7d57310

Please sign in to comment.