Skip to content

Commit

Permalink
Merge branch 'osx_bundle'
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Nov 30, 2023
2 parents 9e9438b + 71eb0d4 commit 6db5481
Showing 51 changed files with 516 additions and 213 deletions.
20 changes: 15 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -3,12 +3,17 @@ if (EMSCRIPTEN)
else()
cmake_minimum_required(VERSION 3.10)
endif()

project(HelloImGui LANGUAGES C CXX VERSION "1.0.0")
set(CMAKE_CXX_STANDARD 17)

if (IOS)
set(DEPLOYMENT_TARGET "13.0" CACHE STRING "" FORCE)
endif()

project(HelloImGui LANGUAGES C CXX VERSION "1.0.0")
set(CMAKE_CXX_STANDARD 17)
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(MACOSX TRUE)
endif()


###############################################################################
@@ -39,6 +44,12 @@ if (WIN32)
option(HELLOIMGUI_WIN32_NO_CONSOLE "Under windows, build apps without Dos Console" ON)
option(HELLOIMGUI_WIN32_AUTO_WINMAIN "Under windows, automatically provide a WinMain (provide `int main(int, char**)`, it will be called by WinMain())" ON)
endif()
#------------------------------------------------------------------------------
# Options / macOS: provide regular terminal executables, not app bundles
#------------------------------------------------------------------------------
if(MACOSX)
option(HELLOIMGUI_MACOS_NO_BUNDLE "Under macOS, build regular terminal executables, not app bundles" OFF)
endif()

#------------------------------------------------------------------------------
# Options / Backend selection
@@ -90,17 +101,16 @@ endif()
#------------------------------------------------------------------------------
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
option(HELLOIMGUI_BUILD_DEMOS "Build demos" ON)
option(HELLOIMGUI_BUILD_TESTS "Build tests" ON)
else()
option(HELLOIMGUI_BUILD_DEMOS "Build demos" OFF)
option(HELLOIMGUI_BUILD_TESTS "Build tests" OFF)
endif()
option(HELLOIMGUI_BUILD_TESTS "Build tests" OFF)

#------------------------------------------------------------------------------
# Options / ImGui Test Engine
#------------------------------------------------------------------------------
option(HELLOIMGUI_WITH_TEST_ENGINE "Provide ImGui Test engine" OFF)
message(WARNING "HELLOIMGUI_WITH_TEST_ENGINE=${HELLOIMGUI_WITH_TEST_ENGINE}")
message(STATUS "HELLOIMGUI_WITH_TEST_ENGINE=${HELLOIMGUI_WITH_TEST_ENGINE}")

#------------------------------------------------------------------------------
# Instructions: how to enable Esmcripten multihtread support
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<img src="logo/logo_hello_imgui.png" width="200">

