[CMake] Using find_program() command to search in only one given directory

Alexander Neundorf a.neundorf-work at gmx.net
Thu Sep 2 12:50:09 EDT 2010


On Wednesday 01 September 2010, Nicholas Kinar wrote:
>   Hello,
>
> Suppose that I have a program (named "my-config") that is on the *NIX
> system path, and I have another version of the program (also named
> "my-config") in a sub-folder of the HOME directory.
>
> How would I use the find_program() command to determine if the program
> exists, given the search directory?  In other words, given a variable
> with the path to the program (CONFIG_EXECUTABLE_PATH), how do I force
> the find_program() command to search only in the path specified by that
> particular variable?
>
> I've been trying to use the find_program() command with the
> NO_DEFAULT_PATH modifier, but this does not seem to be working, since
> cmake will only find the program on the *NIX system path:
>
> find_program(CONFIG_EXECUTABLE NAMES my-config PATHS
> ${CONFIG_EXECUTABLE_PATH}  NO_DEFAULT_PATH)

Looks good, should work.

>
> Alternately, must I simply set the path to the program using the
> following command?
>
> set(CONFIG_EXECUTABLE, ${CONFIG_EXECUTABLE_PATH}/my-config)

You can do that too.
You can also check via
if(EXISTS ...)

Alex


More information about the CMake mailing list