1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-07-01 14:11:15 +02:00

build: never install cmocka

meson's default behavior is to install subprojects, so because we use a
wrap to get cmocka if needed and the cmocka wrap sets install=true
unless cross-compiling, cmocka headers and libraries will be installed
by `meson install`. This isn't useful (because cmocka is used only for
tests which don't get installed), and can cause install errors in some
configurations.

meson can be told to never install subprojects with `meson install
--skip-subprojects` which solves this, but is inconvenient because that
option must be specified on the command line and there is little hope of
meson's default behavior changing [1].

To fix this, I've replaced `patch_url` for the wrap with an included
`patch_directory` instead, which was created by unpacking the original
archive pointed to by `patch_url` and setting `install : false` in
src/meson.build.

A more concise option to make the same change would be to make the
change to the `install` option in a new patch specified via `diff_files`
(which works because patches from `diff_files` are applied after
applying the `patch_*` archive), but `diff_files` is not supported by
Meson before version 0.63.0 which would require increasing flashrom's
minimum meson version from the current 0.56.0. This seems too new, since
meson 0.56 was released in October 2020 while meson 0.63 was released in
July 2022.

[1]: https://github.com/mesonbuild/meson/issues/10561#issuecomment-1444059473

BUG=https://ticket.coreboot.org/issues/561

Change-Id: I15f549175e2d5d52979814d7f7530da868871ce8
Signed-off-by: Peter Marheine <pmarheine@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/84557
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
This commit is contained in:
Peter Marheine
2024-09-26 14:48:58 +10:00
committed by Anastasia Klimchuk
parent 84bfe0e04e
commit 6c26e9efed
6 changed files with 325 additions and 3 deletions

View File

@ -5,6 +5,4 @@ source_url = https://cmocka.org/files/1.1/cmocka-1.1.5.tar.xz
source_filename = cmocka-1.1.5.tar.xz source_filename = cmocka-1.1.5.tar.xz
source_hash = f0ccd8242d55e2fd74b16ba518359151f6f8383ff8aef4976e48393f77bba8b6 source_hash = f0ccd8242d55e2fd74b16ba518359151f6f8383ff8aef4976e48393f77bba8b6
patch_url = https://wrapdb.mesonbuild.com/v1/projects/cmocka/1.1.5/3/get_zip patch_directory = cmocka-1.1.5
patch_filename = cmocka-1.1.5-3-wrap.zip
patch_hash = 81ce48613680d3c3a0b396ac570c852b290adcd18202fb16aaf703a9493f4348

View File

