Skip to content

Commit

Permalink
Fixing build for arm64 Windows (KhronosGroup#582)
Browse files Browse the repository at this point in the history
* Set up code signing in GitHub actions.

* Fix compile warnings in both clang_cl and mingw.

* Fix build script to return failure codes
  • Loading branch information
Honeybunch authored Jun 15, 2022
1 parent c1cede3 commit 78cda69
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 15 deletions.
29 changes: 24 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ macro(commom_lib_settings lib write)
-Wno-nested-anon-types
-Wno-gnu-anonymous-struct
>
$<$<CXX_COMPILER_ID:GNU>:
-Wno-cast-function-type
>
# not clang options
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:
-Wno-pedantic
Expand Down Expand Up @@ -524,9 +527,9 @@ PRIVATE
# "CMAKE_CXX_COMPILER_ID = ${CMAKE_CXX_COMPILER_ID} "
# "CMAKE_CXX_COMPILER_VERSION = ${CMAKE_CXX_COMPILER_VERSION}"
#)
if(MSVC)
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
# Currently no need to disable any warnings in basisu code. Rich fixed them.
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set_source_files_properties(
# It's too much work to discriminate which files need which warnings
# disabled.
Expand All @@ -543,7 +546,7 @@ elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
PROPERTIES COMPILE_OPTIONS "-Wno-unused-but-set-variable"
)
endif()
elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if (${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER_EQUAL "12.0.5")
set_source_files_properties( lib/basisu/encoder/basisu_kernels_sse.cpp
PROPERTIES COMPILE_OPTIONS "-Wno-unused-parameter;-Wno-deprecated-copy;-Wno-uninitialized-const-reference"
Expand All @@ -553,13 +556,22 @@ elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
PROPERTIES COMPILE_OPTIONS "-Wno-unused-parameter"
)
endif()
if (${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER_EQUAL "13.1")
if (${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER_EQUAL "12.0.0")
# Primarily an issue on windows using clang/clangcl
# Lowest tested clang version was 12.0.0 and highest was 14.0.4
set_source_files_properties(
lib/basisu/zstd/zstd.c
PROPERTIES COMPILE_OPTIONS "-Wno-unused-function"
)
endif()
if (${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER_EQUAL "13.0.0")
get_source_file_property(zstd_options lib/basisu/zstd/zstd.c COMPILE_OPTIONS)
set_source_files_properties(
# We haven't fixed zstd.c because the fix would have to be applied
# every time the upstream script is used to create an updated
# single file decoder.
lib/basisu/zstd/zstd.c
PROPERTIES COMPILE_OPTIONS "-Wno-unused-but-set-variable"
PROPERTIES COMPILE_OPTIONS "${zstd_options};-Wno-unused-but-set-variable"
)
endif()
if (${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER_EQUAL "15.0")
Expand Down Expand Up @@ -890,6 +902,13 @@ if( APPLE AND CMAKE_OSX_ARCHITECTURES )
else()
set(processor_name ${CMAKE_OSX_ARCHITECTURES})
endif()
elseif(CMAKE_CXX_COMPILER_ARCHITECTURE_ID)
# When targeting Windows arm64 CMAKE_SYSTEM_PROCESSOR will incorrectly
# return AMD64.
# See: https://gitlab.kitware.com/cmake/cmake/-/issues/15170
# We assume that when building for Windows arm64 that we are using MSVC
# so we can detect the processor arch name with CMAKE_CXX_COMPILER_ARCHITECTURE_ID
set(processor_name ${CMAKE_CXX_COMPILER_ARCHITECTURE_ID})
elseif( CMAKE_SYSTEM_PROCESSOR )
set(processor_name ${CMAKE_SYSTEM_PROCESSOR})
elseif( IOS )
Expand Down
6 changes: 3 additions & 3 deletions cmake/cputypetest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ function(set_target_processor_type out)
set(${out} x86_64 PARENT_SCOPE)

else()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
if("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "ARM")
if(MSVC) # MSVC is true for all msvc-style compilers, including clang-cl
if("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "ARM" OR "${CMAKE_GENERATOR_PLATFORM}" STREQUAL "arm")
set(processor "arm")
elseif("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "ARM64")
elseif("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "ARM64" OR "${CMAKE_GENERATOR_PLATFORM}" STREQUAL "arm64")
set(processor "arm64")
else()
set(C_PREPROCESS ${CMAKE_C_COMPILER} /EP /nologo)
Expand Down
13 changes: 9 additions & 4 deletions lib/etcdec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,13 @@ submitted to the exclusive jurisdiction of the Swedish Courts.
// the source of the functions or the compiled binary code.
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable: 4100 4244 )
#elif __clang__
#pragma warning(disable: 4100 4244)
#endif
// clang-cl defines both _MSC_VER and __clang__
#if __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#if __clang_major__ > 13 || (__clang_major__ == 13 && __clang_minor__ >= 1)
#if __has_warning("-Wunused-but-set-variable")
#pragma clang diagnostic ignored "-Wunused-but-set-variable"
#endif
#elif __GNUC__
Expand Down Expand Up @@ -1862,6 +1864,9 @@ void decompressBlockAlpha16bit(uint8* data, uint8* img, int width, int height, i
// Reenable warnings disabled at the top of this file.
#if defined(_MSC_VER)
#pragma warning(pop)
#else
#endif
#if __clang__
#pragma clang diagnostic pop
#elif __GNUC__
#pragma GCC diagnostic pop
#endif
2 changes: 1 addition & 1 deletion lib/gl_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ MODIFICATIONS for use in libktx
#include "formatsize.h"
#include "vkformat_enum.h"

#if defined(_WIN32)
#if defined(_WIN32) && !defined(__MINGW32__)
#define NOMINMAX
#ifndef __cplusplus
#undef inline
Expand Down
3 changes: 1 addition & 2 deletions lib/vk_funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ static HMODULE
ktxGetVulkanModuleHandle()
{
HMODULE module = NULL;
BOOL found;
found = GetModuleHandleExA(
GetModuleHandleExA(
0,
VULKANLIB,
&module
Expand Down

0 comments on commit 78cda69

Please sign in to comment.