1# Copyright © 2018 Intel Corporation 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15project( 16 'cmocka', 17 ['c'], 18 version : '1.1.5', 19 license : 'APLv2', 20 meson_version : '>= 0.48.0', 21 default_options : ['c_std=c99', 'buildtype=debugoptimized'], 22) 23 24lib_version = '0.5.0' 25 26# TODO: pkg-config 27# TODO: cmake-config 28 29inc_include = include_directories('include') 30 31##################### 32# Config Generation # 33##################### 34 35cc_dict = { 36 'compiler': meson.get_compiler('c'), 37 'machine': host_machine, 38 'config_h_subdir': 'private', 39 'native': false 40} 41 42cc_native_dict = { 43 'compiler': meson.get_compiler('c', native: true), 44 'machine': build_machine, 45 'config_h_subdir': 'private_native', 46 'native': true 47} 48 49configurations = [cc_dict, cc_native_dict] 50 51foreach entry : configurations 52 compiler = entry.get('compiler') 53 is_native = entry.get('native') 54 machine = entry.get('machine') 55 56 config = configuration_data() 57 58 if ['gcc', 'clang'].contains(compiler.get_id()) 59 add_project_arguments( 60 # I've explicitly skipped the duplicated -W versions when they also test 61 # for the -Werror version 62 compiler.get_supported_arguments( 63 '-Wshadow', 64 '-Wmissing-prototypes', 65 '-Wcast-align', 66 '-Werror=address', 67 '-Werror=strict-prototypes', 68 '-Werror=write-strings', 69 '-Werror=implicit-function-declaration', 70 '-Werror=pointer-arith', 71 '-Werror=declaration-after-statement', 72 '-Werror=return-type', 73 '-Werror=uninitialized', 74 '-Wimplicit-fallthrough', 75 '-Werror=strict-overflow', 76 '-Wstrict-overflow=2', 77 '-Wno-format-zero-length', 78 '-Wformat', 79 '-Werror=format-security', 80 '-Wno-gnu-zero-variadic-macro-arguments', 81 '-fno-common', 82 ), 83 language : ['c'], 84 native: is_native 85 ) 86 # We can't test the build type, so we can' add -D_FORTIFY_SOURCE=2 here 87 if machine.system() == 'darwin' 88 if compiler.has_argument('-Wno-deprecated-declarations') 89 add_project_arguments('-Wno-deprecated-declarations', language : ['c'], native: is_native) 90 endif 91 endif 92 elif compiler.get_id() == 'msvc' 93 add_project_arguments( 94 '/D_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1', 95 '/D_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT=1', 96 '/D_CRT_NONSTDC_NO_WARNINGS=1', 97 '/D_CRT_SECURE_NO_WARNINGS=1', 98 language : ['c'], 99 native: is_native 100 ) 101 endif 102 103 # TODO: solaris extensions 104 105 foreach h : ['assert.h', 'inttypes.h', 'io.h', 'malloc.h', 'memory.h', 106 'setjmp.h', 'signal.h', 'stdarg.h', 'stddef.h', 'stdint.h', 107 'stdio.h', 'stdlib.h', 'string.h', 'strings.h', 'sys/stat.h', 108 'sys/types.h', 'time.h', 'unistd.h'] 109 if compiler.check_header(h) 110 config.set('HAVE_@0@'.format(h.underscorify().to_upper()), 1) 111 endif 112 endforeach 113 114 if config.get('HAVE_TIME_H', 0) == 1 115 if compiler.has_member('struct timespec', 'tv_sec', prefix : '#include <time.h>') 116 config.set('HAVE_STRUCT_TIMESPEC', 1) 117 endif 118 endif 119 120 foreach f : ['calloc', 'exit', 'fprintf', 'free', 'longjmp', 'siglongjmp', 121 'malloc', 'memcpy', 'memset', 'printf', 'setjmp', 'signal', 122 'strsignal', 'strcmp', 'clock_gettime'] 123 if compiler.has_function(f) 124 config.set('HAVE_@0@'.format(f.underscorify().to_upper()), 1) 125 endif 126 endforeach 127 128 if machine.system() == 'windows' 129 foreach f : ['_vsnprintf_s', '_vsnprtinf', '_snprintf_s', '_snprintf'] 130 if compiler.has_function(f) 131 config.set('HAVE_@0@'.format(f.underscorify().to_upper()), 1) 132 endif 133 endforeach 134 foreach f : ['snprintf', 'vsnprintf'] 135 if compiler.has_header_symbol('stdio.h', f) 136 config.set('HAVE_@0@'.format(f.underscorify().to_upper()), 1) 137 endif 138 endforeach 139else 140 foreach f : ['snprintf', 'vsnprintf'] 141 if compiler.has_function(f) 142 config.set('HAVE_@0@'.format(f.underscorify().to_upper()), 1) 143 endif 144 endforeach 145endif 146 147 if machine.system() == 'windows' 148 if compiler.compiles(''' 149 __declspec(thread) int tls; 150 151 int main(void) { 152 return 0; 153 }''', 154 name : 'Thread Local Storage') 155 config.set('HAVE_MSVC_THREAD_LOCAL_STORAGE', 1) 156 endif 157 else 158 if compiler.compiles(''' 159 __thread int tls; 160 161 int main(void) { 162 return 0; 163 }''', 164 name : 'Thread Local Storage') 165 config.set('HAVE_GCC_THREAD_LOCAL_STORAGE', 1) 166 endif 167 endif 168 169 if (config.get('HAVE_TIME_H', 0) == 1 and 170 config.get('HAVE_STRUCT_TIMESPEC', 0) == 1 and 171 config.get('HAVE_CLOCK_GETTIME', 0) == 1) 172 if compiler.has_header_symbol('time.h', 'CLOCK_REALTIME') 173 config.set('HAVE_CLOCK_REALTIME', 1) 174 endif 175 endif 176 177 config.set('WORDS_SIZEOF_VOID_P', compiler.sizeof('void *')) 178 if machine.endian() == 'big' 179 config.set('WORDS_BIGENDIAN', 1) 180 endif 181 182 # Execute subdir to create config.h for this pass 183 # This requires the use of the variable named "config" for configuration_data(), 184 # as this variable is used in each configuration header subdirectory. 185 subdir(entry.get('config_h_subdir')) 186 187endforeach 188 189########################### 190# Subdirectory Processing # 191########################### 192 193subdir('src') 194 195###################### 196# Dependency Targets # 197###################### 198 199# TODO: doc, include, tests, example 200# Since we're using this as a wrap, and it's a unit test framework we're not 201# going to install it. 202 203cmocka_dep = declare_dependency( 204 link_with : libcmocka, 205 include_directories : inc_include, 206 version : meson.project_version(), 207) 208 209cmocka_native_dep = declare_dependency( 210 link_with : libcmocka_native, 211 include_directories : inc_include, 212 version : meson.project_version(), 213) 214