Skip to content

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

Description

@Shadows-of-Fire

Describe the issue

CMake provides a series of variables (CMAKE_RUNTIME_OUTPUT_DIRECTORY, CMAKE_ARCHIVE_OUTPUT_DIRECTORY, CMAKE_LIBRARY_OUTPUT_DIRECTORY, CMAKE_PDB_OUTPUT_DIRECTORY, CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY). collectively CMAKE_<ARTIFACT>_OUTPUT_DIRECTORY, by which users can elect to tell the build where to place build-tree artifacts of a given artifact kind.

GTest does not respect these variables, as it hardcodes the underlying target properties in internal_utils.cmake::cxx_library_with_type
https://github.com/google/googletest/blame/d72f9c8aea6817cdf1ca0ac10887f328de7f3da2/googletest/cmake/internal_utils.cmake#L171-L177

This makes it difficult to configure where GTest artifacts are placed from the user side. It's not impossible because a consumer can override the properties on the created target(s), but it's obtuse and difficult to discern which targets need this treatment.

These are effectively the defaults, so we should simply not be setting the *_OUTPUT_DIRECTORY properties on gtest artifacts.

Steps to reproduce the problem

Build GTest with CMake, provide -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY to a value other than lib/. Observe that GTest artifacts are still in lib/

What version of GoogleTest are you using?

d72f9c8

What operating system and version are you using?

Ubuntu 24.04

What compiler and version are you using?

GCC 13

What build system are you using?

CMake 3.31

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions