-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This simple C++ project supports compilation with cmake and with meson. It's supposed to be used with oe-selftest for the devtool ide plugin. Signed-off-by: Adrian Freihofer <[email protected]>
- Loading branch information
1 parent
4c5e2bf
commit 05453ed
Showing
12 changed files
with
241 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
build* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# | ||
# Copyright OpenEmbedded Contributors | ||
# | ||
# SPDX-License-Identifier: MIT | ||
# | ||
|
||
SUMMARY = "A C++ example compiled with cmake." | ||
|
||
inherit cmake | ||
|
||
require cpp-example.inc | ||
|
||
SRC_URI += "\ | ||
file://CMakeLists.txt \ | ||
" | ||
|
||
FILES:${PN}-ptest += "${bindir}/test-cmake-example" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/sh | ||
# | ||
# Copyright OpenEmbedded Contributors | ||
# | ||
# SPDX-License-Identifier: MIT | ||
# | ||
|
||
test-cmake-example | ||
|
||
# Note: run-ptests exits with exit value from test-cmake-example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# | ||
# Copyright OpenEmbedded Contributors | ||
# | ||
# SPDX-License-Identifier: MIT | ||
# | ||
|
||
LICENSE = "MIT" | ||
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" | ||
|
||
inherit ptest | ||
|
||
DEPENDS += "json-c" | ||
|
||
PV = "1.0" | ||
|
||
S = "${WORKDIR}" | ||
|
||
SRC_URI = "\ | ||
file://cpp-example.cpp \ | ||
file://cpp-example-lib.hpp \ | ||
file://cpp-example-lib.cpp \ | ||
file://test-cpp-example.cpp \ | ||
file://run-ptest \ | ||
" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# | ||
# Copyright OpenEmbedded Contributors | ||
# | ||
# SPDX-License-Identifier: MIT | ||
# | ||
|
||
cmake_minimum_required(VERSION 3.22) | ||
|
||
project(cmake-example | ||
VERSION 1.0.0 | ||
LANGUAGES CXX | ||
) | ||
|
||
option(BUILD_SHARED_LIBS "Build using shared libraries" ON) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED On) | ||
set(CMAKE_CXX_EXTENSIONS Off) | ||
|
||
include(GNUInstallDirs) | ||
|
||
# Find json-c | ||
# find_package(PkgConfig REQUIRED) | ||
# pkg_check_modules(JSONC REQUIRED json-c) | ||
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 | ||
VERSION ${PROJECT_VERSION} | ||
SOVERSION ${PROJECT_VERSION_MAJOR} | ||
) | ||
target_link_libraries(cmake-example-lib PRIVATE json-c::json-c) | ||
# target_link_libraries(cmake-example-lib ${JSONC_LIBRARIES}) | ||
# target_include_directories(cmake-example-lib PUBLIC ${JSONC_INCLUDE_DIRS}) | ||
# target_compile_options(cmake-example-lib PUBLIC ${JSONC_CFLAGS_OTHER}) | ||
install(TARGETS cmake-example-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_link_libraries(cmake-example PRIVATE cmake-example-lib) | ||
|
||
install(TARGETS cmake-example | ||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | ||
) | ||
|
||
# A simple test executable for testing the library | ||
add_executable(test-cmake-example test-cpp-example.cpp) | ||
target_link_libraries(test-cmake-example PRIVATE cmake-example-lib) | ||
|
||
install(TARGETS test-cmake-example | ||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | ||
) | ||
|
||
include(CTest) | ||
add_test(NAME test-cmake-example COMMAND test-cmake-example) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright OpenEmbedded Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#include <string> | ||
#include <json-c/json.h> | ||
#include "cpp-example-lib.hpp" | ||
|
||
const std::string& CppExample::get_string() { | ||
return test_string; | ||
} | ||
|
||
const char* CppExample::get_json_c_version() { | ||
return json_c_version(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright OpenEmbedded Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <string> | ||
|
||
struct CppExample { | ||
inline static const std::string test_string = "cpp-example-lib Magic: 123456789"; | ||
|
||
const std::string& get_string(); | ||
const char* get_json_c_version(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright OpenEmbedded Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#include "cpp-example-lib.hpp" | ||
|
||
#include <iostream> | ||
|
||
int main() { | ||
auto cpp_example = CppExample(); | ||
std::cout << "C++ example linking " << cpp_example.get_string() << std::endl; | ||
std::cout << "Linking json-c version " << cpp_example.get_json_c_version() << std::endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# | ||
# Copyright OpenEmbedded Contributors | ||
# | ||
# SPDX-License-Identifier: MIT | ||
# | ||
|
||
project('meson-example', 'cpp', | ||
version: '1.0.0', | ||
default_options: ['cpp_std=c++17'] | ||
) | ||
|
||
|
||
jsoncdep = dependency('json-c') | ||
|
||
mesonexlib = shared_library('mesonexlib', | ||
'cpp-example-lib.cpp', 'cpp-example-lib.hpp', | ||
version: meson.project_version(), | ||
soversion: meson.project_version().split('.')[0], | ||
dependencies : jsoncdep, | ||
install : true | ||
) | ||
|
||
executable('mesonex', | ||
'cpp-example.cpp', | ||
link_with : mesonexlib, | ||
install : true | ||
) | ||
|
||
test_mesonex = executable('test-mesonex', | ||
'test-cpp-example.cpp', | ||
link_with : mesonexlib, | ||
install : true | ||
) | ||
test('meson example test', test_mesonex) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright OpenEmbedded Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#include "cpp-example-lib.hpp" | ||
|
||
#include <iostream> | ||
|
||
int main() { | ||
auto cpp_example = CppExample(); | ||
auto ret_string = cpp_example.get_string(); | ||
if(0 == ret_string.compare(CppExample::test_string)) { | ||
std::cout << "PASS: " << ret_string << " = " << CppExample::test_string << std::endl; | ||
} else { | ||
std::cout << "FAIL: " << ret_string << " != " << CppExample::test_string << std::endl; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# | ||
# Copyright OpenEmbedded Contributors | ||
# | ||
# SPDX-License-Identifier: MIT | ||
# | ||
|
||
SUMMARY = "A C++ example compiled with meson." | ||
|
||
inherit pkgconfig meson | ||
|
||
require cpp-example.inc | ||
|
||
SRC_URI += "\ | ||
file://meson.build \ | ||
" | ||
|
||
FILES:${PN}-ptest += "${bindir}/test-mesonex" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/sh | ||
# | ||
# Copyright OpenEmbedded Contributors | ||
# | ||
# SPDX-License-Identifier: MIT | ||
# | ||
|
||
test-mesonex | ||
|
||
# Note: run-ptests exits with exit value from test-mesonex |