Skip to content

Commit c332564

Browse files
committed
cmake: Fix and test installation
Fix - Installation of cmake files targets lib/cmake/vatomic Added - Small project to test usage of installed cmake files with find_package. - Action in CI to install vatomic and test build the dependent project Signed-off-by: Diogo Behrens <[email protected]>
1 parent c3858a9 commit c332564

File tree

5 files changed

+64
-18
lines changed

5 files changed

+64
-18
lines changed

.github/workflows/actions.yml

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,25 @@ env:
44
REGISTRY: ghcr.io
55

66
jobs:
7+
test-install:
8+
strategy:
9+
matrix:
10+
os: [ubuntu-22.04, ubuntu-22.04-arm, macos-latest]
11+
runs-on: ${{ matrix.os }}
12+
steps:
13+
- uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
- name: Configure vatomic
17+
run: cmake -S. -Bbuild -DCMAKE_INSTALL_PREFIX=/tmp/target
18+
- name: Install library
19+
run: cmake --install build
20+
21+
- name: Configure test project
22+
run: cmake -Stest/project -Bbuild2 -DCMAKE_PREFIX_PATH=/tmp/target
23+
- name: Build test project
24+
run: cmake --build build2
25+
726
test-native:
827
strategy:
928
matrix:
@@ -14,7 +33,7 @@ jobs:
1433
with:
1534
fetch-depth: 0
1635
- name: Configure Testing
17-
run: cmake -S. -Bbuild ${{ matrix.config }}
36+
run: cmake -S. -Bbuild
1837
- name: Build Tests
1938
run: cmake --build build
2039
- name: Run Tests
@@ -26,17 +45,22 @@ jobs:
2645
- uses: actions/checkout@v4
2746
with:
2847
fetch-depth: 0
29-
- name: Configure and Build
48+
- name: Configure, Build, Install
3049
id: test
3150
uses: vmactions/netbsd-vm@v1
3251
with:
3352
release: "10.1"
3453
usesh: true
3554
prepare: /usr/sbin/pkg_add curl cmake
3655
run: |
56+
rm -rf /tmp/target
3757
cmake -S. -Bbuild
38-
cmake --build build
58+
cmake --build build -DCMAKE_INSTALL_PREFIX=/tmp/target
3959
ctest --test-dir build --output-on-failure
60+
cmake --install build
61+
cmake -Stest/project -Bbuild2 -DCMAKE_PREFIX_PATH=/tmp/target
62+
cmake --build build2
63+
4064
4165
check-expectations:
4266
runs-on: ubuntu-22.04

CMakeLists.txt

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,9 @@ target_include_directories(
2020

2121
# Prepare install targets
2222
install(DIRECTORY include/vsync DESTINATION include)
23-
install(DIRECTORY shared/vsync DESTINATION share)
23+
install(FILES vmm.cat DESTINATION share/vsync/)
2424
install(TARGETS vatomic EXPORT ${PROJECT_TARGETS})
2525

26-
# If this is not the top level project, do not enable testing and other targets.
27-
if(NOT CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
28-
return()
29-
endif()
30-
3126
# Atomic templating
3227
add_subdirectory(template)
3328
add_subdirectory(tmplr)
@@ -57,11 +52,12 @@ add_dependencies(clang-format-apply sanitize-vatomic)
5752
# General diff check for pipeline
5853
add_custom_target(diff-check COMMAND git --no-pager diff --exit-code)
5954

60-
# Configure testing
61-
include(CTest)
62-
include(ProcessorCount)
63-
include(cmake/v_add_test.cmake)
64-
65-
enable_testing()
66-
add_subdirectory(test)
67-
add_subdirectory(verify)
55+
# Enable testing and verification only if this is the top level project
56+
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
57+
include(CTest)
58+
include(ProcessorCount)
59+
include(cmake/v_add_test.cmake)
60+
enable_testing()
61+
add_subdirectory(test)
62+
add_subdirectory(verify)
63+
endif()

cmake/export.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ if(NOT DEFINED PROJECT_TARGETS)
66
set(PROJECT_TARGETS "${PROJECT_NAME}Targets")
77
endif()
88

9-
set(PROJECT_CMAKE_DIR "${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake")
9+
set(PROJECT_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
1010
set(PROJECT_CONFIG_FILE "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake")
1111
set(PROJECT_VERSION_FILE
1212
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake")

test/project/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved.
2+
# SPDX-License-Identifier: MIT
3+
4+
# set CMAKE_PREFIX_PATH with the CMAKE_INSTALL_PATH used to install vatomic
5+
6+
cmake_minimum_required(VERSION 3.16)
7+
project(test LANGUAGES C)
8+
find_package(vatomic CONFIG REQUIRED)
9+
add_executable(test test.c)
10+
target_link_libraries(test PRIVATE vatomic::vatomic)

test/project/test.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (C) Huawei Technologies Co., Ltd. 2025. All rights reserved.
3+
* SPDX-License-Identifier: MIT
4+
*/
5+
#include <vsync/atomic.h>
6+
#include <stdio.h>
7+
8+
vatomic32_t count;
9+
10+
int
11+
main()
12+
{
13+
vatomic_inc(&count);
14+
printf("count: %u\n", vatomic_read(&count));
15+
return 0;
16+
}

0 commit comments

Comments
 (0)