CMakeLists.txt 5.9 KB
Newer Older
W
wangliu 已提交
1
cmake_minimum_required(VERSION 3.6)
2
option(USE_OPENMP "openmp support" OFF)
D
dolphin8 已提交
3

朔-望's avatar
朔-望 已提交
4
project(paddle-mobile)
W
wangliu 已提交
5

6
option(DEBUGING "enable debug mode" ON)
L
liuruilong 已提交
7 8
option(USE_EXCEPTION "use std exception" OFF)
option(LOG_PROFILE "log profile" OFF)
L
liuruilong 已提交
9
# select the platform to build
10
option(X86 "x86" OFF)
Z
zhaojiaying01 已提交
11
option(CPU "armv7 with neon" ON)
W
wangliu 已提交
12
option(MALI_GPU "mali gpu" OFF)
Z
zhaojiaying01 已提交
13
option(FPGA "fpga" OFF)
W
wangliu 已提交
14

15
file(GLOB_RECURSE PADDLE_MOBILE_CC src/*.cc src/*.cpp src/*.c src/*.mm)
W
wangliu 已提交
16
file(GLOB_RECURSE PADDLE_MOBILE_H src/*.h)
L
liuruilong 已提交
17 18
include_directories(src/)

Z
zhaojiaying01 已提交
19
if(IS_IOS)
20
    set(CMAKE_CXX_FLAGS "-mfpu=neon -marm -fobjc-abi-version=2 -fobjc-arc -std=gnu++11 -stdlib=libc++ -O3 -s -isysroot ${CMAKE_OSX_SYSROOT} ${CMAKE_CXX_FLAGS}")
Z
zhaojiaying01 已提交
21
else()
22
    set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
Z
zhaojiaying01 已提交
23 24
endif()

25
if(DEBUGING)
L
liuruilong 已提交
26
    message(STATUS "debug")
27 28
    set(CMAKE_BUILD_TYPE debug)
    set(CMAKE_CXX_FLAGS "-O0 -g ${CMAKE_CXX_FLAGS}")
L
liuruilong 已提交
29
    add_definitions(-DPADDLE_MOBILE_DEBUG)
30
else()
L
liuruilong 已提交
31
    set(CMAKE_BUILD_TYPE Release)
32
    set(CMAKE_CXX_FLAGS "-Os ${CMAKE_CXX_FLAGS}")
L
liuruilong 已提交
33
    set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG")
34
endif()
L
liuruilong 已提交
35

36
if(USE_EXCEPTION)
L
liuruilong 已提交
37 38 39 40 41
    message(STATUS "use exception")
    add_definitions(-DENABLE_EXCEPTION)
    add_definitions(-fexceptions)
else()
    add_definitions(-fno-exceptions)
42
endif()
L
liuruilong 已提交
43

44
if(LOG_PROFILE)
L
liuruilong 已提交
45 46 47
    add_definitions(-DPADDLE_MOBILE_PROFILE)
endif()

48
if(USE_OPENMP AND NOT IS_IOS)
L
liuruilong 已提交
49 50 51 52 53
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
    add_definitions(-DPADDLE_MOBILE_USE_OPENMP)
endif()

# platform control
54
if(ARM_LINUX)
L
liuruilong 已提交
55
    include("${CMAKE_CURRENT_LIST_DIR}/tools/arm-platform.cmake")
56
endif()
W
wangliu 已提交
57

58 59 60 61
if(CPU)
    add_definitions(-DPADDLE_MOBILE_CPU)
elseif(X86)
    add_definitions(-DPADDLE_MOBILE_X86)
W
wangliu 已提交
62
else()
L
liuruilong 已提交
63 64 65 66
    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 已提交
67

L
liuruilong 已提交
68 69 70 71
    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 已提交
72 73
endif()

74
if(MALI_GPU)
L
for  
liuruilong 已提交
75
    add_definitions(-DPADDLE_MOBILE_MALI_GPU)
S
sharper 已提交
76 77 78 79 80 81 82 83 84 85 86
    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 已提交
87
else()
88 89 90 91 92 93 94 95 96
    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 已提交
97 98 99
endif()

if(FPGA)
100 101
    set(DEBUGING ON)
    add_definitions(-DPADDLE_MOBILE_DEBUG)
W
wangliu 已提交
102 103
    add_definitions(-DPADDLE_MOBILE_FPGA)
else()
L
liuruilong 已提交
104 105 106 107 108 109 110 111 112
    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 已提交
113

D
dolphin8 已提交
114

115 116 117 118 119 120 121 122 123 124 125
    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()

126
if(ANDROID_NDK_TOOLCHAIN_INCLUDED)
W
wangliu 已提交
127
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -llog")
W
wangliu 已提交
128
else()
129 130 131
    list(REMOVE_ITEM PADDLE_MOBILE_H ${CMAKE_CURRENT_SOURCE_DIR}/src/jni/paddle_mobile_jni.h)
    list(REMOVE_ITEM PADDLE_MOBILE_CC ${CMAKE_CURRENT_SOURCE_DIR}/src/jni/paddle_mobile_jni.cpp)
    list(REMOVE_ITEM PADDLE_MOBILE_H ${CMAKE_CURRENT_SOURCE_DIR}/src/operators/math/math_func_neon.h)
132
endif()
W
wangliu 已提交
133

134
if(IS_IOS)
L
liuruilong 已提交
135
else()
136 137
    list(REMOVE_ITEM PADDLE_MOBILE_H ${CMAKE_CURRENT_SOURCE_DIR}/src/ios_io/PaddleMobile.h)
    list(REMOVE_ITEM PADDLE_MOBILE_CC ${CMAKE_CURRENT_SOURCE_DIR}/src/ios_io/PaddleMobile.mm)
L
liuruilong 已提交
138
    list(REMOVE_ITEM PADDLE_MOBILE_H ${CMAKE_CURRENT_SOURCE_DIR}/src/ios_io/op_symbols.h)
139
endif()
朔-望's avatar
朔-望 已提交
140

D
dolphin8 已提交
141 142 143 144 145
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 已提交
146

147
# NET default
148
if(FPGA)
149 150 151 152 153
    set(NET "FPGAnets" CACHE STRING "select net type")
else()
    set(NET "default" CACHE STRING "select net type")
endif()

154
set_property(CACHE NET PROPERTY STRINGS "default" "googlenet" "mobilenet" "yolo" "squeezenet" "FPGAnets" "NLP")
D
dolphin8 已提交
155
include("${CMAKE_CURRENT_LIST_DIR}/tools/op.cmake")
H
Haipeng Wang 已提交
156

157

L
liuruilong 已提交
158
# build library
159
if(ANDROID_NDK_TOOLCHAIN_INCLUDED)
D
dolphin8 已提交
160
    list(REMOVE_DUPLICATES CMAKE_CXX_FLAGS)
L
liuruilong 已提交
161
    add_library(paddle-mobile SHARED ${PADDLE_MOBILE_CC} ${PADDLE_MOBILE_H})
162
elseif(IS_IOS)
163 164 165 166 167 168 169 170 171 172 173
    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()
174 175 176
else()
  add_library(paddle-mobile SHARED ${PADDLE_MOBILE_CC} ${PADDLE_MOBILE_H})
endif()
朔-望's avatar
朔-望 已提交
177

L
liuruilong 已提交
178
# unit test
W
wangliu 已提交
179
if(DEBUGING)
L
liuruilong 已提交
180 181 182 183
    if(IS_IOS)
    else()
        add_subdirectory(test)
    endif()
W
wangliu 已提交
184
endif()
W
wangliu 已提交
185

186