Skip to content

Bug Fix: Respect CMake output directory overrides#4963

Open
dragoiuc wants to merge 1 commit into
google:mainfrom
dragoiuc:fix-cmake-output-directories
Open

Bug Fix: Respect CMake output directory overrides#4963
dragoiuc wants to merge 1 commit into
google:mainfrom
dragoiuc:fix-cmake-output-directories

Conversation

@dragoiuc
Copy link
Copy Markdown

Fixes #4957.

This PR updates GoogleTest's CMake output directory handling so that user-provided
CMAKE_<ARTIFACT>_OUTPUT_DIRECTORY values are respected.

Before this change, cxx_library_with_type set the output directory properties
directly on each target. Because of that, setting something like
CMAKE_ARCHIVE_OUTPUT_DIRECTORY would not affect where libgtest.a or
libgtest_main.a were placed.

The fix keeps GoogleTest's existing default layout when users do not set any
custom output directories, but avoids overriding the user's values when they do.

I also added a regression test for this behavior. The test checks that:

  • default builds still place artifacts in the expected bin/ and lib/ locations
  • custom CMAKE_*_OUTPUT_DIRECTORY values are respected

Tests run:

  • cmake -S . -B /tmp/gtest-pr-check -DBUILD_GMOCK=OFF -Dgtest_build_tests=ON -DINSTALL_GTEST=OFF
  • cmake --build /tmp/gtest-pr-check -j2
  • ctest --test-dir /tmp/gtest-pr-check -R googletest-cmake-output-directory-test --output-on-failure
  • ctest --test-dir /tmp/gtest-pr-check --output-on-failure
  • manual smoke check with a custom CMAKE_ARCHIVE_OUTPUT_DIRECTORY for gtest and gtest_main

@dragoiuc dragoiuc changed the title Respect CMake output directory overrides Bug Fix: Respect CMake output directory overrides Apr 25, 2026
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.

[Bug]: CMake - GTest does not respect user CMAKE_<ARTIFACT>_OUTPUT_DIRECTORY

1 participant