From: Viktor Szakats Date: Mon, 11 Nov 2024 10:03:08 +0000 (+0100) Subject: cmake: sync GSS config code with other deps X-Git-Tag: curl-8_11_1~79 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e0e93d43146cd0832d387c82570df58ffdcd2cfb;p=thirdparty%2Fcurl.git cmake: sync GSS config code with other deps - stop passing explicit libpaths via `CMAKE_SHARED_LINKER_FLAGS` and `CMAKE_EXE_LINKER_FLAGS`. `link_directories()` is doing that already. - use `curl_required_libpaths()` to pass libpaths to the feature test. Reported-by: Daniel Engberg Fixes #15536 Also fixes GSS feature detection with non-gcc/clang compilers, such as MSVC. - add libpaths to `CURL_LIBPATHS`. - move `GSS_CFLAGS`, `GSS_LDFLAGS` stringifications to FindGSS. To match the `CFLAGS` format returned by the rest of Find modules. - reorder calls to match other dependencies. - don't extend system `LDFLAGS` when FindGSS did not return any. - ignore `LDFLAGS` when detecting GSS via `pkg-config`. `LDFLAGS` holds a copy of libpaths and libs in this case. Ignore those to avoid these duplicates making into `libcurl.pc` and `curl-config`. Also syncing behavior with other Find modules which also ignore raw `LDFLAGS`. - ignore raw `LDFLAGS` coming from `krb5-config --libs`. FindGSS no longer returns dependency-specific `LDFLAGS` after this. Syncing behavior with other Find modules. - reduce scope of checker state push/pop/set. Closes #15545 --- diff --git a/CMake/FindGSS.cmake b/CMake/FindGSS.cmake index 2224f27ae2..2dfc9ff4db 100644 --- a/CMake/FindGSS.cmake +++ b/CMake/FindGSS.cmake @@ -34,7 +34,6 @@ # - `GSS_INCLUDE_DIRS`: The GSS include directories. # - `GSS_LIBRARIES`: The GSS library names. # - `GSS_LIBRARY_DIRS`: The GSS library directories. -# - `GSS_LDFLAGS`: Required linker flags. # - `GSS_CFLAGS`: Required compiler flags. # - `GSS_VERSION`: This is set to version advertised by pkg-config or read from manifest. # In case the library is found but no version info available it is set to "unknown" @@ -91,7 +90,7 @@ if(NOT _GSS_FOUND) # Not found by pkg-config. Let us take more traditional appr RESULT_VARIABLE _gss_configure_failed OUTPUT_STRIP_TRAILING_WHITESPACE ) - message(STATUS "FindGSS CFLAGS: ${_GSS_CFLAGS}") + message(STATUS "FindGSS krb5-config --cflags: ${_GSS_CFLAGS}") if(NOT _gss_configure_failed) # 0 means success # Should also work in an odd case when multiple directories are given string(STRIP "${_GSS_CFLAGS}" _GSS_CFLAGS) @@ -114,7 +113,7 @@ if(NOT _GSS_FOUND) # Not found by pkg-config. Let us take more traditional appr RESULT_VARIABLE _gss_configure_failed OUTPUT_STRIP_TRAILING_WHITESPACE ) - message(STATUS "FindGSS LDFLAGS: ${_gss_lib_flags}") + message(STATUS "FindGSS krb5-config --libs: ${_gss_lib_flags}") if(NOT _gss_configure_failed) # 0 means success # This script gives us libraries and link directories. Blah. We have to deal with it. @@ -129,8 +128,6 @@ if(NOT _GSS_FOUND) # Not found by pkg-config. Let us take more traditional appr elseif(_flag MATCHES "^-L.*") string(REGEX REPLACE "^-L" "" _val "${_flag}") list(APPEND _GSS_LIBRARY_DIRS "${_val}") - else() - list(APPEND _GSS_LDFLAGS "${_flag}") endif() endforeach() endif() @@ -286,10 +283,11 @@ else() message(STATUS "Found GSS/${GSS_FLAVOUR} (via pkg-config): ${_GSS_INCLUDE_DIRS} (found version \"${_GSS_VERSION}\")") endif() +string(REPLACE ";" " " _GSS_CFLAGS "${_GSS_CFLAGS}") + set(GSS_INCLUDE_DIRS ${_GSS_INCLUDE_DIRS}) set(GSS_LIBRARIES ${_GSS_LIBRARIES}) set(GSS_LIBRARY_DIRS ${_GSS_LIBRARY_DIRS}) -set(GSS_LDFLAGS ${_GSS_LDFLAGS}) set(GSS_CFLAGS ${_GSS_CFLAGS}) set(GSS_VERSION ${_GSS_VERSION}) @@ -346,7 +344,6 @@ mark_as_advanced( _GSS_CFLAGS _GSS_FOUND _GSS_INCLUDE_DIRS - _GSS_LDFLAGS _GSS_LIBRARIES _GSS_LIBRARY_DIRS _GSS_MODULE_NAME diff --git a/CMakeLists.txt b/CMakeLists.txt index aece9eac8e..fc44cca2db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1210,17 +1210,12 @@ if(CURL_USE_GSSAPI) set(HAVE_GSSAPI ${GSS_FOUND}) if(GSS_FOUND) - cmake_push_check_state() - list(APPEND CMAKE_REQUIRED_INCLUDES ${GSS_INCLUDE_DIRS}) - - string(REPLACE ";" " " GSS_CFLAGS "${GSS_CFLAGS}") - string(REPLACE ";" " " GSS_LDFLAGS "${GSS_LDFLAGS}") - - foreach(_dir IN LISTS GSS_LIBRARY_DIRS) - set(GSS_LDFLAGS "${GSS_LDFLAGS} -L\"${_dir}\"") - endforeach() + if(GSS_FLAVOUR STREQUAL "GNU") + set(HAVE_GSSGNU 1) + else() + cmake_push_check_state() + list(APPEND CMAKE_REQUIRED_INCLUDES ${GSS_INCLUDE_DIRS}) - if(NOT GSS_FLAVOUR STREQUAL "GNU") set(_include_list "") check_include_file("gssapi/gssapi.h" HAVE_GSSAPI_GSSAPI_H) if(HAVE_GSSAPI_GSSAPI_H) @@ -1238,8 +1233,9 @@ if(CURL_USE_GSSAPI) endif() if(NOT DEFINED HAVE_GSS_C_NT_HOSTBASED_SERVICE) - set(CMAKE_REQUIRED_FLAGS "${GSS_CFLAGS} ${GSS_LDFLAGS}") + set(CMAKE_REQUIRED_FLAGS ${GSS_CFLAGS}) set(CMAKE_REQUIRED_LIBRARIES ${GSS_LIBRARIES}) + curl_required_libpaths("${GSS_LIBRARY_DIRS}") check_symbol_exists("GSS_C_NT_HOSTBASED_SERVICE" "${_include_list}" HAVE_GSS_C_NT_HOSTBASED_SERVICE) endif() if(NOT HAVE_GSS_C_NT_HOSTBASED_SERVICE) @@ -1247,23 +1243,23 @@ if(CURL_USE_GSSAPI) endif() endif() unset(_include_list) + cmake_pop_check_state() endif() - cmake_pop_check_state() - include_directories(SYSTEM ${GSS_INCLUDE_DIRS}) - link_directories(${GSS_LIBRARY_DIRS}) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GSS_CFLAGS}") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${GSS_LDFLAGS}") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GSS_LDFLAGS}") list(APPEND CURL_LIBS ${GSS_LIBRARIES}) + list(APPEND CURL_LIBDIRS ${GSS_LIBRARY_DIRS}) if(GSS_FLAVOUR STREQUAL "GNU") - set(HAVE_GSSGNU 1) list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "gss") elseif(GSS_FLAVOUR STREQUAL "MIT") list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "mit-krb5-gssapi") else() # Heimdal list(APPEND LIBCURL_PC_REQUIRES_PRIVATE "heimdal-gssapi") endif() + include_directories(SYSTEM ${GSS_INCLUDE_DIRS}) + link_directories(${GSS_LIBRARY_DIRS}) + if(GSS_CFLAGS) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GSS_CFLAGS}") + endif() else() message(WARNING "GSSAPI has been requested, but no supporting libraries found. Skipping.") endif()