Skip to content

fix: Respect CMAKE_INSTALL_PREFIX and BENCHMARK_ENABLE_INSTALL.#52

Open
jenskeiner wants to merge 1 commit into
CodSpeedHQ:mainfrom
jenskeiner:fix/core-install-prefix-and-gating
Open

fix: Respect CMAKE_INSTALL_PREFIX and BENCHMARK_ENABLE_INSTALL.#52
jenskeiner wants to merge 1 commit into
CodSpeedHQ:mainfrom
jenskeiner:fix/core-install-prefix-and-gating

Conversation

@jenskeiner
Copy link
Copy Markdown

Suggested changes to fix #51.

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Jun 3, 2026

Greptile Summary

This PR fixes two related CMake install issues: the headers install destination was hardcoded to /usr/local (ignoring CMAKE_INSTALL_PREFIX), and there was no way to opt out of installation. The fix adds include(GNUInstallDirs) for standard prefix-relative variables and gates all install() calls behind the BENCHMARK_ENABLE_INSTALL flag (defaulting ON, same variable name as Google Benchmark for compatibility).

  • Header destination fixed: DIRECTORY … DESTINATION /usr/localDESTINATION \"${CMAKE_INSTALL_INCLUDEDIR}\", and trailing slashes are added so the directory contents are placed directly under CMAKE_INSTALL_INCLUDEDIR rather than creating an extra include/ subdirectory level.
  • Installation guard added: BENCHMARK_ENABLE_INSTALL (defaults ON, respects -DBENCHMARK_ENABLE_INSTALL=OFF) using the if(NOT DEFINED) / set() pattern, which is the correct idiom for CMake 3.10 compatibility (avoids CMP0077 issues present with option() before 3.13).

Confidence Score: 4/5

Safe to merge — the install logic is correct and the hardcoded path is properly replaced with prefix-relative variables.

The two targeted changes (GNUInstallDirs adoption and BENCHMARK_ENABLE_INSTALL guard) work as intended with no regressions to the build or library targets. The one outstanding gap is that the EXPORT codspeed-targets clause has no matching install(EXPORT …) call, so the CMake package export file is never written at install time, leaving find_package(codspeed) broken for downstream consumers.

core/CMakeLists.txt — the install(TARGETS … EXPORT codspeed-targets) block needs a companion install(EXPORT codspeed-targets DESTINATION …) to complete the exported package setup.

Important Files Changed

Filename Overview
core/CMakeLists.txt Adds GNUInstallDirs for prefix-relative install destinations, wraps all install() calls behind BENCHMARK_ENABLE_INSTALL guard, and fixes directory trailing slashes so header contents (not the directory node itself) land in CMAKE_INSTALL_INCLUDEDIR.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[cmake configure] --> B[include GNUInstallDirs\nsets CMAKE_INSTALL_INCLUDEDIR\nCMAKE_INSTALL_LIBDIR\nCMAKE_INSTALL_BINDIR]
    B --> C{BENCHMARK_ENABLE_INSTALL\ndefined?}
    C -- No --> D[set BENCHMARK_ENABLE_INSTALL = ON]
    C -- Yes --> E{BENCHMARK_ENABLE_INSTALL?}
    D --> E
    E -- ON --> F[install DIRECTORY\ninclude/ → CMAKE_INSTALL_INCLUDEDIR]
    F --> G[install TARGETS codspeed\ninstrument_hooks\nEXPORT codspeed-targets]
    E -- OFF --> H[Skip install — no files\ncopied to prefix]
Loading

Reviews (1): Last reviewed commit: "fix: Respect CMAKE_INSTALL_PREFIX and BE..." | Re-trigger Greptile

Comment thread core/CMakeLists.txt
Comment on lines +227 to +234
install(
TARGETS codspeed instrument_hooks
EXPORT codspeed-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Missing install(EXPORT) call for codspeed-targets

The EXPORT codspeed-targets clause on install(TARGETS ...) registers the targets into an export set, but without a matching install(EXPORT codspeed-targets DESTINATION ...) call, no codspeed-targets.cmake file is ever written to disk during installation. Downstream projects relying on find_package(codspeed) after cmake --install won't get the imported-target file they need. Adding install(EXPORT codspeed-targets DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/codspeed") inside the same BENCHMARK_ENABLE_INSTALL guard would complete the export setup.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fair point. I would like to note that I think the dangling export was not introduced by the proposed code changes, but may have made reaching it more likely. Still, I think gating install() and honoring an install prefix are valid fixes. Maybe fixing the dangling export makes sense in another PR?

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.

Core install rules use a hardcoded absolute DESTINATION /usr/local and are not gated by BENCHMARK_ENABLE_INSTALL.

1 participant