Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

How do I config ylt with fetch content? #580

Closed
1 of 2 tasks
yhyu13 opened this issue Jan 27, 2024 · 6 comments
Closed
1 of 2 tasks

How do I config ylt with fetch content? #580

yhyu13 opened this issue Jan 27, 2024 · 6 comments
Assignees

Comments

@yhyu13
Copy link
Contributor

yhyu13 commented Jan 27, 2024

Search before asking

  • I searched the issues and found no similar issues.

What happened + What you expected to happen

Hi, I am using ylt in a project. And the way I import ylt is by fetch content.

include(FetchContent)
FetchContent_Declare(
    yalantinglibs
    GIT_REPOSITORY https://github.com/yhyu13/yalantinglibs.git
    GIT_TAG 679cbac8f3c5566a842c91b9d332632d3076f6ac
    GIT_SHALLOW 1 # optional ( --depth=1 )
)
FetchContent_MakeAvailable(yalantinglibs)

I found severl config flag interesting https://github.com/alibaba/yalantinglibs/blob/main/cmake/config.cmake

How do I enable these flag options in my build with the way fetch content work?

Do these flags taken effect simply by truning them to ON, and leave everything else to CMAKE? Then I should probably make a cl to my fork repo that turn these flag on

Reproduction way

Anything else

Are you willing to submit a PR?

  • Yes I am willing to submit a PR!
@qicosmos
Copy link
Collaborator

Can you look at this PR: #519

maybe helpful for you.

@yhyu13
Copy link
Contributor Author

yhyu13 commented Feb 4, 2024

@qicosmos

It seems config.cmake is only included when compiling yalantinlibs as the promary project, the config.cmake is never toched on fetch content, only install.cmake is executed

if(CMAKE_PROJECT_NAME STREQUAL "yaLanTingLibs") # if ylt is top-level project

It does hinder users's ability to config yanlantinlibs out of the box, but since fectch content allow pulling from git forks, it is ok, we just need to modify config into our need.

@yhyu13
Copy link
Contributor Author

yhyu13 commented Feb 4, 2024

Ok, here is my solution, one solution is to modify yanlantinlibs in my local repo and commit config.cmake into Cmakelists.txt and change options in what I want them to be. Another way to work around is figure out all compilation flags and add them manully.

include(FetchContent)
Set(FETCHCONTENT_QUIET FALSE)
FetchContent_Declare(
    yalantinglibs
    GIT_REPOSITORY https://github.com/yhyu13/yalantinglibs.git
    GIT_TAG 679cbac8f3c5566a842c91b9d332632d3076f6ac
    GIT_SHALLOW 1 # optional ( --depth=1 )
    GIT_PROGRESS TRUE
    SYSTEM
)
FetchContent_MakeAvailable(yalantinglibs)
target_compile_definitions(yalantinglibs INTERFACE YLT_ENABLE_PMR IGUANA_ENABLE_PMR ENABLE_STRUCT_PACK_OPTIMIZE)
target_link_libraries(Common PUBLIC yalantinglibs::yalantinglibs)

If you wan to use uring on linux, you need add compile defintion ASIO_HAS_IO_URING ASIO_HAS_FILE YLT_ENABLE_FILE_IO_URING and manully target_link_libary with uring

@yhyu13
Copy link
Contributor Author

yhyu13 commented Feb 4, 2024

I will leave this issue open, may be consider adding more config cmake options for devs who use fetch content for easier configuration?

@poor-circle
Copy link
Collaborator

Maybe we can export config.cmake to user. but some options' name should be changed to avoid conflict with user defined option. And I'll add some description to document later.

@PikachuHyA
Copy link
Collaborator

@yhyu13 hi, I test fetch content on my MacOS 13, it work fine

the highlight cmake config maybe

# change ylt_cmake_fetch to your own target name
target_link_libraries(ylt_cmake_fetch PRIVATE yalantinglibs)

the following is detail information about my demo

  • cmake config
cmake_minimum_required(VERSION 3.28)
project(ylt_cmake_fetch)

set(CMAKE_CXX_STANDARD 20)
include(FetchContent)
FetchContent_Declare(
        yalantinglibs
        GIT_REPOSITORY https://github.com/alibaba/yalantinglibs.git
        GIT_TAG a920fce8b0d7b6a3a42e459c17ee5b9925d5a2ff # the least commit id
        GIT_SHALLOW 1 # optional ( --depth=1 )
)
FetchContent_MakeAvailable(yalantinglibs)
add_executable(ylt_cmake_fetch main.cpp)
target_link_libraries(ylt_cmake_fetch PRIVATE yalantinglibs)
  • c++ code
#include <iostream>
#include <ylt/struct_pack.hpp>

struct Foo {
    int x;
};

int main() {
    std::cout << "Hello, World!" << std::endl;
    Foo foo{.x = 100};
    auto buf = struct_pack::serialize(foo);
    auto ret = struct_pack::deserialize<Foo>(buf);
    if (ret) {
        std::cout << "use struct_pack success" << std::endl;
        std::cout << "foo.x is " << ret->x << std::endl;
    }
    else {
        std::cout << "Error: " << std::endl;
    }
    return 0;
}

  • output
Hello, World!
use struct_pack success
foo.x is 100

@alibaba alibaba locked and limited conversation to collaborators Feb 4, 2024
@poor-circle poor-circle converted this issue into discussion #590 Feb 4, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants