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

[cairo] CMake does not copy necessary dlls after glib/gtk port update. #17595

Closed
csorvagep opened this issue Apr 30, 2021 · 8 comments · Fixed by #17596
Closed

[cairo] CMake does not copy necessary dlls after glib/gtk port update. #17595

csorvagep opened this issue Apr 30, 2021 · 8 comments · Fixed by #17596
Assignees
Labels
category:port-bug The issue is with a library, which is something the port should already support

Comments

@csorvagep
Copy link
Contributor

Describe the bug
After PR #13100, I'm not able to run my application becaue, CMake does not copy dlls next to the executeble. I'm using my own CMake module file (Findcairo.cmake) in order to setup cairo, but this does not work anymore. After configuring, the library is called cairo.lib (earlier this was cairod.lib for debug) and the dll is cairo-2.dll. If I start my application, the windows tells me, that there is no libcairo-2.dll.

My module file is probably not the best, but can anyone help me how to set this up?

Environment

  • OS: Windows 10 20H2
  • Compiler: MSVC v16.9.3

Here's my Findcairo.cmake file:

if (NOT WIN32)
    find_package(PkgConfig)
    if (PKG_CONFIG_FOUND)
        pkg_check_modules(_CAIRO cairo)

        SET(CAIRO_VERSION ${_CAIRO_VERSION})
        STRING (REGEX REPLACE "([0-9]+).([0-9]+).([0-9]+)" "\\1" num "${CAIRO_VERSION}")
        MATH (EXPR CAIRO_VERSION_MAJOR "${num}")
        STRING (REGEX REPLACE "([0-9]+).([0-9]+).([0-9]+)" "\\2" num "${CAIRO_VERSION}")
        MATH (EXPR CAIRO_VERSION_MINOR "${num}")
        STRING (REGEX REPLACE "([0-9]+).([0-9]+).([0-9]+)" "\\3" num "${CAIRO_VERSION}")
        MATH (EXPR CAIRO_VERSION_MICRO "${num}")
    endif (PKG_CONFIG_FOUND)
endif (NOT WIN32)

set(_CAIRO_ROOT_HINTS_AND_PATHS
  HINTS 
     $ENV{CAIRO}
     $ENV{CAIRO_DIR}
     ${CMAKE_FIND_ROOT_PATH}
     ${CAIRO_ROOT_DIR}
  PATHS
    ${CMAKE_FIND_ROOT_PATH}
    $ENV{CAIRO}/src
    /usr
    /usr/local
)

find_path(CAIRO_INCLUDE_DIR
    NAMES
        cairo.h
    HINTS
        ${_CAIRO_INCLUDEDIR}
        ${_CAIRO_ROOT_HINTS_AND_PATHS}
    PATH_SUFFIXES
        include
        "include/cairo"
)

if(NOT CAIRO_LIBRARY)
    FIND_LIBRARY(CAIRO_LIBRARY_RELEASE
        NAMES
            cairo
            cairo-static
        HINTS
            ${_CAIRO_LIBDIR}
            ${_CAIRO_ROOT_HINTS_AND_PATHS}
        PATH_SUFFIXES
            "lib"
            "local/lib"
    ) 

    FIND_LIBRARY(CAIRO_LIBRARY_DEBUG
        NAMES
            cairod
            cairo-staticd
        HINTS
            ${_CAIRO_LIBDIR}
            ${_CAIRO_ROOT_HINTS_AND_PATHS}
        PATH_SUFFIXES
            "lib"
            "local/lib"
    ) 

    include(SelectLibraryConfigurations)
    select_library_configurations(CAIRO)
endif()
set(CAIRO_LIBRARIES ${CAIRO_LIBRARY})

