Skip to content

Commit cf7d219

Browse files
committed
cmake(): allow setting HOST_CPU for cross-compilation
Git's regular Makefile mentions that HOST_CPU should be defined when cross-compiling Git: https://github.com/git-for-windows/git/blob/37796bca76ef4180c39ee508ca3e42c0777ba444/Makefile#L438-L439 This is then used to set the GIT_HOST_CPU variable when compiling Git: https://github.com/git-for-windows/git/blob/37796bca76ef4180c39ee508ca3e42c0777ba444/Makefile#L1337-L1341 Then, when the user runs `git version --build-options`, it returns that value: https://github.com/git-for-windows/git/blob/37796bca76ef4180c39ee508ca3e42c0777ba444/help.c#L658 This commit adds the same functionality to the CMake configuration. Users can now set -DHOST_CPU= to set the target architecture. Signed-off-by: Dennis Ameling <[email protected]>
1 parent 37796bc commit cf7d219

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

.github/workflows/git-artifacts.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ jobs:
295295
run: |
296296
cmake `pwd`/contrib/buildsystems/ -DCMAKE_PREFIX_PATH=`pwd`/compat/vcbuild/vcpkg/installed/arm64-windows \
297297
-DNO_GETTEXT=YesPlease -DPERL_TESTS=OFF -DPYTHON_TESTS=OFF -DCURL_NO_CURL_CMAKE=ON -DCMAKE_GENERATOR_PLATFORM=arm64 -DVCPKG_ARCH=arm64-windows \
298-
-DCMAKE_INSTALL_PREFIX="`pwd`/git-arm64" -DSKIP_DASHED_BUILT_INS=ON
298+
-DCMAKE_INSTALL_PREFIX="`pwd`/git-arm64" -DSKIP_DASHED_BUILT_INS=ON -DHOST_CPU=arm64
299299
- name: MSBuild
300300
if: env.SKIP != 'true'
301301
run: msbuild git.sln -property:Configuration=Release

contrib/buildsystems/CMakeLists.txt

+8-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,14 @@ endif()
194194

195195
#default behaviour
196196
include_directories(${CMAKE_SOURCE_DIR})
197-
add_compile_definitions(GIT_HOST_CPU="${CMAKE_SYSTEM_PROCESSOR}")
197+
198+
# When cross-compiling, define HOST_CPU as the canonical name of the CPU on
199+
# which the built Git will run (for instance "x86_64").
200+
if(NOT HOST_CPU)
201+
add_compile_definitions(GIT_HOST_CPU="${CMAKE_SYSTEM_PROCESSOR}")
202+
else()
203+
add_compile_definitions(GIT_HOST_CPU="${HOST_CPU}")
204+
endif()
198205
add_compile_definitions(SHA256_BLK INTERNAL_QSORT RUNTIME_PREFIX)
199206
add_compile_definitions(NO_OPENSSL SHA1_DC SHA1DC_NO_STANDARD_INCLUDES
200207
SHA1DC_INIT_SAFE_HASH_DEFAULT=0

0 commit comments

Comments
 (0)