TheLartians/ModernCppStarter

Suggestion to define main project name in a separate file

ldeng-ustc opened this issue · 1 comments

The main project name (Greeter) is currently used across multiple files. So it requires modifications in all these files to use this template, which can be time-consuming and error-prone.

I suggest defining the main project name in a separate file. This way, any changes to the name would only need to be made in one place, reducing potential errors and increasing efficiency.

for example, we can create a new file info.cmake:

# Note: update this to your new project's name and version
set(MAIN_PROJECT_NAME Greeter)

And then, include this file in other files:

# ./CMakeLists.txt
cmake_minimum_required(VERSION 3.14...3.22)

# ---- Project ----
include(info.cmake)
project(
  ${MAIN_PROJECT_NAME}
  VERSION 1.0
  LANGUAGES CXX
)

Then, one can start its own projects with changing only one Greeter.

I write a demo in this branch, but I haven’t updated the documentation. If this suggestion is accepted, I can submit a PR.

Hey thanks for the input! I've also been bugged by this, but decided to not bother as it would introduce extra complexity without not adding long term benefits. Also in an actual project, you would expect the project name to be hardcoded in multiple places instead of being encoded in a generic variable name.