if (NOT CAIRO_VERSION)
    if (EXISTS "${CAIRO_INCLUDE_DIR}/cairo-version.h")
        file(READ "${CAIRO_INCLUDE_DIR}/cairo-version.h" CAIRO_VERSION_CONTENT)

        string(REGEX MATCH "#define +CAIRO_VERSION_MAJOR +([0-9]+)" _dummy "${CAIRO_VERSION_CONTENT}")
        set(CAIRO_VERSION_MAJOR "${CMAKE_MATCH_1}")

        string(REGEX MATCH "#define +CAIRO_VERSION_MINOR +([0-9]+)" _dummy "${CAIRO_VERSION_CONTENT}")
        set(CAIRO_VERSION_MINOR "${CMAKE_MATCH_1}")

        string(REGEX MATCH "#define +CAIRO_VERSION_MICRO +([0-9]+)" _dummy "${CAIRO_VERSION_CONTENT}")
        set(CAIRO_VERSION_MICRO "${CMAKE_MATCH_1}")

        set(CAIRO_VERSION "${CAIRO_VERSION_MAJOR}.${CAIRO_VERSION_MINOR}.${CAIRO_VERSION_MICRO}")
        set(CAIRO_VERSION_STRING CAIRO_VERSION)
    endif ()
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
    cairo 
    REQUIRED_VARS 
        CAIRO_LIBRARIES 
        CAIRO_INCLUDE_DIR
    VERSION_VAR
        CAIRO_VERSION_STRING
)

MARK_AS_ADVANCED(
    CAIRO_INCLUDE_DIR 
    CAIRO_LIBRARY
    CAIRO_LIBRARIES)
@Neumann-A
Copy link
Contributor

Neumann-A commented Apr 30, 2021

Use FindPkgConfig together with the pkgconf port on windows. (As long as you don't care about multi-config generators.)

@csorvagep
Copy link
Contributor Author

Thanks, I've added the pkgconf to the manifest file, and I changed my CMakeLists.txt to this:

find_package(PkgConfig)
pkg_check_modules(Cairo REQUIRED IMPORTED_TARGET cairo)
target_link_libraries(my_target PUBLIC PkgConfig::Cairo)

But still there is no dlls next to the executable. The target receives cairo transitively, but that should be fine, because the headers are found and the link works.

@csorvagep
Copy link
Contributor Author

Here are the variables set by pkgconfig (changed the project path to ${workspaceFolder}):

[cmake] Cairo_FOUND: 1
[cmake] Cairo_INCLUDE_DIRS: ${workspaceFolder}/build/vcpkg_installed/x64-windows/debug/lib/pkgconfig/../../../include/cairo
[cmake] Cairo_LIBRARIES: cairo
[cmake] Cairo_LINK_LIBRARIES: ${workspaceFolder}/build/vcpkg_installed/x64-windows/debug/lib/cairo.lib
[cmake] Cairo_LIBRARY_DIRS: ${workspaceFolder}/build/vcpkg_installed/x64-windows/debug/lib/pkgconfig/../../lib
[cmake] Cairo_LDFLAGS: -L${workspaceFolder}/build/vcpkg_installed/x64-windows/debug/lib/pkgconfig/../../lib;-lcairo
[cmake] Cairo_LDFLAGS_OTHER: 
[cmake] Cairo_CFLAGS: -I${workspaceFolder}/build/vcpkg_installed/x64-windows/debug/lib/pkgconfig/../../../include/cairo
[cmake] Cairo_CFLAGS_OTHER: 

@Neumann-A
Copy link
Contributor

Add this patch into the portfile of cairo and rebuild cairo.
win_def.txt

@Neumann-A
Copy link
Contributor

Or you can try out #17596

@Neumann-A
Copy link
Contributor

@ras0219-msft: Is it possible to bake a check into the vcpkg-tool so this can be caught earlier?

@csorvagep
Copy link
Contributor Author

Thanks @Neumann-A, this works now.

@JackBoosY JackBoosY added the category:port-bug The issue is with a library, which is something the port should already support label May 2, 2021
@ras0219-msft
Copy link
Contributor

Hmm. I think the right check would be something like "for all DLLs, is there at least one reference from a .lib file to it?". We can't simply ask "are all references satisfied" because it's unfortunately normal to depend upon external stuff like kernel32 et al.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:port-bug The issue is with a library, which is something the port should already support
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants