diff --git a/CMakeLists.txt b/CMakeLists.txt index a4ece493..d149311d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,7 +90,6 @@ option(HELLOIMGUI_USE_SDL_OPENGL3 "Build HelloImGui for SDL+OpenGL3" OFF) # HELLOIMGUI_IMGUI_SOURCE_DIR: folder containing the sources for imgui (by default in the submodule external/imgui) if (NOT DEFINED HELLOIMGUI_IMGUI_SOURCE_DIR) set(HELLOIMGUI_IMGUI_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/external/imgui" CACHE STRING "Source dir of ImGui") - message(WARNING "Defined HELLOIMGUI_IMGUI_SOURCE_DIR=${HELLOIMGUI_IMGUI_SOURCE_DIR}") endif() # if HELLOIMGUI_BUILD_IMGUI, imgui will be built as part of the build of HelloImGui if (NOT DEFINED HELLOIMGUI_BUILD_IMGUI) diff --git a/hello_imgui_cmake/android/hello_imgui_android.cmake b/hello_imgui_cmake/android/hello_imgui_android.cmake index 0aef1107..88d1f519 100644 --- a/hello_imgui_cmake/android/hello_imgui_android.cmake +++ b/hello_imgui_cmake/android/hello_imgui_android.cmake @@ -1,6 +1,2 @@ -if (ANDROID) - function (hello_imgui_platform_customization app_name assets_location) endfunction() - -endif(ANDROID) diff --git a/hello_imgui_cmake/apple/hello_imgui_apple.cmake b/hello_imgui_cmake/apple/hello_imgui_apple.cmake index 9961941b..0fb86a01 100644 --- a/hello_imgui_cmake/apple/hello_imgui_apple.cmake +++ b/hello_imgui_cmake/apple/hello_imgui_apple.cmake @@ -1,255 +1,92 @@ -if (APPLE) +if(IOS) + include(${CMAKE_CURRENT_LIST_DIR}/hello_imgui_ios.cmake) +endif() +if(MACOSX) + include(${CMAKE_CURRENT_LIST_DIR}/hello_imgui_macos.cmake) +endif() - # hello_imgui_select_plist: select best plist file for the current platform - function(hello_imgui_select_plist assets_location output_plist_path) - # List of possible paths, in order of priority (first is highest priority) - if (MACOSX) - set(possible_paths - ${CMAKE_CURRENT_SOURCE_DIR}/macos/Info.plist - ${assets_location}/app_settings/apple/Info.macos.plist - ${assets_location}/app_settings/apple/Info.plist - ${HELLOIMGUI_BASEPATH}/hello_imgui_cmake/apple/info_plist/Info.plist.in - ) - endif() - if (IOS) - set(possible_paths - ${CMAKE_CURRENT_SOURCE_DIR}/ios/Info.plist - ${assets_location}/app_settings/apple/Info.ios.plist - ${assets_location}/app_settings/apple/Info.plist - ${HELLOIMGUI_BASEPATH}/hello_imgui_cmake/apple/info_plist/Info.plist.in - ) - endif() - - # Find the first existing plist - foreach(possible_path ${possible_paths}) - if (EXISTS ${possible_path}) - set(found_plist ${possible_path}) - break() - endif() - endforeach() - - # if found_plist is not defined, we have a problem - if (NOT DEFINED found_plist) - message(FATAL_ERROR "hello_imgui_select_plist: no plist found in ${possible_paths}") - endif() - - set(${output_plist_path} ${found_plist} PARENT_SCOPE) - endfunction() - - # This function is common to IOS and MACOSX, and customize the Info.plist - function(hello_imgui_add_info_plist app_name assets_location) - hello_imgui_select_plist( ${assets_location} info_plist_in) - message(VERBOSE "hello_imgui_add_info_plist: info_plist_in=${info_plist_in} for app_name=${app_name}") - set(info_plist_configured ${CMAKE_CURRENT_BINARY_DIR}/Info${app_name}.plist) - - 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() - - # 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} +# hello_imgui_select_plist: select best plist file for the current platform +function(hello_imgui_select_plist assets_location output_plist_path) + # List of possible paths, in order of priority (first is highest priority) + if (MACOSX) + set(possible_paths + ${CMAKE_CURRENT_SOURCE_DIR}/macos/Info.plist + ${assets_location}/app_settings/apple/Info.macos.plist + ${assets_location}/app_settings/apple/Info.plist + ${HELLOIMGUI_BASEPATH}/hello_imgui_cmake/apple/info_plist/Info.plist.in ) - endfunction() - - ######################################################## - # Specific functions for IOS - ######################################################## + endif() 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() - - # Handle icons (and conversion if necessary) - function(hello_imgui_ios_add_icons app_name assets_location) - # Default HelloImGui icons - set(icons_assets_folder ${HELLOIMGUI_BASEPATH}/hello_imgui_cmake/apple/ios_icons) - set(found_custom_icon OFF) - - # First possible custom icons folder, in ios/icons - set(custom_icons_assets_folder ${CMAKE_CURRENT_SOURCE_DIR}/ios/icons) - if ((NOT found_custom_icon) AND (IS_DIRECTORY ${custom_icons_assets_folder})) - message(STATUS "hello_imgui_ios_add_icons: found ios/icons specific icons folder for app ${app_name} ") - set(icons_assets_folder ${custom_icons_assets_folder}) - set(found_custom_icon ON) - endif() - - # Second possible custom icon, in assets/app_settings/icon.png - set(custom_app_png_icon ${assets_location}/app_settings/icon.png) - if ((NOT found_custom_icon) AND (EXISTS ${custom_app_png_icon})) - # find python program - find_program(PYTHON_EXECUTABLE NAMES python3 python) - if (NOT PYTHON_EXECUTABLE) - message(WARNING " - ${app_name}: can't create iOS icon from ${custom_app_png_icon} - (did not find python) - This is not a fatal error, but the iOS app will not have the correct icon. - ") - return() - endif() - - # We need to convert icon.png to an icon folder - set(script_png_icon_to_icon_folder "${HELLOIMGUI_BASEPATH}/hello_imgui_cmake/apple/ios_png_icon_to_icon_folder.py") - message(STATUS "hello_imgui_ios_add_icons: converting ${custom_app_png_icon} to icon folder for app ${app_name} ") - set(custom_icons_assets_folder ${CMAKE_CURRENT_BINARY_DIR}/custom_icons) - execute_process( - COMMAND ${PYTHON_EXECUTABLE} ${script_png_icon_to_icon_folder} ${custom_app_png_icon} ${custom_icons_assets_folder} - RESULT_VARIABLE script_png_icon_to_icon_folder_result - ) - if (NOT ${script_png_icon_to_icon_folder_result} EQUAL 0) - message(WARNING " - ${app_name}: failed to create iOS icon from ${custom_app_icon} - Tried to run: - ${PYTHON_EXECUTABLE} ${script_png_icon_to_icon_folder} ${custom_app_png_icon} ${custom_icons_assets_folder} - This is not a fatal error, but the app will not have a custom icon. - ") - return() - endif() - - set(icons_assets_folder ${custom_icons_assets_folder}) - set(found_custom_icon ON) - endif() - - hello_imgui_apple_bundle_add_files_from_folder(${app_name} ${icons_assets_folder} "") - endfunction() - - - function(hello_imgui_ios_copy_resources app_name assets_location) - # if assets_location/app_settings/apple/Resources/ios exists, copy it to the bundle Resources folder - set(custom_resources_folder ${assets_location}/app_settings/apple/Resources/ios) - if (EXISTS ${custom_resources_folder}) - message(STATUS "hello_imgui_ios_copy_resources: found custom iOS resources folder ${custom_resources_folder} for app ${app_name} ") - hello_imgui_apple_bundle_add_files_from_folder(${app_name} ${custom_resources_folder} "Resources") - endif() - endfunction() - - endif(IOS) - - - - ######################################################## - # Specific functions for MACOSX - ######################################################## - if (MACOSX) - - # Handle icons (and conversion if necessary) - function(hello_imgui_macos_add_icons app_name assets_location) - # Default HelloImGui icon - set(app_icon ${HELLOIMGUI_BASEPATH}/hello_imgui_cmake/apple/mac_icons/icon.icns) - set(found_custom_icon OFF) + set(possible_paths + ${CMAKE_CURRENT_SOURCE_DIR}/ios/Info.plist + ${assets_location}/app_settings/apple/Info.ios.plist + ${assets_location}/app_settings/apple/Info.plist + ${HELLOIMGUI_BASEPATH}/hello_imgui_cmake/apple/info_plist/Info.plist.in + ) + endif() - # First possible custom icon in macos/icon.icns - set(custom_app_icon ${CMAKE_CURRENT_SOURCE_DIR}/macos/${HELLO_IMGUI_BUNDLE_ICON_FILE}) - if ((NOT found_custom_icon) AND (EXISTS ${custom_app_icon})) - set(app_icon ${custom_app_icon}) - set(found_custom_icon ON) - message(STATUS "hello_imgui_macos_add_icons: found app specific icon at ${custom_app_icon} for app ${app_name} ") - endif() + # Find the first existing plist + foreach(possible_path ${possible_paths}) + if (EXISTS ${possible_path}) + set(found_plist ${possible_path}) + break() + endif() + endforeach() - # Second possible custom icon, in assets/app_settings/icon.png (which we need to convert to icon.icns) - set(custom_app_png_icon ${assets_location}/app_settings/icon.png) - if ((NOT found_custom_icon) AND (EXISTS ${custom_app_png_icon})) - # find python program - find_program(PYTHON_EXECUTABLE NAMES python3 python) - if (NOT PYTHON_EXECUTABLE) - message(WARNING " - ${app_name}: can't create a macOS icons from ${custom_app_png_icon} - (did not find python) - This is not a fatal error, but the app will not have a custom icon. - ") - return() - endif() + # if found_plist is not defined, we have a problem + if (NOT DEFINED found_plist) + message(FATAL_ERROR "hello_imgui_select_plist: no plist found in ${possible_paths}") + endif() - # We need to convert icon.png to icon.icns - set(script_png_to_icns "${HELLOIMGUI_BASEPATH}/hello_imgui_cmake/apple/macos_png_icon_to_icns.py") - message(VERBOSE "hello_imgui_macos_add_icons: converting ${custom_app_png_icon} to icns for app ${app_name}") - set(custom_app_icon ${CMAKE_CURRENT_BINARY_DIR}/icon.icns) - execute_process( - COMMAND ${PYTHON_EXECUTABLE} ${script_png_to_icns} ${custom_app_png_icon} ${custom_app_icon} - RESULT_VARIABLE script_png_to_icns_result - ) - if (NOT ${script_png_to_icns_result} EQUAL 0) - message(WARNING " - ${app_name}: failed to create macOS icon from ${custom_app_icon} - Tried to run: - ${PYTHON_EXECUTABLE} ${script_png_to_icns} ${custom_app_png_icon} ${custom_app_icon} - This is not a fatal error, but the app will not have a custom icon. - ") - return() - endif() + set(${output_plist_path} ${found_plist} PARENT_SCOPE) +endfunction() - set(app_icon ${custom_app_icon}) - set(found_custom_icon ON) - message(VERBOSE "found custom icon at ${custom_app_icon} for app ${app_name} ") - endif() - # Add icon to target - target_sources(${app_name} PRIVATE ${app_icon}) - set_source_files_properties(${app_icon} - PROPERTIES - MACOSX_PACKAGE_LOCATION "Resources" - ) - endfunction() - endif(MACOSX) +# This function is common to IOS and MACOSX, and customize the Info.plist +function(hello_imgui_add_info_plist app_name assets_location) + hello_imgui_select_plist( ${assets_location} info_plist_in) + message(VERBOSE "hello_imgui_add_info_plist: info_plist_in=${info_plist_in} for app_name=${app_name}") + set(info_plist_configured ${CMAKE_CURRENT_BINARY_DIR}/Info${app_name}.plist) + 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() - ######################################################## - # Definitions of hello_imgui_platform_customization - # for IOS and MACOSX - ######################################################## + # 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() + + + +######################################################## +# Definitions of hello_imgui_platform_customization +# for IOS and MACOSX +######################################################## +function(hello_imgui_platform_customization app_name assets_location) if (MACOSX AND NOT HELLOIMGUI_MACOS_NO_BUNDLE) - - function(hello_imgui_platform_customization app_name assets_location) - hello_imgui_add_info_plist(${app_name} ${assets_location}) - hello_imgui_macos_add_icons(${app_name} ${assets_location}) - endfunction() - + hello_imgui_add_info_plist(${app_name} ${assets_location}) + hello_imgui_macos_add_icons(${app_name} ${assets_location}) elseif(IOS) - - function(hello_imgui_platform_customization app_name assets_location) - hello_imgui_ios_check_development_team() - hello_imgui_ios_set_dev_team(${app_name}) - hello_imgui_add_info_plist(${app_name} ${assets_location}) - hello_imgui_ios_copy_resources(${app_name} ${assets_location}) - hello_imgui_ios_add_icons(${app_name} ${assets_location}) - endfunction() - + hello_imgui_ios_check_development_team() + hello_imgui_ios_set_dev_team(${app_name}) + hello_imgui_add_info_plist(${app_name} ${assets_location}) + hello_imgui_ios_copy_resources(${app_name} ${assets_location}) + hello_imgui_ios_add_icons(${app_name} ${assets_location}) endif() -endif(APPLE) +endfunction() diff --git a/hello_imgui_cmake/apple/hello_imgui_ios.cmake b/hello_imgui_cmake/apple/hello_imgui_ios.cmake new file mode 100644 index 00000000..e29fe35f --- /dev/null +++ b/hello_imgui_cmake/apple/hello_imgui_ios.cmake @@ -0,0 +1,89 @@ +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() + +# Handle icons (and conversion if necessary) +function(hello_imgui_ios_add_icons app_name assets_location) + # Default HelloImGui icons + set(icons_assets_folder ${HELLOIMGUI_BASEPATH}/hello_imgui_cmake/apple/ios_icons) + set(found_custom_icon OFF) + + # First possible custom icons folder, in ios/icons + set(custom_icons_assets_folder ${CMAKE_CURRENT_SOURCE_DIR}/ios/icons) + if ((NOT found_custom_icon) AND (IS_DIRECTORY ${custom_icons_assets_folder})) + message(STATUS "hello_imgui_ios_add_icons: found ios/icons specific icons folder for app ${app_name} ") + set(icons_assets_folder ${custom_icons_assets_folder}) + set(found_custom_icon ON) + endif() + + # Second possible custom icon, in assets/app_settings/icon.png + set(custom_app_png_icon ${assets_location}/app_settings/icon.png) + if ((NOT found_custom_icon) AND (EXISTS ${custom_app_png_icon})) + # find python program + find_program(PYTHON_EXECUTABLE NAMES python3 python) + if (NOT PYTHON_EXECUTABLE) + message(WARNING " + ${app_name}: can't create iOS icon from ${custom_app_png_icon} + (did not find python) + This is not a fatal error, but the iOS app will not have the correct icon. + ") + return() + endif() + + # We need to convert icon.png to an icon folder + set(script_png_icon_to_icon_folder "${HELLOIMGUI_BASEPATH}/hello_imgui_cmake/apple/ios_png_icon_to_icon_folder.py") + message(STATUS "hello_imgui_ios_add_icons: converting ${custom_app_png_icon} to icon folder for app ${app_name} ") + set(custom_icons_assets_folder ${CMAKE_CURRENT_BINARY_DIR}/custom_icons) + execute_process( + COMMAND ${PYTHON_EXECUTABLE} ${script_png_icon_to_icon_folder} ${custom_app_png_icon} ${custom_icons_assets_folder} + RESULT_VARIABLE script_png_icon_to_icon_folder_result + ) + if (NOT ${script_png_icon_to_icon_folder_result} EQUAL 0) + message(WARNING " + ${app_name}: failed to create iOS icon from ${custom_app_icon} + Tried to run: + ${PYTHON_EXECUTABLE} ${script_png_icon_to_icon_folder} ${custom_app_png_icon} ${custom_icons_assets_folder} + This is not a fatal error, but the app will not have a custom icon. + ") + return() + endif() + + set(icons_assets_folder ${custom_icons_assets_folder}) + set(found_custom_icon ON) + endif() + + hello_imgui_apple_bundle_add_files_from_folder(${app_name} ${icons_assets_folder} "") +endfunction() + + +function(hello_imgui_ios_copy_resources app_name assets_location) + # if assets_location/app_settings/apple/Resources/ios exists, copy it to the bundle Resources folder + set(custom_resources_folder ${assets_location}/app_settings/apple/Resources/ios) + if (EXISTS ${custom_resources_folder}) + message(STATUS "hello_imgui_ios_copy_resources: found custom iOS resources folder ${custom_resources_folder} for app ${app_name} ") + hello_imgui_apple_bundle_add_files_from_folder(${app_name} ${custom_resources_folder} "Resources") + endif() +endfunction() diff --git a/hello_imgui_cmake/apple/hello_imgui_macos.cmake b/hello_imgui_cmake/apple/hello_imgui_macos.cmake new file mode 100644 index 00000000..3a9f5790 --- /dev/null +++ b/hello_imgui_cmake/apple/hello_imgui_macos.cmake @@ -0,0 +1,61 @@ +######################################################## +# Specific functions for MACOSX +######################################################## +# Handle icons (and conversion if necessary) +function(hello_imgui_macos_add_icons app_name assets_location) + # Default HelloImGui icon + set(app_icon ${HELLOIMGUI_BASEPATH}/hello_imgui_cmake/apple/mac_icons/icon.icns) + set(found_custom_icon OFF) + + # First possible custom icon in macos/icon.icns + set(custom_app_icon ${CMAKE_CURRENT_SOURCE_DIR}/macos/${HELLO_IMGUI_BUNDLE_ICON_FILE}) + if ((NOT found_custom_icon) AND (EXISTS ${custom_app_icon})) + set(app_icon ${custom_app_icon}) + set(found_custom_icon ON) + message(STATUS "hello_imgui_macos_add_icons: found app specific icon at ${custom_app_icon} for app ${app_name} ") + endif() + + # Second possible custom icon, in assets/app_settings/icon.png (which we need to convert to icon.icns) + set(custom_app_png_icon ${assets_location}/app_settings/icon.png) + if ((NOT found_custom_icon) AND (EXISTS ${custom_app_png_icon})) + # find python program + find_program(PYTHON_EXECUTABLE NAMES python3 python) + if (NOT PYTHON_EXECUTABLE) + message(WARNING " + ${app_name}: can't create a macOS icons from ${custom_app_png_icon} + (did not find python) + This is not a fatal error, but the app will not have a custom icon. + ") + return() + endif() + + # We need to convert icon.png to icon.icns + set(script_png_to_icns "${HELLOIMGUI_BASEPATH}/hello_imgui_cmake/apple/macos_png_icon_to_icns.py") + message(VERBOSE "hello_imgui_macos_add_icons: converting ${custom_app_png_icon} to icns for app ${app_name}") + set(custom_app_icon ${CMAKE_CURRENT_BINARY_DIR}/icon.icns) + execute_process( + COMMAND ${PYTHON_EXECUTABLE} ${script_png_to_icns} ${custom_app_png_icon} ${custom_app_icon} + RESULT_VARIABLE script_png_to_icns_result + ) + if (NOT ${script_png_to_icns_result} EQUAL 0) + message(WARNING " + ${app_name}: failed to create macOS icon from ${custom_app_icon} + Tried to run: + ${PYTHON_EXECUTABLE} ${script_png_to_icns} ${custom_app_png_icon} ${custom_app_icon} + This is not a fatal error, but the app will not have a custom icon. + ") + return() + endif() + + set(app_icon ${custom_app_icon}) + set(found_custom_icon ON) + message(VERBOSE "found custom icon at ${custom_app_icon} for app ${app_name} ") + endif() + + # Add icon to target + target_sources(${app_name} PRIVATE ${app_icon}) + set_source_files_properties(${app_icon} + PROPERTIES + MACOSX_PACKAGE_LOCATION "Resources" + ) +endfunction() diff --git a/hello_imgui_cmake/emscripten/hello_imgui_emscripten.cmake b/hello_imgui_cmake/emscripten/hello_imgui_emscripten.cmake index 62ed9f3c..30f3fc45 100644 --- a/hello_imgui_cmake/emscripten/hello_imgui_emscripten.cmake +++ b/hello_imgui_cmake/emscripten/hello_imgui_emscripten.cmake @@ -1,5 +1,3 @@ -if (EMSCRIPTEN) - include(${CMAKE_CURRENT_LIST_DIR}/hello_imgui_emscripten_global_options.cmake) @@ -127,5 +125,3 @@ function(hello_imgui_platform_customization app_name assets_location) _hello_imgui_emscripten_target_compile_options(${app_name}) _hello_imgui_emscripten_add_js_css_resources(${app_name} ${assets_location}) endfunction() - -endif (EMSCRIPTEN) diff --git a/hello_imgui_cmake/hello_imgui_add_app.cmake b/hello_imgui_cmake/hello_imgui_add_app.cmake index 57e17404..7ebe6716 100644 --- a/hello_imgui_cmake/hello_imgui_add_app.cmake +++ b/hello_imgui_cmake/hello_imgui_add_app.cmake @@ -88,13 +88,18 @@ endfunction() function(hello_imgui_platform_customization app_name assets_location) endfunction() # But it can be overriden by platform specific implementations, in the following files: -include(${HELLOIMGUI_CMAKE_PATH}/apple/hello_imgui_apple.cmake) -include(${HELLOIMGUI_CMAKE_PATH}/android/hello_imgui_android.cmake) -include(${HELLOIMGUI_CMAKE_PATH}/emscripten/hello_imgui_emscripten.cmake) -include(${HELLOIMGUI_CMAKE_PATH}/windows/hello_imgui_windows.cmake) -include(${HELLOIMGUI_CMAKE_PATH}/assets/hello_imgui_assets.cmake) - -include(${HELLOIMGUI_CMAKE_PATH}/android/apkCMake/apkCMake.cmake) +if(APPLE) + include(${CMAKE_CURRENT_LIST_DIR}/apple/hello_imgui_apple.cmake) +elseif(ANDROID) + include(${CMAKE_CURRENT_LIST_DIR}/android/hello_imgui_android) # almost empty + include(${CMAKE_CURRENT_LIST_DIR}/android/apkCMake/apkCMake.cmake) # most of the logic is here and called by hello_imgui_prepare_app() +elseif (EMSCRIPTEN) + include(${CMAKE_CURRENT_LIST_DIR}/emscripten/hello_imgui_emscripten.cmake) +elseif (WIN32) + include(${CMAKE_CURRENT_LIST_DIR}/windows/hello_imgui_windows.cmake) +endif() + +include(${CMAKE_CURRENT_LIST_DIR}/assets/hello_imgui_assets.cmake) function(set_bundle_variables_defaults app_name) diff --git a/hello_imgui_cmake/windows/hello_imgui_windows.cmake b/hello_imgui_cmake/windows/hello_imgui_windows.cmake index b81e5a72..6c9dd46b 100644 --- a/hello_imgui_cmake/windows/hello_imgui_windows.cmake +++ b/hello_imgui_cmake/windows/hello_imgui_windows.cmake @@ -1,67 +1,60 @@ -# if we are under windows -if (WIN32) - - function(_hello_imgui_create_windows_ico assets_location) - set(custom_app_png_icon ${assets_location}/app_settings/icon.png) - if (NOT EXISTS ${custom_app_png_icon}) - return() - endif() - - # find python program - find_program(PYTHON_EXECUTABLE NAMES python3 python) - # if python is not found, we can't create the ico file - if (NOT PYTHON_EXECUTABLE) - message(WARNING " - ${app_name}: can't create a windows ico file from ${custom_app_png_icon} - (did not find python) - This is not a fatal error, but the web app will not have a favicon. - ") - return() - endif() - - # We need to convert icon.png to a windows ico file - set(script_png_to_ico "${HELLOIMGUI_BASEPATH}/hello_imgui_cmake/windows/windows_png_icon_to_ico.py") - message(VERBOSE "_hello_imgui_create_ico: converting ${custom_app_png_icon} to windows ico for app ${app_name}") - set(custom_app_icon ${CMAKE_CURRENT_BINARY_DIR}/icon.ico) - execute_process( - COMMAND ${PYTHON_EXECUTABLE} ${script_png_to_ico} ${custom_app_png_icon} ${custom_app_icon} - RESULT_VARIABLE script_png_to_ico_result - ) - if (NOT ${script_png_to_ico_result} EQUAL 0) - message(WARNING " - ${app_name}: failed to create a Windows ico file from ${custom_app_icon} - Tried to run: - ${PYTHON_EXECUTABLE} ${script_png_to_ico} ${custom_app_png_icon} ${custom_app_icon} - - This is not a fatal error, but the app will not have a custom icon. - In order to have a custom icon, you need to have python with the Pillow package: - pip install Pillow - ") - return() - endif() - endfunction() - - function(_hello_imgui_add_windows_icon app_name assets_location) - _hello_imgui_create_windows_ico(${assets_location}) - set(custom_app_icon ${CMAKE_CURRENT_BINARY_DIR}/icon.ico) - if (NOT EXISTS ${custom_app_icon}) - return() - endif() - - # Create rc file - set(icon_rc_file "${CMAKE_CURRENT_BINARY_DIR}/app_${app_name}.rc") - set(icon_rc_file_contents "IDI_ICON1 ICON DISCARDABLE \"${custom_app_icon}\"") - file(WRITE ${icon_rc_file} ${icon_rc_file_contents}) - - # Add the rc file to the executable - target_sources(${app_name} PRIVATE ${icon_rc_file}) - endfunction() - - - function(hello_imgui_platform_customization app_name assets_location) - _hello_imgui_add_windows_icon(${app_name} ${assets_location}) - endfunction() -endif(WIN32) - - - +function(_hello_imgui_create_windows_ico assets_location) + set(custom_app_png_icon ${assets_location}/app_settings/icon.png) + if (NOT EXISTS ${custom_app_png_icon}) + return() + endif() + + # find python program + find_program(PYTHON_EXECUTABLE NAMES python3 python) + # if python is not found, we can't create the ico file + if (NOT PYTHON_EXECUTABLE) + message(WARNING " + ${app_name}: can't create a windows ico file from ${custom_app_png_icon} + (did not find python) + This is not a fatal error, but the web app will not have a favicon. + ") + return() + endif() + + # We need to convert icon.png to a windows ico file + set(script_png_to_ico "${HELLOIMGUI_BASEPATH}/hello_imgui_cmake/windows/windows_png_icon_to_ico.py") + message(VERBOSE "_hello_imgui_create_ico: converting ${custom_app_png_icon} to windows ico for app ${app_name}") + set(custom_app_icon ${CMAKE_CURRENT_BINARY_DIR}/icon.ico) + execute_process( + COMMAND ${PYTHON_EXECUTABLE} ${script_png_to_ico} ${custom_app_png_icon} ${custom_app_icon} + RESULT_VARIABLE script_png_to_ico_result + ) + if (NOT ${script_png_to_ico_result} EQUAL 0) + message(WARNING " + ${app_name}: failed to create a Windows ico file from ${custom_app_icon} + Tried to run: + ${PYTHON_EXECUTABLE} ${script_png_to_ico} ${custom_app_png_icon} ${custom_app_icon} + + This is not a fatal error, but the app will not have a custom icon. + In order to have a custom icon, you need to have python with the Pillow package: + pip install Pillow + ") + return() + endif() +endfunction() + +function(_hello_imgui_add_windows_icon app_name assets_location) + _hello_imgui_create_windows_ico(${assets_location}) + set(custom_app_icon ${CMAKE_CURRENT_BINARY_DIR}/icon.ico) + if (NOT EXISTS ${custom_app_icon}) + return() + endif() + + # Create rc file + set(icon_rc_file "${CMAKE_CURRENT_BINARY_DIR}/app_${app_name}.rc") + set(icon_rc_file_contents "IDI_ICON1 ICON DISCARDABLE \"${custom_app_icon}\"") + file(WRITE ${icon_rc_file} ${icon_rc_file_contents}) + + # Add the rc file to the executable + target_sources(${app_name} PRIVATE ${icon_rc_file}) +endfunction() + + +function(hello_imgui_platform_customization app_name assets_location) + _hello_imgui_add_windows_icon(${app_name} ${assets_location}) +endfunction()