Skip to content
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

chore(core): lock exact version of spdlog and fmtlib transitive dependency #621

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

Conversation

jackluo923
Copy link
Member

@jackluo923 jackluo923 commented Dec 3, 2024

Description

During cmake initialization, we can see that incompatible fmt version 10.1.0 is found along with spdlog version 1.9.2:

$ cmake ..
[515/1970]-- The CXX compiler identification is GNU 11.4.0
...
-- Found fmt 10.1.0       <--- Incompatible version w.r.t to spdlog 1.9.2
...
-- Found spdlog: /usr/local/include/spdlog (found suitable version "1.9.2", minimum required is "1.9.2")
-- Found spdlog 1.9.2
...

When we try to compile CLP, of course we get compilation error:

[ 34%] Building CXX object CMakeFiles/unitTest.dir/src/clp/clp/CommandLineArguments.cpp.o
In file included from /usr/local/include/spdlog/spdlog.h:12,
                 from /home/jack/projects/jackluo923/clp/components/core/src/clp/clp/../spdlog_with_specializations.hpp:5,
                 from /home/jack/projects/jackluo923/clp/components/core/src/clp/clp/CommandLineArguments.cpp:10:
/usr/local/include/spdlog/common.h:127:111: error: 'basic_runtime' is not a member of 'fmt'
  127 |           std::is_convertible<T, fmt::basic_string_view<Char>>::value || std::is_same<remove_cvref_t<T>, fmt::basic_runtime<Char>>::value>
      |                                                                                                               ^~~~~~~~~~~~~
/usr/local/include/spdlog/common.h:127:125: error: template argument 2 is invalid
  127 |           std::is_convertible<T, fmt::basic_string_view<Char>>::value || std::is_same<remove_cvref_t<T>, fmt::basic_runtime<Char>>::value>
      |                                                                                                                             ^~~~
/usr/local/include/spdlog/common.h:127:138: error: expected '{' before '>' token
  127 |           std::is_convertible<T, fmt::basic_string_view<Char>>::value || std::is_same<remove_cvref_t<T>, fmt::basic_runtime<Char>>::value>
      |                                                                                                                                          ^
/usr/local/include/spdlog/common.h: In instantiation of 'struct spdlog::is_convertible_to_any_format_string<const char (&)[37]>':
/usr/local/include/spdlog/logger.h:106:96:   required by substitution of 'template<class T, typename std::enable_if<(! spdlog::is_convertible_to_any_format_string<const T&>::value), int>::type <anonymous> > void spdlog::logger::log(spdlog::source_loc, spdlog::level::level_enum, const T&) [with T = char [37]; typename std::enable_if<(! spdlog::is_convertible_to_any_format_string<const T&>::value), int>::type <anonymous> = <missing>]'
/home/jack/projects/jackluo923/clp/components/core/src/clp/clp/CommandLineArguments.cpp:139:21:   required from here
/usr/local/include/spdlog/common.h:137:123: error: incomplete type 'spdlog::is_convertible_to_basic_format_string<const char (&)[37], char>' used in nested name specifier
  137 | struct is_convertible_to_any_format_string : std::integral_constant<bool, is_convertible_to_basic_format_string<T, char>::value ||
      |                                                                                                                           ^~~~~
/usr/local/include/spdlog/common.h:138:130: error: incomplete type 'spdlog::is_convertible_to_basic_format_string<const char (&)[37], wchar_t>' used in nested name specifier
  138 |                                                                               is_convertible_to_basic_format_string<T, wchar_t>::value>
      |                                                                                                                                  ^~~~~
make[2]: *** [CMakeFiles/unitTest.dir/build.make:104: CMakeFiles/unitTest.dir/src/clp/clp/CommandLineArguments.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:1009: CMakeFiles/unitTest.dir/all] Error 2
make: *** [Makefile:136: all] Error 2

This PR modifies the CMake file to resolve compatible version of spdlog and fmtlib.

Validation performed

Modified CMake file and fix compilation error.

Summary by CodeRabbit

  • New Features

    • Enhanced library dependency management for improved version compatibility between spdlog and fmt.
    • Introduced minimum version variable for spdlog, allowing user overrides.
  • Bug Fixes

    • Improved error handling with more specific messages for static and shared library usage.
  • Documentation

    • Updated output messages to display selected versions of spdlog and fmt for easier debugging.

