Renaming `CMakeLists.txt`

2019-08-03 23:17发布

问题:

Is there any way to rename the various CMakeLists.txt into something more meaningful?

It can be quite distracting to have a bunch of them open at the same time when working on a bigger project that contains several CMake projects.

回答1:

No, it's not possible. The name is meaningful, you will get used to it.

Rationale: CMake must find the files, the common choice is the related files have a common name and CMake will look for it in every folder. Make (Makefile) and Autotools (e.g. Makefile.am) chose similar.

Alternative approaches would be to configure the file name project wide (your problem would remain) or indicating the file names in the file in the parent directory (error prone).



回答2:

There's no reasonable excuse that CMake doesn't use a specified file extension like every other tool in the toolkit. You can do this by putting a dummy CMakeLists.txt, which contains:

cmake_minimum_required(VERSION 3.8)
INCLUDE("meaningfulFilename.cmake")

Then put your actual cmake code in the .cmake file.



标签: cmake