Skip to content

Commit 58fe528

Browse files
dennisamelingdscho
authored andcommitted
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 e4b5d6f commit 58fe528

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

.github/workflows/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ jobs:
166166
shell: bash
167167
run: |
168168
cmake `pwd`/contrib/buildsystems/ -DCMAKE_PREFIX_PATH=`pwd`/compat/vcbuild/vcpkg/installed/${{ matrix.arch }}-windows \
169-
-DNO_GETTEXT=YesPlease -DPERL_TESTS=OFF -DPYTHON_TESTS=OFF -DCURL_NO_CURL_CMAKE=ON -DCMAKE_GENERATOR_PLATFORM=${{ matrix.arch }} -DVCPKG_ARCH=${{ matrix.arch }}-windows
169+
-DNO_GETTEXT=YesPlease -DPERL_TESTS=OFF -DPYTHON_TESTS=OFF -DCURL_NO_CURL_CMAKE=ON -DCMAKE_GENERATOR_PLATFORM=${{ matrix.arch }} -DVCPKG_ARCH=${{ matrix.arch }}-windows -DHOST_CPU=${{ matrix.arch }}
170170
- name: MSBuild
171171
run: msbuild git.sln -property:Configuration=Release -property:Platform=${{ matrix.arch }} -maxCpuCount:4 -property:PlatformToolset=v142
172172
- name: bundle artifact tar

contrib/buildsystems/CMakeLists.txt

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

224224
#default behaviour
225225
include_directories(${CMAKE_SOURCE_DIR})
226-
add_compile_definitions(GIT_HOST_CPU="${CMAKE_SYSTEM_PROCESSOR}")
226+
227+
# When cross-compiling, define HOST_CPU as the canonical name of the CPU on
228+
# which the built Git will run (for instance "x86_64").
229+
if(NOT HOST_CPU)
230+
add_compile_definitions(GIT_HOST_CPU="${CMAKE_SYSTEM_PROCESSOR}")
231+
else()
232+
add_compile_definitions(GIT_HOST_CPU="${HOST_CPU}")
233+
endif()
227234
add_compile_definitions(SHA256_BLK INTERNAL_QSORT RUNTIME_PREFIX)
228235
add_compile_definitions(NO_OPENSSL SHA1_DC SHA1DC_NO_STANDARD_INCLUDES
229236
SHA1DC_INIT_SAFE_HASH_DEFAULT=0

0 commit comments

Comments
 (0)