pthom / hello_imgui

Hello, Dear ImGui: unleash your creativity in app development and prototyping
https://pthom.github.io/hello_imgui
MIT License
678 stars 103 forks source link

add HELLO_IMGUI_LINK_LIBRARIES to hello_imgui_add_app.cmake #115

Closed andersc closed 5 months ago

andersc commented 5 months ago

Unsure if this is an OK way to include libraries to be linked or if there is another preferred way. Did not update the documentation as I felt it was showing the minimal needed cmake config.

Did test like this ->

add_library(tstlib STATIC)
target_sources(tstlib PRIVATE librarytest.cpp)

add_library(tstlib2 STATIC)
target_sources(tstlib2 PRIVATE librarytest2.cpp)

SET(HELLO_IMGUI_LINK_LIBRARIES tstlib tstlib2)
hello_imgui_add_app(hello_world main.cpp)

Where main.cpp calls some public methods in tstlib and tstlib2

pthom commented 5 months ago

Hello, thanks for this suggestion!

However, I'm not sure if this is really needed. Because what you are trying to do:

add_library(tstlib STATIC)
target_sources(tstlib PRIVATE librarytest.cpp)

add_library(tstlib2 STATIC)
target_sources(tstlib2 PRIVATE librarytest2.cpp)

SET(HELLO_IMGUI_LINK_LIBRARIES tstlib tstlib2)
hello_imgui_add_app(hello_world main.cpp)

Could be rewritten as:

add_library(tstlib STATIC)
target_sources(tstlib PRIVATE librarytest.cpp)

add_library(tstlib2 STATIC)
target_sources(tstlib2 PRIVATE librarytest2.cpp)

hello_imgui_add_app(hello_world main.cpp)

# Added this
target_link_libraries(hello_world PRIVATE tstlib tstlib2)

Would that be enough for you?

Or, if you have many many executable to generate and you are looking for a way to avoid having add the link manually for all of the executables? If so you could write a function with the same signature as hello_imgui_add_app, which would call hello_imgui_add_app and then add the link for the additional libraries.

Am I missing something? Is there another reason why this might be needed?

andersc commented 5 months ago

Hi.

Works for me and is more 'clean'.

/A