CMakeLists.txt 5.2 KB
Newer Older
朔-望's avatar
朔-望 已提交
1 2
cmake_minimum_required(VERSION 3.0)
project(paddle-mobile)
W
wangliu 已提交
3

L
for  
liuruilong 已提交
4
option(DEBUGING "enable debug mode" ON)
W
wangliu 已提交
5
option(USE_OPENMP "openmp support" OFF)
L
liuruilong 已提交
6
option(USE_EXCEPTION "use std exception" ON)
L
liuruilong 已提交
7 8
option(LOG_PROFILE "log profile" ON)
# select the platform to build
S
sharper 已提交
9
option(CPU "cpu" OFF)
L
liuruilong 已提交
10
option(MALI_GPU "mali gpu" ON)
R
Ruilong Liu 已提交
11
option(FPGA "fpga" OFF)
L
for  
liuruilong 已提交
12 13 14

if (CPU)
    add_definitions(-DPADDLE_MOBILE_CPU)
L
liuruilong 已提交
15 16 17
endif()

if (MALI_GPU)
L
for  
liuruilong 已提交
18
    add_definitions(-DPADDLE_MOBILE_MALI_GPU)
S
sharper 已提交
19 20 21 22 23 24 25 26 27 28 29
    add_definitions(-DUSE_ACL=1)
    add_definitions(-DUSE_OPENCL)
    set(ACL_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/src/operators/kernel/mali/ACL_Android)
    include_directories(${ACL_ROOT} ${ACL_ROOT}/include)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -L${ACL_ROOT}/build")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -larm_compute")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -larm_compute_core")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -larm_compute_graph")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -L${ACL_ROOT}/build/opencl-1.2-stubs")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lOpenCL")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_ACL=1")
L
liuruilong 已提交
30 31 32
endif()

if(FPGA)
L
for  
liuruilong 已提交
33 34 35
    add_definitions(-DPADDLE_MOBILE_FPGA)
endif()

Z
zhaojiaying01 已提交
36
set(CMAKE_CXX_FLAGS "-std=c++14 -O3 -s ${CMAKE_CXX_FLAGS}")
W
wangliu 已提交
37
if (DEBUGING)
L
liuruilong 已提交
38
    set(CMAKE_BUILD_TYPE Debug)
Z
zhaojiaying01 已提交
39
    set(CMAKE_CXX_FLAGS_DEBUG "-O3 -DNDEBUG")
W
wangliu 已提交
40
else()
L
liuruilong 已提交
41
    set(CMAKE_BUILD_TYPE Release)
Z
zhaojiaying01 已提交
42
    set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
W
wangliu 已提交
43 44
endif ()

L
liuruilong 已提交
45 46 47
if(DEBUGING)
    message(STATUS "debuging")
    add_definitions(-DPADDLE_MOBILE_DEBUG)
W
wangliu 已提交
48 49 50 51
    if(ANDROID)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -llog")
    endif()

W
wangliu 已提交
52
else()
L
liuruilong 已提交
53 54
    message(STATUS "releasing")
    add_definitions(-fvisibility=hidden -fvisibility-inlines-hidden)
W
wangliu 已提交
55
endif()
朔-望's avatar
朔-望 已提交
56

W
wangliu 已提交
57
if (USE_EXCEPTION)
W
wangliu 已提交
58
    message(STATUS "use exception")
W
wangliu 已提交
59 60 61 62 63 64
    add_definitions(-DENABLE_EXCEPTION)
    add_definitions(-fexceptions)
else()
    add_definitions(-fno-exceptions)
endif ()

L
liuruilong 已提交
65 66 67 68
if (LOG_PROFILE)
    add_definitions(-DPADDLE_MOBILE_PROFILE)
endif()

69 70 71 72 73 74 75 76
if(IS_MAC)
    add_definitions(-DX86)
elseif(IS_IOS)
    add_definitions(-DIOS)
elseif(V7)
    add_definitions(-DARMV7)
elseif(V8)
    add_definitions(-DARMV8)
77 78 79
else ()
    add_definitions(-DX86)
endif()
Z
zhaojiaying01 已提交
80

朔-望's avatar
朔-望 已提交
81 82
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
朔-望's avatar
朔-望 已提交
83 84 85 86
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY build)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY build)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY build)

