-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update CMakeLists.txt to download properly Update README Update CMakeLists
- Loading branch information
Showing
3 changed files
with
99 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
cmake_minimum_required(VERSION 3.6) | ||
|
||
project(ImGuiExample) | ||
|
||
set(CMAKE_CXX_STANDARD 11) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
set(CMAKE_CXX_EXTENSIONS OFF) | ||
|
||
set(BUILD_FOR_ANDROID CACHE BOOL 0) | ||
|
||
set(DEAR_IMGUI_SRCS | ||
${CMAKE_CURRENT_SOURCE_DIR}/../../imgui.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/../../imgui_demo.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/../../imgui_draw.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/../../imgui_tables.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/../../imgui_widgets.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/../../backends/imgui_impl_sdl3.cpp | ||
${CMAKE_CURRENT_SOURCE_DIR}/../../backends/imgui_impl_opengl3.cpp | ||
) | ||
|
||
set(DEAR_IMGUI_HEADERS | ||
${CMAKE_CURRENT_SOURCE_DIR}/../../imgui.h | ||
${CMAKE_CURRENT_SOURCE_DIR}/../../imconfig.h | ||
${CMAKE_CURRENT_SOURCE_DIR}/../../imgui_internal.h | ||
${CMAKE_CURRENT_SOURCE_DIR}/../../imstb_rectpack.h | ||
${CMAKE_CURRENT_SOURCE_DIR}/../../imstb_textedit.h | ||
${CMAKE_CURRENT_SOURCE_DIR}/../../imstb_truetype.h | ||
${CMAKE_CURRENT_SOURCE_DIR}/../../backends/imgui_impl_sdl3.h | ||
${CMAKE_CURRENT_SOURCE_DIR}/../../backends/imgui_impl_opengl3.h | ||
) | ||
|
||
if(NOT DEFINED ENV{BUILD_FOR_ANDROID}) | ||
set(EXE "example_sdl3_opengl3") | ||
|
||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../.. ${CMAKE_CURRENT_SOURCE_DIR}/../../backends) | ||
|
||
add_executable(${EXE} ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp ${DEAR_IMGUI_SRCS}) | ||
find_package(SDL3 REQUIRED CONFIG REQUIRED COMPONENTS SDL3-shared) | ||
find_package(OpenGL REQUIRED) | ||
target_link_libraries(${EXE} PRIVATE GL GLU SDL3::SDL3) | ||
else() | ||
message(STATUS "Building SDL3 app for Android...") | ||
|
||
if(NOT DEFINED ENV{ANDROID_HOME}) | ||
message(FATAL_ERROR "Set ANDROID_HOME to path of Android Sdk.") | ||
endif() | ||
|
||
if(NOT DEFINED ENV{ANDROID_NDK_HOME}) | ||
message(FATAL_ERROR "Set ANDROID_NDK_HOME to path of Android Ndk.") | ||
endif() | ||
|
||
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE IMGUI_IMPL_OPENGL_ES3) | ||
|
||
set(ANDROID_JNI_FILES | ||
${DEAR_IMGUI_SRCS} | ||
${DEAR_IMGUI_HEADERS} | ||
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp) | ||
set(JAVA_PKG_NAME "com.example.imgui") | ||
set(SDL_DIR_NAME SDL-main) | ||
set(ANDROID_BUILD_SCRIPT "${CMAKE_BINARY_DIR}/${SDL_DIR_NAME}/build-scripts/androidbuild.sh") | ||
|
||
file(DOWNLOAD https://github.com/libsdl-org/SDL/archive/main.zip SHOW_PROGRESS ${CMAKE_BINARY_DIR}/${SDL_DIR_NAME}.zip STATUS DOWNLOAD_STATUS) | ||
file(ARCHIVE_EXTRACT INPUT ${SDL_DIR_NAME}.zip) | ||
# Separate the returned status code, and error message. | ||
list(GET DOWNLOAD_STATUS 0 STATUS_CODE) | ||
list(GET DOWNLOAD_STATUS 1 ERROR_MESSAGE) | ||
# Check if download was successful. | ||
if(${STATUS_CODE} EQUAL 0) | ||
message(STATUS "Download completed successfully!") | ||
else() | ||
# Exit CMake if the download failed, printing the error message. | ||
message(FATAL_ERROR "Error occurred during download: ${ERROR_MESSAGE}") | ||
endif() | ||
|
||
if(NOT EXISTS ${ANDROID_BUILD_SCRIPT}) | ||
message(FATAL_ERROR ": ${ANDROID_BUILD_SCRIPT} is not valid.") | ||
endif() | ||
|
||
set(ANDROID_APP_PREFIX ${CMAKE_BINARY_DIR}/${SDL_DIR_NAME}/build/${JAVA_PKG_NAME}) | ||
execute_process(COMMAND bash ${ANDROID_BUILD_SCRIPT} ${JAVA_PKG_NAME} ${ANDROID_JNI_FILES} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) | ||
if(EXISTS ${ANDROID_APP_PREFIX}/app) | ||
execute_process(COMMAND sed -i -e "s|-lGLESv2|-lGLESv3|" ${ANDROID_APP_PREFIX}/app/jni/src/Android.mk WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) | ||
execute_process(COMMAND sed -i -e "s|Game|${PROJECT_NAME}|g" ${ANDROID_APP_PREFIX}/app/src/main/res/values/strings.xml WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) | ||
execute_process(COMMAND sed -i -e "s|\"SDLActivity\"|\"${PROJECT_NAME}Activity\"|g" ${ANDROID_APP_PREFIX}/app/src/main/AndroidManifest.xml WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) | ||
endif() | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,11 @@ | ||
# Example SDL3 with OpenGL3 | ||
|
||
# How to Build | ||
## Android | ||
|
||
## Windows with Visual Studio's IDE | ||
This example can run the Dear ImGui demo app on modern Android (targeting API 33+). | ||
|
||
Use the provided project file (.vcxproj). Add to solution (imgui_examples.sln) if necessary. | ||
Set JAVA_HOME, ANDROID_HOME, and ANDROID_NDK_HOME environment variables in order to run `CMakeLists.txt`. | ||
|
||
## Windows with Visual Studio's CLI | ||
Example CMake command to run from a "build" directory within this example: `BUILD_FOR_ANDROID=1 cmake ..` | ||
|
||
Use build_win32.bat or directly: | ||
``` | ||
set SDL2_DIR=path_to_your_sdl3_folder | ||
cl /Zi /MD /utf-8 /I.. /I..\.. /I%SDL2_DIR%\include main.cpp ..\..\backends\imgui_impl_sdl3.cpp ..\..\backends\imgui_impl_opengl3.cpp ..\..\imgui*.cpp /FeDebug/example_sdl3_opengl3.exe /FoDebug/ /link /libpath:%SDL2_DIR%\lib\x86 SDL3.lib opengl32.lib /subsystem:console | ||
# ^^ include paths ^^ source files ^^ output exe ^^ output dir ^^ libraries | ||
# or for 64-bit: | ||
cl /Zi /MD /utf-8 /I.. /I..\.. /I%SDL2_DIR%\include main.cpp ..\..\backends\imgui_impl_sdl3.cpp ..\..\backends\imgui_impl_opengl3.cpp ..\..\imgui*.cpp /FeDebug/example_sdl3_opengl3.exe /FoDebug/ /link /libpath:%SDL2_DIR%\lib\x64 SDL3.lib SDL2mainopengl32.lib /subsystem:console | ||
``` | ||
|
||
## Linux and similar Unixes | ||
|
||
Use our Makefile or directly: | ||
``` | ||
c++ `sdl3-config --cflags` -I .. -I ../.. -I ../../backends | ||
main.cpp ../../backends/imgui_impl_sdl3.cpp ../../backends/imgui_impl_opengl3.cpp ../../imgui*.cpp | ||
`sdl3-config --libs` -lGL -ldl | ||
``` | ||
|
||
## macOS | ||
|
||
Use our Makefile or directly: | ||
``` | ||
brew install sdl3 | ||
c++ `sdl3-config --cflags` -I .. -I ../.. -I ../../backends | ||
main.cpp ../../backends/imgui_impl_sdl3.cpp ../../backends/imgui_impl_opengl3.cpp ../../imgui*.cpp | ||
`sdl3-config --libs` -framework OpenGl -framework CoreFoundation | ||
``` | ||
|
||
## Emscripten | ||
|
||
As of 2023-05-30 Emscripten doesn't support SDL3 yet. | ||
Example Gradle build: `ANDROID_HOME=MY_SDK_PATH ANDROID_NDK_HOME=MY_NDK_PATH build/SDL-main/build/my.java.pkg/gradlew installDebug`. This should install the demo app on a connected emulator or physical device. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters