Skip to content

Commit 64a6257

Browse files
committed
Test FetchContent of UMF on Linux and Windows
Test FetchContent of UMF on Linux and Windows - on Windows with the 'Ninja' and 'NMake Makefiles' generators. Add the fetch_content example based on the basic example. Signed-off-by: Lukasz Dorau <[email protected]>
1 parent aa3a452 commit 64a6257

File tree

4 files changed

+224
-0
lines changed

4 files changed

+224
-0
lines changed

.github/workflows/pr_push.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ jobs:
6363
uses: ./.github/workflows/reusable_qemu.yml
6464
with:
6565
short_run: true
66+
FetchContent:
67+
needs: [FastBuild]
68+
uses: ./.github/workflows/reusable_fetch_content.yml
6669
ProxyLib:
6770
needs: [Build]
6871
uses: ./.github/workflows/reusable_proxy_lib.yml
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Test FetchContent of UMF on Linux and Windows (on Windows with the 'Ninja' and 'NMake Makefiles' generators)
2+
name: FetchContent
3+
4+
on: workflow_call
5+
6+
permissions:
7+
contents: read
8+
packages: read
9+
10+
jobs:
11+
Linux-FetchContent:
12+
runs-on: ubuntu-latest
13+
container:
14+
image: ghcr.io/bb-ur/umf-${{ matrix.os }}:latest
15+
options: --user test_user --cap-add=SYS_NICE --cap-add=SYS_PTRACE
16+
volumes:
17+
- ${{ github.workspace }}:${{ github.workspace }}
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
os: ['ubuntu-24.04']
22+
build_type: [Debug]
23+
name: FetchContent-Linux (${{matrix.os}}, build_type=${{matrix.build_type}})
24+
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
28+
with:
29+
fetch-depth: 0
30+
31+
- name: Configure the fetch_content example
32+
working-directory: ${{github.workspace}}/examples/fetch_content
33+
# Fetch_Content the UMF code from the current repository (-DUMF_REPO="${{github.workspace}}")
34+
run: >
35+
cmake
36+
-B ${{github.workspace}}/examples/fetch_content/build
37+
-DCMAKE_BUILD_TYPE=${{matrix.build_type}}
38+
-DUMF_REPO="${{github.workspace}}"
39+
40+
- name: Build the fetch_content example
41+
working-directory: ${{github.workspace}}/examples/fetch_content
42+
run: cmake --build ${{github.workspace}}/examples/fetch_content/build --config ${{matrix.build_type}} -j $(nproc)
43+
44+
- name: Run the fetch_content example
45+
working-directory: ${{github.workspace}}/examples/fetch_content/build
46+
run: ./umf_example_fetch_content
47+
48+
# Build and test the fetch_content example with different CMake generators on Windows
49+
Windows-FetchContent:
50+
strategy:
51+
fail-fast: false
52+
matrix:
53+
build_type: [Debug]
54+
generator: ['Ninja', 'NMake Makefiles']
55+
name: FetchContent-Windows (generator=${{matrix.generator}}, build_type=${{matrix.build_type}})
56+
runs-on: windows-latest
57+
58+
steps:
59+
- name: Checkout
60+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
61+
with:
62+
fetch-depth: 0
63+
64+
- name: Set VCPKG_PATH
65+
run: echo "VCPKG_PATH=${{github.workspace}}/examples/fetch_content/build/vcpkg/packages/hwloc_x64-windows;${{github.workspace}}/examples/fetch_content/build/vcpkg/packages/tbb_x64-windows;${{github.workspace}}/examples/fetch_content/build/vcpkg/packages/jemalloc_x64-windows" >> $env:GITHUB_ENV
66+
67+
- name: Initialize vcpkg
68+
uses: lukka/run-vcpkg@5e0cab206a5ea620130caf672fce3e4a6b5666a1 # v11.5
69+
env:
70+
VCPKG_PATH: ${{env.VCPKG_PATH}}
71+
with:
72+
vcpkgGitCommitId: ea2a964f9303270322cf3f2d51c265ba146c422d # 1.04.2025
73+
vcpkgDirectory: ${{github.workspace}}/examples/fetch_content/build/vcpkg
74+
vcpkgJsonGlob: '**/vcpkg.json'
75+
76+
- name: Install dependencies
77+
run: vcpkg install --triplet x64-windows
78+
79+
- name: Install Ninja
80+
if: matrix.generator == 'Ninja'
81+
uses: seanmiddleditch/gha-setup-ninja@3b1f8f94a2f8254bd26914c4ab9474d4f0015f67 # v6
82+
83+
- name: Configure MSVC environment
84+
uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0
85+
86+
- name: Configure the fetch_content example
87+
working-directory: ${{github.workspace}}/examples/fetch_content
88+
# Fetch_Content the UMF code from the current repository (-DUMF_REPO="${{github.workspace}}")
89+
run: >
90+
cmake
91+
-B ${{github.workspace}}/examples/fetch_content/build
92+
-DCMAKE_BUILD_TYPE=${{matrix.build_type}}
93+
-DCMAKE_PREFIX_PATH="${{env.VCPKG_PATH}}"
94+
-DUMF_REPO="${{github.workspace}}"
95+
-DCMAKE_C_COMPILER=cl
96+
-DCMAKE_CXX_COMPILER=cl
97+
-G "${{matrix.generator}}"
98+
99+
- name: Build the fetch_content example
100+
working-directory: ${{github.workspace}}/examples/fetch_content
101+
shell: cmd
102+
run: cmake --build ${{github.workspace}}/examples/fetch_content/build --config ${{matrix.build_type}} -j %NUMBER_OF_PROCESSORS%
103+
104+
- name: Run the fetch_content example
105+
shell: cmd
106+
working-directory: ${{github.workspace}}/examples/fetch_content/build
107+
run: dir .\umf_example_fetch_content.exe

