From 65f5c8d430dec30e5156f593b704a7de2debf754 Mon Sep 17 00:00:00 2001 From: Vladislav Shchapov Date: Fri, 10 Nov 2023 17:33:30 +0500 Subject: [PATCH 01/11] Enable CI on push Signed-off-by: Vladislav Shchapov --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4324179b..d38d4eec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,7 +1,7 @@ name: CI -on: pull_request +on: [push, pull_request] jobs: From b6275718cb26249e7d328dd132562c04d808b233 Mon Sep 17 00:00:00 2001 From: Vladislav Shchapov Date: Fri, 10 Nov 2023 17:38:49 +0500 Subject: [PATCH 02/11] Allow test and install if argparse is not master project Signed-off-by: Vladislav Shchapov --- CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f9f183f..58814e2c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,8 +13,8 @@ project(argparse LANGUAGES CXX ) -option(ARGPARSE_INSTALL "Include an install target" ON) -option(ARGPARSE_BUILD_TESTS "Build tests" ON) +option(ARGPARSE_INSTALL "Include an install target" ${ARGPARSE_IS_TOP_LEVEL}) +option(ARGPARSE_BUILD_TESTS "Build tests" ${ARGPARSE_IS_TOP_LEVEL}) option(ARGPARSE_BUILD_SAMPLES "Build samples" OFF) include(GNUInstallDirs) @@ -32,11 +32,11 @@ if(ARGPARSE_BUILD_SAMPLES) add_subdirectory(samples) endif() -if(ARGPARSE_BUILD_TESTS AND ARGPARSE_IS_TOP_LEVEL) +if(ARGPARSE_BUILD_TESTS) add_subdirectory(test) endif() -if(ARGPARSE_INSTALL AND ARGPARSE_IS_TOP_LEVEL) +if(ARGPARSE_INSTALL) install(TARGETS argparse EXPORT argparseConfig) install(EXPORT argparseConfig NAMESPACE argparse:: @@ -95,6 +95,6 @@ if(ARGPARSE_INSTALL AND ARGPARSE_IS_TOP_LEVEL) install(FILES "${PKG_CONFIG_FILE_NAME}" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" ) -endif() -include(CPack) + include(CPack) +endif() From 4dfa5cc338ed46938343da1757a3bde8f56bb419 Mon Sep 17 00:00:00 2001 From: Vladislav Shchapov Date: Fri, 10 Nov 2023 18:06:00 +0500 Subject: [PATCH 03/11] Switch to ctest Signed-off-by: Vladislav Shchapov --- .github/workflows/ci.yml | 28 ++++++++++++----------- .gitignore | 3 +++ CMakeLists.txt | 5 +++-- test/CMakeLists.txt | 31 ++++++++++++++------------ test/README.md | 6 ++--- test/main.cpp | 3 ++- test/test_actions.cpp | 2 +- test/test_append.cpp | 2 +- test/test_as_container.cpp | 2 +- test/test_bool_operator.cpp | 2 +- test/test_choices.cpp | 2 +- test/test_compound_arguments.cpp | 4 ++-- test/test_container_arguments.cpp | 4 ++-- test/test_default_args.cpp | 2 +- test/test_default_value.cpp | 2 +- test/test_equals_form.cpp | 2 +- test/test_error_reporting.cpp | 2 +- test/test_get.cpp | 2 +- test/test_help.cpp | 2 +- test/test_invalid_arguments.cpp | 2 +- test/test_is_used.cpp | 2 +- test/test_issue_37.cpp | 2 +- test/test_mutually_exclusive_group.cpp | 2 +- test/test_negative_numbers.cpp | 2 +- test/test_optional_arguments.cpp | 2 +- test/test_parent_parsers.cpp | 2 +- test/test_parse_args.cpp | 2 +- test/test_parse_known_args.cpp | 2 +- test/test_positional_arguments.cpp | 2 +- test/test_prefix_chars.cpp | 2 +- test/test_repr.cpp | 2 +- test/test_required_arguments.cpp | 2 +- test/test_scan.cpp | 2 +- test/test_stringstream.cpp | 2 +- test/test_subparsers.cpp | 2 +- test/test_version.cpp | 2 +- 36 files changed, 75 insertions(+), 65 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d38d4eec..dedae76f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,6 +12,8 @@ jobs: strategy: + fail-fast: false + matrix: toolchain: @@ -63,25 +65,25 @@ jobs: steps: - name: Checkout Code - uses: actions/checkout@v2 + uses: actions/checkout@v3 + + - name: Create Build Environment + run: cmake -E make_directory ${{runner.workspace}}/build - name: Configure - working-directory: test - run: cmake -S . -B build ${{ matrix.cmake_opts }} + working-directory: ${{runner.workspace}}/build + shell: bash + run: cmake -DCMAKE_BUILD_TYPE=Release ${{ matrix.cmake_opts }} $GITHUB_WORKSPACE env: CC: ${{ matrix.c_compiler }} CXX: ${{ matrix.cxx_compiler }} - name: Build for ${{ matrix.os }} with ${{ matrix.compiler }} - working-directory: test - run: cmake --build build + working-directory: ${{runner.workspace}}/build + run: cmake --build . --config Release - name: Test - if: ${{ ! startsWith(matrix.os, 'windows') }} - working-directory: test/build - run: ./tests - - - name: Test (Windows) - if: ${{ startsWith(matrix.os, 'windows') }} - working-directory: test/build - run: ./Debug/tests.exe + working-directory: ${{runner.workspace}}/build + run: ctest -C Release -V + env: + CTEST_OUTPUT_ON_FAILURE: True diff --git a/.gitignore b/.gitignore index cdcb6f62..fded6749 100644 --- a/.gitignore +++ b/.gitignore @@ -264,6 +264,9 @@ __pycache__/ # CMake build directory build +# CMake Testing directory +Testing + # Cppcheck build directory analysis-cppcheck-build-dir diff --git a/CMakeLists.txt b/CMakeLists.txt index 58814e2c..248c16f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,11 +31,12 @@ target_include_directories(argparse INTERFACE if(ARGPARSE_BUILD_SAMPLES) add_subdirectory(samples) endif() - + if(ARGPARSE_BUILD_TESTS) + enable_testing() add_subdirectory(test) endif() - + if(ARGPARSE_INSTALL) install(TARGETS argparse EXPORT argparseConfig) install(EXPORT argparseConfig diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 587eb824..4be29ba2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,5 +1,3 @@ -cmake_minimum_required(VERSION 3.6) -project(argparse_tests) if(MSVC) # Force to always compile with W4 @@ -8,9 +6,12 @@ if(MSVC) else() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4") endif() -elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) +elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU") # Update if necessary - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long -Wpedantic -Wsign-conversion -Wshadow -Wconversion -Werror -Wextra") + set(ARGPARSE_PEDANTIC_COMPILE_FLAGS -Wall -Wno-long-long -Wpedantic -Wsign-conversion -Wshadow -Wconversion -Werror -Wextra) +elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + # Update if necessary + set(ARGPARSE_PEDANTIC_COMPILE_FLAGS -Wall -Wno-long-long -Wpedantic -Wsign-conversion -Wshadow -Wconversion -Werror -Wextra) endif() if(NOT CMAKE_BUILD_TYPE) @@ -19,7 +20,11 @@ endif() # Disable deprecation for windows if (WIN32) - add_compile_definitions(_CRT_SECURE_NO_WARNINGS) + add_compile_definitions(_CRT_SECURE_NO_WARNINGS) +endif() + +if(NOT CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 17) endif() # ARGPARSE executable @@ -56,13 +61,11 @@ file(GLOB ARGPARSE_TEST_SOURCES test_equals_form.cpp test_prefix_chars.cpp ) -set_source_files_properties(main.cpp - PROPERTIES - COMPILE_DEFINITIONS DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN) -ADD_EXECUTABLE(ARGPARSE_TESTS ${ARGPARSE_TEST_SOURCES}) -INCLUDE_DIRECTORIES("../include" ".") -set_target_properties(ARGPARSE_TESTS PROPERTIES OUTPUT_NAME tests) -set_property(TARGET ARGPARSE_TESTS PROPERTY CXX_STANDARD 17) -# Set ${PROJECT_NAME} as the startup project -set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ARGPARSE_TESTS) +add_executable(argparse_tests ${ARGPARSE_TEST_SOURCES}) +if(ARGPARSE_PEDANTIC_COMPILE_FLAGS) + target_compile_options(argparse_tests PRIVATE ${ARGPARSE_PEDANTIC_COMPILE_FLAGS}) +endif() +target_link_libraries(argparse_tests PRIVATE argparse::argparse) + +add_test(NAME argparse_tests COMMAND argparse_tests) diff --git a/test/README.md b/test/README.md index 491cf1a6..f127ccc2 100644 --- a/test/README.md +++ b/test/README.md @@ -7,7 +7,7 @@ $ mkdir build $ cd build $ cmake ../. $ make -$ ./tests +$ ./argparse_tests ``` ## Windows @@ -21,5 +21,5 @@ $ cmake ../. -G "Visual Studio 15 2017" ``` 2. Open ARGPARSE.sln -3. Build tests in RELEASE | x64 -4. Run tests.exe +3. Build argparse_tests in RELEASE | x64 +4. Run argparse_tests.exe diff --git a/test/main.cpp b/test/main.cpp index 53c0a370..9076ec34 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -1 +1,2 @@ -#include +#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN +#include "doctest.hpp" diff --git a/test/test_actions.cpp b/test/test_actions.cpp index aa8cd3de..febbed4c 100644 --- a/test/test_actions.cpp +++ b/test/test_actions.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" using doctest::test_suite; diff --git a/test/test_append.cpp b/test/test_append.cpp index 8a68c65d..8e419bff 100644 --- a/test/test_append.cpp +++ b/test/test_append.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" #include #include diff --git a/test/test_as_container.cpp b/test/test_as_container.cpp index 37f725ec..cb2f0cbc 100644 --- a/test/test_as_container.cpp +++ b/test/test_as_container.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" using doctest::test_suite; diff --git a/test/test_bool_operator.cpp b/test/test_bool_operator.cpp index a34b5d64..5e8d4149 100644 --- a/test/test_bool_operator.cpp +++ b/test/test_bool_operator.cpp @@ -4,7 +4,7 @@ import argparse; #include #endif -#include +#include "doctest.hpp" using doctest::test_suite; diff --git a/test/test_choices.cpp b/test/test_choices.cpp index 678aba82..b176956e 100644 --- a/test/test_choices.cpp +++ b/test/test_choices.cpp @@ -4,7 +4,7 @@ import argparse; #include #endif -#include +#include "doctest.hpp" using doctest::test_suite; diff --git a/test/test_compound_arguments.cpp b/test/test_compound_arguments.cpp index 927e5b2e..78bb098f 100644 --- a/test/test_compound_arguments.cpp +++ b/test/test_compound_arguments.cpp @@ -3,8 +3,8 @@ import argparse; #else #include #endif -#include -#include +#include "doctest.hpp" +#include "test_utility.hpp" using doctest::test_suite; diff --git a/test/test_container_arguments.cpp b/test/test_container_arguments.cpp index e6596950..8d52d4ad 100644 --- a/test/test_container_arguments.cpp +++ b/test/test_container_arguments.cpp @@ -3,8 +3,8 @@ import argparse; #else #include #endif -#include -#include +#include "doctest.hpp" +#include "test_utility.hpp" using doctest::test_suite; diff --git a/test/test_default_args.cpp b/test/test_default_args.cpp index 4b813fb4..5fbb7561 100644 --- a/test/test_default_args.cpp +++ b/test/test_default_args.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" #include #include diff --git a/test/test_default_value.cpp b/test/test_default_value.cpp index 5287173b..48cf64c9 100644 --- a/test/test_default_value.cpp +++ b/test/test_default_value.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" #include using doctest::test_suite; diff --git a/test/test_equals_form.cpp b/test/test_equals_form.cpp index a4b89a49..5afa2212 100644 --- a/test/test_equals_form.cpp +++ b/test/test_equals_form.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" #include #include diff --git a/test/test_error_reporting.cpp b/test/test_error_reporting.cpp index 0c911321..6a5f064e 100644 --- a/test/test_error_reporting.cpp +++ b/test/test_error_reporting.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" #include #include diff --git a/test/test_get.cpp b/test/test_get.cpp index 13db01c4..ea9e1db9 100644 --- a/test/test_get.cpp +++ b/test/test_get.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" #include diff --git a/test/test_help.cpp b/test/test_help.cpp index 864a8077..17c0b728 100644 --- a/test/test_help.cpp +++ b/test/test_help.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" #include #include diff --git a/test/test_invalid_arguments.cpp b/test/test_invalid_arguments.cpp index 86e344cc..fedc398c 100644 --- a/test/test_invalid_arguments.cpp +++ b/test/test_invalid_arguments.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" using doctest::test_suite; diff --git a/test/test_is_used.cpp b/test/test_is_used.cpp index cfb6e439..72ba17f3 100644 --- a/test/test_is_used.cpp +++ b/test/test_is_used.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" using doctest::test_suite; diff --git a/test/test_issue_37.cpp b/test/test_issue_37.cpp index 7e8e2bc1..ac8c7d1a 100644 --- a/test/test_issue_37.cpp +++ b/test/test_issue_37.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" using doctest::test_suite; diff --git a/test/test_mutually_exclusive_group.cpp b/test/test_mutually_exclusive_group.cpp index f2433647..3d368ebb 100644 --- a/test/test_mutually_exclusive_group.cpp +++ b/test/test_mutually_exclusive_group.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" using doctest::test_suite; diff --git a/test/test_negative_numbers.cpp b/test/test_negative_numbers.cpp index f9dd463c..e4d85757 100644 --- a/test/test_negative_numbers.cpp +++ b/test/test_negative_numbers.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" using doctest::test_suite; diff --git a/test/test_optional_arguments.cpp b/test/test_optional_arguments.cpp index 74a4c25a..2f8097ed 100644 --- a/test/test_optional_arguments.cpp +++ b/test/test_optional_arguments.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" using doctest::test_suite; diff --git a/test/test_parent_parsers.cpp b/test/test_parent_parsers.cpp index 9f9a7f80..60890a62 100644 --- a/test/test_parent_parsers.cpp +++ b/test/test_parent_parsers.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" using doctest::test_suite; diff --git a/test/test_parse_args.cpp b/test/test_parse_args.cpp index bb3af2a0..b56ea9bc 100644 --- a/test/test_parse_args.cpp +++ b/test/test_parse_args.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" #include diff --git a/test/test_parse_known_args.cpp b/test/test_parse_known_args.cpp index 909621f7..9b2976fa 100644 --- a/test/test_parse_known_args.cpp +++ b/test/test_parse_known_args.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" #include #include diff --git a/test/test_positional_arguments.cpp b/test/test_positional_arguments.cpp index 16650488..f80c8789 100644 --- a/test/test_positional_arguments.cpp +++ b/test/test_positional_arguments.cpp @@ -4,7 +4,7 @@ import argparse; #include #endif #include -#include +#include "doctest.hpp" using doctest::test_suite; diff --git a/test/test_prefix_chars.cpp b/test/test_prefix_chars.cpp index a5c3394c..0739d43b 100644 --- a/test/test_prefix_chars.cpp +++ b/test/test_prefix_chars.cpp @@ -4,7 +4,7 @@ import argparse; #include #endif #include -#include +#include "doctest.hpp" using doctest::test_suite; diff --git a/test/test_repr.cpp b/test/test_repr.cpp index d924a720..c31b576d 100644 --- a/test/test_repr.cpp +++ b/test/test_repr.cpp @@ -4,7 +4,7 @@ import argparse.details; #else #include #endif -#include +#include "doctest.hpp" #include #include diff --git a/test/test_required_arguments.cpp b/test/test_required_arguments.cpp index 7d7a077e..6a22415d 100644 --- a/test/test_required_arguments.cpp +++ b/test/test_required_arguments.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" using doctest::test_suite; diff --git a/test/test_scan.cpp b/test/test_scan.cpp index c556cb90..45f65a4e 100644 --- a/test/test_scan.cpp +++ b/test/test_scan.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" #include using doctest::test_suite; diff --git a/test/test_stringstream.cpp b/test/test_stringstream.cpp index 105bb409..620d06eb 100644 --- a/test/test_stringstream.cpp +++ b/test/test_stringstream.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" #include #include diff --git a/test/test_subparsers.cpp b/test/test_subparsers.cpp index 532c9a7e..b75e98e5 100644 --- a/test/test_subparsers.cpp +++ b/test/test_subparsers.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" #include #include diff --git a/test/test_version.cpp b/test/test_version.cpp index 3179f566..641a727f 100644 --- a/test/test_version.cpp +++ b/test/test_version.cpp @@ -3,7 +3,7 @@ import argparse; #else #include #endif -#include +#include "doctest.hpp" #include using doctest::test_suite; From 7c976519f30628515bfa997f0a7f02110575dd39 Mon Sep 17 00:00:00 2001 From: Vladislav Shchapov Date: Fri, 10 Nov 2023 18:51:45 +0500 Subject: [PATCH 04/11] Build samples in CI Signed-off-by: Vladislav Shchapov --- .github/workflows/ci.yml | 2 +- samples/CMakeLists.txt | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dedae76f..84867763 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,7 +73,7 @@ jobs: - name: Configure working-directory: ${{runner.workspace}}/build shell: bash - run: cmake -DCMAKE_BUILD_TYPE=Release ${{ matrix.cmake_opts }} $GITHUB_WORKSPACE + run: cmake -DARGPARSE_BUILD_SAMPLES=ON -DCMAKE_BUILD_TYPE=Release ${{ matrix.cmake_opts }} $GITHUB_WORKSPACE env: CC: ${{ matrix.c_compiler }} CXX: ${{ matrix.cxx_compiler }} diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index dfcc9272..87e4ca64 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -1,5 +1,3 @@ -cmake_minimum_required(VERSION 3.6) -project(argparse_samples) if(MSVC) # Force to always compile with W4 @@ -16,6 +14,9 @@ endif() if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) endif() +if(NOT CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 17) +endif() # Disable deprecation for windows if (WIN32) @@ -23,10 +24,9 @@ if (WIN32) endif() function(add_sample NAME) - ADD_EXECUTABLE(ARGPARSE_SAMPLE_${NAME} ${NAME}.cpp) - INCLUDE_DIRECTORIES("../include" ".") - set_target_properties(ARGPARSE_SAMPLE_${NAME} PROPERTIES OUTPUT_NAME ${NAME}) - set_property(TARGET ARGPARSE_SAMPLE_${NAME} PROPERTY CXX_STANDARD 17) + add_executable(argparse_sample_${NAME} ${NAME}.cpp) + target_link_libraries(argparse_sample_${NAME} PRIVATE argparse::argparse) + set_target_properties(argparse_sample_${NAME} PROPERTIES OUTPUT_NAME ${NAME}) endfunction() add_sample(positional_argument) @@ -43,4 +43,4 @@ add_sample(gathering_remaining_arguments) add_sample(subcommands) add_sample(parse_known_args) add_sample(custom_prefix_characters) -add_sample(custom_assignment_characters) \ No newline at end of file +add_sample(custom_assignment_characters) From c5d76b7696cef3000e1c7fb633a81cf71b78ed07 Mon Sep 17 00:00:00 2001 From: Vladislav Shchapov Date: Fri, 10 Nov 2023 18:59:40 +0500 Subject: [PATCH 05/11] Unification of build params for tests and samples Signed-off-by: Vladislav Shchapov --- CMakeLists.txt | 20 ++++++++++++++++++++ samples/CMakeLists.txt | 31 +++++++------------------------ test/CMakeLists.txt | 32 ++++---------------------------- 3 files changed, 31 insertions(+), 52 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 248c16f1..4b82f13d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,26 @@ target_include_directories(argparse INTERFACE $ $) + +# Pedantic compiler options +# Update if necessary +if(MSVC) + set(ARGPARSE_PEDANTIC_COMPILE_FLAGS "/W4") + #list(APPEND ARGPARSE_PEDANTIC_COMPILE_FLAGS "/WX") +elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU") + set(ARGPARSE_PEDANTIC_COMPILE_FLAGS -Wall -Wno-long-long -pedantic -Wsign-conversion -Wshadow -Wconversion -Werror -Wextra) +elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(ARGPARSE_PEDANTIC_COMPILE_FLAGS -Wall -Wno-long-long -pedantic -Wsign-conversion -Wshadow -Wconversion -Werror -Wextra) +endif() + +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release) +endif() + +if(NOT CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 17) +endif() + if(ARGPARSE_BUILD_SAMPLES) add_subdirectory(samples) endif() diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 87e4ca64..18a92fd4 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -1,31 +1,14 @@ -if(MSVC) - # Force to always compile with W4 - if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") - string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4") - endif() -elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) - # Update if necessary - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long -pedantic -Wsign-conversion -Wshadow -Wconversion") -endif() - -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Release) -endif() -if(NOT CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 17) -endif() - -# Disable deprecation for windows -if (WIN32) - add_compile_definitions(_CRT_SECURE_NO_WARNINGS) -endif() - function(add_sample NAME) add_executable(argparse_sample_${NAME} ${NAME}.cpp) target_link_libraries(argparse_sample_${NAME} PRIVATE argparse::argparse) + if(ARGPARSE_PEDANTIC_COMPILE_FLAGS) + target_compile_options(argparse_sample_${NAME} PRIVATE ${ARGPARSE_PEDANTIC_COMPILE_FLAGS}) + endif() + + # Disable deprecation for windows + target_compile_definitions(argparse_sample_${NAME} PRIVATE _CRT_SECURE_NO_WARNINGS) + set_target_properties(argparse_sample_${NAME} PROPERTIES OUTPUT_NAME ${NAME}) endfunction() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4be29ba2..e67e04e1 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,33 +1,6 @@ -if(MSVC) - # Force to always compile with W4 - if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") - string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4") - endif() -elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU") - # Update if necessary - set(ARGPARSE_PEDANTIC_COMPILE_FLAGS -Wall -Wno-long-long -Wpedantic -Wsign-conversion -Wshadow -Wconversion -Werror -Wextra) -elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - # Update if necessary - set(ARGPARSE_PEDANTIC_COMPILE_FLAGS -Wall -Wno-long-long -Wpedantic -Wsign-conversion -Wshadow -Wconversion -Werror -Wextra) -endif() - -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Release) -endif() - -# Disable deprecation for windows -if (WIN32) - add_compile_definitions(_CRT_SECURE_NO_WARNINGS) -endif() - -if(NOT CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 17) -endif() -# ARGPARSE executable +# ARGPARSE test executable file(GLOB ARGPARSE_TEST_SOURCES main.cpp test_actions.cpp @@ -68,4 +41,7 @@ if(ARGPARSE_PEDANTIC_COMPILE_FLAGS) endif() target_link_libraries(argparse_tests PRIVATE argparse::argparse) +# Disable deprecation for windows +target_compile_definitions(argparse_tests PRIVATE _CRT_SECURE_NO_WARNINGS) + add_test(NAME argparse_tests COMMAND argparse_tests) From 08510212e58e82d2fd83e0fb37ae242ddb89c862 Mon Sep 17 00:00:00 2001 From: Vladislav Shchapov Date: Fri, 10 Nov 2023 19:41:21 +0500 Subject: [PATCH 06/11] Enable warning as error for MSVC Signed-off-by: Vladislav Shchapov --- CMakeLists.txt | 9 +++++++-- samples/gathering_remaining_arguments.cpp | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b82f13d..a92cf775 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,8 +32,13 @@ target_include_directories(argparse INTERFACE # Pedantic compiler options # Update if necessary if(MSVC) - set(ARGPARSE_PEDANTIC_COMPILE_FLAGS "/W4") - #list(APPEND ARGPARSE_PEDANTIC_COMPILE_FLAGS "/WX") + # Force to always compile with W4 + if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") + string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + else() + set(ARGPARSE_PEDANTIC_COMPILE_FLAGS "/W4") + endif() + list(APPEND ARGPARSE_PEDANTIC_COMPILE_FLAGS "/WX") elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU") set(ARGPARSE_PEDANTIC_COMPILE_FLAGS -Wall -Wno-long-long -pedantic -Wsign-conversion -Wshadow -Wconversion -Werror -Wextra) elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") diff --git a/samples/gathering_remaining_arguments.cpp b/samples/gathering_remaining_arguments.cpp index 099b07f8..46423e37 100644 --- a/samples/gathering_remaining_arguments.cpp +++ b/samples/gathering_remaining_arguments.cpp @@ -20,7 +20,7 @@ int main(int argc, char *argv[]) { std::cout << files.size() << " files provided" << std::endl; for (auto &file : files) std::cout << file << std::endl; - } catch (std::logic_error &e) { + } catch (const std::logic_error &) { std::cout << "No files provided" << std::endl; } } \ No newline at end of file From d29ee968a724bf1a234e05cb38fe573bf1a9f1a6 Mon Sep 17 00:00:00 2001 From: Vladislav Shchapov Date: Fri, 10 Nov 2023 20:09:02 +0500 Subject: [PATCH 07/11] Remove _CRT_SECURE_NO_WARNINGS Signed-off-by: Vladislav Shchapov --- samples/CMakeLists.txt | 4 ---- test/CMakeLists.txt | 4 ---- 2 files changed, 8 deletions(-) diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 18a92fd4..36d7024e 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -5,10 +5,6 @@ function(add_sample NAME) if(ARGPARSE_PEDANTIC_COMPILE_FLAGS) target_compile_options(argparse_sample_${NAME} PRIVATE ${ARGPARSE_PEDANTIC_COMPILE_FLAGS}) endif() - - # Disable deprecation for windows - target_compile_definitions(argparse_sample_${NAME} PRIVATE _CRT_SECURE_NO_WARNINGS) - set_target_properties(argparse_sample_${NAME} PROPERTIES OUTPUT_NAME ${NAME}) endfunction() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e67e04e1..ecab89db 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -40,8 +40,4 @@ if(ARGPARSE_PEDANTIC_COMPILE_FLAGS) target_compile_options(argparse_tests PRIVATE ${ARGPARSE_PEDANTIC_COMPILE_FLAGS}) endif() target_link_libraries(argparse_tests PRIVATE argparse::argparse) - -# Disable deprecation for windows -target_compile_definitions(argparse_tests PRIVATE _CRT_SECURE_NO_WARNINGS) - add_test(NAME argparse_tests COMMAND argparse_tests) From 1c57e16e9ade5c7ebebc95bb1790f994f350bea0 Mon Sep 17 00:00:00 2001 From: Vladislav Shchapov Date: Fri, 10 Nov 2023 20:22:56 +0500 Subject: [PATCH 08/11] cmake verbose build Signed-off-by: Vladislav Shchapov --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 84867763..9e9cda16 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -80,7 +80,7 @@ jobs: - name: Build for ${{ matrix.os }} with ${{ matrix.compiler }} working-directory: ${{runner.workspace}}/build - run: cmake --build . --config Release + run: cmake --build . --config Release --verbose - name: Test working-directory: ${{runner.workspace}}/build From b9a08e1bf9a830f4a37a5882e43706416ba76c98 Mon Sep 17 00:00:00 2001 From: Vladislav Shchapov Date: Fri, 10 Nov 2023 20:27:44 +0500 Subject: [PATCH 09/11] debug build Signed-off-by: Vladislav Shchapov --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9e9cda16..a1b2fed1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,17 +73,17 @@ jobs: - name: Configure working-directory: ${{runner.workspace}}/build shell: bash - run: cmake -DARGPARSE_BUILD_SAMPLES=ON -DCMAKE_BUILD_TYPE=Release ${{ matrix.cmake_opts }} $GITHUB_WORKSPACE + run: cmake -DARGPARSE_BUILD_SAMPLES=ON -DCMAKE_BUILD_TYPE=Debug ${{ matrix.cmake_opts }} $GITHUB_WORKSPACE env: CC: ${{ matrix.c_compiler }} CXX: ${{ matrix.cxx_compiler }} - name: Build for ${{ matrix.os }} with ${{ matrix.compiler }} working-directory: ${{runner.workspace}}/build - run: cmake --build . --config Release --verbose + run: cmake --build . --config Debug --verbose - name: Test working-directory: ${{runner.workspace}}/build - run: ctest -C Release -V + run: ctest -C Debug -V env: CTEST_OUTPUT_ON_FAILURE: True From 869f054e9b14e6a701d1941581022a8836c32778 Mon Sep 17 00:00:00 2001 From: Vladislav Shchapov Date: Fri, 10 Nov 2023 20:32:14 +0500 Subject: [PATCH 10/11] Fix MSVC warning: unreachable code Signed-off-by: Vladislav Shchapov --- include/argparse/argparse.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/argparse/argparse.hpp b/include/argparse/argparse.hpp index 0c85127d..3ddeef8b 100644 --- a/include/argparse/argparse.hpp +++ b/include/argparse/argparse.hpp @@ -1387,8 +1387,9 @@ class Argument { } if constexpr (details::IsContainer) { return any_cast_container(m_values); + } else { + return std::any_cast(m_values.front()); } - return std::any_cast(m_values.front()); } template From b1aee23066c315b0a00e017781d5dd003d9c1660 Mon Sep 17 00:00:00 2001 From: Vladislav Shchapov Date: Fri, 10 Nov 2023 20:36:18 +0500 Subject: [PATCH 11/11] Fix xmake.lua Signed-off-by: Vladislav Shchapov --- xmake.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/xmake.lua b/xmake.lua index c95bda3a..ab45def4 100644 --- a/xmake.lua +++ b/xmake.lua @@ -48,7 +48,6 @@ if get_config("enable_tests") then add_includedirs("test") - add_files("test/main.cpp", { defines = { "DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN" } }) add_files("test/**.cpp") add_deps("argparse") @@ -64,7 +63,6 @@ if get_config("enable_tests") then add_includedirs("test") - add_files("test/main.cpp", { defines = { "DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN" } }) add_files("test/**.cpp") add_files("test/argparse_details.cppm")