-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
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 project #1713
base: master
Are you sure you want to change the base?
Add CMake project #1713
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
cmake_minimum_required(VERSION 3.1) | ||
|
||
# Fetching version from header file | ||
file(STRINGS ../imgui.h ImGui_VERSION_NUM_HEADER_STRING | ||
REGEX "#define[ \t]+IMGUI_VERSION_NUM[ \t]+([0-9]+)" | ||
LIMIT_COUNT 1) | ||
string(REGEX REPLACE "#define[ \t]+IMGUI_VERSION_NUM[ \t]+([0-9]+)" "\\1" | ||
IMGUI_VERSION_NUM "${ImGui_VERSION_NUM_HEADER_STRING}") | ||
math(EXPR IMGUI_VERSION_MAJOR "${IMGUI_VERSION_NUM} / 10000") | ||
math(EXPR IMGUI_VERSION_MINOR "(${IMGUI_VERSION_NUM} % 10000) / 100") | ||
math(EXPR IMGUI_VERSION_PATCH "${IMGUI_VERSION_NUM} % 100") | ||
|
||
project(imgui_examples | ||
VERSION "${IMGUI_VERSION_MAJOR}.${IMGUI_VERSION_MINOR}.${IMGUI_VERSION_PATCH}" | ||
LANGUAGES CXX) | ||
|
||
get_filename_component(ImGui_SRCDIR "${CMAKE_CURRENT_LIST_DIR}" DIRECTORY) | ||
|
||
include("${CMAKE_CURRENT_LIST_DIR}/ImGuiModule.cmake") | ||
|
||
set(ImGui_OPTIONS) | ||
|
||
imgui_option(USER_CONFIG "Dear ImGui user config for include" "" STRING) | ||
imgui_option(EXAMPLES "Dear ImGui example applications" ON) | ||
imgui_option(BACKENDS "Dear ImGui platform and render backends" ON) | ||
imgui_option(MISC "Dear ImGui misc features" ON) | ||
imgui_option(3RDPARTY "Dear ImGui example dependencies" ON) | ||
imgui_option(OPENGL_LOADER | ||
"Dear ImGui OpenGL loader (IMGL3W, GL3W, GLEW, GLAD or CUSTOM)" | ||
"IMGL3W" | ||
STRINGS "IMGL3W" "GL3W" "GLEW" "GLAD" "CUSTOM") | ||
imgui_option(FREETYPE "Dear ImGui will build font atlases using FreeType instead of stb_truetype" OFF) | ||
imgui_option(TOOLS "Dear ImGui auxiliary applications" OFF) | ||
imgui_option(PACKAGE "Dear ImGui packaging" OFF) | ||
|
||
file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/ImGuiOptions.cmake" | ||
CONTENT "${ImGui_OPTIONS_CMAKE}") | ||
|
||
include("${CMAKE_CURRENT_LIST_DIR}/ImGuiTargets.cmake") | ||
|
||
set(ImGui_DIR "${CMAKE_CURRENT_LIST_DIR}") | ||
|
||
imgui_example(example_null | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will be nice to only have this example to be built by default and then have imgui_option for building each of the examples, because right now I can't imagine a case where user would want to build every example - this requires too much dependencies. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Usually everything is built by default and then for people that want to tailor their builds they manually set options to I heavily suggest this be the case, as fresh clones for contributing won't need to guess at what options to build just to e.g. fix a bug or add a feature, whereas a consuming project will be willing to take the time to tailor the builds to their usecases. tl;dr everything should be enabled by default (a full build). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that applies here, as you are usually only interested in one particular combination of platform and render backend. I'd wager a guess that contributors are more likely to figure out what build options to use (or spend the time to download all the different bindings) than people who "just want to try it out". That is double true for people that don't use ImGui directly, but where ImGui is a dependency of their dependency. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Qix- Actually, the modern convention is to only default everything on when Also, I find that packages with lots of examples/testing/ci options are easier to work with when their "build this thing?" options are specified in the nearest cmakelists.txt to the particular example/package: in a setup like dear imguis, where the examples double as documentation, the easier it is to simply lift an example directory and start coding, the better. I know it adds some maintenance headache, but welcome to library maintenance. |
||
TARGETS Core) | ||
|
||
imgui_example(example_sdl3_sdlrenderer3 | ||
BACKENDS ImplSDL3 ImplSDLRenderer3) | ||
|
||
imgui_example(example_sdl3_opengl3 | ||
BACKENDS ImplSDL3 ImplOpenGL3) | ||
|
||
imgui_example(example_glfw_opengl3 | ||
BACKENDS ImplGlfw ImplOpenGL3) | ||
|
||
if(NOT EMSCRIPTEN) | ||
imgui_example(example_glut_opengl2 | ||
BACKENDS ImplGLUT ImplOpenGL2) | ||
|
||
imgui_example(example_sdl2_sdlrenderer2 | ||
BACKENDS ImplSDL2 ImplSDLRenderer2) | ||
|
||
imgui_example(example_sdl2_opengl2 | ||
BACKENDS ImplSDL2 ImplOpenGL2) | ||
|
||
imgui_example(example_sdl2_opengl3 | ||
BACKENDS ImplSDL2 ImplOpenGL3) | ||
|
||
imgui_example(example_sdl2_vulkan | ||
BACKENDS ImplSDL2 ImplVulkan) | ||
|
||
imgui_example(example_sdl3_vulkan | ||
BACKENDS ImplSDL3 ImplVulkan) | ||
|
||
imgui_example(example_glfw_opengl2 | ||
BACKENDS ImplGlfw ImplOpenGL2) | ||
|
||
imgui_example(example_glfw_vulkan | ||
BACKENDS ImplGlfw ImplVulkan) | ||
endif() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just out of curiosity, is emscripten exclusive of SDL/GLFW/etc? I thought SDL worked with emscripten. |
||
|
||
if(NOT "${CMAKE_CURRENT_LIST_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}") | ||
foreach(FILE ImGuiConfig.cmake ImGuiModule.cmake ImGuiTargets.cmake) | ||
configure_file(${FILE} ${FILE} COPYONLY) | ||
endforeach() | ||
endif() | ||
|
||
install(FILES ImGuiConfig.cmake ImGuiModule.cmake ImGuiTargets.cmake | ||
"${CMAKE_CURRENT_BINARY_DIR}/ImGuiOptions.cmake" | ||
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/imgui) | ||
|
||
if(ImGui_PACKAGE) | ||
if(NOT DEFINED CPACK_PACKAGE_NAME) | ||
set(CPACK_PACKAGE_NAME "dear-imgui") | ||
endif() | ||
include(CPack) | ||
endif() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"version": 2, | ||
"configurePresets": [ | ||
{ | ||
"name": "vcpkg", | ||
"generator": "Ninja", | ||
"binaryDir": "${sourceDir}/../build/${presetName}", | ||
"cacheVariables": { | ||
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" | ||
} | ||
}, | ||
{ | ||
"name": "emscripten", | ||
"inherits": "vcpkg", | ||
"cacheVariables": { | ||
"VCPKG_TARGET_TRIPLET": "wasm32-emscripten", | ||
"VCPKG_CHAINLOAD_TOOLCHAIN_FILE": "$env{EMSCRIPTEN_ROOT}/cmake/Modules/Platform/Emscripten.cmake" | ||
} | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
if(NOT DEFINED ImGui_FIND_COMPONENTS) | ||
set(ImGui_FIND_COMPONENTS Core) | ||
endif() | ||
|
||
include("${CMAKE_CURRENT_LIST_DIR}/ImGuiTargets.cmake") | ||
|
||
foreach(COMPONENT ${ImGui_FIND_COMPONENTS}) | ||
if(NOT ";${ImGui_AVAILABLE_COMPONENTS};" MATCHES ";${COMPONENT};") | ||
set(ImGui_FOUND FALSE) | ||
set(ImGui_NOT_FOUND_MESSAGE "Unavailable component: ${COMPONENT}.") | ||
endif() | ||
if(NOT ";${ImGui_SUPPORTED_COMPONENTS};" MATCHES ";${COMPONENT};") | ||
set(ImGui_FOUND FALSE) | ||
set(ImGui_NOT_FOUND_MESSAGE "Unsupported component: ${COMPONENT}.") | ||
endif() | ||
endforeach() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems way overengineered. Is this all necessary, especially seeing as how there's only one component? |
||
|
||
if(NOT ImGui_FOUND) | ||
set(ImGui_NOT_FOUND_MESSAGE "${ImGui_NOT_FOUND_MESSAGE}\nSupported components: ${ImGui_SUPPORTED_COMPONENTS}.") | ||
set(ImGui_NOT_FOUND_MESSAGE "${ImGui_NOT_FOUND_MESSAGE}\nAvailable components: ${ImGui_AVAILABLE_COMPONENTS}.") | ||
endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mix of CamelCase and ALL_CAPS is a bit unreadable. Isn't it better to go full ALL_CAPS? IMGUI_SRCDIR looks a bit better, I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. The typical naming convention is entirely upper-case unless you're referring to targets or namespaces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Who else wants to use the ALL_CAPS convention for variables?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also suggest going ALL_CAPS for the IMGUI_XXX variable, unless you thing the current way is generally more standard in cmake land (the
ImGui_OPTIONS_XXX
stuff looks odd).