Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMakeList - how to patch source with older cmake

Tags:

cmake

I have source code foo_src.tgz. foo_src has a Makefile that needs patching before it can be built. The CMakeLists.txt looks like this:

project(foo_prj)
cmake_minimum_required(VERSION 3.17)
enable_language(C ASM CXX)


include_directories(patchtest)

ExternalProject_Add(
        foo
        URL file://${CMAKE_CURRENT_LIST_DIR}/patchtest/foo_src.tgz
        URL_HASH MD5=b5f0cf41a1712d815fdc6ad13124f570
        PATCH_COMMAND cmake -E patch < ${CMAKE_CURRENT_LIST_DIR}/patchtest/fooMakefile.patch
        CONFIGURE_COMMAND ""
        INSTALL_COMMAND cmake -E echo "Skipping install step."
        BUILD_COMMAND make foo CC=${CMAKE_C_COMPILER}
        SOURCE_DIR patchtest
        STEP_TARGETS build
        EXCLUDE_FROM_ALL TRUE
        BUILD_IN_SOURCE 1
        BUILD_ALWAYS 1)

But this gives me a cmake -E command usage error:

CMake Error: cmake version 3.8.2
Usage: cmake -E <command> [arguments...]
Available commands: 
.
.
.

So it's worth noting that in the usage message of allowable cmake commands, 'patch' is not one of them. The cmake version available in my toolchain in only version 3.8.2. So, how can I go about patching the source with an older cmake?

edit according to this, the PATCH_COMMAND should be available.

UPDATE

Solved this. First I replaced:

PATCH_COMMAND cmake -E patch < ${CMAKE_CURRENT_LIST_DIR}/patchtest/uio48Makefile.patch

with:

PATCH_COMMAND ${CMAKE_COMMAND} -E patch < ${CMAKE_CURRENT_LIST_DIR}/patchtest/uio48Makefile.patch

This didn't work, but it did use my local cmake, version 3.17, rather than my toolchain cmake. This produced the same cmake command usage error though. I then replaced the cmake command in the patch ine like this:

PATCH_COMMAND patch < ${CMAKE_CURRENT_LIST_DIR}/patchtest/uio48Makefile.patch

This works! ya....can someone please explain?

like image 224
cogito Avatar asked Jan 19 '26 16:01

cogito


1 Answers

If in our case patch works, there might be a working command patch in your system, not cmake.

In my case, I don't have patch, but I have git apply in my system, so I use:

PATCH_COMMAND git apply "${CMAKE_CURRENT_LIST_DIR}/do-not-build-shared.diff"
like image 143
Felix F Xu Avatar answered Jan 22 '26 23:01

Felix F Xu