Skip to content

statically link GTest, update to 1.18.0, fetch it with CPM - #705

Merged
chyunsu3 merged 3 commits into
dmlc:mainlinefrom
jameslamb:static-gtest
Sep 3, 2026
Merged

statically link GTest, update to 1.18.0, fetch it with CPM#705
chyunsu3 merged 3 commits into
dmlc:mainlinefrom
jameslamb:static-gtest

Conversation

@jameslamb

Copy link
Copy Markdown
Contributor

Closes #704

Proposes:

Notes for Reviewers

How I tested this

Using the reproducible example from #704.

# build tests
$ rm -rf ./build
$ cmake -B build -S . -DBUILD_SHARED_LIBS=ON -DBUILD_CPP_TEST=ON
$ cmake --build build -j8

# relocate the test executable
$ TMP_DIR=$(mktemp -d)
$ mv ./build/treelite_cpp_test "${TMP_DIR}/"
$ rm -rf ./build
$ pushd "${TMP_DIR}"

# try testing
$ ./treelite_cpp_test
...
[==========] 29 tests from 9 test suites ran. (11 ms total)
[  PASSED  ] 29 tests.

$ ldd ./treelite_cpp_test
        linux-vdso.so.1 (0x0000766f56a2e000)
        libgomp.so.1 => /lib/x86_64-linux-gnu/libgomp.so.1 (0x0000766f569bd000)
        libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x0000766f56200000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x0000766f568d4000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x0000766f568a6000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x0000766f55e00000)
        /lib64/ld-linux-x86-64.so.2 (0x0000766f56a30000)

@codecov

codecov Bot commented Sep 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.97%. Comparing base (b0525f6) to head (f91ecf0).

Additional details and impacted files
@@            Coverage Diff            @@
##           mainline     #705   +/-   ##
=========================================
  Coverage     83.97%   83.97%           
=========================================
  Files            75       75           
  Lines          6908     6908           
  Branches        559      559           
=========================================
  Hits           5801     5801           
  Misses         1107     1107           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread cmake/CPMFindGTest.cmake Outdated
# As of v1.14.0, googletest did literal string replacements on CMAKE_CXX_FLAGS,
# and doesn't respect CMAKE_MSVC_RUNTIME_LIBRARY.
#
# TODO(jameslamb): remove this once this project uses at least GTest v1.18.0

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'd love to use the latest GTest. Is there a disadvantage for upgrading?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh sure! I'm not aware of any disadvantage. Looks like it still has a CMake minimum of 3.16 (build link), and CI could tell us if it has any compiler support limitations or other problems like that (but I really doubt it for that project).

Also... statically linking it makes it even safer to upgrade this project to a different version 😁

I'll try that here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I just tried locally on my Mac and tests seem to work fine with the latest version (1.18.0, released 3 weeks ago).

Pushed f91ecf0 with that upgrade + removing the MSVC stuff.

@jameslamb jameslamb changed the title statically link GTest, fetch it with CPM statically link GTest, update to 1.18.0, fetch it with CPM Sep 3, 2026
@jameslamb
jameslamb requested a review from chyunsu3 September 3, 2026 02:20
@chyunsu3
chyunsu3 merged commit 59cc88a into dmlc:mainline Sep 3, 2026
20 checks passed
@chyunsu3

chyunsu3 commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

Thanks!

@jameslamb
jameslamb deleted the static-gtest branch September 3, 2026 04:52
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.

[c++] test executables are not relocatable

2 participants