diff --git a/cmake/fetch_llvm.cmake b/cmake/fetch_llvm.cmake index deb82580..c94c669e 100644 --- a/cmake/fetch_llvm.cmake +++ b/cmake/fetch_llvm.cmake @@ -5,22 +5,16 @@ # top level to any library builds to prevent repeated checkouts. include(FetchContent) +include(${CMAKE_CURRENT_LIST_DIR}/patch_repo.cmake) if(NOT VERSIONS_JSON) include(${CMAKE_CURRENT_LIST_DIR}/read_versions.cmake) endif() read_repo_version(llvmproject llvm-project) - -set(patch_script ${CMAKE_CURRENT_LIST_DIR}/patch_repo.py) -if(GIT_PATCH_METHOD STREQUAL "am") - set(patch_script_args --method am) -elseif(GIT_PATCH_METHOD STREQUAL "apply") - set(patch_script_args --method apply) -endif() -set(patch_dir ${CMAKE_CURRENT_LIST_DIR}/../patches) -set(LLVM_PATCH_COMMAND ${Python3_EXECUTABLE} ${patch_script} ${patch_script_args} ${patch_dir}/llvm-project) +get_patch_command(llvm-project llvm_patch_command) if(APPLY_LLVM_PERFORMANCE_PATCHES) - set(LLVM_PATCH_COMMAND ${LLVM_PATCH_COMMAND} && ${Python3_EXECUTABLE} ${patch_script} ${patch_script_args} ${patch_dir}/llvm-project-perf) + get_patch_command(llvm-project-perf llvm_perf_patch_command) + set(llvm_patch_command ${llvm_patch_command} && ${llvm_perf_patch_command} ) endif() FetchContent_Declare(llvmproject @@ -28,7 +22,7 @@ FetchContent_Declare(llvmproject GIT_TAG "${llvmproject_TAG}" GIT_SHALLOW "${llvmproject_SHALLOW}" GIT_PROGRESS TRUE - PATCH_COMMAND ${LLVM_PATCH_COMMAND} + PATCH_COMMAND ${llvm_patch_command} # Add the llvm subdirectory later to ensure that # LLVMEmbeddedToolchainForArm is the first project declared. # Otherwise CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT diff --git a/cmake/fetch_newlib.cmake b/cmake/fetch_newlib.cmake index b3b621ee..e0f20def 100644 --- a/cmake/fetch_newlib.cmake +++ b/cmake/fetch_newlib.cmake @@ -5,27 +5,20 @@ # top level to any library builss to prevent repeated checkouts. include(FetchContent) +include(${CMAKE_CURRENT_LIST_DIR}/patch_repo.cmake) if(NOT VERSIONS_JSON) include(${CMAKE_CURRENT_LIST_DIR}/read_versions.cmake) endif() read_repo_version(newlib newlib) - -set(patch_script ${CMAKE_CURRENT_LIST_DIR}/patch_repo.py) -if(GIT_PATCH_METHOD STREQUAL "am") - set(patch_script_args --method am) -elseif(GIT_PATCH_METHOD STREQUAL "apply") - set(patch_script_args --method apply) -endif() -set(patch_dir ${CMAKE_CURRENT_LIST_DIR}/../patches) -set(NEWLIB_PATCH_COMMAND ${Python3_EXECUTABLE} ${patch_script} ${patch_script_args} ${patch_dir}/newlib) +get_patch_command(newlib newlib_patch_command) FetchContent_Declare(newlib GIT_REPOSITORY https://sourceware.org/git/newlib-cygwin.git GIT_TAG "${newlib_TAG}" GIT_SHALLOW "${newlib_SHALLOW}" GIT_PROGRESS TRUE - PATCH_COMMAND ${NEWLIB_PATCH_COMMAND} + PATCH_COMMAND ${newlib_patch_command} # Similarly to picolibc, we don't do the configuration here. SOURCE_SUBDIR do_not_add_newlib_subdir ) diff --git a/cmake/fetch_picolibc.cmake b/cmake/fetch_picolibc.cmake index f0ad368f..4dabc459 100644 --- a/cmake/fetch_picolibc.cmake +++ b/cmake/fetch_picolibc.cmake @@ -5,27 +5,20 @@ # top level to any library builss to prevent repeated checkouts. include(FetchContent) +include(${CMAKE_CURRENT_LIST_DIR}/patch_repo.cmake) if(NOT VERSIONS_JSON) include(${CMAKE_CURRENT_LIST_DIR}/read_versions.cmake) endif() read_repo_version(picolibc picolibc) - -set(patch_script ${CMAKE_CURRENT_LIST_DIR}/patch_repo.py) -if(GIT_PATCH_METHOD STREQUAL "am") - set(patch_script_args --method am) -elseif(GIT_PATCH_METHOD STREQUAL "apply") - set(patch_script_args --method apply) -endif() -set(patch_dir ${CMAKE_CURRENT_LIST_DIR}/../patches) -set(PICOLIBC_PATCH_COMMAND ${Python3_EXECUTABLE} ${patch_script} ${patch_script_args} ${patch_dir}/picolibc) +get_patch_command(picolibc picolibc_patch_command) FetchContent_Declare(picolibc GIT_REPOSITORY https://github.com/picolibc/picolibc.git GIT_TAG "${picolibc_TAG}" GIT_SHALLOW "${picolibc_SHALLOW}" GIT_PROGRESS TRUE - PATCH_COMMAND ${PICOLIBC_PATCH_COMMAND} + PATCH_COMMAND ${picolibc_patch_command} # We only want to download the content, not configure it at this # stage. picolibc will be built in many configurations using # ExternalProject_Add using the sources that are checked out here. diff --git a/cmake/patch_repo.cmake b/cmake/patch_repo.cmake new file mode 100644 index 00000000..c0677f72 --- /dev/null +++ b/cmake/patch_repo.cmake @@ -0,0 +1,16 @@ + +# Function to generate a PATCH_COMMAND, calling the +# patch_repo.py script using a target set of patches. + +function(get_patch_command patch_dir patch_command_out) + set(patch_script ${CMAKE_CURRENT_LIST_DIR}/patch_repo.py) + list(APPEND patch_script_args ${Python3_EXECUTABLE} ${patch_script}) + if(GIT_PATCH_METHOD STREQUAL "am") + list(APPEND patch_script_args "--method" "am") + elseif(GIT_PATCH_METHOD STREQUAL "apply") + list(APPEND patch_script_args "--method" "apply") + endif() + list(APPEND patch_script_args ${CMAKE_CURRENT_LIST_DIR}/../patches/${patch_dir}) + + set(${patch_command_out} ${patch_script_args} PARENT_SCOPE) +endfunction()