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

CMake support for better dependency management #946

Closed
fizdm opened this issue Sep 9, 2023 · 4 comments
Closed

CMake support for better dependency management #946

fizdm opened this issue Sep 9, 2023 · 4 comments

Comments

@fizdm
Copy link

fizdm commented Sep 9, 2023

In some cases it makes sense to use liburing as static library and when you try to realize this in CMake project without install liburing to your system you have only one way to do this: move it on CMake build step, which forces you to hard-code binary and include dir pathes. To avoid this and get all include and lib pathes from CMake lib target you can use FetchContent, but it requires CMakeLists.txt in dependency :/

@fizdm
Copy link
Author

fizdm commented Sep 9, 2023

It looks like there is an attempt to intergrate CMake with liburing (#438), but it is more like "make CMake around exists code base" than "make everything around CMake". So..I would like to help with this and would be glad to hear any suggestions

@cmazakas
Copy link
Contributor

In general, FetchContent is a very poor solution to dependency management.

Build liburing externally or just build it as an ExternalProject or command or something like that and just find_package() like you normally would.

@fizdm
Copy link
Author

fizdm commented Sep 15, 2023

Okay, got it

If someone else is looking for a static linking solution with CMake. I solved it this way:

  • add git submodule to external/liburing.git
  • create external/CMakeLists.txt
set(LIBURING_LIB_PATH ${CMAKE_CURRENT_LIST_DIR}/liburing.git/src/liburing.a)
if (NOT EXISTS ${LIBURING_LIB_PATH})
    message(STATUS "Building liburing")
    execute_process(
            COMMAND ./configure
            WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/liburing.git
            OUTPUT_QUIET
    )

    execute_process(
            COMMAND make
            WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/liburing.git
            OUTPUT_QUIET
    )
endif ()

add_library(${PROJECT_NAME}_liburing STATIC IMPORTED GLOBAL)
set_property(TARGET ${PROJECT_NAME}_liburing PROPERTY
        IMPORTED_LOCATION ${LIBURING_LIB_PATH})
target_include_directories(${PROJECT_NAME}_liburing INTERFACE ${CMAKE_CURRENT_LIST_DIR}/liburing.git/src/include)

@fizdm fizdm closed this as completed Sep 15, 2023
@cmazakas
Copy link
Contributor

bozhe moi

git clone liburing.git \
  && cd liburing \
  && ./configure --prefix=/muh/install/path \
  && make && make install

Here's the find script:

find_package(PkgConfig REQUIRED)
pkg_check_modules(PC_liburing REQUIRED liburing)

find_path(liburing_INCLUDE_DIR
  NAMES liburing.h
  PATHS ${PC_liburing_INCLUDE_DIRS}
)
find_library(liburing_LIBRARY
  NAMES uring
  PATHS ${PC_liburing_LIBRARY_DIRS}
)

set(liburing_VERSION ${PC_liburing_VERSION})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(liburing
  FOUND_VAR liburing_FOUND
  REQUIRED_VARS
    liburing_LIBRARY
    liburing_INCLUDE_DIR
  VERSION_VAR liburing_VERSION
)

if(liburing_FOUND AND NOT TARGET liburing::liburing)
  add_library(liburing::liburing UNKNOWN IMPORTED)
  set_target_properties(liburing::liburing PROPERTIES
    IMPORTED_LOCATION "${liburing_LIBRARY}"
    INTERFACE_INCLUDE_DIRECTORIES "${liburing_INCLUDE_DIR}"
  )
endif()

mark_as_advanced(
  liburing_INCLUDE_DIR
  liburing_LIBRARY
)

Then in your cmake toolchain file:

list(APPEND CMAKE_PREFIX_PATH "/muh/install/path")

and then:

find_package(liburing 2.5 REQUIRED)

will just work, it's ez pz, man

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