new file mode 100644
@@ -0,0 +1,13 @@
+#
+# Copyright OpenEmbedded Contributors
+#
+# SPDX-License-Identifier: MIT
+#
+
+SUMMARY = "A C++ example compiled with cmake and clang."
+
+require cmake-example.inc
+
+TOOLCHAIN = "clang"
+EX_BINARY_NAME = "${BPN}"
+EX_SERVICE_USER = "cmake-example"
@@ -4,22 +4,8 @@
# SPDX-License-Identifier: MIT
#
-SUMMARY = "A C++ example compiled with cmake."
+SUMMARY = "A C++ example compiled with cmake and GCC."
-require cpp-example.inc
+require cmake-example.inc
-SRC_URI += "file://CMakeLists.txt"
-
-inherit cmake-qemu
-
-PACKAGECONFIG[failing_test] = "-DFAILING_TEST=ON"
-
-FILES:${PN}-ptest += "${bindir}/test-cmake-example"
-
-do_run_tests () {
- bbnote ${DESTDIR:+DESTDIR=${DESTDIR} }${CMAKE_VERBOSE} cmake --build '${B}' --target test -- ${EXTRA_OECMAKE_BUILD}
- eval ${DESTDIR:+DESTDIR=${DESTDIR} }${CMAKE_VERBOSE} cmake --build '${B}' --target test -- ${EXTRA_OECMAKE_BUILD}
-}
-do_run_tests[doc] = "Run cmake --target=test using qemu-user"
-
-addtask do_run_tests after do_compile
+TOOLCHAIN = "gcc"
new file mode 100644
@@ -0,0 +1,29 @@
+#
+# Copyright OpenEmbedded Contributors
+#
+# SPDX-License-Identifier: MIT
+#
+
+require cpp-example.inc
+
+SRC_URI += "file://CMakeLists.txt"
+
+inherit cmake-qemu
+
+PACKAGECONFIG[failing_test] = "-DFAILING_TEST=ON"
+
+# Support installing all recipe variants in parallel
+EXTRA_OECMAKE += "\
+ -DBINARY_NAME=${EX_BINARY_NAME} \
+ -DTEST_BINARY_NAME=${EX_TEST_BINARY_NAME} \
+"
+
+FILES:${PN}-ptest += "${bindir}/${EX_TEST_BINARY_NAME}"
+
+do_run_tests () {
+ bbnote ${DESTDIR:+DESTDIR=${DESTDIR} }${CMAKE_VERBOSE} cmake --build '${B}' --target test -- ${EXTRA_OECMAKE_BUILD}
+ eval ${DESTDIR:+DESTDIR=${DESTDIR} }${CMAKE_VERBOSE} cmake --build '${B}' --target test -- ${EXTRA_OECMAKE_BUILD}
+}
+do_run_tests[doc] = "Run cmake --target=test using qemu-user"
+
+addtask do_run_tests after do_compile
deleted file mode 100644
@@ -1,10 +0,0 @@
-#!/bin/sh
-#
-# Copyright OpenEmbedded Contributors
-#
-# SPDX-License-Identifier: MIT
-#
-
-test-cmake-example
-
-# Note: run-ptests exits with exit value from test-cmake-example
@@ -35,10 +35,16 @@ INITSCRIPT_PARAMS = "defaults 99"
# Create cpp-example user and group
USERADD_PACKAGES = "${PN}"
-GROUPADD_PARAM:${PN} = "--system ${BPN}"
-USERADD_PARAM:${PN} = "--system --home /var/lib/${BPN} --no-create-home --shell /bin/false --gid ${BPN} ${BPN}"
+GROUPADD_PARAM:${PN} = "--system ${EX_SERVICE_USER}"
+USERADD_PARAM:${PN} = "--system --home /var/lib/${EX_SERVICE_USER} --no-create-home --shell /bin/false --gid ${EX_SERVICE_USER} ${EX_SERVICE_USER}"
+EX_SERVICE_USER ?= "${BPN}"
EX_BINARY_NAME ?= "${BPN}"
+EX_TEST_BINARY_NAME ?= "test-${EX_BINARY_NAME}"
+
+do_install_ptest() {
+ sed -i -e 's|@TEST_BINARY_NAME@|${EX_TEST_BINARY_NAME}|g' ${D}${PTEST_PATH}/run-ptest
+}
do_install:append() {
# Install configuration file owned by the recipe's unprivileged user.
@@ -47,7 +53,7 @@ do_install:append() {
# in the final image. devtool deploy-target is a raw file copy and does not run
# pkg_postinst, so the UID in ${D} must already be correct.
install -d ${D}${sysconfdir}
- install -m 0644 -g ${BPN} -o ${BPN} ${S}/cpp-example.conf ${D}${sysconfdir}/${BPN}.conf
+ install -m 0644 -g ${EX_SERVICE_USER} -o ${EX_SERVICE_USER} ${S}/cpp-example.conf ${D}${sysconfdir}/${BPN}.conf
sed -i -e 's|@BINARY_NAME@|${BPN}|g' ${D}${sysconfdir}/${BPN}.conf
# Install service files or init scripts and substitute placeholders in service files
@@ -57,8 +63,8 @@ do_install:append() {
sed -i \
-e 's|@BINDIR@|${bindir}|g' \
-e 's|@BINARY_NAME@|${EX_BINARY_NAME}|g' \
- -e 's|@USER@|${BPN}|g' \
- -e 's|@GROUP@|${BPN}|g' \
+ -e 's|@USER@|${EX_SERVICE_USER}|g' \
+ -e 's|@GROUP@|${EX_SERVICE_USER}|g' \
${D}${systemd_system_unitdir}/${BPN}.service
else
install -d ${D}${sysconfdir}/init.d
@@ -66,8 +72,8 @@ do_install:append() {
sed -i \
-e 's|@BINDIR@|${bindir}|g' \
-e 's|@BINARY_NAME@|${EX_BINARY_NAME}|g' \
- -e 's|@USER@|${BPN}|g' \
- -e 's|@GROUP@|${BPN}|g' \
+ -e 's|@USER@|${EX_SERVICE_USER}|g' \
+ -e 's|@GROUP@|${EX_SERVICE_USER}|g' \
${D}${sysconfdir}/init.d/${BPN}
fi
}
@@ -14,6 +14,9 @@ project(cmake-example
option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
option(FAILING_TEST "Compile a failing unit test to test the test infrastructure" OFF)
+set(BINARY_NAME "cmake-example" CACHE STRING "Name of the installed executable and library prefix")
+set(TEST_BINARY_NAME "test-cmake-example" CACHE STRING "Name of the installed test executable")
+
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED On)
set(CMAKE_CXX_EXTENSIONS Off)
@@ -21,7 +24,7 @@ set(CMAKE_CXX_EXTENSIONS Off)
include(GNUInstallDirs)
# Define the config file path as a constant
-set(CPP_EXAMPLE_CONFIG_PATH "${CMAKE_INSTALL_FULL_SYSCONFDIR}/cmake-example.conf")
+set(CPP_EXAMPLE_CONFIG_PATH "${CMAKE_INSTALL_FULL_SYSCONFDIR}/${BINARY_NAME}.conf")
# Generate config.h from config.h.in
configure_file(config.h.in config.h @ONLY)
@@ -30,44 +33,44 @@ configure_file(config.h.in config.h @ONLY)
find_package(json-c)
# A simple library linking json-c library found by pkgconfig
-add_library(cmake-example-lib cpp-example-lib.cpp cpp-example-lib.hpp)
-set_target_properties(cmake-example-lib PROPERTIES
+add_library(${BINARY_NAME}-lib cpp-example-lib.cpp cpp-example-lib.hpp)
+set_target_properties(${BINARY_NAME}-lib PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
)
# Add the build directory to include path for config.h
-target_include_directories(cmake-example-lib PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
+target_include_directories(${BINARY_NAME}-lib PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
-target_link_libraries(cmake-example-lib PRIVATE json-c::json-c)
+target_link_libraries(${BINARY_NAME}-lib PRIVATE json-c::json-c)
-install(TARGETS cmake-example-lib
+install(TARGETS ${BINARY_NAME}-lib
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
# A simple executable linking the library
-add_executable(cmake-example cpp-example.cpp)
-target_include_directories(cmake-example PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
-target_link_libraries(cmake-example PRIVATE cmake-example-lib)
+add_executable(${BINARY_NAME} cpp-example.cpp)
+target_include_directories(${BINARY_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
+target_link_libraries(${BINARY_NAME} PRIVATE ${BINARY_NAME}-lib)
-install(TARGETS cmake-example
+install(TARGETS ${BINARY_NAME}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
# A simple test executable for testing the library
-add_executable(test-cmake-example test-cpp-example.cpp)
-target_include_directories(test-cmake-example PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
-target_link_libraries(test-cmake-example PRIVATE cmake-example-lib)
+add_executable(${TEST_BINARY_NAME} test-cpp-example.cpp)
+target_include_directories(${TEST_BINARY_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
+target_link_libraries(${TEST_BINARY_NAME} PRIVATE ${BINARY_NAME}-lib)
if (FAILING_TEST)
- target_compile_definitions(test-cmake-example PRIVATE FAIL_COMPARISON_STR="foo")
+ target_compile_definitions(${TEST_BINARY_NAME} PRIVATE FAIL_COMPARISON_STR="foo")
endif(FAILING_TEST)
-install(TARGETS test-cmake-example
+install(TARGETS ${TEST_BINARY_NAME}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
include(CTest)
-add_test(NAME test-cmake-example COMMAND test-cmake-example)
+add_test(NAME ${TEST_BINARY_NAME} COMMAND ${TEST_BINARY_NAME})
@@ -16,8 +16,11 @@ if get_option('FAILING_TEST').enabled()
add_project_arguments('-DFAIL_COMPARISON_STR=foo', language: 'cpp')
endif
+binary_name = get_option('BINARY_NAME')
+test_binary_name = get_option('TEST_BINARY_NAME')
+
# Generate config.h from config.h.in
-config_path = get_option('sysconfdir') / 'meson-example.conf'
+config_path = get_option('sysconfdir') / get_option('CONFIG_FILE_NAME')
conf_data = configuration_data()
conf_data.set('CPP_EXAMPLE_CONFIG_PATH', config_path)
configure_file(input : 'config.h.in',
@@ -27,7 +30,7 @@ configure_file(input : 'config.h.in',
# Include the build directory for config.h
inc_dir = include_directories('.')
-mesonexlib = shared_library('mesonexlib',
+exlib = shared_library(binary_name + 'lib',
'cpp-example-lib.cpp', 'cpp-example-lib.hpp',
version: meson.project_version(),
soversion: meson.project_version().split('.')[0],
@@ -36,18 +39,18 @@ mesonexlib = shared_library('mesonexlib',
install : true
)
-executable('mesonex',
+executable(binary_name,
'cpp-example.cpp',
- link_with : mesonexlib,
+ link_with : exlib,
include_directories : inc_dir,
install : true
)
-test_mesonex = executable('test-mesonex',
+test_exe = executable(test_binary_name,
'test-cpp-example.cpp',
- link_with : mesonexlib,
+ link_with : exlib,
include_directories : inc_dir,
install : true
)
-test('meson example test', test_mesonex)
+test('meson example test', test_exe)
@@ -1,3 +1,9 @@
option('FAILING_TEST', type : 'feature', value : 'disabled',
description : 'Compile a failing unit test to test the test infrastructure')
+option('BINARY_NAME', type : 'string', value : 'mesonex',
+ description : 'Name of the installed executable')
+option('TEST_BINARY_NAME', type : 'string', value : 'test-mesonex',
+ description : 'Name of the installed test executable')
+option('CONFIG_FILE_NAME', type : 'string', value : 'meson-example.conf',
+ description : 'Configuration file name in sysconfdir')
similarity index 51%
rename from meta-selftest/recipes-test/cpp/meson-example/run-ptest
rename to meta-selftest/recipes-test/cpp/files/run-ptest
@@ -5,6 +5,6 @@
# SPDX-License-Identifier: MIT
#
-test-mesonex
+@TEST_BINARY_NAME@
-# Note: run-ptests exits with exit value from test-mesonex
+# Note: run-ptest exits with exit value from @TEST_BINARY_NAME@
new file mode 100644
@@ -0,0 +1,13 @@
+#
+# Copyright OpenEmbedded Contributors
+#
+# SPDX-License-Identifier: MIT
+#
+
+SUMMARY = "A C++ example compiled with meson and clang."
+
+require meson-example.inc
+
+TOOLCHAIN = "clang"
+EX_BINARY_NAME = "mesonex-clang"
+EX_SERVICE_USER = "meson-example"
@@ -4,26 +4,8 @@
# SPDX-License-Identifier: MIT
#
-SUMMARY = "A C++ example compiled with meson."
+SUMMARY = "A C++ example compiled with meson and GCC."
-require cpp-example.inc
+require meson-example.inc
-SRC_URI += "\
- file://meson.build \
- file://meson.options \
-"
-
-inherit pkgconfig meson
-
-PACKAGECONFIG[failing_test] = "-DFAILING_TEST=enabled"
-
-FILES:${PN}-ptest += "${bindir}/test-mesonex"
-
-do_run_tests () {
- meson test -C "${B}" --no-rebuild
-}
-do_run_tests[doc] = "Run meson test using qemu-user"
-
-addtask do_run_tests after do_compile
-
-EX_BINARY_NAME = "mesonex"
+TOOLCHAIN = "gcc"
new file mode 100644
@@ -0,0 +1,36 @@
+#
+# Copyright OpenEmbedded Contributors
+#
+# SPDX-License-Identifier: MIT
+#
+
+SUMMARY = "A C++ example compiled with meson."
+
+require cpp-example.inc
+
+SRC_URI += "\
+ file://meson.build \
+ file://meson.options \
+"
+
+inherit pkgconfig meson
+
+PACKAGECONFIG[failing_test] = "-DFAILING_TEST=enabled"
+
+# Support installing all recipes variants in parallel
+EXTRA_OEMESON += "\
+ -DBINARY_NAME=${EX_BINARY_NAME} \
+ -DTEST_BINARY_NAME=${EX_TEST_BINARY_NAME} \
+ -DCONFIG_FILE_NAME=${BPN}.conf \
+"
+
+FILES:${PN}-ptest += "${bindir}/${EX_TEST_BINARY_NAME}"
+
+do_run_tests () {
+ meson test -C "${B}" --no-rebuild
+}
+do_run_tests[doc] = "Run meson test using qemu-user"
+
+addtask do_run_tests after do_compile
+
+EX_BINARY_NAME = "mesonex"