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

Unable to cmake: "zstd::libzstd_static" missing #25

Open
tranzmatt opened this issue Feb 3, 2023 · 7 comments
Open

Unable to cmake: "zstd::libzstd_static" missing #25

tranzmatt opened this issue Feb 3, 2023 · 7 comments

Comments

@tranzmatt
Copy link

When I go to build via cmake, I get the following:

build$ cmake ..
-- Configuring done
CMake Error at CMakeLists.txt:10 (add_library):
  Target "light_pcapng" links to target "zstd::libzstd_static" but the target
  was not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?

I'm running Ubuntu 22.04 and have all the zstd libs and headers installed, so I don't know what it's complaining about. Is there some special version I need?

@kayoub5
Copy link
Member

kayoub5 commented Feb 3, 2023

Content of FindZstd.cmake file?

@tranzmatt
Copy link
Author

tranzmatt commented Feb 3, 2023

I cloned from your master branch, hash c8e5657 and the contents are unchanged.

All I do is

mkdir build
cd build
cmake ..

@tranzmatt
Copy link
Author


add_library(light_zstd INTERFACE)

function(zstd_libraries SHARED_LIB STATIC_LIB)
    if(BUILD_SHARED_LIBS)
        target_link_libraries(light_zstd INTERFACE ${SHARED_LIB})
    else()
        target_link_libraries(light_zstd INTERFACE ${STATIC_LIB})
        # this pthread linking is required for the static linking of certain zstd
        # versions. See: https://github.com/facebook/zstd/pull/2097
        find_package(Threads REQUIRED)
        target_link_libraries(light_zstd INTERFACE ${CMAKE_THREAD_LIBS_INIT})
    endif()
endfunction()

# Try to find zstd in the cmake search path
find_package(zstd QUIET)
if(zstd_FOUND)
    if(TARGET zstd::zstd)
        # dependency was resolved by conan (find_package generator)
        target_link_libraries(light_zstd INTERFACE zstd::zstd)
    else()
        zstd_libraries(zstd::libzstd_shared zstd::libzstd_static)
    endif()
else()
    # zstd was not found, so we do not resolve our dependency by ourself
    # try finding the library on the system with the traditional method 
    # (no cmake package on system)
    find_path(ZSTD_INCLUDE_DIRS zstd.h)
    find_library(ZSTD_STATIC_LIB NAMES libzstd.a)
    find_library(ZSTD_SHARED_LIB NAMES libzstd.so)

    if(ZSTD_INCLUDE_DIRS AND ZSTD_STATIC_LIB AND ZSTD_SHARED_LIB)
        zstd_libraries("${ZSTD_SHARED_LIB}" "${ZSTD_STATIC_LIB}")
        target_include_directories(light_zstd INTERFACE "${ZSTD_INCLUDE_DIRS}")
        set(zstd_FOUND ON)
    endif()
endif()

if(NOT zstd_FOUND)
    # compile library if not found
    include(FetchContent)

    FetchContent_Declare(
        zstd
        GIT_REPOSITORY https://github.com/facebook/zstd.git
        GIT_TAG v1.5.0)

    FetchContent_GetProperties(zstd POPULATED ZSTD_POPULATED)

    if(NOT ZSTD_POPULATED)
        FetchContent_Populate(zstd)
        add_subdirectory("${zstd_SOURCE_DIR}/build/cmake" "${zstd_BINARY_DIR}" EXCLUDE_FROM_ALL)
    endif()
    zstd_libraries(libzstd_shared libzstd_static)
    target_include_directories(light_zstd INTERFACE "${zstd_SOURCE_DIR}/lib")
endif()```

@kayoub5
Copy link
Member

kayoub5 commented Feb 3, 2023

I cloned from your master branch, hash c8e5657 and the contents are unchanged.

All I do is

mkdir build cd build cmake ..

Content of FindZstd.cmake in your cmake installation

@tranzmatt
Copy link
Author

tranzmatt commented Feb 3, 2023

There isn't one. I checked out master. Am I on the wrong tag/branch?

$ find . -name "*.cmake"
./cmake/zlib.cmake
./cmake/zstd.cmake

I'm running cmake version 3.22.1 installed by 22.04, but I don't see any FindZstd.cmake

@kayoub5
Copy link
Member

kayoub5 commented Feb 3, 2023

Comment the line find_package(zstd QUIET) and set zstd_FOUND to false

@tranzmatt
Copy link
Author

That seemed to work. Cmake and make built it. Thanks.

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