microsoft / vcpkg

C++ Library Manager for Windows, Linux, and MacOS
MIT License
23.36k stars 6.45k forks source link

[libdatachannel] Failed to build libdatachannel as a static library without srtp. #41797

Closed Nemirtingas closed 1 month ago

Nemirtingas commented 1 month ago

Operating system

Linux

Compiler

GCC

Steps to reproduce the behavior

vcpkg install libdatachannel

Then use libdatachannel in your project.

Failure logs

CMake Error at /vcpkg/scripts/buildsystems/vcpkg.cmake:859 (_find_package):
  Could not find a package configuration file provided by "libSRTP" with any
  of the following names:

    libSRTPConfig.cmake
    libsrtp-config.cmake

  Add the installation prefix of "libSRTP" to CMAKE_PREFIX_PATH or set
  "libSRTP_DIR" to a directory containing one of the above files.  If
  "libSRTP" provides a separate development package or SDK, be sure it has
  been installed.
Call Stack (most recent call first):
  /vcpkg/downloads/tools/cmake-3.30.1-linux/cmake-3.30.1-linux-x86_64/share/cmake-3.30/Modules/CMakeFindDependencyMacro.cmake:76 (find_package)
  build/linux_vcpkg/x86-linux-nemirtingas/share/libdatachannel/LibDataChannelConfig.cmake:8 (find_dependency)
  /vcpkg/scripts/buildsystems/vcpkg.cmake:859 (_find_package)
  CMakeLists.txt:82 (find_package)

Additional context

Here is the config file's LibDataChannelConfig.cmake content:

if(NOT "OFF")
    include(CMakeFindDependencyMacro)
    set(THREADS_PREFER_PTHREAD_FLAG ON)
    find_dependency(Threads)
    find_dependency(plog CONFIG)
    find_dependency(unofficial-usrsctp CONFIG)
    if(NOT "ON")
        find_dependency(libSRTP CONFIG)
    endif()
    find_dependency(OpenSSL)
    find_dependency(LibJuice)
endif()

include("${CMAKE_CURRENT_LIST_DIR}/LibDataChannelTargets.cmake")

if(NOT "ON") and if(NOT "OFF") doesn't work. Its always true. https://github.com/microsoft/vcpkg/blob/e60236ee051183f1122066bee8c54a0b47c43a60/ports/libdatachannel/dependencies.diff#L45-L61

When building a static library.

dg0yt commented 1 month ago

if(NOT "ON") and if(NOT "OFF") doesn't work. Its always true.

It does work. At least with cmake_minimum_required(VERSION 3.0). (CMP0012.)

cmake_minimum_required(VERSION 3.0)
if("ON")
    message(STATUS "okay: ON")
endif()
if(NOT "ON")
    message(FATAL_ERROR "not okay: NOT ON")
endif()
if("OFF")
    message(FATAL_ERROR "not okay: OFF")
endif()
if(NOT "OFF")
    message(STATUS "okay: NOT OFF")
endif()
Nemirtingas commented 1 month ago

The patch adds all this logic before cmake_minimum_required: https://github.com/paullouisageneau/libdatachannel/blob/3c33ea0f49fff2630be080b2043052b4d3de5786/CMakeLists.txt#L1

Maybe thats the issue?

dg0yt commented 1 month ago

The patch doesn't add any code before cmake_minimum_required. A config.cmake file is generally used after cmake_minimum_required + project.

dg0yt commented 1 month ago

AFAIU you must look at your project, not at vcpkg.

Nemirtingas commented 1 month ago

My cmakelists.txt is written as:

cmake_policy(SET CMP0063 NEW)
cmake_policy(SET CMP0091 NEW)
project(lib_name)
cmake_minimum_required(VERSION 3.15)

find_package(LibDataChannel CONFIG REQUIRED)

What could be the issue then?

dg0yt commented 1 month ago

cmake_minimum_required must be used before project. Frequent error.

Nemirtingas commented 1 month ago

Dang x), thanks for the help!