examples/fetch_content/CMakeLists.txt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright (C) 2025 Intel Corporation
2+
# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
3+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
5+
cmake_minimum_required(VERSION 3.14.0 FATAL_ERROR)
6+
project(umf_example_fetch_content LANGUAGES C)
7+
enable_testing()
8+
9+
set(UMF_EXAMPLE_DIR "${CMAKE_SOURCE_DIR}/..")
10+
list(APPEND CMAKE_MODULE_PATH "${UMF_EXAMPLE_DIR}/cmake")
11+
message(STATUS "CMAKE_MODULE_PATH=${CMAKE_MODULE_PATH}")
12+
13+
include("fetch_umf.cmake")
14+
15+
find_package(PkgConfig)
16+
pkg_check_modules(LIBHWLOC hwloc>=2.3.0)
17+
if(NOT LIBHWLOC_FOUND)
18+
find_package(LIBHWLOC 2.3.0 REQUIRED hwloc)
19+
endif()
20+
21+
pkg_check_modules(TBB tbb)
22+
if(NOT TBB_FOUND)
23+
find_package(TBB REQUIRED tbb)
24+
endif()
25+
26+
# build the example
27+
set(EXAMPLE_NAME umf_example_fetch_content)
28+
# reusing the basic.c source file from the basic example
29+
add_executable(${EXAMPLE_NAME} ${CMAKE_SOURCE_DIR}/../basic/basic.c)
30+
target_include_directories(${EXAMPLE_NAME} PRIVATE ${LIBUMF_INCLUDE_DIRS})
31+
target_link_directories(${EXAMPLE_NAME} PRIVATE ${LIBHWLOC_LIBRARY_DIRS})
32+
target_link_libraries(${EXAMPLE_NAME} PRIVATE ${LIBUMF_LIBRARIES} hwloc)
33+
34+
# an optional part - adds a test of this example
35+
add_test(
36+
NAME ${EXAMPLE_NAME}
37+
COMMAND ${EXAMPLE_NAME}
38+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
39+
40+
set_tests_properties(${EXAMPLE_NAME} PROPERTIES LABELS "example-standalone")
41+
42+
if(LINUX)
43+
# set LD_LIBRARY_PATH
44+
set_property(
45+
TEST ${EXAMPLE_NAME}
46+
PROPERTY
47+
ENVIRONMENT_MODIFICATION
48+
"LD_LIBRARY_PATH=path_list_append:${LIBUMF_LIBRARY_DIRS};LD_LIBRARY_PATH=path_list_append:${LIBHWLOC_LIBRARY_DIRS}"
49+
)
50+
endif()
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Copyright (C) 2025 Intel Corporation
2+
# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
3+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
5+
message(STATUS "Downloading Unified Memory Framework ...")
6+
7+
include(FetchContent)
8+
9+
if(NOT DEFINED UMF_REPO)
10+
set(UMF_REPO "https://github.com/oneapi-src/unified-memory-framework.git")
11+
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
12+
string(REPLACE "\\" "/" OUT_UMF_REPO "${UMF_REPO}")
13+
message(
14+
STATUS
15+
"Replaced \"${UMF_REPO}\" with \"${OUT_UMF_REPO}\" for Windows compatibility"
16+
)
17+
set(UMF_REPO "${OUT_UMF_REPO}")
18+
endif()
19+
20+
if(NOT DEFINED UMF_TAG)
21+
set(UMF_TAG HEAD)
22+
endif()
23+
24+
message(
25+
STATUS
26+
"Will fetch Unified Memory Framework from ${UMF_REPO} at ${UMF_TAG} ..."
27+
)
28+
message(STATUS "CMAKE_GENERATOR: ${CMAKE_GENERATOR}")
29+
30+
FetchContent_Declare(
31+
unified-memory-framework
32+
GIT_REPOSITORY ${UMF_REPO}
33+
GIT_TAG ${UMF_TAG})
34+
35+
set(UMF_BUILD_TESTS
36+
OFF
37+
CACHE INTERNAL "Do not build UMF tests")
38+
set(UMF_BUILD_EXAMPLES
39+
OFF
40+
CACHE INTERNAL "Do not build UMF examples")
41+
set(UMF_BUILD_SHARED_LIBRARY
42+
OFF
43+
CACHE INTERNAL "Build UMF shared library")
44+
set(UMF_BUILD_LIBUMF_POOL_DISJOINT
45+
ON
46+
CACHE INTERNAL "Build Disjoint Pool")
47+
set(UMF_BUILD_CUDA_PROVIDER
48+
OFF
49+
CACHE INTERNAL "Do not build CUDA provider")
50+
set(UMF_BUILD_LEVEL_ZERO_PROVIDER
51+
OFF
52+
CACHE INTERNAL "Do not build L0 provider")
53+
set(UMF_DISABLE_HWLOC
54+
OFF
55+
CACHE INTERNAL "Enable HWLOC support")
56+
set(UMF_LINK_HWLOC_STATICALLY
57+
OFF
58+
CACHE INTERNAL "UMF_LINK_HWLOC_STATICALLY=OFF")
59+
60+
FetchContent_MakeAvailable(unified-memory-framework)
61+
FetchContent_GetProperties(unified-memory-framework)
62+
63+
set(LIBUMF_INCLUDE_DIRS ${unified-memory-framework_SOURCE_DIR}/include)
64+
set(LIBUMF_LIBRARIES umf::umf umf::headers)

0 commit comments

Comments
 (0)