jlconlin
jlconlin

Reputation: 15054

Where does cmake look for .cmake scripts?

I am trying to execute_process in cmake like this

execute_process(COMMAND ${CMAKE_COMMAND} -P myScript.cmake

This only works if the file, myScript.cmake is in the same working directory.

Three related questions:

  1. Does cmake have a standard location to look for .cmake scripts?
  2. Is there a cmake variable I can define to tell cmake where to look? or
  3. Should I always give a full path to the script (i.e., -P ${PATH_VAR}/myScript.cmake)?

Upvotes: 4

Views: 3098

Answers (1)

Fraser
Fraser

Reputation: 78300

Does cmake have a standard location to look for .cmake scripts?

For execute_process, no. The find_XXX commands (e.g. find_file) and include do though.


Is there a cmake variable I can define to tell cmake where to look?

Again, for execute_process, no. For find_xxx or include, you can set the variable CMAKE_MODULE_PATH.


Should I always give a full path to the script (i.e., -P ${PATH_VAR}/myScript.cmake)?

That's a good option; passing a full path leaves no room for uncertainty. However, you can get away with a relative path too. The default working directory for execute_process is the CMAKE_BINARY_DIR, so you can pass the path to the script relative to that.

Alternatively you can specify the WORKING_DIRECTORY in the execute_process call either as a full path or relative to the CMAKE_BINARY_DIR.

If you feel your script is in a standard location, you could consider "finding" it first using a call to find_file. This would yield the full path to the script if found and that variable can be used in your execute_process call.

Upvotes: 7

Related Questions