CARVIEW |
Navigation Menu
-
-
Notifications
You must be signed in to change notification settings - Fork 11k
Add CMake configuration #3027
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
base: master
Are you sure you want to change the base?
Add CMake configuration #3027
Conversation
c8bce83
to
3a99ca1
Compare
Any guidance on how to test Marmalade apps would be appreciated. I'd be happy to add the configuration for them. |
81253b2
to
920e7c7
Compare
Hey i like clarity of CMake code in this PR. Great job 👍 I have a few commends:
I think it would be very convenient if we could have all of cmake scripts in one file. I know this is not exactly conventional in CMake projects. Reason i am suggesting it is because Dear ImGui is a multi-buildsystem project and CMake support would be an addon instead of a main build system. Example targets could be created by one-liner if we made a macro for it. Defining most examples is almost same. Third party dependencies could use some touching up. For example if
if (NOT DEFINED IMGUI_SDL_TARGET)
find_package(SDL2 QUIET)
if (TARGET SDL2::SDL2)
# Some platforms (Linux) have SDL target properly exported as CMake target.
set (IMGUI_SDL_TARGET SDL2::SDL2)
elseif (SDL2_FOUND)
# Platforms that do not export target but use old CMake conventions can be handled this way.
add_library(SDL2::SDL2 INTERFACE IMPORTED)
target_link_libraries(SDL2::SDL2 INTERFACE ${SDL2_LIBRARIES})
target_include_directories(SDL2::SDL2 INTERFACE ${SDL2_INCLUDE_DIRS})
set (IMGUI_SDL_TARGET SDL2::SDL2)
elseif (NOT "$ENV{SDL2_DIR}" STREQUAL "")
# On windows we may set SDL2_DIR environment variable and link to binary SDL distribution.
add_library(SDL2::SDL2 INTERFACE IMPORTED)
set_target_properties(SDL2::SDL2 PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES $ENV{SDL2_DIR}/include
INTERFACE_LINK_LIBRARIES "$ENV{SDL2_DIR}/lib/${IMGUI_PLATFORM_ARCH}/SDL2.lib;$ENV{SDL2_DIR}/lib/${IMGUI_PLATFORM_ARCH}/SDL2main.lib"
)
set (IMGUI_SDL_TARGET SDL2::SDL2)
add_custom_target(CopySDL ALL COMMAND ${CMAKE_COMMAND} -E copy
"$ENV{SDL2_DIR}/lib/${IMGUI_PLATFORM_ARCH}/SDL2.dll" "${IMGUI_OUTPUT_DIR}/$<CONFIG>/SDL2.dll")
add_dependencies(${IMGUI_SDL_TARGET} CopySDL)
elseif (PkgConfig_FOUND)
# Rest of the platforms (like MacOS) can consume SDL via pkg-config.
pkg_check_modules(SDL2 QUIET IMPORTED_TARGET sdl2)
if (SDL2_FOUND)
set (IMGUI_SDL_TARGET PkgConfig::sdl2)
endif ()
endif ()
endif () This is not perfect, but could serve as a starting point. My GLFW bit: if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../glfw/CMakeLists.txt)
# When parent directory contains GLFW source code - we can build it directly.
set (GLFW_STANDALONE OFF)
set (GLFW_INSTALL OFF)
set (GLFW_BUILD_DOCS OFF)
add_subdirectory (${CMAKE_CURRENT_SOURCE_DIR}/../glfw ${CMAKE_CURRENT_BINARY_DIR}/glfw)
set (IMGUI_GLFW_TARGET glfw)
elseif (MSVC)
# We ship compiled libraries in our repository for Visual Studio.
add_library(glfw INTERFACE IMPORTED)
target_link_libraries(glfw INTERFACE libs/glfw/lib-vc2010-${IMGUI_PLATFORM_BITS}/glfw3.lib)
target_include_directories(glfw INTERFACE libs/glfw/include)
set (IMGUI_GLFW_TARGET glfw)
elseif (PkgConfig_FOUND)
pkg_check_modules(GLFW QUIET IMPORTED_TARGET glfw3)
if (GLFW_FOUND)
set (IMGUI_GLFW_TARGET PkgConfig::glfw)
endif ()
endif () |
You can ignore this, I am going to scrap that backend and move it elsewhere eventually. |
Hey @rokups, thanks for the feedback!
Yes - using the
I'll defer to @ocornut here, but I will say this: it is indeed very unconventional, and it's going to hurt maintainability in the long-term. I highly recommend against it.
I didn't know
Definitely; this is how I intend to use ImGui in my projects as well. I still need to test, but I've written the configuration with this in mind, and I believe the current configuration allows for this. If not,
I'll give it a shot, thanks :)
Sounds good; what about allegro? I'm not familiar with that either. |
@rokups your glfw pkgconfig code seems to fail for me:
|
Imported library description does not mention this property. I guess invisibility is a byproduct of library not producing any output. And they arent object libraries as object libraries are ones that compile source files but do not link them into libraries/exes. They just inject extra includes/libs/flags to linking target. But we can exploit them to also inject source files to linking targets by using
Could maybe CMake version being rather old? See https://cmake.org/cmake/help/v3.17/module/FindPkgConfig.html?highlight=pkg%20config#module:FindPkgConfig for your version of CMake. |
This seems strange. Targets shouldn't be able to conflict - CMake wouldn't know what to do. I think there's a missing piece of information somewhere here 😅 In your opinion, what are the pros/cons of using import libraries vs. object libraries?
|
@podsvirov I didn't add it since it's not an EDIT: nevermind, I see what you mean. Added :) |
@Qix-, any efforts to export your configuration for others and install examples? |
PS: my acount is @podsvirov :-). Dear @podgorskiy, sorry for noise. |
Whoops, sorry about that. Don't know why github did that. 😅 (EDIT: Oh I see he's also active around here; yes, sorry for the noise indeed!) What do you mean by exporting configuration? As far as installation, I don't know that examples really need to have install targets. |
Yes, we can simply built examples, but then we simply build only examples... |
I don't understand what you mean by "package". Packaging what, and for whom? ImGui examples aren't going to be used by anyone outside the project, so there's no point in having an install target for them. What's the use-case? I'm pretty reluctant on adding anything that doesn't need to be added. |
What is holding back the vulkan stuff? I see the cmake files in the commit. |
@Cazadorro I only have a mac machine and (correct me if I'm wrong) ImGui doesn't have a MoltenVK sample (I've never worked with moltenvk personally). Further, you can't test Vulkan in virtual machines yet (at least, VMWare doesn't support it). Just compilation, but that doesn't tell me if it actually runs or not. |
I haven't used moltenvk, but theoretically it should be exposed the same way as vulkan, so I don't think it would require a code change to support. Do you need people to run things for you? I've got vulkan on my machines, and have gotten imgui to work in vulkan based off of the examples and implementations. |
c++ in general has the exact same problem. The solution is usually to not let the perfect become the enemy of the good and work iteratively - especially in the early phase. Start with a simple version, that covers just a few core scenarious and make sure you are reasonably happy with the way it can be used (a.k.a. the interface). Then iteratively improve it based on user feedback. Also consider that breaking changes to the build system interface are usually much less disruptive than changes to the library itself, because there is "usually" only 1 or at most a handful of locations in the user project, where that interface is used. So there is less reason to be affraid to get stuck with a "bad" interface if the initial design is not ideal. I guess what I'm trying to say: Assuming permission from @qix, you should probably just merge these changes and see what further issues / PRs pop up instead of delaying this indefinetly until no one feels there is even a point in working on cmake support at all. |
0c1e5bd
to
bb6a60b
Compare
8b83e0a
to
d735066
Compare
b3b85d8
to
0755767
Compare
c817acb
to
8d39063
Compare
…nd languages used.
e7958b9
to
b40701b
Compare
…. Renamed reference to SDL to SDL2.
I rebased this over latest, force-pushed so it's a clean PR, switched to C++11, etc. adjusted for moved backends, renamed |
Supersedes #1713. This is a much simpler configuration for use with CMake projects.
Provided here as suggested in #1713 (comment).
Platforms
General TODO's
Examples
example_allegro5
example_apple_metal
example_apple_opengl2
example_emscripten
example_glfw_metal
example_glfw_opengl2
example_glfw_opengl3
example_glfw_vulkan
example_glut_opengl2
example_null
example_sdl_directx11
example_sdl_metal
example_sdl_opengl2
example_sdl_opengl3
example_sdl_vulkan
example_win32_directx10
example_win32_directx11
example_win32_directx12
example_win32_directx9
Implementations
Let me know if I'm missing anything.