From c109a486b664193e18df46a35f01495970451a7b Mon Sep 17 00:00:00 2001 From: Thomas Lauf Date: Wed, 23 Sep 2026 22:00:20 +0200 Subject: [PATCH] Only install library and headers when libshared is built standalone install() rules are cumulative across a CMake project, so projects that include libshared via add_subdirectory() (e.g. Timewarrior since GothenburgBitFactory/timewarrior#706) inherit the rules installing lib/libshared.a and all headers to include/, polluting the embedding project's install manifest. Guard the install rules with LIBSHARED_IS_TOP_LEVEL, which is set when libshared is the top-level project, so they only apply to standalone builds. Closes #122 Signed-off-by: Thomas Lauf --- CMakeLists.txt | 5 +++++ src/CMakeLists.txt | 8 +++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 21f67c0..014544d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,11 @@ set(CMAKE_CXX_STANDARD 17) set (CMAKE_EXPORT_COMPILE_COMMANDS ON) project (shared) + +if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) + set (LIBSHARED_IS_TOP_LEVEL ON) +endif () + include (CXXSniffer) include (CheckFunctionExists) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4e17455..4c39464 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -56,9 +56,11 @@ set (shared_SRCS Args.cpp add_library (shared STATIC ${shared_SRCS}) -set (CMAKE_INSTALL_LIBDIR lib CACHE PATH "Output directory for libraries") -install (TARGETS shared DESTINATION lib) -install (FILES ${shared_HEADERS} DESTINATION include) +if (LIBSHARED_IS_TOP_LEVEL) + set (CMAKE_INSTALL_LIBDIR lib CACHE PATH "Output directory for libraries") + install (TARGETS shared DESTINATION lib) + install (FILES ${shared_HEADERS} DESTINATION include) +endif () add_executable (lex_executable lex.cpp) target_link_libraries (lex_executable shared)