Is there some place CMake stores away the command used when generating? Or is there a way to get it to do this?
My situation is I’ve started working on a project where Conan is used and the folks that wrote the Conan files didn’t make it possible to use the individual CMake projects by themselves - you’ve got to do this giant “build everything” step that builds the world. Of course this is not optimal if you want to use an IDE while making changes in a specific CMake project.
If I could grab the generation command that was used by the “build everything” step and then just mimic that command in my IDE (i.e. plug it into a QtCreator ‘kit’) then I’d have a decent workaround for now.
I’d just re-run the generation command in the existing build folder but from within the IDE.
The long-term solution is to fix the Conan/CMake integration to be more transparent to the CMake projects, but that will take a while.
It was pointed out to me there’s a
rebuild_cache target on the CMake
Slack channel in Cpplang (thanks @ben.boeckel). I don’t know if there’s a way to use this target to help me enable IDE use with the project, though.
Perhaps the real question that should be asked is, “Does QtCreator support opening a project from a build folder with existing CMake-generated build files?” I’ve looked for this in the past but haven’t been able to do it but maybe QtCreator 9 does this? I’ll try to get that answer on the Qt forums.
You shouldn’t try to retrieve the CMake command line, it won’t always capture all the information you need. CMake’s cache is where details are captured. CMake can be re-run without any arguments at all, and it will use information in the cache from previous runs. If you are looking at a workflow that wants to retrieve the CMake command line, consider how you’d handle the situation where CMake is re-run without any arguments. At best, you should retrieve the information you want from the cache, or perhaps from the CMake file API.
Thanks, Craig. I definitely see what you’re saying. I also found a workaround for my problem that doesn’t require me to capture the original CMake command.
My first choice is always to open a CMake project within my IDE and allow it to call the generation command based on either toolchain or QtCreator kit or some combination of those. In my situation I can’t do that, but I found that I can pass an existing build folder, produced by the Conan build, to my IDE. It’s not ideal, but at least I’ll be back to having my IDE understand the complete CMake project again with all the benefits that brings.