• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#  SPDX-License-Identifier: Apache-2.0
2#  ----------------------------------------------------------------------------
3#  Copyright 2020-2022 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
18if(${UNIVERSAL_BUILD})
19    set(ASTC_TARGET astc${CODEC})
20else()
21    set(ASTC_TARGET astc${CODEC}-${ISA_SIMD})
22endif()
23
24project(${ASTC_TARGET})
25
26set(GNU_LIKE "GNU,Clang,AppleClang")
27set(CLANG_LIKE "Clang,AppleClang")
28
29add_library(${ASTC_TARGET}-static
30    STATIC
31        astcenc_averages_and_directions.cpp
32        astcenc_block_sizes.cpp
33        astcenc_color_quantize.cpp
34        astcenc_color_unquantize.cpp
35        astcenc_compress_symbolic.cpp
36        astcenc_compute_variance.cpp
37        astcenc_decompress_symbolic.cpp
38        astcenc_diagnostic_trace.cpp
39        astcenc_entry.cpp
40        astcenc_find_best_partitioning.cpp
41        astcenc_ideal_endpoints_and_weights.cpp
42        astcenc_image.cpp
43        astcenc_integer_sequence.cpp
44        astcenc_mathlib.cpp
45        astcenc_mathlib_softfloat.cpp
46        astcenc_partition_tables.cpp
47        astcenc_percentile_tables.cpp
48        astcenc_pick_best_endpoint_format.cpp
49        astcenc_platform_isa_detection.cpp
50        astcenc_quantization.cpp
51        astcenc_symbolic_physical.cpp
52        astcenc_weight_align.cpp
53        astcenc_weight_quant_xfer_tables.cpp)
54
55target_include_directories(${ASTC_TARGET}-static
56    PUBLIC
57        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
58        $<INSTALL_INTERFACE:.>)
59
60if(${CLI})
61    add_executable(${ASTC_TARGET}
62        astcenccli_error_metrics.cpp
63        astcenccli_image.cpp
64        astcenccli_image_external.cpp
65        astcenccli_image_load_store.cpp
66        astcenccli_platform_dependents.cpp
67        astcenccli_toplevel.cpp
68        astcenccli_toplevel_help.cpp)
69
70    target_link_libraries(${ASTC_TARGET}
71        PRIVATE
72            ${ASTC_TARGET}-static)
73endif()
74
75macro(astcenc_set_properties NAME)
76
77    target_compile_features(${NAME}
78        PRIVATE
79            cxx_std_14)
80
81    target_compile_definitions(${NAME}
82        PRIVATE
83            # MSVC defines
84            $<$<CXX_COMPILER_ID:MSVC>:_CRT_SECURE_NO_WARNINGS>)
85
86    if(${DECOMPRESSOR})
87        target_compile_definitions(${NAME}
88            PRIVATE
89                ASTCENC_DECOMPRESS_ONLY)
90    endif()
91
92    if(${BLOCK_MAX_TEXELS})
93        target_compile_definitions(${NAME}
94            PRIVATE
95                ASTCENC_BLOCK_MAX_TEXELS=${BLOCK_MAX_TEXELS})
96    endif()
97
98    if(${DIAGNOSTICS})
99        target_compile_definitions(${NAME}
100            PUBLIC
101                ASTCENC_DIAGNOSTICS)
102    endif()
103
104    target_compile_options(${NAME}
105        PRIVATE
106            # Use pthreads on Linux/macOS
107            $<$<PLATFORM_ID:Linux,Darwin>:-pthread>
108
109            # MSVC compiler defines
110            $<$<CXX_COMPILER_ID:MSVC>:/EHsc>
111            $<$<CXX_COMPILER_ID:MSVC>:/fp:strict>
112
113            # G++ and Clang++ compiler defines
114            $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall>
115            $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wextra>
116            $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wpedantic>
117            $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Werror>
118            $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wshadow>
119            $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wdouble-promotion>
120
121            # Hide noise thrown up by Clang 10 and clang-cl
122            $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-unknown-warning-option>
123            $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-c++98-compat-pedantic>
124            $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-c++98-c++11-compat-pedantic>
125            $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-float-equal>
126            $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-deprecated-declarations>
127            $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-atomic-implicit-seq-cst>
128
129            # Clang 10 also throws up warnings we need to investigate (ours)
130            $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-cast-align>
131            $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-sign-conversion>
132            $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-implicit-int-conversion>
133            $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-shift-sign-overflow>
134            $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-format-nonliteral>
135            $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-reserved-identifier>
136            $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-cast-function-type>
137
138            $<$<CXX_COMPILER_ID:Clang>:-Wdocumentation>)
139
140    target_link_options(${NAME}
141        PRIVATE
142            # Use pthreads on Linux/macOS
143            $<$<PLATFORM_ID:Linux,Darwin>:-pthread>)
144
145    if(${ASAN})
146        target_compile_options(${NAME}
147            PRIVATE
148                $<$<CXX_COMPILER_ID:${CLANG_LIKE}>:-fsanitize=address>)
149
150        target_link_options(${NAME}
151            PRIVATE
152                $<$<CXX_COMPILER_ID:${CLANG_LIKE}>:-fsanitize=address>)
153    endif()
154
155    if(${NO_INVARIANCE})
156            target_compile_definitions(${NAME}
157                PRIVATE
158                    ASTCENC_NO_INVARIANCE=1)
159    endif()
160
161    if(${CLI})
162        # Enable LTO on release builds
163        set_property(TARGET ${NAME}
164            PROPERTY
165                INTERPROCEDURAL_OPTIMIZATION_RELEASE True)
166
167        # Use a static runtime on MSVC builds (ignored on non-MSVC compilers)
168        set_property(TARGET ${NAME}
169            PROPERTY
170                MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
171    endif()
172
173    # Set up configuration for SIMD ISA builds
174    if(${ISA_SIMD} MATCHES "none")
175        if(NOT ${UNIVERSAL_BUILD})
176            target_compile_definitions(${NAME}
177                PRIVATE
178                    ASTCENC_NEON=0
179                    ASTCENC_SSE=0
180                    ASTCENC_AVX=0
181                    ASTCENC_POPCNT=0
182                    ASTCENC_F16C=0)
183        endif()
184
185    elseif(${ISA_SIMD} MATCHES "neon")
186        if(NOT ${UNIVERSAL_BUILD})
187            target_compile_definitions(${NAME}
188                PRIVATE
189                    ASTCENC_NEON=1
190                    ASTCENC_SSE=0
191                    ASTCENC_AVX=0
192                    ASTCENC_POPCNT=0
193                    ASTCENC_F16C=0)
194        endif()
195
196    elseif((${ISA_SIMD} MATCHES "sse2") OR (${UNIVERSAL_BUILD} AND ${ISA_SSE2}))
197        if(NOT ${UNIVERSAL_BUILD})
198            target_compile_definitions(${NAME}
199                PRIVATE
200                    ASTCENC_NEON=0
201                    ASTCENC_SSE=20
202                    ASTCENC_AVX=0
203                    ASTCENC_POPCNT=0
204                    ASTCENC_F16C=0)
205        endif()
206
207        # These settings are needed on AppleClang as SSE4.1 is on by default
208        # Suppress unused argument for macOS universal build behavior
209        target_compile_options(${NAME}
210            PRIVATE
211                $<$<CXX_COMPILER_ID:AppleClang>:-msse2>
212                $<$<CXX_COMPILER_ID:AppleClang>:-mno-sse4.1>
213                $<$<CXX_COMPILER_ID:AppleClang>:-Wno-unused-command-line-argument>)
214
215    elseif((${ISA_SIMD} MATCHES "sse4.1") OR (${UNIVERSAL_BUILD} AND ${ISA_SSE41}))
216        if(NOT ${UNIVERSAL_BUILD})
217            target_compile_definitions(${NAME}
218                PRIVATE
219                    ASTCENC_NEON=0
220                    ASTCENC_SSE=41
221                    ASTCENC_AVX=0
222                    ASTCENC_POPCNT=1
223                    ASTCENC_F16C=0)
224        endif()
225
226        # Suppress unused argument for macOS universal build behavior
227        target_compile_options(${NAME}
228            PRIVATE
229                $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-msse4.1 -mpopcnt>
230                $<$<CXX_COMPILER_ID:AppleClang>:-Wno-unused-command-line-argument>)
231
232    elseif((${ISA_SIMD} MATCHES "avx2") OR (${UNIVERSAL_BUILD} AND ${ISA_AVX2}))
233        if(NOT ${UNIVERSAL_BUILD})
234            target_compile_definitions(${NAME}
235                PRIVATE
236                    ASTCENC_NEON=0
237                    ASTCENC_SSE=41
238                    ASTCENC_AVX=2
239                    ASTCENC_POPCNT=1
240                    ASTCENC_F16C=1)
241        endif()
242
243        # Suppress unused argument for macOS universal build behavior
244        target_compile_options(${NAME}
245            PRIVATE
246                $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-mavx2 -mpopcnt -mf16c>
247                $<$<CXX_COMPILER_ID:MSVC>:/arch:AVX2>
248                $<$<CXX_COMPILER_ID:AppleClang>:-Wno-unused-command-line-argument>)
249
250    endif()
251
252endmacro()
253
254if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
255    string(CONCAT EXTERNAL_CXX_FLAGS
256            " $<$<NOT:$<CXX_COMPILER_ID:MSVC>>: -fno-strict-aliasing>"
257            " $<$<NOT:$<CXX_COMPILER_ID:MSVC>>: -Wno-unused-parameter>"
258            " $<$<NOT:$<CXX_COMPILER_ID:MSVC>>: -Wno-old-style-cast>"
259            " $<$<NOT:$<CXX_COMPILER_ID:MSVC>>: -Wno-double-promotion>"
260            " $<$<NOT:$<CXX_COMPILER_ID:MSVC>>: -Wno-zero-as-null-pointer-constant>"
261            " $<$<NOT:$<CXX_COMPILER_ID:MSVC>>: -Wno-disabled-macro-expansion>"
262            " $<$<NOT:$<CXX_COMPILER_ID:MSVC>>: -Wno-reserved-id-macro>"
263            " $<$<NOT:$<CXX_COMPILER_ID:MSVC>>: -Wno-extra-semi-stmt>"
264            " $<$<NOT:$<CXX_COMPILER_ID:MSVC>>: -Wno-implicit-fallthrough>"
265            " $<$<NOT:$<CXX_COMPILER_ID:MSVC>>: -Wno-tautological-type-limit-compare>"
266            " $<$<NOT:$<CXX_COMPILER_ID:MSVC>>: -Wno-cast-qual>"
267            " $<$<NOT:$<CXX_COMPILER_ID:MSVC>>: -Wno-reserved-identifier>"
268            " $<$<CXX_COMPILER_ID:Clang>: -Wno-missing-prototypes>"
269            " $<$<NOT:$<CXX_COMPILER_ID:MSVC>>: -Wno-suggest-override>"
270            " $<$<NOT:$<CXX_COMPILER_ID:MSVC>>: -Wno-used-but-marked-unused>"
271            " $<$<NOT:$<CXX_COMPILER_ID:MSVC>>: -Wno-noexcept-type>"
272            " $<$<NOT:$<CXX_COMPILER_ID:MSVC>>: -Wno-comma>"
273            " $<$<NOT:$<CXX_COMPILER_ID:MSVC>>: -Wno-c99-extensions>")
274
275    set_source_files_properties(astcenccli_image_external.cpp
276        PROPERTIES
277            COMPILE_FLAGS ${EXTERNAL_CXX_FLAGS})
278endif()
279
280astcenc_set_properties(${ASTC_TARGET}-static)
281
282if(${CLI})
283    astcenc_set_properties(${ASTC_TARGET})
284
285    string(TIMESTAMP astcencoder_YEAR "%Y")
286
287    configure_file(
288        astcenccli_version.h.in
289        astcenccli_version.h
290        ESCAPE_QUOTES @ONLY)
291
292    target_include_directories(${ASTC_TARGET}
293        PRIVATE
294            ${CMAKE_CURRENT_BINARY_DIR})
295
296    install(TARGETS ${ASTC_TARGET} DESTINATION ${PACKAGE_ROOT})
297endif()
298