CMakeLists.txt 8.4 KB
Newer Older
1
cmake_minimum_required(VERSION 3.10.0)
H
hjchen2 已提交
2

H
hjchen2 已提交
3 4 5 6 7 8
option(USE_OPENMP    "build with openmp support" ON)
option(USE_EXCEPTION "build with exception" ON)
option(WITH_LOGGING  "print logging for debug" ON)
option(WITH_SYMBOL   "build with all symbols" ON) # turn off if use jni or ios io
option(WITH_PROFILE  "print op profile for debug" OFF)
option(WITH_TEST     "build with unit tests" ON)
H
hjchen2 已提交
9

L
liuruilong 已提交
10
# select the platform to build
H
hjchen2 已提交
11 12 13 14
option(CPU        "build with arm CPU support" ON)
option(GPU_MALI   "build with arm mali GPU support" OFF)
option(GPU_CL     "build with OpenCL support" OFF)
option(FPGA       "build with FPGA support" OFF)
Z
zhangyang 已提交
15
if(FPGA)
H
hjchen2 已提交
16 17
  option(FPGAV1     "build with fpga v1 support" ON)
  option(FPGAV2     "build with fpga v2 support" OFF)
Z
zhangyang 已提交
18
endif()
W
wangliu 已提交
19

L
liuruilong 已提交
20
project(paddle-mobile)
W
wangliu 已提交
21

