Getting CMake's FetchContent_Declare to pull from specific branch
-
Hello everyone, I don't know if here is the right place to ask, but I'm starting to work on my note editor again. Recently, MicroTeX has recieved updates, but they are not yet present on the master branch. I'm using it to render LaTeX fragments in QTextDocuments.
my CMakeLists.txt contains these lines :
FetchContent_Declare(MicroTeX GIT_REPOSITORY https://github.com/NanoMichael/MicroTeX.git GIT_TAG origin/master ) FetchContent_MakeAvailable(MicroTeX)Since the most recent branch of MicroTeX is openmath, I've tried to change the GIT_TAG to
origin/openmathor
"openmath". However, doing so blocks all builds, as CMake says it could not clone the repository. How Can I force CMake to use this branch ?Thanks for your answers.
-
Hi,
From a quick look at the documentation of FetchContent_Declare, I think you should pass the commit hash matching that tag.
-
I've tried to change the
GIT_TAGtoorigin/openmathor"openmath". However, doing so blocks all builds, as CMake says it could not clone the repository.Can you show us the error message?
I used
GIT_TAG origin/openmathand it fetched correctly, however broke the configure step because that branch's code is full of compiler warnings, treated as error. (If I useorigin/master, I get an unmettinyxml2dependency instead, which I haven't bothered installing).I think you should pass the commit hash matching that tag.
This is correct, you should, for security (not technical) reasons:
it is advisable to use a hash for
GIT_TAGrather than a branch or tag name. A commit hash is more secure and helps to confirm that the downloaded contents are what you expected.^1But branch and tag names work too.
Since the
openmathbranch has not changed in 2 years, you could always try:GIT_TAG 086f4eb740270b28bd0c61a0a359aea9300d61ae # Current openmath HEAD.For which I get the same result as
GIT_TAG origin/openmath- ie it fetches, just has compilation errors compiling the MicroTex source.Cheers.
-
One thing I'd check first is whether the
openmathbranch actually exists on the remote and whether your local CMake cache is holding on to an older checkout.You could also try specifying the branch name directly:
FetchContent_Declare( MicroTeX GIT_REPOSITORY https://github.com/NanoMichael/MicroTeX.git GIT_TAG openmath GIT_SHALLOW FALSE )If you've already configured the project once, delete the
_depsdirectory (or at least themicrotex-srcfolder) and rerun CMake so it performs a fresh clone. I've run into cases whereFetchContentkept using the cached repository and ignored changes toGIT_TAG.If it still fails, does the error say it can't find the
openmathref, or is it failing during the clone itself? That detail would help narrow down whether it's a branch name issue or something else. -
I've tried to change the
GIT_TAGtoorigin/openmathor"openmath". However, doing so blocks all builds, as CMake says it could not clone the repository.Can you show us the error message?
I used
GIT_TAG origin/openmathand it fetched correctly, however broke the configure step because that branch's code is full of compiler warnings, treated as error. (If I useorigin/master, I get an unmettinyxml2dependency instead, which I haven't bothered installing).I think you should pass the commit hash matching that tag.
This is correct, you should, for security (not technical) reasons:
it is advisable to use a hash for
GIT_TAGrather than a branch or tag name. A commit hash is more secure and helps to confirm that the downloaded contents are what you expected.^1But branch and tag names work too.
Since the
openmathbranch has not changed in 2 years, you could always try:GIT_TAG 086f4eb740270b28bd0c61a0a359aea9300d61ae # Current openmath HEAD.For which I get the same result as
GIT_TAG origin/openmath- ie it fetches, just has compilation errors compiling the MicroTex source.Cheers.
@Paul-Colby Thanks for the clarification you made !
I was way too terse with my answer.