mosra / magnum-integration

Integration libraries for the Magnum C++11 graphics engine
https://magnum.graphics/
Other
97 stars 44 forks source link

Custom flags for Dear ImGui integration #76

Closed Xeverous closed 3 years ago

Xeverous commented 3 years ago

I have this problem: https://stackoverflow.com/a/57608651/4818802

I want to add target_compile_options(??? PUBLIC $<$<CXX_COMPILER_ID:GNU>:-D__USE_MINGW_ANSI_STDIO=1>) so that ImGui is built with this flag and the flag is forwarded to my project. What would be a correct target? I can not specify this property on MagnumIntegration::ImGui because it is an ALIAS target.

I'm also open to other solutions - preferably through CMake but without touching stuff like CMAKE_CXX_FLAGS.

pezcode commented 3 years ago

Try adding the compile flag to MagnumImGuiIntegration, but you'll need CMake 3.13 to modify targets created in a different directory.

Something like the following could work with older CMake versions:

set_source_files_properties("${IMGUI_DIR}/imgui.cpp"
    TARGET_DIRECTORY MagnumImGuiIntegration
    PROPERTIES COMPILE_DEFINITIONS $<$<CXX_COMPILER_ID:GNU>:__USE_MINGW_ANSI_STDIO=1>
)
Xeverous commented 3 years ago

I'm using CMake 3.18 (and willing to upgrade whenever needed). This works: target_compile_options(MagnumImGuiIntegration PUBLIC $<$<CXX_COMPILER_ID:GNU>:-D__USE_MINGW_ANSI_STDIO=1>) but I still get the warning. The problem lies in Dear ImGui's #define IM_FMTARGS(FMT) __attribute__((format(printf, FMT, FMT+1))) which might not be correct for MinGW (which has ms_printf and gnu_printf formats).

Xeverous commented 3 years ago

I don't get the warning when using printf even without __USE_MINGW_ANSI_STDIO, it only happens for ImGui's functions.

Xeverous commented 3 years ago

I think it's Dear ImGui's fault in this case: https://github.com/ocornut/imgui/issues/3592. I don't get these warnings for standard printf and ImGui uses them in their implementation - ImGui's text functions are just incorrectly labeled for MinGW.