开发者

Proper way of dividing CMakeLists to subprojects

What's the idiomatic way to have a few libraries and a few executables which are interdependent,开发者_StackOverflow in a single cmake project, and have cmake compute the interlibrary dependencies, and generate non recursive makefiles, so that empty compilation will be fast (at least for unix).

This example seems outdated, doesn't really work in recent cmake, and seem to generate recursive makefile.


According to the CMake FAQ generating recursive Makefiles is necessary by design:

CMake does not actually generate truly recursive makefiles that follow the directory structure. It generates a fixed 3-level makefile structure in which each level has a defined purpose:

  1. Makefile: Command-line interface entry points. Maps "make" invocations into calls to the level 2 makefile:
    • make -f CMakeFiles/Makefile2 ...
  2. CMakeFiles/Makefile2: Inter-target dependencies. Evaluates targets in dependency order invoking for each target the depends and build steps in level 3:
    • make -f CMakeFiles/$(target).dir/build.make .../depend
    • make -f CMakeFiles/$(target).dir/build.make .../build
  3. CMakeFiles/.dir/build.make: File-level dependencies and rules:
    • depend: Evaluates custom commands (to produce generate source files) and then scans sources for implicit dependencies.
    • build: Loads dependency scanning results from previous step. Compiles and links.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