Closed carlocorradini closed 2 months ago
Hmm, what do you mean by "build another CPM package..." ... this sounds odd ...
Here's how I would approach this problem:
CPMAddPackage(
NAME imgui
...
DOWNLOAD_ONLY TRUE
)
set(third_party_imgui_cmakelists https://gist.github.com/rokups/f771217b2d530d170db5cb1e08e9a8f4)
file(
DOWNLOAD
${third_party_imgui_cmakelists}
${imgu_SOURCE_DIR}
EXPECTED_HASH SHA256= #whatever the hash is :D
)
add_subdirectory( ${imgui_SOURCE_DIR} ) #and maybe set EXCLUDE_FROM_ALL or SYSTEM
CPM might complain about a dirty repository if you let CPM clone the project and throw in the CMakeLists. So you might have to download the compressed source instead.
I think you are always stuck at a 3 step solution: download source, download cmakelists, add to build.
(Haven't tested it)
Awesome! This works:
CPMAddPackage(
NAME imgui
VERSION 1.91.1
GITHUB_REPOSITORY ocornut/imgui
DOWNLOAD_ONLY TRUE)
file(
DOWNLOAD
"https://gist.githubusercontent.com/rokups/f771217b2d530d170db5cb1e08e9a8f4/raw/4c2c14374ab878ca2f45daabfed4c156468e4e27/CMakeLists.txt"
"${imgui_SOURCE_DIR}/CMakeLists.txt"
EXPECTED_HASH
SHA256=fd62f69364ce13a4f7633a9b50ae6672c466bcc44be60c69c45c0c6e225bb086)
set(IMGUI_EXAMPLES FALSE)
set(IMGUI_DEMO FALSE)
set(IMGUI_ENABLE_STDLIB_SUPPORT TRUE)
add_subdirectory(${imgui_SOURCE_DIR} EXCLUDE_FROM_ALL TRUE SYSTEM TRUE)
Is there a helper CPM method similar to CPMAddPackage
that allows add_subdirectory
without requiring set(...)
?
There is cpm_add_subdirectory
. That would set all options for you, like it would when you use CPMAddPackage.
However, it's an internal function and not expected to be used outside. Atleast that's my feeling after working with CPM over the last months. :) (Also it requires other arguments, that are anoying to set.)
I agree that since cpm_add_subdirectory
is an internal function, it shouldn't be used.
What would you think, though, if we attempted to create a version that was not limited to CPM?
Since add_subdirectory
is such a common operation, it could be useful to simplify it using a CPM function like to CPMAddPackage
.
PS: Add ImGui
example?
Just fyi, I am not a maintainer. I'm just interested in, what i think is a really cool project ❤️.
PS: Add
ImGui
example?
Feel free to add something. However, recent merge-requests that add new examples have been rejected, because there are already quite a lot of them. It is encouraged to add them to the wiki section "example snippets".
I agree that since
cpm_add_subdirectory
is an internal function, it shouldn't be used. What would you think, though, if we attempted to create a version that was not limited to CPM? Sinceadd_subdirectory
is such a common operation, it could be useful to simplify it using a CPM function like toCPMAddPackage
.
This is something only the maintainer should decide, but personally I think this is outside of the scope of the cpm project and plainly not necessary.
Looping over options and setting them before calling add_subdirectory can be done in a custom function and 6 lines of code, if you really need it multiple times. And I can't think of anything else that could be added, to what essentially is a "wrapper function". :D
@Avus-c Done and agree 🥳
My use case is to configure and compile
ImGui
. Unfortunately,ImGui
does not provide a CMakeLists.txt file and therefore there is the need to create one (see https://gist.github.com/rokups/f771217b2d530d170db5cb1e08e9a8f4).I've tried two approaches, but neither is "a practical and good solution":
NAME _imgui
andDOWNLOAD_ONLY TRUE
. Then, copy the CMakeLists.txt file to${_imgui_SOURCE_DIR}
. Finally, build another CPM package with theNAME imgui
and theSOURCE_DIR ${_imgui_SOURCE_DIR}
.Do you have any suggestions or a better solution for this situation? Thanks 🥳
After this issue is resolved, I will create a PR for adding the
ImGui
example.