@ -0,0 +1,19 @@
Copyright (c) 2018 The Meson development team
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,213 @@
# Copyright © 2018 Intel Corporation
#
# 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.
project(
'cmocka',
['c'],
version : '1.1.5',
license : 'APLv2',
meson_version : '>= 0.48.0',
default_options : ['c_std=c99', 'buildtype=debugoptimized'],
)
lib_version = '0.5.0'
# TODO: pkg-config
# TODO: cmake-config
inc_include = include_directories('include')
#####################
# Config Generation #
#####################
cc_dict = {
'compiler': meson.get_compiler('c'),
'machine': host_machine,
'config_h_subdir': 'private',
'native': false
}
cc_native_dict = {
'compiler': meson.get_compiler('c', native: true),
'machine': build_machine,
'config_h_subdir': 'private_native',
'native': true
}
configurations = [cc_dict, cc_native_dict]
foreach entry : configurations
compiler = entry.get('compiler')
is_native = entry.get('native')
machine = entry.get('machine')
config = configuration_data()
if ['gcc', 'clang'].contains(compiler.get_id())
add_project_arguments(
# I've explicitly skipped the duplicated -W versions when they also test
# for the -Werror version
compiler.get_supported_arguments(
'-Wshadow',
'-Wmissing-prototypes',
'-Wcast-align',
'-Werror=address',
'-Werror=strict-prototypes',
'-Werror=write-strings',
'-Werror=implicit-function-declaration',
'-Werror=pointer-arith',
'-Werror=declaration-after-statement',
'-Werror=return-type',
'-Werror=uninitialized',
'-Wimplicit-fallthrough',
'-Werror=strict-overflow',
'-Wstrict-overflow=2',
'-Wno-format-zero-length',
'-Wformat',
'-Werror=format-security',
'-Wno-gnu-zero-variadic-macro-arguments',
'-fno-common',
),
language : ['c'],
native: is_native
)
# We can't test the build type, so we can' add -D_FORTIFY_SOURCE=2 here
if machine.system() == 'darwin'
if compiler.has_argument('-Wno-deprecated-declarations')
add_project_arguments('-Wno-deprecated-declarations', language : ['c'], native: is_native)
endif
endif
elif compiler.get_id() == 'msvc'
add_project_arguments(
'/D_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1',
'/D_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT=1',
'/D_CRT_NONSTDC_NO_WARNINGS=1',
'/D_CRT_SECURE_NO_WARNINGS=1',
language : ['c'],
native: is_native
)
endif
# TODO: solaris extensions
foreach h : ['assert.h', 'inttypes.h', 'io.h', 'malloc.h', 'memory.h',
'setjmp.h', 'signal.h', 'stdarg.h', 'stddef.h', 'stdint.h',
'stdio.h', 'stdlib.h', 'string.h', 'strings.h', 'sys/stat.h',
'sys/types.h', 'time.h', 'unistd.h']
if compiler.check_header(h)
config.set('HAVE_@0@'.format(h.underscorify().to_upper()), 1)
endif
endforeach
if config.get('HAVE_TIME_H', 0) == 1
if compiler.has_member('struct timespec', 'tv_sec', prefix : '#include <time.h>')
config.set('HAVE_STRUCT_TIMESPEC', 1)
endif
endif
foreach f : ['calloc', 'exit', 'fprintf', 'free', 'longjmp', 'siglongjmp',
'malloc', 'memcpy', 'memset', 'printf', 'setjmp', 'signal',
'strsignal', 'strcmp', 'clock_gettime']
if compiler.has_function(f)
config.set('HAVE_@0@'.format(f.underscorify().to_upper()), 1)
endif
endforeach
if machine.system() == 'windows'
foreach f : ['_vsnprintf_s', '_vsnprtinf', '_snprintf_s', '_snprintf']
if compiler.has_function(f)
config.set('HAVE_@0@'.format(f.underscorify().to_upper()), 1)
endif
endforeach
foreach f : ['snprintf', 'vsnprintf']
if compiler.has_header_symbol('stdio.h', f)
config.set('HAVE_@0@'.format(f.underscorify().to_upper()), 1)
endif
endforeach
else
foreach f : ['snprintf', 'vsnprintf']
if compiler.has_function(f)
config.set('HAVE_@0@'.format(f.underscorify().to_upper()), 1)
endif
endforeach
endif
if machine.system() == 'windows'
if compiler.compiles('''
__declspec(thread) int tls;
int main(void) {
return 0;
}''',
name : 'Thread Local Storage')
config.set('HAVE_MSVC_THREAD_LOCAL_STORAGE', 1)
endif
else
if compiler.compiles('''
__thread int tls;
int main(void) {
return 0;
}''',
name : 'Thread Local Storage')
config.set('HAVE_GCC_THREAD_LOCAL_STORAGE', 1)
endif
endif
if (config.get('HAVE_TIME_H', 0) == 1 and
config.get('HAVE_STRUCT_TIMESPEC', 0) == 1 and
config.get('HAVE_CLOCK_GETTIME', 0) == 1)
if compiler.has_header_symbol('time.h', 'CLOCK_REALTIME')
config.set('HAVE_CLOCK_REALTIME', 1)
endif
endif
config.set('WORDS_SIZEOF_VOID_P', compiler.sizeof('void *'))
if machine.endian() == 'big'
config.set('WORDS_BIGENDIAN', 1)
endif
# Execute subdir to create config.h for this pass
# This requires the use of the variable named "config" for configuration_data(),
# as this variable is used in each configuration header subdirectory.
subdir(entry.get('config_h_subdir'))
endforeach
###########################
# Subdirectory Processing #
###########################
subdir('src')
######################
# Dependency Targets #
######################
# TODO: doc, include, tests, example
# Since we're using this as a wrap, and it's a unit test framework we're not
# going to install it.
cmocka_dep = declare_dependency(
link_with : libcmocka,
include_directories : inc_include,
version : meson.project_version(),
)
cmocka_native_dep = declare_dependency(
link_with : libcmocka_native,
include_directories : inc_include,
version : meson.project_version(),
)

View File

@ -0,0 +1,23 @@
# Copyright © 2018 Intel Corporation
#
# 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.
## This file sets the config.h header for standard builds (e.g., not native: true)
config_h = configure_file(
configuration : config,
output : 'config.h',
)
inc_private = include_directories('.')

View File

@ -0,0 +1,23 @@
# Copyright © 2018 Intel Corporation
#
# 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.
## This file sets the config.h header for standard builds (e.g., not native: true)
config_h_native = configure_file(
configuration : config,
output : 'config.h',
)
inc_private_native = include_directories('.')

View File

@ -0,0 +1,46 @@
# Copyright © 2018 Intel Corporation
#
# 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.
# cmocka rather annoyingly uses different standards for different platforms.
_overrides = []
if host_machine.system() != 'windows'
_overrides += 'c_std=gnu99'
endif
libcmocka = library(
'cmocka',
['cmocka.c'],
c_args : '-DHAVE_CONFIG_H=1',
include_directories : [inc_include, inc_private],
vs_module_defs : 'cmocka.def',
soversion : host_machine.system() != 'windows' ? lib_version.split('.')[0] : '',
version : lib_version,
install : false,
override_options : _overrides,
build_by_default: false,
)
libcmocka_native = library(
'cmocka_native',
['cmocka.c'],
c_args : '-DHAVE_CONFIG_H=1',
include_directories : [inc_include, inc_private_native],
vs_module_defs : 'cmocka.def',
soversion : build_machine.system() != 'windows' ? lib_version.split('.')[0] : '',
version : lib_version,
install : false, # Cannot install native targets in cross builds
override_options : _overrides,
native: true,
build_by_default: false,
)