CMP0112 policy warning when using CMake 3.19 + file(GENERATE) + --trace-redirect
Assuming usage of CMake 3.19, with minimum required set to 3.18.
Sample project:
cmake_minimum_required(VERSION 3.18)
project(cmake_policy_112 LANGUAGES CXX)
set(source "${CMAKE_CURRENT_BINARY_DIR}/main.cpp")
file(GENERATE OUTPUT "${source}"
CONTENT " int main(int argc, char *argv[]) { return 0; }")
add_library(mylib SHARED "${source}")
set(target_info"${CMAKE_CURRENT_BINARY_DIR}/target_info.txt")
file(GENERATE OUTPUT "${target_info}"
CONTENT "$<TARGET_FILE_NAME:mylib>")
$ cmake .. --trace-redirect=log.txt
Trace will be written to log.txt
-- The CXX compiler identification is AppleClang 11.0.3.11030032
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
CMake Warning (dev) at CMakeLists.txt:12 (file):
Policy CMP0112 is not set: Target file component generator expressions do
not add target dependencies. Run "cmake --help-policy CMP0112" for policy
details. Use the cmake_policy command to set the policy and suppress this
warning.
Dependency being added to target:
"mylib"
This warning is for project developers. Use -Wno-dev to suppress it.
-- Generating done
I can of course silence the warning by adding the following code to the project
if(POLICY CMP0112)
cmake_policy(SET CMP0112 NEW)
endif()
But to me it seems that the warning should not be shown when used in the context of file(GENERATE)
. Because file(GENERATE)
doesn't have any kind of DEPENDS
option like add_custom_command
does.
Is this an oversight or are my expectations wrong?