microsoft / vcpkg

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

[raylib] cmake config is insufficient #25249

Closed Neumann-A closed 2 months ago

Neumann-A commented 2 years ago

Instead of generating a proper targets file for cmake raylib tries to run its own thing. This of course doesn't work correctly with vcpkg so that the target raylib export is not properly setup for all cases (debug/release).

JackBoosY commented 2 years ago

raylib-config.cmake and raylib-config-version.cmake are come from the upstream: https://github.com/raysan5/raylib/blob/master/cmake/raylib-config.cmake https://github.com/raysan5/raylib/blob/master/cmake/raylib-config-version.cmake

Maybe we should wait for the upstream make some changes?

MonicaLiu0311 commented 1 year ago

Upstream issue: https://github.com/raysan5/raylib/issues/3018

raysan5 commented 1 year ago

What's the state of this issue? Could anyone review it?

I'm afraid I'm not the maintainer of the raylib CMake build system...

MonicaLiu0311 commented 1 year ago

Upstream replies will not maintain the CMake build system, so the depends:upstream-changes tag has been removed.

archydragon commented 1 year ago

I was looking at this issue from raylib side and failed to recognize what exactly is broken (disclaimer: I ain'f neither raylib nor vcpkg expert). Passing specific CMAKE_BUILD_TYPE variable and --config parameter to cmake --build works as expected (as to me), I'm getting differently optimized builds:

    Directory: C:\Users\archy\ws\raylib-cmake-test\build\Release

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----          6/4/2023  10:14 PM          10240 main.exe
-a----          6/4/2023  10:10 PM        1419776 raylib.dll
    Directory: C:\Users\archy\ws\raylib-cmake-test\build\Debug

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----          6/4/2023  10:11 PM          54272 main.exe
-a----          6/4/2023  10:11 PM         929792 main.pdb
-a----          6/4/2023  10:10 PM        3454976 raylib.dll

What is exact expected behavior?

Neumann-A commented 1 year ago

The problem is :

if (NOT TARGET raylib)
    set(XPREFIX PC_RAYLIB)

    find_package(PkgConfig QUIET)
    pkg_check_modules(${XPREFIX} QUIET raylib)

    if (raylib_USE_STATIC_LIBS)
        set(XPREFIX ${XPREFIX}_STATIC)
    endif()

    set(raylib_DEFINITIONS ${${XPREFIX}_CFLAGS})

    find_path(raylib_INCLUDE_DIR
        NAMES raylib.h
        HINTS ${${XPREFIX}_INCLUDE_DIRS}
    )

    set(RAYLIB_NAMES raylib)

    if (raylib_USE_STATIC_LIBS)
        set(RAYLIB_NAMES libraylib.a raylib.lib ${RAYLIB_NAMES})
    endif()

    find_library(raylib_LIBRARY
        NAMES ${RAYLIB_NAMES}
        HINTS ${${XPREFIX}_LIBRARY_DIRS}
    )

    set(raylib_LIBRARIES    ${raylib_LIBRARY})
    set(raylib_LIBRARY_DIRS ${${XPREFIX}_LIBRARY_DIRS})
    set(raylib_LIBRARY_DIR  ${raylib_LIBRARY_DIRS})
    set(raylib_INCLUDE_DIRS ${raylib_INCLUDE_DIR})
    set(raylib_LDFLAGS      ${${XPREFIX}_LDFLAGS})

    include(FindPackageHandleStandardArgs)
    find_package_handle_standard_args(raylib DEFAULT_MSG
        raylib_LIBRARY
        raylib_INCLUDE_DIR
    )

    mark_as_advanced(raylib_LIBRARY raylib_INCLUDE_DIR)

    if (raylib_USE_STATIC_LIBS)
      add_library(raylib STATIC IMPORTED GLOBAL)
    else()
      add_library(raylib SHARED IMPORTED GLOBAL)
    endif()
    string (REPLACE ";" " " raylib_LDFLAGS "${raylib_LDFLAGS}")

    set_target_properties(raylib
      PROPERTIES
      IMPORTED_LOCATION             "${raylib_LIBRARIES}"
      IMPORTED_IMPLIB               "${raylib_LIBRARIES}"
      INTERFACE_INCLUDE_DIRECTORIES "${raylib_INCLUDE_DIRS}"
      INTERFACE_LINK_LIBRARIES      "${raylib_LDFLAGS}"
      INTERFACE_COMPILE_OPTIONS     "${raylib_DEFINITIONS}"
    )

    if (raylib_VERBOSE)
      message(STATUS "raylib_FOUND: ${raylib_FOUND}")
      message(STATUS "raylib_INCLUDE_DIRS: ${raylib_INCLUDE_DIRS}")
      message(STATUS "raylib_LIBRARIES: ${raylib_LIBRARIES}")
      message(STATUS "raylib_LDFLAGS: ${raylib_LDFLAGS}")
      message(STATUS "raylib_DEFINITIONS: ${raylib_DEFINITIONS}")
    endif()
endif()

This only works for single config builds.

github-actions[bot] commented 9 months ago

This is an automated message. Per our repo policy, stale issues get closed if there has been no activity in the past 180 days. The issue will be automatically closed in 14 days. If you wish to keep this issue open, please add a new comment.

github-actions[bot] commented 3 months ago

This is an automated message. Per our repo policy, stale issues get closed if there has been no activity in the past 180 days. The issue will be automatically closed in 14 days. If you wish to keep this issue open, please add a new comment.