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

3
# basic build option
4 5 6 7 8
if(IS_IOS)
    option(USE_OPENMP       "build with openmp support"      OFF)
else()
    option(USE_OPENMP       "build with openmp support"      ON)
endif()
9 10 11 12 13 14 15 16 17 18
option(USE_EXCEPTION    "build with exception"           ON)
option(WITH_LOGGING     "print logging for debug"        OFF)
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)

# select platform: CPU, GPU_CL, FPGA
option(CPU              "build with arm CPU support"     ON)
option(GPU_CL           "build with OpenCL support"      OFF)
option(FPGA             "build with FPGA support"        OFF)
Z
zhangyang 已提交
19
if(FPGA)
20 21 22
  option(FPGAV1     "build with fpga v1 support"   ON)
  option(FPGAV2     "build with fpga v2 support"   OFF)
  option(FPGAKD     "build with fpga KD support"   OFF)
Z
zhangyang 已提交
23
endif()
W
wangliu 已提交
24

L
liuruilong 已提交
25
project(paddle-mobile)
W
wangliu 已提交
26

27
# source code
28
file(GLOB_RECURSE PADDLE_MOBILE_CC src/*.cc src/*.cpp src/*.c src/*.mm)
W
wangliu 已提交
29
file(GLOB_RECURSE PADDLE_MOBILE_H src/*.h)
L
liuruilong 已提交
30 31
include_directories(src/)

32
# build flags
33
set(CMAKE_CXX_FLAGS "-O3 -s -DNDEBUG ${CMAKE_CXX_FLAGS} -Wno-attributes")
Z
zhaojiaying01 已提交
34
if(IS_IOS)
H
hjchen2 已提交
35 36
    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}")
37
    add_compile_options(-fembed-bitcode)
Z
zhaojiaying01 已提交
38
else()
39
    set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
Z
zhaojiaying01 已提交
40 41
endif()

42
# others
H
hjchen2 已提交
43 44 45 46 47 48
if(USE_OPENMP)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
    add_definitions(-DPADDLE_MOBILE_USE_OPENMP)
endif()

if(WITH_LOGGING)
49
    message(STATUS "Debugging mode")
L
liuruilong 已提交
50
    add_definitions(-DPADDLE_MOBILE_DEBUG)
51
else()
L
liuruilong 已提交
52 53
endif()

H
hjchen2 已提交
54
if(NOT WITH_SYMBOL)
L
liuruilong 已提交
55
    add_definitions(-fvisibility=hidden -fvisibility-inlines-hidden)
56
endif()
L
liuruilong 已提交
57

58
if(USE_EXCEPTION)
59
    message(STATUS "Use exception")
H
hjchen2 已提交
60
    add_definitions(-DENABLE_EXCEPTION -fexceptions)
L
liuruilong 已提交
61 62
else()
    add_definitions(-fno-exceptions)
63
endif()
L
liuruilong 已提交
64

H
hjchen2 已提交
65
if(WITH_PROFILE)
L
liuruilong 已提交
66 67 68 69
    add_definitions(-DPADDLE_MOBILE_PROFILE)
endif()

# platform control
70
if(ARM_LINUX)
L
liuruilong 已提交
71
    include("${CMAKE_CURRENT_LIST_DIR}/tools/arm-platform.cmake")
72
endif()
W
wangliu 已提交
73

74 75
if(CPU)
    add_definitions(-DPADDLE_MOBILE_CPU)
W
wangliu 已提交
76
else()
L
liuruilong 已提交
77 78 79 80
    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 已提交
81

L
liuruilong 已提交
82 83 84 85
    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 已提交
86 87
endif()

Z
zhaojiaying01 已提交
88 89
if (GPU_CL)
    add_definitions(-DPADDLE_MOBILE_CL)
L
liuruilong 已提交
90 91 92 93

    # opencl version
    add_definitions(-DCL_TARGET_OPENCL_VERSION=220)

D
dolphin8 已提交
94
    link_libraries(${CMAKE_CURRENT_LIST_DIR}/third_party/opencl/libOpenCL.so)
L
liuruilong 已提交
95
    include_directories(third_party/opencl/OpenCL-Headers)
Z
zhaojiaying01 已提交
96 97 98 99 100 101 102 103 104 105 106 107
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()

L
liuruilong 已提交
108
if(FPGA)
C
Chon 已提交
109
    file(GLOB_RECURSE _tmp_list src/operators/math/*.cpp src/operators/math/*.cc src/operators/kernel/fpga/*.cc)
Z
zhangyang 已提交
110 111 112 113 114 115 116 117 118 119 120
    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)
C
Chon 已提交
121
        add_definitions(-DPADDLE_MOBILE_FPGA)
Z
zhangyang 已提交
122 123 124 125 126 127 128 129
        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})
130
            list(REMOVE_ITEM PADDLE_MOBILE_H ${f})
Z
zhangyang 已提交
131
        endforeach()
C
Chon 已提交
132 133 134 135 136 137 138 139 140
        file(GLOB_RECURSE _tmp_list src/operators/kernel/fpga/KD/*.cpp src/fpga/KD/*.cpp)
        foreach(f ${_tmp_list})
            list(REMOVE_ITEM PADDLE_MOBILE_CC ${f})
        endforeach()
        file(GLOB_RECURSE _tmp_list src/operators/kernel/fpga/KD/*.h src/operators/kernel/fpga/KD/*.hpp
            src/fpga/KD/*.h src/fpga/KD/*.hpp)
        foreach(f ${_tmp_list})
            list(REMOVE_ITEM PADDLE_MOBILE_H ${f})
        endforeach()
Z
zhangyang 已提交
141 142
    endif()
    if(FPGAV2)
C
Chon 已提交
143
        add_definitions(-DPADDLE_MOBILE_FPGA)
Z
zhangyang 已提交
144 145 146 147 148 149 150 151
        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})
152
            list(REMOVE_ITEM PADDLE_MOBILE_H ${f})
Z
zhangyang 已提交
153
        endforeach()
C
Chon 已提交
154 155 156 157 158 159 160 161 162
        file(GLOB_RECURSE _tmp_list src/operators/kernel/fpga/KD/*.cpp src/fpga/KD/*.cpp)
        foreach(f ${_tmp_list})
            list(REMOVE_ITEM PADDLE_MOBILE_CC ${f})
        endforeach()
        file(GLOB_RECURSE _tmp_list src/operators/kernel/fpga/KD/*.h src/operators/kernel/fpga/KD/*.hpp
            src/fpga/KD/*.h src/fpga/KD/*.hpp)
        foreach(f ${_tmp_list})
            list(REMOVE_ITEM PADDLE_MOBILE_H ${f})
        endforeach()
Z
zhangyang 已提交
163
    endif()
C
Chon 已提交
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
    if(FPGAKD)
        message("FPGAKD enabled")
        add_definitions(-DPADDLE_MOBILE_FPGA_KD)
        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})
            list(REMOVE_ITEM PADDLE_MOBILE_H ${f})
        endforeach()
        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})
            list(REMOVE_ITEM PADDLE_MOBILE_H ${f})
        endforeach()

        file(GLOB_RECURSE _tmp_list src/operators/kernel/central-arm-func/*.h)
        foreach(f ${_tmp_list})
            list(APPEND PADDLE_MOBILE_H ${f})
        endforeach()
        file(GLOB_RECURSE _tmp_list src/operators/kernel/central-arm-func/*.cpp)
        foreach(f ${_tmp_list})
            list(APPEND PADDLE_MOBILE_CC ${f})
        endforeach()
Z
zhangyang 已提交
192

C
Chon 已提交
193
    endif()
W
wangliu 已提交
194
else()
L
liuruilong 已提交
195 196 197 198 199 200 201 202 203
    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 已提交
204

D
dolphin8 已提交
205

206 207 208 209 210 211 212 213 214 215 216
    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()

217
if(ANDROID_NDK_TOOLCHAIN_INCLUDED)
W
wangliu 已提交
218
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -llog")
W
wangliu 已提交
219
else()
L
liuruilong 已提交
220 221
    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)
222
    list(REMOVE_ITEM PADDLE_MOBILE_H ${CMAKE_CURRENT_SOURCE_DIR}/src/operators/math/math_func_neon.h)
223
endif()
W
wangliu 已提交
224

225
if(IS_IOS)
L
liuruilong 已提交
226
else()
L
liuruilong 已提交
227 228 229
    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 已提交
230
endif ()
朔-望's avatar
朔-望 已提交
231

D
dolphin8 已提交
232 233 234 235 236
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 已提交
237

238
# NET default
Z
zhangyang 已提交
239 240 241 242
if(FPGAV1)
    set(NET "FPGA_NET_V1" CACHE STRING "select net type")
elseif(FPGAV2)
    set(NET "FPGA_NET_V2" CACHE STRING "select net type")
C
Chon 已提交
243 244
elseif(FPGAKD)
    set(NET "FPGA_OPS_KD" CACHE STRING "select net type")
245
else()
246
    set(NET "default"     CACHE STRING "select net type")
247 248
endif()

249
set_property(CACHE NET PROPERTY STRINGS "default" "googlenet" "mobilenet" "yolo" "squeezenet" "FPGA_NET_V1" "FPGA_NET_V2" "NLP" "op")
D
dolphin8 已提交
250
include("${CMAKE_CURRENT_LIST_DIR}/tools/op.cmake")
H
Haipeng Wang 已提交
251

L
liuruilong 已提交
252
# build library
253
if(ANDROID_NDK_TOOLCHAIN_INCLUDED)
D
dolphin8 已提交
254
    list(REMOVE_DUPLICATES CMAKE_CXX_FLAGS)
H
hjchen2 已提交
255
    add_library(paddle-mobile SHARED ${PADDLE_MOBILE_CC} ${PADDLE_MOBILE_H})
256
elseif(IS_IOS)
257 258 259 260 261 262 263 264 265 266 267
    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()
268
else()
H
hjchen2 已提交
269
  add_library(paddle-mobile SHARED ${PADDLE_MOBILE_CC} ${PADDLE_MOBILE_H})
270
endif()
朔-望's avatar
朔-望 已提交
271

L
liuruilong 已提交
272
# unit test
H
hjchen2 已提交
273
if(WITH_TEST AND WITH_SYMBOL)
L
liuruilong 已提交
274 275 276 277
    if(IS_IOS)
    else()
        add_subdirectory(test)
    endif()
Z
zhangyang 已提交
278 279
elseif(FPGA)
    add_subdirectory(test)
W
wangliu 已提交
280
endif()
281 282 283 284 285 286 287 288

# # if you want to combine third party static librares into paddle mobile so, please uncomment this code block
# target_link_libraries(
#     paddle-mobile
#     -Wl,--whole-archive
#     "path_to_third_party_static_library"
#     -Wl,--no-whole-archive
# )