diff options
author | aqua <aqua@iserlohn-fortress.net> | 2024-04-28 10:50:04 +0300 |
---|---|---|
committer | aqua <aqua@iserlohn-fortress.net> | 2024-04-28 10:50:04 +0300 |
commit | 0eb0cf57720943ad71857a4a4fc0a9f365581d2a (patch) | |
tree | e1f8234c4351ffbf37d26416b88ae5749a8ee881 | |
parent | Readded command line options (diff) | |
download | smolbote-0eb0cf57720943ad71857a4a4fc0a9f365581d2a.tar.xz |
Added compiler warnings for poi
-rw-r--r-- | CMakeLists.txt | 22 | ||||
-rw-r--r-- | cmake/CompilerOptions.cmake | 89 | ||||
-rw-r--r-- | cmake/CppCheck.cmake | 11 | ||||
-rw-r--r-- | meson.build | 143 | ||||
-rw-r--r-- | src/CMakeLists.txt | 1 |
5 files changed, 121 insertions, 145 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 8740168..30cc928 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,12 @@ cmake_minimum_required(VERSION 3.16) project(smolbote VERSION 0.1.0 LANGUAGES CXX) +list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") + +include(CppCheck) +include(CompilerOptions) +include(FeatureSummary) + set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # set C++ standard for all targets @@ -9,13 +15,23 @@ set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) +# set PIE for all targets +set(CMAKE_POSITION_INDEPENDENT_CODE ON) + # dependencies find_package(GTest) enable_testing() -find_package(spdlog) +find_package(spdlog REQUIRED) -find_package(Qt6 6.0.0 COMPONENTS Network Widgets SvgWidgets WebEngineCore WebEngineWidgets Concurrent REQUIRED) +find_package(Qt6 6.0.0 REQUIRED COMPONENTS + Network + Widgets + SvgWidgets + WebEngineCore + WebEngineWidgets + Concurrent +) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTORCC ON) @@ -36,3 +52,5 @@ add_subdirectory(src) include(GNUInstallDirs) install(TARGETS poi DESTINATION ${CMAKE_INSTALL_BINDIR}) + +feature_summary(WHAT ALL) diff --git a/cmake/CompilerOptions.cmake b/cmake/CompilerOptions.cmake new file mode 100644 index 0000000..dbb37fd --- /dev/null +++ b/cmake/CompilerOptions.cmake @@ -0,0 +1,89 @@ +# ================================================================================== +# adapted from +# https://github.com/zhivkopetrov/cmake_helpers.git +# MIT License Copyright (c) 2020-2023 Zhivko Petrov +# +# some compiler warnings from +# https://lefticus.gitbooks.io/cpp-best-practices/content/02-Use_the_Tools_Available.html +# +# ================================================================================== +# target_enable_warnings + +function(target_enable_warnings target) + if(CMAKE_CXX_COMPILER_ID MATCHES MSVC) + target_compile_options( + ${target} + PRIVATE + /W4 + /WX + ) + endif() + + if((CMAKE_CXX_COMPILER_ID MATCHES GNU) OR + (CMAKE_CXX_COMPILER_ID MATCHES Clang)) + target_compile_options( + ${target} + PRIVATE + # compiler warnings + # generic + -Wall -Wextra # reasonable and standard + -Wpedantic # non-standard cpp is used + -Wmisleading-indentation + -Wlogical-op # logical op being used instead of bitwise + -Wundef + -Wuninitialized + -Weffc++ # disabled because it would require skeleton changes + # variables + -Wshadow # variable declaration shadows one from parent context + -Wunused # anything being unused + # casts + -Werror=old-style-cast # C-style casts + -Wcast-align # performance problem casts + -Wcast-qual + -Wuseless-cast # cast to same type + # conversion + #-Wconversion # type conversion may lose data + -Wsign-conversion # sign conversion + -Wdouble-promotion # implicit float to double + # functions + -Wunused-parameter + -Werror=missing-declarations # missing function declaration in header files + -Werror=redundant-decls + -Werror=return-type + -Werror=overloaded-virtual + # inheritance + -Wnon-virtual-dtor # class with virtual functions has non-virt dtor + -Woverloaded-virtual # overloaded (not override) virtual function + # branches + -Wduplicated-cond # if/else chain has duplicated conditions + -Wduplicated-branches # if/else chain has duplicated code + # pointers + -Wpointer-arith + -Wnull-dereference + # style + -Wformat=2 # security issues around printf + -Werror=date-time # usage of __DATE__ and __TIME__ macros + -Werror=missing-field-initializers + # logic + -Wlogical-op + -Wimplicit-fallthrough + -Wduplicated-cond + -Wduplicated-branches + + # other flags + -ffunction-sections # place each function into its own section + # better ASLR but larger executables + -fstack-protector-all # emit check for buffer overflows on all functions + -fstack-clash-protection # emit check for stack clash attacks + ) + endif() + + # add -Werror to release builds + if((${CMAKE_BUILD_TYPE} MATCHES Release) OR + (${CMAKE_BUILD_TYPE} MATCHES MinSizeRel)) + # currently disabled + #target_compile_options(${target} PRIVATE -Werror) + endif() + +endfunction() + diff --git a/cmake/CppCheck.cmake b/cmake/CppCheck.cmake new file mode 100644 index 0000000..d8a4559 --- /dev/null +++ b/cmake/CppCheck.cmake @@ -0,0 +1,11 @@ +find_program(CMAKE_CXX_CPPCHECK NAMES cppcheck) + +if(CMAKE_CXX_CPPCHECK) + list(APPEND CMAKE_CXX_CPPCHECK + --std=c++20 + --enable=all + --inconclusive + --quiet + --suppressions-list=${PROJECT_SOURCE_DIR}/CppCheckSuppressions.txt + ) +endif() diff --git a/meson.build b/meson.build deleted file mode 100644 index 6534910..0000000 --- a/meson.build +++ /dev/null @@ -1,143 +0,0 @@ -project('smolbote', ['cpp'], - version: '0.1.0', - default_options: ['cpp_std=c++2a', 'warning_level=3'], - license: 'GPL3', - meson_version: '>=0.57.0' -) - -kconfig = import('keyval') -kconf = kconfig.load(host_machine.system() + '/.config') - -cdata = configuration_data(kconf) - -version_h = vcs_tag( - command: [find_program('git').full_path(), 'describe', '--long', '--abbrev=40'], - #fallback: defaults to meson.project_version(), - input: 'include/version.h.in', - output: 'version.h' -) - -# add -DQT_NO_DEBUG to non-debug builds -if not get_option('debug') - add_project_arguments('-DQT_NO_DEBUG', language: 'cpp') -endif - -sourceset = import('sourceset') - -cxx = meson.get_compiler('cpp') - -# add some specific flags -add_project_arguments(cxx.get_supported_arguments([ - '-ffunction-sections', # Place each function into its own section, better ASLR but larger executables - '-fstack-protector-all', # Emit code to check for buffer overflows on all functions - '-fstack-clash-protection', # Emit code to check for stack clash attacks - - # gcc specific - '-fconcepts', # gcc9 c++20 compat - - # clang specific - '-mspeculative-load-hardening', # Spectre v1 mitigation - '-Xclang -plugin-arg-clazy -Xclang level0,level1', # clazy default warning level - - ## warnings - # variables - '-Wunused', # warn on anything being unused - '-Wshadow', # if variable declaration shadows one from a parent context - # functions - '-Wnon-virtual-dtor', # if class with virtual functions has non-virtual dtor - '-Werror=missing-declarations', # missing function declarations in header files - '-Werror=redundant-decls', - '-Woverloaded-virtual', # warn if you overload (not override) a virtual function - '-Werror=return-type', - # style - '-Wformat=2', # security issues around printf - '-Wdate-time', # __TIME__ and __DATE__ macros - '-Werror=missing-field-initializers', - # objects - '-Wnull-dereference', - '-Wconsumed', # use-after-move warnings - '-Wlifetime', # object lifetime issues - # logic - '-Wlogical-op', # logical operations being used where bitwise were probably wanted - '-Wimplicit-fallthrough', - '-Wduplicated-cond', # if/else chain has duplicated conditions - '-Wduplicated-brances', # if/else branches have duplicated code - # casts - '-Wold-style-cast', - '-Wcast-align', # potential performance problem casts - '-Wuseless-cast', # cast to same type - '-Wconversion', # type conversions that may lose data - '-Wsign-conversion', # sign conversions - '-Wdouble-promotion', # float is promoted to double - # others - '-Werror=pedantic', # if non-standard c++ is used - #'-Weffc++', -]), language: 'cpp') - -# Dependencies -mod_qt5 = import('qt6') -dep_qt5 = dependency('qt6', - modules: [ 'Core', 'Network', 'Widgets', 'SvgWidgets', 'WebEngineCore', 'WebEngineWidgets', 'Concurrent' ], - include_type: 'system' -) - -dep_spdlog = dependency('spdlog', fallback: ['spdlog', 'spdlog_dep'], version: '>=1.3.1') -dep_fmt = dependency('fmt') - -optional_deps = [] -poi_cpp_args = [] - -dep_breakpad = disabler() # dependency('breakpad-client', include_type: 'system', required: get_option('crashhandler')) -dep_threads = disabler() # dependency('threads', include_type: 'system', required: get_option('crashhandler')) -if dep_breakpad.found() - poi_cpp_args += '-DHAVE_BREAKPAD' -endif - -dep_gtest = dependency('gtest', required: false, disabler: true) -dep_catch = disabler() # dependency('catch2', required: true, fallback: ['catch2', 'catch2_dep'] ) -dep_SingleApplication = dependency('singleapplication', fallback: [ 'singleapplication', 'SingleApplication_dep' ]) -dep_args = dependency('args.hxx', fallback: [ 'args', 'args_dep' ]) - -# Generate config header - -poi_sourceset = sourceset.source_set() - -subdir('include') # plugin interaces - -subdir('lib/bookmarks') -subdir('lib/configuration') -subdir('lib/downloads') -subdir('lib/pluginloader') -subdir('lib/urlfilter') -subdir('lib/session_formats') - -subdir('src') -subdir('lang') -subdir('doc') -subdir('tools') - -subdir('plugins/ProfileEditor') - -subdir('test/firefox-bookmarks-json-parser') - -ssconfig = poi_sourceset.apply(cdata) - -poi_exe = executable(get_option('poi'), - cpp_args: ['-DQAPPLICATION_CLASS=QApplication', '-DSPDLOG_FMT_EXTERNAL=1', poi_cpp_args], - sources: [ssconfig.sources()], - include_directories: [ plugininterfaces_include, include_directories('src') ], - dependencies: [ dep_qt5, dep_spdlog, dep_fmt, dep_SingleApplication, dep_args, optional_deps, dep_bookmarks, dep_configuration, dep_downloads, dep_pluginloader, dep_urlfilter, ssconfig.dependencies(), lib_session_formats ], - install: true, -) - -test('poi-bookmarks: xbel', poi_exe, args: [ 'bookmarks', '-x', files('test/bookmarks.xbel'), '--export=stdout' ]) - -subdir(host_machine.system()) - -# cppcheck target -cppcheck = find_program('cppcheck', required: false) -if cppcheck.found() -run_target('cppcheck', - command: [cppcheck, '--enable=all', '--project=' + meson.project_build_root() / 'compile_commands.json'] -) -endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bd6082a..be2452b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -69,6 +69,7 @@ add_executable(poi ) target_sources(poi PRIVATE settings.h) target_include_directories(poi PRIVATE ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_CURRENT_BINARY_DIR}) +target_enable_warnings(poi) target_link_libraries(poi PRIVATE SingleApplication::SingleApplication spdlog::spdlog PRIVATE bookmarks configuration downloads session_formats urlfilter |