Skip to content

build(cmake): Allow ystdlib-cpp to be imported into other CMake projects as a library #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

PacificViking
Copy link

@PacificViking PacificViking commented May 26, 2025

Description

Provides necessary configurations so that dependent projects can use this project as a library rather than a subproject.

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

Test cases still pass. Confirmed that headers are visible from other CMake projects, and the correct symbols are in the built library file.

Summary by CodeRabbit

  • New Features
    • Added full CMake package support, enabling installation and integration of the library with other CMake projects.
    • Introduced versioning and export targets for improved downstream usage.
    • Provided options for building shared libraries and enabling testing.
  • Chores
    • Updated project configuration to enforce C++20 and improved installation rules for headers and targets.
    • Added package configuration files and dependency handling for seamless consumption.

@PacificViking PacificViking requested a review from a team as a code owner May 26, 2025 19:03
Copy link

coderabbitai bot commented May 26, 2025

Walkthrough

A comprehensive CMake package configuration was introduced for the ystdlib-cpp project. This includes a new ystdlib-config.cmake.in file for package setup and dependency management, updates to CMakeLists.txt for target creation, installation, export, versioning, and header installation, enabling downstream CMake consumption.

Changes

File(s) Change Summary
CMake/ystdlib-config.cmake.in Added new CMake config file for ystdlib package setup, dependency handling, and target inclusion safeguards.
CMakeLists.txt Enhanced with project versioning, target creation, installation/export rules, header installation, and config file generation for CMake package consumption.

Sequence Diagram(s)

sequenceDiagram
    participant UserProject
    participant CMake
    participant ystdlib-config.cmake
    participant ystdlib-targets.cmake

    UserProject->>CMake: find_package(ystdlib)
    CMake->>ystdlib-config.cmake: Load config file
    ystdlib-config.cmake->>ystdlib-config.cmake: Check dependencies (Catch2, outcome)
    ystdlib-config.cmake->>ystdlib-targets.cmake: Include targets if not already defined
    ystdlib-targets.cmake-->>CMake: Define ystdlib::ystdlib target
    CMake-->>UserProject: ystdlib::ystdlib available for linking
Loading

Possibly related PRs

Suggested reviewers

  • davidlion

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 9

🔭 Outside diff range comments (1)
CMakeLists.txt (1)

62-67: ⚠️ Potential issue

Link to outcome is missing.

You find_package(outcome REQUIRED) but do not actually link it into ystdlib. Without:

target_link_libraries(ystdlib PUBLIC outcome::outcome)

downstream consumers will miss this dependency. Please uncomment or add the correct link command.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d3fc980 and 4aa941c.

