Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cmake file structure, how to split a CMakeLists.txt into multiple files?

Tags:

cmake

Over time my CMakeLists.txt files have grown by the addition of dozens of self functions and definitions. I would like to split these into their own file so as to simplify reuse in other projects and make the CMakeLists.txt file more readable.

currently I use a superdir CMakeLists.txt but I feel there has to be a better solution then that... something similar to \input in latex? or include in c++ for that matter Ideas?

like image 592
midjji Avatar asked Apr 02 '14 07:04

midjji


People also ask

What can I do with CMakeLists txt?

CMakeLists. txt file is placed at the source of the project you want to build. CMakeLists. txt is placed at the root of the source tree of any application, library it will work for.

What does Add_subdirectory do in CMake?

Add a subdirectory to the build. Adds a subdirectory to the build. The source_dir specifies the directory in which the source CMakeLists.

What is .CMake file?

CMake is a meta build system that uses scripts called CMakeLists to generate build files for a specific environment (for example, makefiles on Unix machines). When you create a new CMake project in CLion, a CMakeLists. txt file is automatically generated under the project root.


1 Answers

CMake has its own include command which allows you to bring additional CMake code into play, with variables in the included file still in the scope of the including CMakeList file (unlike add_subdirectory for example). Its effect should be as though you had pasted the contents of the included file into the CMakeList file at the point of the include.

like image 145
Fraser Avatar answered Sep 22 '22 00:09

Fraser