-
Notifications
You must be signed in to change notification settings - Fork 6
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
base: main
Are you sure you want to change the base?
Conversation
WalkthroughA comprehensive CMake package configuration was introduced for the ystdlib-cpp project. This includes a new Changes
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
Possibly related PRs
Suggested reviewers
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 issueLink to
outcome
is missing.You
find_package(outcome REQUIRED)
but do not actually link it intoystdlib
. 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
📒 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
andcheck_required_components
aligns with best practices inCMakePackageConfigHelpers
.
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/
toCMAKE_MODULE_PATH
and includingystdlib-cpp-helpers
,CMakePackageConfigHelpers
, andGNUInstallDirs
is necessary for the later package‐config steps.
16-18
: Build options follow established convention.Defining
BUILD_SHARED_LIBS
andYSTDLIB_CPP_BUILD_TESTING
is clear and consistent.
41-46
: Export of compile commands is intentional.Enabling
CMAKE_EXPORT_COMPILE_COMMANDS
withFORCE
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
andYSTDLIB_CPP_BUILD_TESTING
toYSTDLIB_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
andYSTDLIB_INSTALL_INCLUDE_DIR
correctly map tolib/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
asystdlib-targets
is aligned with CMake package guidelines.
139-146
: Export namespace and destination are set properly.Using
NAMESPACE ystdlib::
ensures downstreamfind_package(ystdlib)
works as intended.
148-157
: Header installation looks good.Copying
*.h
,*.hpp
, and*.tpp
fromsrc/ystdlib
is appropriate.
159-166
: Package configuration generation is correct.The call to
configure_package_config_file
withPATH_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 downstreamfind_package
.
182-183
: Verify no source duplication viaadd_subdirectory
.You glob all sources under
src/
to createystdlib
, then addsrc/ystdlib
again as a subdirectory. This can lead to duplicate targets or conflicting CMakeLists. Please confirm whetheradd_subdirectory(src/ystdlib)
is still required in this context.
if(@Catch2_FOUND@) | ||
find_dependency(Catch2) | ||
endif() |
There was a problem hiding this comment.
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.
if(@outcome_FOUND@) | ||
find_dependency(outcome) | ||
endif() |
There was a problem hiding this comment.
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.
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
# target_link_libraries(ystdlib | ||
# PUBLIC | ||
# outcome | ||
# ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
target_compile_features(ystdlib | ||
PRIVATE cxx_std_20 | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
project(YSTDLIB_CPP | ||
VERSION "${YSTDLIB_CPP_VERSION}" | ||
LANGUAGES CXX | ||
) |
There was a problem hiding this comment.
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).
There was a problem hiding this 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
📒 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}
: - Preferfalse == <expression>
rather than!<expression>
.
src/ystdlib/error_handling/test/test_ErrorCode.cpp
There was a problem hiding this 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 suggestionInconsistent project name vs package name
The project is declared asYSTDLIB_CPP
but all install paths and the export namespace useystdlib
. This mismatch can confuse downstream users callingfind_package(ystdlib)
. Consider renaming the project toystdlib
(or vice versa) to align naming.Apply this diff:
- project(YSTDLIB_CPP + project(ystdlib VERSION "${YSTDLIB_CPP_VERSION}" LANGUAGES CXX )
113-115
: 🛠️ Refactor suggestionPropagate C++20 requirement to consumers
PRIVATE cxx_std_20
hides the C++ standard requirement from downstream targets. Change toPUBLIC cxx_std_20
so any project linking againstystdlib
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 issueRegex for excluding test files is incorrect
The current regex".*test_*\..*"
does not properly match filenames liketest_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
📒 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 localCMake
directory toCMAKE_MODULE_PATH
and includingCMakePackageConfigHelpers
andGNUInstallDirs
correctly equips the project for package configuration and standard install-directory variables.
104-106
: Correct creation of library and alias
Theadd_library(ystdlib ${SOURCE_FILES})
and the subsequent aliasadd_library(ystdlib::ystdlib ALIAS ystdlib)
properly define both the target and its public namespace.
107-112
: Include directories are well defined
UsingPUBLIC $<BUILD_INTERFACE:…>
andPUBLIC $<INSTALL_INTERFACE:…>
sets up clean include paths for both build-time and install-time usage.
126-133
: Export namespace installation is correct
Theinstall(EXPORT ystdlib-targets NAMESPACE ystdlib:: DESTINATION ${YSTDLIB_INSTALL_CONFIG_DIR})
ensures downstreamfind_package(ystdlib)
can locate your targets.
135-144
: Header installation matches expectations
Installing thesrc/ystdlib
directory withFILES_MATCHING
patterns for.h
,.hpp
, and.tpp
correctly delivers public headers.
146-153
: Package config generation is correct
Theconfigure_package_config_file
invocation properly generatesystdlib-config.cmake
for downstream consumers to locate dependencies and targets.
155-159
: Version file generation is correct
Thewrite_basic_package_version_file
withSameMajorVersion
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 forfind_package
.
CMakeLists.txt
Outdated
install( | ||
TARGETS | ||
ystdlib | ||
EXPORT | ||
ystdlib-targets | ||
) |
There was a problem hiding this comment.
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.
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.
There was a problem hiding this 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 ininstall(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 issuePropagate C++20 requirement to consumers
The current visibility isPRIVATE
, which hides the C++20 requirement from downstream targets and may lead to compilation errors in client code. Change toPUBLIC
so that any project linking againstystdlib
also uses C++20:- target_compile_features(ystdlib PRIVATE cxx_std_20) + target_compile_features(ystdlib PUBLIC cxx_std_20)
124-135
: 🛠️ Refactor suggestionUpdate include install path variable
After renaming toYSTDLIB_CPP_INSTALL_INCLUDE_DIR
, update theinstall(DIRECTORY ...)
call accordingly to maintain consistency:- DESTINATION "${YSTDLIB_INSTALL_INCLUDE_DIR}" + DESTINATION "${YSTDLIB_CPP_INSTALL_INCLUDE_DIR}"
99-99
:⚠️ Potential issueFix test file exclusion regex
The current regex".*test_*\..*"
does not exclude files liketest_foo.cpp
(the*
quantifier applies to_
, and the\.
is placed too early). Update to properly filter out any file beginning withtest_
. 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
📒 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
IncludingCMakePackageConfigHelpers
andGNUInstallDirs
is correct and necessary to supportconfigure_package_config_file
, version file generation, and standard installation directory variables.
92-98
: Enable reconfigure on new sources
UsingCONFIGURE_DEPENDS
withfile(GLOB_RECURSE ...)
is good practice, as it triggers CMake reconfiguration when source files are added or removed.
101-102
: Define library and alias target
Theadd_library(ystdlib ${SOURCE_FILES})
and aliasadd_library(ystdlib::ystdlib ALIAS ystdlib)
are correctly configured for downstream CMake consumption.
104-109
: Expose include directories properly
Setting the include directories asPUBLIC
withBUILD_INTERFACE
andINSTALL_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 theystdlib::
namespace correctly aligns the build-tree and install-tree usage forfind_package(ystdlib)
.
137-143
: Configure package config file
The use ofconfigure_package_config_file
withystdlib-config.cmake.in
and specifyingPATH_VARS
for the include dir is correctly set up for downstream package discovery.
145-148
: Write package version file
Generating the version file withSameMajorVersion
compatibility ensures consumers can check version constraints appropriately.
150-155
: Install package config files
Installing bothystdlib-config.cmake
andystdlib-config-version.cmake
into the config directory completes the exported CMake package layout.
set(YSTDLIB_INSTALL_CONFIG_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/ystdlib) | ||
set(YSTDLIB_INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR}) | ||
|
There was a problem hiding this comment.
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_DIR
→YSTDLIB_CPP_INSTALL_CONFIG_DIR
YSTDLIB_INSTALL_INCLUDE_DIR
→YSTDLIB_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) |
There was a problem hiding this comment.
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.
There was a problem hiding this 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
📒 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 thatcheck_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.
# gersemi: off | ||
# this file is preprocessed and should not be linted like a CMake file | ||
include(CMakeFindDependencyMacro) |
There was a problem hiding this comment.
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@") |
There was a problem hiding this comment.
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.
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.
if(NOT TARGET ystdlib::ystdlib) | ||
include(${CMAKE_CURRENT_LIST_DIR}/ystdlib-targets.cmake) | ||
endif() |
There was a problem hiding this comment.
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.
Description
Provides necessary configurations so that dependent projects can use this project as a library rather than a subproject.
Checklist
breaking change.
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