22
file(GLOB_RECURSE PADDLE_MOBILE_CC src/*.cc src/*.cpp src/*.c src/*.mm)
W
wangliu 已提交
23
file(GLOB_RECURSE PADDLE_MOBILE_H src/*.h)
L
liuruilong 已提交
24 25
include_directories(src/)

H
hjchen2 已提交
26
set(CMAKE_CXX_FLAGS "-O3 -s -DNDEBUG ${CMAKE_CXX_FLAGS}")
Z
zhaojiaying01 已提交
27
if(IS_IOS)
H
hjchen2 已提交
28 29
    set(CMAKE_CXX_FLAGS "-mfpu=neon -marm -fobjc-abi-version=2 -fobjc-arc \
        -std=gnu++11 -stdlib=libc++ -isysroot ${CMAKE_OSX_SYSROOT} ${CMAKE_CXX_FLAGS}")
30
    add_compile_options(-fembed-bitcode)
Z
zhaojiaying01 已提交
31
else()
32
    set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
Z
zhaojiaying01 已提交
33 34
endif()

H
hjchen2 已提交
35 36 37 38 39 40
if(USE_OPENMP)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
    add_definitions(-DPADDLE_MOBILE_USE_OPENMP)
endif()

if(WITH_LOGGING)
H
hjchen2 已提交
41
    message(STATUS "debugging mode")
L
liuruilong 已提交
42
    add_definitions(-DPADDLE_MOBILE_DEBUG)
43
else()
L
liuruilong 已提交
44 45
endif()

H
hjchen2 已提交
46
if(NOT WITH_SYMBOL)
L
liuruilong 已提交
47
    add_definitions(-fvisibility=hidden -fvisibility-inlines-hidden)
48
endif()
L
liuruilong 已提交
49

50
if(USE_EXCEPTION)
L
liuruilong 已提交
51
    message(STATUS "use exception")
H
hjchen2 已提交
52
    add_definitions(-DENABLE_EXCEPTION -fexceptions)
L
liuruilong 已提交
53 54
else()
    add_definitions(-fno-exceptions)
55
endif()
L
liuruilong 已提交
56

H
hjchen2 已提交
57
if(WITH_PROFILE)
L
liuruilong 已提交
58 59 60 61
    add_definitions(-DPADDLE_MOBILE_PROFILE)
endif()

# platform control
62
if(ARM_LINUX)
L
liuruilong 已提交
63
    include("${CMAKE_CURRENT_LIST_DIR}/tools/arm-platform.cmake")
64
endif()
W
wangliu 已提交
65

66 67
if(CPU)
    add_definitions(-DPADDLE_MOBILE_CPU)
W
wangliu 已提交
68
else()
L
liuruilong 已提交
69 70 71 72
    file(GLOB_RECURSE _tmp_list src/operators/kernel/arm/*.cpp src/operators/kernel/arm/*.cc)
    foreach(f ${_tmp_list})
        list(REMOVE_ITEM PADDLE_MOBILE_CC ${f})
    endforeach()
W
wangliu 已提交
73

L
liuruilong 已提交
74 75 76 77
    file(GLOB_RECURSE _tmp_list_h src/operators/kernel/arm/*.h)
    foreach(f ${_tmp_list_h})
        list(REMOVE_ITEM PADDLE_MOBILE_H ${f})
    endforeach()
L
liuruilong 已提交
78 79
endif()

Z
zhaojiaying01 已提交
80 81
if (GPU_CL)
    add_definitions(-DPADDLE_MOBILE_CL)
L
liuruilong 已提交
82 83 84 85

    # opencl version
    add_definitions(-DCL_TARGET_OPENCL_VERSION=220)

D
dolphin8 已提交
86
    link_libraries(${CMAKE_CURRENT_LIST_DIR}/third_party/opencl/libOpenCL.so)
L
liuruilong 已提交
87
    include_directories(third_party/opencl/OpenCL-Headers)
Z
zhaojiaying01 已提交
88 89 90 91 92 93 94 95 96 97 98 99 100
else()
    file(GLOB_RECURSE _tmp_list src/framework/cl/*.cpp src/operators/kernel/cl/*.cpp)
    foreach(f ${_tmp_list})
        list(REMOVE_ITEM PADDLE_MOBILE_CC ${f})
    endforeach()

    file(GLOB_RECURSE _tmp_list_h src/framework/cl/*.h)
    foreach(f ${_tmp_list_h})
        list(REMOVE_ITEM PADDLE_MOBILE_H ${f})
    endforeach()
endif()

if (GPU_MALI)
L
for  
liuruilong 已提交
101
    add_definitions(-DPADDLE_MOBILE_MALI_GPU)
S
sharper 已提交
102 103 104 105 106 107 108 109 110 111 112
    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")
W
wangliu 已提交
113
else()
114 115 116 117 118 119 120 121 122
    file(GLOB_RECURSE _tmp_list src/operators/kernel/mali/*.cpp src/operators/kernel/mali/*.cc)
    foreach(f ${_tmp_list})
        list(REMOVE_ITEM PADDLE_MOBILE_CC ${f})
    endforeach()

    file(GLOB_RECURSE _tmp_list_h src/operators/kernel/mali/*.h)
    foreach(f ${_tmp_list_h})
        list(REMOVE_ITEM PADDLE_MOBILE_H ${f})
    endforeach()
L
liuruilong 已提交
123 124 125
endif()

if(FPGA)
W
wangliu 已提交
126
    add_definitions(-DPADDLE_MOBILE_FPGA)
Z
zhangyang 已提交
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
    file(GLOB_RECURSE _tmp_list src/operators/math/*.cpp src/operators/kernel/fpga/*.cc)
    foreach(f ${_tmp_list})
        list(REMOVE_ITEM PADDLE_MOBILE_CC ${f})
    endforeach()
    file(GLOB_RECURSE _tmp_list_h src/operators/math/*.h)
    foreach(f ${_tmp_list_h})
        list(REMOVE_ITEM PADDLE_MOBILE_H ${f})
    endforeach()
    list(APPEND PADDLE_MOBILE_CC src/operators/math/softmax.cpp)
    list(APPEND PADDLE_MOBILE_h src/operators/math/softmax.h)
    list(APPEND PADDLE_MOBILE_h src/operators/math/math_func_neon.h)
    if(FPGAV1)
        message("FPGA_V1 enabled")
        add_definitions(-DPADDLE_MOBILE_FPGA_V1)
        file(GLOB_RECURSE _tmp_list src/operators/kernel/fpga/V2/*.cpp src/fpga/V2/*.cpp)
        foreach(f ${_tmp_list})
            list(REMOVE_ITEM PADDLE_MOBILE_CC ${f})
        endforeach()
        file(GLOB_RECURSE _tmp_list src/operators/kernel/fpga/V2/*.h src/fpga/V2/*.h)
        foreach(f ${_tmp_list})
147
            list(REMOVE_ITEM PADDLE_MOBILE_H ${f})
Z
zhangyang 已提交
148 149 150 151 152 153 154 155 156 157 158
        endforeach()
    endif()
    if(FPGAV2)
        message("FPGA_V2 enabled")
        add_definitions(-DPADDLE_MOBILE_FPGA_V2)
        file(GLOB_RECURSE _tmp_list src/operators/kernel/fpga/V1/*.cpp src/fpga/V1/*.cpp)
        foreach(f ${_tmp_list})
            list(REMOVE_ITEM PADDLE_MOBILE_CC ${f})
        endforeach()
        file(GLOB_RECURSE _tmp_list src/operators/kernel/fpga/V1/*.h src/fpga/V1/*.h)
        foreach(f ${_tmp_list})
159
            list(REMOVE_ITEM PADDLE_MOBILE_H ${f})
Z
zhangyang 已提交
160 161 162
        endforeach()
    endif()

W
wangliu 已提交
163
else()
L
liuruilong 已提交
164 165 166 167 168 169 170 171 172
    file(GLOB_RECURSE _tmp_list src/operators/kernel/fpga/*.cpp src/operators/kernel/fpga/*.cc)
    foreach(f ${_tmp_list})
        list(REMOVE_ITEM PADDLE_MOBILE_CC ${f})
    endforeach()

    file(GLOB_RECURSE _tmp_list_h src/operators/kernel/fpga/*.h)
    foreach(f ${_tmp_list_h})
        list(REMOVE_ITEM PADDLE_MOBILE_H ${f})
    endforeach()
L
for  
liuruilong 已提交
173

D
dolphin8 已提交
174

175 176 177 178 179 180 181 182 183 184 185
    file(GLOB_RECURSE _tmp_list src/fpga/*.cpp src/fpga/*.cc)
    foreach(f ${_tmp_list})
        list(REMOVE_ITEM PADDLE_MOBILE_CC ${f})
    endforeach()

    file(GLOB_RECURSE _tmp_list_h src/fpga/*.h)
    foreach(f ${_tmp_list_h})
        list(REMOVE_ITEM PADDLE_MOBILE_H ${f})
    endforeach()
endif()

186
if(ANDROID_NDK_TOOLCHAIN_INCLUDED)
W
wangliu 已提交
187
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -llog")
W
wangliu 已提交
188
else()
L
liuruilong 已提交
189 190
    list(REMOVE_ITEM PADDLE_MOBILE_H ${CMAKE_CURRENT_SOURCE_DIR}/src/io/jni/paddle_mobile_jni.h)
    list(REMOVE_ITEM PADDLE_MOBILE_CC ${CMAKE_CURRENT_SOURCE_DIR}/src/io/jni/paddle_mobile_jni.cpp)
191
    list(REMOVE_ITEM PADDLE_MOBILE_H ${CMAKE_CURRENT_SOURCE_DIR}/src/operators/math/math_func_neon.h)
192
endif()
W
wangliu 已提交
193

194
if(IS_IOS)
L
liuruilong 已提交
195
else()
L
liuruilong 已提交
196 197 198
    list(REMOVE_ITEM PADDLE_MOBILE_H ${CMAKE_CURRENT_SOURCE_DIR}/src/io/ios_io/PaddleMobileCPU.h)
    list(REMOVE_ITEM PADDLE_MOBILE_CC ${CMAKE_CURRENT_SOURCE_DIR}/src/io/ios_io/PaddleMobileCPU.mm)
    list(REMOVE_ITEM PADDLE_MOBILE_H ${CMAKE_CURRENT_SOURCE_DIR}/src/io/ios_io/op_symbols.h)
L
liuruilong 已提交
199
endif ()
朔-望's avatar
朔-望 已提交
200

D
dolphin8 已提交
201 202 203 204 205
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY build)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY build)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY build)
H
Haipeng Wang 已提交
206

207
# NET default
Z
zhangyang 已提交
208 209 210 211
if(FPGAV1)
    set(NET "FPGA_NET_V1" CACHE STRING "select net type")
elseif(FPGAV2)
    set(NET "FPGA_NET_V2" CACHE STRING "select net type")
212 213 214 215
else()
    set(NET "default" CACHE STRING "select net type")
endif()

qnqinan's avatar
qnqinan 已提交
216
set_property(CACHE NET PROPERTY STRINGS "default" "googlenet" "mobilenet" "yolo" "squeezenet" "FPGA_NET_V1" "FPGA_NET_V2" "NLP")
D
dolphin8 已提交
217
include("${CMAKE_CURRENT_LIST_DIR}/tools/op.cmake")
H
Haipeng Wang 已提交
218

L
liuruilong 已提交
219
# build library
220
if(ANDROID_NDK_TOOLCHAIN_INCLUDED)
D
dolphin8 已提交
221
    list(REMOVE_DUPLICATES CMAKE_CXX_FLAGS)
H
hjchen2 已提交
222
    add_library(paddle-mobile SHARED ${PADDLE_MOBILE_CC} ${PADDLE_MOBILE_H})
223
elseif(IS_IOS)
224 225 226 227 228 229 230 231 232 233 234
    if(USE_OPENMP)
        add_library(paddle-mobile-stage0 STATIC ${PADDLE_MOBILE_CC} ${PADDLE_MOBILE_H})
        add_custom_target(paddle-mobile ALL
            COMMAND libtool -static -o ${CMAKE_BINARY_DIR}/libpaddle-mobile.a ${CMAKE_CURRENT_LIST_DIR}/tools/libomp.a $<TARGET_FILE:paddle-mobile-stage0>
            WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
            DEPENDS paddle-mobile
        )
        add_dependencies(paddle-mobile paddle-mobile-stage0)
    else()
        add_library(paddle-mobile STATIC ${PADDLE_MOBILE_CC} ${PADDLE_MOBILE_H})
    endif()
235
else()
H
hjchen2 已提交
236
  add_library(paddle-mobile SHARED ${PADDLE_MOBILE_CC} ${PADDLE_MOBILE_H})
237
endif()
朔-望's avatar
朔-望 已提交
238

L
liuruilong 已提交
239
# unit test
H
hjchen2 已提交
240
if(WITH_TEST AND WITH_SYMBOL)
L
liuruilong 已提交
241 242 243 244
    if(IS_IOS)
    else()
        add_subdirectory(test)
    endif()
Z
zhangyang 已提交
245 246
elseif(FPGA)
    add_subdirectory(test)
W
wangliu 已提交
247
endif()
W
wangliu 已提交
248