hyperrealm / libconfig

C/C++ library for processing configuration files
https://hyperrealm.github.io/libconfig/
GNU Lesser General Public License v2.1
1.12k stars 366 forks source link

Cmake config is broken. #231

Closed FrankXie05 closed 1 year ago

FrankXie05 commented 1 year ago

Hi, I'm one of the maintainers of vcpkg, and we recently received a question about libconfg using cmake. Issue: There seems to be this problem with the exported cmake usage after we installed libconfig, it fails to link against libconfig++. Run command ./vcpkg install libconfig:x64-windows --head and output:

libconfig provides CMake targets:

    # this is heuristically generated, and may not be correct
    find_package(libconfig CONFIG REQUIRED)
    target_link_libraries(main PRIVATE libconfig::libconfig libconfig::libconfig++)

For this reason, I made a patch to separate libconfig and libconfig++.

However, from the code structure, libconfig does not seem to be separated, but is linked to libconfig++. BUt, it was broken. https://github.com/hyperrealm/libconfig/blob/4f13b7f5152427b5e511a09617ca2d9ff63f7800/lib/CMakeLists.txt#L144 https://github.com/hyperrealm/libconfig/blob/4f13b7f5152427b5e511a09617ca2d9ff63f7800/lib/CMakeLists.txt#L152

Reproduce steps: CMakeLists.txt

cmake_minimum_required(VERSION 3.0)
project(test)
add_executable(main main.cpp)
find_package(libconfig CONFIG REQUIRED)
target_link_libraries(main PRIVATE libconfig::libconfig libconfig::libconfig++)

Error:

CMake Error at CMakeLists.txt:5 (target_link_libraries):
  Target "main" links to:

    libconfig::libconfig++

  but the target was not found.  Possible reasons include:

    * There is a typo in the target name.
    * A find_package call is missing for an IMPORTED target.
    * An ALIAS target is missing.

Related vcpkg issue and PR: https://github.com/microsoft/vcpkg/issues/30906 https://github.com/microsoft/vcpkg/pull/30980

@hyperrealm

dg0yt commented 1 year ago

This question drags in a lot of vcpkg particularities. More general (https://github.com/microsoft/vcpkg/pull/30980#discussion_r1172147992), please solve this problem and inconsistency:

Target libconfig++ is in namespace and directory libconfig but in config libconfig++. This makes the target unreachable.

Consistent patterns would be:

I would recommend the first alternative, in particular because they are connected.

mllusar commented 1 year ago

Hey ! Is there any new about this issue ? I really need to use libonfig++ under Cmake with vcpkg.

I'm not an advanced programmer, but it seams that all we need need is to rename the namespace.

FrankXie05 commented 1 year ago

@mllusar You can use my PR temporarily https://github.com/microsoft/vcpkg/pull/30980

dg0yt commented 1 year ago
  • Target libconfig++ is in namespace, config and directory libconfig.

Implemented in #234.