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

cmake ignores Cflags.private #14641

Closed
Andarwinux opened this issue Aug 22, 2024 · 4 comments
Closed

cmake ignores Cflags.private #14641

Andarwinux opened this issue Aug 22, 2024 · 4 comments

Comments

@Andarwinux
Copy link

I did this

build curl with cmake -DCURL_USE_PKGCONFIG=ON

I expected the following

curl cmake should apply Cflags.private: -DLIBSSH_STATIC from dependency pkgconfig (libssh.pc), but it doesn't, causing the build to fail.

FAILED: src/curl.exe
: && /build/install/bin/x86_64-w64-mingw32-clang -DNGHTTP3_STATICLIB -DNGHTTP2_STATICLIB  -Werror-implicit-function-declaration -Wextra -Wall -pedantic -Wbad-function-cast -Wconversion -Winline -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wno-long-long -Wno-multichar -Wpointer-arith -Wshadow -Wsign-compare -Wundef -Wunused -Wwrite-strings -Waddress -Wattributes -Wcast-align -Wdeclaration-after-statement -Wdiv-by-zero -Wempty-body -Wendif-labels -Wfloat-equal -Wformat-security -Wignored-qualifiers -Wmissing-field-initializers -Wmissing-noreturn -Wno-format-nonliteral -Wno-system-headers -Wold-style-definition -Wredundant-decls -Wsign-conversion -Wno-error=sign-conversion -Wstrict-prototypes -Wtype-limits -Wunreachable-code -Wunused-parameter -Wvla -Wshift-sign-overflow -Wshorten-64-to-32 -Wlanguage-extension-token -Wformat=2 -Wdouble-promotion -Wenum-conversion -Wpragmas -Wunused-const-variable -Wunreachable-code-break -Wheader-guard -Wsometimes-uninitialized -Wcomma -Wmissing-variable-declarations -Wassign-enum -Wextra-semi-stmt -Wimplicit-fallthrough -O3 -DNDEBUG  src/CMakeFiles/curl.dir/Unity/unity_0_c.c.obj src/CMakeFiles/curl.dir/curl.rc.res -o src/curl.exe -Wl,--out-implib,src/libcurl.dll.a -Wl,--major-image-version,0,--minor-image-version,0  -municode  lib/libcurl.a  /build/install/x86_64-w64-mingw32/lib/libcares.a  -lws2_32  -lbcrypt  /build/install/x86_64-w64-mingw32/lib/libssl.a  /build/install/x86_64-w64-mingw32/lib/libcrypto.a  /build/install/x86_64-w64-mingw32/lib/libz.a  /build/install/x86_64-w64-mingw32/lib/libbrotlidec.a  /build/install/x86_64-w64-mingw32/lib/libbrotlicommon.a  /build/install/x86_64-w64-mingw32/lib/libzstd.a  /build/install/x86_64-w64-mingw32/lib/libnghttp2.a  /build/install/x86_64-w64-mingw32/lib/libnghttp3.a  -lwldap32  -lnormaliz  /build/install/x86_64-w64-mingw32/lib/libpsl.a  /build/install/x86_64-w64-mingw32/lib/libssh.a  /build/install/x86_64-w64-mingw32/lib/libwsock32.a  /build/install/x86_64-w64-mingw32/lib/libiphlpapi.a  /build/install/x86_64-w64-mingw32/lib/libpthread.a  /build/install/x86_64-w64-mingw32/lib/libssl.a  /build/install/x86_64-w64-mingw32/lib/libcrypto.a  /build/install/x86_64-w64-mingw32/lib/libz.a  /build/install/x86_64-w64-mingw32/lib/libbrotlienc.a  /build/install/x86_64-w64-mingw32/lib/libbrotlidec.a  /build/install/x86_64-w64-mingw32/lib/libbrotlicommon.a  /build/install/x86_64-w64-mingw32/lib/libm.a  /build/install/x86_64-w64-mingw32/lib/libzstd.a  /build/install/x86_64-w64-mingw32/lib/libws2_32.a  /build/install/x86_64-w64-mingw32/lib/libgdi32.a  /build/install/x86_64-w64-mingw32/lib/libcrypt32.a  -liphlpapi  -ladvapi32  -lcrypt32  /build/install/x86_64-w64-mingw32/lib/libbrotlidec.a  /build/install/x86_64-w64-mingw32/lib/libbrotlicommon.a  /build/install/x86_64-w64-mingw32/lib/libnghttp2.a  /build/install/x86_64-w64-mingw32/lib/libnghttp3.a  -lwldap32  -lnormaliz  /build/install/x86_64-w64-mingw32/lib/libpsl.a  /build/install/x86_64-w64-mingw32/lib/libssh.a  /build/install/x86_64-w64-mingw32/lib/libwsock32.a  /build/install/x86_64-w64-mingw32/lib/libiphlpapi.a  /build/install/x86_64-w64-mingw32/lib/libpthread.a  /build/install/x86_64-w64-mingw32/lib/libssl.a  /build/install/x86_64-w64-mingw32/lib/libcrypto.a  /build/install/x86_64-w64-mingw32/lib/libz.a  /build/install/x86_64-w64-mingw32/lib/libbrotlienc.a  /build/install/x86_64-w64-mingw32/lib/libm.a  /build/install/x86_64-w64-mingw32/lib/libws2_32.a  /build/install/x86_64-w64-mingw32/lib/libgdi32.a  /build/install/x86_64-w64-mingw32/lib/libcrypt32.a  -liphlpapi  -ladvapi32  -lcrypt32  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && :
ld.lld: error: undefined symbol: __declspec(dllimport) ssh_init
>>> referenced by /build/packages/curl-prefix/src/curl-build/lib/CMakeFiles/libcurl_object.dir/Unity/unity_0_c.c
>>>               libcurl.a(unity_0_c.c.obj)

