Should multiple projects in the same buildsystem be allowed to have the same name?
I was recently tried doing something funny for no good reason: making a project directory add itself as a subdirectory.
cmake_minimum_required(VERSION 3.24) # or whatever version
set(CMAKE_MAXIMUM_RECURSION_DEPTH 10)
project(another)
add_subdirectory(. _)
As a side question, it brought up the fact that you can have multiple projects in a buildsystem with the same name. I didn't get any errors about that. I just got an error about the maximum recursion depth being reached.
First of all, I can't think of a reason why I'd want to have two projects with the same name in the same buildsystem.
Entertaining the possibility, it seems like it could cause problem though, no? There are several variables that are prefixed with the name of a project (see PROJECT-NAME_BINARY_DIR
and click next page for more).
I tested the following:
# root/CMakeLists.txt
cmake_minimum_required(VERSION 3.24) # or whatever version
project(hello)
add_subdirectory(. subdir)
message("${hello_SOURCE_DIR}")
# root/subdir/CMakeLists.txt
project(hello)
And this printed the source directory of the subdirectory.
Is this intended behaviour? If not, would it be a good idea to make it a fatal error for two projects in the same buildsystem to have the same name?