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

后端 未结 3 1347
温柔的废话
温柔的废话 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:48

    I believe that a CMake 'module' is simply a file that can be used with the find_package directive. That is, when you run find_package(Module), it searches for a file in the MODULE_PATH that is named FindModule.cmake.

    That said, if you include a file without the extension, it too will search through your MODULE_PATH for that file.cmake. In a CMake project I'm working on, I have a very similar directory structure as to what you propose.

    + root/
      + CMakeLists.txt
      + cmake/
      | + FindMatlab.cmake
      | + TestInline.cmake
      | + stdint.cmake
      + src/
      + include/
    

    In CMakeLists.txt I have:

    set (CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/cmake")
    find_package (Matlab) # runs FindMatlab.cmake
    include(TestInline) # defines a macro:
    test_inline (CONFIG_C_INLINE)
    include(stdint) # simply executes flat CMake code
    

    Perhaps your issue is that you are trying to define the Module path from the environment. Instead, try to simply append to it within the very CMakeList you try to access the modules/files.

提交回复
热议问题