Skip to content

Commit

Permalink
Simplify hello_imgui_add_app win32 implementation
Browse files Browse the repository at this point in the history
Before passing source list to add_executable function:

* HELLOIMGUI_WIN32_NO_CONSOLE: Prepending "WIN32" flag to the source
list

* HELLOIMGUI_WIN32_AUTO_WINMAIN: Appending HelloImGui_WinMain.cpp file
to the source list
  • Loading branch information
Boying Xu committed Mar 13, 2024
1 parent 04c5a29 commit 7472a68
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions hello_imgui_cmake/hello_imgui_add_app.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,26 @@ function(hello_imgui_add_app)
")

#############################################################################

# Add the target for the application
if (ANDROID)
add_library(${app_name} SHARED ${app_sources})
else()
add_executable(${app_name} ${app_sources})
endif()

# If windows, and if the user wants to, we can make this an app without console
# and provide a WinMain entry point
if (WIN32)
if (HELLOIMGUI_WIN32_NO_CONSOLE)
# Make this an app without console, and use HelloImGui_WinMain.cpp
if (MINGW)
target_link_options(${app_name} PRIVATE -Wl,--subsystem,windows)
else() # If MSVC
target_link_options(${app_name} PRIVATE /SUBSYSTEM:WINDOWS)
endif()
# Make this an app without console
list(PREPEND app_sources WIN32)
endif()
if (HELLOIMGUI_WIN32_AUTO_WINMAIN)
target_sources(${app_name} PRIVATE ${HELLOIMGUI_CMAKE_PATH}/HelloImGui_WinMain.cpp)
# Use HelloImGui_WinMain.cpp
list(APPEND app_sources ${HELLOIMGUI_CMAKE_PATH}/HelloImGui_WinMain.cpp)
endif()
endif()

# Add the target for the application
if (ANDROID)
add_library(${app_name} SHARED ${app_sources})
else()
add_executable(${app_name} ${app_sources})
endif()

hello_imgui_prepare_app(${app_name} ${assets_location})
endfunction()

Expand Down

0 comments on commit 7472a68

Please sign in to comment.