xxhash.cmake 3.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# Copyright (c) 2018 PaddlePaddle 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.

M
minqiyang 已提交
15 16
INCLUDE(ExternalProject)

17
set(XXHASH_PREFIX_DIR ${THIRD_PARTY_PATH}/xxhash)
M
minqiyang 已提交
18 19
set(XXHASH_INSTALL_DIR ${THIRD_PARTY_PATH}/install/xxhash)
set(XXHASH_INCLUDE_DIR "${XXHASH_INSTALL_DIR}/include")
20 21 22 23 24 25 26
set(XXHASH_REPOSITORY  https://github.com/Cyan4973/xxHash)
set(XXHASH_TAG         v0.6.5)

cache_third_party(extern_xxhash
    REPOSITORY    ${XXHASH_REPOSITORY}
    TAG           ${XXHASH_TAG}
    DIR           ${XXHASH_PREFIX_DIR})
M
minqiyang 已提交
27

M
minqiyang 已提交
28 29 30
IF(WITH_STATIC_LIB)
  SET(BUILD_CMD make lib)
ELSE()
Q
Qiao Longfei 已提交
31
  IF(APPLE)
32
    SET(BUILD_CMD sed -i \"\" "s/-Wstrict-prototypes -Wundef/-Wstrict-prototypes -Wundef -fPIC/g" ${XXHASH_SOURCE_DIR}/Makefile && make lib)
Q
Qiao Longfei 已提交
33
  ELSE(APPLE)
34
    SET(BUILD_CMD sed -i "s/-Wstrict-prototypes -Wundef/-Wstrict-prototypes -Wundef -fPIC/g" ${XXHASH_SOURCE_DIR}/Makefile && make lib)
Q
Qiao Longfei 已提交
35
  ENDIF(APPLE)
M
minqiyang 已提交
36
ENDIF()
M
minqiyang 已提交
37

P
peizhilin 已提交
38 39
if(WIN32)
  ExternalProject_Add(
40 41
      extern_xxhash
      ${EXTERNAL_PROJECT_LOG_ARGS}
42
      ${SHALLOW_CLONE}
43 44 45 46 47
      "${XXHASH_DOWNLOAD_CMD}"
      PREFIX           ${XXHASH_PREFIX_DIR}
      SOURCE_DIR       ${XXHASH_SOURCE_DIR}
      UPDATE_COMMAND   ""
      PATCH_COMMAND    ""
48
      CONFIGURE_COMMAND
49
                      ${CMAKE_COMMAND} ${XXHASH_SOURCE_DIR}/cmake_unofficial
50 51 52 53 54 55 56 57 58 59
                      -DCMAKE_INSTALL_PREFIX:PATH=${XXHASH_INSTALL_DIR}
                      -DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
                      -DCMAKE_VERBOSE_MAKEFILE:BOOL=OFF
                      -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON
                      -DBUILD_XXHSUM=OFF
                      -DCMAKE_GENERATOR=${CMAKE_GENERATOR}
                      -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM}
                      -DBUILD_SHARED_LIBS=OFF
                      ${OPTIONAL_CACHE_ARGS}
      TEST_COMMAND      ""
P
peizhilin 已提交
60 61 62 63 64
  )
else()
  ExternalProject_Add(
      extern_xxhash
      ${EXTERNAL_PROJECT_LOG_ARGS}
65 66 67 68
      "${XXHASH_DOWNLOAD_CMD}"
      PREFIX           ${XXHASH_PREFIX_DIR}
      SOURCE_DIR       ${XXHASH_SOURCE_DIR}
      UPDATE_COMMAND    ""
P
peizhilin 已提交
69
      CONFIGURE_COMMAND ""
70
      BUILD_IN_SOURCE   1
P
peizhilin 已提交
71
      BUILD_COMMAND     ${BUILD_CMD}
72
      INSTALL_COMMAND   make PREFIX=${XXHASH_INSTALL_DIR} install
P
peizhilin 已提交
73 74 75
      TEST_COMMAND      ""
  )
endif()
M
minqiyang 已提交
76

P
peizhilin 已提交
77
if (WIN32)
78
  set(XXHASH_LIBRARIES "${XXHASH_INSTALL_DIR}/lib/xxhash.lib")
P
peizhilin 已提交
79 80 81
else()
  set(XXHASH_LIBRARIES "${XXHASH_INSTALL_DIR}/lib/libxxhash.a")
endif ()
M
minqiyang 已提交
82 83 84 85 86 87
INCLUDE_DIRECTORIES(${XXHASH_INCLUDE_DIR})

add_library(xxhash STATIC IMPORTED GLOBAL)
set_property(TARGET xxhash PROPERTY IMPORTED_LOCATION ${XXHASH_LIBRARIES})
include_directories(${XXHASH_INCLUDE_DIR})
add_dependencies(xxhash extern_xxhash)