From 8f034f6b48fd2d30f711396a021e1dc050c8941c Mon Sep 17 00:00:00 2001 From: David Neto Date: Tue, 13 Feb 2024 19:17:22 +0000 Subject: cmake: Allow external control of whether to test or install This makes the project more composable: It can be built and tested as part of a larger set of projects, from source. --- .github/workflows/ci.yml | 6 +++--- CMakeLists.txt | 14 ++++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5de0877..fbb0078 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ on: env: CMAKE_GENERATOR: Ninja - + permissions: contents: read @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index e1a2af0..698666f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) -- cgit v1.2.3