• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#  SPDX-License-Identifier: Apache-2.0
2#  ----------------------------------------------------------------------------
3#  Copyright 2020-2024 Arm Limited
4#
5#  Licensed under the Apache License, Version 2.0 (the "License"); you may not
6#  use this file except in compliance with the License. You may obtain a copy
7#  of the License at:
8#
9#      http://www.apache.org/licenses/LICENSE-2.0
10#
11#  Unless required by applicable law or agreed to in writing, software
12#  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13#  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14#  License for the specific language governing permissions and limitations
15#  under the License.
16#  ----------------------------------------------------------------------------
17
18# CMake configuration
19cmake_minimum_required(VERSION 3.15)
20cmake_policy(SET CMP0069 NEW)  # LTO support
21cmake_policy(SET CMP0091 NEW)  # MSVC runtime support
22
23if(MSVC)
24    add_compile_options("/wd4324") # Disable structure was padded due to alignment specifier
25endif()
26
27project(astcencoder VERSION 4.7.0)
28
29set(CMAKE_CXX_STANDARD 14)
30set(CMAKE_CXX_STANDARD_REQUIRED ON)
31set(CMAKE_CXX_EXTENSIONS OFF)
32set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
33set(CMAKE_XCODE_ATTRIBUTE_VALID_ARCHS "x86_64 x86_64h arm64")
34
35include(CTest)
36
37option(ASTCENC_ISA_AVX2 "Enable astcenc builds for AVX2 SIMD")
38option(ASTCENC_ISA_SSE41 "Enable astcenc builds for SSE4.1 SIMD")
39option(ASTCENC_ISA_SSE2 "Enable astcenc builds for SSE2 SIMD")
40option(ASTCENC_ISA_NEON "Enable astcenc builds for NEON SIMD")
41option(ASTCENC_ISA_NONE "Enable astcenc builds for no SIMD")
42option(ASTCENC_ISA_NATIVE "Enable astcenc builds for native SIMD")
43option(ASTCENC_DECOMPRESSOR "Enable astcenc builds for decompression only")
44option(ASTCENC_SHAREDLIB "Enable astcenc builds with core library shared objects")
45option(ASTCENC_DIAGNOSTICS "Enable astcenc builds with diagnostic trace")
46option(ASTCENC_ASAN "Enable astcenc builds with address sanitizer")
47option(ASTCENC_UNITTEST "Enable astcenc builds with unit tests")
48option(ASTCENC_INVARIANCE "Enable astcenc floating point invariance" ON)
49option(ASTCENC_CLI "Enable build of astcenc command line tools" ON)
50
51# Preflight for some macOS-specific build options
52if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
53    option(ASTCENC_UNIVERSAL_BUILD "Enable universal multi-arch build" ON)
54
55    if(${ASTCENC_UNIVERSAL_BUILD})
56        set(ASTCENC_ISA_SSE41 ON)
57        set(ASTCENC_ISA_AVX2 ON)
58        set(ASTCENC_ISA_NEON ON)
59
60        if(${ASTCENC_ISA_SSE2})
61            message(FATAL_ERROR "ISA_SSE2 cannot be used in a universal build")
62        endif()
63
64        if(${ASTCENC_ISA_NONE})
65            message(FATAL_ERROR "ISA_NONE cannot be used in a universal build")
66        endif()
67
68        if(${ASTCENC_ISA_NATIVE})
69            message(FATAL_ERROR "ISA_NATIVE cannot be used in a universal build")
70        endif()
71    endif()
72else()
73    set(ASTCENC_UNIVERSAL_BUILD OFF)
74endif()
75
76# Count options which MUST be x64
77set(ASTCENC_X64_ISA_COUNT 0)
78set(ASTCENC_CONFIGS ${ASTCENC_ISA_AVX2} ${ASTCENC_ISA_SSE41} ${ASTCENC_ISA_SSE2})
79foreach(ASTCENC_CONFIG ${ASTCENC_CONFIGS})
80    if(${ASTCENC_CONFIG})
81        math(EXPR ASTCENC_X64_ISA_COUNT "${ASTCENC_X64_ISA_COUNT} + 1")
82    endif()
83endforeach()
84
85# Count options which MUST be arm64
86set(ASTCENC_ARM64_ISA_COUNT 0)
87set(ASTCENC_CONFIGS ${ASTCENC_ISA_NEON})
88foreach(ASTCENC_CONFIG ${ASTCENC_CONFIGS})
89    if(${ASTCENC_CONFIG})
90        math(EXPR ASTCENC_ARM64_ISA_COUNT "${ASTCENC_ARM64_ISA_COUNT} + 1")
91    endif()
92endforeach()
93
94# Non-macOS builds
95if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
96    if(("${ASTCENC_ARM64_ISA_COUNT}" GREATER 0) AND ("${ASTCENC_X64_ISA_COUNT}" GREATER 0))
97        message(FATAL_ERROR "Builds can only support a single architecture per configure.")
98    endif()
99endif()
100
101# If nothing more specific is set then fall back on the compiler's defaults
102if(("${ASTCENC_ARM64_ISA_COUNT}" EQUAL 0) AND ("${ASTCENC_X64_ISA_COUNT}" EQUAL 0) AND (NOT "${ASTCENC_ISA_NONE}"))
103    set(ASTCENC_ISA_NATIVE ON)
104endif()
105
106function(printopt optName optVal)
107    if(${optVal})
108        message(STATUS "  ${optName}  - ON")
109    else()
110        message(STATUS "  ${optName}  - OFF")
111    endif()
112endfunction()
113
114if("${ASTCENC_BLOCK_MAX_TEXELS}")
115     message(STATUS "  Max block texels - ${ASTCENC_BLOCK_MAX_TEXELS}")
116endif()
117
118printopt("AVX2 backend   " ${ASTCENC_ISA_AVX2})
119printopt("SSE4.1 backend " ${ASTCENC_ISA_SSE41})
120printopt("SSE2 backend   " ${ASTCENC_ISA_SSE2})
121printopt("NEON backend   " ${ASTCENC_ISA_NEON})
122printopt("NONE backend   " ${ASTCENC_ISA_NONE})
123printopt("NATIVE backend " ${ASTCENC_ISA_NATIVE})
124if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
125    printopt("Universal bin  " ${ASTCENC_UNIVERSAL_BUILD})
126endif()
127printopt("Invariance     " ${ASTCENC_INVARIANCE})
128printopt("Shared libs    " ${ASTCENC_SHAREDLIB})
129printopt("Decompressor   " ${ASTCENC_DECOMPRESSOR})
130printopt("Diagnostics    " ${ASTCENC_DIAGNOSTICS})
131printopt("ASAN           " ${ASTCENC_ASAN})
132printopt("Unit tests     " ${ASTCENC_UNITTEST})
133
134# Subcomponents
135add_subdirectory(Source)
136
137# Configure package archive
138if(ASTCENC_PACKAGE)
139    if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
140        string(TOLOWER "macOS" ASTCENC_PKG_OS)
141    else()
142        string(TOLOWER ${CMAKE_SYSTEM_NAME} ASTCENC_PKG_OS)
143    endif()
144
145    set(CPACK_PACKAGE_FILE_NAME "astcenc-${CMAKE_PROJECT_VERSION}-${ASTCENC_PKG_OS}-${ASTCENC_PACKAGE}")
146    set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY FALSE)
147    set(CPACK_PACKAGE_CHECKSUM SHA256)
148    set(CPACK_GENERATOR ZIP)
149
150    include(CPack) # Must be included after CPack configuration.
151endif()
152