Skip to content

Commit e7d4860

Browse files
committed
more fixes related to the C++20 support
1 parent e606477 commit e7d4860

21 files changed

+155
-114
lines changed

Pipfile.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generator_code/targets/cppDesktop.json

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"-i"
3737
],
3838
"file_patters": [
39-
"include/unit_system.hpp",
39+
"include/unit_system_17.hpp",
4040
"include/unit_system_20.hpp",
4141
"src/*.cpp"
4242
]
@@ -46,7 +46,36 @@
4646
"command": [
4747
"meson",
4848
"setup",
49-
"build",
49+
"build_17",
50+
"-Dcpp_std=c++17",
51+
"--wipe"
52+
],
53+
"environment": {
54+
"colorize_console": "1"
55+
}
56+
},
57+
{
58+
"command": [
59+
"meson",
60+
"compile",
61+
"-C",
62+
"build_17"
63+
]
64+
},
65+
{
66+
"command": [
67+
"meson",
68+
"test",
69+
"-C",
70+
"build_17"
71+
]
72+
},
73+
74+
{
75+
"command": [
76+
"meson",
77+
"setup",
78+
"build_20",
5079
"-Dcpp_std=c++20",
5180
"--wipe"
5281
],
@@ -59,15 +88,15 @@
5988
"meson",
6089
"compile",
6190
"-C",
62-
"build"
91+
"build_20"
6392
]
6493
},
6594
{
6695
"command": [
6796
"meson",
6897
"test",
6998
"-C",
70-
"build"
99+
"build_20"
71100
]
72101
}
73102
]

generator_code/targets/meson.json

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"-i"
3737
],
3838
"file_patters": [
39-
"include/unit_system.hpp",
39+
"include/unit_system_17.hpp",
4040
"include/unit_system_20.hpp",
4141
"src/*.cpp"
4242
]
@@ -46,7 +46,36 @@
4646
"command": [
4747
"meson",
4848
"setup",
49-
"build",
49+
"build_17",
50+
"-Dcpp_std=c++17",
51+
"--wipe"
52+
],
53+
"environment": {
54+
"colorize_console": "1"
55+
}
56+
},
57+
{
58+
"command": [
59+
"meson",
60+
"compile",
61+
"-C",
62+
"build_17"
63+
]
64+
},
65+
{
66+
"command": [
67+
"meson",
68+
"test",
69+
"-C",
70+
"build_17"
71+
]
72+
},
73+
74+
{
75+
"command": [
76+
"meson",
77+
"setup",
78+
"build_20",
5079
"-Dcpp_std=c++20",
5180
"--wipe"
5281
],
@@ -59,15 +88,15 @@
5988
"meson",
6089
"compile",
6190
"-C",
62-
"build"
91+
"build_20"
6392
]
6493
},
6594
{
6695
"command": [
6796
"meson",
6897
"test",
6998
"-C",
70-
"build"
99+
"build_20"
71100
]
72101
}
73102
]

