vcpkg/ports/folly/portfile.cmake
2019-05-21 21:00:24 -07:00

98 lines
3.3 KiB
CMake

include(vcpkg_common_functions)
if(NOT VCPKG_TARGET_ARCHITECTURE STREQUAL x64)
message(FATAL_ERROR "Folly only supports the x64 architecture.")
endif()
vcpkg_check_linkage(ONLY_STATIC_LIBRARY)
# Required to run build/generate_escape_tables.py et al.
vcpkg_find_acquire_program(PYTHON3)
get_filename_component(PYTHON3_DIR "${PYTHON3}" DIRECTORY)
vcpkg_add_to_path("${PYTHON3_DIR}")
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO facebook/folly
REF v2019.05.13.00
SHA512 5dfeef0c2845b15e32a29119921d65e349a7ae9bcfa25c406d42d8df1614d2542153cd0ad8d0cf22592045b24272375a7839af91579d6be685cb8a3512586689
HEAD_REF master
PATCHES
missing-include-atomic.patch
boost-1.70.patch
reorder-glog-gflags.patch
)
file(COPY
${CMAKE_CURRENT_LIST_DIR}/FindLZ4.cmake
${CMAKE_CURRENT_LIST_DIR}/FindSnappy.cmake
DESTINATION ${SOURCE_PATH}/CMake/
)
file(REMOVE ${SOURCE_PATH}/CMake/FindGFlags.cmake)
if(VCPKG_CRT_LINKAGE STREQUAL static)
set(MSVC_USE_STATIC_RUNTIME ON)
else()
set(MSVC_USE_STATIC_RUNTIME OFF)
endif()
set(FEATURE_OPTIONS)
macro(feature FEATURENAME PACKAGENAME)
if("${FEATURENAME}" IN_LIST FEATURES)
list(APPEND FEATURE_OPTIONS -DCMAKE_DISABLE_FIND_PACKAGE_${PACKAGENAME}=OFF)
else()
list(APPEND FEATURE_OPTIONS -DCMAKE_DISABLE_FIND_PACKAGE_${PACKAGENAME}=ON)
endif()
endmacro()
feature(zlib ZLIB)
feature(bzip2 BZip2)
feature(lzma LibLZMA)
feature(lz4 LZ4)
feature(zstd Zstd)
feature(snappy Snappy)
vcpkg_configure_cmake(
SOURCE_PATH ${SOURCE_PATH}
PREFER_NINJA
OPTIONS
-DMSVC_USE_STATIC_RUNTIME=${MSVC_USE_STATIC_RUNTIME}
-DCMAKE_DISABLE_FIND_PACKAGE_LibDwarf=ON
-DCMAKE_DISABLE_FIND_PACKAGE_Libiberty=ON
-DCMAKE_DISABLE_FIND_PACKAGE_LibAIO=ON
-DLIBAIO_FOUND=OFF
-DLIBURCU_FOUND=OFF
-DCMAKE_DISABLE_FIND_PACKAGE_LibURCU=ON
-DCMAKE_INSTALL_DIR=share/folly
${FEATURE_OPTIONS}
)
vcpkg_install_cmake(ADD_BIN_TO_PATH)
vcpkg_copy_pdbs()
vcpkg_fixup_cmake_targets(CONFIG_PATH share/folly)
# Release folly-targets.cmake does not link to the right libraries in debug mode.
# We substitute with generator expressions so that the right libraries are linked for debug and release.
set(FOLLY_TARGETS_CMAKE "${CURRENT_PACKAGES_DIR}/share/folly/folly-targets.cmake")
FILE(READ ${FOLLY_TARGETS_CMAKE} _contents)
string(REPLACE "\${_IMPORT_PREFIX}/lib/zlib.lib" "ZLIB::ZLIB" _contents "${_contents}")
STRING(REPLACE "\${_IMPORT_PREFIX}/lib/" "\${_IMPORT_PREFIX}/\$<\$<CONFIG:DEBUG>:debug/>lib/" _contents "${_contents}")
STRING(REPLACE "\${_IMPORT_PREFIX}/debug/lib/" "\${_IMPORT_PREFIX}/\$<\$<CONFIG:DEBUG>:debug/>lib/" _contents "${_contents}")
string(REPLACE "-vc140-mt.lib" "-vc140-mt\$<\$<CONFIG:DEBUG>:-gd>.lib" _contents "${_contents}")
FILE(WRITE ${FOLLY_TARGETS_CMAKE} "${_contents}")
FILE(READ ${CURRENT_PACKAGES_DIR}/share/folly/folly-config.cmake _contents)
FILE(WRITE ${CURRENT_PACKAGES_DIR}/share/folly/folly-config.cmake
"include(CMakeFindDependencyMacro)
find_dependency(Threads)
find_dependency(glog CONFIG)
${_contents}")
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)
# Handle copyright
file(COPY ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/folly)
file(RENAME ${CURRENT_PACKAGES_DIR}/share/folly/LICENSE ${CURRENT_PACKAGES_DIR}/share/folly/copyright)