Enable stdc++17 by default

This commit is contained in:
2025-05-15 17:16:59 +08:00
parent e444af237e
commit 2480b6ea8a
6 changed files with 37 additions and 5 deletions

View File

@@ -2,7 +2,6 @@ cmake_minimum_required(VERSION 3.17)
option(ENABLE_ICONV "Use libiconv to convert encoding" ON)
option(ENABLE_STANDALONE "Build utils standalone" OFF)
option(ENABLE_CXX17 "Enable C++ 17" OFF)
option(INSTALL_DEP_FILES "Install a file with dependences." OFF)
option(ENABLE_SSL "Enable SSL" OFF)
option(ENABLE_ZLIB "Use Zlib to uncompress http data." OFF)
@@ -186,9 +185,7 @@ endif()
if (ENABLE_ZLIB)
target_link_libraries(utils ZLIB::ZLIB)
endif()
if (ENABLE_CXX17)
target_compile_features(utils PRIVATE cxx_std_17)
endif()
target_compile_features(utils PRIVATE cxx_std_17)
if (ENABLE_STANDALONE)
install(TARGETS utils)
endif()

View File

@@ -1,4 +1,4 @@
project('utils')
project('utils', default_options: ['cpp_std=c++17'])
add_languages('c', 'cpp', required: true)
cc = meson.get_compiler('c')
@@ -181,3 +181,19 @@ utils_dep = declare_dependency(include_directories: include_directories('.'), li
if get_option('utils_standalone')
install_headers(source_file_headers)
endif
if get_option('test')
gtest = subproject('gtest')
gtest_main_dep = gtest.get_variable('gtest_main_dep')
test_exe = executable('unittest',
files(
'test/stack_test.cpp',
'test/queue_test.cpp',
'test/binary_tree_test.cpp',
'test/hash_map_test.cpp',
'test/hash_lib_test.cpp',
),
dependencies: [utils_dep, gtest_main_dep],
)
test('unittest', test_exe, args: ['-v'], timeout: 60)
endif

View File

@@ -2,3 +2,4 @@ option('utils_iconv', type: 'feature', value: 'auto', description: 'Enable iconv
option('utils_standalone', type: 'boolean', value: false, description: 'Build standalone utils')
option('utils_ssl', type: 'feature', value: 'disabled', description: 'Enable SSL support')
option('utils_zlib', type: 'feature', value: 'disabled', description: 'Enable zlib support for uncompress http data.')
option('test', type: 'boolean', value: false, description: 'Enable test')

1
subprojects/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
*/

16
subprojects/gtest.wrap Normal file
View File

@@ -0,0 +1,16 @@
[wrap-file]
directory = googletest-1.15.2
source_url = https://github.com/google/googletest/archive/refs/tags/v1.15.2.tar.gz
source_filename = gtest-1.15.2.tar.gz
source_hash = 7b42b4d6ed48810c5362c265a17faebe90dc2373c885e5216439d37927f02926
patch_filename = gtest_1.15.2-4_patch.zip
patch_url = https://wrapdb.mesonbuild.com/v2/gtest_1.15.2-4/get_patch
patch_hash = a5151324b97e6a98fa7a0e8095523e6d5c4bb3431210d6ac4ad9800c345acf40
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/gtest_1.15.2-4/gtest-1.15.2.tar.gz
wrapdb_version = 1.15.2-4
[provide]
gtest = gtest_dep
gtest_main = gtest_main_dep
gmock = gmock_dep
gmock_main = gmock_main_dep

View File

@@ -12,6 +12,7 @@ TEST(HashLibTest, SHA512ClassTest) {
GTEST_ASSERT_EQ(re, sha512.digest());
auto hexRe = hashHex<SHA512>("Hello, World!");
GTEST_ASSERT_EQ(hexRe, sha512.hexDigest());
GTEST_ASSERT_EQ(hashHex<SHA512>("Hello, World!Hello, World!"), hashHex<SHA512>("Hello, World!", another));
another.update("Hello, World!");
GTEST_ASSERT_EQ(hashHex<SHA512>("Hello, World!Hello, World!"), another.hexDigest());
sha512.update("Hello, World!");