[libcamera-devel] [PATCH v1 6/6] apps: Shared common source between applications
Laurent Pinchart
laurent.pinchart at ideasonboard.com
Thu Oct 20 01:15:37 CEST 2022
Multiple source files in the src/apps/cam/ directory are used by cam,
qcam and lc-compliance. They are compiled separately for each
application. Move them to the src/apps/ directory and compile them in a
static library to decrease the number of compilation operations.
Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
---
src/apps/cam/camera_session.cpp | 5 +++--
src/apps/cam/camera_session.h | 2 +-
src/apps/cam/drm.cpp | 2 +-
src/apps/cam/file_sink.cpp | 5 +++--
src/apps/cam/main.cpp | 7 ++++---
src/apps/cam/meson.build | 14 ++------------
src/apps/cam/sdl_sink.cpp | 5 +++--
src/apps/cam/sdl_texture.h | 2 +-
src/apps/{cam => }/dng_writer.cpp | 0
src/apps/{cam => }/dng_writer.h | 0
src/apps/{cam => }/event_loop.cpp | 0
src/apps/{cam => }/event_loop.h | 0
src/apps/{cam => }/image.cpp | 0
src/apps/{cam => }/image.h | 0
src/apps/lc-compliance/main.cpp | 2 +-
src/apps/lc-compliance/meson.build | 3 +--
src/apps/lc-compliance/simple_capture.h | 2 +-
src/apps/meson.build | 25 +++++++++++++++++++++++++
src/apps/{cam => }/options.cpp | 0
src/apps/{cam => }/options.h | 0
src/apps/qcam/format_converter.cpp | 2 +-
src/apps/qcam/main.cpp | 4 ++--
src/apps/qcam/main_window.cpp | 4 ++--
src/apps/qcam/main_window.h | 2 +-
src/apps/qcam/meson.build | 13 ++-----------
src/apps/qcam/viewfinder_gl.cpp | 2 +-
src/apps/qcam/viewfinder_qt.cpp | 2 +-
src/apps/{cam => }/stream_options.cpp | 0
src/apps/{cam => }/stream_options.h | 0
29 files changed, 56 insertions(+), 47 deletions(-)
rename src/apps/{cam => }/dng_writer.cpp (100%)
rename src/apps/{cam => }/dng_writer.h (100%)
rename src/apps/{cam => }/event_loop.cpp (100%)
rename src/apps/{cam => }/event_loop.h (100%)
rename src/apps/{cam => }/image.cpp (100%)
rename src/apps/{cam => }/image.h (100%)
rename src/apps/{cam => }/options.cpp (100%)
rename src/apps/{cam => }/options.h (100%)
rename src/apps/{cam => }/stream_options.cpp (100%)
rename src/apps/{cam => }/stream_options.h (100%)
diff --git a/src/apps/cam/camera_session.cpp b/src/apps/cam/camera_session.cpp
index 6b409c983b86..c581410e4dec 100644
--- a/src/apps/cam/camera_session.cpp
+++ b/src/apps/cam/camera_session.cpp
@@ -13,9 +13,11 @@
#include <libcamera/control_ids.h>
#include <libcamera/property_ids.h>
+#include "../event_loop.h"
+#include "../stream_options.h"
+
#include "camera_session.h"
#include "capture_script.h"
-#include "event_loop.h"
#include "file_sink.h"
#ifdef HAVE_KMS
#include "kms_sink.h"
@@ -24,7 +26,6 @@
#ifdef HAVE_SDL
#include "sdl_sink.h"
#endif
-#include "stream_options.h"
using namespace libcamera;
diff --git a/src/apps/cam/camera_session.h b/src/apps/cam/camera_session.h
index d562caae0794..46748d5c98ac 100644
--- a/src/apps/cam/camera_session.h
+++ b/src/apps/cam/camera_session.h
@@ -21,7 +21,7 @@
#include <libcamera/request.h>
#include <libcamera/stream.h>
-#include "options.h"
+#include "../options.h"
class CaptureScript;
class FrameSink;
diff --git a/src/apps/cam/drm.cpp b/src/apps/cam/drm.cpp
index 2e4d7985245d..3ad33175fdd3 100644
--- a/src/apps/cam/drm.cpp
+++ b/src/apps/cam/drm.cpp
@@ -24,7 +24,7 @@
#include <libdrm/drm_mode.h>
-#include "event_loop.h"
+#include "../event_loop.h"
namespace DRM {
diff --git a/src/apps/cam/file_sink.cpp b/src/apps/cam/file_sink.cpp
index 9d60c04e1cf4..dc109af729fe 100644
--- a/src/apps/cam/file_sink.cpp
+++ b/src/apps/cam/file_sink.cpp
@@ -15,9 +15,10 @@
#include <libcamera/camera.h>
-#include "dng_writer.h"
+#include "../dng_writer.h"
+#include "../image.h"
+
#include "file_sink.h"
-#include "image.h"
using namespace libcamera;
diff --git a/src/apps/cam/main.cpp b/src/apps/cam/main.cpp
index d70130e2ab81..85a678f86819 100644
--- a/src/apps/cam/main.cpp
+++ b/src/apps/cam/main.cpp
@@ -14,11 +14,12 @@
#include <libcamera/libcamera.h>
#include <libcamera/property_ids.h>
+#include "../event_loop.h"
+#include "../options.h"
+#include "../stream_options.h"
+
#include "camera_session.h"
-#include "event_loop.h"
#include "main.h"
-#include "options.h"
-#include "stream_options.h"
using namespace libcamera;
diff --git a/src/apps/cam/meson.build b/src/apps/cam/meson.build
index 297de64fbdd9..48c834ace71b 100644
--- a/src/apps/cam/meson.build
+++ b/src/apps/cam/meson.build
@@ -10,16 +10,12 @@ cam_enabled = true
cam_sources = files([
'camera_session.cpp',
'capture_script.cpp',
- 'event_loop.cpp',
'file_sink.cpp',
'frame_sink.cpp',
- 'image.cpp',
'main.cpp',
- 'options.cpp',
- 'stream_options.cpp',
])
-cam_cpp_args = []
+cam_cpp_args = [apps_cpp_args]
libdrm = dependency('libdrm', required : false)
libjpeg = dependency('libjpeg', required : false)
@@ -49,14 +45,8 @@ if libsdl2.found()
endif
endif
-if libtiff.found()
- cam_cpp_args += ['-DHAVE_TIFF']
- cam_sources += files([
- 'dng_writer.cpp',
- ])
-endif
-
cam = executable('cam', cam_sources,
+ link_with : apps_lib,
dependencies : [
libatomic,
libcamera_public,
diff --git a/src/apps/cam/sdl_sink.cpp b/src/apps/cam/sdl_sink.cpp
index ee177227dbca..ec9dd1868332 100644
--- a/src/apps/cam/sdl_sink.cpp
+++ b/src/apps/cam/sdl_sink.cpp
@@ -19,8 +19,9 @@
#include <libcamera/camera.h>
#include <libcamera/formats.h>
-#include "event_loop.h"
-#include "image.h"
+#include "../event_loop.h"
+#include "../image.h"
+
#ifdef HAVE_LIBJPEG
#include "sdl_texture_mjpg.h"
#endif
diff --git a/src/apps/cam/sdl_texture.h b/src/apps/cam/sdl_texture.h
index 6ccd85eab390..6890f239ddd6 100644
--- a/src/apps/cam/sdl_texture.h
+++ b/src/apps/cam/sdl_texture.h
@@ -11,7 +11,7 @@
#include <SDL2/SDL.h>
-#include "image.h"
+#include "../image.h"
class SDLTexture
{
diff --git a/src/apps/cam/dng_writer.cpp b/src/apps/dng_writer.cpp
similarity index 100%
rename from src/apps/cam/dng_writer.cpp
rename to src/apps/dng_writer.cpp
diff --git a/src/apps/cam/dng_writer.h b/src/apps/dng_writer.h
similarity index 100%
rename from src/apps/cam/dng_writer.h
rename to src/apps/dng_writer.h
diff --git a/src/apps/cam/event_loop.cpp b/src/apps/event_loop.cpp
similarity index 100%
rename from src/apps/cam/event_loop.cpp
rename to src/apps/event_loop.cpp
diff --git a/src/apps/cam/event_loop.h b/src/apps/event_loop.h
similarity index 100%
rename from src/apps/cam/event_loop.h
rename to src/apps/event_loop.h
diff --git a/src/apps/cam/image.cpp b/src/apps/image.cpp
similarity index 100%
rename from src/apps/cam/image.cpp
rename to src/apps/image.cpp
diff --git a/src/apps/cam/image.h b/src/apps/image.h
similarity index 100%
rename from src/apps/cam/image.h
rename to src/apps/image.h
diff --git a/src/apps/lc-compliance/main.cpp b/src/apps/lc-compliance/main.cpp
index 7eb52ae4c094..2cc6b77fc78e 100644
--- a/src/apps/lc-compliance/main.cpp
+++ b/src/apps/lc-compliance/main.cpp
@@ -15,7 +15,7 @@
#include <libcamera/libcamera.h>
#include "environment.h"
-#include "../cam/options.h"
+#include "../options.h"
using namespace libcamera;
diff --git a/src/apps/lc-compliance/meson.build b/src/apps/lc-compliance/meson.build
index 05d622be0a40..51d9075ac30b 100644
--- a/src/apps/lc-compliance/meson.build
+++ b/src/apps/lc-compliance/meson.build
@@ -11,8 +11,6 @@ endif
lc_compliance_enabled = true
lc_compliance_sources = files([
- '../cam/event_loop.cpp',
- '../cam/options.cpp',
'environment.cpp',
'main.cpp',
'simple_capture.cpp',
@@ -21,6 +19,7 @@ lc_compliance_sources = files([
lc_compliance = executable('lc-compliance', lc_compliance_sources,
cpp_args : [ '-fexceptions' ],
+ link_with : apps_lib,
dependencies : [
libatomic,
libcamera_public,
diff --git a/src/apps/lc-compliance/simple_capture.h b/src/apps/lc-compliance/simple_capture.h
index 9d31f7cb2e53..5a64395d986c 100644
--- a/src/apps/lc-compliance/simple_capture.h
+++ b/src/apps/lc-compliance/simple_capture.h
@@ -11,7 +11,7 @@
#include <libcamera/libcamera.h>
-#include "../cam/event_loop.h"
+#include "../event_loop.h"
class SimpleCapture
{
diff --git a/src/apps/meson.build b/src/apps/meson.build
index 95f1f5190c7a..e1879806c99e 100644
--- a/src/apps/meson.build
+++ b/src/apps/meson.build
@@ -10,6 +10,31 @@ endif
libtiff = dependency('libtiff-4', required : false)
+apps_sources = files([
+ 'image.cpp',
+ 'options.cpp',
+ 'stream_options.cpp',
+])
+
+apps_cpp_args = []
+
+if libevent.found()
+ apps_sources += files([
+ 'event_loop.cpp',
+ ])
+endif
+
+if libtiff.found()
+ apps_cpp_args += ['-DHAVE_TIFF']
+ apps_sources += files([
+ 'dng_writer.cpp',
+ ])
+endif
+
+apps_lib = static_library('apps', apps_sources,
+ cpp_args : apps_cpp_args,
+ dependencies : [libcamera_public])
+
subdir('lc-compliance')
subdir('cam')
diff --git a/src/apps/cam/options.cpp b/src/apps/options.cpp
similarity index 100%
rename from src/apps/cam/options.cpp
rename to src/apps/options.cpp
diff --git a/src/apps/cam/options.h b/src/apps/options.h
similarity index 100%
rename from src/apps/cam/options.h
rename to src/apps/options.h
diff --git a/src/apps/qcam/format_converter.cpp b/src/apps/qcam/format_converter.cpp
index 9331da0ce7a3..0390e0184454 100644
--- a/src/apps/qcam/format_converter.cpp
+++ b/src/apps/qcam/format_converter.cpp
@@ -14,7 +14,7 @@
#include <libcamera/formats.h>
-#include "../cam/image.h"
+#include "../image.h"
#define RGBSHIFT 8
#ifndef MAX
diff --git a/src/apps/qcam/main.cpp b/src/apps/qcam/main.cpp
index d3f01a85f1fb..0373c78d53c8 100644
--- a/src/apps/qcam/main.cpp
+++ b/src/apps/qcam/main.cpp
@@ -13,8 +13,8 @@
#include <libcamera/camera_manager.h>
-#include "../cam/options.h"
-#include "../cam/stream_options.h"
+#include "../options.h"
+#include "../stream_options.h"
#include "main_window.h"
#include "message_handler.h"
diff --git a/src/apps/qcam/main_window.cpp b/src/apps/qcam/main_window.cpp
index f553ccb01805..a90e95d545e1 100644
--- a/src/apps/qcam/main_window.cpp
+++ b/src/apps/qcam/main_window.cpp
@@ -26,8 +26,8 @@
#include <QToolButton>
#include <QtDebug>
-#include "../cam/dng_writer.h"
-#include "../cam/image.h"
+#include "../dng_writer.h"
+#include "../image.h"
#include "cam_select_dialog.h"
#ifndef QT_NO_OPENGL
diff --git a/src/apps/qcam/main_window.h b/src/apps/qcam/main_window.h
index 95b64124336f..8d378a1ff768 100644
--- a/src/apps/qcam/main_window.h
+++ b/src/apps/qcam/main_window.h
@@ -27,7 +27,7 @@
#include <QQueue>
#include <QTimer>
-#include "../cam/stream_options.h"
+#include "../stream_options.h"
#include "viewfinder.h"
diff --git a/src/apps/qcam/meson.build b/src/apps/qcam/meson.build
index e298101e2c43..eb0712d91351 100644
--- a/src/apps/qcam/meson.build
+++ b/src/apps/qcam/meson.build
@@ -15,9 +15,6 @@ endif
qcam_enabled = true
qcam_sources = files([
- '../cam/image.cpp',
- '../cam/options.cpp',
- '../cam/stream_options.cpp',
'cam_select_dialog.cpp',
'format_converter.cpp',
'main.cpp',
@@ -36,14 +33,7 @@ qcam_resources = files([
'assets/feathericons/feathericons.qrc',
])
-qt5_cpp_args = ['-DQT_NO_KEYWORDS']
-
-if libtiff.found()
- qt5_cpp_args += ['-DHAVE_TIFF']
- qcam_sources += files([
- '../cam/dng_writer.cpp',
- ])
-endif
+qt5_cpp_args = [apps_cpp_args, '-DQT_NO_KEYWORDS']
if cxx.has_header_symbol('QOpenGLWidget', 'QOpenGLWidget',
dependencies : qt5_dep, args : '-fPIC')
@@ -73,6 +63,7 @@ resources = qt5.preprocess(moc_headers: qcam_moc_headers,
qcam = executable('qcam', qcam_sources, resources,
install : true,
+ link_with : apps_lib,
dependencies : [
libatomic,
libcamera_public,
diff --git a/src/apps/qcam/viewfinder_gl.cpp b/src/apps/qcam/viewfinder_gl.cpp
index 38ddad58e09e..7b791765734e 100644
--- a/src/apps/qcam/viewfinder_gl.cpp
+++ b/src/apps/qcam/viewfinder_gl.cpp
@@ -16,7 +16,7 @@
#include <libcamera/formats.h>
-#include "../cam/image.h"
+#include "../image.h"
static const QList<libcamera::PixelFormat> supportedFormats{
/* YUV - packed (single plane) */
diff --git a/src/apps/qcam/viewfinder_qt.cpp b/src/apps/qcam/viewfinder_qt.cpp
index c20fd6bc8fc2..e4efc587c759 100644
--- a/src/apps/qcam/viewfinder_qt.cpp
+++ b/src/apps/qcam/viewfinder_qt.cpp
@@ -20,7 +20,7 @@
#include <QPainter>
#include <QtDebug>
-#include "../cam/image.h"
+#include "../image.h"
#include "format_converter.h"
diff --git a/src/apps/cam/stream_options.cpp b/src/apps/stream_options.cpp
similarity index 100%
rename from src/apps/cam/stream_options.cpp
rename to src/apps/stream_options.cpp
diff --git a/src/apps/cam/stream_options.h b/src/apps/stream_options.h
similarity index 100%
rename from src/apps/cam/stream_options.h
rename to src/apps/stream_options.h
--
Regards,
Laurent Pinchart
More information about the libcamera-devel
mailing list