Uninitialized variables not checked in CMake scripts outside top-level directory
Background
Suppose I have this trivial project:
my_project
|---CMakeLists.txt
|---sample
|---main.c
|---CMakeLists.txt
CMakeLists.txt:
cmake_minimum_required(VERSION 3.5)
project(my_project)
add_subdirectory(sample)
sample/CMakeLists.txt:
add_executable(my_project main.c ${UNITIALIZED_VAR})
If I invoke CMake with --warn-unitialized
, I will get a warning about using UNITIALIZED_VAR
, whose value is not set prior to use.
Issue
If I move sample
outside my_project
(updating add_subdirectory
call) like so:
sample
|---main.c
|---CMakeLists.txt
my_project
|---CMakeLists.txt
CMake will no longer warn of using UNITIALIZED_VAR
, even with --warn-unitialized
.
Desired Behavior
CMake should warn of uninitialized variables if --warn-unitialized
is passed, regardless of location of subdirectory.