Skip to content

Commit cb091a9

Browse files
authored
Merge pull request #160 from eseiler/infra/google
[INFRA] google
2 parents 7dbb31f + b37a03a commit cb091a9

File tree

6 files changed

+52
-34
lines changed

6 files changed

+52
-34
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ If you are working in the field of sequence analysis, we recommend using the
9595

9696
An application with one option parsing an integer from the command line can be written in only 5 lines of code:
9797

98-
<!-- MARKDOWN-AUTO-DOCS:START (CODE:src=./test/snippet/readme_sneak_peek.cpp&lines=3-13) -->
98+
<!-- MARKDOWN-AUTO-DOCS:START (CODE:src=./test/snippet/readme_sneak_peek.cpp&lines=3-15) -->
9999
<!-- The below code snippet is automatically added from ./test/snippet/readme_sneak_peek.cpp -->
100100
```cpp
101101
#include <sharg/all.hpp>

include/sharg/detail/format_base.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,9 @@ class format_help_base : public format_base
212212
format_help_base(std::vector<std::string> const & names,
213213
update_notifications const version_updates,
214214
bool const advanced) :
215+
version_check_dev_decision{version_updates},
215216
command_names{names},
216-
show_advanced_options{advanced},
217-
version_check_dev_decision{version_updates}
217+
show_advanced_options{advanced}
218218
{}
219219
//!\}
220220

test/cmake/sharg_require_benchmark.cmake

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,35 @@
77

88
cmake_minimum_required (VERSION 3.16)
99

10-
# Exposes the google-benchmark target `gbenchmark`.
10+
# Exposes the google-benchmark target `benchmark` and `benchmark_main`.
11+
# CMake 3.24: https://cmake.org/cmake/help/latest/module/FetchContent.html#variable:FETCHCONTENT_TRY_FIND_PACKAGE_MODE
1112
macro (sharg_require_benchmark)
1213
enable_testing ()
1314

14-
set (gbenchmark_git_tag "v1.7.0")
15+
set (benchmark_version "1.7.0")
16+
set (gbenchmark_git_tag "v${benchmark_version}")
1517

16-
message (STATUS "Fetch Google Benchmark:")
18+
find_package (benchmark ${benchmark_version} EXACT QUIET)
1719

18-
include (FetchContent)
19-
FetchContent_Declare (
20-
gbenchmark_fetch_content
21-
GIT_REPOSITORY "https://github.com/google/benchmark.git"
22-
GIT_TAG "${gbenchmark_git_tag}")
23-
option (BENCHMARK_ENABLE_TESTING "" OFF)
24-
option (BENCHMARK_ENABLE_WERROR "" OFF) # Does not apply to Debug builds.
25-
FetchContent_MakeAvailable (gbenchmark_fetch_content)
20+
if (NOT benchmark_FOUND)
21+
message (STATUS "Fetching Google Benchmark ${benchmark_version}")
2622

27-
# NOTE: google benchmark's CMakeLists.txt already defines Shlwapi
28-
add_library (gbenchmark ALIAS benchmark_main)
23+
include (FetchContent)
24+
FetchContent_Declare (
25+
gbenchmark_fetch_content
26+
GIT_REPOSITORY "https://github.com/google/benchmark.git"
27+
GIT_TAG "${gbenchmark_git_tag}")
28+
option (BENCHMARK_ENABLE_TESTING "" OFF)
29+
option (BENCHMARK_ENABLE_WERROR "" OFF) # Does not apply to Debug builds.
30+
option (BENCHMARK_ENABLE_INSTALL "" OFF)
31+
FetchContent_MakeAvailable (gbenchmark_fetch_content)
32+
else ()
33+
message (STATUS "Found Google Benchmark ${benchmark_version}")
34+
endif ()
2935

36+
# NOTE: google benchmark's CMakeLists.txt already defines Shlwapi
3037
if (NOT TARGET gbenchmark_build)
31-
add_custom_target (gbenchmark_build DEPENDS gbenchmark)
32-
target_compile_options ("benchmark_main" PUBLIC "-w")
38+
add_custom_target (gbenchmark_build DEPENDS benchmark_main benchmark)
3339
endif ()
40+
3441
endmacro ()

test/cmake/sharg_require_test.cmake

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,32 @@
88
cmake_minimum_required (VERSION 3.16)
99

1010
# Exposes the google-test targets `gtest` and `gtest_main`.
11+
# CMake 3.24: https://cmake.org/cmake/help/latest/module/FetchContent.html#variable:FETCHCONTENT_TRY_FIND_PACKAGE_MODE
1112
macro (sharg_require_test)
1213
enable_testing ()
1314

14-
set (gtest_git_tag "release-1.12.1")
15+
set (gtest_version "1.12.1")
16+
set (gtest_git_tag "release-${gtest_version}")
1517

16-
message (STATUS "Fetch Google Test:")
18+
find_package (GTest ${gtest_version} EXACT QUIET)
1719

18-
include (FetchContent)
19-
FetchContent_Declare (
20-
gtest_fetch_content
21-
GIT_REPOSITORY "https://github.com/google/googletest.git"
22-
GIT_TAG "${gtest_git_tag}")
23-
option (BUILD_GMOCK "" OFF)
24-
FetchContent_MakeAvailable (gtest_fetch_content)
20+
if (NOT GTest_FOUND)
21+
message (STATUS "Fetching Google Test ${gtest_version}")
22+
23+
include (FetchContent)
24+
FetchContent_Declare (
25+
gtest_fetch_content
26+
GIT_REPOSITORY "https://github.com/google/googletest.git"
27+
GIT_TAG "${gtest_git_tag}")
28+
option (BUILD_GMOCK "" OFF)
29+
option (INSTALL_GTEST "" OFF)
30+
FetchContent_MakeAvailable (gtest_fetch_content)
31+
else ()
32+
message (STATUS "Found Google Test ${gtest_version}")
33+
endif ()
2534

2635
if (NOT TARGET gtest_build)
2736
add_custom_target (gtest_build DEPENDS gtest_main gtest)
28-
target_compile_options ("gtest_main" PUBLIC "-w")
29-
target_compile_options ("gtest" PUBLIC "-w")
3037
endif ()
38+
3139
endmacro ()

test/sharg-test.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ endif ()
5858
# needed for performance test cases in sharg/test/performance
5959
if (NOT TARGET sharg::test::performance)
6060
add_library (sharg_test_performance INTERFACE)
61-
target_link_libraries (sharg_test_performance INTERFACE "sharg::test" "gbenchmark")
61+
target_link_libraries (sharg_test_performance INTERFACE "sharg::test" "benchmark_main" "benchmark")
6262

6363
add_library (sharg::test::performance ALIAS sharg_test_performance)
6464
endif ()

test/snippet/readme_sneak_peek.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ int main(int argc, char ** argv)
1010
parser.add_subsection("Eating Numbers");
1111
parser.add_option(val, sharg::config{.short_id = 'i', .long_id = "int", .description = "Desc."});
1212
parser.parse();
13+
14+
return 0;
1315
}
1416

1517
#undef main
1618

17-
int main(int argc, char ** argv)
19+
int main()
1820
{
19-
char * test_argv[] = {"./Eat-Me-App", "-h"};
20-
int const test_argc = sizeof(test_argv) / sizeof(*test_argv);
21-
return test(test_argc, test_argv);
21+
std::string argv1{"./Eat-Me-App"}, argv2{"-h"};
22+
std::array argv{argv1.data(), argv2.data()};
23+
24+
return test(argv.size(), argv.data());
2225
}

0 commit comments

Comments
 (0)