📒 Files selected for processing (2)
  • CMake/ystdlib-config.cmake.in (1 hunks)
  • CMakeLists.txt (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
CMakeLists.txt (1)
Learnt from: Bill-hbrhbr
PR: y-scope/ystdlib-cpp#32
File: CMakeLists.txt:0-0
Timestamp: 2025-02-28T05:04:33.616Z
Learning: The y-scope/ystdlib-cpp project uses the "YSTDLIB_CPP_" prefix for project-specific CMake variables, following good naming convention practices.
🔇 Additional comments (18)
CMake/ystdlib-config.cmake.in (3)

1-4: Proper initialization of CMake package config.

Including CMakeFindDependencyMacro and invoking @PACKAGE_INIT@ is exactly what downstream consumers need to locate this package.


17-20: Correctly set and verify include directory and components.

Using set_and_check and check_required_components aligns with best practices in CMakePackageConfigHelpers.


21-24: Guard for multiple inclusion of targets file.

The if(NOT TARGET ystdlib::ystdlib) wrap prevents duplicate imports—this is spot on.

CMakeLists.txt (15)

4-7: Module path and helper includes are correct.

Appending CMake/ to CMAKE_MODULE_PATH and including ystdlib-cpp-helpers, CMakePackageConfigHelpers, and GNUInstallDirs is necessary for the later package‐config steps.


16-18: Build options follow established convention.

Defining BUILD_SHARED_LIBS and YSTDLIB_CPP_BUILD_TESTING is clear and consistent.


41-46: Export of compile commands is intentional.

Enabling CMAKE_EXPORT_COMPILE_COMMANDS with FORCE is useful for IDE integration and static analysis.


48-56: Top‐level dependency settings are correct.

Conditionally including your dependency settings and CTest only when this is the top‐level project is exactly right.


58-61: Test‐enable logic is clear.

Mapping BUILD_TESTING and YSTDLIB_CPP_BUILD_TESTING to YSTDLIB_CPP_ENABLE_TESTS is straightforward.


69-90: Catch2 test setup looks good.

All testing machinery (finding Catch2, setting up unified test target) is correctly gated by YSTDLIB_CPP_ENABLE_TESTS.


93-95: Installation directory variables are well defined.

YSTDLIB_INSTALL_CONFIG_DIR and YSTDLIB_INSTALL_INCLUDE_DIR correctly map to lib/cmake/ystdlib and the chosen include directory.


123-124: Linker language explicitly set.

Specifying LINKER_LANGUAGE CXX is correct for a C++ library.


132-137: Installation of the library target is correct.

Exporting ystdlib as ystdlib-targets is aligned with CMake package guidelines.


139-146: Export namespace and destination are set properly.

Using NAMESPACE ystdlib:: ensures downstream find_package(ystdlib) works as intended.


148-157: Header installation looks good.

Copying *.h, *.hpp, and *.tpp from src/ystdlib is appropriate.


159-166: Package configuration generation is correct.

The call to configure_package_config_file with PATH_VARS YSTDLIB_INSTALL_INCLUDE_DIR matches the template.


168-172: Version file creation is correct.

Using SameMajorVersion compatibility is sensible for a 0.x library.


174-180: Config files are installed to the right location.

Installing both the config and version files under ${YSTDLIB_INSTALL_CONFIG_DIR} enables clean downstream find_package.


182-183: Verify no source duplication via add_subdirectory.

You glob all sources under src/ to create ystdlib, then add src/ystdlib again as a subdirectory. This can lead to duplicate targets or conflicting CMakeLists. Please confirm whether add_subdirectory(src/ystdlib) is still required in this context.

Comment on lines +5 to +7
if(@Catch2_FOUND@)
find_dependency(Catch2)
endif()
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Consider pinning Catch2 version in find_dependency.

Currently you only invoke:

if(@Catch2_FOUND@)
    find_dependency(Catch2)
endif()

It’s more robust to propagate the same version you used when building, e.g.:

-if(@Catch2_FOUND@)
-    find_dependency(Catch2)
+if(@Catch2_FOUND@)
+    find_dependency(Catch2 @Catch2_VERSION@ REQUIRED)
endif()

This guards against incompatible Catch2 releases in downstream projects.

🤖 Prompt for AI Agents
In CMake/ystdlib-config.cmake.in around lines 5 to 7, the find_dependency call
for Catch2 does not specify a version, which can lead to incompatible versions
being used downstream. Modify the find_dependency(Catch2) call to include the
exact version of Catch2 that was used during the build by passing the version
variable or string, ensuring consistent and compatible Catch2 versions in
downstream projects.

Comment on lines +9 to +11
if(@outcome_FOUND@)
find_dependency(outcome)
endif()
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Optional: add version constraint for outcome.

Similar to Catch2, you may want to require the same outcome version downstream. For example:

-if(@outcome_FOUND@)
-    find_dependency(outcome)
+if(@outcome_FOUND@)
+    find_dependency(outcome @outcome_VERSION@ REQUIRED)
endif()

This helps ensure ABI compatibility.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if(@outcome_FOUND@)
find_dependency(outcome)
endif()
if(@outcome_FOUND@)
find_dependency(outcome @outcome_VERSION@ REQUIRED)
endif()
🤖 Prompt for AI Agents
In CMake/ystdlib-config.cmake.in around lines 9 to 11, the find_dependency call
for outcome lacks a version constraint. Modify the find_dependency(outcome) line
to include a version requirement that matches the version used by your project,
similar to how it is done for Catch2. This ensures downstream consumers use a
compatible outcome version and maintain ABI compatibility.

CMakeLists.txt Outdated
Comment on lines 106 to 109
# target_link_libraries(ystdlib
# PUBLIC
# outcome
# )
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Uncomment and correct outcome linkage.

The commented block:

# target_link_libraries(ystdlib
#     PUBLIC
#     outcome
# )

should be activated and refer to the proper target name:

-# target_link_libraries(ystdlib
-#     PUBLIC
-#     outcome
-# )
+target_link_libraries(ystdlib
+    PUBLIC
+    outcome::outcome
+)

This is critical for correct downstream linking.

🤖 Prompt for AI Agents
In CMakeLists.txt around lines 106 to 109, uncomment the target_link_libraries
block for ystdlib and ensure the linked target name is correct. Replace
"outcome" with the proper target name as defined in your project or
dependencies, then activate the block so ystdlib correctly links to that target
for proper downstream linkage.

CMakeLists.txt Outdated
Comment on lines 119 to 121
target_compile_features(ystdlib
PRIVATE cxx_std_20
)
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Propagate C++20 requirement to consumers.

Using PRIVATE cxx_std_20 hides the requirement from downstream targets. Change to PUBLIC so consumers compile with C++20 as well:

-target_compile_features(ystdlib
-    PRIVATE cxx_std_20
-)
+target_compile_features(ystdlib
+    PUBLIC cxx_std_20
+)

Otherwise headers using C++20 features may break in client code.

🤖 Prompt for AI Agents
In CMakeLists.txt around lines 119 to 121, the target_compile_features uses
PRIVATE for cxx_std_20, which hides the C++20 requirement from downstream
consumers. Change PRIVATE to PUBLIC so that the C++20 standard requirement is
propagated to all targets that link against ystdlib, ensuring client code
compiling with these headers also uses C++20.

CMakeLists.txt Outdated
Comment on lines 11 to 14
project(YSTDLIB_CPP
VERSION "${YSTDLIB_CPP_VERSION}"
LANGUAGES CXX
)
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Project name vs. package name mismatch.

You declare:

project(YSTDLIB_CPP
    VERSION "${YSTDLIB_CPP_VERSION}"
    LANGUAGES CXX
)

but the generated package is called ystdlib. Consider renaming the project to ystdlib (or aligning the package name) to avoid confusion when users do find_package(ystdlib).

🤖 Prompt for AI Agents
In CMakeLists.txt around lines 11 to 14, the project name is set to YSTDLIB_CPP,
but the generated package is named ystdlib, causing a mismatch. Rename the
project from YSTDLIB_CPP to ystdlib to align the project name with the package
name, ensuring consistency and avoiding confusion when users call
find_package(ystdlib).

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 662e768 and 93c4d50.

📒 Files selected for processing (1)
  • src/ystdlib/error_handling/test/test_ErrorCode.cpp (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ` rather than `!`.

**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}: - Prefer false == <expression> rather than !<expression>.

  • src/ystdlib/error_handling/test/test_ErrorCode.cpp

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (3)
CMakeLists.txt (3)

11-14: 🛠️ Refactor suggestion

Inconsistent project name vs package name
The project is declared as YSTDLIB_CPP but all install paths and the export namespace use ystdlib. This mismatch can confuse downstream users calling find_package(ystdlib). Consider renaming the project to ystdlib (or vice versa) to align naming.

Apply this diff:

- project(YSTDLIB_CPP
+ project(ystdlib
     VERSION "${YSTDLIB_CPP_VERSION}"
     LANGUAGES CXX
 )

113-115: 🛠️ Refactor suggestion

Propagate C++20 requirement to consumers
PRIVATE cxx_std_20 hides the C++ standard requirement from downstream targets. Change to PUBLIC cxx_std_20 so any project linking against ystdlib will also compile with C++20.

-target_compile_features(ystdlib
-    PRIVATE cxx_std_20
-)
+target_compile_features(ystdlib
+    PUBLIC cxx_std_20
+)

96-102: ⚠️ Potential issue

Regex for excluding test files is incorrect
The current regex ".*test_*\..*" does not properly match filenames like test_foo.cpp. Update to:

- list(FILTER SOURCE_FILES EXCLUDE REGEX ".*test_*\..*")
+ list(FILTER SOURCE_FILES EXCLUDE REGEX ".*test_.*\\..*")

This ensures any file starting with test_ is filtered out.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 93c4d50 and 0a88c49.

📒 Files selected for processing (1)
  • CMakeLists.txt (2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: Bill-hbrhbr
PR: y-scope/ystdlib-cpp#32
File: CMakeLists.txt:0-0
Timestamp: 2025-02-28T05:04:33.616Z
Learning: The y-scope/ystdlib-cpp project uses the "YSTDLIB_CPP_" prefix for project-specific CMake variables, following good naming convention practices.
CMakeLists.txt (1)
Learnt from: Bill-hbrhbr
PR: y-scope/ystdlib-cpp#32
File: CMakeLists.txt:0-0
Timestamp: 2025-02-28T05:04:33.616Z
Learning: The y-scope/ystdlib-cpp project uses the "YSTDLIB_CPP_" prefix for project-specific CMake variables, following good naming convention practices.
🔇 Additional comments (8)
CMakeLists.txt (8)

4-7: Good addition of CMake helper modules
Appending the local CMake directory to CMAKE_MODULE_PATH and including CMakePackageConfigHelpers and GNUInstallDirs correctly equips the project for package configuration and standard install-directory variables.


104-106: Correct creation of library and alias
The add_library(ystdlib ${SOURCE_FILES}) and the subsequent alias add_library(ystdlib::ystdlib ALIAS ystdlib) properly define both the target and its public namespace.


107-112: Include directories are well defined
Using PUBLIC $<BUILD_INTERFACE:…> and PUBLIC $<INSTALL_INTERFACE:…> sets up clean include paths for both build-time and install-time usage.


126-133: Export namespace installation is correct
The install(EXPORT ystdlib-targets NAMESPACE ystdlib:: DESTINATION ${YSTDLIB_INSTALL_CONFIG_DIR}) ensures downstream find_package(ystdlib) can locate your targets.


135-144: Header installation matches expectations
Installing the src/ystdlib directory with FILES_MATCHING patterns for .h, .hpp, and .tpp correctly delivers public headers.


146-153: Package config generation is correct
The configure_package_config_file invocation properly generates ystdlib-config.cmake for downstream consumers to locate dependencies and targets.


155-159: Version file generation is correct
The write_basic_package_version_file with SameMajorVersion provides necessary version compatibility semantics.


161-167: Installation of generated config files is correct
Installing both the config and version files into ${YSTDLIB_INSTALL_CONFIG_DIR} completes the package setup for find_package.

CMakeLists.txt Outdated
Comment on lines 119 to 124
install(
TARGETS
ystdlib
EXPORT
ystdlib-targets
)
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Specify explicit install destinations for target types
The default install locations may not cover all target types. It’s best practice to specify ARCHIVE, LIBRARY, and RUNTIME destinations. For example:

 install(TARGETS ystdlib
-    EXPORT ystdlib-targets
+    EXPORT ystdlib-targets
+    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
 )
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
install(
TARGETS
ystdlib
EXPORT
ystdlib-targets
)
install(
TARGETS
ystdlib
EXPORT
ystdlib-targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
🤖 Prompt for AI Agents
In CMakeLists.txt around lines 119 to 124, the install command for the ystdlib
target lacks explicit destination paths for ARCHIVE, LIBRARY, and RUNTIME target
types. Update the install() call to specify these destinations explicitly to
ensure proper installation locations for all target types, improving clarity and
portability of the build configuration.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (4)
CMakeLists.txt (4)

120-120: 🧹 Nitpick (assertive)

Specify explicit install destinations
It’s best practice to define explicit destinations for archives, shared libraries, and executables in install(TARGETS ...) to ensure consistent install layouts across platforms. For example:

 install(TARGETS ystdlib EXPORT ystdlib-targets
-)
+    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+)

111-111: ⚠️ Potential issue

Propagate C++20 requirement to consumers
The current visibility is PRIVATE, which hides the C++20 requirement from downstream targets and may lead to compilation errors in client code. Change to PUBLIC so that any project linking against ystdlib also uses C++20:

- target_compile_features(ystdlib PRIVATE cxx_std_20)
+ target_compile_features(ystdlib PUBLIC  cxx_std_20)

124-135: 🛠️ Refactor suggestion

Update include install path variable
After renaming to YSTDLIB_CPP_INSTALL_INCLUDE_DIR, update the install(DIRECTORY ...) call accordingly to maintain consistency:

-    DESTINATION "${YSTDLIB_INSTALL_INCLUDE_DIR}"
+    DESTINATION "${YSTDLIB_CPP_INSTALL_INCLUDE_DIR}"

99-99: ⚠️ Potential issue

Fix test file exclusion regex
The current regex ".*test_*\..*" does not exclude files like test_foo.cpp (the * quantifier applies to _, and the \. is placed too early). Update to properly filter out any file beginning with test_. For example:

- list(FILTER SOURCE_FILES EXCLUDE REGEX ".*test_*\\..*")
+ list(FILTER SOURCE_FILES EXCLUDE REGEX ".*test_.*\\..*")
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0a88c49 and e4dc708.

📒 Files selected for processing (1)
  • CMakeLists.txt (2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: Bill-hbrhbr
PR: y-scope/ystdlib-cpp#32
File: CMakeLists.txt:0-0
Timestamp: 2025-02-28T05:04:33.616Z
Learning: The y-scope/ystdlib-cpp project uses the "YSTDLIB_CPP_" prefix for project-specific CMake variables, following good naming convention practices.
CMakeLists.txt (1)
Learnt from: Bill-hbrhbr
PR: y-scope/ystdlib-cpp#32
File: CMakeLists.txt:0-0
Timestamp: 2025-02-28T05:04:33.616Z
Learning: The y-scope/ystdlib-cpp project uses the "YSTDLIB_CPP_" prefix for project-specific CMake variables, following good naming convention practices.
🔇 Additional comments (8)
CMakeLists.txt (8)

5-6: Include modules for package configuration and standard dirs
Including CMakePackageConfigHelpers and GNUInstallDirs is correct and necessary to support configure_package_config_file, version file generation, and standard installation directory variables.


92-98: Enable reconfigure on new sources
Using CONFIGURE_DEPENDS with file(GLOB_RECURSE ...) is good practice, as it triggers CMake reconfiguration when source files are added or removed.


101-102: Define library and alias target
The add_library(ystdlib ${SOURCE_FILES}) and alias add_library(ystdlib::ystdlib ALIAS ystdlib) are correctly configured for downstream CMake consumption.


104-109: Expose include directories properly
Setting the include directories as PUBLIC with BUILD_INTERFACE and INSTALL_INTERFACE is the right approach to ensure consumers see the correct headers both in-tree and from an installed package.


122-122: Export namespace installation
Installing the export under the ystdlib:: namespace correctly aligns the build-tree and install-tree usage for find_package(ystdlib).


137-143: Configure package config file
The use of configure_package_config_file with ystdlib-config.cmake.in and specifying PATH_VARS for the include dir is correctly set up for downstream package discovery.


145-148: Write package version file
Generating the version file with SameMajorVersion compatibility ensures consumers can check version constraints appropriately.


150-155: Install package config files
Installing both ystdlib-config.cmake and ystdlib-config-version.cmake into the config directory completes the exported CMake package layout.

Comment on lines +89 to +91
set(YSTDLIB_INSTALL_CONFIG_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/ystdlib)
set(YSTDLIB_INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR})

Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use consistent variable prefix
Project-specific variables should use the YSTDLIB_CPP_ prefix according to project conventions. Rename:

  • YSTDLIB_INSTALL_CONFIG_DIRYSTDLIB_CPP_INSTALL_CONFIG_DIR
  • YSTDLIB_INSTALL_INCLUDE_DIRYSTDLIB_CPP_INSTALL_INCLUDE_DIR
🤖 Prompt for AI Agents
In CMakeLists.txt around lines 89 to 91, the variables
YSTDLIB_INSTALL_CONFIG_DIR and YSTDLIB_INSTALL_INCLUDE_DIR do not follow the
project naming convention. Rename these variables to use the YSTDLIB_CPP_
prefix, changing them to YSTDLIB_CPP_INSTALL_CONFIG_DIR and
YSTDLIB_CPP_INSTALL_INCLUDE_DIR respectively, to maintain consistent variable
naming across the project.


set(YSTDLIB_CPP_VERSION "0.0.1" CACHE STRING "Project version.")

project(YSTDLIB_CPP VERSION "${YSTDLIB_CPP_VERSION}" LANGUAGES CXX)
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Align project name with package name
The project is declared as YSTDLIB_CPP, but the exported package and namespace are ystdlib. This mismatch can confuse downstream users invoking find_package(ystdlib). Consider renaming the project to ystdlib or adjusting the package name to match.

🤖 Prompt for AI Agents
In CMakeLists.txt at line 10, the project name is set to YSTDLIB_CPP, which does
not match the exported package and namespace name ystdlib. To fix this, rename
the project to ystdlib so that the project declaration aligns with the package
name used in find_package calls, ensuring consistency and avoiding confusion for
downstream users.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

♻️ Duplicate comments (2)
CMake/ystdlib-config.cmake.in (2)

7-9: Pin Catch2 version in find_dependency
Please propagate the Catch2 version to downstream by specifying:

-if(@Catch2_FOUND@)
-    find_dependency(Catch2)
+if(@Catch2_FOUND@)
+    find_dependency(Catch2 @Catch2_VERSION@ REQUIRED)
endif()

11-13: Pin outcome version in find_dependency
Similarly, include the outcome version constraint:

-if(@outcome_FOUND@)
-    find_dependency(outcome)
+if(@outcome_FOUND@)
+    find_dependency(outcome @outcome_VERSION@ REQUIRED)
endif()
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e4dc708 and a3bc9d5.

📒 Files selected for processing (1)
  • CMake/ystdlib-config.cmake.in (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: Bill-hbrhbr
PR: y-scope/ystdlib-cpp#32
File: CMakeLists.txt:0-0
Timestamp: 2025-02-28T05:04:33.616Z
Learning: The y-scope/ystdlib-cpp project uses the "YSTDLIB_CPP_" prefix for project-specific CMake variables, following good naming convention practices.
🔇 Additional comments (3)
CMake/ystdlib-config.cmake.in (3)

5-6: Initialise package version correctly
The @PACKAGE_INIT@ placeholder should remain directly after the include directives to load the version file and initialize the package.


17-17: Verify required components specification
Confirm that check_required_components(ystdlib) enforces the correct set of components. If your library defines named components (e.g., Core, Extras), consider listing them explicitly:

check_required_components(ystdlib Core Extras)

23-23: Re-enable gersemi linting
The # gersemi: on directive correctly resumes linting for downstream edits.

Comment on lines +1 to +3
# gersemi: off
# this file is preprocessed and should not be linted like a CMake file
include(CMakeFindDependencyMacro)
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Include CMakePackageConfigHelpers for config helpers
To ensure the macros set_and_check and check_required_components are available, add

include(CMakePackageConfigHelpers)

immediately after include(CMakeFindDependencyMacro), or verify that @PACKAGE_INIT@ injects it.

🤖 Prompt for AI Agents
In CMake/ystdlib-config.cmake.in at lines 1 to 3, the file includes
CMakeFindDependencyMacro but does not include CMakePackageConfigHelpers, which
provides the macros set_and_check and check_required_components. To fix this,
add the line include(CMakePackageConfigHelpers) immediately after the
include(CMakeFindDependencyMacro) line, or verify that the @PACKAGE_INIT@
variable injects this include; if not, explicitly add the include to ensure
these macros are available.

find_dependency(outcome)
endif()

set_and_check(ystdlib_INCLUDE_DIR "@PACKAGE_YSTDLIB_INSTALL_INCLUDE_DIR@")
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Use consistent variable prefix for include directory
Based on the project convention (YSTDLIB_CPP_ prefix for CMake variables), rename ystdlib_INCLUDE_DIR to:

-set_and_check(ystdlib_INCLUDE_DIR "@PACKAGE_YSTDLIB_INSTALL_INCLUDE_DIR@")
+set_and_check(YSTDLIB_CPP_INCLUDE_DIR "@PACKAGE_YSTDLIB_INSTALL_INCLUDE_DIR@")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
set_and_check(ystdlib_INCLUDE_DIR "@PACKAGE_YSTDLIB_INSTALL_INCLUDE_DIR@")
-set_and_check(ystdlib_INCLUDE_DIR "@PACKAGE_YSTDLIB_INSTALL_INCLUDE_DIR@")
+set_and_check(YSTDLIB_CPP_INCLUDE_DIR "@PACKAGE_YSTDLIB_INSTALL_INCLUDE_DIR@")
🤖 Prompt for AI Agents
In CMake/ystdlib-config.cmake.in at line 15, rename the variable
ystdlib_INCLUDE_DIR to use the project convention prefix YSTDLIB_CPP_, changing
it to YSTDLIB_CPP_INCLUDE_DIR for consistency with other CMake variables.

Comment on lines +20 to +22
if(NOT TARGET ystdlib::ystdlib)
include(${CMAKE_CURRENT_LIST_DIR}/ystdlib-targets.cmake)
endif()
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Quote include path for robustness
Wrap the path in quotes to guard against spaces in CMAKE_CURRENT_LIST_DIR:

-if(NOT TARGET ystdlib::ystdlib)
-    include(${CMAKE_CURRENT_LIST_DIR}/ystdlib-targets.cmake)
+if(NOT TARGET ystdlib::ystdlib)
+    include("${CMAKE_CURRENT_LIST_DIR}/ystdlib-targets.cmake")
endif()
🤖 Prompt for AI Agents
In CMake/ystdlib-config.cmake.in around lines 20 to 22, the include statement
uses an unquoted path which can cause issues if CMAKE_CURRENT_LIST_DIR contains
spaces. Fix this by wrapping the path in double quotes to ensure the include
directive handles paths with spaces correctly.

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.

1 participant