Description
Hello,
I am encountering a problem while trying to add cmocka to my cmake project using CPM. Due to internal conflicts between my toolchain file and the cmocka generation process, I have to patch some of their cmake files. To do so, I am using the PATCHES keyword and passing a list of patch files. The first configure runs perfect but subsequent reconfigurations fail with the following error:
[cmake] [ 11%] Performing update step for 'cmocka-populate'
[cmake] -- Already at requested tag: cmocka-1.1.5
[cmake] [ 22%] Performing patch step for 'cmocka-populate'
[cmake] patching file ConfigureChecks.cmake
[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 ConfigureChecks.cmake.rej
[cmake] gmake[2]: *** [CMakeFiles/cmocka-populate.dir/build.make:118: cmocka-populate-prefix/src/cmocka-populate-stamp/cmocka-populate-patch] Error 1
[cmake] gmake[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/cmocka-populate.dir/all] Error 2
[cmake] gmake: *** [Makefile:91: all] Error 2
[cmake]
[cmake] CMake Error at /usr/share/cmake-3.30/Modules/FetchContent.cmake:1918 (message):
[cmake] Build step for cmocka failed: 2
[cmake] Call Stack (most recent call first):
[cmake] /usr/share/cmake-3.30/Modules/FetchContent.cmake:1609 (__FetchContent_populateSubbuild)
[cmake] /usr/share/cmake-3.30/Modules/FetchContent.cmake:2145:EVAL:2 (__FetchContent_doPopulation)
[cmake] /usr/share/cmake-3.30/Modules/FetchContent.cmake:2145 (cmake_language)
[cmake] /usr/share/cmake-3.30/Modules/FetchContent.cmake:1978:EVAL:1 (__FetchContent_Populate)
[cmake] /usr/share/cmake-3.30/Modules/FetchContent.cmake:1978 (cmake_language)
[cmake] cmake/CPM.cmake:1074 (FetchContent_Populate)
[cmake] cmake/CPM.cmake:868 (cpm_fetch_package)
[cmake] test/cmake/FetchCMocka.cmake:21 (CPMAddPackage)
[cmake] test/CMakeLists.txt:4 (include)
[cmake]
[cmake]
[cmake] -- Configuring incomplete, errors occurred!
It seems that the failure is due to an attempt to reapply the patches when reconfiguring. This causes the problem to stop the reconfigure process because the patch command returns an error.
If so, I believe the PATCHES keyword should check whether the patches have already been applied. git apply can check it using
git apply --check
--check
Instead of applying the patch, see if the patch is applicable to the current working tree and/or the index file and detects errors. Turns off "apply". -- git manual
Otherwise is there any workaround to ensure patches are only applied if they have not been applied already?
Thank you for your help!