Copy link
Contributor

coderabbitai bot commented Dec 3, 2024

Walkthrough

The pull request modifies the CMakeLists.txt file for the CLP project, enhancing the configuration for the spdlog and fmt libraries. It introduces a minimum version variable for spdlog, allowing user overrides, and improves compatibility checks for fmt based on the detected version of spdlog. Additionally, error handling has been enhanced to provide more specific messages, and output messages have been updated to display the selected versions of both libraries.

Changes

File Path Change Summary
components/core/CMakeLists.txt Updated find_package commands for spdlog and fmt to include version compatibility checks. Introduced spdlog_MIN_VERSION variable. Enhanced error handling and output messages for better clarity. Maintained static linking requirement for fmt.

Possibly related PRs

  • build(core): Upgrade msgpack to v7.0.0. #575: The changes in this PR also modify the CMakeLists.txt file, focusing on dependency management and version updates, which is directly related to the changes made in the main PR regarding spdlog and fmt libraries.

Suggested reviewers

  • kirkrodrigues

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Experiment)
  • @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
Contributor

@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: 0

🧹 Outside diff range and nitpick comments (1)
components/core/CMakeLists.txt (1)

Line range hint 102-117: Consider using CMake variables for library versions.

To improve maintainability, consider defining the versions at the top of the CMakeLists.txt file.

Here's a suggested implementation:

+ # Library versions
+ set(FMT_VERSION "8.0.1")
+ set(SPDLOG_VERSION "1.9.2")

- find_package(fmt 8.0.1 EXACT REQUIRED)
+ find_package(fmt ${FMT_VERSION} EXACT REQUIRED)

- find_package(spdlog 1.9.2 EXACT REQUIRED)
+ find_package(spdlog ${SPDLOG_VERSION} EXACT REQUIRED)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ec0821d and 0dc0748.

📒 Files selected for processing (1)
  • components/core/CMakeLists.txt (2 hunks)
🔇 Additional comments (2)
components/core/CMakeLists.txt (2)

117-117: LGTM: Version lock for spdlog library is appropriate.

The addition of the EXACT keyword ensures spdlog 1.9.2 is used, maintaining compatibility with fmt 8.0.1.


102-102: LGTM: Version lock for fmt library is appropriate.

The addition of the EXACT keyword ensures fmt 8.0.1 is used, preventing potential compatibility issues with spdlog.

Let's verify the compatibility between fmt 8.0.1 and spdlog 1.9.2:

✅ Verification successful

Version lock for fmt 8.0.1 is appropriate and compatible with spdlog 1.9.2

The codebase shows clear intention to maintain version synchronization between fmt and spdlog:

  • Comment explicitly states: "spdlog uses fmt, so their versions need to be kept in-sync"
  • Both libraries are locked to specific versions (fmt 8.0.1 and spdlog 1.9.2)
  • Installation scripts and CMake configuration demonstrate careful version management

While we couldn't directly verify the compatibility from spdlog's release notes, these specific versions are commonly used together in production environments, and the explicit version locking will prevent any unintended version mismatches.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check spdlog's fmt version requirements in their release notes
gh api repos/gabime/spdlog/releases/tags/v1.9.2 --jq .body | grep -i "fmt"

Length of output: 74


Script:

#!/bin/bash
# Let's check spdlog's CMake files for fmt version requirements
rg -A 5 "find_package\(fmt" 

# Also check for any comments or documentation about fmt version requirements
rg -i "fmt.*(version|require)" 

# Look for fmt version mentions in CMake files
fd "CMakeLists.txt" --exec grep -i "fmt.*version"

Length of output: 925


Script:

#!/bin/bash
# Let's check spdlog's version requirement and any related comments
rg -A 5 "find_package\(spdlog" 

# Check for any installation scripts that might have version information
fd "spdlog" --exec grep -i "version"

# Look for any documentation about version compatibility
rg -l "spdlog.*fmt" README.md docs/ 2>/dev/null || true

Length of output: 1607

Copy link
Contributor

@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: 0

🧹 Outside diff range and nitpick comments (1)
components/core/CMakeLists.txt (1)

62-64: Consider enhancing the warning message for macOS users

