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

Update CMake quickstart with find_package + add CMake source build guide #4682

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

phetdam
Copy link

@phetdam phetdam commented Dec 16, 2024

This PR updates the GoogleTest documentation as follows:

  1. Update the CMake quickstart to show usage with find_package
  2. Add a CMake source build guide for *nix single- and multi-config generators and Windows Visual Studio generators

Work was inspired by the conversation in #4681 and by previous experience building older (v1.10.0) versions of GoogleTest from source in Windows environments with both gtest.lib and gtestd.lib installed side-by-side linked against the shared C runtime. This is common in Windows development environments as there is more than one C runtime library and loading multiple (possibly ABI-incompatible) instances of the C runtime is generally discouraged.

…ntent + update gtest_force_shared_crt comments
modified:   docs/_data/navigation.yml
    Add source-build-cmake.html to the guides section

new file:   docs/source-build-cmake.md
    Add CMake build instructions for *nix and Windows
@phetdam
Copy link
Author

phetdam commented Dec 16, 2024

If this is accepted maybe it can also address #3843 as it provides an "official" workaround via CMAKE_DEBUG_POSTFIX.


# Since CMake 3.20 CONFIG can be omitted as the FindGTest find module will
# prefer the upstream (provided by Google Test) GTestConfig.cmake if available
find_package(GTest 1.15.0 REQUIRED CONFIG)
Copy link

Choose a reason for hiding this comment

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

I think there is no need to differentiate; target_link_libraries should be directly followed by find_package.

Copy link
Author

Choose a reason for hiding this comment

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

The target_link_libraries call is in the "Create and run a binary" section; here I just mirror the FetchContent section.

@Mq-b
Copy link

Mq-b commented Dec 16, 2024

If this is accepted maybe it can also address #3843 as it provides an "official" workaround via CMAKE_DEBUG_POSTFIX.

#3843 issue I have encountered and resolved myself, and I believe this is the approach most people would choose, source code building, then using find_package and target_link_libraries. #4681 was proposed by me and should also be the conventional approach for most people.

@Mq-b
Copy link

Mq-b commented Dec 23, 2024

benchmark build tutorial is very comprehensive and detailed, considering a variety of situations and multiple platforms, and it is recommended to introduce it:

find_package(benchmark REQUIRED)
target_link_libraries(MyTarget benchmark::benchmark)

@phetdam
Copy link
Author

phetdam commented Dec 23, 2024

benchmark build tutorial is very comprehensive and detailed, considering a variety of situations and multiple platforms

Yes, I just looked at their README.md and it has good instructions for building.

However, on Windows there needs to be extra attention on the C runtime being linked, which is why we want to distinguish the debug library in /install_root/lib with a d suffix via -DCMAKE_DEBUG_POSTFIX=d.

@Yankuba-debug
Copy link

Positive

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.

3 participants