meson.build revision a156c6bd
1# Copyright © 2018 Intel Corporation 2 3# Permission is hereby granted, free of charge, to any person obtaining a copy 4# of this software and associated documentation files (the "Software"), to deal 5# in the Software without restriction, including without limitation the rights 6# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7# copies of the Software, and to permit persons to whom the Software is 8# furnished to do so, subject to the following conditions: 9 10# The above copyright notice and this permission notice shall be included in 11# all copies or substantial portions of the Software. 12 13# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19# SOFTWARE. 20 21project( 22 'pixman', 23 ['c'], 24 version : '0.42.2', 25 license : 'MIT', 26 meson_version : '>= 0.52.0', 27 default_options : ['c_std=gnu99', 'buildtype=debugoptimized'], 28) 29 30config = configuration_data() 31cc = meson.get_compiler('c') 32null_dep = dependency('', required : false) 33 34add_project_arguments( 35 cc.get_supported_arguments([ 36 '-Wdeclaration-after-statement', 37 '-fno-strict-aliasing', 38 '-fvisibility=hidden', 39 '-Wundef', 40 # -ftrapping-math is the default for gcc, but -fno-trapping-math is the 41 # default for clang. The FLOAT_IS_ZERO macro is used to guard against 42 # floating-point exceptions, however with -fno-trapping-math, the compiler 43 # can reorder floating-point operations so that they occur before the guard. 44 # Note, this function is ignored in clang < 10.0.0. 45 '-ftrapping-math' 46 ]), 47 language : ['c'] 48) 49 50# GCC and Clang both ignore -Wno options that they don't recognize, so test for 51# -W<opt>, then add -Wno-<opt> if it's ignored 52foreach opt : ['unused-local-typedefs'] 53 if cc.has_argument('-W' + opt) 54 add_project_arguments(['-Wno-' + opt], language : ['c']) 55 endif 56endforeach 57 58use_loongson_mmi = get_option('loongson-mmi') 59have_loongson_mmi = false 60loongson_mmi_flags = ['-mloongson-mmi'] 61if not use_loongson_mmi.disabled() 62 if host_machine.cpu_family() == 'mips64' and cc.compiles(''' 63 #ifndef __mips_loongson_vector_rev 64 #error "Loongson Multimedia Instructions are only available on Loongson" 65 #endif 66 #if defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 4)) 67 #error "Need GCC >= 4.4 for Loongson MMI compilation" 68 #endif 69 #include "pixman/loongson-mmintrin.h" 70 int main () { 71 union { 72 __m64 v; 73 char c[8]; 74 } a = { .c = {1, 2, 3, 4, 5, 6, 7, 8} }; 75 int b = 4; 76 __m64 c = _mm_srli_pi16 (a.v, b); 77 return 0; 78 }''', 79 args : loongson_mmi_flags, 80 include_directories : include_directories('.'), 81 name : 'Loongson MMI Intrinsic Support') 82 have_loongson_mmi = true 83 endif 84endif 85 86if have_loongson_mmi 87 config.set10('USE_LOONGSON_MMI', true) 88elif use_loongson_mmi.enabled() 89 error('Loongson MMI Support unavailable, but required') 90endif 91 92use_mmx = get_option('mmx') 93have_mmx = false 94mmx_flags = [] 95 96if cc.get_id() == 'msvc' 97 mmx_flags = ['/w14710', '/w14714', '/wd4244'] 98elif cc.get_id() == 'sun' 99 mmx_flags = ['-xarch=sse'] 100else 101 mmx_flags = ['-mmmx', '-Winline'] 102endif 103if not use_mmx.disabled() 104 if host_machine.cpu_family() == 'x86_64' or cc.get_id() == 'msvc' 105 have_mmx = true 106 elif host_machine.cpu_family() == 'x86' and cc.compiles(''' 107 #include <mmintrin.h> 108 #include <stdint.h> 109 110 /* Check support for block expressions */ 111 #define _mm_shuffle_pi16(A, N) \ 112 ({ \ 113 __m64 ret; \ 114 \ 115 /* Some versions of clang will choke on K */ \ 116 asm ("pshufw %2, %1, %0\n\t" \ 117 : "=y" (ret) \ 118 : "y" (A), "K" ((const int8_t)N) \ 119 ); \ 120 \ 121 ret; \ 122 }) 123 124 int main () { 125 __m64 v = _mm_cvtsi32_si64 (1); 126 __m64 w; 127 128 w = _mm_shuffle_pi16(v, 5); 129 130 /* Some versions of clang will choke on this */ 131 asm ("pmulhuw %1, %0\n\t" 132 : "+y" (w) 133 : "y" (v) 134 ); 135 136 return _mm_cvtsi64_si32 (v); 137 }''', 138 args : mmx_flags, 139 name : 'MMX Intrinsic Support') 140 have_mmx = true 141 endif 142endif 143 144if have_mmx 145 # Inline assembly do not work on X64 MSVC, so we use 146 # compatibility intrinsics there 147 if cc.get_id() != 'msvc' or host_machine.cpu_family() != 'x86_64' 148 config.set10('USE_X86_MMX', true) 149 endif 150elif use_mmx.enabled() 151 error('MMX Support unavailable, but required') 152endif 153 154use_sse2 = get_option('sse2') 155have_sse2 = false 156sse2_flags = [] 157if cc.get_id() == 'sun' 158 sse2_flags = ['-xarch=sse2'] 159elif cc.get_id() != 'msvc' 160 sse2_flags = ['-msse2', '-Winline'] 161endif 162if not use_sse2.disabled() 163 if host_machine.cpu_family() == 'x86' 164 if cc.compiles(''' 165 #if defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2)) 166 # if !defined(__amd64__) && !defined(__x86_64__) 167 # error "Need GCC >= 4.2 for SSE2 intrinsics on x86" 168 # endif 169 #endif 170 #include <mmintrin.h> 171 #include <xmmintrin.h> 172 #include <emmintrin.h> 173 int param; 174 int main () { 175 __m128i a = _mm_set1_epi32 (param), b = _mm_set1_epi32 (param + 1), c; 176 c = _mm_xor_si128 (a, b); 177 return _mm_cvtsi128_si32(c); 178 }''', 179 args : sse2_flags, 180 name : 'SSE2 Intrinsic Support') 181 have_sse2 = true 182 endif 183 elif host_machine.cpu_family() == 'x86_64' 184 have_sse2 = true 185 endif 186endif 187 188if have_sse2 189 config.set10('USE_SSE2', true) 190elif use_sse2.enabled() 191 error('sse2 Support unavailable, but required') 192endif 193 194use_ssse3 = get_option('ssse3') 195have_ssse3 = false 196ssse3_flags = [] 197if cc.get_id() != 'msvc' 198 ssse3_flags = ['-mssse3', '-Winline'] 199endif 200 201# x64 pre-2010 MSVC compilers crashes when building the ssse3 code 202if not use_ssse3.disabled() and not (cc.get_id() == 'msvc' and cc.version().version_compare('<16') and host_machine.cpu_family() == 'x86_64') 203 if host_machine.cpu_family().startswith('x86') 204 if cc.compiles(''' 205 #include <mmintrin.h> 206 #include <xmmintrin.h> 207 #include <emmintrin.h> 208 int param; 209 int main () { 210 __m128i a = _mm_set1_epi32 (param), b = _mm_set1_epi32 (param + 1), c; 211 c = _mm_xor_si128 (a, b); 212 return _mm_cvtsi128_si32(c); 213 }''', 214 args : ssse3_flags, 215 name : 'SSSE3 Intrinsic Support') 216 have_ssse3 = true 217 endif 218 endif 219endif 220 221if have_ssse3 222 config.set10('USE_SSSE3', true) 223elif use_ssse3.enabled() 224 error('ssse3 Support unavailable, but required') 225endif 226 227use_vmx = get_option('vmx') 228have_vmx = false 229vmx_flags = ['-maltivec', '-mabi=altivec'] 230if not use_vmx.disabled() 231 if host_machine.cpu_family().startswith('ppc') 232 if cc.compiles(''' 233 #include <altivec.h> 234 int main () { 235 vector unsigned int v = vec_splat_u32 (1); 236 v = vec_sub (v, v); 237 return 0; 238 }''', 239 args : vmx_flags, 240 name : 'VMX/Altivec Intrinsic Support') 241 have_vmx = true 242 endif 243 endif 244endif 245 246if have_vmx 247 config.set10('USE_VMX', true) 248elif use_vmx.enabled() 249 error('vmx Support unavailable, but required') 250endif 251 252use_armv6_simd = get_option('arm-simd') 253have_armv6_simd = false 254if not use_armv6_simd.disabled() 255 if host_machine.cpu_family() == 'arm' 256 if cc.compiles(files('arm-simd-test.S'), name : 'ARMv6 SIMD Intrinsic Support') 257 have_armv6_simd = true 258 endif 259 endif 260endif 261 262if have_armv6_simd 263 config.set10('USE_ARM_SIMD', true) 264elif use_armv6_simd.enabled() 265 error('ARMv6 SIMD Support unavailable, but required') 266endif 267 268use_neon = get_option('neon') 269have_neon = false 270if not use_neon.disabled() 271 if host_machine.cpu_family() == 'arm' 272 if cc.compiles(files('neon-test.S'), name : 'NEON Intrinsic Support') 273 have_neon = true 274 endif 275 endif 276endif 277 278if have_neon 279 config.set10('USE_ARM_NEON', true) 280elif use_neon.enabled() 281 error('NEON Support unavailable, but required') 282endif 283 284use_a64neon = get_option('a64-neon') 285have_a64neon = false 286if not use_a64neon.disabled() 287 if host_machine.cpu_family() == 'aarch64' 288 if cc.compiles(files('a64-neon-test.S'), name : 'NEON A64 Intrinsic Support') 289 have_a64neon = true 290 endif 291 endif 292endif 293 294if have_a64neon 295 config.set10('USE_ARM_A64_NEON', true) 296elif use_a64neon.enabled() 297 error('A64 NEON Support unavailable, but required') 298endif 299 300use_iwmmxt = get_option('iwmmxt') 301have_iwmmxt = false 302iwmmxt_flags = ['-flax-vector-conversions', '-Winline'] 303if not use_iwmmxt.disabled() 304 if get_option('iwmmxt2') 305 iwmmxt_flags += '-march=iwmmxt2' 306 else 307 iwmmxt_flags += '-march=iwmmxt' 308 endif 309 310 if host_machine.cpu_family() == 'arm' 311 if cc.compiles(''' 312 #ifndef __IWMMXT__ 313 #error "IWMMXT not enabled (with -march=iwmmxt)" 314 #endif 315 #if defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8)) 316 #error "Need GCC >= 4.8 for IWMMXT intrinsics" 317 #endif 318 #include <mmintrin.h> 319 int main () { 320 union { 321 __m64 v; 322 char c[8]; 323 } a = { .c = {1, 2, 3, 4, 5, 6, 7, 8} }; 324 int b = 4; 325 __m64 c = _mm_srli_si64 (a.v, b); 326 } 327 ''', 328 args : iwmmxt_flags, 329 name : 'IWMMXT Intrinsic Support') 330 have_iwmmxt = true 331 endif 332 endif 333endif 334 335if have_iwmmxt 336 config.set10('USE_ARM_IWMMXT', true) 337elif use_iwmmxt.enabled() 338 error('IWMMXT Support unavailable, but required') 339endif 340 341use_mips_dspr2 = get_option('mips-dspr2') 342have_mips_dspr2 = false 343mips_dspr2_flags = ['-mdspr2'] 344if not use_mips_dspr2.disabled() 345 if host_machine.cpu_family() == 'mips32' 346 if cc.compiles(''' 347 #if !(defined(__mips__) && __mips_isa_rev >= 2) 348 #error MIPS DSPr2 is currently only available on MIPS32r2 platforms. 349 #endif 350 int 351 main () 352 { 353 int c = 0, a = 0, b = 0; 354 __asm__ __volatile__ ( 355 "precr.qb.ph %[c], %[a], %[b] \n\t" 356 : [c] "=r" (c) 357 : [a] "r" (a), [b] "r" (b) 358 ); 359 return c; 360 }''', 361 args : mipds_dspr2_flags, 362 name : 'DSPr2 Intrinsic Support') 363 have_mips_dspr2 = true 364 endif 365 endif 366endif 367 368if have_mips_dspr2 369 config.set10('USE_MIPS_DSPR2', true) 370elif use_mips_dspr2.enabled() 371 error('MIPS DSPr2 Support unavailable, but required') 372endif 373 374use_gnu_asm = get_option('gnu-inline-asm') 375if not use_gnu_asm.disabled() 376 if cc.compiles(''' 377 int main () { 378 /* Most modern architectures have a NOP instruction, so this is a fairly generic test. */ 379 asm volatile ( "\tnop\n" : : : "cc", "memory" ); 380 return 0; 381 } 382 ''', 383 name : 'GNU Inline ASM support.') 384 config.set10('USE_GCC_INLINE_ASM', true) 385 elif use_gnu_asm.enabled() 386 error('GNU inline assembly support missing but required.') 387 endif 388endif 389 390if get_option('timers') 391 config.set('PIXMAN_TIMERS', 1) 392endif 393if get_option('gnuplot') 394 config.set('PIXMAN_GNUPLOT', 1) 395endif 396 397if cc.get_id() != 'msvc' 398 dep_openmp = dependency('openmp', required : get_option('openmp')) 399 if dep_openmp.found() 400 config.set10('USE_OPENMP', true) 401 elif meson.version().version_compare('<0.51.0') 402 # In versions of meson before 0.51 the openmp dependency can still 403 # inject arguments in the the auto case when it is not found, the 404 # detection does work correctly in that case however, so we just 405 # replace dep_openmp with null_dep to work around this. 406 dep_openmp = null_dep 407 endif 408else 409 # the MSVC implementation of openmp is not compliant enough for our 410 # uses here, so we disable it here. 411 # Please see: https://stackoverflow.com/questions/12560243/using-threadprivate-directive-in-visual-studio 412 dep_openmp = null_dep 413endif 414 415dep_gtk = dependency('gtk+-3.0', required : get_option('gtk')) 416dep_glib = dependency('glib-2.0', required : get_option('gtk')) 417 418dep_png = null_dep 419if not get_option('libpng').disabled() 420 dep_png = dependency('libpng', required : false) 421 422 # We need to look for the right library to link to for libpng, 423 # when looking for libpng manually 424 foreach png_ver : [ '16', '15', '14', '13', '12', '10' ] 425 if not dep_png.found() 426 dep_png = cc.find_library('libpng@0@'.format(png_ver), has_headers : ['png.h'], required : false) 427 endif 428 endforeach 429 430 if get_option('libpng').enabled() and not dep_png.found() 431 error('libpng support requested but libpng library not found') 432 endif 433endif 434 435if dep_png.found() 436 config.set('HAVE_LIBPNG', 1) 437endif 438dep_m = cc.find_library('m', required : false) 439dep_threads = dependency('threads') 440 441# MSVC-style compilers do not come with pthreads, so we must link 442# to it explicitly, currently pthreads-win32 is supported 443pthreads_found = false 444 445if dep_threads.found() and cc.has_header('pthread.h') 446 if cc.get_argument_syntax() == 'msvc' 447 pthread_lib = null_dep 448 foreach pthread_type : ['VC3', 'VSE3', 'VCE3', 'VC2', 'VSE2', 'VCE2'] 449 if not pthread_lib.found() 450 pthread_lib = cc.find_library('pthread@0@'.format(pthread_type), required : false) 451 endif 452 endforeach 453 if pthread_lib.found() 454 pthreads_found = true 455 dep_threads = pthread_lib 456 endif 457 else 458 pthreads_found = true 459 endif 460endif 461 462if pthreads_found 463 config.set('HAVE_PTHREADS', 1) 464endif 465 466funcs = ['sigaction', 'alarm', 'mprotect', 'getpagesize', 'mmap', 'getisax', 'gettimeofday'] 467# mingw claimes to have posix_memalign, but it doesn't 468if host_machine.system() != 'windows' 469 funcs += 'posix_memalign' 470endif 471 472foreach f : funcs 473 if cc.has_function(f) 474 config.set('HAVE_@0@'.format(f.to_upper()), 1) 475 endif 476endforeach 477 478# This is only used in one test, that defines _GNU_SOURCE 479if cc.has_function('feenableexcept', 480 prefix : '#define _GNU_SOURCE\n#include <fenv.h>', 481 dependencies : dep_m) 482 config.set('HAVE_FEENABLEEXCEPT', 1) 483endif 484 485if cc.has_header_symbol('fenv.h', 'FE_DIVBYZERO') 486 config.set('HAVE_FEDIVBYZERO', 1) 487endif 488 489foreach h : ['sys/mman.h', 'fenv.h', 'unistd.h'] 490 if cc.check_header(h) 491 config.set('HAVE_@0@'.format(h.underscorify().to_upper()), 1) 492 endif 493endforeach 494 495use_tls = get_option('tls') 496have_tls = '' 497if not use_tls.disabled() 498 # gcc on Windows only warns that __declspec(thread) isn't supported, 499 # passing -Werror=attributes makes it fail. 500 if (host_machine.system() == 'windows' and 501 cc.compiles('int __declspec(thread) foo;', 502 args : cc.get_supported_arguments(['-Werror=attributes']), 503 name : 'TLS via __declspec(thread)')) 504 have_tls = '__declspec(thread)' 505 elif cc.compiles('int __thread foo;', name : 'TLS via __thread') 506 have_tls = '__thread' 507 endif 508endif 509 510if have_tls != '' 511 config.set('TLS', have_tls) 512elif use_tls.enabled() 513 error('Compiler TLS Support unavailable, but required') 514endif 515 516if cc.links(''' 517 static int x = 1; 518 static void __attribute__((constructor)) constructor_function () { x = 0; } 519 int main (void) { return x; } 520 ''', 521 name : '__attribute__((constructor))') 522 config.set('TOOLCHAIN_SUPPORTS_ATTRIBUTE_CONSTRUCTOR', 1) 523endif 524 525if cc.links( 526 ' __float128 a = 1.0Q, b = 2.0Q; int main (void) { return a + b; }', 527 name : 'Has float128 support') 528 config.set('HAVE_FLOAT128', 1) 529endif 530 531if cc.has_function('clz') 532 config.set('HAVE_BUILTIN_CLZ', 1) 533endif 534 535if cc.links(''' 536 unsigned int __attribute__ ((vector_size(16))) e, a, b; 537 int main (void) { e = a - ((b << 27) + (b >> (32 - 27))) + 1; return e[0]; } 538 ''', 539 name : 'Support for GCC vector extensions') 540 config.set('HAVE_GCC_VECTOR_EXTENSIONS', 1) 541endif 542 543if host_machine.endian() == 'big' 544 config.set('WORDS_BIGENDIAN', 1) 545endif 546 547config.set('SIZEOF_LONG', cc.sizeof('long')) 548 549# Required to make pixman-private.h 550config.set('PACKAGE', 'foo') 551 552version_conf = configuration_data() 553split = meson.project_version().split('.') 554version_conf.set('PIXMAN_VERSION_MAJOR', split[0]) 555version_conf.set('PIXMAN_VERSION_MINOR', split[1]) 556version_conf.set('PIXMAN_VERSION_MICRO', split[2]) 557 558add_project_arguments('-DHAVE_CONFIG_H', language : ['c']) 559 560subdir('pixman') 561 562if not get_option('tests').disabled() 563 subdir('test') 564 subdir('demos') 565endif 566 567pkg = import('pkgconfig') 568pkg.generate(libpixman, 569 name : 'Pixman', 570 filebase : 'pixman-1', 571 description : 'The pixman library (version 1)', 572 subdirs: 'pixman-1', 573 version : meson.project_version(), 574) 575