Open
Description
Due to a dependency with improper CMakeLists.txt I tried to use the PATCHES
field, however the second time I run the configuration CMake fails during FetchContent_MakeAvailable
for that package with this output:
[cmake] -- CPM: Adding package sqlite_protobuf@0 (082596c282cab90f50b6d6dee5f9be22fd503dbe)
[cmake] [ 11%] Performing update step for 'sqlite_protobuf-populate'
[cmake] -- Already at requested ref: 082596c282cab90f50b6d6dee5f9be22fd503dbe
[cmake] [ 22%] Performing patch step for 'sqlite_protobuf-populate'
[cmake] patching file CMakeLists.txt
[cmake] Reversed (or previously applied) patch detected! Assume -R? [n]
[cmake] Apply anyway? [n]
[cmake] Skipping patch.
[cmake] 1 out of 1 hunk ignored -- saving rejects to file CMakeLists.txt.rej
[cmake] patching file src/CMakeLists.txt
[cmake] Reversed (or previously applied) patch detected! Assume -R? [n]
[cmake] Apply anyway? [n]
[cmake] Skipping patch.
[cmake] 2 out of 2 hunks ignored -- saving rejects to file src/CMakeLists.txt.rej
[cmake] make[2]: *** [CMakeFiles/sqlite_protobuf-populate.dir/build.make:118: sqlite_protobuf-populate-prefix/src/sqlite_protobuf-populate-stamp/sqlite_protobuf-populate-patch] Error 1
[cmake] make[1]: *** [CMakeFiles/Makefile2:87: CMakeFiles/sqlite_protobuf-populate.dir/all] Error 2
[cmake] make: *** [Makefile:91: all] Error 2
[cmake]
[cmake] CMake Error at /usr/share/cmake/Modules/FetchContent.cmake:1918 (message):
[cmake] Build step for sqlite_protobuf failed: 2
[cmake] Call Stack (most recent call first):
[cmake] /usr/share/cmake/Modules/FetchContent.cmake:1609 (__FetchContent_populateSubbuild)
[cmake] /usr/share/cmake/Modules/FetchContent.cmake:2145:EVAL:2 (__FetchContent_doPopulation)
[cmake] /usr/share/cmake/Modules/FetchContent.cmake:2145 (cmake_language)
[cmake] /usr/share/cmake/Modules/FetchContent.cmake:2384 (__FetchContent_Populate)
[cmake] build/cmake/CPM_0.40.2.cmake:1114 (FetchContent_MakeAvailable)
[cmake] build/cmake/CPM_0.40.2.cmake:895 (cpm_fetch_package)
[cmake] src/wrapper/CMakeLists.txt:3 (cpmaddpackage)
[cmake]
[cmake]
[cmake] -- Configuring incomplete, errors occurred!
This is the relevant piece of my CMakeLists.txt:
cpmaddpackage(
NAME
sqlite_protobuf
GITHUB_REPOSITORY
rgov/sqlite_protobuf
GIT_TAG
082596c282cab90f50b6d6dee5f9be22fd503dbe
PATCHES
"${PROJECT_SOURCE_DIR}/cmake/sqlite_protobuf_fix.patch")
Metadata
Metadata
Assignees
Labels
No labels
Activity
soulfresh commentedon Nov 26, 2024
I'm seeing the same issue. If I choose "no" at the patch reverse step, the build fails because the patch fails to apply. If I choose "yes", then the patch is reversed and the library is no longer patched the way I need. It might be good to set a cache variable tracking each patch that has been applied and then skipping that patch on subsequent passes.
soulfresh commentedon Nov 26, 2024
For anyone else who finds this, here's my workaround:
apirogov commentedon Nov 27, 2024
Have the same issue. Hope this gets fixed soon!
apirogov commentedon Nov 28, 2024
The workaround works only when no CPM caching is used. Otherwise probably it needs to do something more reliable, like checking whether it was just freshly downloaded or not.
soulfresh commentedon Nov 29, 2024
Hmmm...it seems to work for me with CPM caching on (unless I'm misunderstanding what CPM caching does). In my project, I've set
set(CPM_SOURCE_CACHE "${CMAKE_CURRENT_SOURCE_DIR}/deps")
. On the first run, it downloads the package, applies my patch and sets my custom CMake cache variable. On subsequent runs, CPM doesn't re-download the package or apply the patch and my app builds as expected. Its possible for my custom CMake cache variable to get out of sync with the file system if the dependency cache is deleted but that CMake variable is not removed. I use aclean
script to ensure both get removed.My work around is definitely less than ideal but should work; though I may be misunderstanding something.
revert use of CPM for saucer as CPM cannot handle patches unlike Fetc…
rokups commentedon Mar 30, 2025
Could something like this be considered for a fix?
aaeberharter commentedon Apr 30, 2025
The following does NOT work reliably, instead the fix by @BohdanBuinich should be used.
carlocorradini commentedon May 8, 2025
Any update? 😥
fix: Patch commands fail trying to re-apply the same patch twice
fix: Patch commands fail trying to re-apply the same patch twice