开发者

Should I separate CMakeList.txt from source folder?

开发者 https://www.devze.com 2023-03-18 14:34 出处:网络
I\'m new to build tool, when I come across Autotool, I have an option to write only one Makefile.am in the top build folder and leave the source folder containing all cpp files clean. I could use VPAT

I'm new to build tool, when I come across Autotool, I have an option to write only one Makefile.am in the top build folder and leave the source folder containing all cpp files clean. I could use VPATH to tell automake to look for the source code inside that folder instead of write /src/ every where. (refer to my old question here: Automake Variables to tidy up Makefile.am)

However It appears to me that CMake have no VPATH to set and some fox around said that It's impossible to do so. So there are two choices:

  • Create CMakeList.txt in the source folder
  • Create CMakeList.txt in top build folder and leave the source alone, with a cost that I need to extend "/src" to every开发者_高级运维 source code files.

Which one is more commonly use? I prefer the second because It leave my source code clean from any build-relating-source. In that case is there anyway to get rid of "/src"?


In our company we're using the first option, having a CMakeLists.txt in every subdirectory and building the tree from a root-CMakeLists.txt by using the add_subdirectory command.

This is a modular approach where each subcomponent (think about the project has different parts like boost is split up into system, thread, date_time etc) has its own build-file. If a user wants he is able to just build the subcomponent or to build the whole project.

We're additionally using this as an easy way to include optional subcomponents to the project. The user then can set a Bool value like BUILD_SUBFOO and the add_subdirectory will just be executed, if this Bool is TRUE.

Well-known projects are using this approach too. Here is a link to the root CMakeLists.txt from KDevelop (look at lines 52-62).


I'm quite sure you can do:

FILE(GLOB Source_files src/*.cpp)

which would do exactly what you want.

0

精彩评论

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