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
|
# SPDX-License-Identifier: Apache-2.0
# ----------------------------------------------------------------------------
# Copyright 2020-2022 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(ASTC_TARGET astc${CODEC})
project(${ASTC_TARGET})
set(GNU_LIKE "GNU,Clang,AppleClang")
set(CLANG_LIKE "Clang,AppleClang")
set(CMAKE_THREAD_PREFER_PTHREAD ON)
find_package(Threads REQUIRED)
add_library(${ASTC_TARGET}-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_platform_isa_detection.cpp
astcenc_quantization.cpp
astcenc_symbolic_physical.cpp
astcenc_weight_align.cpp
astcenc_weight_quant_xfer_tables.cpp)
if(BUILD_SHARED_LIBS)
target_compile_definitions(${ASTC_TARGET}-static
PUBLIC
ASTCENC_DYNAMIC_LIBRARY
PRIVATE
ASTCENC_EXPORTS)
endif()
target_include_directories(${ASTC_TARGET}-static
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
if(${CLI})
add_executable(${ASTC_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(${ASTC_TARGET} PRIVATE ${stb_INCLUDE_DIR})
target_link_libraries(${ASTC_TARGET}
PRIVATE
tinyexr::tinyexr
stb
ZLIB::ZLIB
${ASTC_TARGET}-static)
endif()
macro(astcenc_set_properties NAME)
target_compile_features(${NAME}
PRIVATE
cxx_std_14)
target_compile_definitions(${NAME}
PRIVATE
# MSVC defines
$<$<CXX_COMPILER_ID:MSVC>:_CRT_SECURE_NO_WARNINGS>)
if(${DECOMPRESSOR})
target_compile_definitions(${NAME}
PRIVATE
ASTCENC_DECOMPRESS_ONLY)
endif()
if(${BLOCK_MAX_TEXELS})
target_compile_definitions(${NAME}
PRIVATE
ASTCENC_BLOCK_MAX_TEXELS=${BLOCK_MAX_TEXELS})
endif()
if(${DIAGNOSTICS})
target_compile_definitions(${NAME}
PUBLIC
ASTCENC_DIAGNOSTICS)
endif()
target_compile_options(${NAME}
PRIVATE
# MSVC compiler defines
$<$<CXX_COMPILER_ID:MSVC>:/EHsc>
$<$<CXX_COMPILER_ID:MSVC>:/fp:strict>
$<$<CXX_COMPILER_ID:MSVC>:/wd4324>
# G++ and Clang++ compiler defines
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wextra>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wpedantic>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wshadow>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wdouble-promotion>
# Hide noise thrown up by Clang 10 and clang-cl
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-unknown-warning-option>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-c++98-compat-pedantic>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-c++98-c++11-compat-pedantic>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-float-equal>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-deprecated-declarations>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-atomic-implicit-seq-cst>
# Clang 10 also throws up warnings we need to investigate (ours)
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-cast-align>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-sign-conversion>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-implicit-int-conversion>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-shift-sign-overflow>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-format-nonliteral>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-reserved-identifier>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-cast-function-type>
$<$<CXX_COMPILER_ID:Clang>:-Wdocumentation>)
target_link_libraries(${NAME}
PRIVATE
# Use pthreads on Linux/macOS
Threads::Threads)
if(${ASAN})
target_compile_options(${NAME}
PRIVATE
$<$<CXX_COMPILER_ID:${CLANG_LIKE}>:-fsanitize=address>)
target_link_options(${NAME}
PRIVATE
$<$<CXX_COMPILER_ID:${CLANG_LIKE}>:-fsanitize=address>)
endif()
if(${NO_INVARIANCE})
target_compile_definitions(${NAME}
PRIVATE
ASTCENC_NO_INVARIANCE=1)
target_compile_options(${NAME}
PRIVATE
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-ffp-contract=fast>)
endif()
if(${CLI})
# Enable LTO on release builds
set_property(TARGET ${NAME}
PROPERTY
INTERPROCEDURAL_OPTIMIZATION_RELEASE True)
# Use a static runtime on MSVC builds (ignored on non-MSVC compilers)
set_property(TARGET ${NAME}
PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
# Set up configuration for SIMD ISA builds
if(${ISA_SIMD} MATCHES "none")
if(NOT ${UNIVERSAL_BUILD})
target_compile_definitions(${NAME}
PRIVATE
ASTCENC_NEON=0
ASTCENC_SSE=0
ASTCENC_AVX=0
ASTCENC_POPCNT=0
ASTCENC_F16C=0)
endif()
elseif(${ISA_SIMD} MATCHES "neon")
if(NOT ${UNIVERSAL_BUILD})
target_compile_definitions(${NAME}
PRIVATE
ASTCENC_NEON=1
ASTCENC_SSE=0
ASTCENC_AVX=0
ASTCENC_POPCNT=0
ASTCENC_F16C=0)
endif()
# 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(${NAME}
PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/d2ssa-cfg-sink->)
endif()
elseif((${ISA_SIMD} MATCHES "sse2") OR (${UNIVERSAL_BUILD} AND ${ISA_SSE2}))
if(NOT ${UNIVERSAL_BUILD})
target_compile_definitions(${NAME}
PRIVATE
ASTCENC_NEON=0
ASTCENC_SSE=20
ASTCENC_AVX=0
ASTCENC_POPCNT=0
ASTCENC_F16C=0)
endif()
# These settings are needed on AppleClang as SSE4.1 is on by default
# Suppress unused argument for macOS universal build behavior
target_compile_options(${NAME}
PRIVATE
$<$<CXX_COMPILER_ID:AppleClang>:-msse2>
$<$<CXX_COMPILER_ID:AppleClang>:-mno-sse4.1>
$<$<CXX_COMPILER_ID:AppleClang>:-Wno-unused-command-line-argument>)
elseif((${ISA_SIMD} MATCHES "sse4.1") OR (${UNIVERSAL_BUILD} AND ${ISA_SSE41}))
if(NOT ${UNIVERSAL_BUILD})
target_compile_definitions(${NAME}
PRIVATE
ASTCENC_NEON=0
ASTCENC_SSE=41
ASTCENC_AVX=0
ASTCENC_POPCNT=1
ASTCENC_F16C=0)
endif()
# Suppress unused argument for macOS universal build behavior
target_compile_options(${NAME}
PRIVATE
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-msse4.1 -mpopcnt>
$<$<CXX_COMPILER_ID:AppleClang>:-Wno-unused-command-line-argument>)
elseif((${ISA_SIMD} MATCHES "avx2") OR (${UNIVERSAL_BUILD} AND ${ISA_AVX2}))
if(NOT ${UNIVERSAL_BUILD})
target_compile_definitions(${NAME}
PRIVATE
ASTCENC_NEON=0
ASTCENC_SSE=41
ASTCENC_AVX=2
ASTCENC_POPCNT=1
ASTCENC_F16C=1)
endif()
# Suppress unused argument for macOS universal build behavior
target_compile_options(${NAME}
PRIVATE
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-mavx2 -mpopcnt -mf16c>
$<$<CXX_COMPILER_ID:MSVC>:/arch:AVX2>
$<$<CXX_COMPILER_ID:AppleClang>:-Wno-unused-command-line-argument>)
# 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(${NO_INVARIANCE})
target_compile_options(${NAME}
PRIVATE
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-mfma>)
endif()
endif()
endmacro()
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
string(CONCAT EXTERNAL_CXX_FLAGS
" $<$<NOT:$<CXX_COMPILER_ID:MSVC>>: -fno-strict-aliasing>"
" $<$<NOT:$<CXX_COMPILER_ID:MSVC>>: -Wno-unused-parameter>"
" $<$<NOT:$<CXX_COMPILER_ID:MSVC>>: -Wno-old-style-cast>"
" $<$<NOT:$<CXX_COMPILER_ID:MSVC>>: -Wno-double-promotion>"
" $<$<NOT:$<CXX_COMPILER_ID:MSVC>>: -Wno-zero-as-null-pointer-constant>"
" $<$<NOT:$<CXX_COMPILER_ID:MSVC>>: -Wno-disabled-macro-expansion>"
" $<$<NOT:$<CXX_COMPILER_ID:MSVC>>: -Wno-reserved-id-macro>"
" $<$<NOT:$<CXX_COMPILER_ID:MSVC>>: -Wno-extra-semi-stmt>"
" $<$<NOT:$<CXX_COMPILER_ID:MSVC>>: -Wno-implicit-fallthrough>"
" $<$<NOT:$<CXX_COMPILER_ID:MSVC>>: -Wno-tautological-type-limit-compare>"
" $<$<NOT:$<CXX_COMPILER_ID:MSVC>>: -Wno-cast-qual>"
" $<$<NOT:$<CXX_COMPILER_ID:MSVC>>: -Wno-reserved-identifier>"
" $<$<CXX_COMPILER_ID:Clang>: -Wno-missing-prototypes>"
" $<$<NOT:$<CXX_COMPILER_ID:MSVC>>: -Wno-suggest-override>"
" $<$<NOT:$<CXX_COMPILER_ID:MSVC>>: -Wno-used-but-marked-unused>"
" $<$<NOT:$<CXX_COMPILER_ID:MSVC>>: -Wno-noexcept-type>"
" $<$<NOT:$<CXX_COMPILER_ID:MSVC>>: -Wno-comma>"
" $<$<NOT:$<CXX_COMPILER_ID:MSVC>>: -Wno-c99-extensions>")
set_source_files_properties(astcenccli_image_external.cpp
PROPERTIES
COMPILE_FLAGS ${EXTERNAL_CXX_FLAGS})
endif()
astcenc_set_properties(${ASTC_TARGET}-static)
target_compile_options(${ASTC_TARGET}-static
PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4>)
set_target_properties(${ASTC_TARGET}-static
PROPERTIES
OUTPUT_NAME ${ASTC_TARGET}
EXPORT_NAME ${ASTC_TARGET}
VERSION ${ASTCENC_VERSION}
SOVERSION ${ASTCENC_SOVERSION}
)
install(TARGETS ${ASTC_TARGET}-static DESTINATION ${CMAKE_INSTALL_LIBDIR} EXPORT astcencTargets)
if(${CLI})
astcenc_set_properties(${ASTC_TARGET})
target_compile_options(${ASTC_TARGET}
PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W3>)
string(TIMESTAMP astcencoder_YEAR "%Y")
configure_file(
astcenccli_version.h.in
astcenccli_version.h
ESCAPE_QUOTES @ONLY)
target_include_directories(${ASTC_TARGET}
PRIVATE
${CMAKE_CURRENT_BINARY_DIR})
install(TARGETS ${ASTC_TARGET} DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
|