vcpkg/ports/tensorflow-cc/portfile.cmake
Joachim Gehweiler 11b4a16bca
[tensorflow-cc] More or less completely rewritten port, update to 2.3.1 (#13028)
* fix build issues occurring from default bazel config being used because customized bazel config is stored in wrong directory

* [tensorflow-cc] Update CONTROL and ci.baseline.txt

* fix also applies to windows static build

* fix debug and static builds as well as library naming for non-linux
- add patch to fix debug builds
- add patch to fix exports for static linking
- really build debug (instead of cloning release)
- override bazel build options for debug (work around bazel bug)
- bazel doesn't support static libraries: work around by building dynamic library and constructing static linkage commands from build log
- Windows .pdb file can't be >4GB even on x64: work around using reduced debug information
- Windows doesn't support .lib files >4GB even on x64, so split into multiple libs
- vcpkg requires equal amount of libs for debug and release: work around using handcrafted empty dummy libs
- fix naming of libs (.dll on Windows and .dylib on macOS)

* upgrade tensorflow from v1.14 to v2.3
- adapt patch files to tensorflow code changes
- update bazel from v0.25.2 to v3.1
- on Windows use python installed on the host instead of embedded python obtained via vcpkg because embedded python lacks pip, which we need to obtain numpy
- on Windows add MSYS2 to the PATH so that bazel tools can access MSYS2 GIT
- add support for custom CA certificates when using HTTPS_PROXY

* fix execute process macro
The existing implementation totally screwed up commands if the command's arguments contained semicolons (this is the case, e.g., in the FindPython modules of the cmake distribution).

* extend overriden execute_process to more than one COMMAND as there actually are use cases for this

* added another patch required for tensorflow v2.3, fixed path and working directory

* Revert "incorporate changes from microsoft:master"

* Revert "Revert "incorporate changes from microsoft:master""

* final fixes for static build + improving out messages

* enabling linux and osx in CI to see if it works now

* simplified code, fixed version numbers, fixed generated include cmake file

* fix failing postbuild check on handcrafted empty dummy library by spreading the last real libraries contents over the required number of libraries

* remove dead code commit by mistake again

* improvements from code review

* cleaner fix for debug code

* find pip3 in PATH (PYTHON3_DIR apparently not valid for pip3)

* fix error in python helper script

* fix wrong libname in postbuild script

* fix python detection + switch to python on msys2 (instead of embedded python) for Windows as we need numpy

* fix order of arguments

* fix command (it may contain spaces such as C:\Program Files\...)

* revert last commit (root cause for CI failures is something different: there are line breaks in path)

* fix regex comparision
(value needs to be escaped as it may contains regex special characters such as brackets, eg C:/Program Files (x86)/...)

* fix linebreaks in generated file

* fix CRT linkage
(macOS doesn't support static CRT linkage; it's set to dynamic even static target triplets for macOS and linux)

* refactor implemenation to avoid as much code duplication as possible -- algorithmically identical

* fix version numbers in helper scripts

* enable work-around for Windows until bazel fix is available

* install missing python3-pip on linux

* fix linux build by patching

* apply timeout feature now available via merged master branch

* correct linux build patch

* improve debug build patches
(no functional difference because LOG(FATAL, ...) macro internally anyway calls abort(), which the compiler doesn't detect in debug mode...

* improve linux patch

* temporarily add debug to inspect what's going on on macOS CI

* remove temporary debug code and fix static linking scripts for linux and macOS

* fix regex escaping

* fix ambiguous match while grepping for the framework link command

* extend fix of ambiguous match while grepping for the framework link command

* fix what merge of master broke

* fix more what got broken by merging master
(all packages and their dependencies are now maintained manually instead of using pacman...)

* remove "unofficial" from filename

* added switch do distinct classic and manifest mode when generating config.cmake file

* create symlinks for libraries without version number

* fix linux postbuild script

* temporarily disable code making problems

* add note for linking on Linux and macOS

* forget to add README file in previous commit

* add file forgotton in macro fixing patch

* fix python library path

* fix macOS static link command

* update linkage instructions in README

* Update ports/tensorflow-cc/CONTROL

* Update ports/tensorflow-cc/portfile.cmake

* Update scripts/ci.baseline.txt

* use vcpkg_execute_required_process

* pass C_FLAGS and CXX_FLAGS to bazel

* fix INTERFACE_INCLUDE_DIRECTORIES

* fix optional c/cxx arguments

* also add linker opts

* update README

* merge static libs into one
to support force_load (cannot force_load both due to duplicate symbols)

* update README

* quote python path (it might contain spaces that don't get escaped inside outer quotes of bash command)

* fix python path also for static build

* add arm(64) as currently unsupported arch

* bazel 3.7 is available -> remove workaround

* update README, remove necessary c-ares from deps

* update msys package

* add uwp specific options, and minor general improvements

* fix string replace

* fix control file and windows path separator

* revert backslashes-fix -- the root cause was missing .exe extension

* upgrade to tf 2.3.1

* fix hard-coded version

* remove uwp work-in-progress code so that PR can be merged

* update README and print out usage info in portfile

* Update ports/tensorflow-cc/README-linux

Co-authored-by: nicole mazzuca <mazzucan@outlook.com>

* Update ports/tensorflow-cc/README-linux

Co-authored-by: nicole mazzuca <mazzucan@outlook.com>

* Update ports/tensorflow-cc/README-linux

Co-authored-by: nicole mazzuca <mazzucan@outlook.com>

* Update ports/tensorflow-cc/README-linux

Co-authored-by: nicole mazzuca <mazzucan@outlook.com>

* Update ports/tensorflow-cc/README-linux

Co-authored-by: nicole mazzuca <mazzucan@outlook.com>

* Update ports/tensorflow-cc/README-windows

Co-authored-by: nicole mazzuca <mazzucan@outlook.com>

* Update ports/tensorflow-cc/portfile.cmake

Co-authored-by: nicole mazzuca <mazzucan@outlook.com>

* Update ports/tensorflow-cc/portfile.cmake

Co-authored-by: nicole mazzuca <mazzucan@outlook.com>

* Update ports/tensorflow-cc/portfile.cmake

Co-authored-by: nicole mazzuca <mazzucan@outlook.com>

* Update ports/tensorflow-cc/portfile.cmake

Co-authored-by: nicole mazzuca <mazzucan@outlook.com>

* Update ports/tensorflow-cc/portfile.cmake

Co-authored-by: nicole mazzuca <mazzucan@outlook.com>

* improve usage hints as discussed in review

* add comment

* apply changes from review

* make additional compiler / linker args space-proof

* Update ports/tensorflow-cc/README-macos

Co-authored-by: nicole mazzuca <mazzucan@outlook.com>

* Update ports/tensorflow-cc/tensorflow-cc-config-shared.cmake.in

Co-authored-by: nicole mazzuca <mazzucan@outlook.com>

* Update ports/tensorflow-cc/tensorflow-cc-config-shared.cmake.in

Co-authored-by: nicole mazzuca <mazzucan@outlook.com>

* Update ports/tensorflow-cc/README-linux

Co-authored-by: nicole mazzuca <mazzucan@outlook.com>

* Update ports/tensorflow-cc/README-macos

Co-authored-by: nicole mazzuca <mazzucan@outlook.com>

* apply changes from code review

* maybe fix the config files

* rob.maynard CRs

* fix windows static lib naming for first part

* Update ports/tensorflow-cc/generate_static_link_cmd_windows.py

Co-authored-by: nicole mazzuca <mazzucan@outlook.com>

* apply rob maynards 1st suggestion

* nicole CRs

* format/fix-compile

* fix missing string termination

* prefer IMPORTED_LOCATION over IMPORTED_LOCATION_RELEASE to have default fall-back

* hopefully fix the issue where no libraries are generated

* final stuff

Co-authored-by: Gehweiler <Joachim_Gehweiler@McAfee.com>
Co-authored-by: wangli28 <wangli28@beyondsoft.com>
Co-authored-by: Jack·Boos·Yu <47264268+JackBoosY@users.noreply.github.com>
Co-authored-by: Joachim Gehweiler <joachim@Joachims-iMac.local>
Co-authored-by: nicole mazzuca <mazzucan@outlook.com>
2020-11-12 10:15:48 -08:00

446 lines
20 KiB
CMake

vcpkg_fail_port_install(ON_ARCH "x86" "arm" ON_TARGET "UWP")
set(TF_VERSION 2.3.1)
set(TF_VERSION_SHORT 2.3)
vcpkg_find_acquire_program(BAZEL)
get_filename_component(BAZEL_DIR "${BAZEL}" DIRECTORY)
vcpkg_add_to_path(PREPEND ${BAZEL_DIR})
set(ENV{BAZEL_BIN_PATH} "${BAZEL}")
function(tensorflow_try_remove_recurse_wait PATH_TO_REMOVE)
file(REMOVE_RECURSE ${PATH_TO_REMOVE})
if(EXISTS "${PATH_TO_REMOVE}")
vcpkg_execute_required_process(COMMAND ${CMAKE_COMMAND} -E sleep 5 WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR} LOGNAME prerequesits-sleep-${TARGET_TRIPLET})
file(REMOVE_RECURSE ${PATH_TO_REMOVE})
endif()
endfunction()
vcpkg_find_acquire_program(GIT)
get_filename_component(GIT_DIR "${GIT}" DIRECTORY)
vcpkg_add_to_path(PREPEND ${GIT_DIR})
if(CMAKE_HOST_WIN32)
vcpkg_acquire_msys(MSYS_ROOT PACKAGES bash unzip patch diffutils libintl gzip coreutils mingw-w64-x86_64-python-numpy)
vcpkg_add_to_path(${MSYS_ROOT}/usr/bin)
vcpkg_add_to_path(${MSYS_ROOT}/mingw64/bin)
set(BASH ${MSYS_ROOT}/usr/bin/bash.exe)
set(ENV{BAZEL_SH} ${MSYS_ROOT}/usr/bin/bash.exe)
set(ENV{BAZEL_VC} $ENV{VCInstallDir})
set(ENV{BAZEL_VC_FULL_VERSION} $ENV{VCToolsVersion})
set(PYTHON3 "${MSYS_ROOT}/mingw64/bin/python3.exe")
vcpkg_execute_required_process(COMMAND ${PYTHON3} -c "import site; print(site.getsitepackages()[0])" WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR} LOGNAME prerequesits-pypath-${TARGET_TRIPLET} OUTPUT_VARIABLE PYTHON_LIB_PATH)
else()
vcpkg_find_acquire_program(PYTHON3)
get_filename_component(PYTHON3_DIR "${PYTHON3}" DIRECTORY)
vcpkg_add_to_path(PREPEND ${PYTHON3_DIR})
vcpkg_execute_required_process(COMMAND ${PYTHON3} -m pip install --user -U numpy WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR} LOGNAME prerequesits-pip-${TARGET_TRIPLET})
vcpkg_execute_required_process(COMMAND ${PYTHON3} -c "import site; print(site.getusersitepackages())" WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR} LOGNAME prerequesits-pypath-${TARGET_TRIPLET} OUTPUT_VARIABLE PYTHON_LIB_PATH)
endif()
set(ENV{PYTHON_BIN_PATH} "${PYTHON3}")
set(ENV{PYTHON_LIB_PATH} "${PYTHON_LIB_PATH}")
# check if numpy can be loaded
vcpkg_execute_required_process(COMMAND ${PYTHON3} -c "import numpy" WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR} LOGNAME prerequesits-numpy-${TARGET_TRIPLET})
# tensorflow has long file names, which will not work on windows
set(ENV{TEST_TMPDIR} ${BUILDTREES_DIR}/.bzl)
set(ENV{USE_DEFAULT_PYTHON_LIB_PATH} 1)
set(ENV{TF_NEED_KAFKA} 0)
set(ENV{TF_NEED_OPENCL_SYCL} 0)
set(ENV{TF_NEED_AWS} 0)
set(ENV{TF_NEED_GCP} 0)
set(ENV{TF_NEED_HDFS} 0)
set(ENV{TF_NEED_S3} 0)
set(ENV{TF_ENABLE_XLA} 0)
set(ENV{TF_NEED_GDR} 0)
set(ENV{TF_NEED_VERBS} 0)
set(ENV{TF_NEED_OPENCL} 0)
set(ENV{TF_NEED_MPI} 0)
set(ENV{TF_NEED_TENSORRT} 0)
set(ENV{TF_NEED_NGRAPH} 0)
set(ENV{TF_NEED_IGNITE} 0)
set(ENV{TF_NEED_ROCM} 0)
set(ENV{TF_SET_ANDROID_WORKSPACE} 0)
set(ENV{TF_DOWNLOAD_CLANG} 0)
set(ENV{TF_NCCL_VERSION} ${TF_VERSION_SHORT})
set(ENV{NCCL_INSTALL_PATH} "")
set(ENV{CC_OPT_FLAGS} "/arch:AVX")
set(ENV{TF_NEED_CUDA} 0)
set(ENV{TF_CONFIGURE_IOS} 0)
if(VCPKG_TARGET_IS_WINDOWS)
set(BAZEL_LIB_NAME tensorflow_cc.dll)
set(PLATFORM_SUFFIX windows)
set(STATIC_LINK_CMD static_link.bat)
elseif(VCPKG_TARGET_IS_OSX)
set(BAZEL_LIB_NAME libtensorflow_cc.dylib)
set(PLATFORM_SUFFIX macos)
set(STATIC_LINK_CMD sh static_link.sh)
if(VCPKG_LIBRARY_LINKAGE STREQUAL dynamic)
set(TF_LIB_NAME "libtensorflow_cc.dylib")
set(TF_LIB_NAME_SHORT "libtensorflow_cc.2.dylib")
set(TF_LIB_NAME_FULL "libtensorflow_cc.${TF_VERSION}.dylib")
set(TF_FRAMEWORK_NAME "libtensorflow_framework.dylib")
set(TF_FRAMEWORK_NAME_SHORT "libtensorflow_framework.2.dylib")
set(TF_FRAMEWORK_NAME_FULL "libtensorflow_framework.${TF_VERSION}.dylib")
else()
set(TF_LIB_NAME "libtensorflow_cc.a")
set(TF_LIB_NAME_SHORT "libtensorflow_cc.2.a")
set(TF_LIB_NAME_FULL "libtensorflow_cc.${TF_VERSION}.a")
endif()
else()
set(BAZEL_LIB_NAME libtensorflow_cc.so)
set(PLATFORM_SUFFIX linux)
set(STATIC_LINK_CMD sh static_link.sh)
if(VCPKG_LIBRARY_LINKAGE STREQUAL dynamic)
set(TF_LIB_NAME "libtensorflow_cc.so")
set(TF_LIB_NAME_SHORT "libtensorflow_cc.so.2")
set(TF_LIB_NAME_FULL "libtensorflow_cc.so.${TF_VERSION}")
set(TF_FRAMEWORK_NAME "libtensorflow_framework.so")
set(TF_FRAMEWORK_NAME_SHORT "libtensorflow_framework.so.2")
set(TF_FRAMEWORK_NAME_FULL "libtensorflow_framework.so.${TF_VERSION}")
else()
set(TF_LIB_NAME "libtensorflow_cc.a")
set(TF_LIB_NAME_SHORT "libtensorflow_cc.a.2")
set(TF_LIB_NAME_FULL "libtensorflow_cc.a.${TF_VERSION}")
endif()
endif()
foreach(BUILD_TYPE dbg rel)
# prefer repeated source extraction here for each build type over extracting once above the loop and copying because users reported issues with copying symlinks
set(STATIC_ONLY_PATCHES)
set(LINUX_ONLY_PATCHES)
if(VCPKG_LIBRARY_LINKAGE STREQUAL static)
set(STATIC_ONLY_PATCHES change-macros-for-static-lib.patch) # there is no static build option - change macros via patch and link library manually at the end
endif()
if(VCPKG_TARGET_IS_LINUX)
set(LINUX_ONLY_PATCHES fix-linux-build.patch)
endif()
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO tensorflow/tensorflow
REF "v${TF_VERSION}"
SHA512 e497ef4564f50abf9f918be4522cf702f4cf945cb1ebf83af1386ac4ddc7373b3ba70c7f803f8ca06faf2c6b5396e60b1e0e9b97bfbd667e733b08b6e6d70ef0
HEAD_REF master
PATCHES
fix-build-error.patch # Fix namespace error
fix-dbg-build-errors.patch # Fix no return statement
fix-more-build-errors.patch # Fix no return statement
${STATIC_ONLY_PATCHES}
${LINUX_ONLY_PATCHES}
)
message(STATUS "Configuring TensorFlow (${BUILD_TYPE})")
tensorflow_try_remove_recurse_wait(${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${BUILD_TYPE})
file(RENAME ${SOURCE_PATH} ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${BUILD_TYPE})
set(SOURCE_PATH "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${BUILD_TYPE}")
vcpkg_execute_required_process(
COMMAND ${PYTHON3} ${SOURCE_PATH}/configure.py --workspace "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${BUILD_TYPE}"
WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${BUILD_TYPE}
LOGNAME config-${TARGET_TRIPLET}-${BUILD_TYPE}
)
if(DEFINED ENV{BAZEL_CUSTOM_CACERTS})
file(APPEND ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${BUILD_TYPE}/.bazelrc "startup --host_jvm_args=-Djavax.net.ssl.trustStore='$ENV{BAZEL_CUSTOM_CACERTS}'\n")
message(STATUS "Using custom CA certificate store at: $ENV{BAZEL_CUSTOM_CACERTS}")
if(DEFINED ENV{BAZEL_CUSTOM_CACERTS_PASSWORD})
file(APPEND ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${BUILD_TYPE}/.bazelrc "startup --host_jvm_args=-Djavax.net.ssl.trustStorePassword='$ENV{BAZEL_CUSTOM_CACERTS_PASSWORD}'\n")
message(STATUS "Using supplied custom CA certificate store password.")
endif()
else()
if(DEFINED ENV{HTTPS_PROXY})
message(STATUS "You are using HTTPS_PROXY. In case you encounter bazel certificate errors, you might want to set: BAZEL_CUSTOM_CACERTS=/path/to/trust.store (and optionally BAZEL_CUSTOM_CACERTS_PASSWORD), and to enable vcpkg to actually use it: VCPKG_KEEP_ENV_VARS=BAZEL_CUSTOM_CACERTS;BAZEL_CUSTOM_CACERTS_PASSWORD")
if(CMAKE_HOST_WIN32)
message(STATUS "(For BAZEL_CUSTOM_CACERTS please use forward slashes instead of backslashes on Windows systems.")
endif()
endif()
endif()
message(STATUS "Warning: Building TensorFlow can take an hour or more.")
set(COPTS)
set(CXXOPTS)
set(LINKOPTS)
if(VCPKG_TARGET_IS_WINDOWS)
set(PLATFORM_COMMAND WINDOWS_COMMAND)
else()
set(PLATFORM_COMMAND UNIX_COMMAND)
endif()
if(BUILD_TYPE STREQUAL dbg)
if(VCPKG_TARGET_IS_WINDOWS)
set(BUILD_OPTS "--compilation_mode=dbg --features=fastbuild") # link with /DEBUG:FASTLINK instead of /DEBUG:FULL to avoid .pdb >4GB error
else()
set(BUILD_OPTS "--compilation_mode=dbg")
endif()
separate_arguments(VCPKG_C_FLAGS ${PLATFORM_COMMAND} ${VCPKG_C_FLAGS})
separate_arguments(VCPKG_C_FLAGS_DEBUG ${PLATFORM_COMMAND} ${VCPKG_C_FLAGS_DEBUG})
foreach(OPT IN LISTS VCPKG_C_FLAGS VCPKG_C_FLAGS_DEBUG)
list(APPEND COPTS "--copt='${OPT}'")
endforeach()
separate_arguments(VCPKG_CXX_FLAGS ${PLATFORM_COMMAND} ${VCPKG_CXX_FLAGS})
separate_arguments(VCPKG_CXX_FLAGS_DEBUG ${PLATFORM_COMMAND} ${VCPKG_CXX_FLAGS_DEBUG})
foreach(OPT IN LISTS VCPKG_CXX_FLAGS VCPKG_CXX_FLAGS_DEBUG)
list(APPEND CXXOPTS "--cxxopt='${OPT}'")
endforeach()
separate_arguments(VCPKG_LINKER_FLAGS ${PLATFORM_COMMAND} ${VCPKG_LINKER_FLAGS})
separate_arguments(VCPKG_LINKER_FLAGS_DEBUG ${PLATFORM_COMMAND} ${VCPKG_LINKER_FLAGS_DEBUG})
foreach(OPT IN LISTS VCPKG_LINKER_FLAGS VCPKG_LINKER_FLAGS_DEBUG)
list(APPEND LINKOPTS "--linkopt='${OPT}'")
endforeach()
else()
set(BUILD_OPTS "--compilation_mode=opt")
separate_arguments(VCPKG_C_FLAGS ${PLATFORM_COMMAND} ${VCPKG_C_FLAGS})
separate_arguments(VCPKG_C_FLAGS_RELEASE ${PLATFORM_COMMAND} ${VCPKG_C_FLAGS_RELEASE})
foreach(OPT IN LISTS VCPKG_C_FLAGS VCPKG_C_FLAGS_RELEASE)
list(APPEND COPTS "--copt='${OPT}'")
endforeach()
separate_arguments(VCPKG_CXX_FLAGS ${PLATFORM_COMMAND} ${VCPKG_CXX_FLAGS})
separate_arguments(VCPKG_CXX_FLAGS_RELEASE ${PLATFORM_COMMAND} ${VCPKG_CXX_FLAGS_RELEASE})
foreach(OPT IN LISTS VCPKG_CXX_FLAGS VCPKG_CXX_FLAGS_RELEASE)
list(APPEND CXXOPTS "--cxxopt='${OPT}'")
endforeach()
separate_arguments(VCPKG_LINKER_FLAGS ${PLATFORM_COMMAND} ${VCPKG_LINKER_FLAGS})
separate_arguments(VCPKG_LINKER_FLAGS_RELEASE ${PLATFORM_COMMAND} ${VCPKG_LINKER_FLAGS_RELEASE})
foreach(OPT IN LISTS VCPKG_LINKER_FLAGS VCPKG_LINKER_FLAGS_RELEASE)
list(APPEND LINKOPTS "--linkopt='${OPT}'")
endforeach()
endif()
if(VCPKG_LIBRARY_LINKAGE STREQUAL dynamic)
if(VCPKG_TARGET_IS_WINDOWS)
list(JOIN COPTS " " COPTS)
list(JOIN CXXOPTS " " CXXOPTS)
list(JOIN LINKOPTS " " LINKOPTS)
vcpkg_execute_build_process(
COMMAND ${BASH} --noprofile --norc -c "'${BAZEL}' build --verbose_failures ${BUILD_OPTS} ${COPTS} ${CXXOPTS} ${LINKOPTS} --python_path='${PYTHON3}' --define=no_tensorflow_py_deps=true ///tensorflow:tensorflow_cc.dll ///tensorflow:install_headers"
WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${BUILD_TYPE}
LOGNAME build-${TARGET_TRIPLET}-${BUILD_TYPE}
)
else()
vcpkg_execute_build_process(
COMMAND ${BAZEL} build --verbose_failures ${BUILD_OPTS} --python_path=${PYTHON3} ${COPTS} ${CXXOPTS} ${LINKOPTS} --define=no_tensorflow_py_deps=true //tensorflow:${BAZEL_LIB_NAME} //tensorflow:install_headers
WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${BUILD_TYPE}
LOGNAME build-${TARGET_TRIPLET}-${BUILD_TYPE}
)
endif()
else()
if(VCPKG_TARGET_IS_WINDOWS)
if(VCPKG_CRT_LINKAGE STREQUAL static)
if(BUILD_TYPE STREQUAL dbg)
list(APPEND COPTS "--copt=-MTd")
else()
list(APPEND COPTS "--copt=-MT")
endif()
endif()
list(JOIN COPTS " " COPTS)
list(JOIN CXXOPTS " " CXXOPTS)
list(JOIN LINKOPTS " " LINKOPTS)
vcpkg_execute_build_process(
COMMAND ${BASH} --noprofile --norc -c "${BAZEL} build -s --verbose_failures ${BUILD_OPTS} --features=fully_static_link ${COPTS} ${CXXOPTS} ${LINKOPTS} --python_path='${PYTHON3}' --define=no_tensorflow_py_deps=true ///tensorflow:tensorflow_cc.dll ///tensorflow:install_headers"
WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${BUILD_TYPE}
LOGNAME build-${TARGET_TRIPLET}-${BUILD_TYPE}
)
else()
vcpkg_execute_build_process(
COMMAND ${BAZEL} build -s --verbose_failures ${BUILD_OPTS} ${COPTS} ${CXXOPTS} ${LINKOPTS} --python_path=${PYTHON3} --define=no_tensorflow_py_deps=true //tensorflow:${BAZEL_LIB_NAME} //tensorflow:install_headers
WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${BUILD_TYPE}
LOGNAME build-${TARGET_TRIPLET}-${BUILD_TYPE}
)
endif()
if(NOT VCPKG_TARGET_IS_OSX)
if(VCPKG_TARGET_IS_WINDOWS)
vcpkg_execute_build_process(
COMMAND ${PYTHON3} "${CMAKE_CURRENT_LIST_DIR}/convert_lib_params_${PLATFORM_SUFFIX}.py"
WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${BUILD_TYPE}/bazel-bin/tensorflow
LOGNAME postbuild1-${TARGET_TRIPLET}-${BUILD_TYPE}
)
else()
vcpkg_execute_build_process(
COMMAND ${PYTHON3} "${CMAKE_CURRENT_LIST_DIR}/convert_lib_params_${PLATFORM_SUFFIX}.py" "${TF_VERSION}"
WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${BUILD_TYPE}/bazel-bin/tensorflow
LOGNAME postbuild1-${TARGET_TRIPLET}-${BUILD_TYPE}
)
endif()
endif()
vcpkg_execute_build_process(
COMMAND ${PYTHON3} "${CMAKE_CURRENT_LIST_DIR}/generate_static_link_cmd_${PLATFORM_SUFFIX}.py" "${CURRENT_BUILDTREES_DIR}/build-${TARGET_TRIPLET}-${BUILD_TYPE}-err.log" # for some reason stdout of bazel ends up in stderr
WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${BUILD_TYPE}/bazel-${TARGET_TRIPLET}-${BUILD_TYPE}
LOGNAME postbuild2-${TARGET_TRIPLET}-${BUILD_TYPE}
)
vcpkg_execute_build_process(
COMMAND ${STATIC_LINK_CMD}
WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${BUILD_TYPE}/bazel-${TARGET_TRIPLET}-${BUILD_TYPE}
LOGNAME postbuild3-${TARGET_TRIPLET}-${BUILD_TYPE}
)
endif()
if(BUILD_TYPE STREQUAL "dbg")
set(DIR_PREFIX "/debug")
else()
set(DIR_PREFIX "")
endif()
if(VCPKG_TARGET_IS_WINDOWS)
if(VCPKG_LIBRARY_LINKAGE STREQUAL dynamic)
file(COPY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${BUILD_TYPE}/bazel-bin/tensorflow/tensorflow_cc.dll DESTINATION ${CURRENT_PACKAGES_DIR}${DIR_PREFIX}/bin)
# rename before copy because after copy the file might be locked by anti-malware scanners for some time so that renaming fails
file(RENAME ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${BUILD_TYPE}/bazel-bin/tensorflow/tensorflow_cc.dll.if.lib ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${BUILD_TYPE}/bazel-bin/tensorflow/tensorflow_cc.lib)
file(COPY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${BUILD_TYPE}/bazel-bin/tensorflow/tensorflow_cc.lib DESTINATION ${CURRENT_PACKAGES_DIR}${DIR_PREFIX}/lib)
if(BUILD_TYPE STREQUAL dbg)
file(COPY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${BUILD_TYPE}/bazel-bin/tensorflow/tensorflow_cc.pdb DESTINATION ${CURRENT_PACKAGES_DIR}${DIR_PREFIX}/bin)
message(STATUS "Warning: debug information tensorflow_cc.pdb will be of limited use because only a reduced set could be produced due to the 4GB internal PDB file limit even on x64.")
endif()
else()
if(BUILD_TYPE STREQUAL dbg)
set(library_parts_variable TF_LIB_PARTS_DEBUG)
else()
set(library_parts_variable TF_LIB_PARTS_RELEASE)
endif()
set(${library_parts_variable})
# library might have been split because no more than 4GB are supported even on x64 Windows
foreach(PART_NO RANGE 1 100)
set(source "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${BUILD_TYPE}/bazel-bin/tensorflow/tensorflow_cc-part${PART_NO}.lib")
if(EXISTS "${source}")
file(COPY "${source}" DESTINATION "${CURRENT_PACKAGES_DIR}${DIR_PREFIX}/lib")
list(APPEND ${library_parts_variable} "tensorflow_cc-part${PART_NO}.lib")
else()
break()
endif()
endforeach()
endif()
else()
file(COPY
${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${BUILD_TYPE}/bazel-bin/tensorflow/${TF_LIB_NAME_FULL}
DESTINATION ${CURRENT_PACKAGES_DIR}${DIR_PREFIX}/lib
)
# Note: these use relative links
file(CREATE_LINK ${TF_LIB_NAME_FULL}
${CURRENT_PACKAGES_DIR}${DIR_PREFIX}/lib/${TF_LIB_NAME_SHORT}
SYMBOLIC
)
file(CREATE_LINK ${TF_LIB_NAME_FULL}
${CURRENT_PACKAGES_DIR}${DIR_PREFIX}/lib/${TF_LIB_NAME}
SYMBOLIC
)
if(VCPKG_LIBRARY_LINKAGE STREQUAL dynamic)
file(COPY
${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${BUILD_TYPE}/bazel-bin/tensorflow/${TF_FRAMEWORK_NAME_FULL}
DESTINATION ${CURRENT_PACKAGES_DIR}${DIR_PREFIX}/lib
)
file(CREATE_LINK
${TF_FRAMEWORK_NAME_FULL}
${CURRENT_PACKAGES_DIR}${DIR_PREFIX}/lib/${TF_FRAMEWORK_NAME_SHORT}
SYMBOLIC
)
file(CREATE_LINK
${TF_FRAMEWORK_NAME_FULL}
${CURRENT_PACKAGES_DIR}${DIR_PREFIX}/lib/${TF_FRAMEWORK_NAME}
SYMBOLIC
)
endif()
endif()
endforeach()
file(COPY
${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/bazel-bin/tensorflow/include/
DESTINATION ${CURRENT_PACKAGES_DIR}/include/tensorflow-external
)
if(VCPKG_LIBRARY_LINKAGE STREQUAL static)
message(STATUS "Warning: Static TensorFlow build contains several external dependencies that may cause linking conflicts (for example, one cannot use both openssl and TensorFlow in the same project, since TensorFlow contains boringssl).")
if(VCPKG_TARGET_IS_WINDOWS)
message(STATUS "Note: For some TensorFlow features (e.g. OpRegistry), it might be necessary to tell the linker to include the whole library, i.e., link using options '/WHOLEARCHIVE:tensorflow_cc-part1.lib /WHOLEARCHIVE:tensorflow_cc-part2.lib ...'")
else()
message(STATUS "Note: There is no separate libtensorflow_framework.a as it got merged into libtensorflow_cc.a to avoid linking conflicts.")
if(VCPKG_TARGET_IS_OSX)
message(STATUS "Note: Beside TensorFlow itself, you'll need to also pass its dependancies to the linker, for example '-ltensorflow_cc -framework CoreFoundation'")
message(STATUS "Note: For some TensorFlow features (e.g. OpRegistry), it might be necessary to tell the linker to include the whole library: '-Wl,-force_load,path/to/libtensorflow_cc.a -framework CoreFoundation -framework Security [rest of linker arguments]'")
else()
message(STATUS "Note: Beside TensorFlow itself, you'll need to also pass its dependancies to the linker, for example '-ltensorflow_cc -lm -ldl -lpthread'")
message(STATUS "Note: For some TensorFlow features (e.g. OpRegistry), it might be necessary to tell the linker to include the whole library: '-Wl,--whole-archive -ltensorflow_cc -Wl,--no-whole-archive [rest of linker arguments]'")
endif()
endif()
configure_file(
${CMAKE_CURRENT_LIST_DIR}/README-${PLATFORM_SUFFIX}
${CURRENT_PACKAGES_DIR}/share/tensorflow-cc/README
COPYONLY)
endif()
file(COPY ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/tensorflow-cc)
file(RENAME ${CURRENT_PACKAGES_DIR}/share/tensorflow-cc/LICENSE ${CURRENT_PACKAGES_DIR}/share/tensorflow-cc/copyright)
# NOTE: if this port ever supports VCPKG_BUILD_TYPE, use that to set these.
set(TENSORFLOW_HAS_RELEASE ON)
set(TENSORFLOW_HAS_DEBUG ON)
if(VCPKG_TARGET_IS_WINDOWS)
if(VCPKG_LIBRARY_LINKAGE STREQUAL dynamic)
configure_file(
${CMAKE_CURRENT_LIST_DIR}/tensorflow-cc-config-windows-dll.cmake.in
${CURRENT_PACKAGES_DIR}/share/tensorflow-cc/tensorflow-cc-config.cmake
@ONLY)
else()
configure_file(
${CMAKE_CURRENT_LIST_DIR}/tensorflow-cc-config-windows-lib.cmake.in
${CURRENT_PACKAGES_DIR}/share/tensorflow-cc/tensorflow-cc-config.cmake
@ONLY)
set(VCPKG_POLICY_MISMATCHED_NUMBER_OF_BINARIES enabled)
set(prefix [[${TENSORFLOW_INSTALL_PREFIX}]])
set(libs_to_link)
foreach(lib IN LISTS TF_LIB_PARTS_RELEASE)
list(APPEND libs_to_link "$<$<CONFIG:Release>:${prefix}/lib/${lib}>")
endforeach()
foreach(lib IN LISTS TF_LIB_PARTS_DEBUG)
list(APPEND libs_to_link "$<$<CONFIG:Debug>:${prefix}/debug/lib/${lib}>")
endforeach()
if(TENSORFLOW_HAS_RELEASE)
set(TF_LIB_PARTS_DEFAULT ${TF_LIB_PARTS_RELEASE})
set(prefix_DEFAULT "${prefix}")
elseif(TENSORFLOW_HAS_DEBUG)
set(TF_LIB_PARTS_DEFAULT ${TF_LIB_PARTS_DEBUG})
set(prefix_DEFAULT "${prefix}/debug")
endif()
foreach(lib IN LISTS TF_LIB_PARTS_DEFAULT)
list(APPEND libs_to_link
"$<$<NOT:$<OR:$<CONFIG:Release>,$<CONFIG:Debug>>>:${prefix}/lib/${lib}>")
endforeach()
string(REPLACE ";" "\n\t\t" libs_to_link "${libs_to_link}")
file(APPEND ${CURRENT_PACKAGES_DIR}/share/tensorflow-cc/tensorflow-cc-config.cmake "
target_link_libraries(tensorflow_cc::tensorflow_cc
INTERFACE
${libs_to_link}
)"
)
endif()
else()
if(VCPKG_LIBRARY_LINKAGE STREQUAL dynamic)
configure_file(
${CMAKE_CURRENT_LIST_DIR}/tensorflow-cc-config-shared.cmake.in
${CURRENT_PACKAGES_DIR}/share/tensorflow-cc/tensorflow-cc-config.cmake
@ONLY)
else()
configure_file(
${CMAKE_CURRENT_LIST_DIR}/tensorflow-cc-config-static.cmake.in
${CURRENT_PACKAGES_DIR}/share/tensorflow-cc/tensorflow-cc-config.cmake
@ONLY)
endif()
endif()
message(STATUS "You may want to delete ${CURRENT_BUILDTREES_DIR} and ${BUILDTREES_DIR}/.bzl to free diskspace.")