CMakeLists.txt 6.3 KB
Newer Older
Z
zhangjinchao01 已提交
1 2 3 4 5 6 7
cmake_minimum_required(VERSION 2.8)

project(paddle CXX C)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
set(PROJ_ROOT ${CMAKE_SOURCE_DIR})
include(package)
B
backyes 已提交
8
find_package(SWIG 2.0)
Z
zhangjinchao01 已提交
9 10
find_package(CUDA QUIET)
find_package(Protobuf REQUIRED)
11 12 13 14 15 16 17 18 19 20 21

# Check protobuf library version.
execute_process(COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} --version
	OUTPUT_VARIABLE PROTOBUF_VERSION)
string(REPLACE "libprotoc " "" PROTOBUF_VERSION ${PROTOBUF_VERSION})

set(PROTOBUF_3 OFF)
if (${PROTOBUF_VERSION} VERSION_GREATER "3.0.0" OR ${PROTOBUF_VERSION} VERSION_EQUAL "3.0.0")
    set(PROTOBUF_3 ON)
endif()

Z
zhangjinchao01 已提交
22 23
find_package(PythonLibs 2.7 REQUIRED)
find_package(PythonInterp 2.7 REQUIRED)
Y
Yu Yang 已提交
24 25
find_package(ZLIB REQUIRED)
find_package(NumPy REQUIRED)
Z
zhangjinchao01 已提交
26
find_package(Threads REQUIRED)
27
find_package(AVX QUIET)
Z
zhangjinchao01 已提交
28 29 30 31 32 33 34 35 36 37 38
find_package(Glog)
find_package(Gflags QUIET)
find_package(GTest)
find_package(Sphinx)
find_package(Doxygen)
include(cblas)
find_program(M4_EXECUTABLE m4)
###################### Configurations ###########################
option(WITH_DSO "Compile PaddlePaddle with dynamic linked libraries" ON)
option(WITH_GPU "Compile PaddlePaddle with gpu" ${CUDA_FOUND})
option(WITH_DOUBLE "Compile PaddlePaddle with double precision, otherwise use single precision" OFF)
39
option(WITH_AVX "Compile PaddlePaddle with avx intrinsics" ${AVX_FOUND})
L
liaogang 已提交
40
option(WITH_PYTHON "Compile PaddlePaddle with python interpreter" ON)
Z
zhangjinchao01 已提交
41 42 43 44 45
option(WITH_STYLE_CHECK "Style Check for PaddlePaddle" ${PYTHONINTERP_FOUND})
option(WITH_RDMA "Compile PaddlePaddle with rdma support" OFF)
option(WITH_GLOG "Compile PaddlePaddle use glog, otherwise use a log implement internally" ${LIBGLOG_FOUND})
option(WITH_GFLAGS "Compile PaddlePaddle use gflags, otherwise use a flag implement internally" ${GFLAGS_FOUND})
option(WITH_TIMER "Compile PaddlePaddle use timer" OFF)
L
liaogang 已提交
46
option(WITH_PROFILER "Compile PaddlePaddle use gpu profiler" OFF)
Z
zhangjinchao01 已提交
47 48
option(WITH_TESTING "Compile and run unittest for PaddlePaddle" ${GTEST_FOUND})
option(WITH_DOC "Compile PaddlePaddle with documentation" OFF)
L
liaogang 已提交
49
option(WITH_SWIG_PY "Compile PaddlePaddle with py PaddlePaddle prediction api" ${SWIG_FOUND})
Y
Yu Yang 已提交
50
option(ON_TRAVIS "Running test on travis-ci or not." OFF)
G
gangliao 已提交
51 52 53
option(ON_COVERALLS "Generating code coverage data on coveralls or not." OFF)
option(COVERALLS_UPLOAD "Uploading the generated coveralls json." ON)

Z
zhangjinchao01 已提交
54
if(NOT CMAKE_BUILD_TYPE)
55
    set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
Z
zhangjinchao01 已提交
56 57 58 59 60 61 62
        "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel"
        FORCE)
endif()

include(enableCXX11)
include(cpplint)
include(ccache)
B
backyes 已提交
63 64 65
if(WITH_RDMA)
  include(rdma)
endif()
Z
zhangjinchao01 已提交
66 67 68 69 70
include(util)
include(flags)
include(cudnn)
include(FindPythonModule)
include(check_packages)
B
backyes 已提交
71
include(swig)
G
gangliao 已提交
72
include(coveralls)
Z
zhangjinchao01 已提交
73

74 75 76 77 78 79 80 81 82 83
# Set PaddlePaddle version to Git tag name or Git commit ID.
find_package(Git REQUIRED)
execute_process(
  COMMAND ${GIT_EXECUTABLE} describe --tags --exact-match --abbrev=0
  WORKING_DIRECTORY ${PROJ_ROOT}
  OUTPUT_VARIABLE GIT_TAG_NAME
  RESULT_VARIABLE GIT_RESULT
  ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT ${GIT_RESULT})
  set(PADDLE_VERSION ${GIT_TAG_NAME})
