Added SNAPPY support in CMake scripts

This commit is contained in:
Alexey Petrenko 2017-07-27 18:31:21 +03:00 committed by Martin Wicke
parent bfdffb2adb
commit b40716f792
2 changed files with 58 additions and 0 deletions

View File

@ -33,6 +33,7 @@ option(tensorflow_BUILD_MORE_PYTHON_TESTS "Build more python unit tests for cont
option(tensorflow_BUILD_SHARED_LIB "Build TensorFlow as a shared library" OFF) option(tensorflow_BUILD_SHARED_LIB "Build TensorFlow as a shared library" OFF)
option(tensorflow_OPTIMIZE_FOR_NATIVE_ARCH "Enable compiler optimizations for the native processor architecture (if available)" ON) option(tensorflow_OPTIMIZE_FOR_NATIVE_ARCH "Enable compiler optimizations for the native processor architecture (if available)" ON)
option(tensorflow_WIN_CPU_SIMD_OPTIONS "Enables CPU SIMD instructions") option(tensorflow_WIN_CPU_SIMD_OPTIONS "Enables CPU SIMD instructions")
option(tensorflow_ENABLE_SNAPPY_SUPPORT "Enable SNAPPY compression support" OFF)
if (NOT WIN32) if (NOT WIN32)
# Threads: defines CMAKE_THREAD_LIBS_INIT and adds -pthread compile option # Threads: defines CMAKE_THREAD_LIBS_INIT and adds -pthread compile option
@ -204,6 +205,16 @@ if(tensorflow_ENABLE_JEMALLOC_SUPPORT)
list(APPEND tensorflow_EXTERNAL_DEPENDENCIES jemalloc) list(APPEND tensorflow_EXTERNAL_DEPENDENCIES jemalloc)
include_directories(${jemalloc_INCLUDE_DIRS}) include_directories(${jemalloc_INCLUDE_DIRS})
endif() endif()
if(tensorflow_ENABLE_SNAPPY_SUPPORT)
if (WIN32)
include(snappy)
list(APPEND tensorflow_EXTERNAL_LIBRARIES ${snappy_STATIC_LIBRARIES})
list(APPEND tensorflow_EXTERNAL_DEPENDENCIES snappy)
include_directories(${snappy_INCLUDE_DIR})
else()
message(FATAL_ERROR "CMake build with SNAPPY is only supported on Windows at the moment")
endif()
endif()
if(WIN32) if(WIN32)
list(APPEND tensorflow_EXTERNAL_LIBRARIES wsock32 ws2_32 shlwapi) list(APPEND tensorflow_EXTERNAL_LIBRARIES wsock32 ws2_32 shlwapi)
endif() endif()

View File

@ -0,0 +1,47 @@
# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
include (ExternalProject)
set(snappy_URL https://github.com/google/snappy.git)
set(snappy_TAG "1.1.6")
set(snappy_BUILD ${CMAKE_CURRENT_BINARY_DIR}/snappy/src/snappy)
set(snappy_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/snappy/src/snappy)
if(WIN32)
set(snappy_STATIC_LIBRARIES ${snappy_BUILD}/$(Configuration)/snappy.lib)
endif()
set(snappy_HEADERS
"${snappy_INCLUDE_DIR}/snappy.h"
)
ExternalProject_Add(snappy
PREFIX snappy
GIT_REPOSITORY ${snappy_URL}
GIT_TAG ${snappy_TAG}
DOWNLOAD_DIR "${DOWNLOAD_LOCATION}"
BUILD_IN_SOURCE 1
INSTALL_COMMAND ""
LOG_DOWNLOAD ON
LOG_CONFIGURE ON
LOG_BUILD ON
CMAKE_CACHE_ARGS
-DCMAKE_BUILD_TYPE:STRING=Release
-DCMAKE_VERBOSE_MAKEFILE:BOOL=OFF
-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON
)
# actually enables snappy in the source code
add_definitions(-DSNAPPY)