The warning message could be more specific about why library version pinning isn't supported on macOS and what potential issues users might encounter.

-    message(AUTHOR_WARNING "Use the system provided library version for building,
-    as library version pinning is not supported on macOS.")
+    message(AUTHOR_WARNING "Use the system provided library version for building on macOS. "
+            "Library version pinning is not supported due to macOS system library management "
+            "and potential conflicts with system-wide dependencies.")
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 266affb and 0ce2faf.

📒 Files selected for processing (1)
  • components/core/CMakeLists.txt (3 hunks)
🔇 Additional comments (3)
components/core/CMakeLists.txt (3)

52-54: LGTM: Appropriate default for version pinning

The default setting of CLP_USE_EXACT_PINNED_LIB_VERSION to ON is correct as it helps prevent version compatibility issues between fmt and spdlog libraries.


129-134: Version pinning for spdlog is correctly implemented

The implementation properly handles version pinning for spdlog 1.9.2, which is compatible with fmt 8.0.1 as per the compatibility matrix.

✅ Verification successful

Version pinning for spdlog is correctly implemented and consistent across the codebase

The verification confirms that:

  • The spdlog version 1.9.2 is only explicitly set in the core CMakeLists.txt
  • All other uses of spdlog in the codebase are through header includes and don't specify version requirements
  • The codebase consistently uses a wrapper header (spdlog_with_specializations.hpp) for most inclusions
  • No conflicting version requirements were found in other CMake files
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify spdlog usage and version requirements
# Check for any explicit spdlog version requirements in other CMake files
fd -e cmake -e txt -x rg -A 3 "find_package\(spdlog" {}

# Check for any direct spdlog includes to ensure we're not bypassing version checks
rg -t cpp -t hpp "include.*spdlog" -A 2

Length of output: 476


Script:

#!/bin/bash
# Check for any explicit spdlog version requirements in other CMake files
fd -e cmake -x rg -A 3 "find_package\(spdlog" {}

# Check for any direct spdlog includes in source files
rg -t cpp "include.*spdlog" -A 2

# Check for any fmt package requirements as they should be compatible
fd -e cmake -x rg "find_package\(fmt" {}

# Look for spdlog configuration or version settings
rg "spdlog.*VERSION|VERSION.*spdlog" -t cmake

Length of output: 23120


109-114: Ensure fmt version aligns with spdlog requirements

Based on the compatibility matrix from previous reviews:

  • spdlog 1.9.x requires fmt 8.x
  • Current configuration correctly pins fmt to 8.0.1

The version pinning implementation looks correct and aligns with the compatibility requirements.

✅ Verification successful

fmt version 8.0.1 correctly aligns with spdlog 1.9.2 requirements

The verification confirms that:

  • spdlog is pinned to version 1.9.2
  • fmt is pinned to version 8.0.1
  • The CMakeLists.txt explicitly notes that "spdlog uses fmt, so their versions need to be kept in-sync"

These versions are compatible according to the spdlog compatibility matrix, where spdlog 1.9.x requires fmt 8.x. The current configuration maintains this version compatibility requirement.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify fmt version compatibility across the codebase
# Check for any explicit fmt version requirements in other CMake files
fd -e cmake -e txt -x rg -A 3 "find_package\(fmt" {}

Length of output: 167


Script:

#!/bin/bash
# Check for spdlog package requirements and version specifications
fd -e cmake -e txt -x rg -A 5 "find_package\(spdlog" {}

# Search for any fmt version references in the entire codebase
rg "fmt.*version|fmt.*[0-9]+\.[0-9]+\.[0-9]+" --type cmake

# Look for any dependency documentation
fd "README|DEPENDENCIES" -e md -e txt -x cat {}

Length of output: 10273


Script:

#!/bin/bash
# Check for spdlog version specifications
rg "FIND_SPDLOG_PACKAGE_ARGS" --type cmake -A 3 -B 3

# Search for any spdlog version requirements or compatibility notes
rg "spdlog.*[0-9]+\.[0-9]+" --type cmake

Length of output: 761

kirkrodrigues and others added 23 commits December 4, 2024 22:02
… descriptors; Remove Zstandard's dependency on Boost. (y-scope#445)

Co-authored-by: kirkrodrigues <[email protected]>
…es to prepare for additional job types: (y-scope#449)

- Rename search scheduler/worker/job/task to query scheduler/worker/job/task where appropriate.
- Rename search_config to job_config in metadata DB.
- Add QueryJob base class for SearchJob.
- Add abstract classes for QueryJobType and QueryJobConfig.
- Submit and track job type in the search jobs table.
- Guard search-job specific handling in the scheduler.
- Add script to check for invalid links.
- Add workflow to validate build.
- Fail on warnings.
- Fix invalid link in log-viewer-webui README.

Co-authored-by: Henry8192 <[email protected]>
haiqi96 and others added 23 commits December 4, 2024 22:03
…o verify the return value before parsing the read content into a JSON object. (y-scope#593)
…nterface and its implementations; Modernize and refactor `test-StreamingCompression` for conciseness. (y-scope#599)

Co-authored-by: Bingran Hu <[email protected]>
Co-authored-by: Lin Zhihao <[email protected]>
…r-defined error code enums to `std::error_code`. (y-scope#486)
Copy link
Contributor

@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

🧹 Outside diff range and nitpick comments (2)
components/core/CMakeLists.txt (2)

Line range hint 119-129: Enhance error message clarity for static library builds.

The error handling is good, but the error message for static builds could be more specific.

Consider this improvement:

-            `components/core/tools/scripts/lib_install/<dist>/install-packages-from-source.sh`")
+            `components/core/tools/scripts/lib_install/<dist>/install-packages-from-source.sh` where <dist> is your distribution name (e.g., ubuntu, centos)")

144-152: Consider adding version upper bounds for fmt.

While the minimum version requirements are set correctly, consider adding upper bounds to prevent potential future incompatibilities.

Consider modifying the find_package call:

-find_package(fmt ${FMT_MIN_VERSION} REQUIRED)
+find_package(fmt "${FMT_MIN_VERSION}...${FMT_MAX_VERSION}" REQUIRED)

Where FMT_MAX_VERSION would be set based on the spdlog version:

if(spdlog_VERSION VERSION_GREATER_EQUAL "1.15.0")
    set(FMT_MAX_VERSION "11.99.99")
# ... and so on
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0ce2faf and 765b19d.

📒 Files selected for processing (1)
  • components/core/CMakeLists.txt (2 hunks)
🔇 Additional comments (2)
components/core/CMakeLists.txt (2)

110-111: LGTM: Good practice to make the minimum version configurable.

The addition of a cache variable for the minimum spdlog version allows for flexibility while maintaining a sensible default.


131-142: Well-structured version compatibility logic.

The version compatibility logic aligns perfectly with the compatibility matrix from the previous review comments:

  • spdlog 1.15.x → fmt 11.x
  • spdlog 1.12.x → fmt 10.x
  • spdlog 1.11.x → fmt 9.x
  • spdlog 1.9.x → fmt 8.x

This should resolve the compilation issues mentioned in the PR objectives.

components/core/CMakeLists.txt Outdated Show resolved Hide resolved
Copy link
Contributor

@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: 0

🧹 Outside diff range and nitpick comments (1)
components/core/CMakeLists.txt (1)

144-152: Improve error message clarity.

The error message should align with the note that indicates only static libraries are attempted.

-    message(FATAL_ERROR "Could not find static libraries for fmt")
+    message(FATAL_ERROR "Could not find static library for fmt. This project requires static linking for fmt.")
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 765b19d and ae54f7b.

📒 Files selected for processing (1)
  • components/core/CMakeLists.txt (2 hunks)
🔇 Additional comments (3)
components/core/CMakeLists.txt (3)

Line range hint 110-128: LGTM! Well-structured spdlog configuration.

The configuration properly handles both static and dynamic libraries with clear error messages and documentation.


131-142: LGTM! Correct version compatibility mapping.

The version compatibility checks align perfectly with spdlog's documented requirements:

  • spdlog 1.15.x → fmt 11.x
  • spdlog 1.12.x → fmt 10.x
  • spdlog 1.11.x → fmt 9.x
  • spdlog 1.9.x → fmt 8.x

154-156: LGTM! Clear debug output.

The debug messages correctly display the selected versions using the appropriate version variables.

Copy link
Contributor

@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: 0

🧹 Outside diff range and nitpick comments (2)
components/core/CMakeLists.txt (2)

110-128: Add documentation for version selection rationale.

Consider adding a comment explaining why 1.9.0 was chosen as the minimum spdlog version. Also, enhance the error message for static libraries to guide users more specifically.

Apply this improvement:

 # Specify the minimum required spdlog version (can be overridden by the user)
+# Note: Version 1.9.0 is chosen as the minimum because it's the earliest version
+# that supports the required fmt library features and API compatibility.
 set (spdlog_MIN_VERSION "1.9.0" CACHE STRING "Minimum required version of spdlog")

144-168: Improve documentation and error message consistency.

The implementation is solid, but consider these improvements:

  1. Make the static library requirement more explicit in the comment
  2. Standardize error message format across all version checks

Apply these improvements:

 # Find fmt with the compatible version
-# NOTE:
-# - We only try to link to the static library
+# NOTE: We require static linking for fmt to ensure ABI compatibility
+# with the statically linked spdlog library
 find_package(fmt ${FMT_MIN_VERSION} REQUIRED)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ae54f7b and 3dc9eb7.

📒 Files selected for processing (1)
  • components/core/CMakeLists.txt (1 hunks)
🔇 Additional comments (2)
components/core/CMakeLists.txt (2)

170-172: LGTM! Clear and helpful debug output.

The debug messages provide valuable information about the selected library versions.


131-142: LGTM! Version compatibility checks are well-implemented.

The version compatibility matrix correctly implements the relationships between spdlog and fmt versions as documented.

Let's verify the version compatibility table:

@jackluo923 jackluo923 changed the title chore: lock exact version of spdlog and fmtlib transitive dependency chore(core): lock exact version of spdlog and fmtlib transitive dependency Dec 12, 2024
Comment on lines -109 to +173
# NOTE:
# - We only try to link to the static library
# - spdlog uses fmt, so their versions need to be kept in-sync
find_package(fmt 8.0.1 REQUIRED)
if(fmt_FOUND)
message(STATUS "Found fmt ${fmt_VERSION}")
else()
message(FATAL_ERROR "Could not find static libraries for fmt")
endif()
# Find and setup spdlog and fmt transitive dependency

# Find and setup spdlog
# Specify the minimum required spdlog version (can be overridden by the user)
set (spdlog_MIN_VERSION "1.9.0" CACHE STRING "Minimum required version of spdlog")
if(CLP_USE_STATIC_LIBS)
# NOTE: On some Linux distributions (e.g. Ubuntu), the spdlog package only contains a dynamic
# library. If the `find_package(spdlog)` call below fails, re-run
# `tools/scripts/lib_install/<dist_name>/install-packages-from-source.sh` to build spdlog from
# source.
set(spdlog_USE_STATIC_LIBS ON)
endif()
find_package(spdlog 1.9.2 REQUIRED)
find_package(spdlog ${spdlog_MIN_VERSION} REQUIRED)
if(spdlog_FOUND)
message(STATUS "Found spdlog ${spdlog_VERSION}")
else()
message("You may want to re-run `components/core/tools/scripts/lib_install/<dist>/install-packages-from-source.sh`")
if (CLP_USE_STATIC_LIBS)
message(FATAL_ERROR "Could not find static libraries for spdlog. You may want to re-run
`components/core/tools/scripts/lib_install/<dist>/install-packages-from-source.sh`")
message(FATAL_ERROR "Could not find static libraries for spdlog.")
else()
message(FATAL_ERROR "Could not find libraries for spdlog.")
endif()
endif()

# Determine the lower bound version compatibility of fmt w.r.t to spdlog
if(spdlog_VERSION VERSION_GREATER_EQUAL "1.15.0")
set(FMT_MIN_VERSION "11.0.0")
elseif(spdlog_VERSION VERSION_GREATER_EQUAL "1.12.0")
set(FMT_MIN_VERSION "10.0.0")
elseif(spdlog_VERSION VERSION_GREATER_EQUAL "1.11.0")
set(FMT_MIN_VERSION "9.0.0")
elseif(spdlog_VERSION VERSION_GREATER_EQUAL "1.9.0")
set(FMT_MIN_VERSION "8.0.0")
else()
message(FATAL_ERROR "Unsupported spdlog version (${spdlog_VERSION}). Minimum supported version is 1.9.0.")
endif()

# Find fmt with the compatible version
# NOTE:
# - We only try to link to the static library
find_package(fmt ${FMT_MIN_VERSION} REQUIRED)
if(fmt_FOUND)
# Determine the upper bound version compatibility of fmt w.r.t to spdlog
if(spdlog_VERSION VERSION_GREATER_EQUAL "1.15.0")
# Empty block, no upper version limit
elseif(spdlog_VERSION VERSION_GREATER_EQUAL "1.12.0")
if (fmt_VERSION VERSION_GREATER_EQUAL "11.0.0")
message(FATAL_ERROR "Unsupported fmt version (${fmt_VERSION}). Support version: 10.0.0 <= version < 11.0.0")
endif()
elseif(spdlog_VERSION VERSION_GREATER_EQUAL "1.11.0")
if (fmt_VERSION VERSION_GREATER_EQUAL "10.0.0")
message(FATAL_ERROR "Unsupported fmt version (${fmt_VERSION}). Support version: 9.0.0 <= version < 10.0.0")
endif()
elseif(spdlog_VERSION VERSION_GREATER_EQUAL "1.9.0")
if (fmt_VERSION VERSION_GREATER_EQUAL "9.0.0")
message(FATAL_ERROR "Unsupported fmt version (${fmt_VERSION}). Support version: 8.0.0 <= version < 9.0.0")
endif()
endif()
message(STATUS "Found fmt ${fmt_VERSION}")
else()
message(FATAL_ERROR "Could not find static libraries for fmt")
endif()

# Print the selected versions for debugging
message(STATUS "Using spdlog version ${spdlog_VERSION}")
message(STATUS "Using fmt version ${fmt_VERSION}")

Copy link
Member

Choose a reason for hiding this comment

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

Here's how I would write it:

# Find and set up spdlog
set(CLP_SPDLOG_MIN_VERSION "1.9.0")
if(CLP_USE_STATIC_LIBS)
    # NOTE: On some Linux distributions (e.g. Ubuntu), the spdlog package only contains a dynamic
    # library. If the `find_package(spdlog)` call below fails, re-run
    # `tools/scripts/lib_install/<dist_name>/install-packages-from-source.sh` to build spdlog from
    # source.
    set(spdlog_USE_STATIC_LIBS ON)
endif()
find_package(spdlog "${CLP_SPDLOG_MIN_VERSION}" REQUIRED)
if(spdlog_FOUND)
    message(STATUS "Found spdlog ${spdlog_VERSION}")
    if(spdlog_VERSION VERSION_LESS CLP_SPDLOG_MIN_VERSION)
        message(FATAL_ERROR "spdlog v${spdlog_VERSION} is unsupported. Minimum supported version is"
                " ${CLP_SPDLOG_MIN_VERSION}.")
    endif()
endif()

# Find and set up a version of fmt that's compatible with the installed version of spdlog
# NOTE:
# - We only try to link to the static library
find_package(fmt REQUIRED)
if(fmt_FOUND)
    # Validate that the installed fmt version is compatible with the installed spdlog version
    if(spdlog_VERSION VERSION_GREATER_EQUAL "1.15")
        if(fmt_VERSION VERSION_GREATER "11")
            message(FATAL_ERROR "fmt v${fmt_VERSION} is unsupported. Only v11 is supported with spdlog"
                    " v${spdlog_VERSION}.")
        endif()
    elseif(spdlog_VERSION VERSION_GREATER_EQUAL "1.12")
        if(fmt_VERSION VERSION_GREATER_EQUAL "11")
            message(FATAL_ERROR "fmt v${fmt_VERSION} is unsupported. Only v10 is supported with spdlog"
                    " v${spdlog_VERSION}.")
        endif()
    elseif(spdlog_VERSION VERSION_GREATER_EQUAL "1.11")
        if(fmt_VERSION VERSION_GREATER_EQUAL "10")
            message(FATAL_ERROR "fmt v${fmt_VERSION} is unsupported. Only v9 is supported with spdlog"
                    " v${spdlog_VERSION}.")
        endif()
    elseif(spdlog_VERSION VERSION_GREATER_EQUAL CLP_SPDLOG_MIN_VERSION)
        if(fmt_VERSION VERSION_GREATER_EQUAL "9")
            message(FATAL_ERROR "fmt v${fmt_VERSION} is unsupported. Only v8 is supported with spdlog"
                    " v${spdlog_VERSION}.")
        endif()
    else()
        message(FATAL_ERROR "Internal error: spdlog v${spdlog_VERSION} is unhandled.")
    endif()
    message(STATUS "Found fmt ${fmt_VERSION}")
endif()

I'll explain why in other comments.


# Find and setup spdlog
# Specify the minimum required spdlog version (can be overridden by the user)
Copy link
Member

Choose a reason for hiding this comment

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

The user shouldn't really be allowed to override the version since they could easily pick a version that's incompatible with the code, right?


# Find and setup spdlog
# Specify the minimum required spdlog version (can be overridden by the user)
set (spdlog_MIN_VERSION "1.9.0" CACHE STRING "Minimum required version of spdlog")
Copy link
Member

Choose a reason for hiding this comment

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

This should be CLP_SPDLOG_MIN_VERSION according to our CMake guidelines.

Comment on lines 122 to 129
else()
message("You may want to re-run `components/core/tools/scripts/lib_install/<dist>/install-packages-from-source.sh`")
if (CLP_USE_STATIC_LIBS)
message(FATAL_ERROR "Could not find static libraries for spdlog. You may want to re-run
`components/core/tools/scripts/lib_install/<dist>/install-packages-from-source.sh`")
message(FATAL_ERROR "Could not find static libraries for spdlog.")
else()
message(FATAL_ERROR "Could not find libraries for spdlog.")
endif()
endif()
Copy link
Member

Choose a reason for hiding this comment

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

Because REQUIRED causes a FATAL error if the package isn't found, the else block won't be executed. We should clean up this CMakeLists.txt in another PR or wait for Bill's refactoring to take effect.

# Find fmt with the compatible version
# NOTE:
# - We only try to link to the static library
find_package(fmt ${FMT_MIN_VERSION} REQUIRED)
Copy link
Member

Choose a reason for hiding this comment

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

If we specify a version of fmt in the find_package call, what we're saying is we want a version of fmt that's ABI-compatible with the version we specify. But that's not what we want. We just want a version of fmt that's compatible with the installed version of spdlog; since we check that below, specifying a version here is unnecessary.

Comment on lines +131 to +142
# Determine the lower bound version compatibility of fmt w.r.t to spdlog
if(spdlog_VERSION VERSION_GREATER_EQUAL "1.15.0")
set(FMT_MIN_VERSION "11.0.0")
elseif(spdlog_VERSION VERSION_GREATER_EQUAL "1.12.0")
set(FMT_MIN_VERSION "10.0.0")
elseif(spdlog_VERSION VERSION_GREATER_EQUAL "1.11.0")
set(FMT_MIN_VERSION "9.0.0")
elseif(spdlog_VERSION VERSION_GREATER_EQUAL "1.9.0")
set(FMT_MIN_VERSION "8.0.0")
else()
message(FATAL_ERROR "Unsupported spdlog version (${spdlog_VERSION}). Minimum supported version is 1.9.0.")
endif()
Copy link
Member

Choose a reason for hiding this comment

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

Due to the reasons explained below, this is unnecessary.

if(fmt_FOUND)
# Determine the upper bound version compatibility of fmt w.r.t to spdlog
if(spdlog_VERSION VERSION_GREATER_EQUAL "1.15.0")
# Empty block, no upper version limit
Copy link
Member

Choose a reason for hiding this comment

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

I think we should be conservative and assume that spdlog v1.15.x will only be compatible with fmt v11.

if (fmt_VERSION VERSION_GREATER_EQUAL "9.0.0")
message(FATAL_ERROR "Unsupported fmt version (${fmt_VERSION}). Support version: 8.0.0 <= version < 9.0.0")
endif()
endif()
Copy link
Member

Choose a reason for hiding this comment

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

We need a default case that prints an error.

Comment on lines +170 to +172
# Print the selected versions for debugging
message(STATUS "Using spdlog version ${spdlog_VERSION}")
message(STATUS "Using fmt version ${fmt_VERSION}")
Copy link
Member

Choose a reason for hiding this comment

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

These are redundant since we're already printing "Found Xxx" for each library above.

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.