1cc1dc7a3Sopenharmony_ci# SPDX-License-Identifier: Apache-2.0 2cc1dc7a3Sopenharmony_ci# ---------------------------------------------------------------------------- 3cc1dc7a3Sopenharmony_ci# Copyright 2020-2024 Arm Limited 4cc1dc7a3Sopenharmony_ci# 5cc1dc7a3Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License"); you may not 6cc1dc7a3Sopenharmony_ci# use this file except in compliance with the License. You may obtain a copy 7cc1dc7a3Sopenharmony_ci# of the License at: 8cc1dc7a3Sopenharmony_ci# 9cc1dc7a3Sopenharmony_ci# http://www.apache.org/licenses/LICENSE-2.0 10cc1dc7a3Sopenharmony_ci# 11cc1dc7a3Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software 12cc1dc7a3Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13cc1dc7a3Sopenharmony_ci# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14cc1dc7a3Sopenharmony_ci# License for the specific language governing permissions and limitations 15cc1dc7a3Sopenharmony_ci# under the License. 16cc1dc7a3Sopenharmony_ci# ---------------------------------------------------------------------------- 17cc1dc7a3Sopenharmony_ci 18cc1dc7a3Sopenharmony_ci# CMake configuration 19cc1dc7a3Sopenharmony_cicmake_minimum_required(VERSION 3.15) 20cc1dc7a3Sopenharmony_cicmake_policy(SET CMP0069 NEW) # LTO support 21cc1dc7a3Sopenharmony_cicmake_policy(SET CMP0091 NEW) # MSVC runtime support 22cc1dc7a3Sopenharmony_ci 23cc1dc7a3Sopenharmony_ciif(MSVC) 24cc1dc7a3Sopenharmony_ci add_compile_options("/wd4324") # Disable structure was padded due to alignment specifier 25cc1dc7a3Sopenharmony_ciendif() 26cc1dc7a3Sopenharmony_ci 27cc1dc7a3Sopenharmony_ciproject(astcencoder VERSION 4.7.0) 28cc1dc7a3Sopenharmony_ci 29cc1dc7a3Sopenharmony_ciset(CMAKE_CXX_STANDARD 14) 30cc1dc7a3Sopenharmony_ciset(CMAKE_CXX_STANDARD_REQUIRED ON) 31cc1dc7a3Sopenharmony_ciset(CMAKE_CXX_EXTENSIONS OFF) 32cc1dc7a3Sopenharmony_ciset(CMAKE_EXPORT_COMPILE_COMMANDS 1) 33cc1dc7a3Sopenharmony_ciset(CMAKE_XCODE_ATTRIBUTE_VALID_ARCHS "x86_64 x86_64h arm64") 34cc1dc7a3Sopenharmony_ci 35cc1dc7a3Sopenharmony_ciinclude(CTest) 36cc1dc7a3Sopenharmony_ci 37cc1dc7a3Sopenharmony_cioption(ASTCENC_ISA_AVX2 "Enable astcenc builds for AVX2 SIMD") 38cc1dc7a3Sopenharmony_cioption(ASTCENC_ISA_SSE41 "Enable astcenc builds for SSE4.1 SIMD") 39cc1dc7a3Sopenharmony_cioption(ASTCENC_ISA_SSE2 "Enable astcenc builds for SSE2 SIMD") 40cc1dc7a3Sopenharmony_cioption(ASTCENC_ISA_NEON "Enable astcenc builds for NEON SIMD") 41cc1dc7a3Sopenharmony_cioption(ASTCENC_ISA_NONE "Enable astcenc builds for no SIMD") 42cc1dc7a3Sopenharmony_cioption(ASTCENC_ISA_NATIVE "Enable astcenc builds for native SIMD") 43cc1dc7a3Sopenharmony_cioption(ASTCENC_DECOMPRESSOR "Enable astcenc builds for decompression only") 44cc1dc7a3Sopenharmony_cioption(ASTCENC_SHAREDLIB "Enable astcenc builds with core library shared objects") 45cc1dc7a3Sopenharmony_cioption(ASTCENC_DIAGNOSTICS "Enable astcenc builds with diagnostic trace") 46cc1dc7a3Sopenharmony_cioption(ASTCENC_ASAN "Enable astcenc builds with address sanitizer") 47cc1dc7a3Sopenharmony_cioption(ASTCENC_UNITTEST "Enable astcenc builds with unit tests") 48cc1dc7a3Sopenharmony_cioption(ASTCENC_INVARIANCE "Enable astcenc floating point invariance" ON) 49cc1dc7a3Sopenharmony_cioption(ASTCENC_CLI "Enable build of astcenc command line tools" ON) 50cc1dc7a3Sopenharmony_ci 51cc1dc7a3Sopenharmony_ci# Preflight for some macOS-specific build options 52cc1dc7a3Sopenharmony_ciif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") 53cc1dc7a3Sopenharmony_ci option(ASTCENC_UNIVERSAL_BUILD "Enable universal multi-arch build" ON) 54cc1dc7a3Sopenharmony_ci 55cc1dc7a3Sopenharmony_ci if(${ASTCENC_UNIVERSAL_BUILD}) 56cc1dc7a3Sopenharmony_ci set(ASTCENC_ISA_SSE41 ON) 57cc1dc7a3Sopenharmony_ci set(ASTCENC_ISA_AVX2 ON) 58cc1dc7a3Sopenharmony_ci set(ASTCENC_ISA_NEON ON) 59cc1dc7a3Sopenharmony_ci 60cc1dc7a3Sopenharmony_ci if(${ASTCENC_ISA_SSE2}) 61cc1dc7a3Sopenharmony_ci message(FATAL_ERROR "ISA_SSE2 cannot be used in a universal build") 62cc1dc7a3Sopenharmony_ci endif() 63cc1dc7a3Sopenharmony_ci 64cc1dc7a3Sopenharmony_ci if(${ASTCENC_ISA_NONE}) 65cc1dc7a3Sopenharmony_ci message(FATAL_ERROR "ISA_NONE cannot be used in a universal build") 66cc1dc7a3Sopenharmony_ci endif() 67cc1dc7a3Sopenharmony_ci 68cc1dc7a3Sopenharmony_ci if(${ASTCENC_ISA_NATIVE}) 69cc1dc7a3Sopenharmony_ci message(FATAL_ERROR "ISA_NATIVE cannot be used in a universal build") 70cc1dc7a3Sopenharmony_ci endif() 71cc1dc7a3Sopenharmony_ci endif() 72cc1dc7a3Sopenharmony_cielse() 73cc1dc7a3Sopenharmony_ci set(ASTCENC_UNIVERSAL_BUILD OFF) 74cc1dc7a3Sopenharmony_ciendif() 75cc1dc7a3Sopenharmony_ci 76cc1dc7a3Sopenharmony_ci# Count options which MUST be x64 77cc1dc7a3Sopenharmony_ciset(ASTCENC_X64_ISA_COUNT 0) 78cc1dc7a3Sopenharmony_ciset(ASTCENC_CONFIGS ${ASTCENC_ISA_AVX2} ${ASTCENC_ISA_SSE41} ${ASTCENC_ISA_SSE2}) 79cc1dc7a3Sopenharmony_ciforeach(ASTCENC_CONFIG ${ASTCENC_CONFIGS}) 80cc1dc7a3Sopenharmony_ci if(${ASTCENC_CONFIG}) 81cc1dc7a3Sopenharmony_ci math(EXPR ASTCENC_X64_ISA_COUNT "${ASTCENC_X64_ISA_COUNT} + 1") 82cc1dc7a3Sopenharmony_ci endif() 83cc1dc7a3Sopenharmony_ciendforeach() 84cc1dc7a3Sopenharmony_ci 85cc1dc7a3Sopenharmony_ci# Count options which MUST be arm64 86cc1dc7a3Sopenharmony_ciset(ASTCENC_ARM64_ISA_COUNT 0) 87cc1dc7a3Sopenharmony_ciset(ASTCENC_CONFIGS ${ASTCENC_ISA_NEON}) 88cc1dc7a3Sopenharmony_ciforeach(ASTCENC_CONFIG ${ASTCENC_CONFIGS}) 89cc1dc7a3Sopenharmony_ci if(${ASTCENC_CONFIG}) 90cc1dc7a3Sopenharmony_ci math(EXPR ASTCENC_ARM64_ISA_COUNT "${ASTCENC_ARM64_ISA_COUNT} + 1") 91cc1dc7a3Sopenharmony_ci endif() 92cc1dc7a3Sopenharmony_ciendforeach() 93cc1dc7a3Sopenharmony_ci 94cc1dc7a3Sopenharmony_ci# Non-macOS builds 95cc1dc7a3Sopenharmony_ciif(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") 96cc1dc7a3Sopenharmony_ci if(("${ASTCENC_ARM64_ISA_COUNT}" GREATER 0) AND ("${ASTCENC_X64_ISA_COUNT}" GREATER 0)) 97cc1dc7a3Sopenharmony_ci message(FATAL_ERROR "Builds can only support a single architecture per configure.") 98cc1dc7a3Sopenharmony_ci endif() 99cc1dc7a3Sopenharmony_ciendif() 100cc1dc7a3Sopenharmony_ci 101cc1dc7a3Sopenharmony_ci# If nothing more specific is set then fall back on the compiler's defaults 102cc1dc7a3Sopenharmony_ciif(("${ASTCENC_ARM64_ISA_COUNT}" EQUAL 0) AND ("${ASTCENC_X64_ISA_COUNT}" EQUAL 0) AND (NOT "${ASTCENC_ISA_NONE}")) 103cc1dc7a3Sopenharmony_ci set(ASTCENC_ISA_NATIVE ON) 104cc1dc7a3Sopenharmony_ciendif() 105cc1dc7a3Sopenharmony_ci 106cc1dc7a3Sopenharmony_cifunction(printopt optName optVal) 107cc1dc7a3Sopenharmony_ci if(${optVal}) 108cc1dc7a3Sopenharmony_ci message(STATUS " ${optName} - ON") 109cc1dc7a3Sopenharmony_ci else() 110cc1dc7a3Sopenharmony_ci message(STATUS " ${optName} - OFF") 111cc1dc7a3Sopenharmony_ci endif() 112cc1dc7a3Sopenharmony_ciendfunction() 113cc1dc7a3Sopenharmony_ci 114cc1dc7a3Sopenharmony_ciif("${ASTCENC_BLOCK_MAX_TEXELS}") 115cc1dc7a3Sopenharmony_ci message(STATUS " Max block texels - ${ASTCENC_BLOCK_MAX_TEXELS}") 116cc1dc7a3Sopenharmony_ciendif() 117cc1dc7a3Sopenharmony_ci 118cc1dc7a3Sopenharmony_ciprintopt("AVX2 backend " ${ASTCENC_ISA_AVX2}) 119cc1dc7a3Sopenharmony_ciprintopt("SSE4.1 backend " ${ASTCENC_ISA_SSE41}) 120cc1dc7a3Sopenharmony_ciprintopt("SSE2 backend " ${ASTCENC_ISA_SSE2}) 121cc1dc7a3Sopenharmony_ciprintopt("NEON backend " ${ASTCENC_ISA_NEON}) 122cc1dc7a3Sopenharmony_ciprintopt("NONE backend " ${ASTCENC_ISA_NONE}) 123cc1dc7a3Sopenharmony_ciprintopt("NATIVE backend " ${ASTCENC_ISA_NATIVE}) 124cc1dc7a3Sopenharmony_ciif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") 125cc1dc7a3Sopenharmony_ci printopt("Universal bin " ${ASTCENC_UNIVERSAL_BUILD}) 126cc1dc7a3Sopenharmony_ciendif() 127cc1dc7a3Sopenharmony_ciprintopt("Invariance " ${ASTCENC_INVARIANCE}) 128cc1dc7a3Sopenharmony_ciprintopt("Shared libs " ${ASTCENC_SHAREDLIB}) 129cc1dc7a3Sopenharmony_ciprintopt("Decompressor " ${ASTCENC_DECOMPRESSOR}) 130cc1dc7a3Sopenharmony_ciprintopt("Diagnostics " ${ASTCENC_DIAGNOSTICS}) 131cc1dc7a3Sopenharmony_ciprintopt("ASAN " ${ASTCENC_ASAN}) 132cc1dc7a3Sopenharmony_ciprintopt("Unit tests " ${ASTCENC_UNITTEST}) 133cc1dc7a3Sopenharmony_ci 134cc1dc7a3Sopenharmony_ci# Subcomponents 135cc1dc7a3Sopenharmony_ciadd_subdirectory(Source) 136cc1dc7a3Sopenharmony_ci 137cc1dc7a3Sopenharmony_ci# Configure package archive 138cc1dc7a3Sopenharmony_ciif(ASTCENC_PACKAGE) 139cc1dc7a3Sopenharmony_ci if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") 140cc1dc7a3Sopenharmony_ci string(TOLOWER "macOS" ASTCENC_PKG_OS) 141cc1dc7a3Sopenharmony_ci else() 142cc1dc7a3Sopenharmony_ci string(TOLOWER ${CMAKE_SYSTEM_NAME} ASTCENC_PKG_OS) 143cc1dc7a3Sopenharmony_ci endif() 144cc1dc7a3Sopenharmony_ci 145cc1dc7a3Sopenharmony_ci set(CPACK_PACKAGE_FILE_NAME "astcenc-${CMAKE_PROJECT_VERSION}-${ASTCENC_PKG_OS}-${ASTCENC_PACKAGE}") 146cc1dc7a3Sopenharmony_ci set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY FALSE) 147cc1dc7a3Sopenharmony_ci set(CPACK_PACKAGE_CHECKSUM SHA256) 148cc1dc7a3Sopenharmony_ci set(CPACK_GENERATOR ZIP) 149cc1dc7a3Sopenharmony_ci 150cc1dc7a3Sopenharmony_ci include(CPack) # Must be included after CPack configuration. 151cc1dc7a3Sopenharmony_ciendif() 152