DRTVWR-418: Compute ADDRESS_SIZE from arch if not specified.

Migrate the logic formerly used only for LINUX to detect whether ADDRESS_SIZE
is set to 32 or 64, and if not, detect a default for the platform. But instead
of using uname -m, use python's platform.machine().

On Windows, stop forcing ARCH to i686 and ADDRESS_SIZE to 32.

On Mac, reset default to x86_64 instead of i386; stop forcing ADDRESS_SIZE to
32.
master
Nat Goodspeed 2016-11-16 15:27:36 -05:00
parent 934b94e74a
commit 8c061ab184
1 changed files with 34 additions and 26 deletions

View File

@ -60,38 +60,47 @@ if (NOT CMAKE_BUILD_TYPE)
"Build type. One of: Debug Release RelWithDebInfo" FORCE)
endif (NOT CMAKE_BUILD_TYPE)
# If someone has specified an address size, use that to determine the
# architecture. Otherwise, let the architecture specify the address size.
if (ADDRESS_SIZE EQUAL 32)
#message(STATUS "ADDRESS_SIZE is 32")
set(ARCH i686)
elseif (ADDRESS_SIZE EQUAL 64)
#message(STATUS "ADDRESS_SIZE is 64")
set(ARCH x86_64)
else (ADDRESS_SIZE EQUAL 32)
#message(STATUS "ADDRESS_SIZE is UNRECOGNIZED: '${ADDRESS_SIZE}'")
# Use Python's platform.machine() since uname -m isn't available everywhere.
# Even if you can assume cygwin uname -m, the answer depends on whether
# you're running 32-bit cygwin or 64-bit cygwin! But even 32-bit Python will
# report a 64-bit processor.
execute_process(COMMAND
"${PYTHON_EXECUTABLE}" "-c"
"import platform; print platform.machine()"
OUTPUT_VARIABLE ARCH OUTPUT_STRIP_TRAILING_WHITESPACE)
# We expect values of the form i386, i686, x86_64, AMD64.
# In CMake, expressing ARCH.endswith('64') is awkward:
string(LENGTH "${ARCH}" ARCH_LENGTH)
math(EXPR ARCH_LEN_2 "${ARCH_LENGTH} - 2")
string(SUBSTRING "${ARCH}" ${ARCH_LEN_2} 2 ARCH_LAST_2)
if (ARCH_LAST_2 STREQUAL 64)
#message(STATUS "ARCH is detected as 64; ARCH is ${ARCH}")
set(ADDRESS_SIZE 64)
else ()
#message(STATUS "ARCH is detected as 32; ARCH is ${ARCH}")
set(ADDRESS_SIZE 32)
endif ()
endif (ADDRESS_SIZE EQUAL 32)
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(WINDOWS ON BOOL FORCE)
set(ARCH i686)
set(LL_ARCH ${ARCH}_win32)
set(LL_ARCH_DIR ${ARCH}-win32)
set(ADDRESS_SIZE 32)
endif (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(LINUX ON BOOl FORCE)
# If someone has specified a word size, use that to determine the
# architecture. Otherwise, let the architecture specify the word size.
if (ADDRESS_SIZE EQUAL 32)
#message(STATUS "ADDRESS_SIZE is 32")
set(ARCH i686)
elseif (ADDRESS_SIZE EQUAL 64)
#message(STATUS "ADDRESS_SIZE is 64")
set(ARCH x86_64)
else (ADDRESS_SIZE EQUAL 32)
#message(STATUS "ADDRESS_SIZE is UNDEFINED")
execute_process(COMMAND uname -m COMMAND sed s/i.86/i686/
OUTPUT_VARIABLE ARCH OUTPUT_STRIP_TRAILING_WHITESPACE)
if (ARCH STREQUAL x86_64)
#message(STATUS "ARCH is detected as 64; ARCH is ${ARCH}")
set(ADDRESS_SIZE 64)
else (ARCH STREQUAL x86_64)
#message(STATUS "ARCH is detected as 32; ARCH is ${ARCH}")
set(ADDRESS_SIZE 32)
endif (ARCH STREQUAL x86_64)
endif (ADDRESS_SIZE EQUAL 32)
if (ADDRESS_SIZE EQUAL 32)
set(DEB_ARCHITECTURE i386)
set(FIND_LIBRARY_USE_LIB64_PATHS OFF)
@ -143,15 +152,14 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libstdc++")
set(CMAKE_XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT dwarf-with-dsym)
# Build only for i386 by default, system default on MacOSX 10.6+ is x86_64
# Build only for x86_64 by default
if (NOT CMAKE_OSX_ARCHITECTURES)
set(CMAKE_OSX_ARCHITECTURES "i386")
set(CMAKE_OSX_ARCHITECTURES "x86_64")
endif (NOT CMAKE_OSX_ARCHITECTURES)
set(ARCH ${CMAKE_OSX_ARCHITECTURES})
set(LL_ARCH ${ARCH}_darwin)
set(LL_ARCH_DIR universal-darwin)
set(ADDRESS_SIZE 32)
endif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# Default deploy grid