Skip to content

Commit

Permalink
be more sophisticated about deriving configs from macOS variables
Browse files Browse the repository at this point in the history
this patch is fixing two issues:

Currently when figuring out the toolchain package name, we make some wrong
assumptions like the presence of CMAKE_OSX_ARCHITECTURES means a unified
build. Also when CMAKE_OSX_ARCHITECTURES is not present and we are building on
macOS silicon, the package name will be `AArch64`.

Should do some parsing of the CMAKE_OSX_ARCHITECTURES and look at the
CMAKE_SYSTEM_PROCESSOR var, to deduce the right system name.

Basically when CMAKE_OSX_ARCHITECTURES is set and non-empty, this overrides the
system architecture, and we need to figure out if we do a unified build (both
x86_64 and arm64 are specified), or either.

If it's a unified build, use `unified` to make this clear, instead of the
current behaviour of omitting the arch string.

Another issue is that we use the presence of the CMAKE_OSX_ARCHITECTURES string
to infer if we should build a `.dmg` or not. Seeing the complexity around
CMAKE_OSX_ARCHITECTURES, it's better to just use CMAKE_SYSTEM_NAME, which would
always point to `Darwin`
  • Loading branch information
stuij committed Sep 26, 2023
1 parent de381f7 commit 37e42d1
Showing 1 changed file with 34 additions and 11 deletions.
45 changes: 34 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -323,25 +323,48 @@ set(CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY TRUE)
# Compress package in parallel.
set(CPACK_THREADS 0 CACHE STRING "")


if(CMAKE_OSX_ARCHITECTURES)
# For universal binaries don't include architecture in the package name.
set(CPACK_SYSTEM_NAME "${CMAKE_SYSTEM_NAME}")
# set processor_name
string(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} processor_name)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# If we're compiling on OSX we need to understand what targets we're
# building for.
string(FIND "${CMAKE_OSX_ARCHITECTURES}" "x86_64" x86_result)
string(FIND "${CMAKE_OSX_ARCHITECTURES}" "arm64" arm64_result)

if((NOT ${x86_result} EQUAL -1) AND (NOT ${arm64_result} EQUAL -1))
set(processor_name "unified")
elseif(NOT ${x86_result} EQUAL -1)
set(processor_name "x86_64")
elseif(NOT ${arm64_result} EQUAL -1)
set(processor_name "silicon")
# CMAKE_OSX_ARCHITECTURES wasn't set or malformed
# if it was malformed, we'll catch that later in the process
# we set processor_name to the system processor
elseif(${processor_name} MATCHES "arm64")
set(processor_name "silicon")
else()
set(processor_name "x86_64")
endif()
else()
string(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} processor_name)
string(REGEX MATCH "amd64|x64|x86" x86_match ${processor_name})
if(x86_match)
set(processor_name "x86_64")
else()
set(processor_name "AArch64")
endif()
if(LLVM_TOOLCHAIN_CROSS_BUILD_MINGW)
set(CPACK_SYSTEM_NAME "Windows-${processor_name}")
else()
set(CPACK_SYSTEM_NAME "${CMAKE_SYSTEM_NAME}-${processor_name}")
endif()
endif()

if(LLVM_TOOLCHAIN_CROSS_BUILD_MINGW)
set(CPACK_SYSTEM_NAME "Windows-${processor_name}")
else()
set(CPACK_SYSTEM_NAME "${CMAKE_SYSTEM_NAME}-${processor_name}")
endif()


cmake_print_variables(processor_name CPACK_SYSTEM_NAME CMAKE_SYSTEM_NAME CMAKE_SYSTEM_PROCESSOR)



add_subdirectory(
${llvmproject_SOURCE_DIR}/llvm llvm
)
Expand Down Expand Up @@ -1372,7 +1395,7 @@ endif()
if(LLVM_TOOLCHAIN_CROSS_BUILD_MINGW OR WIN32)
set(cpack_generator ZIP)
set(package_filename_extension ".zip")
elseif(CMAKE_OSX_ARCHITECTURES)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(cpack_generator DragNDrop)
set(package_filename_extension ".dmg")
else()
Expand Down

0 comments on commit 37e42d1

Please sign in to comment.