Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utilitze JS crypto.createUUID() when compiling with Emscripten #71

Open
negentropicdev opened this issue Dec 18, 2023 · 2 comments
Open

Comments

@negentropicdev
Copy link

Similar to the other platform defines, emscripten provides a mechanism for calling JS APIs from C++ and all modern browsers provide a secure UUID generation method.

I'm current experimenting with this for a cross platform I'm building, one of which is to WASM but I am not a cmake wizard and am just statically including all the necessary crossguid files in my app with crossguid as a submodule. I can get all the includes and everything straightened out but am not sure of the proper way to nest the crossguid build from another cmake project.

@neonsoftware
Copy link

Hi @negentropicdev,

[I am just a user]

In standard CMake practice it could be by using CMake's FetchContent, which handles dependent CMake-based libraries available on public git repositories.

Here is a sample micro-project using it. It should compile fine.

main.cpp

#include "crossguid/guid.hpp"
#include <iostream>

int main()
{
    std::cout << "Here is a new GUID : " << xg::newGuid() << std::endl;
    return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.15)
project(mySample)

set(CMAKE_CXX_STANDARD 17)

# Using FetchContent to include crossguid
include(FetchContent)

# indicate crossguid's location and version to use
FetchContent_Declare(
        crossguid
        GIT_REPOSITORY https://github.com/graeme-hill/crossguid.git
        GIT_TAG master)

# making available throughout the project
FetchContent_MakeAvailable(crossguid)

add_executable(sample main.cpp)

# add crossguid as dependency (provides both link and include files)
target_link_libraries(sample PRIVATE crossguid)

NOTE:
You will need, in your CMakeLists.txt, all the 4 lines where I have added a comment line.
Each of those line is standard and needed (include, FetchContent_Declare, FetchContent_MakeAvailable, target_link_libraries).

Would this help ?

Let me know.

Cheers

@negentropicdev
Copy link
Author

I would give that a shot but I'm currently relying on changes I've made to support the additional toolchain that aren't in the public repo right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants