Set warnings as errors

This commit is contained in:
momo5502 2022-03-15 19:18:51 +01:00
parent 409537d600
commit 41c6647fd9
3 changed files with 77 additions and 3 deletions

View File

@ -23,4 +23,5 @@ enable_driver_support()
##########################################
add_subdirectory(src)
add_subdirectory_and_get_targets("src" SRC_TARGETS)
targets_set_warnings_as_errors(${SRC_TARGETS})

View File

@ -1,3 +1,5 @@
include_guard()
##########################################
macro(set_artifact_directory directory)
@ -31,4 +33,75 @@ endmacro()
macro(enable_driver_support)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/external/FindWDK/cmake")
find_package(WDK REQUIRED)
endmacro()
endmacro()
##########################################
function(target_set_warnings_as_errors target)
get_target_property(target_type ${target} TYPE)
if(("${target_type}" STREQUAL "INTERFACE_LIBRARY") OR ("${target_type}" STREQUAL "UTILITY"))
return()
endif()
set(compile_options)
if(MSVC)
set(compile_options /W4 /WX)
if (CLANG)
set(compile_options ${compile_options} -Xclang -Wconversion)
endif()
else()
# lots of warnings and all warnings as errors
set(compile_options -Wall -Wextra -Wconversion -pedantic -Werror)
endif()
target_compile_options(${target} PRIVATE
$<$<COMPILE_LANGUAGE:C>:$<$<CONFIG:RELEASE>:${compile_options}>>
$<$<COMPILE_LANGUAGE:CXX>:$<$<CONFIG:RELEASE>:${compile_options}>>
)
endfunction()
##########################################
function(targets_set_warnings_as_errors)
foreach(target ${ARGV})
target_set_warnings_as_errors(${target})
endforeach()
endfunction()
##########################################
function(get_all_targets var)
set(targets)
get_all_targets_recursive(targets ${CMAKE_CURRENT_SOURCE_DIR})
set(${var} ${targets} PARENT_SCOPE)
endfunction()
##########################################
macro(get_all_targets_recursive targets dir)
get_property(subdirectories DIRECTORY ${dir} PROPERTY SUBDIRECTORIES)
foreach(subdir ${subdirectories})
get_all_targets_recursive(${targets} ${subdir})
endforeach()
get_property(current_targets DIRECTORY ${dir} PROPERTY BUILDSYSTEM_TARGETS)
list(APPEND ${targets} ${current_targets})
endmacro()
##########################################
macro(list_difference list_a list_to_remove result)
set(${result} ${list_a})
list(REMOVE_ITEM ${result} ${list_to_remove})
endmacro()
##########################################
macro(add_subdirectory_and_get_targets directory targets)
get_all_targets(EXISTING_TARGETS)
add_subdirectory(${directory})
get_all_targets(ALL_TARGETS)
list_difference("${ALL_TARGETS}" "${EXISTING_TARGETS}" ${targets})
endmacro()

View File

@ -18,7 +18,7 @@ std::filesystem::path get_current_path()
return selfdir;
}
int main(const int argc, char* argv[])
int main(const int /*argc*/, char* /*argv*/[])
{
const auto manager = OpenSCManagerA(nullptr, nullptr, SC_MANAGER_ALL_ACCESS);
if (manager == nullptr)