虽然我可以根据编译器设置不同的警告级别,例如:
if(MSVC)
target_compile_options(${TARGET_NAME} PRIVATE /W4 /WX)
else()
target_compile_options(${TARGET_NAME} PRIVATE -Wall -Wextra -pedantic -Werror)
endif()
我无法逐个文件地设置它们。
在同一目录中,我有一组文件的名称在${SRC_WARN}
CMake变量中,与其他文件相比,它们需要不同的警告级别。
是否可以通过target_compile_options
指定这种条件?
您可以使用COMPILE_OPTIONS
为单个文件(或文件组)设置编译选项(COMPILE_OPTIONS
)。您可以通过添加到现有的CMake代码来更改set_source_files_properties()
源文件的set_source_files_properties()
:
COMPILE_OPTIONS