L
liuruilong 已提交
87
file(GLOB_RECURSE PADDLE_MOBILE_CC src/*.cc src/*.cpp src/*.c)
朔-望's avatar
朔-望 已提交
88 89
file(GLOB_RECURSE PADDLE_MOBILE_H src/*.h)

W
wangliu 已提交
90 91 92 93 94 95
if (NOT ANDROID)
list(REMOVE_ITEM PADDLE_MOBILE_CC ${CMAKE_CURRENT_SOURCE_DIR}/src/jni/*.cpp)
list(REMOVE_ITEM PADDLE_MOBILE_CC ${CMAKE_CURRENT_SOURCE_DIR}/src/jni/*.h)
list(REMOVE_ITEM PADDLE_MOBILE_CC ${CMAKE_CURRENT_SOURCE_DIR}/src/operators/math/math_func_neon.h)
endif ()

朔-望's avatar
朔-望 已提交
96 97
include_directories(src/)

H
Haipeng Wang 已提交
98 99
if(USE_OPENMP)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
H
Haipeng Wang 已提交
100 101 102
    add_definitions(-DPADDLE_MOBILE_USE_OPENMP)
endif()

L
liuruilong 已提交
103 104 105 106 107 108 109 110 111
if (googlenet)
    add_definitions(-DCONCAT_OP)
    add_definitions(-DCONV_OP)
    add_definitions(-DLRN_OP)
    add_definitions(-DMUL_OP)
    add_definitions(-DELEMENTWISEADD_OP)
    add_definitions(-DFUSION_FC_OP)
    add_definitions(-DPOOL_OP)
    add_definitions(-DRELU_OP)
W
wangliu 已提交
112
    add_definitions(-DFUSION_CONVADD_OP)
L
liuruilong 已提交
113
    add_definitions(-DFUSION_CONVADD_RELU_OP)
L
liuruilong 已提交
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
elseif (mobilenet)
    add_definitions(-DCONV_OP)
    add_definitions(-DELEMENTWISEADD_OP)
    add_definitions(-DRELU_OP)
    add_definitions(-DSOFTMAX_OP)
    add_definitions(-DSOFTMAX_OP)
    add_definitions(-DDEPTHWISECONV_OP)
    add_definitions(-DBATCHNORM_OP)
    add_definitions(-DPOOL_OP)
    add_definitions(-DRESHAPE_OP)
elseif (yolo)
    add_definitions(-DBATCHNORM_OP)
    add_definitions(-DCONV_OP)
    add_definitions(-DRELU_OP)
    add_definitions(-DELEMENTWISEADD_OP)
elseif (squeezenet)
    add_definitions(-DCONCAT_OP)
    add_definitions(-DCONV_OP)
    add_definitions(-DRELU_OP)
    add_definitions(-DELEMENTWISEADD_OP)
    add_definitions(-DPOOL_OP)
    add_definitions(-DRESHAPE_OP)
    add_definitions(-DSOFTMAX_OP)
elseif(resnet)
    add_definitions(-DCONV_OP)
    add_definitions(-DBATCHNORM_OP)
    add_definitions(-DELEMENTWISEADD_OP)
    add_definitions(-DSOFTMAX_OP)
    add_definitions(-DMUL_OP)
    add_definitions(-DPOOL_OP)
    add_definitions(-DRELU_OP)
else ()
    add_definitions(-DBATCHNORM_OP)
    add_definitions(-DBOXCODER_OP)
    add_definitions(-DCONCAT_OP)
    add_definitions(-DCONV_OP)
    add_definitions(-DDEPTHWISECONV_OP)
    add_definitions(-DELEMENTWISEADD_OP)
W
wangliu 已提交
152
    add_definitions(-DFUSION_CONVADD_OP)
L
liuruilong 已提交
153 154 155 156 157 158 159 160 161 162 163 164
    add_definitions(-DCONVADDRELU_OP)
    add_definitions(-DFUSION_FC_OP)
    add_definitions(-DLRN_OP)
    add_definitions(-DMUL_OP)
    add_definitions(-DMULTICLASSNMS_OP)
    add_definitions(-DPOOL_OP)
    add_definitions(-DPRIORBOX_OP)
    add_definitions(-DRELU_OP)
    add_definitions(-DRESHAPE_OP)
    add_definitions(-DSIGMOID_OP)
    add_definitions(-DSOFTMAX_OP)
    add_definitions(-DTRANSPOSE_OP)
L
liuruilong 已提交
165
    add_definitions(-DFUSION_CONVADD_RELU_OP)
H
Haipeng Wang 已提交
166 167
endif()

L
liuruilong 已提交
168 169 170 171 172 173 174
if (IS_IOS)
    add_library(paddle-mobile STATIC ${PADDLE_MOBILE_CC} ${PADDLE_MOBILE_H})
elseif(ANDROID)
    add_library(paddle-mobile SHARED ${PADDLE_MOBILE_CC} ${PADDLE_MOBILE_H})
else()
    add_library(paddle-mobile SHARED ${PADDLE_MOBILE_CC} ${PADDLE_MOBILE_H})
endif ()
朔-望's avatar
朔-望 已提交
175

W
wangliu 已提交
176
if(DEBUGING)
L
liuruilong 已提交
177
    add_subdirectory(test)
W
wangliu 已提交
178
endif()
W
wangliu 已提交
179 180