For the cmake “include” command, what is the difference between a file and a module?

后端 未结 3 1334
温柔的废话
温柔的废话 2020-12-24 05:22

I use some libraries that I don\'t want built as part of every project that uses them. A very understandable example is LLVM, which has 78 static libraries. Even having the

3条回答
  •  温柔的废话
    2020-12-24 05:53

    I had this same question after reading the CMake include() command documentation. It states:

    Load and run CMake code from the file given. [...snip for brevity...] If a module is specified instead of a file, the file with name .cmake is searched first in CMAKE_MODULE_PATH, then in the CMake module directory.

    This leaves a lot of interpretation as to what CMake considers a module vs. a file, because a CMake module is a file on the file system after all. So what's the difference?

    The CMake source code is the only place I could find the answer. Basically CMake considers the argument to include() to be a file if it looks like an absolute path. This means:

    • On Linux/Unix
      • The argument starts with either '/' or '~'
    • On Windows
      • The argument's second character is ':' (as in C:)
      • The argument starts with '\'

    CMake assumes anything else that doesn't meet the above criteria is a Module. In which case it appends '.cmake' to the argument and searches the CMAKE_MODULE_PATH for it.

提交回复
热议问题