From 65d0d76b014143f2912f161901f765ac6d651cff Mon Sep 17 00:00:00 2001 From: Bobby Reynolds <37971212+reynoldsbd@users.noreply.github.com> Date: Tue, 2 Nov 2021 13:37:59 -0700 Subject: [PATCH] Fix cross-compilation from Windows to Linux due to CPACK logic (#436) When determining value for CPACK_PACKAGE_ARCHITECTURE, prefer to use value from CMAKE_SYSTEM_PROCESSOR before falling back to uname output. Additionally, if building from a Windows host, emit a fatal error instead of attempting to call uname. Fix By: Bobby Reynolds (@reynoldsbd) --- CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 194485a3..a84a1659 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -689,6 +689,12 @@ IF (CARES_INSTALL) if( ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" ) if ( "${CPACK_PACKAGE_ARCHITECTURE}" STREQUAL "" ) + set( CPACK_PACKAGE_ARCHITECTURE "${CMAKE_SYSTEM_PROCESSOR}" ) + endif() + if ( "${CPACK_PACKAGE_ARCHITECTURE}" STREQUAL "" ) + if ( "${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows" ) + message( FATAL_ERROR "Failed to determine CPACK_PACKAGE_ARCHITECTURE. Is CMAKE_SYSTEM_PROCESSOR set?" ) + endif() # Note: the architecture should default to the local architecture, but it # in fact comes up empty. We call `uname -m` to ask the kernel instead. EXECUTE_PROCESS( COMMAND uname -m COMMAND tr -d '\n' OUTPUT_VARIABLE CPACK_PACKAGE_ARCHITECTURE )