Z
zhangjinchao01 已提交
84
else()
85
  execute_process(
86
    COMMAND ${GIT_EXECUTABLE} log -1 --format=%h
87 88 89 90 91 92 93 94 95 96
    WORKING_DIRECTORY ${PROJ_ROOT}
    OUTPUT_VARIABLE GIT_SHA1
    RESULT_VARIABLE GIT_RESULT
    ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
  if(NOT ${GIT_RESULT})
    set(PADDLE_VERSION ${GIT_SHA1})
  else()
    set(PADDLE_VERSION "unknown")
    message(WARNING "Cannot add paddle version from git tag")
  endif()
Z
zhangjinchao01 已提交
97
endif()
98
add_definitions(-DPADDLE_VERSION=\"${PADDLE_VERSION}\")
Z
zhangjinchao01 已提交
99 100 101 102 103 104 105


if(NOT WITH_GPU)
    add_definitions(-DPADDLE_ONLY_CPU)
    add_definitions(-DHPPL_STUB_FUNC)
    list(APPEND CMAKE_CXX_SOURCE_FILE_EXTENSIONS cu)
else()
H
hedaoyuan 已提交
106 107 108 109 110 111
    if(${CUDA_VERSION_MAJOR} GREATER 6)
        if(COMPILER_SUPPORT_CXX11)
            LIST(APPEND CUDA_NVCC_FLAGS -std=c++11)
        endif()
    endif()

Z
zhangjinchao01 已提交
112 113 114 115 116
    # TODO(yuyang18): Change it to remove std=c++11 in cuda compile.
    set(CUDA_PROPAGATE_HOST_FLAGS OFF)
    if(NOT CUDNN_FOUND)
        message(FATAL_ERROR "Paddle need cudnn to compile")
    endif()
H
hedaoyuan 已提交
117 118 119
    set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} "-g -O3 --use_fast_math")

    if(WITH_AVX)
G
gangliao 已提交
120
        set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} "-Xcompiler ${AVX_FLAG}")
H
hedaoyuan 已提交
121
    else(WITH_AVX)
G
gangliao 已提交
122
        set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} "-Xcompiler ${SSE3_FLAG}")
H
hedaoyuan 已提交
123
    endif(WITH_AVX)
Z
zhangjinchao01 已提交
124 125 126 127 128 129 130 131 132 133 134

    if(WITH_DSO)
        add_definitions(-DPADDLE_USE_DSO)
    endif(WITH_DSO)

    # Include cuda and cudnn
    include_directories(${CUDNN_INCLUDE_DIR})
    include_directories(${CUDA_TOOLKIT_INCLUDE})
endif(NOT WITH_GPU)

if(WITH_DOUBLE)
135
    add_definitions(-DPADDLE_TYPE_DOUBLE)
Z
zhangjinchao01 已提交
136 137 138 139 140 141 142 143 144
    set(ACCURACY double)
else(WITH_DOUBLE)
    set(ACCURACY float)
endif(WITH_DOUBLE)

if(NOT WITH_TIMER)
    add_definitions(-DPADDLE_DISABLE_TIMER)
endif(NOT WITH_TIMER)

L
liaogang 已提交
145 146 147 148
if(NOT WITH_PROFILER)
    add_definitions(-DPADDLE_DISABLE_PROFILER)
endif(NOT WITH_PROFILER)

Z
zhangjinchao01 已提交
149
if(WITH_AVX)
G
gangliao 已提交
150 151
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${AVX_FLAG}")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${AVX_FLAG}")
Z
zhangjinchao01 已提交
152
else(WITH_AVX)
G
gangliao 已提交
153 154
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SSE3_FLAG}")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SSE3_FLAG}")
Z
zhangjinchao01 已提交
155 156 157 158 159 160 161 162 163
endif(WITH_AVX)

if(WITH_PYTHON)
    include_directories(${PYTHON_INCLUDE_DIR})
    include_directories(${PYTHON_NUMPY_INCLUDE_DIR})
else(WITH_PYTHON)
    add_definitions(-DPADDLE_NO_PYTHON)
endif(WITH_PYTHON)

B
backyes 已提交
164 165 166 167 168
if(WITH_RDMA)
  include_directories("${RDMA_INC_DIR}")
else(WITH_RDMA)
  add_definitions(-DPADDLE_DISABLE_RDMA)
endif(WITH_RDMA)
Z
zhangjinchao01 已提交
169 170 171

if(WITH_GLOG)
    add_definitions(-DPADDLE_USE_GLOG)
B
backyes 已提交
172
    include_directories(${LIBGLOG_INCLUDE_DIR})
Z
zhangjinchao01 已提交
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
endif()

if(WITH_GFLAGS)
    add_definitions(-DPADDLE_USE_GFLAGS)
    add_definitions(-DGFLAGS_NS=${GFLAGS_NAMESPACE})
    include_directories(${GFLAGS_INCLUDE_DIRS})
endif()

if(WITH_TESTING)
    enable_testing()
    include_directories(${GTEST_INCLUDE_DIRS})
endif()

include_directories("${CBLAS_INC_DIR}")
include_directories("${PROJ_ROOT}")
include_directories("${PROJ_ROOT}/paddle/cuda/include")
include_directories(${PROTOBUF_INCLUDE_DIRS})
include_directories("${CMAKE_CURRENT_BINARY_DIR}/proto")
if(EXISTS "${PROJ_ROOT}/paddle/internals/CMakeLists.txt")
    set(PADDLE_WITH_INTERNAL ON)
    include(paddle/internals/CMakeLists.txt)
else()
    set(PADDLE_WITH_INTERNAL OFF)
    set(INTERNAL_PROTO_PATH "")
endif()
add_subdirectory(proto)
add_subdirectory(paddle)
add_subdirectory(python)
if(WITH_DOC)
    add_subdirectory(doc)
    add_subdirectory(doc_cn)
endif()