Ninja: Explicitly fail early with CMP0002 set to OLD
Ninja generator doesn't allow targets with the same name from different sub-directories. Even if CMP0002
is set to OLD
.
Here's root CMakeLists.txt:
cmake_minimum_required(VERSION 3.10)
cmake_policy(SET CMP0013 OLD)
cmake_policy(SET CMP0002 OLD)
project(foobar)
add_subdirectory(subdir)
add_subdirectory(subdir2)
subdir/CMakeLists.txt
:
add_executable(foobar../main.cpp)
subdir2/CMakeLists.txt
:
add_executable(foobar../main.cpp)
After generating CMake project with -G Ninja
error is shown:
CMake Error:
Running
'ninja.EXE' '-C' 'cmake-build-debug' '-t' 'recompact'
failed with:
ninja: error: build.ninja:140: multiple rules generate cmake_object_order_depends_target_foobar [-w dupbuild=err]
Probably, policy CMP0002
should be disabled for Ninja
generator. Instead, it should always check for unique target name
Edited by Brad King