From 8ea6912c9607dab0a30c9bbf518dfc80df68a10c Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sun, 29 Sep 2019 14:24:09 +0300 Subject: libcamera: controls: Auto-generate control_ids.h and control_ids.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bring back auto-generation of control ids. In this version, both the header and the source files are generated from a single YAML file that stores all control definitions. This allows centralising controls in a single file, while the previous version required keeping both declarations (in a header) and documentation (in a the source) in sync manually. Using YAML as a format to store control definitions is a trade-off between ease of use (there are many YAML parsers available) and simplicity (XML was considered, but would have lead to more complex processing). A new build time dependency is added on python3-yaml, which should be available as a package in all distributions and build environments. The YAML format is likely to change over time as we improve documentation of controls, the first version simply copies the information currently available. Future improvements should also include a YAML schema to validate the YAML source file. Signed-off-by: Laurent Pinchart Reviewed-by: Niklas Söderlund --- include/libcamera/control_ids.h | 39 -------------------------------------- include/libcamera/control_ids.h.in | 31 ++++++++++++++++++++++++++++++ include/libcamera/gen-header.sh | 2 +- include/libcamera/meson.build | 18 ++++++++++++++---- 4 files changed, 46 insertions(+), 44 deletions(-) delete mode 100644 include/libcamera/control_ids.h create mode 100644 include/libcamera/control_ids.h.in (limited to 'include') diff --git a/include/libcamera/control_ids.h b/include/libcamera/control_ids.h deleted file mode 100644 index 54235f1a..00000000 --- a/include/libcamera/control_ids.h +++ /dev/null @@ -1,39 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ -/* - * Copyright (C) 2019, Google Inc. - * - * control_ids.h : Control ID list - */ - -#ifndef __LIBCAMERA_CONTROL_IDS_H__ -#define __LIBCAMERA_CONTROL_IDS_H__ - -#include - -#include - -namespace libcamera { - -namespace controls { - -enum { - AWB_ENABLE = 1, - BRIGHTNESS = 2, - CONTRAST = 3, - SATURATION = 4, - MANUAL_EXPOSURE = 5, - MANUAL_GAIN = 6, -}; - -extern const Control AwbEnable; -extern const Control Brightness; -extern const Control Contrast; -extern const Control Saturation; -extern const Control ManualExposure; -extern const Control ManualGain; - -} /* namespace controls */ - -} /* namespace libcamera */ - -#endif // __LIBCAMERA_CONTROL_IDS_H__ diff --git a/include/libcamera/control_ids.h.in b/include/libcamera/control_ids.h.in new file mode 100644 index 00000000..1d0bc791 --- /dev/null +++ b/include/libcamera/control_ids.h.in @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2019, Google Inc. + * + * control_ids.h : Control ID list + * + * This file is auto-generated. Do not edit. + */ + +#ifndef __LIBCAMERA_CONTROL_IDS_H__ +#define __LIBCAMERA_CONTROL_IDS_H__ + +#include + +#include + +namespace libcamera { + +namespace controls { + +enum { +${ids} +}; + +${controls} + +} /* namespace controls */ + +} /* namespace libcamera */ + +#endif // __LIBCAMERA_CONTROL_IDS_H__ diff --git a/include/libcamera/gen-header.sh b/include/libcamera/gen-header.sh index a69fe8e9..7f7816c9 100755 --- a/include/libcamera/gen-header.sh +++ b/include/libcamera/gen-header.sh @@ -19,7 +19,7 @@ EOF headers=$(for header in "$src_dir"/*.h ; do header=$(basename "$header") echo "$header" -done ; echo "version.h" | sort) +done ; echo "control_ids.h" ; echo "version.h" | sort) for header in $headers ; do echo "#include " >> "$dst_file" diff --git a/include/libcamera/meson.build b/include/libcamera/meson.build index 868f1a6b..4ffbdab3 100644 --- a/include/libcamera/meson.build +++ b/include/libcamera/meson.build @@ -3,7 +3,6 @@ libcamera_api = files([ 'buffer.h', 'camera.h', 'camera_manager.h', - 'control_ids.h', 'controls.h', 'event_dispatcher.h', 'event_notifier.h', @@ -18,6 +17,20 @@ libcamera_api = files([ include_dir = join_paths(libcamera_include_dir, 'libcamera') +install_headers(libcamera_api, + subdir : include_dir) + +gen_controls = files('../../src/libcamera/gen-controls.py') + +control_ids_h = custom_target('control_ids_h', + input : files('../../src/libcamera/control_ids.yaml', 'control_ids.h.in'), + output : 'control_ids.h', + depend_files : gen_controls, + command : [gen_controls, '-o', '@OUTPUT@', '@INPUT@'], + install_dir : join_paths('include', include_dir)) + +libcamera_api += control_ids_h + gen_header = files('gen-header.sh') libcamera_h = custom_target('gen-header', @@ -37,6 +50,3 @@ configure_file(input : 'version.h.in', output : 'version.h', configuration : libcamera_version_config, install_dir : join_paths('include', include_dir)) - -install_headers(libcamera_api, - subdir : include_dir) -- cgit v1.2.1