File: cmake_core.cmake

package info (click to toggle)
astc-encoder 5.2.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 43,352 kB
  • sloc: ansic: 44,622; cpp: 24,142; python: 3,403; sh: 78; makefile: 24
file content (553 lines) | stat: -rw-r--r-- 21,141 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
#  SPDX-License-Identifier: Apache-2.0
#  ----------------------------------------------------------------------------
#  Copyright 2020-2024 Arm Limited
#
#  Licensed under the Apache License, Version 2.0 (the "License"); you may not
#  use this file except in compliance with the License. You may obtain a copy
#  of the License at:
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#  License for the specific language governing permissions and limitations
#  under the License.
#  ----------------------------------------------------------------------------

set(ASTCENC_TARGET astc${ASTCENC_CODEC})

project(${ASTCENC_TARGET})

# On CMake 3.25 or older CXX_COMPILER_FRONTEND_VARIANT is not always set
if(CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "")
    set(CMAKE_CXX_COMPILER_FRONTEND_VARIANT "${CMAKE_CXX_COMPILER_ID}")
endif()

# Compiler accepts MSVC-style command line options
set(is_msvc_fe "$<STREQUAL:${CMAKE_CXX_COMPILER_FRONTEND_VARIANT},MSVC>")
# Compiler accepts GNU-style command line options
set(is_gnu_fe1 "$<STREQUAL:${CMAKE_CXX_COMPILER_FRONTEND_VARIANT},GNU>")
# Compiler accepts AppleClang-style command line options, which is also GNU-style
set(is_gnu_fe2 "$<STREQUAL:${CMAKE_CXX_COMPILER_FRONTEND_VARIANT},AppleClang>")
# Compiler accepts GNU-style command line options
set(is_gnu_fe "$<OR:${is_gnu_fe1},${is_gnu_fe2}>")

# Compiler is Visual Studio cl.exe
set(is_msvccl "$<AND:${is_msvc_fe},$<CXX_COMPILER_ID:MSVC>>")
# Compiler is Visual Studio clangcl.exe
set(is_clangcl "$<AND:${is_msvc_fe},$<CXX_COMPILER_ID:Clang>>")
# Compiler is upstream clang with the standard frontend
set(is_clang "$<AND:${is_gnu_fe},$<CXX_COMPILER_ID:Clang,AppleClang>>")

add_library(${ASTCENC_TARGET}-static
    STATIC
        astcenc_averages_and_directions.cpp
        astcenc_block_sizes.cpp
        astcenc_color_quantize.cpp
        astcenc_color_unquantize.cpp
        astcenc_compress_symbolic.cpp
        astcenc_compute_variance.cpp
        astcenc_decompress_symbolic.cpp
        astcenc_diagnostic_trace.cpp
        astcenc_entry.cpp
        astcenc_find_best_partitioning.cpp
        astcenc_ideal_endpoints_and_weights.cpp
        astcenc_image.cpp
        astcenc_integer_sequence.cpp
        astcenc_mathlib.cpp
        astcenc_mathlib_softfloat.cpp
        astcenc_partition_tables.cpp
        astcenc_percentile_tables.cpp
        astcenc_pick_best_endpoint_format.cpp
        astcenc_quantization.cpp
        astcenc_symbolic_physical.cpp
        astcenc_weight_align.cpp
        astcenc_weight_quant_xfer_tables.cpp)

