CMake: how best to build multiple (optional) subprojects?

后端 未结 6 2044
说谎
说谎 2021-02-18 16:23

Imagine an overall project with several components:

  • basic
  • io
  • web
  • app-a
  • app-b
  • app-c

Now, let\'s say web

6条回答
  •  温柔的废话
    2021-02-18 17:04

    I see two additional approaches. One is to simply have basic, io, and web be submodules of each app. Yes, there is duplication of code and wasted disk space, but it is very simple to implement and guarantees that different compiler settings for each app will not interfere with each other across the shared libraries. I suppose this makes the libraries not be shared anymore, but maybe that doesn't need to be a big deal in 2011. RAM and disk have gotten cheaper, but engineering time has not, and sharing of source is arguably more portable than sharing of binaries.

    Another approach is to have the layout specified in the question, and have CMakeLists.txt files in each subdirectory. The CMakeLists.txt files in basic, io, and web generate standalone shared libraries. The CMakeLists.txt files in each app directory pull in each shared library with the add_subdirectory() command. You could then pull down all the library directories and whichever app(s) you wanted and initiate the build from within each app directory.

提交回复
热议问题