How to parse the values passed to findXXX.cmake file?

Hi all,

I need to parse the stuff passed to findXXX.cmake file. How can it be done?

I’ve tried the cmake_parse_arguments but ARGV and ARGN are empty.

Usage example:

CMakeLists.txt file:

find_package(foo REQUIRED
    COMPONENTS
         bar
         baz
) 

findfoo.cmake file:

# find what components do we need and if it is required
# Parsing code here
if(MY_CONDITION)
 do_something()
else ()
  do_another_thing(foo_COMPONENTS)
endif()

Thanks.

You cannot do that. Arguments passed to find_package are already parsed when FindXXX.cmake is called. Various variables are defined to describe the arguments passed to find_package.

The constraint to this approach is that it is not possible to pass unknown (i.e. custom) arguments to find_package.

1 Like

That will do. Many thanks