googletest icon indicating copy to clipboard operation
googletest copied to clipboard

The CMake Build documentation is too detached from reality

Open Mq-b opened this issue 11 months ago • 10 comments
trafficstars

Does the feature exist in the most recent commit?

No.

Why do we need this feature?

I don't think anyone built and imported the GTest testing framework the way the documentation did:

cmake_minimum_required(VERSION 3.14)
project(my_project)

# GoogleTest requires at least C++14
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include(FetchContent)
FetchContent_Declare(
  googletest
  URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

Describe the proposal.

I find this confusing, in fact I think what we should be writing is building from source and importing it using CMake:

find_package(GTest REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE GTest::GTest)

Also, I think "gtest_force_shared_crt" should be defined during the configuration step (e.g., cmake .. -Dgtest_force_shared_crt=ON), when generating the build system, rather than during the build or usage phase.

Let me repeat, I think our documentation should be written to build from source, like:

git clone https://github.com/google/googletest
cd googletest
mkdir build
cd build
cmake .. -Dgtest_force_shared_crt=ON
cmake --build . -j
cmake --install .

I forgot to add -Dgtest_force_shared_crt=ON earlier which caused me to use MT to link to the C++ standard library and keep getting errors.

If it's on Windows, it is also necessary to generate the Release version and install it.

Is the feature specific to an operating system, compiler, or build system version?

No.

Mq-b avatar Dec 14 '24 12:12 Mq-b