Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a33d507
msvc build
wcdnail May 27, 2024
b7b462a
clipp: parametrize char type
wcdnail May 27, 2024
90d76f2
clipp: fork details info
wcdnail May 27, 2024
bb1bb57
clipp: overload note
wcdnail May 27, 2024
4b9250b
TCHAR fixes
wcdnail May 27, 2024
4d4140a
clipp: std::ostream_iterator may be buggy
wcdnail May 27, 2024
351550b
clipp: remove recursive target overload
wcdnail May 27, 2024
345159c
fix build
wcdnail May 27, 2024
243b385
almost all tests fixed
wcdnail May 28, 2024
f40e0b0
clipp: all CHAR test passed
wcdnail May 28, 2024
e4de7cb
build tests & examples as single project
wcdnail May 28, 2024
e05312e
clipp: restore rapid stuff, separate narrow defs
wcdnail May 28, 2024
f4094d6
clipp: revert to legacy value/lause/opt.. overloads
wcdnail May 28, 2024
69af98c
clipp: widen test doc OK
wcdnail May 28, 2024
4b03ff5
fix readme
wcdnail May 28, 2024
a242cfc
clipp: fix readme
wcdnail May 29, 2024
3788f23
+=
wcdnail May 29, 2024
76bc7cb
clipp: attempting to fix gcc build
wcdnail May 30, 2024
d138b52
gcc build OK but a lot of warnings
wcdnail May 30, 2024
ca042fe
clang 17 build OK
wcdnail May 30, 2024
e840c52
clipp: clang (win) build ok, all tests passed
wcdnail May 30, 2024
4eedadd
comment marks
wcdnail May 30, 2024
3178e43
update readme
wcdnail May 30, 2024
ad732f9
clipp: ci build fix
wcdnail May 30, 2024
de48501
clipp: ci build fix 2
wcdnail May 30, 2024
1df1d37
clipp: fix ci 3
wcdnail May 30, 2024
75264eb
clipp: fix CI build again
wcdnail May 30, 2024
845ff08
clipp: CI skip ALL_test.cpp
wcdnail May 30, 2024
061af5a
clipp: attempting to skip ALL_test.cpp again
wcdnail May 30, 2024
0e5be19
clipp: remove extra sources from test dir
wcdnail May 30, 2024
14cb6f1
clipp: cosmetic fix
wcdnail May 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cmake.configureArgs": [
"-DBUILD_TESTING=1",
"-DBUILD_EXAMPLES=1"
]
}
137 changes: 137 additions & 0 deletions ALL_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#include "test/pch.h"

#define __STRNGZ(S) #S
#define _STRNGZ(S) __STRNGZ(S)
#pragma message("C++ std == " _STRNGZ(CLIPP_CXX_STD))

#ifdef ALL_TESTS_AS_SINGLE_PRJ

int actions_test_main();
int alternative_groups_test_main();
int alternative_options_test_main();
int alternative_required_test_main();
int blocking_test01_main();
int blocking_test02_main();
int blocking_test03_main();
int blocking_test04_main();
int blocking_test05_main();
int blocking_test06_main();
int blocking_test07_main();
int blocking_test08_main();
int blocking_test09_main();
int blocking_test10_main();
int documentation_test_main();
int documentation_test_wide_main();
int empty_args_main();
int flag_param_factories_test_main(int argc, char* argv[]);
int joined_flags_test1_main();
int joined_flags_test2_main();
int joined_flags_test3_main();
int joined_flags_test4_main();
int joined_flags_test5_main();
int joined_flags_test6_main();
int joined_params_test1_main();
int joined_params_test2_main();
int joined_sequence_test_main();
int mixed_params_test_main();
int nesting_test_main();
int options_test_main();
int prefix_free_test_main();
int prefix_test_main();
int repeatability_test_main();
int repeatable_alternatives_test_main();
int required_params_test1_main();
int required_params_test2_main();
int usage_lines_test_main();
int values_conversion_test_main();
int values_filter_test_main();
int values_sequencing_test_main();

