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 18set(ASTCENC_TEST test-unit-${ASTCENC_ISA_SIMD}) 19 20add_executable(${ASTCENC_TEST}) 21 22# Enable LTO under the conditions where the codec library will use LTO. 23# The library link will fail if the settings don't match 24if(${ASTCENC_CLI}) 25 set_property(TARGET ${ASTCENC_TEST} 26 PROPERTY 27 INTERPROCEDURAL_OPTIMIZATION_RELEASE True) 28endif() 29 30target_sources(${ASTCENC_TEST} 31 PRIVATE 32 test_simd.cpp 33 test_softfloat.cpp 34 test_decode.cpp 35 ../astcenc_mathlib_softfloat.cpp) 36 37target_include_directories(${ASTCENC_TEST} 38 PRIVATE 39 ${gtest_SOURCE_DIR}/include) 40 41target_link_libraries(${ASTCENC_TEST} 42 PRIVATE 43 astcenc-${ASTCENC_ISA_SIMD}-static) 44 45target_compile_options(${ASTCENC_TEST} 46 PRIVATE 47 # Use pthreads on Linux/macOS 48 $<$<PLATFORM_ID:Linux,Darwin>:-pthread> 49 50 # MSVC compiler defines 51 $<$<CXX_COMPILER_ID:MSVC>:/EHsc> 52 53 # G++ and Clang++ compiler defines 54 $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall> 55 $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wextra> 56 $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wpedantic> 57 $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Werror> 58 $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wshadow> 59 $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-c++98-compat-pedantic> 60 $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-c++98-c++11-compat-pedantic> 61 $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-float-equal> 62 63 # Ignore things that the googletest build triggers 64 $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-unknown-warning-option> 65 $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-double-promotion> 66 $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-undef> 67 $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-reserved-identifier> 68 $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-global-constructors>) 69 70# Set up configuration for SIMD ISA builds 71if(${ASTCENC_ISA_SIMD} MATCHES "none") 72 target_compile_definitions(${ASTCENC_TEST} 73 PRIVATE 74 ASTCENC_NEON=0 75 ASTCENC_SSE=0 76 ASTCENC_AVX=0 77 ASTCENC_POPCNT=0 78 ASTCENC_F16C=0) 79 80elseif(${ASTCENC_ISA_SIMD} MATCHES "neon") 81 target_compile_definitions(${ASTCENC_TEST} 82 PRIVATE 83 ASTCENC_NEON=1 84 ASTCENC_SSE=0 85 ASTCENC_AVX=0 86 ASTCENC_POPCNT=0 87 ASTCENC_F16C=0) 88 89elseif(${ASTCENC_ISA_SIMD} MATCHES "sse2") 90 target_compile_definitions(${ASTCENC_TEST} 91 PRIVATE 92 ASTCENC_NEON=0 93 ASTCENC_SSE=20 94 ASTCENC_AVX=0 95 ASTCENC_POPCNT=0 96 ASTCENC_F16C=0) 97 98 target_compile_options(${ASTCENC_TEST} 99 PRIVATE 100 $<$<CXX_COMPILER_ID:${GNU_LIKE}>:-msse2>) 101 102elseif(${ASTCENC_ISA_SIMD} MATCHES "sse4.1") 103 target_compile_definitions(${ASTCENC_TEST} 104 PRIVATE 105 ASTCENC_NEON=0 106 ASTCENC_SSE=41 107 ASTCENC_AVX=0 108 ASTCENC_POPCNT=1 109 ASTCENC_F16C=0) 110 111 target_compile_options(${ASTCENC_TEST} 112 PRIVATE 113 $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-msse4.1 -mpopcnt>) 114 115elseif(${ASTCENC_ISA_SIMD} MATCHES "avx2") 116 target_compile_definitions(${ASTCENC_TEST} 117 PRIVATE 118 ASTCENC_NEON=0 119 ASTCENC_SSE=41 120 ASTCENC_AVX=2 121 ASTCENC_POPCNT=1 122 ASTCENC_F16C=1) 123 124 target_compile_options(${ASTCENC_TEST} 125 PRIVATE 126 $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-mavx2 -mpopcnt -mf16c> 127 $<$<CXX_COMPILER_ID:MSVC>:/arch:AVX2>) 128 129endif() 130 131target_link_libraries(${ASTCENC_TEST} 132 PRIVATE 133 gtest_main) 134 135add_test(NAME ${ASTCENC_TEST} 136 COMMAND ${ASTCENC_TEST}) 137 138install(TARGETS ${ASTCENC_TEST}) 139