forked from ARM-software/astc-encoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
169 lines (141 loc) · 5.42 KB
/
CMakeLists.txt
File metadata and controls
169 lines (141 loc) · 5.42 KB
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
# 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.
# ----------------------------------------------------------------------------
# CMake configuration
cmake_minimum_required(VERSION 3.15)
cmake_policy(SET CMP0069 NEW) # LTO support
cmake_policy(SET CMP0091 NEW) # MSVC runtime support
project(astcenc VERSION 3.0.0)
# Command line configuration
function(printopt optName optVal optArch tgtArch)
if(${optVal})
if(${optArch} MATCHES ${tgtArch})
message(" -- ${optName} backend - ON")
else()
message(" -- ${optName} backend - SKIPPED (${optArch} only)")
endif()
else()
message(" -- ${optName} backend - OFF")
endif()
endfunction()
set(VALID_ARCH aarch64 aarch32 aarch32hf x64)
set(ARCH x64 CACHE STRING "Target architecture")
set_property(CACHE ARCH PROPERTY STRINGS ${VALID_ARCH})
message("-- Selecting target astcenc backends:")
list(FIND VALID_ARCH ${ARCH} index)
if(index EQUAL -1)
message(FATAL_ERROR "ARCH must be one of ${VALID_ARCH}")
endif()
set(ANY_ISA 0)
option(ISA_AVX2 "Enable builds for AVX2 SIMD")
printopt("AVX2" ${ISA_AVX2} "x64" ${ARCH})
if(${ISA_AVX2} AND ${ARCH} MATCHES "x64")
set(ANY_ISA 1)
endif()
option(ISA_SSE41 "Enable builds for SSE4.1 SIMD")
printopt("SSE4.1" ${ISA_SSE41} "x64" ${ARCH})
if(${ISA_SSE41} AND ${ARCH} MATCHES "x64")
set(ANY_ISA 1)
endif()
option(ISA_SSE2 "Enable builds for SSE2 SIMD")
printopt("SSE2" ${ISA_SSE2} "x64" ${ARCH})
if(${ISA_SSE2} AND ${ARCH} MATCHES "x64")
set(ANY_ISA 1)
endif()
option(ISA_NEON "Enable builds for NEON SIMD")
printopt("NEON" ${ISA_NEON} "aarch32|aarch32hf|aarch64" ${ARCH})
if(${ISA_NEON} AND ${ARCH} MATCHES "aarch32|aarch32hf|aarch64")
set(ANY_ISA 1)
endif()
option(ISA_NONE "Enable builds for no SIMD")
if(${ISA_NONE})
set(ANY_ISA 1)
message(" -- No SIMD backend - ON")
else()
message(" -- No SIMD backend - OFF")
endif()
option(DECOMPRESSOR "Enable builds for decompression only")
if(${DECOMPRESSOR})
message(" -- Decompress-only backend - ON")
else()
message(" -- Decompress-only backend - OFF")
endif()
option(DIAGNOSTICS "Enable builds for diagnostic trace")
if(${DIAGNOSTICS})
message(" -- Diagnostic tracing - ON")
else()
message(" -- Diagnostic tracing - OFF")
endif()
option(UNITTEST "Enable builds for unit tests")
if(${UNITTEST})
message(" -- Unit tests - ON")
else()
message(" -- Unit tests - OFF")
endif()
if(NOT ${ANY_ISA})
message(FATAL_ERROR "At least one backend ISA must be enabled")
endif()
# Project configuration
# Must be done after project() but before compiler settings
# or it gets overriden (this contradicts the official docs)
if(${ARCH} MATCHES "aarch64")
set(CMAKE_OSX_ARCHITECTURES "arm64")
elseif(${ARCH} MATCHES "aarch32|aarch32hf")
# Deliberately use Armv7 for Clang - its most compatible with the current
# code; we provide some fallbacks for a few missing v8 intrinsics.
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(CMAKE_OSX_ARCHITECTURES "armv7")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv7-a")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon-vfpv4")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-command-line-argument")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
# For GCC we directly target Armv8-A A32, and provide some emulated
# fallback intrinsics for functionality that exists for A64 but not A32.
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=armv8-a")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon-fp-armv8")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfp16-format=ieee")
if(${ARCH} STREQUAL "aarch32") # arm-linux-gnueabi-g++
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfloat-abi=softfp")
elseif(${ARCH} STREQUAL "aarch32hf") # arm-linux-gnueabihf-g++
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfloat-abi=hard")
endif()
# Workaround for Source/tinyexr.h:11025
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-type-limits")
endif()
else()
set(CMAKE_OSX_ARCHITECTURES "x86_64")
endif()
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
set(PACKAGE_ROOT astcenc)
include(CTest)
# Subcomponents
add_subdirectory(Source)
# Configure package archive
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
string(TOLOWER "macOS" PKG_OS)
else()
string(TOLOWER ${CMAKE_SYSTEM_NAME} PKG_OS)
endif()
set(PKG_VER ${CMAKE_PROJECT_VERSION_MAJOR}.${CMAKE_PROJECT_VERSION_MINOR})
set(CPACK_PACKAGE_FILE_NAME "astcenc-${PKG_VER}-${PKG_OS}-${ARCH}")
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY FALSE)
set(CPACK_PACKAGE_CHECKSUM SHA256)
set(CPACK_GENERATOR ZIP)
include(CPack) # Must be included after CPack configuration.