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

Recently added find_package CONFIG mode override files (redicts) looks for [pkg name]-extra.cmake in locations which differ from CMake FetchContent's overrides #640

Open
christopherbate opened this issue Feb 6, 2025 · 1 comment

Comments

@christopherbate
Copy link

A behavior recently added in #604 attempts to emulate a FetchContent behavior for allowing
find_package in CONFIG mode to be redirected to some CMake files.

In this section added in the PR's changelist:

   if(DEFINED CMAKE_FIND_PACKAGE_REDIRECTS_DIR)
      # Redirect find_package calls to the CPM package. This is what FetchContent does when you set
      # OVERRIDE_FIND_PACKAGE. The CMAKE_FIND_PACKAGE_REDIRECTS_DIR works for find_package in CONFIG
      # mode, unlike the Find${Name}.cmake fallback. CMAKE_FIND_PACKAGE_REDIRECTS_DIR is not defined
      # in script mode, or in CMake < 3.24.
      # https://cmake.org/cmake/help/latest/module/FetchContent.html#fetchcontent-find-package-integration-examples
      string(TOLOWER ${Name} NameLower)
      file(WRITE ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/${NameLower}-config.cmake
           "include(\"${CMAKE_CURRENT_LIST_DIR}/${NameLower}-extra.cmake\" OPTIONAL)\n"
           "include(\"${CMAKE_CURRENT_LIST_DIR}/${Name}Extra.cmake\" OPTIONAL)\n"
      )
      file(WRITE ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/${NameLower}-version.cmake
           "set(PACKAGE_VERSION_COMPATIBLE TRUE)\n" "set(PACKAGE_VERSION_EXACT TRUE)\n"
      )
    else()
      file(WRITE ${CPM_MODULE_PATH}/Find${Name}.cmake
           "include(\"${CPM_FILE}\")\n${ARGN}\nset(${Name}_FOUND TRUE)"
      )
    endif()

These two lines:

           "include(\"${CMAKE_CURRENT_LIST_DIR}/${NameLower}-extra.cmake\" OPTIONAL)\n"
           "include(\"${CMAKE_CURRENT_LIST_DIR}/${Name}Extra.cmake\" OPTIONAL)\n"

should be

     "include(\"${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/${NameLower}-extra.cmake\" OPTIONAL)\n"
      "include(\"${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/${Name}Extra.cmake\" OPTIONAL)\n"

To match cmake's behavior. I believe this was actually the intent of @patstew's change, but the ${CMAKE_CURRENT_LIST_DIR} is being evaluated prior to writing out the file.

@patstew
Copy link
Contributor

patstew commented Feb 6, 2025

Yea, sorry about that. The fix is in #630 , it's just waiting for approval.

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

No branches or pull requests

2 participants