Giter Site home page Giter Site logo

Comments (7)

lemire avatar lemire commented on June 18, 2024

From the README:

You can create a single-header version of the library where all of the code is put into two files (simdutf.h and simdutf.cpp). We publish a zip archive containing these files, e.g., see https://github.com/simdutf/simdutf/releases/download/v3.2.2/singleheader.zip

There is a single header and a single source file.

We provide an example... here is a simplified version:

#include <iostream>
#include <memory>

#include "simdutf.cpp"
#include "simdutf.h"

int main(int , char *[]) {
  const char *source = "1234";
  // 4 == strlen(source)
  bool validutf8 = simdutf::validate_utf8(source, 4);
  if (validutf8) {
    std::cout << "valid UTF-8" << std::endl;
  } else {
    std::cerr << "invalid UTF-8" << std::endl;
    return EXIT_FAILURE;
  }
  return EXIT_SUCCESS;
}

Also, I expect to be able to install both versions at the same time. But now the amalgamated file from the zip archive and include/simduft.h have the same name, so it's unclear how to differentiate them in CMAKE_INSTALL_INCLUDEDIR.

I am not sure what you mean by both at the same time. You can either use the single-header version, in which case you just copy simdutf.h and simdutf.cpp to your project. Or else, if you want to use simdutf as an installed package of some sort, then you do so... Here is a CMake example...

cmake_minimum_required(VERSION 3.15)

project(test_simdutf_install VERSION 0.1.0 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(MSVC_VERSION GREATER 1910)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -permissive-")
endif()
find_package(simdutf REQUIRED)



file(WRITE main.cpp "
#include <iostream>
#include \"simdutf.h\"
int main(int argc, char *argv[]) {
   const char * ascii = \"1234\";
   bool validutf8 = simdutf::validate_utf8(ascii, 4);
   if(validutf8) {
       std::cout << \"valid UTF-8\" << std::endl;
   } else {
       std::cout << \"invalid UTF-8\" << std::endl;
       return EXIT_FAILURE;
   }
   char16_t utf16_output[4];
   // convert to UTF-16LE
   size_t utf16words = simdutf::convert_utf8_to_utf16le(ascii, 4, utf16_output);
   std::cout << \"wrote \" << utf16words << \" UTF-16 words.\" << std::endl;
   // It wrote utf16words * sizeof(char16_t) bytes.
   //
   // convert it back:
   char buffer[4];
   size_t utf8words = simdutf::convert_utf16le_to_utf8(utf16_output, utf16words, buffer);
   std::cout << \"wrote \" << utf8words << \" UTF-8 words.\" << std::endl;
   return EXIT_SUCCESS;
}")



add_executable(repro main.cpp)
target_link_libraries(repro PUBLIC simdutf::simdutf)

from simdutf.

lemire avatar lemire commented on June 18, 2024

If you use the single-header release, then two files must be installed the header (there is just one) and the source file.

from simdutf.

lemire avatar lemire commented on June 18, 2024

From CMake, you can use simdutf as a dependency as follows...

cmake_minimum_required(VERSION 3.15)

project(simdutf_demo_install VERSION 0.1.0 LANGUAGES CXX)


set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(FetchContent)

FetchContent_Declare(
  simdutf
  GIT_REPOSITORY [email protected]:simdutf/simdutf.git
  GIT_SHALLOW TRUE
  GIT_TAG tags/v3.2.2
  )
FetchContent_MakeAvailable(simdutf)

file(WRITE main.cpp "
#include <iostream>
#include \"simdutf.h\"
int main(int argc, char *argv[]) {
   const char * ascii = \"1234\";
   bool validutf8 = simdutf::validate_utf8(ascii, 4);
   if(validutf8) {
       std::cout << \"valid UTF-8\" << std::endl;
   } else {
       std::cout << \"invalid UTF-8\" << std::endl;
       return EXIT_FAILURE;
   }
   char16_t utf16_output[4];
   // convert to UTF-16LE
   size_t utf16words = simdutf::convert_utf8_to_utf16le(ascii, 4, utf16_output);
   std::cout << \"wrote \" << utf16words << \" UTF-16 words.\" << std::endl;
   // It wrote utf16words * sizeof(char16_t) bytes.
   //
   // convert it back:
   char buffer[4];
   size_t utf8words = simdutf::convert_utf16le_to_utf8(utf16_output, utf16words, buffer);
   std::cout << \"wrote \" << utf8words << \" UTF-8 words.\" << std::endl;
   return EXIT_SUCCESS;
}")



add_executable(repro main.cpp)
target_link_libraries(repro PUBLIC simdutf::simdutf)

from simdutf.

lemire avatar lemire commented on June 18, 2024

I am going to close the issue. The reporter is correct, they need two files for the single-header version.

from simdutf.

lemire avatar lemire commented on June 18, 2024

As a last remark: we do not and probably never will support having both the single-header and another version of the simdutf library in the same project. It is the same code, same library, just packaged differently. Many users find the single-header version simpler.

from simdutf.

tocic avatar tocic commented on June 18, 2024

If you use the single-header release, then two files must be installed the header (there is just one) and the source file.

I understand, but I expected "single-header" to be "header-only". And I've never seen the inclusion of a .cpp file in other projects. You are free to use any distribution method you want, of course, just wanted to know your motivation for this.

I am not sure what you mean by both at the same time

I meant simultaneous installation, not usage. So you can package both versions of the library and give users a chance to select the version they want. Currently, IIUC, you need to create 2 different packages or manually rename/move files.

from simdutf.

lemire avatar lemire commented on June 18, 2024

If you believe that there is a shortcoming, please consider providing a pull request.

from simdutf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.