TheLartians / ModernCppStarter

🚀 Kick-start your C++! A template for modern C++ projects using CMake, CI, code coverage, clang-format, reproducible dependency management and much more.
https://thelartians.github.io/ModernCppStarter
The Unlicense
4.33k stars 381 forks source link

Suggestion to define main project name in a separate file #178

Closed ldeng-ustc closed 11 months ago

ldeng-ustc commented 1 year ago

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.

TheLartians commented 12 months ago

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.