Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Register
  • Sign in
  • CMake CMake
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 4,157
    • Issues 4,157
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 14
    • Merge requests 14
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • External wiki
    • External wiki
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • CMakeCMake
  • CMakeCMake
  • Issues
  • #23603
Closed
Open
Issue created Jun 08, 2022 by Marc Chevrier@marc.chevrierMaintainer

find_(library,file,program): add validation function

For now, when a file is searched using one of the find_library, find_program, and find_file commands, the selection criteria are only based on paths and names.

Unfortunately, possibly, they are multiple files matching with the criteria. In this case, only the first one is returned even is, finally, it is not an acceptable choice.

For example, it is very common, especially on Windows, to have multiple occurrences of python.exe but, depending on what we are looking for (for example 32bit versus 64bit), the file founded is not acceptable.

To remove this limitation, I propose to add the possibility to specify a function which will be called for each file to check if this one is acceptable or not.

This function will take, as arguments, a variable name to output the result of the check and the filename.

function(check_library status filename)
  # status output is used to return check result
  set(${status} "TRUE" PARENT_SCOPE)
endfunction()

find_library(MY_LIB NAMES ... VALIDATOR check_library ...)

Remarks:

  • VALIDATOR as option name is just a suggestion. Any other suggestions for this option are welcomed.
  • Specifying a function rather than a script offers more flexibility: the function has access to the environment where this function is defined: typically the environment of a find_package module.
  • It will be judicious to request that the argument to VALIDATOR must be a function rather than a macro to avoid side effects on the environment. By the way, how to know, in C++, if a command is a macro or a function?
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking