diff options
Diffstat (limited to 'meta-selftest/recipes-test/cpp/files/CMakeLists.txt')
-rw-r--r-- | meta-selftest/recipes-test/cpp/files/CMakeLists.txt | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/meta-selftest/recipes-test/cpp/files/CMakeLists.txt b/meta-selftest/recipes-test/cpp/files/CMakeLists.txt new file mode 100644 index 0000000000..6fa6917d89 --- /dev/null +++ b/meta-selftest/recipes-test/cpp/files/CMakeLists.txt | |||
@@ -0,0 +1,61 @@ | |||
1 | # | ||
2 | # Copyright OpenEmbedded Contributors | ||
3 | # | ||
4 | # SPDX-License-Identifier: MIT | ||
5 | # | ||
6 | |||
7 | cmake_minimum_required(VERSION 3.22) | ||
8 | |||
9 | project(cmake-example | ||
10 | VERSION 1.0.0 | ||
11 | LANGUAGES CXX | ||
12 | ) | ||
13 | |||
14 | option(BUILD_SHARED_LIBS "Build using shared libraries" ON) | ||
15 | option(FAILING_TEST "Compile a failing unit test to test the test infrastructure" OFF) | ||
16 | |||
17 | set(CMAKE_CXX_STANDARD 17) | ||
18 | set(CMAKE_CXX_STANDARD_REQUIRED On) | ||
19 | set(CMAKE_CXX_EXTENSIONS Off) | ||
20 | |||
21 | include(GNUInstallDirs) | ||
22 | |||
23 | # Linking a small library makes the example more useful for testing. | ||
24 | find_package(json-c) | ||
25 | |||
26 | # A simple library linking json-c library found by pkgconfig | ||
27 | add_library(cmake-example-lib cpp-example-lib.cpp cpp-example-lib.hpp) | ||
28 | set_target_properties(cmake-example-lib PROPERTIES | ||
29 | VERSION ${PROJECT_VERSION} | ||
30 | SOVERSION ${PROJECT_VERSION_MAJOR} | ||
31 | ) | ||
32 | target_link_libraries(cmake-example-lib PRIVATE json-c::json-c) | ||
33 | |||
34 | install(TARGETS cmake-example-lib | ||
35 | INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} | ||
36 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
37 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
38 | ) | ||
39 | |||
40 | # A simple executable linking the library | ||
41 | add_executable(cmake-example cpp-example.cpp) | ||
42 | target_link_libraries(cmake-example PRIVATE cmake-example-lib) | ||
43 | |||
44 | install(TARGETS cmake-example | ||
45 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | ||
46 | ) | ||
47 | |||
48 | # A simple test executable for testing the library | ||
49 | add_executable(test-cmake-example test-cpp-example.cpp) | ||
50 | target_link_libraries(test-cmake-example PRIVATE cmake-example-lib) | ||
51 | |||
52 | if (FAILING_TEST) | ||
53 | target_compile_definitions(test-cmake-example PRIVATE FAIL_COMPARISON_STR="foo") | ||
54 | endif(FAILING_TEST) | ||
55 | |||
56 | install(TARGETS test-cmake-example | ||
57 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | ||
58 | ) | ||
59 | |||
60 | include(CTest) | ||
61 | add_test(NAME test-cmake-example COMMAND test-cmake-example) | ||