From 7a13042264595124ee3af0aa646e4224a334181d Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sun, 15 Oct 2023 17:08:22 +0200 Subject: [PATCH 01/10] use inline constexpr instead of static constexpr for free constants --- include/argparse/argparse.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/argparse/argparse.hpp b/include/argparse/argparse.hpp index a779e01..9226649 100644 --- a/include/argparse/argparse.hpp +++ b/include/argparse/argparse.hpp @@ -72,7 +72,7 @@ struct HasContainerTraits< decltype(std::declval().size())>> : std::true_type {}; template -static constexpr bool IsContainer = HasContainerTraits::value; +inline constexpr bool IsContainer = HasContainerTraits::value; template struct HasStreamableTraits : std::false_type {}; @@ -84,7 +84,7 @@ struct HasStreamableTraits< : std::true_type {}; template -static constexpr bool IsStreamable = HasStreamableTraits::value; +inline constexpr bool IsStreamable = HasStreamableTraits::value; constexpr std::size_t repr_max_container_size = 5; From 23aff1938a0140d1fe294f7bd4cd522cf6611d77 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sun, 15 Oct 2023 17:13:56 +0200 Subject: [PATCH 02/10] add argparse C++20 module --- include/argparse/argparse.hpp | 3 +++ module/argparse.cppm | 49 +++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 module/argparse.cppm diff --git a/include/argparse/argparse.hpp b/include/argparse/argparse.hpp index 9226649..668b52a 100644 --- a/include/argparse/argparse.hpp +++ b/include/argparse/argparse.hpp @@ -29,6 +29,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #pragma once + +#ifndef ARGPARSE_MODULE_USE_STD_MODULE #include #include #include @@ -53,6 +55,7 @@ SOFTWARE. #include #include #include +#endif namespace argparse { diff --git a/module/argparse.cppm b/module/argparse.cppm new file mode 100644 index 0000000..2c78428 --- /dev/null +++ b/module/argparse.cppm @@ -0,0 +1,49 @@ +/* + __ _ _ __ __ _ _ __ __ _ _ __ ___ ___ + / _` | '__/ _` | '_ \ / _` | '__/ __|/ _ \ Argument Parser for Modern C++ +| (_| | | | (_| | |_) | (_| | | \__ \ __/ http://github.com/p-ranav/argparse + \__,_|_| \__, | .__/ \__,_|_| |___/\___| + |___/|_| + +Licensed under the MIT License . +SPDX-License-Identifier: MIT +Copyright (c) 2019-2022 Pranav Srinivas Kumar +and other contributors. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +module; + +#include + +export module argparse; + +#ifdef ARGPARSE_MODULE_USE_STD_MODULE +import std; +#endif + +export namespace argparse { + using argparse::nargs_pattern; + using argparse::default_arguments; + using argparse::operator&; + using argparse::Argument; + using argparse::ArgumentParser; +} + From 6723c81877e582a56ff3729357772041fadeca54 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sun, 15 Oct 2023 18:51:56 +0200 Subject: [PATCH 03/10] update test to use module when WITH_MODULE macro is set --- test/argparse_details.cppm | 10 ++++++++++ test/test_actions.cpp | 4 ++++ test/test_append.cpp | 7 +++++++ test/test_as_container.cpp | 4 ++++ test/test_bool_operator.cpp | 5 +++++ test/test_compound_arguments.cpp | 4 ++++ test/test_const_correct.cpp | 4 ++++ test/test_container_arguments.cpp | 4 ++++ test/test_default_args.cpp | 6 ++++++ test/test_default_value.cpp | 4 ++++ test/test_equals_form.cpp | 10 +++++++++- test/test_get.cpp | 6 ++++++ test/test_help.cpp | 6 ++++++ test/test_invalid_arguments.cpp | 4 ++++ test/test_is_used.cpp | 4 ++++ test/test_issue_37.cpp | 4 ++++ test/test_negative_numbers.cpp | 4 ++++ test/test_optional_arguments.cpp | 4 ++++ test/test_parent_parsers.cpp | 4 ++++ test/test_parse_args.cpp | 6 ++++++ test/test_parse_known_args.cpp | 9 ++++++++- test/test_positional_arguments.cpp | 4 ++++ test/test_prefix_chars.cpp | 4 ++++ test/test_repr.cpp | 8 ++++++++ test/test_required_arguments.cpp | 4 ++++ test/test_scan.cpp | 4 ++++ test/test_subparsers.cpp | 11 +++++++++-- test/test_utility.hpp | 2 ++ test/test_value_semantics.cpp | 4 ++++ test/test_version.cpp | 4 ++++ 30 files changed, 154 insertions(+), 4 deletions(-) create mode 100644 test/argparse_details.cppm diff --git a/test/argparse_details.cppm b/test/argparse_details.cppm new file mode 100644 index 0000000..1c1668d --- /dev/null +++ b/test/argparse_details.cppm @@ -0,0 +1,10 @@ +module; + +#include + +export module argparse.details; + +export namespace argparse::details { + using argparse::details::repr; +} + diff --git a/test/test_actions.cpp b/test/test_actions.cpp index 07f59c9..aa8cd3d 100644 --- a/test/test_actions.cpp +++ b/test/test_actions.cpp @@ -1,4 +1,8 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include using doctest::test_suite; diff --git a/test/test_append.cpp b/test/test_append.cpp index 4934514..0114f71 100644 --- a/test/test_append.cpp +++ b/test/test_append.cpp @@ -1,6 +1,13 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include +#include +#include + using doctest::test_suite; TEST_CASE("Simplest .append" * test_suite("append")) { diff --git a/test/test_as_container.cpp b/test/test_as_container.cpp index 2f795fb..fb6e87c 100644 --- a/test/test_as_container.cpp +++ b/test/test_as_container.cpp @@ -1,4 +1,8 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include using doctest::test_suite; diff --git a/test/test_bool_operator.cpp b/test/test_bool_operator.cpp index 93a3be2..aada150 100644 --- a/test/test_bool_operator.cpp +++ b/test/test_bool_operator.cpp @@ -1,4 +1,9 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif + #include using doctest::test_suite; diff --git a/test/test_compound_arguments.cpp b/test/test_compound_arguments.cpp index 3bc1601..fc25fdc 100644 --- a/test/test_compound_arguments.cpp +++ b/test/test_compound_arguments.cpp @@ -1,4 +1,8 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include #include diff --git a/test/test_const_correct.cpp b/test/test_const_correct.cpp index 1acfdd4..a139679 100644 --- a/test/test_const_correct.cpp +++ b/test/test_const_correct.cpp @@ -1,4 +1,8 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include using doctest::test_suite; diff --git a/test/test_container_arguments.cpp b/test/test_container_arguments.cpp index 5eab026..e659695 100644 --- a/test/test_container_arguments.cpp +++ b/test/test_container_arguments.cpp @@ -1,4 +1,8 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include #include diff --git a/test/test_default_args.cpp b/test/test_default_args.cpp index d0cdd25..61fbabc 100644 --- a/test/test_default_args.cpp +++ b/test/test_default_args.cpp @@ -1,7 +1,13 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include + #include #include +#include using doctest::test_suite; diff --git a/test/test_default_value.cpp b/test/test_default_value.cpp index 15271f9..1a28168 100644 --- a/test/test_default_value.cpp +++ b/test/test_default_value.cpp @@ -1,4 +1,8 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include #include diff --git a/test/test_equals_form.cpp b/test/test_equals_form.cpp index 81c31f8..6d95c3e 100644 --- a/test/test_equals_form.cpp +++ b/test/test_equals_form.cpp @@ -1,6 +1,14 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include + #include +#include +#include + using doctest::test_suite; TEST_CASE("Basic --value=value" * test_suite("equals_form")) { @@ -36,4 +44,4 @@ TEST_CASE("Basic --value=value with nargs(2)" * test_suite("equals_form")) { parser.parse_args({"test", "--long=value1", "value2"}); REQUIRE((parser.get>("--long") == std::vector{"value1", "value2"})); -} \ No newline at end of file +} diff --git a/test/test_get.cpp b/test/test_get.cpp index ad719b0..d2144a1 100644 --- a/test/test_get.cpp +++ b/test/test_get.cpp @@ -1,6 +1,12 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include +#include + using doctest::test_suite; TEST_CASE("Getting a simple argument" * test_suite("ArgumentParser::get")) { diff --git a/test/test_help.cpp b/test/test_help.cpp index 293daef..2f29e56 100644 --- a/test/test_help.cpp +++ b/test/test_help.cpp @@ -1,6 +1,12 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include + #include +#include using doctest::test_suite; diff --git a/test/test_invalid_arguments.cpp b/test/test_invalid_arguments.cpp index e8db3f2..86e344c 100644 --- a/test/test_invalid_arguments.cpp +++ b/test/test_invalid_arguments.cpp @@ -1,4 +1,8 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include using doctest::test_suite; diff --git a/test/test_is_used.cpp b/test/test_is_used.cpp index 8d67b85..cfb6e43 100644 --- a/test/test_is_used.cpp +++ b/test/test_is_used.cpp @@ -1,4 +1,8 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include using doctest::test_suite; diff --git a/test/test_issue_37.cpp b/test/test_issue_37.cpp index ab9c984..7e8e2bc 100644 --- a/test/test_issue_37.cpp +++ b/test/test_issue_37.cpp @@ -1,4 +1,8 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include using doctest::test_suite; diff --git a/test/test_negative_numbers.cpp b/test/test_negative_numbers.cpp index fd9b1f9..f9dd463 100644 --- a/test/test_negative_numbers.cpp +++ b/test/test_negative_numbers.cpp @@ -1,4 +1,8 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include using doctest::test_suite; diff --git a/test/test_optional_arguments.cpp b/test/test_optional_arguments.cpp index dd9cec6..65ea25f 100644 --- a/test/test_optional_arguments.cpp +++ b/test/test_optional_arguments.cpp @@ -1,4 +1,8 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include using doctest::test_suite; diff --git a/test/test_parent_parsers.cpp b/test/test_parent_parsers.cpp index ffb9e00..9f9a7f8 100644 --- a/test/test_parent_parsers.cpp +++ b/test/test_parent_parsers.cpp @@ -1,4 +1,8 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include using doctest::test_suite; diff --git a/test/test_parse_args.cpp b/test/test_parse_args.cpp index 7a38abf..bb3af2a 100644 --- a/test/test_parse_args.cpp +++ b/test/test_parse_args.cpp @@ -1,6 +1,12 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include +#include + using doctest::test_suite; TEST_CASE("Missing argument" * test_suite("parse_args")) { diff --git a/test/test_parse_known_args.cpp b/test/test_parse_known_args.cpp index 2a9da84..d5a939c 100644 --- a/test/test_parse_known_args.cpp +++ b/test/test_parse_known_args.cpp @@ -1,6 +1,13 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include +#include +#include + using doctest::test_suite; TEST_CASE("Parse unknown optional and positional arguments without exceptions" * @@ -79,4 +86,4 @@ TEST_CASE("Parse unknown optional and positional arguments in subparsers " REQUIRE((unknown_args == std::vector{"--verbose", "FOO", "5", "BAR", "-jn", "spam"})); } -} \ No newline at end of file +} diff --git a/test/test_positional_arguments.cpp b/test/test_positional_arguments.cpp index cfee488..1665048 100644 --- a/test/test_positional_arguments.cpp +++ b/test/test_positional_arguments.cpp @@ -1,4 +1,8 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include #include diff --git a/test/test_prefix_chars.cpp b/test/test_prefix_chars.cpp index e62b1d9..eb26273 100644 --- a/test/test_prefix_chars.cpp +++ b/test/test_prefix_chars.cpp @@ -1,4 +1,8 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include #include diff --git a/test/test_repr.cpp b/test/test_repr.cpp index c09c3ac..f7330bc 100644 --- a/test/test_repr.cpp +++ b/test/test_repr.cpp @@ -1,6 +1,14 @@ +#ifdef WITH_MODULE +import argparse; +import argparse.details; +#else #include +#endif #include + #include +#include +#include using doctest::test_suite; diff --git a/test/test_required_arguments.cpp b/test/test_required_arguments.cpp index 299808a..7d7a077 100644 --- a/test/test_required_arguments.cpp +++ b/test/test_required_arguments.cpp @@ -1,4 +1,8 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include using doctest::test_suite; diff --git a/test/test_scan.cpp b/test/test_scan.cpp index 6cc53e5..4210d8f 100644 --- a/test/test_scan.cpp +++ b/test/test_scan.cpp @@ -1,4 +1,8 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include #include diff --git a/test/test_subparsers.cpp b/test/test_subparsers.cpp index 0830ce1..9e7c29f 100644 --- a/test/test_subparsers.cpp +++ b/test/test_subparsers.cpp @@ -1,7 +1,14 @@ +#ifdef WITH_MODULE +import argparse; +#else #include -#include +#endif #include +#include +#include +#include + using doctest::test_suite; TEST_CASE("Add subparsers" * test_suite("subparsers")) { @@ -236,4 +243,4 @@ TEST_CASE("Check is_subcommand_used after parse" * test_suite("subparsers")) { REQUIRE(program.is_subcommand_used("clean") == false); REQUIRE(program.is_subcommand_used(command_2) == false); } -} \ No newline at end of file +} diff --git a/test/test_utility.hpp b/test/test_utility.hpp index fd061de..3a596a5 100644 --- a/test/test_utility.hpp +++ b/test/test_utility.hpp @@ -1,6 +1,8 @@ #ifndef ARGPARSE_TEST_UTILITY_HPP #define ARGPARSE_TEST_UTILITY_HPP +#include + namespace testutility { // Get value at index from std::list template diff --git a/test/test_value_semantics.cpp b/test/test_value_semantics.cpp index 2cc0f88..03e5db5 100644 --- a/test/test_value_semantics.cpp +++ b/test/test_value_semantics.cpp @@ -1,4 +1,8 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include using doctest::test_suite; diff --git a/test/test_version.cpp b/test/test_version.cpp index 377126e..3179f56 100644 --- a/test/test_version.cpp +++ b/test/test_version.cpp @@ -1,4 +1,8 @@ +#ifdef WITH_MODULE +import argparse; +#else #include +#endif #include #include From 34353659797fbe4493a0fbfacbda46474d3d4005 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sun, 15 Oct 2023 18:56:53 +0200 Subject: [PATCH 04/10] add xmake support for easier C++20 module compilation and testing --- xmake.lua | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 xmake.lua diff --git a/xmake.lua b/xmake.lua new file mode 100644 index 0000000..242e7df --- /dev/null +++ b/xmake.lua @@ -0,0 +1,91 @@ +set_xmakever("2.8.2") +set_project("argparse") + +set_version("2.9.0", { build = "%Y%m%d%H%M" }) + +option("enable_module") +option("enable_tests") +option("enable_samples") + +add_cxxflags( + "-Wall", + "-Wno-long-long", + "-pedantic", + "-Wsign-conversion", + "-Wshadow", + "-Wconversion", + { toolsets = { "clang", "gcc" } } +) +add_cxxflags("cl::/W4") + +if is_plat("windows") then + add_defines("_CRT_SECURE_NO_WARNINGS") +end + +target("argparse") +do + if get_config("enable_module") then + set_languages("c++20") + set_kind("object") + else + set_languages("c++17") + set_kind("headeronly") + end + + add_includedirs("include", { public = true }) + add_headerfiles("include/argparse/argparse.hpp") + if get_config("enable_module") then + add_files("module/argparse.cppm", { install = true }) + end +end + +if get_config("enable_tests") then + target("argparse_tests") + do + set_kind("binary") + set_languages("c++17") + set_basename("module_tests") + + add_includedirs("test") + + add_files("test/main.cpp", { defines = { "DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN" } }) + add_files("test/**.cpp") + + add_deps("argparse") + end + + if get_config("enable_module") then + target("argparse_module_tests") + do + set_kind("binary") + set_languages("c++20") + set_basename("module_tests") + + add_defines("WITH_MODULE") + + add_includedirs("test") + + add_files("test/main.cpp", { defines = { "DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN" } }) + add_files("test/**.cpp") + add_files("test/argparse_details.cppm") + + add_deps("argparse") + end + end +end + +if get_config("enable_samples") then + for _, sample_file in ipairs(os.files("samples/*.cpp")) do + target(path.basename(sample_file)) + do + set_kind("binary") + set_languages("c++17") + + add_files(sample_file) + + set_policy("build.c++.modules", false) + + add_deps("argparse") + end + end +end From a47dd910f3cbafbc1a8c965da2f1c6fdbfef68ec Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sun, 15 Oct 2023 19:10:35 +0200 Subject: [PATCH 05/10] format lua code with 4 space instead of tabs --- .stylua.toml | 1 + xmake.lua | 108 +++++++++++++++++++++++++-------------------------- 2 files changed, 55 insertions(+), 54 deletions(-) create mode 100644 .stylua.toml diff --git a/.stylua.toml b/.stylua.toml new file mode 100644 index 0000000..394e884 --- /dev/null +++ b/.stylua.toml @@ -0,0 +1 @@ +indent_type = "Spaces" diff --git a/xmake.lua b/xmake.lua index 242e7df..025b26b 100644 --- a/xmake.lua +++ b/xmake.lua @@ -8,84 +8,84 @@ option("enable_tests") option("enable_samples") add_cxxflags( - "-Wall", - "-Wno-long-long", - "-pedantic", - "-Wsign-conversion", - "-Wshadow", - "-Wconversion", - { toolsets = { "clang", "gcc" } } + "-Wall", + "-Wno-long-long", + "-pedantic", + "-Wsign-conversion", + "-Wshadow", + "-Wconversion", + { toolsets = { "clang", "gcc" } } ) add_cxxflags("cl::/W4") if is_plat("windows") then - add_defines("_CRT_SECURE_NO_WARNINGS") + add_defines("_CRT_SECURE_NO_WARNINGS") end target("argparse") do - if get_config("enable_module") then - set_languages("c++20") - set_kind("object") - else - set_languages("c++17") - set_kind("headeronly") - end + if get_config("enable_module") then + set_languages("c++20") + set_kind("object") + else + set_languages("c++17") + set_kind("headeronly") + end - add_includedirs("include", { public = true }) - add_headerfiles("include/argparse/argparse.hpp") - if get_config("enable_module") then - add_files("module/argparse.cppm", { install = true }) - end + add_includedirs("include", { public = true }) + add_headerfiles("include/argparse/argparse.hpp") + if get_config("enable_module") then + add_files("module/argparse.cppm", { install = true }) + end end if get_config("enable_tests") then - target("argparse_tests") - do - set_kind("binary") - set_languages("c++17") - set_basename("module_tests") + target("argparse_tests") + do + set_kind("binary") + set_languages("c++17") + set_basename("module_tests") - add_includedirs("test") + add_includedirs("test") - add_files("test/main.cpp", { defines = { "DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN" } }) - add_files("test/**.cpp") + add_files("test/main.cpp", { defines = { "DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN" } }) + add_files("test/**.cpp") - add_deps("argparse") - end + add_deps("argparse") + end - if get_config("enable_module") then - target("argparse_module_tests") - do - set_kind("binary") - set_languages("c++20") - set_basename("module_tests") + if get_config("enable_module") then + target("argparse_module_tests") + do + set_kind("binary") + set_languages("c++20") + set_basename("module_tests") - add_defines("WITH_MODULE") + add_defines("WITH_MODULE") - add_includedirs("test") + add_includedirs("test") - add_files("test/main.cpp", { defines = { "DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN" } }) - add_files("test/**.cpp") - add_files("test/argparse_details.cppm") + add_files("test/main.cpp", { defines = { "DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN" } }) + add_files("test/**.cpp") + add_files("test/argparse_details.cppm") - add_deps("argparse") - end - end + add_deps("argparse") + end + end end if get_config("enable_samples") then - for _, sample_file in ipairs(os.files("samples/*.cpp")) do - target(path.basename(sample_file)) - do - set_kind("binary") - set_languages("c++17") + for _, sample_file in ipairs(os.files("samples/*.cpp")) do + target(path.basename(sample_file)) + do + set_kind("binary") + set_languages("c++17") - add_files(sample_file) + add_files(sample_file) - set_policy("build.c++.modules", false) + set_policy("build.c++.modules", false) - add_deps("argparse") - end - end + add_deps("argparse") + end + end end From 9788dee9a2c488b0f567ff1bf0c55e2a3500750e Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Sun, 15 Oct 2023 19:16:55 +0200 Subject: [PATCH 06/10] fix basename for tests without module --- xmake.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake.lua b/xmake.lua index 025b26b..abeea24 100644 --- a/xmake.lua +++ b/xmake.lua @@ -44,7 +44,7 @@ if get_config("enable_tests") then do set_kind("binary") set_languages("c++17") - set_basename("module_tests") + set_basename("tests") add_includedirs("test") From 2040a740a342c2aec3cfa18a0f0603cd405e6932 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Thu, 19 Oct 2023 18:57:11 +0200 Subject: [PATCH 07/10] use function style target declaration --- xmake.lua | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/xmake.lua b/xmake.lua index abeea24..0de97e3 100644 --- a/xmake.lua +++ b/xmake.lua @@ -22,8 +22,7 @@ if is_plat("windows") then add_defines("_CRT_SECURE_NO_WARNINGS") end -target("argparse") -do +target("argparse", function() if get_config("enable_module") then set_languages("c++20") set_kind("object") @@ -37,11 +36,10 @@ do if get_config("enable_module") then add_files("module/argparse.cppm", { install = true }) end -end +end) if get_config("enable_tests") then - target("argparse_tests") - do + target("argparse_tests", function() set_kind("binary") set_languages("c++17") set_basename("tests") @@ -52,11 +50,10 @@ if get_config("enable_tests") then add_files("test/**.cpp") add_deps("argparse") - end + end) if get_config("enable_module") then - target("argparse_module_tests") - do + target("argparse_module_tests", function() set_kind("binary") set_languages("c++20") set_basename("module_tests") @@ -70,14 +67,13 @@ if get_config("enable_tests") then add_files("test/argparse_details.cppm") add_deps("argparse") - end + end) end end if get_config("enable_samples") then for _, sample_file in ipairs(os.files("samples/*.cpp")) do - target(path.basename(sample_file)) - do + target(path.basename(sample_file), function() set_kind("binary") set_languages("c++17") @@ -86,6 +82,6 @@ if get_config("enable_samples") then set_policy("build.c++.modules", false) add_deps("argparse") - end + end) end end From 67a4e91da9ac8741d688c08374c94e4d2d3673e5 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Thu, 19 Oct 2023 20:35:56 +0200 Subject: [PATCH 08/10] fix module and headerfile installation --- xmake.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/xmake.lua b/xmake.lua index 0de97e3..b5fd5b4 100644 --- a/xmake.lua +++ b/xmake.lua @@ -23,13 +23,12 @@ if is_plat("windows") then end target("argparse", function() + set_languages("c++17") + set_kind("headeronly") if get_config("enable_module") then set_languages("c++20") - set_kind("object") + set_kind("static") -- static atm because of a XMake bug, headeronly doesn't generate package module metadata else - set_languages("c++17") - set_kind("headeronly") - end add_includedirs("include", { public = true }) add_headerfiles("include/argparse/argparse.hpp") From 7f5de9ab25b88091cd52720f81e3b043e8c8e1a6 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Thu, 19 Oct 2023 21:50:00 +0200 Subject: [PATCH 09/10] fix import std support --- module/argparse.cppm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/module/argparse.cppm b/module/argparse.cppm index 2c78428..fdf2ff4 100644 --- a/module/argparse.cppm +++ b/module/argparse.cppm @@ -29,16 +29,16 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -module; - -#include - export module argparse; #ifdef ARGPARSE_MODULE_USE_STD_MODULE import std; #endif +extern "C++" { +#include +} + export namespace argparse { using argparse::nargs_pattern; using argparse::default_arguments; From 24569f69e8ac1e2ebf8df685c8fa12da8b4135b9 Mon Sep 17 00:00:00 2001 From: Arthur LAURENT Date: Fri, 20 Oct 2023 10:50:58 +0200 Subject: [PATCH 10/10] fix module compilation with clang on windows when std module is disabled --- module/argparse.cppm | 9 ++++++++- xmake.lua | 5 ++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/module/argparse.cppm b/module/argparse.cppm index fdf2ff4..625283e 100644 --- a/module/argparse.cppm +++ b/module/argparse.cppm @@ -29,15 +29,22 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +module; + +#ifndef ARGPARSE_MODULE_USE_STD_MODULE +#include +#endif + export module argparse; #ifdef ARGPARSE_MODULE_USE_STD_MODULE import std; -#endif extern "C++" { #include } +#endif + export namespace argparse { using argparse::nargs_pattern; diff --git a/xmake.lua b/xmake.lua index b5fd5b4..cc33c03 100644 --- a/xmake.lua +++ b/xmake.lua @@ -4,6 +4,7 @@ set_project("argparse") set_version("2.9.0", { build = "%Y%m%d%H%M" }) option("enable_module") +option("enable_std_import", { defines = "ARGPARSE_MODULE_USE_STD_MODULE" }) option("enable_tests") option("enable_samples") @@ -28,7 +29,9 @@ target("argparse", function() if get_config("enable_module") then set_languages("c++20") set_kind("static") -- static atm because of a XMake bug, headeronly doesn't generate package module metadata - else + end + + add_options("enable_std_import") add_includedirs("include", { public = true }) add_headerfiles("include/argparse/argparse.hpp")