mirror of
https://github.com/microsoft/vcpkg.git
synced 2024-11-27 23:59:08 +08:00
[vcpkg_configure_make] Fix handling of link flags (#22798)
* [vcpkg_build_make] only link against manual-link folder if exists * [vcpkg_configure_make] don't set LD_LIBRARY_PATH This is not recommended during the normal build process https://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html * [vcpkg_build_make] Only set the lib path if exists * [vcpkg_configure_make] Resore handling of _LINK_ environment variable * [vcpkg_build_make] Backup and restore CPPFLAGS CFLAGS CXXFLAGS RCFLAGS * [vcpkg_build_make] Fix name of LINKER FLAGS detected from cmake * [vcpkg_build_make] replace obolete _VAR_SUFFIX with cmake_buildtype
This commit is contained in:
parent
a116481681
commit
016788b220
@ -121,7 +121,7 @@ function(vcpkg_build_make)
|
||||
endif()
|
||||
|
||||
# Since includes are buildtype independent those are setup by vcpkg_configure_make
|
||||
vcpkg_backup_env_variables(VARS LIB LIBPATH LIBRARY_PATH LD_LIBRARY_PATH)
|
||||
vcpkg_backup_env_variables(VARS LIB LIBPATH LIBRARY_PATH LD_LIBRARY_PATH CPPFLAGS CFLAGS CXXFLAGS RCFLAGS)
|
||||
|
||||
foreach(buildtype IN ITEMS "debug" "release")
|
||||
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "${buildtype}")
|
||||
@ -142,15 +142,21 @@ function(vcpkg_build_make)
|
||||
z_vcpkg_extract_cpp_flags_and_set_cflags_and_cxxflags("${cmake_buildtype}")
|
||||
|
||||
if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
|
||||
set(LINKER_FLAGS_${cmake_buildtype} "${VCPKG_DETECTED_STATIC_LINKER_FLAGS_${cmake_buildtype}}")
|
||||
set(LINKER_FLAGS_${cmake_buildtype} "${VCPKG_DETECTED_CMAKE_STATIC_LINKER_FLAGS_${cmake_buildtype}}")
|
||||
else() # dynamic
|
||||
set(LINKER_FLAGS_${cmake_buildtype} "${VCPKG_DETECTED_SHARED_LINKER_FLAGS_${cmake_buildtype}}")
|
||||
set(LINKER_FLAGS_${cmake_buildtype} "${VCPKG_DETECTED_CMAKE_SHARED_LINKER_FLAGS_${cmake_buildtype}}")
|
||||
endif()
|
||||
set(LDFLAGS_${cmake_buildtype} "")
|
||||
if(EXISTS "${Z_VCPKG_INSTALLED}${path_suffix}/lib")
|
||||
string(APPEND LDFLAGS_${cmake_buildtype} " -L${Z_VCPKG_INSTALLED}${path_suffix}/lib")
|
||||
endif()
|
||||
if(EXISTS "${Z_VCPKG_INSTALLED}${path_suffix}/lib/manual-link")
|
||||
string(APPEND LDFLAGS_${cmake_buildtype} " -L${Z_VCPKG_INSTALLED}${path_suffix}/lib/manual-link")
|
||||
endif()
|
||||
if (CMAKE_HOST_WIN32 AND VCPKG_DETECTED_CMAKE_C_COMPILER MATCHES "cl.exe")
|
||||
set(LDFLAGS_${cmake_buildtype} "-L${Z_VCPKG_INSTALLED}${path_suffix}/lib -L${Z_VCPKG_INSTALLED}${path_suffix}/lib/manual-link")
|
||||
set(LINK_ENV_${cmake_buildtype} "$ENV{_LINK_} ${LINKER_FLAGS_${cmake_buildtype}}")
|
||||
else()
|
||||
set(LDFLAGS_${cmake_buildtype} "-L${Z_VCPKG_INSTALLED}${path_suffix}/lib -L${Z_VCPKG_INSTALLED}${path_suffix}/lib/manual-link ${LINKER_FLAGS_${cmake_buildtype}}")
|
||||
string(APPEND LDFLAGS_${cmake_buildtype} " ${LINKER_FLAGS_${cmake_buildtype}}")
|
||||
endif()
|
||||
|
||||
# Setup environment
|
||||
@ -159,14 +165,20 @@ function(vcpkg_build_make)
|
||||
set(ENV{CXXFLAGS} "${CXXFLAGS_${cmake_buildtype}}")
|
||||
set(ENV{RCFLAGS} "${VCPKG_DETECTED_CMAKE_RC_FLAGS_${cmake_buildtype}}")
|
||||
set(ENV{LDFLAGS} "${LDFLAGS_${cmake_buildtype}}")
|
||||
vcpkg_host_path_list(PREPEND ENV{LIB} "${Z_VCPKG_INSTALLED}${path_suffix}/lib/" "${Z_VCPKG_INSTALLED}${path_suffix}/lib/manual-link/")
|
||||
vcpkg_host_path_list(PREPEND ENV{LIBPATH} "${Z_VCPKG_INSTALLED}${path_suffix}/lib/" "${Z_VCPKG_INSTALLED}${path_suffix}/lib/manual-link/")
|
||||
vcpkg_host_path_list(PREPEND ENV{LIBRARY_PATH} "${Z_VCPKG_INSTALLED}${path_suffix_${buildtype}}/lib/" "${Z_VCPKG_INSTALLED}${path_suffix}/lib/manual-link/")
|
||||
#vcpkg_host_path_list(PREPEND ENV{LD_LIBRARY_PATH} "${Z_VCPKG_INSTALLED}${path_suffix}/lib/" "${Z_VCPKG_INSTALLED}${path_suffix_${buildtype}}/lib/manual-link/")
|
||||
vcpkg_list(APPEND lib_env_vars LIB LIBPATH LIBRARY_PATH) # LD_LIBRARY_PATH)
|
||||
foreach(lib_env_var IN LISTS lib_env_vars)
|
||||
if(EXISTS "${Z_VCPKG_INSTALLED}${path_suffix}/lib")
|
||||
vcpkg_host_path_list(PREPEND ENV{${lib_env_var}} "${Z_VCPKG_INSTALLED}${path_suffix}/lib")
|
||||
endif()
|
||||
if(EXISTS "${Z_VCPKG_INSTALLED}${path_suffix}/lib/manual-link")
|
||||
vcpkg_host_path_list(PREPEND ENV{${lib_env_var}} "${Z_VCPKG_INSTALLED}${path_suffix}/lib/manual-link")
|
||||
endif()
|
||||
endforeach()
|
||||
unset(lib_env_vars)
|
||||
|
||||
if(LINK_ENV_${_VAR_SUFFIX})
|
||||
if(LINK_ENV_${cmake_buildtype})
|
||||
set(config_link_backup "$ENV{_LINK_}")
|
||||
set(ENV{_LINK_} "${LINK_ENV_${_VAR_SUFFIX}}")
|
||||
set(ENV{_LINK_} "${LINK_ENV_${cmake_buildtype}}")
|
||||
endif()
|
||||
|
||||
if(arg_ADD_BIN_TO_PATH)
|
||||
@ -238,5 +250,5 @@ function(vcpkg_build_make)
|
||||
set(ENV{PATH} "${path_backup}")
|
||||
endif()
|
||||
|
||||
vcpkg_restore_env_variables(VARS LIB LIBPATH LIBRARY_PATH LD_LIBRARY_PATH)
|
||||
vcpkg_restore_env_variables(VARS LIB LIBPATH LIBRARY_PATH LD_LIBRARY_PATH CPPFLAGS CFLAGS CXXFLAGS RCFLAGS)
|
||||
endfunction()
|
||||
|
@ -788,13 +788,13 @@ function(vcpkg_configure_make)
|
||||
endif()
|
||||
set(ENV{PKG_CONFIG} "${PKGCONFIG}")
|
||||
|
||||
vcpkg_list(APPEND lib_env_vars LIB LIBPATH LIBRARY_PATH LD_LIBRARY_PATH)
|
||||
vcpkg_list(APPEND lib_env_vars LIB LIBPATH LIBRARY_PATH) # LD_LIBRARY_PATH)
|
||||
foreach(lib_env_var IN LISTS lib_env_vars)
|
||||
if(EXISTS "${CURRENT_INSTALLED_DIR}${path_suffix_${current_buildtype}}/lib")
|
||||
vcpkg_host_path_list(PREPEND ENV{${lib_env_var}} "${CURRENT_INSTALLED_DIR}${path_suffix_${current_buildtype}}/lib")
|
||||
endif()
|
||||
if(EXISTS "${CURRENT_INSTALLED_DIR}${path_suffix_${current_buildtype}}/lib/manual-link")
|
||||
vcpkg_host_path_list(PREPEND ENV{${lib_env_var}} "${CURRENT_INSTALLED_DIR}" "${path_suffix_${current_buildtype}}/lib/manual-link")
|
||||
vcpkg_host_path_list(PREPEND ENV{${lib_env_var}} "${CURRENT_INSTALLED_DIR}${path_suffix_${current_buildtype}}/lib/manual-link")
|
||||
endif()
|
||||
endforeach()
|
||||
unset(lib_env_vars)
|
||||
|
Loading…
Reference in New Issue
Block a user