diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 04e07e10721f7e6ad1bc376831df992273fe7768..8c39faac7f79ee2ed76070ab118d0cea048ccf37 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -12,7 +12,7 @@ variables: - SRC_DIR=`pwd` - mkdir build - cd build - - cmake -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DlibClaPP_SUBMODULE_DEPENDENCIES=On -DCMAKE_BUILD_TYPE=${BUILD_TYPE} ${SRC_DIR} + - cmake -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DlibClaPP_SUBMODULE_DEPENDENCIES=On -DlibClaPP_PEDANTIC_COMPILER_FLAGS=On -DCMAKE_BUILD_TYPE=${BUILD_TYPE} ${SRC_DIR} - cmake --build . - make install - echo -e '#include<clapp/main_parser.h>\n#include<clapp/build_info.h>\n#include<iostream>\nint main (int argc, char *argv[]) {\nstd::cout << clapp::build_info::project_name << " v" << clapp::build_info::version << std::endl;\n}' | ${CXX} `pkg-config --libs --cflags libclapp` -I${SRC_DIR}/third_party/GSL/include/ --std=c++17 -o out -x c++ - @@ -23,7 +23,7 @@ variables: - SRC_DIR=`pwd` - mkdir build - cd build - - cmake -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DlibClaPP_BUILD_TESTS=On -DlibClaPP_BUILD_EXAMPLES=On -DlibClaPP_BUILD_DOC_CODE=On -DlibClaPP_BUILD_COVERAGE=On -DlibClaPP_SUBMODULE_DEPENDENCIES=On -DCMAKE_BUILD_TYPE=${BUILD_TYPE} ${ADDITIONAL_OPTION} -G "${GENERATOR}" ${SRC_DIR} + - cmake -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DlibClaPP_PEDANTIC_COMPILER_FLAGS=On -DlibClaPP_BUILD_TESTS=On -DlibClaPP_BUILD_EXAMPLES=On -DlibClaPP_BUILD_DOC_CODE=On -DlibClaPP_BUILD_COVERAGE=On -DlibClaPP_SUBMODULE_DEPENDENCIES=On -DCMAKE_BUILD_TYPE=${BUILD_TYPE} ${ADDITIONAL_OPTION} -G "${GENERATOR}" ${SRC_DIR} - cmake --build . artifacts: paths: @@ -35,7 +35,7 @@ variables: - SRC_DIR=`pwd` - mkdir build - cd build - - cmake -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DCLANG_TIDY=${CLANG_TIDY} -DlibClaPP_BUILD_DOC_CODE=On -DlibClaPP_BUILD_TESTS=On -DlibClaPP_BUILD_EXAMPLES=On -DlibClaPP_SUBMODULE_DEPENDENCIES=On -DlibClaPP_BUILD_COVERAGE=On -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DlibClaPP_CLANG_TIDY=On ${SRC_DIR} + - cmake -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DlibClaPP_PEDANTIC_COMPILER_FLAGS=On -DCLANG_TIDY=${CLANG_TIDY} -DlibClaPP_BUILD_DOC_CODE=On -DlibClaPP_BUILD_TESTS=On -DlibClaPP_BUILD_EXAMPLES=On -DlibClaPP_SUBMODULE_DEPENDENCIES=On -DlibClaPP_BUILD_COVERAGE=On -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DlibClaPP_CLANG_TIDY=On ${SRC_DIR} - cmake --build . .test_gcov_template: &test_gcov_definition diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b7a56f4a8f9df2209fc87aea2fc9d18645b56b3..07ea22b617675316a71b47cfc6a566ebfb666992 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,13 +15,13 @@ set(CMAKE_CXX_FLAGS_DEBUG "-ggdb -O0") set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG") if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - list(APPEND libClaPP_TEST_COMPILE_OPTIONS -Wall -Wextra -Wunreachable-code -Wfloat-equal -Werror -pedantic-errors -Wcast-align -Wcast-qual -Wpointer-arith -Wwrite-strings -Wstrict-overflow=2 -Wformat=2 -Wlogical-op -Wduplicated-cond -Wduplicated-branches -Wdouble-promotion -Wold-style-cast -Wshadow -Wwrite-strings -Wuninitialized -Wconversion -Wunused -Wno-missing-braces -Wnarrowing -Wconversion-null -Wuseless-cast -Wsign-conversion -Wrestrict -Wnull-dereference -Wmisleading-indentation -Wnon-virtual-dtor -Woverloaded-virtual) - set(libClaPP_COMPILE_OPTIONS ${libClaPP_TEST_COMPILE_OPTIONS}) - list(APPEND libClaPP_COMPILE_OPTIONS -Weffc++) + list(APPEND libClaPP_TEST_PEDANTIC_COMPILE_OPTIONS -Wall -Wextra -Wunreachable-code -Wfloat-equal -Werror -pedantic-errors -Wcast-align -Wcast-qual -Wpointer-arith -Wwrite-strings -Wstrict-overflow=2 -Wformat=2 -Wlogical-op -Wduplicated-cond -Wduplicated-branches -Wdouble-promotion -Wold-style-cast -Wshadow -Wwrite-strings -Wuninitialized -Wconversion -Wunused -Wno-missing-braces -Wnarrowing -Wconversion-null -Wuseless-cast -Wsign-conversion -Wrestrict -Wnull-dereference -Wmisleading-indentation -Wnon-virtual-dtor -Woverloaded-virtual) + set(libClaPP_PEDANTIC_COMPILE_OPTIONS ${libClaPP_TEST_PEDANTIC_COMPILE_OPTIONS}) + list(APPEND libClaPP_PEDANTIC_COMPILE_OPTIONS -Weffc++) elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") - list(APPEND libClaPP_COMPILE_OPTIONS -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded -Werror -pedantic-errors) - set(libClaPP_TEST_COMPILE_OPTIONS ${libClaPP_COMPILE_OPTIONS}) - list(APPEND libClaPP_TEST_COMPILE_OPTION -Wno-global-constructors) + list(APPEND libClaPP_PEDANTIC_COMPILE_OPTIONS -Weverything -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-padded -Werror -pedantic-errors) + set(libClaPP_TEST_PEDANTIC_COMPILE_OPTIONS ${libClaPP_PEDANTiC_COMPILE_OPTIONS}) + list(APPEND libClaPP_TEST_PEDANTIC_COMPILE_OPTION -Wno-global-constructors) endif() CHECK_CXX_COMPILER_FLAG("-lstdc++fs" COMPILER_SUPPORTS_FILESYSTEM) @@ -41,6 +41,7 @@ option(libClaPP_BUILD_DOC_CODE "Build doc code." Off) option(libClaPP_BUILD_COVERAGE "Cretae gcov build." Off) option(libClaPP_SUBMODULE_DEPENDENCIES "Use dependencies from git submodules." Off) option(libClaPP_ENABLE_IPO "Enable Iterprocedural Optimization, aka Link Time Optimization (LTO)" Off) +option(libClaPP_PEDANTIC_COMPILER_FLAGS "Enable pedantic compiler flags." Off) if(libClaPP_ENABLE_IPO) include(CheckIPOSupported) diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index 49a669c5e07129f3b9ae72169abf0e9c8cb341fa..17707a7c4052c292f59375e06cae223ef42763b9 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -9,7 +9,9 @@ add_custom_command( OUTPUT simple_sub_parser.cpp simple_main_parser.cpp DEPENDS add_executable(libclapp_doc_simple_main_parser simple_main_parser.cpp) target_link_libraries(libclapp_doc_simple_main_parser clapp) -target_compile_options(libclapp_doc_simple_main_parser PRIVATE ${libClaPP_COMPILE_OPTIONS}) +if(libClaPP_PEDANTIC_COMPILER_FLAGS) + target_compile_options(libclapp_doc_simple_main_parser PRIVATE ${libClaPP_PEDANTIC_COMPILE_OPTIONS}) +endif() if(CLANG_TIDY) set_target_properties(libclapp_doc_simple_main_parser PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_DOC_ARGS}") endif() @@ -17,7 +19,9 @@ add_test(NAME libclapp_doc_simple_main_parser_test COMMAND ${RAKU_EXECUTABLE} ${ add_executable(libclapp_doc_simple_sub_parser simple_sub_parser.cpp) target_link_libraries(libclapp_doc_simple_sub_parser clapp) -target_compile_options(libclapp_doc_simple_sub_parser PRIVATE ${libClaPP_COMPILE_OPTIONS}) +if(libClaPP_PEDANTIC_COMPILER_FLAGS) + target_compile_options(libclapp_doc_simple_sub_parser PRIVATE ${libClaPP_PEDANTIC_COMPILE_OPTIONS}) +endif() if(CLANG_TIDY) set_target_properties(libclapp_doc_simple_sub_parser PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_DOC_ARGS}") endif() diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 35238ec08543e1b84033438a5e1b30afa318a60d..2821108572a73bad7fa01a43222dad3192ed2611 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -5,7 +5,9 @@ endif() if(libClaPP_FS_LINKER_FLAG) add_executable(libclapp_example_large large_example.cpp) target_link_libraries(libclapp_example_large clapp ${libClaPP_FS_LINKER_FLAG}) - target_compile_options(libclapp_example_large PRIVATE ${libClaPP_COMPILE_OPTIONS}) + if(libClaPP_PEDANTIC_COMPILER_FLAGS) + target_compile_options(libclapp_example_large PRIVATE ${libClaPP_PEDANTIC_COMPILE_OPTIONS}) + endif() if(CLANG_TIDY) set_target_properties(libclapp_example_large PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_EX_ARGS}") endif() @@ -16,7 +18,9 @@ endif() add_executable(libclapp_example_short short_example.cpp) target_link_libraries(libclapp_example_short clapp) -target_compile_options(libclapp_example_short PRIVATE ${libClaPP_COMPILE_OPTIONS}) +if(libClaPP_PEDANTIC_COMPILER_FLAGS) + target_compile_options(libclapp_example_short PRIVATE ${libClaPP_PEDANTIC_COMPILE_OPTIONS}) +endif() if(CLANG_TIDY) set_target_properties(libclapp_example_short PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_EX_ARGS}") endif() @@ -26,7 +30,9 @@ add_test(NAME short_example_tests COMMAND test_short_example.sh WORKING_DIRECTOR add_executable(libclapp_example_sub_parser sub_parser_example.cpp) target_link_libraries(libclapp_example_sub_parser clapp) -target_compile_options(libclapp_example_sub_parser PRIVATE ${libClaPP_COMPILE_OPTIONS}) +if(libClaPP_PEDANTIC_COMPILER_FLAGS) + target_compile_options(libclapp_example_sub_parser PRIVATE ${libClaPP_PEDANTIC_COMPILE_OPTIONS}) +endif() if(CLANG_TIDY) set_target_properties(libclapp_example_sub_parser PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_EX_ARGS}") endif() diff --git a/src/clapp/CMakeLists.txt b/src/clapp/CMakeLists.txt index cbf5a46fc2571c82d20ddf13b4efaef143c98f97..98a18350277092998c7b03b854a42b0bdb4daf4a 100644 --- a/src/clapp/CMakeLists.txt +++ b/src/clapp/CMakeLists.txt @@ -4,7 +4,9 @@ set(libClaPP_INCLUDE_DIRS $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../inclu target_include_directories(clapp PRIVATE ${libClaPP_INCLUDE_DIRS} SYSTEM INTERFACE ${libClaPP_INCLUDE_DIRS} $<INSTALL_INTERFACE:../include>) target_link_libraries(clapp PUBLIC ClaPP_OPTIONS libClaPP_GSL ${libClaPP_FS_LINKER_FLAG}) -target_compile_options(clapp PRIVATE ${libClaPP_COMPILE_OPTIONS}) +if(libClaPP_PEDANTIC_COMPILER_FLAGS) + target_compile_options(clapp PRIVATE ${libClaPP_PEDANTIC_COMPILE_OPTIONS}) +endif() set_target_properties(clapp PROPERTIES VERSION "${libClaPP_VERSION}" POSITION_INDEPENDENT_CODE ON) if(CLANG_TIDY) set_target_properties(clapp PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_ARGS}") diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d5db6696ec67934fcfe144f9e69366bcf15eb50f..9a5e50f39386eb677f2dd14cbd2f746fbe11ee88 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -2,7 +2,9 @@ set(sources value.cpp argument.cpp option.cpp parser.cpp sub_parser.cpp main_par add_executable(libclapp_tests ${sources}) target_link_libraries(libclapp_tests libClaPP_gmock_main clapp) -target_compile_options(libclapp_tests PRIVATE ${libClaPP_TEST_COMPILE_OPTIONS}) +if(libClaPP_PEDANTIC_COMPILER_FLAGS) + target_compile_options(libclapp_tests PRIVATE ${libClaPP_TEST_PEDANTIC_COMPILE_OPTIONS}) +endif() install(TARGETS libclapp_tests DESTINATION ${CMAKE_INSTALL_BINDIR}) if(CLANG_TIDY) set_target_properties(libclapp_tests PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_ARGS},-llvm-include-order,-clang-diagnostic-global-constructors,-hicpp-special-member-functions,-cppcoreguidelines-owning-memory,-cert-err58-cpp,-cppcoreguidelines-special-member-functions,-clang-diagnostic-used-but-marked-unused,-cppcoreguidelines-pro-type-vararg,-clang-diagnostic-covered-switch-default,-hicpp-vararg,-fuchsia-statically-constructed-objects,-cppcoreguidelines-avoid-goto,-hicpp-avoid-goto,-misc-non-private-member-variables-in-classes,-cppcoreguidelines-non-private-member-variables-in-classes,-hicpp-avoid-c-arrays,-modernize-avoid-c-arrays,-cppcoreguidelines-avoid-c-arrays")