From 32157f8ce5abdca2f25981064006906cd1cce5e5 Mon Sep 17 00:00:00 2001 From: Robert Schumacher Date: Fri, 25 Nov 2016 23:10:27 -0800 Subject: [PATCH] [vcpkg-integrate] Provide an opt-out for autolinking. Properly suppress integration via MSBuild when using CMake. Add lib\ and lib\manual-link\ to additional library paths. [gtest] Because the four libraries provided by gtest supply redundant symbols and define main, opt them all out. Addresses #306. --- ports/gtest/portfile.cmake | 13 +++++++-- scripts/buildsystems/msbuild/vcpkg.targets | 8 ++++-- scripts/buildsystems/vcpkg.cmake | 32 ++++++++++++++++------ 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/ports/gtest/portfile.cmake b/ports/gtest/portfile.cmake index e1d601d7bd..d1ba722d7a 100644 --- a/ports/gtest/portfile.cmake +++ b/ports/gtest/portfile.cmake @@ -37,8 +37,6 @@ message(STATUS "Adding worktree and patching done") vcpkg_configure_cmake( SOURCE_PATH ${CURRENT_BUILDTREES_DIR}/src - OPTIONS - -DBUILD_SHARED_LIBS=ON ) vcpkg_install_cmake() @@ -55,4 +53,15 @@ file(RENAME ${CURRENT_PACKAGES_DIR}/debug/lib/gtest_main.dll ${CURRENT_PACKAGES_ file(RENAME ${CURRENT_PACKAGES_DIR}/debug/lib/gmock.dll ${CURRENT_PACKAGES_DIR}/debug/bin/gmock.dll) file(RENAME ${CURRENT_PACKAGES_DIR}/debug/lib/gmock_main.dll ${CURRENT_PACKAGES_DIR}/debug/bin/gmock_main.dll) +file(MAKE_DIRECTORY ${CURRENT_PACKAGES_DIR}/lib/manual-link) +file(RENAME ${CURRENT_PACKAGES_DIR}/lib/gtest.lib ${CURRENT_PACKAGES_DIR}/lib/manual-link/gtest.lib) +file(RENAME ${CURRENT_PACKAGES_DIR}/lib/gtest_main.lib ${CURRENT_PACKAGES_DIR}/lib/manual-link/gtest_main.lib) +file(RENAME ${CURRENT_PACKAGES_DIR}/lib/gmock.lib ${CURRENT_PACKAGES_DIR}/lib/manual-link/gmock.lib) +file(RENAME ${CURRENT_PACKAGES_DIR}/lib/gmock_main.lib ${CURRENT_PACKAGES_DIR}/lib/manual-link/gmock_main.lib) +file(MAKE_DIRECTORY ${CURRENT_PACKAGES_DIR}/debug/lib/manual-link) +file(RENAME ${CURRENT_PACKAGES_DIR}/debug/lib/gtest.lib ${CURRENT_PACKAGES_DIR}/debug/lib/manual-link/gtest.lib) +file(RENAME ${CURRENT_PACKAGES_DIR}/debug/lib/gtest_main.lib ${CURRENT_PACKAGES_DIR}/debug/lib/manual-link/gtest_main.lib) +file(RENAME ${CURRENT_PACKAGES_DIR}/debug/lib/gmock.lib ${CURRENT_PACKAGES_DIR}/debug/lib/manual-link/gmock.lib) +file(RENAME ${CURRENT_PACKAGES_DIR}/debug/lib/gmock_main.lib ${CURRENT_PACKAGES_DIR}/debug/lib/manual-link/gmock_main.lib) + vcpkg_copy_pdbs() diff --git a/scripts/buildsystems/msbuild/vcpkg.targets b/scripts/buildsystems/msbuild/vcpkg.targets index 18c4e9d9f3..7782551c2c 100644 --- a/scripts/buildsystems/msbuild/vcpkg.targets +++ b/scripts/buildsystems/msbuild/vcpkg.targets @@ -31,11 +31,13 @@ - $(VcpkgRoot)debug\lib\*.lib;%(AdditionalDependencies) - $(VcpkgRoot)lib\*.lib;%(AdditionalDependencies) + %(AdditionalDependencies);$(VcpkgRoot)debug\lib\*.lib + %(AdditionalDependencies);$(VcpkgRoot)lib\*.lib + %(AdditionalLibraryDirectories);$(VcpkgRoot)lib;$(VcpkgRoot)lib\manual-link + %(AdditionalLibraryDirectories);$(VcpkgRoot)debug\lib;$(VcpkgRoot)debug\lib\manual-link - $(VcpkgRoot)include;%(AdditionalIncludeDirectories) + %(AdditionalIncludeDirectories);$(VcpkgRoot)include diff --git a/scripts/buildsystems/vcpkg.cmake b/scripts/buildsystems/vcpkg.cmake index 54960a138f..c77aca52d7 100644 --- a/scripts/buildsystems/vcpkg.cmake +++ b/scripts/buildsystems/vcpkg.cmake @@ -46,21 +46,27 @@ if(NOT VCPKG_TOOLCHAIN) list(APPEND CMAKE_PREFIX_PATH ${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug ) + list(APPEND CMAKE_LIBRARY_PATH + ${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug/lib/manual-link + ) endif() list(APPEND CMAKE_PREFIX_PATH ${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET} ) + list(APPEND CMAKE_LIBRARY_PATH + ${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/manual-link + ) include_directories(${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include) set(CMAKE_PROGRAM_PATH ${CMAKE_PROGRAM_PATH} ${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/tools) - option(OVERRIDE_ADD_EXECUTABLE "Automatically copy dependencies into the output directory for executables." ON) - if(OVERRIDE_ADD_EXECUTABLE) - function(add_executable name) - _add_executable(${ARGV}) - list(FIND ARGV "IMPORTED" IMPORTED_IDX) - if(IMPORTED_IDX EQUAL -1) + option(VCPKG_APPLOCAL_DEPS "Automatically copy dependencies into the output directory for executables." ON) + function(add_executable name) + _add_executable(${ARGV}) + list(FIND ARGV "IMPORTED" IMPORTED_IDX) + if(IMPORTED_IDX EQUAL -1) + if(VCPKG_APPLOCAL_DEPS) add_custom_command(TARGET ${name} POST_BUILD COMMAND powershell -noprofile -executionpolicy UnRestricted -file ${_VCPKG_TOOLCHAIN_DIR}/msbuild/applocal.ps1 -targetBinary $ @@ -68,7 +74,17 @@ if(NOT VCPKG_TOOLCHAIN) -OutVariable out ) endif() - endfunction() - endif() + set_target_properties(${name} PROPERTIES VS_GLOBAL_VcpkgEnabled false) + endif() + endfunction() + + function(add_library name) + _add_library(${ARGV}) + list(FIND ARGV "IMPORTED" IMPORTED_IDX) + if(IMPORTED_IDX EQUAL -1) + set_target_properties(${name} PROPERTIES VS_GLOBAL_VcpkgEnabled false) + endif() + endfunction() + set(VCPKG_TOOLCHAIN ON) endif()