Skip to content

Commit

Permalink
Add compatibility check between target CPU vs Skia CPU
Browse files Browse the repository at this point in the history
This should prevent several linking issues reported only because now
MSVC includes one developer prompt shortcut on Windows (to start the
x86 version) and it's quite common to use the Skia x64 version by
default.

Related to:
aseprite/aseprite#4076
aseprite/aseprite@4f3cf93
aseprite/aseprite#2501 (comment)
aseprite/aseprite#4074 (comment)
aseprite/aseprite#4122 (comment)
  • Loading branch information
dacap committed Nov 3, 2023
1 parent 5214106 commit 838550e
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions cmake/FindSkia.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,35 @@ endif()
# SkShaper module + freetype + harfbuzz + zlib
find_library(SKSHAPER_LIBRARY skshaper PATH "${SKIA_LIBRARY_DIR}")

# Check that Skia is compiled for the same CPU architecture
if(WIN32 AND
MSVC AND
NOT "${MSVC_C_ARCHITECTURE_ID}" EQUAL "" AND
EXISTS "${SKIA_LIBRARY_DIR}/args.gn" )
file(READ "${SKIA_LIBRARY_DIR}/args.gn" SKIA_ARGS_GN)
string(REGEX MATCH "target_cpu *=[ \"]*([^ \"]*)" skia_target_cpu_line "${SKIA_ARGS_GN}")

if(NOT "${skia_target_cpu_line}" EQUAL "")
# TODO We should say "laf" instead of "Aseprite", but for clarity
# with Aseprite users we just say "Aseprite"
set(skia_target_cpu "${CMAKE_MATCH_1}")
string(TOLOWER "${MSVC_C_ARCHITECTURE_ID}" aseprite_target_cpu)

if(NOT "${aseprite_target_cpu}" STREQUAL "${skia_target_cpu}")
message(FATAL_ERROR
"----------------------------------------------------------------------"
" INCOMPATIBILITY ERROR "
"----------------------------------------------------------------------\n"
" The specified Skia library (${SKIA_LIBRARY_DIR}) is compiled\n"
" for ${skia_target_cpu} CPU arch but Aseprite is being targeted for ${aseprite_target_cpu} CPU arch.\n"
" \n"
" Change Skia to the ${aseprite_target_cpu} version, or start the developer prompt for ${skia_target_cpu}:\n"
" https://docs.microsoft.com/en-us/dotnet/framework/tools/developer-command-prompt-for-vs\n"
"----------------------------------------------------------------------")
endif()
endif()
endif()

# Check that if Skia is compiled with libc++, we use -stdlib=libc++
if(UNIX AND NOT APPLE AND EXISTS "${SKIA_LIBRARY_DIR}/args.gn")
file(READ "${SKIA_LIBRARY_DIR}/args.gn" SKIA_ARGS_GN)
Expand Down

0 comments on commit 838550e

Please sign in to comment.