[libcamera-devel,SimpleCam] cmake: Provide a sample CMakeLists.txt
diff mbox series

Message ID 20220809121044.2039635-1-kieran.bingham@ideasonboard.com
State Superseded
Headers show
Series
  • [libcamera-devel,SimpleCam] cmake: Provide a sample CMakeLists.txt
Related show

Commit Message

Kieran Bingham Aug. 9, 2022, 12:10 p.m. UTC
While libcamera uses meson as its build infrastructure, applications are
free to use other make systems. CMake is widely used, so add an example
CMakeLists.txt to support building simple-cam and linking against
libcamera using cmake.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
 CMakeLists.txt | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100644 CMakeLists.txt

Comments

Laurent Pinchart Aug. 9, 2022, 1 p.m. UTC | #1
Hi Kieran,

Thank you for the patch.

On Tue, Aug 09, 2022 at 01:10:44PM +0100, Kieran Bingham via libcamera-devel wrote:
> While libcamera uses meson as its build infrastructure, applications are
> free to use other make systems. CMake is widely used, so add an example
> CMakeLists.txt to support building simple-cam and linking against
> libcamera using cmake.
> 
> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> ---
>  CMakeLists.txt | 32 ++++++++++++++++++++++++++++++++
>  1 file changed, 32 insertions(+)
>  create mode 100644 CMakeLists.txt
> 
> diff --git a/CMakeLists.txt b/CMakeLists.txt
> new file mode 100644
> index 000000000000..fc8e734bdf59
> --- /dev/null
> +++ b/CMakeLists.txt
> @@ -0,0 +1,32 @@
> +cmake_minimum_required(VERSION 3.6)
> +
> +project(SimpleCam
> +	VERSION 1.0

Should meson.build also set version to 1.0 ?

> +	DESCRIPTION "A small and documented example application for libcamera"
> +	LANGUAGES CXX)
> +
> +#set (CMAKE_EXPORT_COMPILE_COMMANDS ON)

Should this line be dropped ? If you want to keep it as an example, I
would add a comment before it.

> +set (CMAKE_CXX_STANDARD 17)
> +
> +find_package(PkgConfig)
> +
> +pkg_check_modules(LIBCAMERA REQUIRED IMPORTED_TARGET libcamera)
> +message(STATUS "libcamera library found:")
> +message(STATUS "    version: ${LIBCAMERA_VERSION}")
> +message(STATUS "    libraries: ${LIBCAMERA_LINK_LIBRARIES}")
> +message(STATUS "    include path: ${LIBCAMERA_INCLUDE_DIRS}")
> +
> +# libevent is used specifically by simple-cam as it's event loop.

s/it's/its/

> +# Applications may use a different event handling implementation.
> +pkg_check_modules(LIBEVENT REQUIRED IMPORTED_TARGET libevent_pthreads)
> +message(STATUS "libevent_pthreads library found:")
> +message(STATUS "    version: ${LIBEVENT_VERSION}")
> +message(STATUS "    libraries: ${LIBEVENT_LINK_LIBRARIES}")
> +message(STATUS "    include path: ${LIBEVENT_INCLUDE_DIRS}")
> +
> +include_directories(${CMAKE_SOURCE_DIR} ${LIBCAMERA_INCLUDE_DIRS} ${LIBEVENT_INCLUDE_DIRS})
> +
> +add_executable(simple-cam simple-cam.cpp event_loop.cpp)
> +
> +target_link_libraries(simple-cam PkgConfig::LIBEVENT)
> +target_link_libraries(simple-cam PkgConfig::LIBCAMERA)

Could you also add the following compiler flags to match what we do in
meson.build ?

-Wall
-Winvalid-pch
-Wnon-virtual-dtor
-Wextra
-Werror
-Wno-unused-parameter
Kieran Bingham Aug. 9, 2022, 1:28 p.m. UTC | #2
Quoting Laurent Pinchart (2022-08-09 14:00:38)
> Hi Kieran,
> 
> Thank you for the patch.
> 
> On Tue, Aug 09, 2022 at 01:10:44PM +0100, Kieran Bingham via libcamera-devel wrote:
> > While libcamera uses meson as its build infrastructure, applications are
> > free to use other make systems. CMake is widely used, so add an example
> > CMakeLists.txt to support building simple-cam and linking against
> > libcamera using cmake.
> > 
> > Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
> > ---
> >  CMakeLists.txt | 32 ++++++++++++++++++++++++++++++++
> >  1 file changed, 32 insertions(+)
> >  create mode 100644 CMakeLists.txt
> > 
> > diff --git a/CMakeLists.txt b/CMakeLists.txt
> > new file mode 100644
> > index 000000000000..fc8e734bdf59
> > --- /dev/null
> > +++ b/CMakeLists.txt
> > @@ -0,0 +1,32 @@
> > +cmake_minimum_required(VERSION 3.6)
> > +
> > +project(SimpleCam
> > +     VERSION 1.0
> 
> Should meson.build also set version to 1.0 ?

I don't think I care about it ;-)

I think I can drop the statement.

> > +     DESCRIPTION "A small and documented example application for libcamera"
> > +     LANGUAGES CXX)
> > +
> > +#set (CMAKE_EXPORT_COMPILE_COMMANDS ON)
> 
> Should this line be dropped ? If you want to keep it as an example, I
> would add a comment before it.

Yes, this is just a leftover.

> > +set (CMAKE_CXX_STANDARD 17)
> > +
> > +find_package(PkgConfig)
> > +
> > +pkg_check_modules(LIBCAMERA REQUIRED IMPORTED_TARGET libcamera)
> > +message(STATUS "libcamera library found:")
> > +message(STATUS "    version: ${LIBCAMERA_VERSION}")
> > +message(STATUS "    libraries: ${LIBCAMERA_LINK_LIBRARIES}")
> > +message(STATUS "    include path: ${LIBCAMERA_INCLUDE_DIRS}")
> > +
> > +# libevent is used specifically by simple-cam as it's event loop.
> 
> s/it's/its/
> 
> > +# Applications may use a different event handling implementation.
> > +pkg_check_modules(LIBEVENT REQUIRED IMPORTED_TARGET libevent_pthreads)
> > +message(STATUS "libevent_pthreads library found:")
> > +message(STATUS "    version: ${LIBEVENT_VERSION}")
> > +message(STATUS "    libraries: ${LIBEVENT_LINK_LIBRARIES}")
> > +message(STATUS "    include path: ${LIBEVENT_INCLUDE_DIRS}")
> > +
> > +include_directories(${CMAKE_SOURCE_DIR} ${LIBCAMERA_INCLUDE_DIRS} ${LIBEVENT_INCLUDE_DIRS})
> > +
> > +add_executable(simple-cam simple-cam.cpp event_loop.cpp)
> > +
> > +target_link_libraries(simple-cam PkgConfig::LIBEVENT)
> > +target_link_libraries(simple-cam PkgConfig::LIBCAMERA)
> 
> Could you also add the following compiler flags to match what we do in
> meson.build ?

Yes, I'll figure out how to add it.

> 
> -Wall
> -Winvalid-pch
> -Wnon-virtual-dtor
> -Wextra
> -Werror
> -Wno-unused-parameter
> 
> -- 
> Regards,
> 
> Laurent Pinchart

Patch
diff mbox series

diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 000000000000..fc8e734bdf59
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,32 @@ 
+cmake_minimum_required(VERSION 3.6)
+
+project(SimpleCam
+	VERSION 1.0
+	DESCRIPTION "A small and documented example application for libcamera"
+	LANGUAGES CXX)
+
+#set (CMAKE_EXPORT_COMPILE_COMMANDS ON)
+set (CMAKE_CXX_STANDARD 17)
+
+find_package(PkgConfig)
+
+pkg_check_modules(LIBCAMERA REQUIRED IMPORTED_TARGET libcamera)
+message(STATUS "libcamera library found:")
+message(STATUS "    version: ${LIBCAMERA_VERSION}")
+message(STATUS "    libraries: ${LIBCAMERA_LINK_LIBRARIES}")
+message(STATUS "    include path: ${LIBCAMERA_INCLUDE_DIRS}")
+
+# libevent is used specifically by simple-cam as it's event loop.
+# Applications may use a different event handling implementation.
+pkg_check_modules(LIBEVENT REQUIRED IMPORTED_TARGET libevent_pthreads)
+message(STATUS "libevent_pthreads library found:")
+message(STATUS "    version: ${LIBEVENT_VERSION}")
+message(STATUS "    libraries: ${LIBEVENT_LINK_LIBRARIES}")
+message(STATUS "    include path: ${LIBEVENT_INCLUDE_DIRS}")
+
+include_directories(${CMAKE_SOURCE_DIR} ${LIBCAMERA_INCLUDE_DIRS} ${LIBEVENT_INCLUDE_DIRS})
+
+add_executable(simple-cam simple-cam.cpp event_loop.cpp)
+
+target_link_libraries(simple-cam PkgConfig::LIBEVENT)
+target_link_libraries(simple-cam PkgConfig::LIBCAMERA)