Skip to content

Commit 2dd4547

Browse files
committed
cmake: treat building for another ISA as a cross-compile.
CMake appears to have the notion that a build is only a cross-compile if the targt *operating system* is different. This is an incorrect notion, as even if the target is the *same* OS but a different instruction set, you may not be able to do tests that involve compiling and running a program. Check whether CMAKE_GENERATOR_PLATFORM is set and has a value different from that of CMAKE_HOST_SYSTEM_PROCESSOR and, if that's the case, set CMAKE_CROSSCOMPILING to TRUE. This comes from libpcap, where the equivalent change fixed issue the-tcpdump-group/libpcap#1352. (A different strategy may be necessary for cross-builds with UNIX toolchains.)
1 parent 10b47a8 commit 2dd4547

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,28 @@ if(MSVC)
392392
endif (USE_STATIC_RT)
393393
endif(MSVC)
394394

395+
#
396+
# CMake's definition of "cross-compiling" appears to be "compiling
397+
# for an *operating system* other than the one on which the build
398+
# is being done*.
399+
#
400+
# This is an inadequate definition, as people build for the same
401+
# operating system but a different instruciton set, e.g. building
402+
# on an IA-32 or x86-64 Linux box for an Arm embedded Linux box,
403+
# or building Arm code on an IA-32 or x86-64 Windows box.
404+
#
405+
# At least for the Windows case, people may do those builds by
406+
# setting the target with th -A flag to CMake; that causes
407+
# CMAKE_GENERATOR_PLATFORM to be set to the target. If
408+
# CMAKE_GENERATOR_PLATFORM is set, compare it with
409+
# CMAKE_HOST_SYSTEM_PROCESSOR and, if they're not equal, set
410+
# CMAKE_CROSSCOMPILING to TRUE.
411+
#
412+
if (CMAKE_GENERATOR_PLATFORM AND
413+
NOT CMAKE_GENERATOR_PLATFORM STREQUAL CMAKE_HOST_SYSTEM_PROCESSOR)
414+
set(CMAKE_CROSSCOMPILING TRUE)
415+
endif()
416+
395417
###################################################################
396418
# Detect available platform features
397419
###################################################################

0 commit comments

Comments
 (0)