Skip to content

Conversation

@Bioblaze
Copy link

Added support for vendored dependency installation and export rules.

Added support for vendored dependency installation and export rules.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances the CMakeLists.txt to better support liboai when used as a vendored dependency via add_subdirectory. The changes allow parent projects to provide dependencies as existing targets and control whether install/export rules are generated.

  • Added conditional install/export rules that are disabled by default when liboai is not the top-level project
  • Modified dependency detection to check for existing targets before calling find_package for both nlohmann_json and CURL
  • Made install rules optional via the LIBOAI_INSTALL option

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

endif()
endif()

# Try to find CURL, but if not found, use the vendored target if it exists
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

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

The comment says "but if not found, use the vendored target if it exists" which is misleading. The code actually checks if the CURL::libcurl target exists first, and only calls find_package if it doesn't exist. Consider revising to: "Try to use CURL::libcurl target if it exists, otherwise try to find CURL package".

Suggested change
# Try to find CURL, but if not found, use the vendored target if it exists
# Try to use CURL::libcurl target if it exists, otherwise try to find CURL package

Copilot uses AI. Check for mistakes.
endif()
option(LIBOAI_INSTALL "Enable liboai install/export rules" ${_LIBOAI_DEFAULT_INSTALL})

# Try to find nlohmann_json, but if not found, use a target if it exists
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

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

The comment says "but if not found, use a target if it exists" which is misleading. The code actually checks if nlohmann_json targets exist first, and only calls find_package if no target exists. Consider revising to: "Try to use nlohmann_json target if it exists, otherwise try to find nlohmann_json package".

Suggested change
# Try to find nlohmann_json, but if not found, use a target if it exists
# Try to use nlohmann_json target if it exists, otherwise try to find nlohmann_json package

Copilot uses AI. Check for mistakes.
Comment on lines +38 to +41
else()
find_package(CURL QUIET)
if(NOT CURL_FOUND)
message(FATAL_ERROR "CURL not found and CURL::libcurl target does not exist")
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

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

For consistency with the nlohmann_json target detection (lines 23-27), consider also checking for a non-namespaced CURL target. Some vendored CURL builds may create a libcurl or curl target without the CURL:: namespace. This would make the dependency detection more robust.

Suggested change
else()
find_package(CURL QUIET)
if(NOT CURL_FOUND)
message(FATAL_ERROR "CURL not found and CURL::libcurl target does not exist")
elseif(TARGET libcurl)
set(CURL_FOUND TRUE)
add_library(CURL::libcurl ALIAS libcurl)
elseif(TARGET curl)
set(CURL_FOUND TRUE)
add_library(CURL::libcurl ALIAS curl)
else()
find_package(CURL QUIET)
if(NOT CURL_FOUND)
message(FATAL_ERROR "CURL not found and no suitable libcurl target exists")

Copilot uses AI. Check for mistakes.
# dependencies (eg. CURL::libcurl) are not part of liboai's export set.
# Only enable install/export when building liboai as the top-level project.
set(_LIBOAI_DEFAULT_INSTALL OFF)
if(PROJECT_IS_TOP_LEVEL)
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

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

The variable PROJECT_IS_TOP_LEVEL is only available in CMake 3.21 and later, but this file requires CMake 3.13 (line 1). This will cause a build failure on CMake versions between 3.13 and 3.20. Either update the minimum required version to 3.21, or add a check to define PROJECT_IS_TOP_LEVEL for older versions.

Copilot uses AI. Check for mistakes.
@jasonduncan jasonduncan merged commit 75e1098 into jasonduncan:main Jan 5, 2026
6 checks passed
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.

2 participants