diff --git a/CMakeLists.txt b/CMakeLists.txt index 2696117..c27350e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}) diff --git a/cmake/utils.cmake b/cmake/utils.cmake index 28bded3..cdcf0ea 100644 --- a/cmake/utils.cmake +++ b/cmake/utils.cmake @@ -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() \ No newline at end of file +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_options}>> + $<$:$<$:${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() diff --git a/src/runner/main.cpp b/src/runner/main.cpp index 058de4b..a272a11 100644 --- a/src/runner/main.cpp +++ b/src/runner/main.cpp @@ -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)