namespace {

int test_main(int(*routine)(), char const* test_name)
{
int const rv = routine();
if (rv != 0) {
std::cerr << "Test '" << test_name << "' failed (" << rv << ")" << std::endl;
return rv;
}
std::cerr << "Test '" << test_name << "' OK" << std::endl;
return 0;
}

int test_main_av(int(*routine)(int, char**), char const* test_name, int argc, char** argv)
{
int const rv = routine(argc, argv);
if (rv != 0) {
std::cerr << "Test '" << test_name << "' failed (" << rv << ")" << std::endl;
return rv;
}
std::cerr << "Test '" << test_name << "' OK" << std::endl;
return 0;
}

#define RUN_TEST(Func) \
do { \
int rv{test_main(Func, #Func)}; \
if (rv != 0) { \
return rv; \
} \
} while (0)

#define RUN_TEST_AV(Func, argc, argv) \
do { \
int rv{test_main_av(Func, #Func, argc, argv)}; \
if (rv != 0) { \
return rv; \
} \
} while (0)

} // namespace

int main(int argc, char* argv[])
{
RUN_TEST(documentation_test_wide_main);

RUN_TEST(actions_test_main);
RUN_TEST(alternative_groups_test_main);
RUN_TEST(alternative_options_test_main);
RUN_TEST(alternative_required_test_main);
RUN_TEST(blocking_test01_main);
RUN_TEST(blocking_test02_main);
RUN_TEST(blocking_test03_main);
RUN_TEST(blocking_test04_main);
RUN_TEST(blocking_test05_main);
RUN_TEST(blocking_test06_main);
RUN_TEST(blocking_test07_main);
RUN_TEST(blocking_test08_main);
RUN_TEST(blocking_test09_main);
RUN_TEST(blocking_test10_main);
RUN_TEST(documentation_test_main);
RUN_TEST(empty_args_main);
RUN_TEST_AV(flag_param_factories_test_main, argc, argv);
RUN_TEST(joined_flags_test1_main);
RUN_TEST(joined_flags_test2_main);
RUN_TEST(joined_flags_test3_main);
RUN_TEST(joined_flags_test4_main);
RUN_TEST(joined_flags_test5_main);
RUN_TEST(joined_flags_test6_main);
RUN_TEST(joined_params_test1_main);
RUN_TEST(joined_params_test2_main);
RUN_TEST(joined_sequence_test_main);
RUN_TEST(mixed_params_test_main);
RUN_TEST(nesting_test_main);
RUN_TEST(options_test_main);
RUN_TEST(prefix_free_test_main);
RUN_TEST(prefix_test_main);
RUN_TEST(repeatability_test_main);
RUN_TEST(repeatable_alternatives_test_main);
RUN_TEST(required_params_test1_main);
RUN_TEST(required_params_test2_main);
RUN_TEST(usage_lines_test_main);
RUN_TEST(values_conversion_test_main);
RUN_TEST(values_filter_test_main);
RUN_TEST(values_sequencing_test_main);
return 0;
}
#endif
108 changes: 106 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ project(clipp
VERSION 1.2.3
LANGUAGES CXX)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

include(GNUInstallDirs)
set(CMAKE_VERBOSE_MAKEFILE ON)

set(CLIPP_CXX_STD cxx_std_17)

message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
add_library(${PROJECT_NAME} INTERFACE)
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_11)
target_compile_features(${PROJECT_NAME} INTERFACE ${CLIPP_CXX_STD})
target_include_directories(${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
Expand Down Expand Up @@ -37,7 +41,107 @@ install(FILES ${CONFIG_VERSION_FILE}
)

option(BUILD_TESTING "Do not build tests by default" OFF)
option(BUILD_TESTING_SINGLE "Build all test as single project" ON)
option(BUILD_EXAMPLES "Do not build examples by default" OFF)
include(CTest)
if(BUILD_TESTING AND ${CMAKE_SOURCE_DIR} STREQUAL ${PROJECT_SOURCE_DIR})

if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()

if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC")
set(CLIPP_COMPILER_OPTS
/W4
/EHsc
)
set(COMPILER_IS_CL 1)
else()
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
#add_compile_options(-stdlib=libc++) # clang version 17.0.6 failed with this option
# TODO: check clang version
set(CLIPP_COMPILER_OPTS
-Wno-c++98-compat
-Wno-c++98-compat-pedantic
)
set(COMPILER_IS_CLANG 1)
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "gcc")
set(CLIPP_COMPILER_OPTS
-Wlogical-op
-Wnoexcept
-Wstrict-null-sentinel
-Wuseless-cast
)
set(COMPILER_IS_GCC 1)
endif()
#if (COMPILER_IS_CLANG OR COMPILER_IS_GCC)
list(APPEND CLIPP_COMPILER_OPTS
-Wall
-Wextra
-Wpedantic
-Wcast-align
-Wcast-qual
-Wctor-dtor-privacy
-Wconversion -Wno-sign-conversion
-Wdisabled-optimization
-Wdouble-promotion
-Wformat=2
-Winit-self
-Wmissing-include-dirs
-Wold-style-cast
-Woverloaded-virtual
-Wredundant-decls
-Wshadow
-Wstrict-aliasing=1
-Wstrict-overflow=5
-Wswitch-default
-Wundef
)
#endif()
endif()

add_compile_options(${CLIPP_COMPILER_OPTS})

message(STATUS "CMAKE_BUILD_TYPE : ${CMAKE_BUILD_TYPE}")
message(STATUS "CMAKE_CXX_COMPILER_ID : ${CMAKE_CXX_COMPILER_ID}")
message(STATUS "CLIPP_CXX_STD : ${CLIPP_CXX_STD}")
message(STATUS "CLIPP_COMPILER_OPTS : ${CLIPP_COMPILER_OPTS}")

message(STATUS "COMPILER_IS_CL : ${COMPILER_IS_CL}")
message(STATUS "COMPILER_IS_CLANG : ${COMPILER_IS_CLANG}")
message(STATUS "COMPILER_IS_GCC : ${COMPILER_IS_GCC}")

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(
-D_DEBUG
)
endif()
if (WIN32)
add_definitions(
-D_WIN32
-D_AMD64_
)
endif()

include_directories(
${CMAKE_SOURCE_DIR}/include
)

if(BUILD_TESTING)
add_subdirectory(test)
endif()
if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

set(ROOT_FILES
${CMAKE_SOURCE_DIR}/README.md
${CMAKE_SOURCE_DIR}/CMakeLists.txt
${CMAKE_SOURCE_DIR}/mk-msvs-solution.cmd
${CMAKE_SOURCE_DIR}/mk-msvs-solution-clang.cmd
${CMAKE_SOURCE_DIR}/mk-vars.cmd
${CMAKE_SOURCE_DIR}/mk-trace.cmd
)

target_sources(${PROJECT_NAME} PRIVATE ${ROOT_FILES})
set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER "root")
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${ROOT_FILES})
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ clipp - command line interfaces for modern C++

Easy to use, powerful and expressive command line argument handling for C++11/14/17 contained in a **single header file**.

- char/wchar_t/TCHAR - all stuff now parametrized
- C++17 by default (gcc 13+, clang 17+, msvc 2022 build ok)
- options, options+value(s), positional values, positional commands, nested alternatives, decision trees, joinable flags, custom value filters, ...
- documentation generation (usage lines, man pages); error handling
- lots of examples; large set of tests
Expand Down
46 changes: 46 additions & 0 deletions examples/ALL_examples.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "pch.h"
#include "example-def.h"

#ifdef ALL_EXAMPLES_AS_SINGLE_PRJ

// #TODO: append test cases

int main(int argc, char* argv[])
{
RUN_EXAMPLE_AV(actions_main, argc, argv);
RUN_EXAMPLE_AV(align_main, argc, argv);
RUN_EXAMPLE_AV(alternatives_main, argc, argv);
RUN_EXAMPLE_AV(annotate_main, argc, argv);
RUN_EXAMPLE_AV(argv0_main, argc, argv);
RUN_EXAMPLE_AV(commands_main, argc, argv);
RUN_EXAMPLE_AV(complex_nesting_main, argc, argv);
RUN_EXAMPLE_AV(convert_main, argc, argv);
RUN_EXAMPLE_AV(counter_main, argc, argv);
RUN_EXAMPLE(documentation_main);
RUN_EXAMPLE_AV(doc_filter_main, argc, argv);
RUN_EXAMPLE_AV(finder_main, argc, argv);
RUN_EXAMPLE_AV(float_vector_main, argc, argv);
RUN_EXAMPLE_AV(groups_main, argc, argv);
RUN_EXAMPLE_AV(joinable_flags_main, argc, argv);
RUN_EXAMPLE_AV(model_main, argc, argv);
RUN_EXAMPLE_AV(naval_fate_main, argc, argv);
RUN_EXAMPLE_AV(nested_alternatives_main, argc, argv);
RUN_EXAMPLE_AV(numbers_main, argc, argv);
RUN_EXAMPLE_AV(options_main, argc, argv);
RUN_EXAMPLE_AV(options_values_main, argc, argv);
RUN_EXAMPLE_AV(parsing_main, argc, argv);
RUN_EXAMPLE_AV(positional_values_main, argc, argv);
RUN_EXAMPLE_AV(repeatable_main, argc, argv);
RUN_EXAMPLE_AV(required_flags_main, argc, argv);
RUN_EXAMPLE(sanity_main);
RUN_EXAMPLE_AV(send_main, argc, argv);
RUN_EXAMPLE_AV(simplify_main, argc, argv);
RUN_EXAMPLE_AV(switches_main, argc, argv);
RUN_EXAMPLE_AV(tagnames_main, argc, argv);
RUN_EXAMPLE_AV(text_formatting_main, argc, argv);
RUN_EXAMPLE_AV(timing_main, argc, argv);
RUN_EXAMPLE_AV(transform_main, argc, argv);
return 0;
}

#endif
33 changes: 33 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
project(clipp-examples)
add_executable(${PROJECT_NAME})
target_compile_features(${PROJECT_NAME} PUBLIC ${CLIPP_CXX_STD})
target_compile_definitions(${PROJECT_NAME} PRIVATE
ALL_EXAMPLES_AS_SINGLE_PRJ
)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} source_files)
foreach(src IN LISTS source_files)
get_filename_component(name_we ${src} NAME_WE)
target_sources(${PROJECT_NAME} PRIVATE ${src})
set_source_files_properties(${src} PROPERTIES COMPILE_FLAGS "-DTHIS_EXAMPLE_FNAME=${name_we}")
endforeach()
target_precompile_headers(${PROJECT_NAME} PRIVATE
"$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_CURRENT_SOURCE_DIR}/pch.h>"
)
target_sources(${PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/example-def.h
${CMAKE_CURRENT_SOURCE_DIR}/pch.h
${CMAKE_SOURCE_DIR}/include/clipp.h
${CMAKE_SOURCE_DIR}/include/clipp-narrow.h
${CMAKE_SOURCE_DIR}/include/clipp-wide.h
)
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${source_files})
source_group("CLIPP" FILES
${CMAKE_SOURCE_DIR}/include/clipp.h
${CMAKE_SOURCE_DIR}/include/clipp-narrow.h
${CMAKE_SOURCE_DIR}/include/clipp-wide.h
)
set_target_properties(${PROJECT_NAME} PROPERTIES
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF
FOLDER "examples"
)
6 changes: 5 additions & 1 deletion examples/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@
*
*****************************************************************************/

#include "pch.h"
#include "example-def.h" // EXAMPLE_MAIN

#include <iostream>
#include <string>
#include <vector>

#include <clipp.h>


int main(int argc, char* argv[])
int EXAMPLE_MAIN(int argc, char* argv[])
{
using namespace clipp;
using std::cout;
Expand Down Expand Up @@ -55,4 +58,5 @@ int main(int argc, char* argv[])

parse(argc, argv, cli);

return 0;
}
Loading