ld.lld: error: undefined symbol: __declspec(dllimport) ssh_finalize
>>> referenced by /build/packages/curl-prefix/src/curl-build/lib/CMakeFiles/libcurl_object.dir/Unity/unity_0_c.c
>>>               libcurl.a(unity_0_c.c.obj)

ld.lld: error: undefined symbol: __declspec(dllimport) ssh_version
>>> referenced by /build/packages/curl-prefix/src/curl-build/lib/CMakeFiles/libcurl_object.dir/Unity/unity_0_c.c
>>>               libcurl.a(unity_0_c.c.obj)

ld.lld: error: undefined symbol: __declspec(dllimport) ssh_set_blocking
>>> referenced by /build/packages/curl-prefix/src/curl-build/lib/CMakeFiles/libcurl_object.dir/Unity/unity_0_c.c
>>>               libcurl.a(unity_0_c.c.obj)

ld.lld: error: undefined symbol: __declspec(dllimport) ssh_connect
>>> referenced by /build/packages/curl-prefix/src/curl-build/lib/CMakeFiles/libcurl_object.dir/Unity/unity_0_c.c
>>>               libcurl.a(unity_0_c.c.obj)

ld.lld: error: undefined symbol: __declspec(dllimport) ssh_userauth_none
>>> referenced by /build/packages/curl-prefix/src/curl-build/lib/CMakeFiles/libcurl_object.dir/Unity/unity_0_c.c
>>>               libcurl.a(unity_0_c.c.obj)

ld.lld: error: undefined symbol: __declspec(dllimport) ssh_userauth_list
>>> referenced by /build/packages/curl-prefix/src/curl-build/lib/CMakeFiles/libcurl_object.dir/Unity/unity_0_c.c
>>>               libcurl.a(unity_0_c.c.obj)

ld.lld: error: undefined symbol: __declspec(dllimport) ssh_userauth_try_publickey
>>> referenced by /build/packages/curl-prefix/src/curl-build/lib/CMakeFiles/libcurl_object.dir/Unity/unity_0_c.c
>>>               libcurl.a(unity_0_c.c.obj)

ld.lld: error: undefined symbol: __declspec(dllimport) ssh_pki_import_privkey_file
>>> referenced by /build/packages/curl-prefix/src/curl-build/lib/CMakeFiles/libcurl_object.dir/Unity/unity_0_c.c
>>>               libcurl.a(unity_0_c.c.obj)

ld.lld: error: undefined symbol: __declspec(dllimport) ssh_userauth_publickey_auto
>>> referenced by /build/packages/curl-prefix/src/curl-build/lib/CMakeFiles/libcurl_object.dir/Unity/unity_0_c.c
>>>               libcurl.a(unity_0_c.c.obj)

ld.lld: error: undefined symbol: __declspec(dllimport) ssh_userauth_publickey
>>> referenced by /build/packages/curl-prefix/src/curl-build/lib/CMakeFiles/libcurl_object.dir/Unity/unity_0_c.c
>>>               libcurl.a(unity_0_c.c.obj)

ld.lld: error: undefined symbol: __declspec(dllimport) ssh_userauth_gssapi
>>> referenced by /build/packages/curl-prefix/src/curl-build/lib/CMakeFiles/libcurl_object.dir/Unity/unity_0_c.c
>>>               libcurl.a(unity_0_c.c.obj)

ld.lld: error: undefined symbol: __declspec(dllimport) ssh_userauth_password
>>> referenced by /build/packages/curl-prefix/src/curl-build/lib/CMakeFiles/libcurl_object.dir/Unity/unity_0_c.c
>>>               libcurl.a(unity_0_c.c.obj)

ld.lld: error: undefined symbol: __declspec(dllimport) sftp_new
>>> referenced by /build/packages/curl-prefix/src/curl-build/lib/CMakeFiles/libcurl_object.dir/Unity/unity_0_c.c
>>>               libcurl.a(unity_0_c.c.obj)

ld.lld: error: undefined symbol: __declspec(dllimport) ssh_get_error
>>> referenced by /build/packages/curl-prefix/src/curl-build/lib/CMakeFiles/libcurl_object.dir/Unity/unity_0_c.c
>>>               libcurl.a(unity_0_c.c.obj)

ld.lld: error: undefined symbol: __declspec(dllimport) sftp_init
>>> referenced by /build/packages/curl-prefix/src/curl-build/lib/CMakeFiles/libcurl_object.dir/Unity/unity_0_c.c
>>>               libcurl.a(unity_0_c.c.obj)

ld.lld: error: undefined symbol: __declspec(dllimport) sftp_canonicalize_path
>>> referenced by /build/packages/curl-prefix/src/curl-build/lib/CMakeFiles/libcurl_object.dir/Unity/unity_0_c.c
>>>               libcurl.a(unity_0_c.c.obj)

ld.lld: error: undefined symbol: __declspec(dllimport) sftp_setstat
>>> referenced by /build/packages/curl-prefix/src/curl-build/lib/CMakeFiles/libcurl_object.dir/Unity/unity_0_c.c
>>>               libcurl.a(unity_0_c.c.obj)

ld.lld: error: undefined symbol: __declspec(dllimport) sftp_symlink
>>> referenced by /build/packages/curl-prefix/src/curl-build/lib/CMakeFiles/libcurl_object.dir/Unity/unity_0_c.c
>>>               libcurl.a(unity_0_c.c.obj)

ld.lld: error: undefined symbol: __declspec(dllimport) sftp_mkdir
>>> referenced by /build/packages/curl-prefix/src/curl-build/lib/CMakeFiles/libcurl_object.dir/Unity/unity_0_c.c
>>>               libcurl.a(unity_0_c.c.obj)

curl/libcurl version

master

operating system

linux

@bagder bagder added the cmake label Aug 22, 2024
@vszakats
Copy link
Member

vszakats commented Aug 22, 2024

Yeah, the Find modules (including those with not-only-hint support for pkg-config, like libssh), don't process the whole information pkg-config is returning, yet.

FindGSS is the only one which does.

Something to be implemented.

@vszakats
Copy link
Member

@Andarwinux Can you make a test if this patch improves things for you?:

--- a/CMake/FindLibssh.cmake
+++ b/CMake/FindLibssh.cmake
@@ -33,6 +33,8 @@
 # LIBSSH_FOUND         System has libssh
 # LIBSSH_INCLUDE_DIRS  The libssh include directories
 # LIBSSH_LIBRARIES     The libssh library names
+# LIBSSH_LIBRARY_DIRS  The libssh library directories
+# LIBSSH_CFLAGS        Required compiler flags
 # LIBSSH_VERSION       Version of libssh
 
 if(CURL_USE_PKGCONFIG AND
@@ -43,10 +45,7 @@ if(CURL_USE_PKGCONFIG AND
 endif()
 
 if(LIBSSH_FOUND)
-  if(NOT DEFINED LIBSSH_LINK_LIBRARIES)
-    set(LIBSSH_LINK_LIBRARIES ${LIBSSH_LIBRARIES})  # Workaround for some systems (seen on Old Linux CI)
-  endif()
-  set(LIBSSH_LIBRARIES ${LIBSSH_LINK_LIBRARIES})
+  string(REPLACE ";" " " LIBSSH_CFLAGS "${LIBSSH_CFLAGS}")
   message(STATUS "Found Libssh (via pkg-config): ${LIBSSH_INCLUDE_DIRS} (Found version \"${LIBSSH_VERSION}\")")
 else()
   find_path(LIBSSH_INCLUDE_DIR NAMES "libssh/libssh.h")
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1071,6 +1071,10 @@ if(NOT USE_LIBSSH2 AND CURL_USE_LIBSSH)
     list(APPEND CURL_LIBS ${LIBSSH_LIBRARIES})
     list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "libssh")
     include_directories(${LIBSSH_INCLUDE_DIRS})
+    link_directories(${LIBSSH_LIBRARY_DIRS})
+    if(LIBSSH_CFLAGS)
+      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${LIBSSH_CFLAGS}")
+    endif()
     set(USE_LIBSSH ON)
   endif()
 endif()

@Andarwinux
Copy link
Author

Yeah, that fixes the build.

@vszakats
Copy link
Member

I'll make this a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

3 participants