Skip to content

threeal/CheckWarning.cmake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

95 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CheckWarning.cmake

CheckWarning.cmake is a CMake module that provides utility functions for checking compiler warnings during your project's build process. This module mainly contains two functions: a target_check_warning function that assists in checking all recommended warnings on a given target, and an add_check_warning function that behaves like target_check_warning but affects all targets globally in the directory.

Integration

Including the Script File

You can integrate this module into your project by including the CheckWarning.cmake file in your project.

include(CheckWarning)

Using CPM.cmake

Alternatively, you can use CPM.cmake to seamlessly integrate this module into your project.

cpmaddpackage(gh:threeal/CheckWarning.cmake@2.1.1)

Usage

Checking Warnings on a Target

To enable all recommended warnings on a target and treat them as errors, use the target_check_warning function. This will cause the build process to fail when a warning is violated.

add_executable(main main.cpp)
target_check_warning(main)

Ignoring Specific Warnings on a Target

You can use the target_compile_options function to ignore specific warnings on a target.

target_check_warning(main)
target_compile_options(main PRIVATE -Wno-unused-variable)

Checking Warnings Globally

To enable all recommended warnings on all targets in the directory, use the add_check_warning function. This function behaves the same as the target_check_warning function.

add_check_warning()

add_library(lib lib.cpp)
add_executable(main main.cpp)

License

This project is licensed under the terms of the MIT License.

Copyright © 2023-2024 Alfi Maulana