1cc1dc7a3Sopenharmony_ci#  SPDX-License-Identifier: Apache-2.0
2cc1dc7a3Sopenharmony_ci#  ----------------------------------------------------------------------------
3cc1dc7a3Sopenharmony_ci#  Copyright 2020-2023 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_ciset(ASTCENC_TARGET astc${ASTCENC_CODEC}-${ASTCENC_ISA_SIMD})
19cc1dc7a3Sopenharmony_ci
20cc1dc7a3Sopenharmony_ciproject(${ASTCENC_TARGET})
21cc1dc7a3Sopenharmony_ci
22cc1dc7a3Sopenharmony_ci# On CMake 3.25 or older CXX_COMPILER_FRONTEND_VARIANT is not always set
23cc1dc7a3Sopenharmony_ciif(CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "")
24cc1dc7a3Sopenharmony_ci    set(CMAKE_CXX_COMPILER_FRONTEND_VARIANT "${CMAKE_CXX_COMPILER_ID}")
25cc1dc7a3Sopenharmony_ciendif()
26cc1dc7a3Sopenharmony_ci
27cc1dc7a3Sopenharmony_ci# Compiler accepts MSVC-style command line options
28cc1dc7a3Sopenharmony_ciset(is_msvc_fe "$<STREQUAL:${CMAKE_CXX_COMPILER_FRONTEND_VARIANT},MSVC>")
29cc1dc7a3Sopenharmony_ci# Compiler accepts GNU-style command line options
30cc1dc7a3Sopenharmony_ciset(is_gnu_fe1 "$<STREQUAL:${CMAKE_CXX_COMPILER_FRONTEND_VARIANT},GNU>")
31cc1dc7a3Sopenharmony_ci# Compiler accepts AppleClang-style command line options, which is also GNU-style
32cc1dc7a3Sopenharmony_ciset(is_gnu_fe2 "$<STREQUAL:${CMAKE_CXX_COMPILER_FRONTEND_VARIANT},AppleClang>")
33cc1dc7a3Sopenharmony_ci# Compiler accepts GNU-style command line options
34cc1dc7a3Sopenharmony_ciset(is_gnu_fe "$<OR:${is_gnu_fe1},${is_gnu_fe2}>")
35cc1dc7a3Sopenharmony_ci
36cc1dc7a3Sopenharmony_ci# Compiler is Visual Studio cl.exe
37cc1dc7a3Sopenharmony_ciset(is_msvccl "$<AND:${is_msvc_fe},$<CXX_COMPILER_ID:MSVC>>")
38cc1dc7a3Sopenharmony_ci# Compiler is Visual Studio clangcl.exe
39cc1dc7a3Sopenharmony_ciset(is_clangcl "$<AND:${is_msvc_fe},$<CXX_COMPILER_ID:Clang>>")
40cc1dc7a3Sopenharmony_ci# Compiler is upstream clang with the standard frontend
41cc1dc7a3Sopenharmony_ciset(is_clang "$<AND:${is_gnu_fe},$<CXX_COMPILER_ID:Clang,AppleClang>>")
42cc1dc7a3Sopenharmony_ci
43cc1dc7a3Sopenharmony_ciadd_library(${ASTCENC_TARGET}-static
44cc1dc7a3Sopenharmony_ci    STATIC
45cc1dc7a3Sopenharmony_ci        astcenc_averages_and_directions.cpp
46cc1dc7a3Sopenharmony_ci        astcenc_block_sizes.cpp
47cc1dc7a3Sopenharmony_ci        astcenc_color_quantize.cpp
48cc1dc7a3Sopenharmony_ci        astcenc_color_unquantize.cpp
49cc1dc7a3Sopenharmony_ci        astcenc_compress_symbolic.cpp
50cc1dc7a3Sopenharmony_ci        astcenc_compute_variance.cpp
51cc1dc7a3Sopenharmony_ci        astcenc_decompress_symbolic.cpp
52cc1dc7a3Sopenharmony_ci        astcenc_diagnostic_trace.cpp
53cc1dc7a3Sopenharmony_ci        astcenc_entry.cpp
54cc1dc7a3Sopenharmony_ci        astcenc_find_best_partitioning.cpp
55cc1dc7a3Sopenharmony_ci        astcenc_ideal_endpoints_and_weights.cpp
56cc1dc7a3Sopenharmony_ci        astcenc_image.cpp
57cc1dc7a3Sopenharmony_ci        astcenc_integer_sequence.cpp
58cc1dc7a3Sopenharmony_ci        astcenc_mathlib.cpp
59cc1dc7a3Sopenharmony_ci        astcenc_mathlib_softfloat.cpp
60cc1dc7a3Sopenharmony_ci        astcenc_partition_tables.cpp
61cc1dc7a3Sopenharmony_ci        astcenc_percentile_tables.cpp
62cc1dc7a3Sopenharmony_ci        astcenc_pick_best_endpoint_format.cpp
63cc1dc7a3Sopenharmony_ci        astcenc_quantization.cpp
64cc1dc7a3Sopenharmony_ci        astcenc_symbolic_physical.cpp
65cc1dc7a3Sopenharmony_ci        astcenc_weight_align.cpp
66cc1dc7a3Sopenharmony_ci        astcenc_weight_quant_xfer_tables.cpp)
67cc1dc7a3Sopenharmony_ci
68cc1dc7a3Sopenharmony_citarget_include_directories(${ASTCENC_TARGET}-static
69cc1dc7a3Sopenharmony_ci    PUBLIC
70cc1dc7a3Sopenharmony_ci        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
71cc1dc7a3Sopenharmony_ci        $<INSTALL_INTERFACE:.>)
72cc1dc7a3Sopenharmony_ci
73cc1dc7a3Sopenharmony_ciif(${ASTCENC_SHAREDLIB})
74cc1dc7a3Sopenharmony_ci    add_library(${ASTCENC_TARGET}-shared
75cc1dc7a3Sopenharmony_ci        SHARED
76cc1dc7a3Sopenharmony_ci            astcenc_averages_and_directions.cpp
77cc1dc7a3Sopenharmony_ci            astcenc_block_sizes.cpp
78cc1dc7a3Sopenharmony_ci            astcenc_color_quantize.cpp
79cc1dc7a3Sopenharmony_ci            astcenc_color_unquantize.cpp
80cc1dc7a3Sopenharmony_ci            astcenc_compress_symbolic.cpp
81cc1dc7a3Sopenharmony_ci            astcenc_compute_variance.cpp
82cc1dc7a3Sopenharmony_ci            astcenc_decompress_symbolic.cpp
83cc1dc7a3Sopenharmony_ci            astcenc_diagnostic_trace.cpp
84cc1dc7a3Sopenharmony_ci            astcenc_entry.cpp
85cc1dc7a3Sopenharmony_ci            astcenc_find_best_partitioning.cpp
86cc1dc7a3Sopenharmony_ci            astcenc_ideal_endpoints_and_weights.cpp
87cc1dc7a3Sopenharmony_ci            astcenc_image.cpp
88cc1dc7a3Sopenharmony_ci            astcenc_integer_sequence.cpp
89cc1dc7a3Sopenharmony_ci            astcenc_mathlib.cpp
90cc1dc7a3Sopenharmony_ci            astcenc_mathlib_softfloat.cpp
91cc1dc7a3Sopenharmony_ci            astcenc_partition_tables.cpp
92cc1dc7a3Sopenharmony_ci            astcenc_percentile_tables.cpp
93cc1dc7a3Sopenharmony_ci            astcenc_pick_best_endpoint_format.cpp
94cc1dc7a3Sopenharmony_ci            astcenc_quantization.cpp
95cc1dc7a3Sopenharmony_ci            astcenc_symbolic_physical.cpp
96cc1dc7a3Sopenharmony_ci            astcenc_weight_align.cpp
97cc1dc7a3Sopenharmony_ci            astcenc_weight_quant_xfer_tables.cpp)
98cc1dc7a3Sopenharmony_ci
99cc1dc7a3Sopenharmony_ci    target_include_directories(${ASTCENC_TARGET}-shared
100cc1dc7a3Sopenharmony_ci        PUBLIC
101cc1dc7a3Sopenharmony_ci            $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
102cc1dc7a3Sopenharmony_ci            $<INSTALL_INTERFACE:.>)
103cc1dc7a3Sopenharmony_ciendif()
104cc1dc7a3Sopenharmony_ci
105cc1dc7a3Sopenharmony_ciif(${ASTCENC_CLI})
106cc1dc7a3Sopenharmony_ci    # Veneer is compiled without any extended ISA so we can safely do
107cc1dc7a3Sopenharmony_ci    # ISA compatability checks without triggering a SIGILL
108cc1dc7a3Sopenharmony_ci    add_library(${ASTCENC_TARGET}-veneer
109cc1dc7a3Sopenharmony_ci        astcenccli_entry.cpp)
110cc1dc7a3Sopenharmony_ci
111cc1dc7a3Sopenharmony_ci    add_executable(${ASTCENC_TARGET}
112cc1dc7a3Sopenharmony_ci        astcenccli_error_metrics.cpp
113cc1dc7a3Sopenharmony_ci        astcenccli_image.cpp
114cc1dc7a3Sopenharmony_ci        astcenccli_image_external.cpp
115cc1dc7a3Sopenharmony_ci        astcenccli_image_load_store.cpp
116cc1dc7a3Sopenharmony_ci        astcenccli_platform_dependents.cpp
117cc1dc7a3Sopenharmony_ci        astcenccli_toplevel.cpp
118cc1dc7a3Sopenharmony_ci        astcenccli_toplevel_help.cpp)
119cc1dc7a3Sopenharmony_ci
120cc1dc7a3Sopenharmony_ci    target_link_libraries(${ASTCENC_TARGET}
121cc1dc7a3Sopenharmony_ci        PRIVATE
122cc1dc7a3Sopenharmony_ci            ${ASTCENC_TARGET}-veneer
123cc1dc7a3Sopenharmony_ci            ${ASTCENC_TARGET}-static)
124cc1dc7a3Sopenharmony_ciendif()
125cc1dc7a3Sopenharmony_ci
126cc1dc7a3Sopenharmony_cimacro(astcenc_set_properties ASTCENC_TARGET_NAME ASTCENC_IS_VENEER)
127cc1dc7a3Sopenharmony_ci
128cc1dc7a3Sopenharmony_ci    target_compile_features(${ASTCENC_TARGET_NAME}
129cc1dc7a3Sopenharmony_ci        PRIVATE
130cc1dc7a3Sopenharmony_ci            cxx_std_14)
131cc1dc7a3Sopenharmony_ci
132cc1dc7a3Sopenharmony_ci    target_compile_definitions(${ASTCENC_TARGET_NAME}
133cc1dc7a3Sopenharmony_ci        PRIVATE
134cc1dc7a3Sopenharmony_ci            $<${is_msvc_fe}:_CRT_SECURE_NO_WARNINGS>)
135cc1dc7a3Sopenharmony_ci
136cc1dc7a3Sopenharmony_ci    if(${ASTCENC_DECOMPRESSOR})
137cc1dc7a3Sopenharmony_ci        target_compile_definitions(${ASTCENC_TARGET_NAME}
138cc1dc7a3Sopenharmony_ci            PRIVATE
139cc1dc7a3Sopenharmony_ci                ASTCENC_DECOMPRESS_ONLY)
140cc1dc7a3Sopenharmony_ci    endif()
141cc1dc7a3Sopenharmony_ci
142cc1dc7a3Sopenharmony_ci    if(${ASTCENC_BLOCK_MAX_TEXELS})
143cc1dc7a3Sopenharmony_ci        target_compile_definitions(${ASTCENC_TARGET_NAME}
144cc1dc7a3Sopenharmony_ci            PRIVATE
145cc1dc7a3Sopenharmony_ci                ASTCENC_BLOCK_MAX_TEXELS=${ASTCENC_BLOCK_MAX_TEXELS})
146cc1dc7a3Sopenharmony_ci    endif()
147cc1dc7a3Sopenharmony_ci
148cc1dc7a3Sopenharmony_ci    if(${ASTCENC_DIAGNOSTICS})
149cc1dc7a3Sopenharmony_ci        target_compile_definitions(${ASTCENC_TARGET_NAME}
150cc1dc7a3Sopenharmony_ci            PUBLIC
151cc1dc7a3Sopenharmony_ci                ASTCENC_DIAGNOSTICS)
152cc1dc7a3Sopenharmony_ci    endif()
153cc1dc7a3Sopenharmony_ci
154cc1dc7a3Sopenharmony_ci    target_compile_options(${ASTCENC_TARGET_NAME}
155cc1dc7a3Sopenharmony_ci        PRIVATE
156cc1dc7a3Sopenharmony_ci            # Use pthreads on Linux/macOS
157cc1dc7a3Sopenharmony_ci            $<$<PLATFORM_ID:Linux,Darwin>:-pthread>
158cc1dc7a3Sopenharmony_ci
159cc1dc7a3Sopenharmony_ci            # MSVC compiler defines
160cc1dc7a3Sopenharmony_ci            $<${is_msvc_fe}:/EHsc>
161cc1dc7a3Sopenharmony_ci            $<${is_msvccl}:/wd4324>
162cc1dc7a3Sopenharmony_ci
163cc1dc7a3Sopenharmony_ci            # G++ and Clang++ compiler defines
164cc1dc7a3Sopenharmony_ci            $<${is_gnu_fe}:-Wall>
165cc1dc7a3Sopenharmony_ci            $<${is_gnu_fe}:-Wextra>
166cc1dc7a3Sopenharmony_ci            $<${is_gnu_fe}:-Wpedantic>
167cc1dc7a3Sopenharmony_ci            $<${is_gnu_fe}:-Werror>
168cc1dc7a3Sopenharmony_ci            $<${is_gnu_fe}:-Wshadow>
169cc1dc7a3Sopenharmony_ci            $<${is_gnu_fe}:-Wdouble-promotion>
170cc1dc7a3Sopenharmony_ci            $<${is_clang}:-Wdocumentation>
171cc1dc7a3Sopenharmony_ci
172cc1dc7a3Sopenharmony_ci            # Hide noise thrown up by Clang 10 and clang-cl
173cc1dc7a3Sopenharmony_ci            $<${is_gnu_fe}:-Wno-unknown-warning-option>
174cc1dc7a3Sopenharmony_ci            $<${is_gnu_fe}:-Wno-c++98-compat-pedantic>
175cc1dc7a3Sopenharmony_ci            $<${is_gnu_fe}:-Wno-c++98-c++11-compat-pedantic>
176cc1dc7a3Sopenharmony_ci            $<${is_gnu_fe}:-Wno-float-equal>
177cc1dc7a3Sopenharmony_ci            $<${is_gnu_fe}:-Wno-deprecated-declarations>
178cc1dc7a3Sopenharmony_ci            $<${is_gnu_fe}:-Wno-atomic-implicit-seq-cst>
179cc1dc7a3Sopenharmony_ci
180cc1dc7a3Sopenharmony_ci            # Clang 10 also throws up warnings we need to investigate (ours)
181cc1dc7a3Sopenharmony_ci            $<${is_gnu_fe}:-Wno-cast-align>
182cc1dc7a3Sopenharmony_ci            $<${is_gnu_fe}:-Wno-sign-conversion>
183cc1dc7a3Sopenharmony_ci            $<${is_gnu_fe}:-Wno-implicit-int-conversion>
184cc1dc7a3Sopenharmony_ci            $<${is_gnu_fe}:-Wno-shift-sign-overflow>
185cc1dc7a3Sopenharmony_ci            $<${is_gnu_fe}:-Wno-format-nonliteral>
186cc1dc7a3Sopenharmony_ci            $<${is_gnu_fe}:-Wno-reserved-identifier>
187cc1dc7a3Sopenharmony_ci            $<${is_gnu_fe}:-Wno-cast-function-type>
188cc1dc7a3Sopenharmony_ci
189cc1dc7a3Sopenharmony_ci            # Force DWARF4 for Valgrind profiling
190cc1dc7a3Sopenharmony_ci            $<$<AND:$<PLATFORM_ID:Linux,Darwin>,${is_clang}>:-gdwarf-4>
191cc1dc7a3Sopenharmony_ci
192cc1dc7a3Sopenharmony_ci            # Disable non-portable Windows.h warning (fixing it fails builds on MinGW)
193cc1dc7a3Sopenharmony_ci            $<$<AND:$<PLATFORM_ID:Windows>,${is_clang}>:-Wno-nonportable-system-include-path>)
194cc1dc7a3Sopenharmony_ci
195cc1dc7a3Sopenharmony_ci    target_link_options(${ASTCENC_TARGET_NAME}
196cc1dc7a3Sopenharmony_ci        PRIVATE
197cc1dc7a3Sopenharmony_ci            # Use pthreads on Linux/macOS
198cc1dc7a3Sopenharmony_ci            $<$<PLATFORM_ID:Linux,Darwin>:-pthread>)
199cc1dc7a3Sopenharmony_ci
200cc1dc7a3Sopenharmony_ci    if(${ASTCENC_ASAN})
201cc1dc7a3Sopenharmony_ci        target_compile_options(${ASTCENC_TARGET_NAME}
202cc1dc7a3Sopenharmony_ci            PRIVATE
203cc1dc7a3Sopenharmony_ci                $<${is_clang}:-fsanitize=address>)
204cc1dc7a3Sopenharmony_ci
205cc1dc7a3Sopenharmony_ci        target_link_options(${ASTCENC_TARGET_NAME}
206cc1dc7a3Sopenharmony_ci            PRIVATE
207cc1dc7a3Sopenharmony_ci                $<${is_clang}:-fsanitize=address>)
208cc1dc7a3Sopenharmony_ci    endif()
209cc1dc7a3Sopenharmony_ci
210cc1dc7a3Sopenharmony_ci    if(NOT ${ASTCENC_INVARIANCE})
211cc1dc7a3Sopenharmony_ci        target_compile_definitions(${ASTCENC_TARGET_NAME}
212cc1dc7a3Sopenharmony_ci            PRIVATE
213cc1dc7a3Sopenharmony_ci                ASTCENC_NO_INVARIANCE=1)
214cc1dc7a3Sopenharmony_ci
215cc1dc7a3Sopenharmony_ci        # For Visual Studio prior to 2022 (compiler < 19.30) /fp:precise
216cc1dc7a3Sopenharmony_ci        # For Visual Studio 2022 (compiler >= 19.30) /fp:precise and /fp:contract
217cc1dc7a3Sopenharmony_ci
218cc1dc7a3Sopenharmony_ci        # For Visual Studio 2022 ClangCL seems to have accidentally enabled contraction by default,
219cc1dc7a3Sopenharmony_ci        # so behaves differently to CL.exe. Use the -Xclang argument to workaround and allow access
220cc1dc7a3Sopenharmony_ci        # GNU-style switch to control contraction on the assumption this gets fixed and disabled.
221cc1dc7a3Sopenharmony_ci        # Note ClangCL does not accept /fp:contract as an argument as of v15.0.7.
222cc1dc7a3Sopenharmony_ci        target_compile_options(${ASTCENC_TARGET_NAME}
223cc1dc7a3Sopenharmony_ci            PRIVATE
224cc1dc7a3Sopenharmony_ci                $<${is_msvccl}:/fp:precise>
225cc1dc7a3Sopenharmony_ci                $<${is_clangcl}:/fp:precise>
226cc1dc7a3Sopenharmony_ci                $<$<AND:${is_msvccl},$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,19.30>>:/fp:contract>
227cc1dc7a3Sopenharmony_ci                $<$<AND:${is_clangcl},$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,14.0.0>>:-Xclang -ffp-contract=fast>
228cc1dc7a3Sopenharmony_ci                $<$<AND:${is_clang},$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,10.0.0>>:-ffp-model=precise>
229cc1dc7a3Sopenharmony_ci                $<${is_gnu_fe}:-ffp-contract=fast>)
230cc1dc7a3Sopenharmony_ci    else()
231cc1dc7a3Sopenharmony_ci        # For Visual Studio prior to 2022 (compiler < 19.30) /fp:strict
232cc1dc7a3Sopenharmony_ci        # For Visual Studio 2022 (compiler >= 19.30) /fp:precise
233cc1dc7a3Sopenharmony_ci
234cc1dc7a3Sopenharmony_ci        # For Visual Studio 2022 ClangCL seems to have accidentally enabled contraction by default,
235cc1dc7a3Sopenharmony_ci        # so behaves differently to CL.exe. Use the -Xclang argument to workaround and allow access
236cc1dc7a3Sopenharmony_ci        # GNU-style switch to control contraction and force disable.
237cc1dc7a3Sopenharmony_ci        target_compile_options(${ASTCENC_TARGET_NAME}
238cc1dc7a3Sopenharmony_ci            PRIVATE
239cc1dc7a3Sopenharmony_ci                $<$<AND:${is_msvccl},$<VERSION_LESS:$<CXX_COMPILER_VERSION>,19.30>>:/fp:strict>
240cc1dc7a3Sopenharmony_ci                $<$<AND:${is_msvccl},$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,19.30>>:/fp:precise>
241cc1dc7a3Sopenharmony_ci                $<${is_clangcl}:/fp:precise>
242cc1dc7a3Sopenharmony_ci                $<$<AND:${is_clangcl},$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,14.0.0>>:-Xclang -ffp-contract=off>
243cc1dc7a3Sopenharmony_ci                $<$<AND:${is_clang},$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,10.0.0>>:-ffp-model=precise>
244cc1dc7a3Sopenharmony_ci                $<${is_gnu_fe}:-ffp-contract=off>)
245cc1dc7a3Sopenharmony_ci    endif()
246cc1dc7a3Sopenharmony_ci
247cc1dc7a3Sopenharmony_ci    if(${ASTCENC_CLI})
248cc1dc7a3Sopenharmony_ci        # Enable LTO on release builds
249cc1dc7a3Sopenharmony_ci        set_property(TARGET ${ASTCENC_TARGET_NAME}
250cc1dc7a3Sopenharmony_ci            PROPERTY
251cc1dc7a3Sopenharmony_ci                INTERPROCEDURAL_OPTIMIZATION_RELEASE True)
252cc1dc7a3Sopenharmony_ci
253cc1dc7a3Sopenharmony_ci        # Use a static runtime on MSVC builds (ignored on non-MSVC compilers)
254cc1dc7a3Sopenharmony_ci        set_property(TARGET ${ASTCENC_TARGET_NAME}
255cc1dc7a3Sopenharmony_ci            PROPERTY
256cc1dc7a3Sopenharmony_ci                MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
257cc1dc7a3Sopenharmony_ci    endif()
258cc1dc7a3Sopenharmony_ci
259cc1dc7a3Sopenharmony_ci    # Set up configuration for SIMD ISA builds
260cc1dc7a3Sopenharmony_ci    if(${ASTCENC_ISA_SIMD} MATCHES "none")
261cc1dc7a3Sopenharmony_ci        target_compile_definitions(${ASTCENC_TARGET_NAME}
262cc1dc7a3Sopenharmony_ci            PRIVATE
263cc1dc7a3Sopenharmony_ci                ASTCENC_NEON=0
264cc1dc7a3Sopenharmony_ci                ASTCENC_SSE=0
265cc1dc7a3Sopenharmony_ci                ASTCENC_AVX=0
266cc1dc7a3Sopenharmony_ci                ASTCENC_POPCNT=0
267cc1dc7a3Sopenharmony_ci                ASTCENC_F16C=0)
268cc1dc7a3Sopenharmony_ci
269cc1dc7a3Sopenharmony_ci    elseif(${ASTCENC_ISA_SIMD} MATCHES "neon")
270cc1dc7a3Sopenharmony_ci        target_compile_definitions(${ASTCENC_TARGET_NAME}
271cc1dc7a3Sopenharmony_ci            PRIVATE
272cc1dc7a3Sopenharmony_ci                ASTCENC_NEON=1
273cc1dc7a3Sopenharmony_ci                ASTCENC_SSE=0
274cc1dc7a3Sopenharmony_ci                ASTCENC_AVX=0
275cc1dc7a3Sopenharmony_ci                ASTCENC_POPCNT=0
276cc1dc7a3Sopenharmony_ci                ASTCENC_F16C=0)
277cc1dc7a3Sopenharmony_ci
278cc1dc7a3Sopenharmony_ci        # Workaround MSVC codegen bug for NEON builds on VS 2022 17.2 or older
279cc1dc7a3Sopenharmony_ci        # https://developercommunity.visualstudio.com/t/inlining-turns-constant-into-register-operand-for/1394798
280cc1dc7a3Sopenharmony_ci        if((CMAKE_CXX_COMPILER_ID MATCHES "MSVC") AND (MSVC_VERSION LESS 1933))
281cc1dc7a3Sopenharmony_ci            target_compile_options(${ASTCENC_TARGET_NAME}
282cc1dc7a3Sopenharmony_ci                PRIVATE
283cc1dc7a3Sopenharmony_ci                    $<${is_msvccl}:/d2ssa-cfg-sink->)
284cc1dc7a3Sopenharmony_ci        endif()
285cc1dc7a3Sopenharmony_ci
286cc1dc7a3Sopenharmony_ci    elseif(${ASTCENC_ISA_SIMD} MATCHES "sse2")
287cc1dc7a3Sopenharmony_ci        target_compile_definitions(${ASTCENC_TARGET_NAME}
288cc1dc7a3Sopenharmony_ci            PRIVATE
289cc1dc7a3Sopenharmony_ci                ASTCENC_NEON=0
290cc1dc7a3Sopenharmony_ci                ASTCENC_SSE=20
291cc1dc7a3Sopenharmony_ci                ASTCENC_AVX=0
292cc1dc7a3Sopenharmony_ci                ASTCENC_POPCNT=0
293cc1dc7a3Sopenharmony_ci                ASTCENC_F16C=0)
294cc1dc7a3Sopenharmony_ci
295cc1dc7a3Sopenharmony_ci        # Force SSE2 on AppleClang (normally SSE4.1 is the default)
296cc1dc7a3Sopenharmony_ci        target_compile_options(${ASTCENC_TARGET_NAME}
297cc1dc7a3Sopenharmony_ci            PRIVATE
298cc1dc7a3Sopenharmony_ci                $<${is_clangcl}:-msse2>
299cc1dc7a3Sopenharmony_ci                $<${is_gnu_fe}:-msse2>
300cc1dc7a3Sopenharmony_ci                $<${is_gnu_fe}:-mno-sse4.1>
301cc1dc7a3Sopenharmony_ci                $<${is_gnu_fe}:-Wno-unused-command-line-argument>)
302cc1dc7a3Sopenharmony_ci
303cc1dc7a3Sopenharmony_ci    elseif(${ASTCENC_ISA_SIMD} MATCHES "sse4.1")
304cc1dc7a3Sopenharmony_ci        target_compile_definitions(${ASTCENC_TARGET_NAME}
305cc1dc7a3Sopenharmony_ci            PRIVATE
306cc1dc7a3Sopenharmony_ci                ASTCENC_NEON=0
307cc1dc7a3Sopenharmony_ci                ASTCENC_SSE=41
308cc1dc7a3Sopenharmony_ci                ASTCENC_AVX=0
309cc1dc7a3Sopenharmony_ci                ASTCENC_POPCNT=1
310cc1dc7a3Sopenharmony_ci                ASTCENC_F16C=0)
311cc1dc7a3Sopenharmony_ci
312cc1dc7a3Sopenharmony_ci        if (${ASTCENC_IS_VENEER})
313cc1dc7a3Sopenharmony_ci            # Force SSE2 on AppleClang (normally SSE4.1 is the default)
314cc1dc7a3Sopenharmony_ci            target_compile_options(${ASTCENC_TARGET_NAME}
315cc1dc7a3Sopenharmony_ci                PRIVATE
316cc1dc7a3Sopenharmony_ci                    $<${is_gnu_fe}:-msse2>
317cc1dc7a3Sopenharmony_ci                    $<${is_gnu_fe}:-mno-sse4.1>
318cc1dc7a3Sopenharmony_ci                    $<${is_gnu_fe}:-Wno-unused-command-line-argument>)
319cc1dc7a3Sopenharmony_ci        else()
320cc1dc7a3Sopenharmony_ci            target_compile_options(${ASTCENC_TARGET_NAME}
321cc1dc7a3Sopenharmony_ci                PRIVATE
322cc1dc7a3Sopenharmony_ci                    $<${is_clangcl}:-msse4.1 -mpopcnt>
323cc1dc7a3Sopenharmony_ci                    $<${is_gnu_fe}:-msse4.1 -mpopcnt>
324cc1dc7a3Sopenharmony_ci                    $<${is_gnu_fe}:-Wno-unused-command-line-argument>)
325cc1dc7a3Sopenharmony_ci        endif()
326cc1dc7a3Sopenharmony_ci
327cc1dc7a3Sopenharmony_ci    elseif(${ASTCENC_ISA_SIMD} MATCHES "avx2")
328cc1dc7a3Sopenharmony_ci        target_compile_definitions(${ASTCENC_TARGET_NAME}
329cc1dc7a3Sopenharmony_ci            PRIVATE
330cc1dc7a3Sopenharmony_ci                ASTCENC_NEON=0
331cc1dc7a3Sopenharmony_ci                ASTCENC_SSE=41
332cc1dc7a3Sopenharmony_ci                ASTCENC_AVX=2
333cc1dc7a3Sopenharmony_ci                ASTCENC_POPCNT=1
334cc1dc7a3Sopenharmony_ci                ASTCENC_F16C=1)
335cc1dc7a3Sopenharmony_ci
336cc1dc7a3Sopenharmony_ci        if (${ASTCENC_IS_VENEER})
337cc1dc7a3Sopenharmony_ci            # Force SSE2 on AppleClang (normally SSE4.1 is the default)
338cc1dc7a3Sopenharmony_ci            target_compile_options(${ASTCENC_TARGET_NAME}
339cc1dc7a3Sopenharmony_ci                PRIVATE
340cc1dc7a3Sopenharmony_ci                    $<${is_gnu_fe}:-msse2>
341cc1dc7a3Sopenharmony_ci                    $<${is_gnu_fe}:-mno-sse4.1>
342cc1dc7a3Sopenharmony_ci                    $<${is_gnu_fe}:-Wno-unused-command-line-argument>)
343cc1dc7a3Sopenharmony_ci        else()
344cc1dc7a3Sopenharmony_ci            target_compile_options(${ASTCENC_TARGET_NAME}
345cc1dc7a3Sopenharmony_ci                PRIVATE
346cc1dc7a3Sopenharmony_ci                    $<${is_msvc_fe}:/arch:AVX2>
347cc1dc7a3Sopenharmony_ci                    $<${is_clangcl}:-mavx2 -mpopcnt -mf16c>
348cc1dc7a3Sopenharmony_ci                    $<${is_gnu_fe}:-mavx2 -mpopcnt -mf16c>
349cc1dc7a3Sopenharmony_ci                    $<${is_gnu_fe}:-Wno-unused-command-line-argument>)
350cc1dc7a3Sopenharmony_ci        endif()
351cc1dc7a3Sopenharmony_ci
352cc1dc7a3Sopenharmony_ci        # Non-invariant builds enable us to loosen the compiler constraints on
353cc1dc7a3Sopenharmony_ci        # floating point, but this is only worth doing on CPUs with AVX2 because
354cc1dc7a3Sopenharmony_ci        # this implies we can also enable the FMA instruction set extensions
355cc1dc7a3Sopenharmony_ci        # which significantly improve performance. Note that this DOES reduce
356cc1dc7a3Sopenharmony_ci        # image quality by up to 0.2 dB (normally much less), but buys an
357cc1dc7a3Sopenharmony_ci        # average of 10-15% performance improvement ...
358cc1dc7a3Sopenharmony_ci        if((NOT ${ASTCENC_INVARIANCE}) AND (NOT ${ASTCENC_IS_VENEER}))
359cc1dc7a3Sopenharmony_ci            target_compile_options(${ASTCENC_TARGET_NAME}
360cc1dc7a3Sopenharmony_ci                PRIVATE
361cc1dc7a3Sopenharmony_ci                    $<${is_gnu_fe}:-mfma>)
362cc1dc7a3Sopenharmony_ci        endif()
363cc1dc7a3Sopenharmony_ci
364cc1dc7a3Sopenharmony_ci    endif()
365cc1dc7a3Sopenharmony_ci
366cc1dc7a3Sopenharmony_ciendmacro()
367cc1dc7a3Sopenharmony_ci
368cc1dc7a3Sopenharmony_cistring(CONCAT EXTERNAL_CXX_FLAGS
369cc1dc7a3Sopenharmony_ci       " $<${is_gnu_fe}: -fno-strict-aliasing>"
370cc1dc7a3Sopenharmony_ci       " $<${is_gnu_fe}: -Wno-unused-parameter>"
371cc1dc7a3Sopenharmony_ci       " $<${is_gnu_fe}: -Wno-old-style-cast>"
372cc1dc7a3Sopenharmony_ci       " $<${is_gnu_fe}: -Wno-double-promotion>"
373cc1dc7a3Sopenharmony_ci       " $<${is_gnu_fe}: -Wno-zero-as-null-pointer-constant>"
374cc1dc7a3Sopenharmony_ci       " $<${is_gnu_fe}: -Wno-disabled-macro-expansion>"
375cc1dc7a3Sopenharmony_ci       " $<${is_gnu_fe}: -Wno-reserved-id-macro>"
376cc1dc7a3Sopenharmony_ci       " $<${is_gnu_fe}: -Wno-extra-semi-stmt>"
377cc1dc7a3Sopenharmony_ci       " $<${is_gnu_fe}: -Wno-implicit-fallthrough>"
378cc1dc7a3Sopenharmony_ci       " $<${is_gnu_fe}: -Wno-tautological-type-limit-compare>"
379cc1dc7a3Sopenharmony_ci       " $<${is_gnu_fe}: -Wno-cast-qual>"
380cc1dc7a3Sopenharmony_ci       " $<${is_gnu_fe}: -Wno-reserved-identifier>"
381cc1dc7a3Sopenharmony_ci       " $<${is_clang}: -Wno-missing-prototypes>"
382cc1dc7a3Sopenharmony_ci       " $<${is_gnu_fe}: -Wno-missing-field-initializers>"
383cc1dc7a3Sopenharmony_ci       " $<${is_gnu_fe}: -Wno-suggest-override>"
384cc1dc7a3Sopenharmony_ci       " $<${is_gnu_fe}: -Wno-used-but-marked-unused>"
385cc1dc7a3Sopenharmony_ci       " $<${is_gnu_fe}: -Wno-noexcept-type>"
386cc1dc7a3Sopenharmony_ci       " $<${is_gnu_fe}: -Wno-comma>"
387cc1dc7a3Sopenharmony_ci       " $<${is_gnu_fe}: -Wno-c99-extensions>")
388cc1dc7a3Sopenharmony_ci
389cc1dc7a3Sopenharmony_ciset_source_files_properties(astcenccli_image_external.cpp
390cc1dc7a3Sopenharmony_ci    PROPERTIES
391cc1dc7a3Sopenharmony_ci        COMPILE_FLAGS ${EXTERNAL_CXX_FLAGS})
392cc1dc7a3Sopenharmony_ci
393cc1dc7a3Sopenharmony_ciastcenc_set_properties(${ASTCENC_TARGET}-static OFF)
394cc1dc7a3Sopenharmony_ci
395cc1dc7a3Sopenharmony_citarget_compile_options(${ASTCENC_TARGET}-static
396cc1dc7a3Sopenharmony_ci    PRIVATE
397cc1dc7a3Sopenharmony_ci        $<${is_msvc_fe}:/W4>)
398cc1dc7a3Sopenharmony_ci
399cc1dc7a3Sopenharmony_ciif(${ASTCENC_SHAREDLIB})
400cc1dc7a3Sopenharmony_ci    astcenc_set_properties(${ASTCENC_TARGET}-shared OFF)
401cc1dc7a3Sopenharmony_ci
402cc1dc7a3Sopenharmony_ci    target_compile_definitions(${ASTCENC_TARGET}-shared
403cc1dc7a3Sopenharmony_ci        PRIVATE
404cc1dc7a3Sopenharmony_ci            ASTCENC_DYNAMIC_LIBRARY=1)
405cc1dc7a3Sopenharmony_ci
406cc1dc7a3Sopenharmony_ci    target_compile_options(${ASTCENC_TARGET}-shared
407cc1dc7a3Sopenharmony_ci        PRIVATE
408cc1dc7a3Sopenharmony_ci            $<${is_gnu_fe}:-fvisibility=hidden>
409cc1dc7a3Sopenharmony_ci            $<${is_msvc_fe}:/W4>)
410cc1dc7a3Sopenharmony_ci
411cc1dc7a3Sopenharmony_ci    if(NOT ${ASTCENC_UNIVERSAL_BUILD})
412cc1dc7a3Sopenharmony_ci        install(TARGETS ${ASTCENC_TARGET}-shared)
413cc1dc7a3Sopenharmony_ci    endif()
414cc1dc7a3Sopenharmony_ciendif()
415cc1dc7a3Sopenharmony_ci
416cc1dc7a3Sopenharmony_ciif(${ASTCENC_CLI})
417cc1dc7a3Sopenharmony_ci    astcenc_set_properties(${ASTCENC_TARGET}-veneer ON)
418cc1dc7a3Sopenharmony_ci    astcenc_set_properties(${ASTCENC_TARGET} OFF)
419cc1dc7a3Sopenharmony_ci
420cc1dc7a3Sopenharmony_ci    target_compile_options(${ASTCENC_TARGET}
421cc1dc7a3Sopenharmony_ci        PRIVATE
422cc1dc7a3Sopenharmony_ci            $<${is_msvc_fe}:/W3>)
423cc1dc7a3Sopenharmony_ci
424cc1dc7a3Sopenharmony_ci    target_compile_options(${ASTCENC_TARGET}-veneer
425cc1dc7a3Sopenharmony_ci        PRIVATE
426cc1dc7a3Sopenharmony_ci            $<${is_msvc_fe}:/W3>)
427cc1dc7a3Sopenharmony_ci
428cc1dc7a3Sopenharmony_ci    string(TIMESTAMP astcencoder_YEAR "%Y")
429cc1dc7a3Sopenharmony_ci
430cc1dc7a3Sopenharmony_ci    configure_file(
431cc1dc7a3Sopenharmony_ci        astcenccli_version.h.in
432cc1dc7a3Sopenharmony_ci        astcenccli_version.h
433cc1dc7a3Sopenharmony_ci        ESCAPE_QUOTES @ONLY)
434cc1dc7a3Sopenharmony_ci
435cc1dc7a3Sopenharmony_ci    target_include_directories(${ASTCENC_TARGET}
436cc1dc7a3Sopenharmony_ci        PRIVATE
437cc1dc7a3Sopenharmony_ci            ${CMAKE_CURRENT_BINARY_DIR})
438cc1dc7a3Sopenharmony_ci
439cc1dc7a3Sopenharmony_ci    if(NOT ${ASTCENC_UNIVERSAL_BUILD})
440cc1dc7a3Sopenharmony_ci        install(TARGETS ${ASTCENC_TARGET})
441cc1dc7a3Sopenharmony_ci    endif()
442cc1dc7a3Sopenharmony_ciendif()
443