target_include_directories(${ASTCENC_TARGET}-static
    PUBLIC
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
        $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

install(TARGETS ${ASTCENC_TARGET}-static EXPORT astcencTargets)

if(${ASTCENC_SHAREDLIB})
    add_library(${ASTCENC_TARGET}-shared
        SHARED
            astcenc_averages_and_directions.cpp
            astcenc_block_sizes.cpp
            astcenc_color_quantize.cpp
            astcenc_color_unquantize.cpp
            astcenc_compress_symbolic.cpp
            astcenc_compute_variance.cpp
            astcenc_decompress_symbolic.cpp
            astcenc_diagnostic_trace.cpp
            astcenc_entry.cpp
            astcenc_find_best_partitioning.cpp
            astcenc_ideal_endpoints_and_weights.cpp
            astcenc_image.cpp
            astcenc_integer_sequence.cpp
            astcenc_mathlib.cpp
            astcenc_mathlib_softfloat.cpp
            astcenc_partition_tables.cpp
            astcenc_percentile_tables.cpp
            astcenc_pick_best_endpoint_format.cpp
            astcenc_quantization.cpp
            astcenc_symbolic_physical.cpp
            astcenc_weight_align.cpp
            astcenc_weight_quant_xfer_tables.cpp)

    target_include_directories(${ASTCENC_TARGET}-shared
        PUBLIC
            $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
            $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
endif()

if(${ASTCENC_CLI})
    # Veneer is compiled without any extended ISA so we can safely do
    # ISA compatability checks without triggering a SIGILL
    add_library(${ASTCENC_TARGET}-veneer1 STATIC
        astcenccli_entry.cpp)

    # Veneer is compiled with extended ISA but without vector length overrides
    # so we can safely do SVE vector length compatability checks
    add_library(${ASTCENC_TARGET}-veneer2 STATIC
        astcenccli_entry2.cpp)

    add_executable(${ASTCENC_TARGET}
        astcenccli_error_metrics.cpp
        astcenccli_image.cpp
        astcenccli_image_external.cpp
        astcenccli_image_load_store.cpp
        astcenccli_platform_dependents.cpp
        astcenccli_toplevel.cpp
        astcenccli_toplevel_help.cpp)

    target_include_directories(${ASTCENC_TARGET} PRIVATE ${stb_INCLUDE_DIR})
    target_link_libraries(${ASTCENC_TARGET}
        PRIVATE
            tinyexr::tinyexr
            stb
            ZLIB::ZLIB
            ${ASTCENC_TARGET}-veneer1
            ${ASTCENC_TARGET}-veneer2
            ${ASTCENC_TARGET}-shared)
endif()

macro(astcenc_set_properties ASTCENC_TARGET_NAME ASTCENC_VENEER_TYPE)

    target_compile_features(${ASTCENC_TARGET_NAME}
        PRIVATE
            cxx_std_14)

    target_compile_definitions(${ASTCENC_TARGET_NAME}
        PRIVATE
            $<${is_msvc_fe}:_CRT_SECURE_NO_WARNINGS>)

    if(${ASTCENC_DECOMPRESSOR})
        target_compile_definitions(${ASTCENC_TARGET_NAME}
            PRIVATE
                ASTCENC_DECOMPRESS_ONLY)
    endif()

    if(${ASTCENC_BLOCK_MAX_TEXELS})
        target_compile_definitions(${ASTCENC_TARGET_NAME}
            PRIVATE
                ASTCENC_BLOCK_MAX_TEXELS=${ASTCENC_BLOCK_MAX_TEXELS})
    endif()

    if(${ASTCENC_DIAGNOSTICS})
        target_compile_definitions(${ASTCENC_TARGET_NAME}
            PUBLIC
                ASTCENC_DIAGNOSTICS)
    endif()

    target_compile_options(${ASTCENC_TARGET_NAME}
        PRIVATE
            # MSVC compiler defines
            $<${is_msvc_fe}:/EHsc>
            $<${is_msvccl}:/wd4324>

            # G++ and Clang++ compiler defines
            $<${is_gnu_fe}:-Wall>
            $<${is_gnu_fe}:-Wextra>
            $<${is_gnu_fe}:-Wpedantic>
            $<${is_gnu_fe}:-Wshadow>
            $<${is_gnu_fe}:-Wdouble-promotion>
            $<${is_clang}:-Wdocumentation>

            # Hide noise thrown up by Clang 10 and clang-cl
            $<${is_gnu_fe}:-Wno-unknown-warning-option>
            $<${is_gnu_fe}:-Wno-c++98-compat-pedantic>
            $<${is_gnu_fe}:-Wno-c++98-c++11-compat-pedantic>
            $<${is_gnu_fe}:-Wno-float-equal>
            $<${is_gnu_fe}:-Wno-deprecated-declarations>
            $<${is_gnu_fe}:-Wno-atomic-implicit-seq-cst>
            $<${is_clang}:-Wno-overriding-option>

            # Clang 10 also throws up warnings we need to investigate (ours)
            $<${is_gnu_fe}:-Wno-cast-align>
            $<${is_gnu_fe}:-Wno-sign-conversion>
            $<${is_gnu_fe}:-Wno-implicit-int-conversion>
            $<${is_gnu_fe}:-Wno-shift-sign-overflow>
            $<${is_gnu_fe}:-Wno-format-nonliteral>
            $<${is_gnu_fe}:-Wno-reserved-identifier>
            $<${is_gnu_fe}:-Wno-cast-function-type>

            # Force DWARF4 for Valgrind profiling
            $<$<AND:$<PLATFORM_ID:Linux,Darwin>,${is_clang}>:-gdwarf-4>

            # Disable non-portable Windows.h warning (fixing it fails builds on MinGW)
            $<$<AND:$<PLATFORM_ID:Windows>,${is_clang}>:-Wno-nonportable-system-include-path>)

    target_link_libraries(${ASTCENC_TARGET_NAME}
        PRIVATE
            # Use pthreads on Linux/macOS
            Threads::Threads)

    if(${ASTCENC_ASAN})
        target_compile_options(${ASTCENC_TARGET_NAME}
            PRIVATE
                $<${is_clang}:-fsanitize=address>)

        target_link_options(${ASTCENC_TARGET_NAME}
            PRIVATE
                $<${is_clang}:-fsanitize=address>)
    endif()

    if(${ASTCENC_UBSAN})
        target_compile_options(${ASTCENC_TARGET_NAME}
            PRIVATE
                $<${is_clang}:-fsanitize=undefined>)

        target_link_options(${ASTCENC_TARGET_NAME}
            PRIVATE
                $<${is_clang}:-fsanitize=undefined>)
    endif()

    if(NOT ${ASTCENC_INVARIANCE})
        target_compile_definitions(${ASTCENC_TARGET_NAME}
            PRIVATE
                ASTCENC_NO_INVARIANCE=1)

        # For Visual Studio prior to 2022 (compiler < 19.30) /fp:precise
        # For Visual Studio 2022 (compiler >= 19.30) /fp:precise and /fp:contract

        # For Visual Studio 2022 ClangCL seems to have accidentally enabled contraction by default,
        # so behaves differently to CL.exe. Use the -Xclang argument to workaround and allow access
        # GNU-style switch to control contraction on the assumption this gets fixed and disabled.
        # Note ClangCL does not accept /fp:contract as an argument as of v15.0.7.
        target_compile_options(${ASTCENC_TARGET_NAME}
            PRIVATE
                $<${is_msvccl}:/fp:precise>
                $<${is_clangcl}:/fp:precise>
                $<$<AND:${is_msvccl},$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,19.30>>:/fp:contract>
                $<$<AND:${is_clangcl},$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,14.0.0>>:-Xclang -ffp-contract=fast>
                $<$<AND:${is_clang},$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,10.0.0>>:-ffp-model=precise>
                $<${is_gnu_fe}:-ffp-contract=fast>)
    else()
        # For Visual Studio prior to 2022 (compiler < 19.30) /fp:strict
        # For Visual Studio 2022 (compiler >= 19.30) /fp:precise

        # For Visual Studio 2022 ClangCL seems to have accidentally enabled contraction by default,
        # so behaves differently to CL.exe. Use the -Xclang argument to workaround and allow access
        # GNU-style switch to control contraction and force disable.
        target_compile_options(${ASTCENC_TARGET_NAME}
            PRIVATE
                $<$<AND:${is_msvccl},$<VERSION_LESS:$<CXX_COMPILER_VERSION>,19.30>>:/fp:strict>
                $<$<AND:${is_msvccl},$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,19.30>>:/fp:precise>
                $<${is_clangcl}:/fp:precise>
                $<$<AND:${is_clangcl},$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,14.0.0>>:-Xclang -ffp-contract=off>
                $<$<AND:${is_clang},$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,10.0.0>>:-ffp-model=precise>
                $<${is_gnu_fe}:-ffp-contract=off>)
    endif()

    if(${ASTCENC_CLI})
        # Enable LTO on release builds
        set_property(TARGET ${ASTCENC_TARGET_NAME}
            PROPERTY
                INTERPROCEDURAL_OPTIMIZATION_RELEASE True)

        # Use a static runtime on MSVC builds (ignored on non-MSVC compilers)
        set_property(TARGET ${ASTCENC_TARGET_NAME}
            PROPERTY
                MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
    endif()

    # Set up configuration for SIMD ISA builds
    if(${ASTCENC_ISA_SIMD} MATCHES "none")
        target_compile_definitions(${ASTCENC_TARGET_NAME}
            PRIVATE
                ASTCENC_NEON=0
                ASTCENC_SVE=0
                ASTCENC_SSE=0
                ASTCENC_AVX=0
                ASTCENC_POPCNT=0
                ASTCENC_F16C=0)

    elseif(${ASTCENC_ISA_SIMD} MATCHES "neon")
        target_compile_definitions(${ASTCENC_TARGET_NAME}
            PRIVATE
                ASTCENC_NEON=1
                ASTCENC_SVE=0
                ASTCENC_SSE=0
                ASTCENC_AVX=0
                ASTCENC_POPCNT=0
                ASTCENC_F16C=0)

        # Workaround MSVC codegen bug for NEON builds on VS 2022 17.2 or older
        # https://developercommunity.visualstudio.com/t/inlining-turns-constant-into-register-operand-for/1394798
        if((CMAKE_CXX_COMPILER_ID MATCHES "MSVC") AND (MSVC_VERSION LESS 1933))
            target_compile_options(${ASTCENC_TARGET_NAME}
                PRIVATE
                    $<${is_msvccl}:/d2ssa-cfg-sink->)
        endif()

    elseif(${ASTCENC_ISA_SIMD} MATCHES "sve_256")
        target_compile_definitions(${ASTCENC_TARGET_NAME}
            PRIVATE
                ASTCENC_NEON=1
                ASTCENC_SVE=8
                ASTCENC_SSE=0
                ASTCENC_AVX=0
                ASTCENC_POPCNT=0
                ASTCENC_F16C=0)

        # Enable SVE in the core library
        if (NOT ${ASTCENC_VENEER_TYPE})
            target_compile_options(${ASTCENC_TARGET_NAME}
                PRIVATE
                    -march=armv8-a+sve -msve-vector-bits=256)

        # Enable SVE without fixed vector length in the veneer
        elseif (${ASTCENC_VENEER_TYPE} EQUAL 2)
            target_compile_options(${ASTCENC_TARGET_NAME}
                PRIVATE
                    -march=armv8-a+sve)
        endif()

    elseif(${ASTCENC_ISA_SIMD} MATCHES "sve_128")
        target_compile_definitions(${ASTCENC_TARGET_NAME}
            PRIVATE
                ASTCENC_NEON=1
                ASTCENC_SVE=4
                ASTCENC_SSE=0
                ASTCENC_AVX=0
                ASTCENC_POPCNT=0
                ASTCENC_F16C=0)

        # Enable SVE in the core library
        # Note that for 128-bit SVE the generated code is actually
        # vector-length agnostic, but any manual intrinsics used in the
        # enhanced-NEON library use 128-bit data width predicates
        if (NOT ${ASTCENC_VENEER_TYPE})
            target_compile_options(${ASTCENC_TARGET_NAME}
                PRIVATE
                    -march=armv8-a+sve)

        # Enable SVE without fixed vector length in the veneer
        elseif (${ASTCENC_VENEER_TYPE} EQUAL 2)
            target_compile_options(${ASTCENC_TARGET_NAME}
                PRIVATE
                    -march=armv8-a+sve)
        endif()

    elseif(${ASTCENC_ISA_SIMD} MATCHES "sse2")
        target_compile_definitions(${ASTCENC_TARGET_NAME}
            PRIVATE
                ASTCENC_NEON=0
                ASTCENC_SVE=0
                ASTCENC_SSE=20
                ASTCENC_AVX=0
                ASTCENC_POPCNT=0
                ASTCENC_F16C=0
                ASTCENC_X86_GATHERS=0)

        # Force SSE2 on AppleClang (normally SSE4.1 is the default)
        target_compile_options(${ASTCENC_TARGET_NAME}
            PRIVATE
                $<${is_clangcl}:-msse2>
                $<${is_gnu_fe}:-msse2>
                $<${is_gnu_fe}:-mno-sse4.1>
                $<${is_gnu_fe}:-Wno-unused-command-line-argument>)

    elseif(${ASTCENC_ISA_SIMD} MATCHES "sse4.1")
        target_compile_definitions(${ASTCENC_TARGET_NAME}
            PRIVATE
                ASTCENC_NEON=0
                ASTCENC_SVE=0
                ASTCENC_SSE=41
                ASTCENC_AVX=0
                ASTCENC_POPCNT=1
                ASTCENC_F16C=0
                ASTCENC_X86_GATHERS=0)

        if (${ASTCENC_VENEER_TYPE} GREATER 0)
            # Force SSE2 on AppleClang (normally SSE4.1 is the default)
            target_compile_options(${ASTCENC_TARGET_NAME}
                PRIVATE
                    $<${is_gnu_fe}:-msse2>
                    $<${is_gnu_fe}:-mno-sse4.1>
                    $<${is_gnu_fe}:-Wno-unused-command-line-argument>)
        else()
            target_compile_options(${ASTCENC_TARGET_NAME}
                PRIVATE
                    $<${is_clangcl}:-msse4.1 -mpopcnt>
                    $<${is_gnu_fe}:-msse4.1 -mpopcnt>
                    $<${is_gnu_fe}:-Wno-unused-command-line-argument>)
        endif()

    elseif(${ASTCENC_ISA_SIMD} MATCHES "avx2")
        # Gathers are quite slow on many x86 microarchitectures, to the point where
        # it can be significantly faster to just avoid them use scalar loads.

        target_compile_definitions(${ASTCENC_TARGET_NAME}
            PRIVATE
                ASTCENC_NEON=0
                ASTCENC_SVE=0
                ASTCENC_SSE=41
                ASTCENC_AVX=2
                ASTCENC_X86_GATHERS=$<BOOL:${ASTCENC_X86_GATHERS}>
                ASTCENC_POPCNT=1
                ASTCENC_F16C=1)

        if (${ASTCENC_VENEER_TYPE} GREATER 0)
            # Force SSE2 on AppleClang (normally SSE4.1 is the default)
            target_compile_options(${ASTCENC_TARGET_NAME}
                PRIVATE
                    $<${is_gnu_fe}:-msse2>
                    $<${is_gnu_fe}:-mno-sse4.1>
                    $<${is_gnu_fe}:-Wno-unused-command-line-argument>)
        else()
            target_compile_options(${ASTCENC_TARGET_NAME}
                PRIVATE
                    $<${is_msvc_fe}:/arch:AVX2>
                    $<${is_clangcl}:-mavx2 -mpopcnt -mf16c>
                    $<${is_gnu_fe}:-mavx2 -mpopcnt -mf16c>
                    $<${is_gnu_fe}:-Wno-unused-command-line-argument>)
        endif()

        # Non-invariant builds enable us to loosen the compiler constraints on
        # floating point, but this is only worth doing on CPUs with AVX2 because
        # this implies we can also enable the FMA instruction set extensions
        # which significantly improve performance. Note that this DOES reduce
        # image quality by up to 0.2 dB (normally much less), but buys an
        # average of 10-15% performance improvement ...
        if((NOT ${ASTCENC_INVARIANCE}) AND (NOT ${ASTCENC_VENEER_TYPE}))
            target_compile_options(${ASTCENC_TARGET_NAME}
                PRIVATE
                    $<${is_gnu_fe}:-mfma>)
        endif()

    elseif(${ASTCENC_ISA_SIMD} MATCHES "native")
        target_compile_definitions(${ASTCENC_TARGET_NAME}
            PRIVATE)

        if (${ASTCENC_VENEER_TYPE} GREATER 0)
            target_compile_options(${ASTCENC_TARGET_NAME}
                PRIVATE
                    $<${is_gnu_fe}:-Wno-unused-command-line-argument>)
        else()
            target_compile_options(${ASTCENC_TARGET_NAME}
                PRIVATE
                    $<${is_gnu_fe}:-Wno-unused-command-line-argument>)
        endif()
    endif()

endmacro()

string(CONCAT EXTERNAL_CXX_FLAGS
       " $<${is_gnu_fe}: -fno-strict-aliasing>"
       " $<${is_gnu_fe}: -Wno-pedantic>"
       " $<${is_gnu_fe}: -Wno-unused-parameter>"
       " $<${is_gnu_fe}: -Wno-old-style-cast>"
       " $<${is_gnu_fe}: -Wno-double-promotion>"
       " $<${is_gnu_fe}: -Wno-zero-as-null-pointer-constant>"
       " $<${is_gnu_fe}: -Wno-disabled-macro-expansion>"
       " $<${is_gnu_fe}: -Wno-reserved-id-macro>"
       " $<${is_gnu_fe}: -Wno-extra-semi-stmt>"
       " $<${is_gnu_fe}: -Wno-implicit-fallthrough>"
       " $<${is_gnu_fe}: -Wno-tautological-type-limit-compare>"
       " $<${is_gnu_fe}: -Wno-cast-qual>"
       " $<${is_gnu_fe}: -Wno-reserved-identifier>"
       " $<${is_clang}: -Wno-missing-prototypes>"
       " $<${is_gnu_fe}: -Wno-missing-field-initializers>"
       " $<${is_gnu_fe}: -Wno-suggest-override>"
       " $<${is_gnu_fe}: -Wno-used-but-marked-unused>"
       " $<${is_gnu_fe}: -Wno-noexcept-type>"
       " $<${is_gnu_fe}: -Wno-comma>"
       " $<${is_gnu_fe}: -Wno-c99-extensions>")

set_source_files_properties(astcenccli_image_external.cpp
    PROPERTIES
        COMPILE_FLAGS ${EXTERNAL_CXX_FLAGS})

astcenc_set_properties(${ASTCENC_TARGET}-static OFF)

target_compile_options(${ASTCENC_TARGET}-static
    PRIVATE
        $<${is_msvc_fe}:/W4>)

set_target_properties(${ASTCENC_TARGET}-static
    PROPERTIES
        OUTPUT_NAME ${ASTCENC_TARGET}
        VERSION ${ASTCENC_VERSION}
)

if(${ASTCENC_SHAREDLIB})
    astcenc_set_properties(${ASTCENC_TARGET}-shared OFF)

    target_compile_definitions(${ASTCENC_TARGET}-shared
        PRIVATE
            ASTCENC_DYNAMIC_LIBRARY=1)

    target_compile_options(${ASTCENC_TARGET}-shared
        PRIVATE
            $<${is_gnu_fe}:-fvisibility=hidden>
            $<${is_msvc_fe}:/W4>)

    set_target_properties(${ASTCENC_TARGET}-shared
        PROPERTIES
            OUTPUT_NAME ${ASTCENC_TARGET}
            VERSION ${ASTCENC_VERSION}
            SOVERSION ${ASTCENC_SOVERSION}
    )

    if(NOT ${ASTCENC_UNIVERSAL_BUILD})
        install(TARGETS ${ASTCENC_TARGET}-shared EXPORT astcencTargets)
    endif()
endif()

if(${ASTCENC_CLI})
    astcenc_set_properties(${ASTCENC_TARGET}-veneer1 1)
    astcenc_set_properties(${ASTCENC_TARGET}-veneer2 2)
    astcenc_set_properties(${ASTCENC_TARGET} 0)

    target_compile_options(${ASTCENC_TARGET}-veneer1
        PRIVATE
            $<${is_msvc_fe}:/W3>)

    target_compile_options(${ASTCENC_TARGET}-veneer2
        PRIVATE
            $<${is_msvc_fe}:/W3>)

    target_compile_options(${ASTCENC_TARGET}
        PRIVATE
            $<${is_msvc_fe}:/W3>)

    string(TIMESTAMP astcencoder_YEAR "%Y")

    configure_file(
        astcenccli_version.h.in
        astcenccli_version.h
        ESCAPE_QUOTES @ONLY)

    target_include_directories(${ASTCENC_TARGET}
        PRIVATE
            ${CMAKE_CURRENT_BINARY_DIR})

    if(NOT ${ASTCENC_UNIVERSAL_BUILD})
        install(TARGETS ${ASTCENC_TARGET})
    endif()
endif()