init
build / Windows (push) Has been cancelled
build / Linux (push) Has been cancelled
build / MacOS (push) Has been cancelled
build / iOS (push) Has been cancelled
build / Emscripten (push) Has been cancelled
build / Android (push) Has been cancelled
scheduled / scheduled (push) Has been cancelled

This commit is contained in:
yhqe committed 2026-03-26 01:10:42 -05:00
commit e756769780
201 files changed
+183124

No files matched your search

@@ -0,0 +1,137 @@
cmake_minimum_required(VERSION 3.20)
project(example_win32_directx11)
# ---------------------------------------------------------------------------
# C++ standard
# The original .vcxproj used "stdcpplatest" on x64 configs. CMake 3.20+
# supports C++23; adjust downward to 20 if your toolchain doesn't support 23.
# ---------------------------------------------------------------------------
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# ---------------------------------------------------------------------------
# Source files
# Paths are relative to this CMakeLists.txt, which lives at:
# astral/examples/example_win32_directx11/
# ---------------------------------------------------------------------------
set(IMGUI_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../..")
set(SOURCES
main.cpp
# core imgui
${IMGUI_ROOT}/imgui.cpp
${IMGUI_ROOT}/imgui_demo.cpp
${IMGUI_ROOT}/imgui_draw.cpp
${IMGUI_ROOT}/imgui_tables.cpp
${IMGUI_ROOT}/imgui_widgets.cpp
# Win32 + DirectX 11 backends
${IMGUI_ROOT}/backends/imgui_impl_dx11.cpp
${IMGUI_ROOT}/backends/imgui_impl_win32.cpp
# FreeType font rasterizer — always compiled because imconfig.h defines
# IMGUI_ENABLE_FREETYPE unconditionally.
${IMGUI_ROOT}/misc/freetype/imgui_freetype.cpp
)
# ---------------------------------------------------------------------------
# Target
# ---------------------------------------------------------------------------
add_executable(${PROJECT_NAME} ${SOURCES})
# ---------------------------------------------------------------------------
# Include directories
# ---------------------------------------------------------------------------
target_include_directories(${PROJECT_NAME} PRIVATE
${IMGUI_ROOT}
${IMGUI_ROOT}/backends
)
# ---------------------------------------------------------------------------
# Preprocessor definitions
# ---------------------------------------------------------------------------
# The original project used Unicode on Win32 and MultiByte on x64.
# We default to Unicode (the more modern choice). Override with -DUSE_MBCS=ON.
option(USE_MBCS "Use Multi-Byte Character Set instead of Unicode" OFF)
if(USE_MBCS)
target_compile_definitions(${PROJECT_NAME} PRIVATE _MBCS)
else()
target_compile_definitions(${PROJECT_NAME} PRIVATE UNICODE _UNICODE)
endif()
# ---------------------------------------------------------------------------
# Compiler options (MSVC)
# ---------------------------------------------------------------------------
if(MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE
/W4 # Warning level 4 (original setting)
/utf-8 # Source and execution charset = UTF-8
/MP # Multi-processor compilation (was enabled on x64 configs)
)
# Debug-specific flags
target_compile_options(${PROJECT_NAME} PRIVATE
$<$<CONFIG:Debug>:/Od> # Disable optimization
)
# Release-specific flags
target_compile_options(${PROJECT_NAME} PRIVATE
$<$<CONFIG:Release>:/O2> # Max speed
$<$<CONFIG:Release>:/Gy> # Function-level linking
$<$<CONFIG:Release>:/Oi> # Intrinsic functions
$<$<CONFIG:Release>:/GS-> # Disable buffer security check (as in original)
)
# Link-time code generation / whole-program optimisation for Release
set_property(TARGET ${PROJECT_NAME} PROPERTY
INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE
)
# Linker: COMDAT folding + reference optimisation for Release
target_link_options(${PROJECT_NAME} PRIVATE
$<$<CONFIG:Release>:/OPT:REF>
$<$<CONFIG:Release>:/OPT:ICF>
)
# Always emit PDB debug info (GenerateDebugInformation was true in all configs)
target_link_options(${PROJECT_NAME} PRIVATE /DEBUG)
# Console subsystem (SubSystem = Console in original)
target_link_options(${PROJECT_NAME} PRIVATE /SUBSYSTEM:CONSOLE)
endif()
# ---------------------------------------------------------------------------
# Link libraries
# ---------------------------------------------------------------------------
target_link_libraries(${PROJECT_NAME} PRIVATE
d3d11
d3dcompiler
dxgi
dwmapi # Required for DwmIsCompositionEnabled / DwmEnableBlurBehindWindow etc.
)
# FreeType — try a system/vcpkg install first, fall back to the local libs/ copy.
find_package(Freetype QUIET)
if(Freetype_FOUND)
target_link_libraries(${PROJECT_NAME} PRIVATE Freetype::Freetype)
else()
message(STATUS "System FreeType not found, falling back to local libs/freetype")
target_include_directories(${PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../libs/freetype/include
)
target_link_directories(${PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../libs/freetype/objs
)
target_link_libraries(${PROJECT_NAME} PRIVATE freetype)
endif()
# ---------------------------------------------------------------------------
# Output directories (mirrors the original build\debug / build\release layout)
# ---------------------------------------------------------------------------
set_target_properties(${PROJECT_NAME} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/build/debug"
RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/build/release"
)