I’m using FetchContent to add PDF-Writer to my project.
This PDF-Writer project contains a series of subfolders for different libraries (Jpeg, Zlib…) and for the main library (PDFWriter). However, it also adds a test executable (PDFWriterTestPlayground).
If I just do FetchContent_Declare(PDF-Writer…) and FetchContent_MakeAvailable(PDF-Writer…), I’ll have the extra unwanted PDFWriterTestPlayground executable added to my project.
What’s the way to go in this case?
- FetchContent_Declare(PDF-Writer…) to download the whole repo (I’ve tried downloading each subdir but without success), then
- FetchContent_Populate(PDF-Writer), and
- add_subdirectory(LibJpeg), add_subdirectory(LibZlib), …, add_subdirectory(PDFWriter)?
The PDF-Writer project doesn’t look like it gives you any direct control over whether to pull in that subdirectory or not. You’ve got at least a few ways of tackling this situation.
OPTION A: First option is always to see if the upstream project will accept a pull request to make adding that subdirectory depend on an
option(). You could then turn that option off before calling
OPTION B: If that isn’t possible, you could create a fork of the PDF-Writer repo, make that change on your own fork in a branch and point your
FetchContent_Declare() call at your fork instead of the official repo.
OPTION C: If you don’t want to use a fork, you could use the URL download method in your
FetchContent_Declare() call, then add a
PATCH_COMMAND that applies the change you want (basically remove the
ADD_SUBDIRECTORY(PDFWriterTestPlayground) at the end of the top level
I comment on the options you wrote about:
A) It’s not possible in my case since the creator of the project stopped supporting it in 2019.
B) I thought about this one, but (I don’t know exactly for what reason) I found a better (¿more elegant?) solution to just try and use the existing project.
C) Beautiful. This is indeed somehow what I was looking for. I (think I) had got it working with the code below, but the PATCH_COMMAND seems much a better option:
Many thanks for your response!