Skip to content

Find googletest from system if available - #442

Open
K1ngfish3r wants to merge 2 commits into
oneapi-src:masterfrom
K1ngfish3r:patch-1
Open

K1ngfish3r wants to merge 2 commits into
oneapi-src:masterfrom
K1ngfish3r:patch-1

Conversation

@K1ngfish3r

Copy link
Copy Markdown

@rwmcguir rwmcguir left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this is a good change for distro and offline builds. But it breaks CMake versions older than 3.24, and the project minimum is 3.12.

FIND_PACKAGE_ARGS was added to FetchContent_Declare in CMake 3.24. Older versions do not know the keyword, so it breaks the clone. That is why the Ubuntu 22.04 jobs fail (CMake 3.22):

fatal: could not create work tree dir '': No such file or directory
Failed to clone repository: 'https://github.com/google/googletest.git'

Could you add the keyword only on CMake 3.24 and newer, and keep 1.14.0 as the minimum version?

if(BUILD_L0_LOADER_TESTS)
	set(INSTALL_GTEST OFF)
    # FIND_PACKAGE_ARGS (CMake 3.24+) uses an installed GTest 1.14.0 or newer
    # when one is found, and downloads v1.14.0 otherwise.
    if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24)
        set(GTEST_FIND_PACKAGE_ARGS FIND_PACKAGE_ARGS 1.14.0 NAMES GTest)
    endif()
    FetchContent_Declare(
        googletest
        GIT_REPOSITORY https://github.com/google/googletest.git
        GIT_TAG        v1.14.0
        ${GTEST_FIND_PACKAGE_ARGS}
    )

GTest's package config uses AnyNewerVersion, so 1.14.0 means "1.14.0 or newer". If the installed version is older, FetchContent falls back to the download.

I tested this locally:

CMake Installed GTest Result Tests
3.22.6 1.14.0 Downloads v1.14.0 (same as today) builds
3.28.3 none Downloads v1.14.0 builds
3.28.3 1.12.0 Too old, downloads v1.14.0 builds
3.28.3 1.14.0 Uses the installed GTest 263/263 pass
3.28.3 1.17.0 Uses the installed GTest. The test target builds as C++17, because GTest 1.17 requires it. 263/263 pass

Also, please use spaces for the indentation of the new lines, like the lines around them.

@K1ngfish3r

K1ngfish3r commented Oct 23, 2026 •

Copy link
Copy Markdown
Author

Thanks, this is a good change for distro and offline builds. But it breaks CMake versions older than 3.24, and the project minimum is 3.12.
...
Could you add the keyword only on CMake 3.24 and newer, and keep 1.14.0 as the minimum version?

it all makes sense, done, have applied your suggestion directly. lemme know if anything else is necessary
EDIT: i had initially assumed the error to be related to github doing github things (ie: failing to resolve). I remember tons of jobs failing back then. didnt realize it was actually a CMake issue

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants