Skip to content

Commit

Permalink
cmake: Allow external control of whether to test or install
Browse files Browse the repository at this point in the history
This makes the project more composable: It can be built and
tested as part of a larger set of projects, from source.
  • Loading branch information
dneto0 authored and charles-lunarg committed Jun 14, 2024
1 parent 05fe2cc commit 8f034f6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:

env:
CMAKE_GENERATOR: Ninja

permissions:
contents: read

Expand All @@ -27,9 +27,9 @@ jobs:
- uses: actions/checkout@v4
- uses: lukka/get-cmake@latest
with:
cmakeVersion: ${{ matrix.cmake-version }}
cmakeVersion: ${{ matrix.cmake-version }}
- uses: ilammy/msvc-dev-cmd@v1
- run: cmake -S . -B build -D BUILD_TESTS=ON -G Ninja
- run: cmake -S . -B build -D VULKAN_HEADERS_ENABLE_TESTS=ON -D VULKAN_HEADERS_ENABLE_INSTALL=ON -G Ninja
- run: ctest --output-on-failure
working-directory: build

Expand Down
14 changes: 8 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ if (CMAKE_VERSION VERSION_LESS "3.21")
string(COMPARE EQUAL ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR} PROJECT_IS_TOP_LEVEL)
endif()

if (PROJECT_IS_TOP_LEVEL)
option(BUILD_TESTS "Build the tests")
if (BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
option(VULKAN_HEADERS_ENABLE_TESTS "Test Vulkan-Headers" ${PROJECT_IS_TOP_LEVEL})
option(VULKAN_HEADERS_ENABLE_INSTALL "Install Vulkan-Headers" ${PROJECT_IS_TOP_LEVEL})

if (VULKAN_HEADERS_ENABLE_TESTS)
enable_testing() # This is only effective in the top level CMakeLists.txt file.
add_subdirectory(tests)
endif()

if (VULKAN_HEADERS_ENABLE_INSTALL)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

Expand Down

0 comments on commit 8f034f6

Please sign in to comment.