third_party.cmake 4.2 KB
Newer Older
W
willzhang4a58 已提交
1 2 3 4 5 6 7 8
if (NOT WIN32)
  find_package(Threads)
endif()

include(zlib)
include(protobuf)
include(googletest)
include(gflags)
W
willzhang4a58 已提交
9
include(glog)
W
willzhang4a58 已提交
10
include(grpc)
J
Jinhui Yuan 已提交
11
include(libjpeg-turbo)
L
Li Xinqi 已提交
12
include(opencv)
J
Jinhui Yuan 已提交
13
include(eigen)
W
willzhang4a58 已提交
14

15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
if (THIRD_PARTY AND PRECOMPILED_THIRD_PARTY)
  if (BUILD_CUDA)
    set(THIRD_PARTY_URL http://download.oneflow.org/third_party_with_cuda.tgz)
  else()
    set(THIRD_PARTY_URL http://download.oneflow.org/third_party_without_cuda.tgz)
  endif()

  if (NOT WIN32)
    message(STATUS "downloading third_partys ...")
    file(DOWNLOAD ${THIRD_PARTY_URL} ${PROJECT_BINARY_DIR}/third_party.tgz SHOW_PROGRESS)
    execute_process(
      COMMAND ${CMAKE_COMMAND} -E tar zxvf ${PROJECT_BINARY_DIR}/third_party.tgz
      WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
    )
  else()
    message(STATUS "win32 not support yet.")
  endif()
endif()

W
willzhang4a58 已提交
34
if (BUILD_CUDA)
35
  set(CUDA_SEPARABLE_COMPILATION ON)
W
willzhang4a58 已提交
36 37
  find_package(CUDA REQUIRED)
  add_definitions(-DWITH_CUDA)
W
willzhang4a58 已提交
38 39 40 41 42 43 44
  foreach(cuda_lib_path ${CUDA_LIBRARIES})
    get_filename_component(cuda_lib_name ${cuda_lib_path} NAME)
    if (${cuda_lib_name} STREQUAL libcudart_static.a)
      get_filename_component(cuda_lib_dir ${cuda_lib_path} DIRECTORY)
      break()
    endif()
  endforeach()
L
Li Xinqi 已提交
45
  set(extra_cuda_libs libculibos.a libcublas_static.a libcurand_static.a)
W
willzhang4a58 已提交
46 47 48
  foreach(extra_cuda_lib ${extra_cuda_libs})
    list(APPEND CUDA_LIBRARIES ${cuda_lib_dir}/${extra_cuda_lib})
  endforeach()
W
willzhang4a58 已提交
49 50
  find_package(CuDNN REQUIRED)
endif()
W
willzhang4a58 已提交
51

52
if (NOT WIN32)
W
willzhang4a58 已提交
53
  set(BLA_STATIC ON)
54
  set(BLA_VENDOR "Intel10_64lp_seq")
W
Will Zhang 已提交
55 56 57 58 59
  find_package(BLAS)
  if (NOT BLAS_FOUND)
    set(BLA_VENDOR "All")
    find_package(BLAS)
  endif()
60 61 62 63
else()
  set(MKL_LIB_PATH "C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2017/windows/mkl/lib/intel64_win")
  set(BLAS_LIBRARIES ${MKL_LIB_PATH}/mkl_core_dll.lib ${MKL_LIB_PATH}/mkl_sequential_dll.lib ${MKL_LIB_PATH}/mkl_intel_lp64_dll.lib)
endif()
W
willzhang4a58 已提交
64
message(STATUS "Found Blas Lib: " ${BLAS_LIBRARIES})
W
willzhang4a58 已提交
65

W
willzhang4a58 已提交
66 67 68 69 70
set(oneflow_third_party_libs
    ${CMAKE_THREAD_LIBS_INIT}
    ${GLOG_STATIC_LIBRARIES}
    ${GFLAGS_STATIC_LIBRARIES}
    ${GOOGLETEST_STATIC_LIBRARIES}
J
Jinhui Yuan 已提交
71
    ${GOOGLEMOCK_STATIC_LIBRARIES}
W
willzhang4a58 已提交
72 73
    ${PROTOBUF_STATIC_LIBRARIES}
    ${GRPC_STATIC_LIBRARIES}
W
willzhang4a58 已提交
74
    ${ZLIB_STATIC_LIBRARIES}
J
jiyuan 已提交
75
    ${farmhash_STATIC_LIBRARIES}
W
willzhang4a58 已提交
76
    ${BLAS_LIBRARIES}
J
Jinhui Yuan 已提交
77
    ${LIBJPEG_STATIC_LIBRARIES}
L
Li Xinqi 已提交
78
    ${OPENCV_STATIC_LIBRARIES}
W
willzhang4a58 已提交
79
)
J
Jinhui Yuan 已提交
80

81 82 83
if(WIN32)
  # static gflags lib requires "PathMatchSpecA" defined in "ShLwApi.Lib"
  list(APPEND oneflow_third_party_libs "ShLwApi.Lib")
84
  list(APPEND oneflow_third_party_libs "Ws2_32.lib")
85 86
endif()

W
willzhang4a58 已提交
87 88 89 90 91 92 93 94
set(oneflow_third_party_dependencies
  zlib_copy_headers_to_destination
  zlib_copy_libs_to_destination
  protobuf_copy_headers_to_destination
  protobuf_copy_libs_to_destination
  protobuf_copy_binary_to_destination
)

95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
if (NOT PRECOMPILED_THIRD_PARTY)
  list(APPEND oneflow_third_party_dependencies 
    gflags_copy_headers_to_destination
    gflags_copy_libs_to_destination
    glog_copy_headers_to_destination
    glog_copy_libs_to_destination
    googletest_copy_headers_to_destination
    googletest_copy_libs_to_destination
    googlemock_copy_headers_to_destination
    googlemock_copy_libs_to_destination
    grpc_copy_headers_to_destination
    grpc_copy_libs_to_destination
    opencv_copy_headers_to_destination
    opencv_copy_libs_to_destination
    eigen
  )
endif()

W
willzhang4a58 已提交
113 114 115 116 117
include_directories(
    ${ZLIB_INCLUDE_DIR}
    ${GFLAGS_INCLUDE_DIR}
    ${GLOG_INCLUDE_DIR}
    ${GOOGLETEST_INCLUDE_DIR}
J
Jinhui Yuan 已提交
118
    ${GOOGLEMOCK_INCLUDE_DIR}
W
willzhang4a58 已提交
119 120
    ${PROTOBUF_INCLUDE_DIR}
    ${GRPC_INCLUDE_DIR}
J
Jinhui Yuan 已提交
121
    ${LIBJPEG_INCLUDE_DIR}
L
Li Xinqi 已提交
122
    ${OPENCV_INCLUDE_DIR}
J
Jinhui Yuan 已提交
123
    ${EIGEN_INCLUDE_DIR}
W
willzhang4a58 已提交
124
)
J
Jinhui Yuan 已提交
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143

if (BUILD_CUDA)
  include(cub)
  include(nccl)

  list(APPEND oneflow_third_party_libs ${CUDA_LIBRARIES})
  list(APPEND oneflow_third_party_libs ${CUDNN_LIBRARIES})
  list(APPEND oneflow_third_party_libs ${NCCL_STATIC_LIBRARIES})

  list(APPEND oneflow_third_party_dependencies cub_copy_headers_to_destination)
  list(APPEND oneflow_third_party_dependencies nccl_copy_headers_to_destination)
  list(APPEND oneflow_third_party_dependencies nccl_copy_libs_to_destination)

  include_directories(
    ${CUDNN_INCLUDE_DIRS}
    ${CUB_INCLUDE_DIR}
    ${NCCL_INCLUDE_DIR}
)
endif()
144 145

message(STATUS "oneflow_third_party_libs: " ${oneflow_third_party_libs})