Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CMake integration #125

Closed

Conversation

seanballais
Copy link

@seanballais seanballais commented Oct 5, 2020

I am using ImPlot in a project of mine. My project uses CMake, and having CMake support in dependencies that I obtain from repositories makes it easier for me to use them in my project. As such, I have added a CMakeLists.txt to my fork of ImPlot so that I can integrate it more easily to my project. I am writing this PR in the hopes that my modifications might be helpful to other developers.

Developers can integrate ImPlot to their CMake project by adding the following lines in a CMakeLists.txt file:

include_directories(path/to/implot/)
add_subdirectory(path/to/implot/)

And then link ImPlot to their executable by doing

target_link_libraries(<target executable>
    implot
    <other libraries>)

if they want to link the static version of ImPlot, or

target_link_libraries(<target executable>
    implot_shared
    <other libraries>)

if they want to the shared version.

I have added three options in the CMakeLists.txt file that can be toggled on or off by setting their values to either ON or OFF, respectively:

  • BUILD_IMPLOT_SHARED - builds a shared library version of ImPlot; turned on by default
  • BUILD_IMPLOT_STATIC - builds a static library version of ImPlot; turned on by default
  • BUILD_IMPLOT_DEMO - includes the demo in the library; turned off by default

I've also updated the README to include the documentation for CMake integration.

@epezent
Copy link
Owner

epezent commented Oct 15, 2020

Hi! Thank you for submitting this PR. I'm sure some may find it useful. However, I will not be merging this yet as:

  1. ImGui does not yet support CMake officially, so it feels strange for us to
  2. Adding ImPlot sources manually to a target in CMake is about as much code as what's above. There's not much benefit that I can see.
  3. I suspect that people using ImPlot either add its sources directly to their own, or add them to their ImGui library complication. Compiling ImPlot as a separate lib seems like overkill.

If and when ImGui provides support for CMake, I'll reopen the issue. To be clear, I use CMake religously and I don't see much benefit to supporting it until ImGui does. Follow their on-going discussion here: ocornut/imgui#1713

Also, just as an FYI to you and others: you should probably never link ImGui or ImPlot dynamically as both are quite call heavy.

@epezent epezent closed this Oct 15, 2020
@seanballais
Copy link
Author

seanballais commented Oct 15, 2020

Hey, @epezent! Thanks for the feedback! 2 and 3 are good points.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants