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 external GoogleTest optionally #4563

Merged
merged 12 commits into from
Dec 16, 2021
Merged

Use external GoogleTest optionally #4563

merged 12 commits into from
Dec 16, 2021

Conversation

cz4rs
Copy link
Contributor

@cz4rs cz4rs commented Nov 30, 2021

fixes #4384


Use find_package(GTest) to check for external GoogleTest library.
When not available, fallback to our internal copy in tpls/gtest.
edit: Always use internal copy when building as a part of Trilinos.

Notes:

-DCMAKE_DISABLE_FIND_PACKAGE_GTest=TRUE

(for example in case when a GTest package is found, but it's not working correctly)

@cz4rs cz4rs marked this pull request as ready for review December 1, 2021 14:29
@cz4rs cz4rs linked an issue Dec 1, 2021 that may be closed by this pull request
3 tasks
@cz4rs
Copy link
Contributor Author

cz4rs commented Dec 2, 2021

Should I add something like this:

When the tests are enabled, Kokkos will try to find and use available GoogleTest package by default. To force the use of internal copy, configure with

-DCMAKE_DISABLE_FIND_PACKAGE_GTest=TRUE

to README.md / BUILD.md? Or is that too much detail?

CMakeLists.txt Show resolved Hide resolved
core/unit_test/CMakeLists.txt Outdated Show resolved Hide resolved
)

# avoid deprecation warnings from MSVC
TARGET_COMPILE_DEFINITIONS(kokkos_gtest PUBLIC GTEST_HAS_TR1_TUPLE=0 GTEST_HAS_PTHREAD=0)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually GTEST_HAS_TR1_TUPLE option was removed completely from gtest.

Copy link
Member

Choose a reason for hiding this comment

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

To other reviewers: Make sure you see that this is dropping the compile definition -DGTEST_HAS_PTHREAD=0

@dalg24
Copy link
Member

dalg24 commented Dec 8, 2021

Retest this please

)

# avoid deprecation warnings from MSVC
TARGET_COMPILE_DEFINITIONS(kokkos_gtest PUBLIC GTEST_HAS_TR1_TUPLE=0 GTEST_HAS_PTHREAD=0)
Copy link
Member

Choose a reason for hiding this comment

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

To other reviewers: Make sure you see that this is dropping the compile definition -DGTEST_HAS_PTHREAD=0

Copy link
Contributor

@masterleinad masterleinad left a comment

Choose a reason for hiding this comment

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

I think we should test this with Trilinos before merging. Otherwise, this looks good to me.

@dalg24
Copy link
Member

dalg24 commented Dec 14, 2021

I think we should test this with Trilinos before merging. Otherwise, this looks good to me.

Not a bad idea. @ndellingwood would you assist with this?

@cz4rs
Copy link
Contributor Author

cz4rs commented Dec 14, 2021

I think we should test this with Trilinos before merging. Otherwise, this looks good to me.

Not a bad idea. @ndellingwood would you assist with this?

No experience with Trilinos here, so I would appreciate someone either testing it or walking me through 👍

@ndellingwood
Copy link
Contributor

@cz4rs @dalg24 I'll test some builds of Trilinos with this PR

@ndellingwood
Copy link
Contributor

@cz4rs @dalg24 so far I tested Trilinos with builds without an external Gtest package, so they fell back to the internal copy; for that case everything passed fine, no surprise. I still need to install and test with Gtest as an external package.

My understanding with these changes is that the use of Gtest as an external package here would be isolated to Kokkos' testing, so this should not impact users of Trilinos (and downstream applications) that rely on the Trilinos Gtest package

@ndellingwood
Copy link
Contributor

ndellingwood commented Dec 15, 2021

@dalg24 @cz4rs My assumption was incorrect - If I enable gtest as TPL in Trilinos and add my external gtest install (googletest v.1.8.0) to the system PATH so my install is found by CMake, then Trilinos configuration fails:

CMake Error at cmake/tribits/core/package_arch/TribitsAddExecutable.cmake:477 (message):
  ERROR: 'GTest::gtest' in TESTONLYLIBS not a TESTONLY lib! If this a regular
  library in this SE package or in an dependent upstream SE package then
  TriBITS will link automatically to it.  If you remove this and it does not
  link, then you need to add a new SE package dependency to this SE package's
  dependencies file
  /ascldap/users/ndellin/trilinos/Trilinos/kokkos/core/cmake/Dependencies.cmake
Call Stack (most recent call first):
  cmake/tribits/core/package_arch/TribitsAddExecutableAndTest.cmake:68 (tribits_add_executable)
  cmake/tribits/core/package_arch/TribitsAddExecutableAndTest.cmake:214 (tribits_add_executable_wrapper)
  kokkos/cmake/kokkos_tribits.cmake:161 (TRIBITS_ADD_EXECUTABLE_AND_TEST)
  kokkos/core/unit_test/CMakeLists.txt:412 (KOKKOS_ADD_EXECUTABLE_AND_TEST)

The relevant CMake configure options I used were:

-D TPL_ENABLE_GTEST=ON  -D GTEST_INCLUDE_DIR=<path-to-gtest-include>

I confirmed the above works with Kokkos' develop branch, so the changes in this PR are impacting the Trilinos configuration. Some applications use gtest through Trilinos for their testing, so this will need to be resolved for acceptance of the next release with Trilinos.


When testing I modified my existing configuration to enable Gtest as TPL as above, but a simplified Trilinos setup and configuration to reproduce using just Kokkos' develop branch should look something like this:

cmake -DCMAKE_CXX_COMPLER=<g++,clang++, or icpc> -DTPL_ENABLE_GTEST=ON  -DGTEST_INCLUDE_DIR=<path-to-ext-gtest-include> -DTrilinos_ENABLE_Kokkos=ON -DKokkos_ENABLE_TESTS=ON -DKokkos_SOURCE_DIR_OVERRIDE:STRING=kokkos $TRILINOS_DIR

@ndellingwood
Copy link
Contributor

I tried another configuration option, enabling Gtest as a package in Trilinos (i.e. -DTrilinos_ENABLE_Gtest=ON) and that case configured without issue with the changes in this PR.
Looking through some relevant Trilinos github issues, there is explicit mention of applications using Gtest as a package through Trilinos (I previously commented that Gtest was enabled as TPL). Better (or proper?) support for enabling Gtest as a TPL in Trilinos is a desired feature as discussed here trilinos/Trilinos#8001 along with a PR with work towards Gtest TPL support in Trilinos here trilinos/Trilinos#9514

@cz4rs
Copy link
Contributor Author

cz4rs commented Dec 15, 2021

@dalg24 @cz4rs My assumption was incorrect - If I enable gtest as TPL in Trilinos and add my external gtest install (googletest v.1.8.0) to the system PATH so my install is found by CMake, then Trilinos configuration fails (...)

Thanks for the feedback! I will see what can be done about this (and take a look at the Trilinos issues linked).

@cz4rs
Copy link
Contributor Author

cz4rs commented Dec 15, 2021

Rebased on top of develop and added c206c49 - this forces the use of internal copy of GTest when building as a part of Trilinos.

Copy link
Member

@Rombur Rombur left a comment

Choose a reason for hiding this comment

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

It looks good. Do we still need the changes in cmake/kokkos_tribits.cmake since we use the internal gtest with Trilinos?

SET(KOKKOS_GTEST_LIB GTest::gtest)
ELSE() # fallback to internal gtest
SET(KOKKOS_GTEST_LIB kokkos_gtest)
ENDIF()
Copy link
Member

Choose a reason for hiding this comment

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

Do we still need these changes since we now always use us the internal gtest with Trilinos?

Copy link
Member

Choose a reason for hiding this comment

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

We do

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, because it's still possible to use either the internal copy or external GTest (without Trilinos).

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.

use external GoogleTest optionally
6 participants