Skip to content

Commit

Permalink
Updated StringView and link list for vcpkglib (#444)
Browse files Browse the repository at this point in the history
* Added template constructor to StringView

Compilation on Raspberry Pi OS with gcc 8.3 was failing because the
StringView class did not have constructor defined for ZStringView.

Addresses microsoft/vcpkg#21142

* Added atomic library to link list

Addresses microsoft/vcpkg#22843
Related to microsoft/vcpkg#21142

* Added expression filter for atomic

* Corrected filter expression

* Detect libatomic

* fix it the strega way!

* Adjust atomic test code

* strega nits

Co-authored-by: Robert Schumacher <[email protected]>
Co-authored-by: nicole mazzuca <[email protected]>
Co-authored-by: nicole mazzuca <[email protected]>
  • Loading branch information
4 people authored Mar 25, 2022
1 parent 5a75f1e commit d9702d9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
27 changes: 27 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,40 @@ else()
)
endif()

set(CPP_ATOMIC_LIBRARY "")
if(NOT MSVC)
# Some platforms require a explicit linkage against libatomic to operate on 64-bit numbers
set(TEST_SOURCE "
#include <stdint.h>
#include <atomic>
std::atomic<uintptr_t> x;
std::atomic<uintmax_t> y;
int main() {
return x + y;
}
")
check_cxx_source_compiles("${TEST_SOURCE}" CPP_ATOMIC_BUILTIN)
if(NOT CPP_ATOMIC_BUILTIN)
list(APPEND CMAKE_REQUIRED_LIBRARIES atomic)
set(CPP_ATOMIC_LIBRARY atomic)
check_cxx_source_compiles("${TEST_SOURCE}" CPP_ATOMIC_WITH_LIBATOMIC)
if (NOT CPP_ATOMIC_WITH_LIBATOMIC)
message(
FATAL_ERROR "unable to link C++ std::atomic code: you may need \
to install GNU libatomic"
)
endif()
endif()
endif()

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(vcpkglib
PUBLIC
fmt::fmt
PRIVATE
Threads::Threads
${CPP_ATOMIC_LIBRARY}
)

if(MSVC)
Expand Down
2 changes: 1 addition & 1 deletion include/vcpkg/base/stringliteral.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ namespace vcpkg
};
}

VCPKG_FORMAT_AS(vcpkg::StringLiteral, vcpkg::StringView);
VCPKG_FORMAT_AS(vcpkg::StringLiteral, vcpkg::ZStringView);
1 change: 1 addition & 0 deletions include/vcpkg/base/stringview.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace vcpkg
{

struct StringView
{
constexpr StringView() = default;
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/base/messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ namespace vcpkg::msg
m.localized_strings.resize(m.names.size());
m.initialized = true;

std::set<StringView, std::less<>> names_set(m.names.begin(), m.names.end());
std::set<StringLiteral, std::less<>> names_set(m.names.begin(), m.names.end());
if (names_set.size() < m.names.size())
{
// This will not trigger on any correct code path, so it's fine to use a naive O(n^2)
Expand Down

0 comments on commit d9702d9

Please sign in to comment.