Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use system googletest dependency when available #304

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ if(BUILD_TESTING)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF) # prefer use of -std14 instead of -gnustd14

if(NOT TARGET gtest OR NOT TARGET gmock_main)
find_package(GTest REQUIRED)
Copy link
Collaborator

Choose a reason for hiding this comment

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

since you add REQUIRED -> if not found the cmake configure will fail where instead you would like to fallback to "build googletest if not found in the system"

if(NOT TARGET GTest::gtest OR NOT TARGET GTest::gmock_main)
Copy link
Collaborator

@Mizux Mizux Aug 23, 2023

Choose a reason for hiding this comment

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

my 2 cents,

  1. GTest::gtest seems to be available only since CMake 3.5 (cpu_feature still use 3.0 as minimum requirement...)
    ref: https://cmake.org/cmake/help/v3.5/module/FindGTest.html
    ref: https://cmake.org/cmake/help/v3.4/module/FindGTest.html

  2. Googletest didn't provide these aliases until recently
    issue: Add CMake aliases googletest#2429
    PR: CMake: Add namespaced ALIAS library googletest#3155
    commit: google/googletest@6c5c455
    available in v1.14.0 … release-1.11.0

to compare with https://repology.org/project/gtest/badges (e.g. ubuntu 20.04 LTS => gtest 1.10.0)

  1. If your superbuild is using add_subdirectory() OR fetch_content() (without the new flag FIND_PACKAGE_ARGS NAMES ...) then you find_package() won't work as expected (i.e. ignore the call since your super already provide it)
    ref: https://cmake.org/cmake/help/latest/module/FetchContent.html#integrating-with-find-package

  2. Also in 3.24 we would be able to have FetchContent calling find_package() before sourcing if unavailable...
    ref: https://cmake.org/cmake/help/latest/module/FetchContent.html#variable:FETCHCONTENT_TRY_FIND_PACKAGE_MODE

Copy link
Collaborator

Choose a reason for hiding this comment

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

EDIT:

  1. DONE (we now target cmake 3.13)
  2. googletest v1.11 (June 2021) should provide alias -> Can we suppose super build use at least googletest 1.11 ?

# Download and unpack googletest at configure time.
configure_file(
cmake/googletest.CMakeLists.txt.in
Expand Down