1# SPDX-License-Identifier: Apache-2.0 2# ---------------------------------------------------------------------------- 3# Copyright 2020-2023 Arm Limited 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); you may not 6# use this file except in compliance with the License. You may obtain a copy 7# of the License at: 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14# License for the specific language governing permissions and limitations 15# under the License. 16# ---------------------------------------------------------------------------- 17 18# Overwrite the LTO flags to force fat LTO; worth 3-4% performance 19# See https://gitlab.kitware.com/cmake/cmake/-/issues/16808 20if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" AND ${ASTCENC_CLI}) 21 set(CMAKE_CXX_COMPILE_OPTIONS_IPO "-flto") 22endif() 23 24if(${ASTCENC_DECOMPRESSOR}) 25 set(ASTCENC_CODEC dec) 26else() 27 set(ASTCENC_CODEC enc) 28endif() 29 30set(ASTCENC_ARTIFACTS native none neon avx2 sse4.1 sse2) 31set(ASTCENC_CONFIGS ${ASTCENC_ISA_NATIVE} ${ASTCENC_ISA_NONE} ${ASTCENC_ISA_NEON} ${ASTCENC_ISA_AVX2} ${ASTCENC_ISA_SSE41} ${ASTCENC_ISA_SSE2}) 32list(LENGTH ASTCENC_ARTIFACTS ASTCENC_ARTIFACTS_LEN) 33math(EXPR ASTCENC_ARTIFACTS_LEN "${ASTCENC_ARTIFACTS_LEN} - 1") 34 35foreach(INDEX RANGE ${ASTCENC_ARTIFACTS_LEN}) 36 list(GET ASTCENC_ARTIFACTS ${INDEX} ASTCENC_ARTIFACT) 37 list(GET ASTCENC_CONFIGS ${INDEX} ASTCENC_CONFIG) 38 if(${ASTCENC_CONFIG}) 39 set(ASTCENC_ISA_SIMD ${ASTCENC_ARTIFACT}) 40 41 if(${ASTCENC_ISA_SIMD} MATCHES "neon") 42 set(CMAKE_OSX_ARCHITECTURES arm64) 43 elseif(${ASTCENC_ISA_SIMD} MATCHES "avx2") 44 set(CMAKE_OSX_ARCHITECTURES x86_64h) 45 elseif(NOT ${ASTCENC_ISA_SIMD} MATCHES "none") 46 set(CMAKE_OSX_ARCHITECTURES x86_64) 47 endif() 48 49 include(cmake_core.cmake) 50 endif() 51endforeach() 52 53if(${ASTCENC_CLI} AND ${ASTCENC_UNIVERSAL_BUILD}) 54 add_custom_target( 55 astc${ASTCENC_CODEC} 56 ALL 57 COMMAND 58 lipo -create -output $<TARGET_FILE_DIR:astc${ASTCENC_CODEC}-sse4.1>/astc${ASTCENC_CODEC} -arch x86_64 $<TARGET_FILE:astc${ASTCENC_CODEC}-sse4.1> -arch x86_64h $<TARGET_FILE:astc${ASTCENC_CODEC}-avx2> -arch arm64 $<TARGET_FILE:astc${ASTCENC_CODEC}-neon> 59 VERBATIM) 60 61 add_dependencies( 62 astc${ASTCENC_CODEC} 63 astc${ASTCENC_CODEC}-sse4.1 64 astc${ASTCENC_CODEC}-avx2 65 astc${ASTCENC_CODEC}-neon) 66 67 install(PROGRAMS $<TARGET_FILE_DIR:astc${ASTCENC_CODEC}-sse4.1>/astc${ASTCENC_CODEC} 68 DESTINATION bin) 69endif() 70 71if(${ASTCENC_SHAREDLIB} AND ${ASTCENC_UNIVERSAL_BUILD}) 72 add_custom_target( 73 astc${ASTCENC_CODEC}-shared 74 ALL 75 COMMAND 76 lipo -create -output $<TARGET_FILE_DIR:astc${ASTCENC_CODEC}-sse4.1-shared>/libastc${ASTCENC_CODEC}-shared.dylib -arch x86_64 $<TARGET_FILE:astc${ASTCENC_CODEC}-sse4.1-shared> -arch x86_64h $<TARGET_FILE:astc${ASTCENC_CODEC}-avx2-shared> -arch arm64 $<TARGET_FILE:astc${ASTCENC_CODEC}-neon-shared> 77 VERBATIM) 78 79 add_dependencies( 80 astc${ASTCENC_CODEC}-shared 81 astc${ASTCENC_CODEC}-sse4.1-shared 82 astc${ASTCENC_CODEC}-avx2-shared 83 astc${ASTCENC_CODEC}-neon-shared) 84 85 install(PROGRAMS $<TARGET_FILE_DIR:astc${ASTCENC_CODEC}-sse4.1-shared>/libastc${ASTCENC_CODEC}-shared.dylib 86 DESTINATION lib) 87endif() 88 89# - - - - - - - - - - - - - - - - - - 90# Unit testing 91if(${ASTCENC_UNITTEST}) 92 set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) 93 set(CMAKE_OSX_ARCHITECTURES x86_64;arm64) 94 add_subdirectory(GoogleTest) 95 enable_testing() 96 add_subdirectory(UnitTest) 97endif() 98