# Copyright 2019 Google LLC
#
# Use of this source code is governed by an MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.

add_library(pikcommon STATIC
  ${CMAKE_CURRENT_LIST_DIR}/simd/targets.cc
  ${CMAKE_CURRENT_LIST_DIR}/simd/targets.h
  ${CMAKE_CURRENT_LIST_DIR}/ac_predictions.cc
  ${CMAKE_CURRENT_LIST_DIR}/ac_predictions.h
  ${CMAKE_CURRENT_LIST_DIR}/ac_strategy.cc
  ${CMAKE_CURRENT_LIST_DIR}/ac_strategy.h
  ${CMAKE_CURRENT_LIST_DIR}/adaptive_quantization.cc
  ${CMAKE_CURRENT_LIST_DIR}/adaptive_quantization.h
  ${CMAKE_CURRENT_LIST_DIR}/adaptive_reconstruction.cc
  ${CMAKE_CURRENT_LIST_DIR}/adaptive_reconstruction_fwd.h
  ${CMAKE_CURRENT_LIST_DIR}/adaptive_reconstruction.h
  ${CMAKE_CURRENT_LIST_DIR}/alpha.cc
  ${CMAKE_CURRENT_LIST_DIR}/alpha.h
  ${CMAKE_CURRENT_LIST_DIR}/ans_common.cc
  ${CMAKE_CURRENT_LIST_DIR}/ans_common.h
  ${CMAKE_CURRENT_LIST_DIR}/ans_decode.cc
  ${CMAKE_CURRENT_LIST_DIR}/ans_decode.h
  ${CMAKE_CURRENT_LIST_DIR}/ans_encode.cc
  ${CMAKE_CURRENT_LIST_DIR}/ans_encode.h
  ${CMAKE_CURRENT_LIST_DIR}/ans_params.h
  ${CMAKE_CURRENT_LIST_DIR}/approx_cube_root.h
  ${CMAKE_CURRENT_LIST_DIR}/ar_control_field.cc
  ${CMAKE_CURRENT_LIST_DIR}/ar_control_field.h
  ${CMAKE_CURRENT_LIST_DIR}/arch_specific.cc
  ${CMAKE_CURRENT_LIST_DIR}/arch_specific.h
  ${CMAKE_CURRENT_LIST_DIR}/args.h
  ${CMAKE_CURRENT_LIST_DIR}/bit_reader.h
  ${CMAKE_CURRENT_LIST_DIR}/bits.h
  ${CMAKE_CURRENT_LIST_DIR}/block.h
  ${CMAKE_CURRENT_LIST_DIR}/block_dictionary.h
  ${CMAKE_CURRENT_LIST_DIR}/block_dictionary.cc
  ${CMAKE_CURRENT_LIST_DIR}/brotli.cc
  ${CMAKE_CURRENT_LIST_DIR}/brotli.h
  ${CMAKE_CURRENT_LIST_DIR}/butteraugli/butteraugli.cc
  ${CMAKE_CURRENT_LIST_DIR}/butteraugli/butteraugli.h
  ${CMAKE_CURRENT_LIST_DIR}/butteraugli_comparator.cc
  ${CMAKE_CURRENT_LIST_DIR}/butteraugli_comparator.h
  ${CMAKE_CURRENT_LIST_DIR}/butteraugli_distance.cc
  ${CMAKE_CURRENT_LIST_DIR}/butteraugli_distance.h
  ${CMAKE_CURRENT_LIST_DIR}/byte_order.h
  ${CMAKE_CURRENT_LIST_DIR}/cache_aligned.cc
  ${CMAKE_CURRENT_LIST_DIR}/cache_aligned.h
  ${CMAKE_CURRENT_LIST_DIR}/cluster.h
  ${CMAKE_CURRENT_LIST_DIR}/codec.h
  ${CMAKE_CURRENT_LIST_DIR}/codec_impl.cc
  ${CMAKE_CURRENT_LIST_DIR}/codec_png.cc
  ${CMAKE_CURRENT_LIST_DIR}/codec_png.h
  ${CMAKE_CURRENT_LIST_DIR}/codec_pnm.cc
  ${CMAKE_CURRENT_LIST_DIR}/codec_pnm.h
  ${CMAKE_CURRENT_LIST_DIR}/color_correlation.cc
  ${CMAKE_CURRENT_LIST_DIR}/color_correlation.h
  ${CMAKE_CURRENT_LIST_DIR}/color_encoding.cc
  ${CMAKE_CURRENT_LIST_DIR}/color_encoding.h
  ${CMAKE_CURRENT_LIST_DIR}/color_management.cc
  ${CMAKE_CURRENT_LIST_DIR}/color_management.h
  ${CMAKE_CURRENT_LIST_DIR}/common.h
  ${CMAKE_CURRENT_LIST_DIR}/compiler_specific.h
  ${CMAKE_CURRENT_LIST_DIR}/compressed_dc.cc
  ${CMAKE_CURRENT_LIST_DIR}/compressed_dc.h
  ${CMAKE_CURRENT_LIST_DIR}/compressed_image.cc
  ${CMAKE_CURRENT_LIST_DIR}/compressed_image_fwd.h
  ${CMAKE_CURRENT_LIST_DIR}/compressed_image.h
  ${CMAKE_CURRENT_LIST_DIR}/context_map_decode.cc
  ${CMAKE_CURRENT_LIST_DIR}/context_map_decode.h
  ${CMAKE_CURRENT_LIST_DIR}/context_map_encode.cc
  ${CMAKE_CURRENT_LIST_DIR}/context_map_encode.h
  ${CMAKE_CURRENT_LIST_DIR}/convolve.h
  ${CMAKE_CURRENT_LIST_DIR}/data_parallel.cc
  ${CMAKE_CURRENT_LIST_DIR}/data_parallel.h
  ${CMAKE_CURRENT_LIST_DIR}/dc_predictor.cc
  ${CMAKE_CURRENT_LIST_DIR}/dc_predictor.h
  ${CMAKE_CURRENT_LIST_DIR}/dct.cc
  ${CMAKE_CURRENT_LIST_DIR}/dct.h
  ${CMAKE_CURRENT_LIST_DIR}/dct_simd_4.h
  ${CMAKE_CURRENT_LIST_DIR}/dct_simd_8.h
  ${CMAKE_CURRENT_LIST_DIR}/dct_simd_any.h
  ${CMAKE_CURRENT_LIST_DIR}/dct_util.cc
  ${CMAKE_CURRENT_LIST_DIR}/dct_util.h
  ${CMAKE_CURRENT_LIST_DIR}/deconvolve.cc
  ${CMAKE_CURRENT_LIST_DIR}/deconvolve.h
  ${CMAKE_CURRENT_LIST_DIR}/descriptive_statistics.cc
  ${CMAKE_CURRENT_LIST_DIR}/descriptive_statistics.h
  ${CMAKE_CURRENT_LIST_DIR}/entropy_coder.cc
  ${CMAKE_CURRENT_LIST_DIR}/entropy_coder.h
  ${CMAKE_CURRENT_LIST_DIR}/entropy_source.h
  ${CMAKE_CURRENT_LIST_DIR}/epf.cc
  ${CMAKE_CURRENT_LIST_DIR}/epf.h
  ${CMAKE_CURRENT_LIST_DIR}/epf_stats.h
  ${CMAKE_CURRENT_LIST_DIR}/epf_target.cc
  ${CMAKE_CURRENT_LIST_DIR}/external_image.cc
  ${CMAKE_CURRENT_LIST_DIR}/external_image.h
  ${CMAKE_CURRENT_LIST_DIR}/fast_log.h
  ${CMAKE_CURRENT_LIST_DIR}/field_encodings.h
  ${CMAKE_CURRENT_LIST_DIR}/fields.h
  ${CMAKE_CURRENT_LIST_DIR}/file_io.h
  ${CMAKE_CURRENT_LIST_DIR}/gaborish.cc
  ${CMAKE_CURRENT_LIST_DIR}/gaborish.h
  ${CMAKE_CURRENT_LIST_DIR}/gamma_correct.h
  ${CMAKE_CURRENT_LIST_DIR}/gauss_blur.cc
  ${CMAKE_CURRENT_LIST_DIR}/gauss_blur.h
  ${CMAKE_CURRENT_LIST_DIR}/gradient_map.cc
  ${CMAKE_CURRENT_LIST_DIR}/gradient_map.h
  ${CMAKE_CURRENT_LIST_DIR}/headers.cc
  ${CMAKE_CURRENT_LIST_DIR}/headers.h
  ${CMAKE_CURRENT_LIST_DIR}/huffman_decode.cc
  ${CMAKE_CURRENT_LIST_DIR}/huffman_decode.h
  ${CMAKE_CURRENT_LIST_DIR}/huffman_encode.cc
  ${CMAKE_CURRENT_LIST_DIR}/huffman_encode.h
  ${CMAKE_CURRENT_LIST_DIR}/image.cc
  ${CMAKE_CURRENT_LIST_DIR}/image.h
  ${CMAKE_CURRENT_LIST_DIR}/lehmer_code.cc
  ${CMAKE_CURRENT_LIST_DIR}/lehmer_code.h
  ${CMAKE_CURRENT_LIST_DIR}/linalg.cc
  ${CMAKE_CURRENT_LIST_DIR}/linalg.h
  ${CMAKE_CURRENT_LIST_DIR}/lossless16.cc
  ${CMAKE_CURRENT_LIST_DIR}/lossless16.h
  ${CMAKE_CURRENT_LIST_DIR}/lossless8.cc
  ${CMAKE_CURRENT_LIST_DIR}/lossless8.h
  ${CMAKE_CURRENT_LIST_DIR}/lossless_entropy.cc
  ${CMAKE_CURRENT_LIST_DIR}/lossless_entropy.h
  ${CMAKE_CURRENT_LIST_DIR}/metadata.cc
  ${CMAKE_CURRENT_LIST_DIR}/metadata.h
  ${CMAKE_CURRENT_LIST_DIR}/multipass_handler.h
  ${CMAKE_CURRENT_LIST_DIR}/noise.cc
  ${CMAKE_CURRENT_LIST_DIR}/noise.h
  ${CMAKE_CURRENT_LIST_DIR}/opsin_image.cc
  ${CMAKE_CURRENT_LIST_DIR}/opsin_image.h
  ${CMAKE_CURRENT_LIST_DIR}/opsin_inverse.cc
  ${CMAKE_CURRENT_LIST_DIR}/opsin_inverse.h
  ${CMAKE_CURRENT_LIST_DIR}/opsin_params.cc
  ${CMAKE_CURRENT_LIST_DIR}/opsin_params.h
  ${CMAKE_CURRENT_LIST_DIR}/optimize.h
  ${CMAKE_CURRENT_LIST_DIR}/os_specific.cc
  ${CMAKE_CURRENT_LIST_DIR}/os_specific.h
  ${CMAKE_CURRENT_LIST_DIR}/padded_bytes.cc
  ${CMAKE_CURRENT_LIST_DIR}/padded_bytes.h
  ${CMAKE_CURRENT_LIST_DIR}/pik.cc
  ${CMAKE_CURRENT_LIST_DIR}/pik.h
  ${CMAKE_CURRENT_LIST_DIR}/pik_info.cc
  ${CMAKE_CURRENT_LIST_DIR}/pik_info.h
  ${CMAKE_CURRENT_LIST_DIR}/pik_multipass.cc
  ${CMAKE_CURRENT_LIST_DIR}/pik_multipass.h
  ${CMAKE_CURRENT_LIST_DIR}/pik_params.h
  ${CMAKE_CURRENT_LIST_DIR}/pik_pass.cc
  ${CMAKE_CURRENT_LIST_DIR}/pik_pass.h
  ${CMAKE_CURRENT_LIST_DIR}/profiler.h
  ${CMAKE_CURRENT_LIST_DIR}/quantizer.cc
  ${CMAKE_CURRENT_LIST_DIR}/quantizer.h
  ${CMAKE_CURRENT_LIST_DIR}/quant_weights.cc
  ${CMAKE_CURRENT_LIST_DIR}/quant_weights.h
  ${CMAKE_CURRENT_LIST_DIR}/rational_polynomial.h
  ${CMAKE_CURRENT_LIST_DIR}/resample.h
  ${CMAKE_CURRENT_LIST_DIR}/resize.h
  ${CMAKE_CURRENT_LIST_DIR}/saliency_map.cc
  ${CMAKE_CURRENT_LIST_DIR}/saliency_map.h
  ${CMAKE_CURRENT_LIST_DIR}/single_image_handler.cc
  ${CMAKE_CURRENT_LIST_DIR}/single_image_handler.h
  ${CMAKE_CURRENT_LIST_DIR}/size_coder.h
  ${CMAKE_CURRENT_LIST_DIR}/status.cc
  ${CMAKE_CURRENT_LIST_DIR}/status.h
  ${CMAKE_CURRENT_LIST_DIR}/tsc_timer.h
  ${CMAKE_CURRENT_LIST_DIR}/upscaler.cc
  ${CMAKE_CURRENT_LIST_DIR}/upscaler.h
  ${CMAKE_CURRENT_LIST_DIR}/write_bits.h
  ${CMAKE_CURRENT_LIST_DIR}/yuv_convert.cc
  ${CMAKE_CURRENT_LIST_DIR}/yuv_convert.h
  ${CMAKE_CURRENT_LIST_DIR}/yuv_opsin_convert.cc
  ${CMAKE_CURRENT_LIST_DIR}/yuv_opsin_convert.h
)

target_include_directories(pikcommon
    PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
target_compile_options(pikcommon PUBLIC -mavx2)

target_link_libraries(pikcommon PRIVATE
  brotlicommon-static
  brotlienc-static
  brotlidec-static
  fse
  lodepng
  lcms2
  Threads::Threads
  "${CMAKE_DL_LIBS}"
)