target_data/Cpp/arduino/examples/advanced_time/advanced_time.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ void loop() {
3030
/* SI delay function */
3131
void delay_si(time_si& t){
3232
if(t <= 16383_us){ /* delayMicroseconds has a limit of 16838us */
33-
delayMicroseconds(unit_cast(t, UNIT_SYSTEM_MICRO).value);
33+
delayMicroseconds(unit_cast(t, UNIT_SYSTEM_MICRO).val());
3434
} else {
35-
delay(unit_cast(t, UNIT_SYSTEM_MILLI).value);
35+
delay(unit_cast(t, UNIT_SYSTEM_MILLI).val());
3636
}
3737
}

target_data/Cpp/arduino/examples/simple_time/simple_time.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ void setup() {
1818

1919
void loop() {
2020
digitalWrite(OUTPUT_LED, HIGH);
21-
delay(delta_t.value);
21+
delay(delta_t.val());
2222

2323
digitalWrite(OUTPUT_LED, LOW);
24-
delay(delta_t.value);
24+
delay(delta_t.val());
2525
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#pragma once
2+
3+
#mesondefine USE_CPP_17
4+
5+
#ifdef USE_CPP_17
6+
#include "unit_system_17.hpp"
7+
#else
8+
#include "unit_system_20.hpp"
9+
#endif

target_data/Cpp/cppDesktop/tests/base_units_test.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include "test_functions.hpp"
2+
13
#include <iostream>
24

35
using namespace sakurajin::unit_system;

target_data/Cpp/cppDesktop/tests/base_units_test_17.cpp

Lines changed: 0 additions & 5 deletions
This file was deleted.

target_data/Cpp/cppDesktop/tests/base_units_test_20.cpp

Lines changed: 0 additions & 5 deletions
This file was deleted.

target_data/Cpp/cppDesktop/tests/common_test.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include "test_functions.hpp"
2+
13
#include <iostream>
24

35
using namespace sakurajin::unit_system::literals;

target_data/Cpp/cppDesktop/tests/common_test_17.cpp

Lines changed: 0 additions & 5 deletions
This file was deleted.

target_data/Cpp/cppDesktop/tests/common_test_20.cpp

Lines changed: 0 additions & 5 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include <gtest/gtest.h>
22

3-
#include "unit_system_20.hpp"
3+
#include "unit_system.hpp"
44

55
#define EXPECT_UNIT_EQ(X, Y) EXPECT_DOUBLE_EQ((X).val(), (Y).convert_like(X).val())

target_data/Cpp/cppDesktop/tests/test_functions_17.hpp

Lines changed: 0 additions & 5 deletions
This file was deleted.

target_data/Cpp/cppDesktop/tests/unit_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
#include "test_functions.hpp"
22

33
using namespace sakurajin::unit_system;
44

target_data/Cpp/cppDesktop/tests/unit_test_17.cpp

Lines changed: 0 additions & 5 deletions
This file was deleted.

target_data/Cpp/cppDesktop/tests/unit_test_20.cpp

Lines changed: 0 additions & 5 deletions
This file was deleted.

target_data/Cpp/meson/meson.build.template

Lines changed: 57 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@ project(
99
meson_version: '>= 1.1.0',
1010
)
1111

12+
use_cpp_17 = false
13+
if get_option('use_cpp_17').enabled()
14+
use_cpp_17 = true
15+
elif get_option('use_cpp_17').disabled()
16+
use_cpp_17 = false
17+
else
18+
cpp_20_supported_versions = [
19+
'c++20', 'c++23', 'c++26', 'c++2a',
20+
'gnu++20', 'gnu++23', 'gnu++26', 'gnu++2a',
21+
'vc++20', 'vc++23', 'vc++26', 'vc++2a',
22+
]
23+
use_cpp_17 = get_option('cpp_std' ) not in cpp_20_supported_versions
24+
endif
25+
26+
1227
#set windows linker argument
1328
cpp = meson.get_compiler('cpp')
1429

@@ -20,40 +35,54 @@ if target_machine.system() == 'windows'
2035
endif
2136
endif
2237

23-
incdirs = include_directories('include')
24-
sources = [
25-
{% for unit in units %}
26-
'src/{{ unit.name }}.cpp',
27-
{% endfor %}
28-
]
29-
30-
unit_system = library(
31-
'unit-system',
32-
sources,
33-
version : meson.project_version(),
34-
soversion : '0',
35-
include_directories : incdirs,
36-
install : true,
37-
)
38+
incdirs = include_directories('include', '.')
3839

39-
unit_system_dep = declare_dependency(
40-
include_directories : incdirs,
41-
link_with : unit_system,
42-
version: meson.project_version(),
43-
)
40+
if use_cpp_17
41+
sources = [
42+
{% for unit in units %}
43+
'src/{{ unit.name }}.cpp',
44+
{% endfor %}
45+
]
4446

45-
unit_system_20_dep = declare_dependency(
46-
include_directories : incdirs,
47-
version: meson.project_version(),
48-
)
47+
unit_system = library(
48+
'unit-system',
49+
sources,
50+
version : meson.project_version(),
51+
soversion : '0',
52+
include_directories : incdirs,
53+
install : true,
54+
)
55+
56+
unit_system_dep = declare_dependency(
57+
include_directories : incdirs,
58+
link_with : unit_system,
59+
version: meson.project_version(),
60+
)
61+
62+
install_headers('include/unit_system_17.hpp', subdir : 'unit_system')
4963

50-
pkg = import('pkgconfig')
51-
pkg.generate(unit_system, subdirs: 'unit_system')
64+
pkg = import('pkgconfig')
65+
pkg.generate(unit_system, subdirs: 'unit_system')
66+
else
67+
unit_system_dep = declare_dependency(
68+
include_directories : incdirs,
69+
version: meson.project_version(),
70+
)
71+
72+
install_headers('include/unit_system_20.hpp', subdir : 'unit_system')
73+
endif
5274

53-
install_headers('include/unit_system.hpp')
75+
conf_data = configuration_data()
76+
conf_data.set('USE_CPP_17', use_cpp_17)
77+
configure_file(
78+
input : 'include/unit_system.hpp.in',
79+
output : 'unit_system.hpp',
80+
configuration : conf_data,
81+
install: true,
82+
install_dir: 'unit_system',
83+
)
5484

5585
meson.override_dependency('unit-system', unit_system_dep)
56-
meson.override_dependency('unit-system-20', unit_system_20_dep)
5786

5887
build_tests = get_option('build_tests').enable_auto_if(not meson.is_subproject())
5988
if build_tests.enabled()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
option('build_tests', type : 'feature', value : 'auto', description: 'disable to not build tests when compiling directly. enable to also build tests if built as subproject')
2+
option('use_cpp_17', type : 'feature', value : 'auto', description: 'force the use of the c++17 variant if enabled, the c++20 version if disabled and auto detect based on cpp_std if auto.')

0 commit comments

Comments
 (0)