# SPDX-License-Identifier: Apache-2.0 # ---------------------------------------------------------------------------- # Copyright 2020-2021 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. # ---------------------------------------------------------------------------- if(${UNIVERSAL_BUILD}) set(ASTC_TARGET astc${CODEC}) else() set(ASTC_TARGET astc${CODEC}-${ISA_SIMD}) endif() project(${ASTC_TARGET}) set(GNU_LIKE "GNU,Clang,AppleClang") set(CLANG_LIKE "Clang,AppleClang") add_library(${ASTC_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_platform_isa_detection.cpp astcenc_quantization.cpp astcenc_symbolic_physical.cpp astcenc_weight_align.cpp astcenc_weight_quant_xfer_tables.cpp) target_include_directories(${ASTC_TARGET}-static PUBLIC $ $) 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_link_libraries(${ASTC_TARGET} PRIVATE ${ASTC_TARGET}-static) endif() macro(astcenc_set_properties NAME) target_compile_features(${NAME} PRIVATE cxx_std_14) target_compile_definitions(${NAME} PRIVATE # MSVC defines $<$:_CRT_SECURE_NO_WARNINGS>) if(${DECOMPRESSOR}) target_compile_definitions(${NAME} PRIVATE ASTCENC_DECOMPRESS_ONLY) endif() if(${DIAGNOSTICS}) target_compile_definitions(${NAME} PUBLIC ASTCENC_DIAGNOSTICS) endif() target_compile_options(${NAME} PRIVATE # Use pthreads on Linux/macOS $<$:-pthread> # MSVC compiler defines $<$:/EHsc> $<$:/fp:strict> # G++ and Clang++ compiler defines $<$>:-Wall> $<$>:-Wextra> $<$>:-Wpedantic> $<$>:-Werror> $<$>:-Wshadow> $<$>:-Wdouble-promotion> # Hide noise thrown up by Clang 10 and clang-cl $<$>:-Wno-unknown-warning-option> $<$>:-Wno-c++98-compat-pedantic> $<$>:-Wno-c++98-c++11-compat-pedantic> $<$>:-Wno-float-equal> $<$>:-Wno-deprecated-declarations> # Clang 10 also throws up warnings we need to investigate (ours) $<$>:-Wno-old-style-cast> $<$>:-Wno-cast-align> $<$>:-Wno-sign-conversion> $<$>:-Wno-implicit-int-conversion> $<$>:-Wno-shift-sign-overflow> $<$>:-Wno-format-nonliteral> $<$:-Wdocumentation>) target_link_options(${NAME} PRIVATE # Use pthreads on Linux/macOS $<$:-pthread>) 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$<$: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() 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 $<$:-msse2> $<$:-mno-sse4.1> $<$:-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 $<$>:-msse4.1 -mpopcnt> $<$:-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 $<$>:-mavx2 -mpopcnt -mf16c> $<$:/arch:AVX2> $<$:-Wno-unused-command-line-argument>) endif() endmacro() if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") string(CONCAT EXTERNAL_CXX_FLAGS " $<$>: -fno-strict-aliasing>" " $<$>: -Wno-unused-parameter>" " $<$>: -Wno-double-promotion>" " $<$>: -Wno-zero-as-null-pointer-constant>" " $<$>: -Wno-disabled-macro-expansion>" " $<$>: -Wno-reserved-id-macro>" " $<$>: -Wno-extra-semi-stmt>" " $<$>: -Wno-implicit-fallthrough>" " $<$>: -Wno-tautological-type-limit-compare>" " $<$>: -Wno-cast-qual>" " $<$: -Wno-missing-prototypes>") set_source_files_properties(astcenccli_image_external.cpp PROPERTIES COMPILE_FLAGS ${EXTERNAL_CXX_FLAGS}) endif() astcenc_set_properties(${ASTC_TARGET}-static) if(${CLI}) astcenc_set_properties(${ASTC_TARGET}) 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 ${PACKAGE_ROOT}) endif()