Skip to content

Commit 6a685cd

Browse files
authored
fix cmake include header (#7)
1 parent a8b2103 commit 6a685cd

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

CMakeLists.txt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,25 @@ if (NOT CMAKE_BUILD_TYPE)
88
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
99
endif()
1010

11+
include(GNUInstallDirs)
1112

1213
add_subdirectory(src)
1314
enable_testing()
1415
add_subdirectory(tests)
15-
add_subdirectory(benchmarks)
16+
add_subdirectory(benchmarks)
17+
18+
install(
19+
FILES include/version_weaver.h
20+
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
21+
COMPONENT version_weaver_development
22+
)
23+
24+
install(
25+
TARGETS version_weaver
26+
EXPORT version_weaver_targets
27+
RUNTIME COMPONENT version_weaver_runtime
28+
LIBRARY COMPONENT version_weaver_runtime
29+
NAMELINK_COMPONENT version_weaver_development
30+
ARCHIVE COMPONENT version_weaver_development
31+
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
32+
)

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ target_include_directories(version_weaver
33
PUBLIC
44
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
55
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
6-
)
6+
)

src/version_weaver.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@ std::string coerce(std::string_view version) { return ""; }
1313
std::string minimum(std::string_view range) { return ""; }
1414
std::string clean(std::string_view range) { return ""; }
1515

16-
inline std::string_view trim_whitespace(std::string_view input) noexcept {
17-
while (!input.empty() && std::isspace(input.front())) {
18-
input.remove_prefix(1);
16+
inline void trim_whitespace(std::string_view* input) noexcept {
17+
while (!input->empty() && std::isspace(input->front())) {
18+
input->remove_prefix(1);
1919
}
20-
while (!input.empty() && std::isspace(input.back())) {
21-
input.remove_suffix(1);
20+
while (!input->empty() && std::isspace(input->back())) {
21+
input->remove_suffix(1);
2222
}
23-
return input;
2423
}
2524

2625
std::expected<Version, ParseError> parse(std::string_view input) {
2726
if (input.size() > MAX_VERSION_LENGTH) {
2827
return std::unexpected(ParseError::VERSION_LARGER_THAN_MAX_LENGTH);
2928
}
3029

31-
std::string_view input_copy = trim_whitespace(input);
30+
std::string_view input_copy = input;
31+
trim_whitespace(&input_copy);
3232

3333
auto dot_iterator = input_copy.find('.');
3434
if (dot_iterator == std::string_view::npos) {
@@ -90,4 +90,5 @@ std::expected<Version, ParseError> parse(std::string_view input) {
9090
version.build = input_copy;
9191
return version;
9292
}
93+
9394
} // namespace version_weaver

0 commit comments

Comments
 (0)