![Ubuntu](https://github.com/pthom/hello_imgui/workflows/Ubuntu/badge.svg)
![Windows](https://github.com/pthom/hello_imgui/workflows/Windows/badge.svg)
![MacOS](https://github.com/pthom/hello_imgui/workflows/MacOS/badge.svg)
@@ -231,6 +233,8 @@ __Table of contents__
* [Embed assets](#embed-assets)
* [Customize per platform](#customize-per-platform)
* [iOS](#ios)
* [macOS](#macos)
* [How to build terminal executables under macOS](#how-to-build-terminal-executables-under-macos)
* [Android](#android)
* [Example of customization:](#example-of-customization)
* [Resizing icons for Android](#resizing-icons-for-android)
@@ -491,7 +495,21 @@ on mobile devices and emscripten, i.e they will be bundled together with the app

### iOS

For iOS, simply create a folder named "ios" beside the application 'CMakeLists.txt'. There, you can add a custom Info.plist, as well as app icons and launch screens.
For iOS, simply create a folder named `ios` beside the application 'CMakeLists.txt'. There, you can add a custom Info.plist, as well as app icons and launch screens.

For an example, see the `ios` folder inside [src/hello_imgui_demos/hello_imgui_demodocking/](src/hello_imgui_demos/hello_imgui_demodocking)


### macOS

For macOS, simply create a folder named `macos` beside the application 'CMakeLists.txt'. There, you can add a custom Info.plist, as well as app icons.

For an example, see the `macos` folder inside [src/hello_imgui_demos/hello_imgui_demodocking/](src/hello_imgui_demos/hello_imgui_demodocking/)

#### How to build terminal executables under macOS

If you prefer to build regular terminal executables (not app bundles), use the cmake option `-DHELLOIMGUI_MACOS_NO_BUNDLE=ON`.


### Android

18 changes: 17 additions & 1 deletion README.src.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<img src="logo/logo_hello_imgui.png" width="200">

![Ubuntu](https://github.com/pthom/hello_imgui/workflows/Ubuntu/badge.svg)
![Windows](https://github.com/pthom/hello_imgui/workflows/Windows/badge.svg)
![MacOS](https://github.com/pthom/hello_imgui/workflows/MacOS/badge.svg)
@@ -427,7 +429,21 @@ on mobile devices and emscripten, i.e they will be bundled together with the app

### iOS

For iOS, simply create a folder named "ios" beside the application 'CMakeLists.txt'. There, you can add a custom Info.plist, as well as app icons and launch screens.
For iOS, simply create a folder named `ios` beside the application 'CMakeLists.txt'. There, you can add a custom Info.plist, as well as app icons and launch screens.

For an example, see the `ios` folder inside [src/hello_imgui_demos/hello_imgui_demodocking/](src/hello_imgui_demos/hello_imgui_demodocking)


### macOS

For macOS, simply create a folder named `macos` beside the application 'CMakeLists.txt'. There, you can add a custom Info.plist, as well as app icons.

For an example, see the `macos` folder inside [src/hello_imgui_demos/hello_imgui_demodocking/](src/hello_imgui_demos/hello_imgui_demodocking/)

#### How to build terminal executables under macOS

If you prefer to build regular terminal executables (not app bundles), use the cmake option `-DHELLOIMGUI_MACOS_NO_BUNDLE=ON`.


### Android

5 changes: 0 additions & 5 deletions hello_imgui_cmake/android/mipmap-source/Readme.md

This file was deleted.

Binary file not shown.
Binary file added hello_imgui_cmake/android/playstore-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified hello_imgui_cmake/android/res/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified hello_imgui_cmake/android/res/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified hello_imgui_cmake/android/res/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified hello_imgui_cmake/android/res/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified hello_imgui_cmake/android/res/mipmap-xxxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
121 changes: 121 additions & 0 deletions hello_imgui_cmake/apple/hello_imgui_apple.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
if (APPLE)

# This function is common to IOS and MACOSX, and customize the Info.plist
function(hello_imgui_add_info_plist app_name)
if (NOT DEFINED HELLO_IMGUI_BUNDLE_IDENTIFIER)
set(HELLO_IMGUI_BUNDLE_IDENTIFIER ${HELLO_IMGUI_BUNDLE_IDENTIFIER_URL_PART}.${HELLO_IMGUI_BUNDLE_IDENTIFIER_NAME_PART})
endif()
if (MACOSX)
set(plist_subfolder "macos")
else()
set(plist_subfolder "ios")
endif()
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${plist_subfolder}/Info.plist)
message("hello_imgui_add_info_plist: ${app_name} found app specific Info.plist")
set(info_plist_in ${CMAKE_CURRENT_SOURCE_DIR}/${plist_subfolder}/Info.plist)
else()
set(info_plist_dir_all ${HELLOIMGUI_BASEPATH}/hello_imgui_cmake/apple/info_plist)
set(info_plist_in ${info_plist_dir_all}/Info.plist.in)
endif()
set(info_plist_configured ${CMAKE_CURRENT_BINARY_DIR}/Info${app_name}.plist)

# Clean CFBundleIdentifier (remove unwanted characters)
# See https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/TP40009249-SW1
# The string should be in reverse DNS format using only the Roman alphabet
# in upper and lower case (A–Z, a–z), the dot (“.”), and the hyphen (“-”)
string(REGEX REPLACE
"[^a-zA-Z.-]" "-"
HELLO_IMGUI_BUNDLE_IDENTIFIER
"${HELLO_IMGUI_BUNDLE_IDENTIFIER}"
)
string(TOLOWER "${HELLO_IMGUI_BUNDLE_IDENTIFIER}" HELLO_IMGUI_BUNDLE_IDENTIFIER)
message(VERBOSE "HELLO_IMGUI_BUNDLE_IDENTIFIER=${HELLO_IMGUI_BUNDLE_IDENTIFIER}")

configure_file(${info_plist_in} ${info_plist_configured})
set_target_properties(${app_name} PROPERTIES
MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_INFO_PLIST ${info_plist_configured}
)
endfunction()

# Specific functions for IOS
if (IOS)
string(REGEX MATCH "SIMULATOR.*" IOS_IS_SIMULATOR ${PLATFORM})

function(hello_imgui_ios_set_dev_team app_name)
if (IOS_IS_SIMULATOR)
return()
endif()
set_target_properties( ${app_name} PROPERTIES
XCODE_ATTRIBUTE_DEVELOPMENT_TEAM ${CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM}
)
endfunction()


# Check CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM
function(hello_imgui_ios_check_development_team)
if (IOS_IS_SIMULATOR)
return()
endif()
if(NOT DEFINED CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM OR ${CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM} STREQUAL "123456789A")
if(DEFINED ENV{CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM})
set(CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM $ENV{CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM} CACHE STRING "iOS Devel Team id" FORCE)
else()
message(FATAL_ERROR "Please set CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM")
endif()
endif()
message(VERBOSE "CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM=${CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM}")
endfunction()


function(hello_imgui_ios_add_icons app_name)
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/ios/icons)
message("hello_imgui_ios_add_icons: ${app_name} found ios/icons specific icons folder")
set(icons_assets_folder ${CMAKE_CURRENT_SOURCE_DIR}/ios/icons)
else()
set(local_assets_folder ${CMAKE_CURRENT_SOURCE_DIR}/assets)

set(icons_assets_folder ${HELLOIMGUI_BASEPATH}/hello_imgui_cmake/apple/ios_icons)
endif()
hello_imgui_apple_bundle_add_files_from_folder(${app_name} ${icons_assets_folder} "")
endfunction()

endif(IOS)

# Specific functions for MACOSX
if (MACOSX)
function(hello_imgui_macos_add_icons app_name)
set(app_icon ${CMAKE_CURRENT_SOURCE_DIR}/macos/${HELLO_IMGUI_BUNDLE_ICON_FILE})
if (EXISTS ${app_icon})
message(STATUS "hello_imgui_macos_add_icons: ${app_name} found app specific icon at ${app_icon}")
else()
set(app_icon ${HELLOIMGUI_BASEPATH}/hello_imgui_cmake/apple/mac_icons/icon.icns)
endif()
target_sources(${app_name} PRIVATE ${app_icon})
set_source_files_properties(${app_icon}
PROPERTIES
MACOSX_PACKAGE_LOCATION "Resources"
)
endfunction()
endif(MACOSX)


# Definitions of hello_imgui_platform_customization for IOS and MACOSX
if (MACOSX AND NOT HELLOIMGUI_MACOS_NO_BUNDLE)

function(hello_imgui_platform_customization app_name)
hello_imgui_add_info_plist(${app_name} sdl)
hello_imgui_macos_add_icons(${app_name})
endfunction()

elseif(IOS)

function(hello_imgui_platform_customization app_name)
hello_imgui_ios_check_development_team()
hello_imgui_ios_set_dev_team(${app_name})
hello_imgui_add_info_plist(${app_name})
hello_imgui_ios_add_icons(${app_name})
endfunction()

endif()
endif(APPLE)
File renamed without changes.
Binary file added hello_imgui_cmake/apple/ios_icons/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added hello_imgui_cmake/apple/mac_icons/icon.icns
Binary file not shown.
23 changes: 13 additions & 10 deletions hello_imgui_cmake/assets/hello_imgui_assets.cmake
Original file line number Diff line number Diff line change
@@ -24,24 +24,27 @@ if (EMSCRIPTEN)
endif()
endfunction()

elseif(IOS)
elseif(IOS OR (MACOSX AND (NOT HELLOIMGUI_MACOS_NO_BUNDLE)))

# Bundle assets / iOS version
function(hello_imgui_bundle_assets_from_folder app_name assets_folder)
FILE(GLOB_RECURSE assets ${assets_folder}/*.*)
# Bundle assets / macOS and iOS app version
function(hello_imgui_apple_bundle_add_files_from_folder app_name assets_folder location_in_bundle)
file(GLOB_RECURSE assets ${assets_folder}/*.*)
target_sources(${app_name} PRIVATE ${assets})
foreach(asset ${assets})
string(REPLACE ${assets_folder}/ "" asset_relative ${asset})
file(RELATIVE_PATH asset_relative ${assets_folder} ${asset})
get_filename_component(asset_dir ${asset_relative} DIRECTORY)
SET_SOURCE_FILES_PROPERTIES (
${app_name}
set_source_files_properties (
${asset}
PROPERTIES
MACOSX_PACKAGE_LOCATION Resources/${asset_dir}
MACOSX_PACKAGE_LOCATION ${location_in_bundle}/${asset_dir}
)
endforeach()
endfunction()

function(hello_imgui_bundle_assets_from_folder app_name assets_folder)
hello_imgui_apple_bundle_add_files_from_folder(${app_name} ${assets_folder} "Resources/assets")
endfunction()

elseif(ANDROID)

function(hello_imgui_bundle_assets_from_folder app_name assets_folder)
@@ -109,9 +112,9 @@ function(hello_imgui_copy_folder1_files_missing_from_folder2 folder_src_1 folder
endfunction()


function(hello_imgui_bundle_assets app_name)
function(hello_imgui_bundle_assets app_name assets_location)
set(common_assets_folder ${HELLOIMGUI_BASEPATH}/hello_imgui_assets)
set(local_assets_folder ${CMAKE_CURRENT_SOURCE_DIR}/assets)
set(local_assets_folder ${assets_location})

set(common_assets_folder_copy ${CMAKE_CURRENT_BINARY_DIR}/tmp/common_assets)
file(REMOVE_RECURSE ${common_assets_folder_copy})
6 changes: 0 additions & 6 deletions hello_imgui_cmake/desktop/hello_imgui_desktop.cmake

This file was deleted.

Loading

0 comments on commit 6db5481

Please sign in to comment.