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

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

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

Z
zhaojiaying01 已提交
17
if(IS_IOS)
18
    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 已提交
19 20 21 22
else()
    set(CMAKE_CXX_FLAGS "-std=c++14 -O3 -s ${CMAKE_CXX_FLAGS}")
endif()

L
liuruilong 已提交
23 24
if (DEBUGING)
    message(STATUS "debug")
Z
zhaojiaying01 已提交
25 26
    set(CMAKE_BUILD_TYPE Release)
    set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG")
L
liuruilong 已提交
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
    add_definitions(-DPADDLE_MOBILE_DEBUG)
else ()
    set(CMAKE_BUILD_TYPE Release)
    set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG")
    add_definitions(-fvisibility=hidden -fvisibility-inlines-hidden)
endif ()

if (USE_EXCEPTION)
    message(STATUS "use exception")
    add_definitions(-DENABLE_EXCEPTION)
    add_definitions(-fexceptions)
else()
    add_definitions(-fno-exceptions)
endif ()

if (LOG_PROFILE)
    add_definitions(-DPADDLE_MOBILE_PROFILE)
endif()

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

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

L
for  
liuruilong 已提交
56
if (CPU)
D
dolphin8 已提交
57
  add_definitions(-DPADDLE_MOBILE_CPU)
W
wangliu 已提交
58
else()
L
liuruilong 已提交
59 60 61 62
    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 已提交
63

L
liuruilong 已提交
64 65 66 67
    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 已提交
68 69 70
endif()

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

if(FPGA)
W
wangliu 已提交
96 97
    add_definitions(-DPADDLE_MOBILE_FPGA)
else()
L
liuruilong 已提交
98 99 100 101 102 103 104 105 106
    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 已提交
107

D
dolphin8 已提交
108

109 110 111 112 113 114 115 116 117 118 119
    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()

L
liuruilong 已提交
120
if (ANDROID_NDK_TOOLCHAIN_INCLUDED)
W
wangliu 已提交
121
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -llog")
W
wangliu 已提交
122
else()
123 124 125
    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)
W
wangliu 已提交
126 127
endif ()

L
liuruilong 已提交
128 129 130 131 132 133
if (IS_IOS)
else()
    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)
    list(REMOVE_ITEM PADDLE_MOBILE_H ${CMAKE_CURRENT_SOURCE_DIR}/src/ios_io/op_symbols.h)
endif ()
朔-望's avatar
朔-望 已提交
134

D
dolphin8 已提交
135 136 137 138 139
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 已提交
140

141
# NET default
H
hanbuhe 已提交
142 143
set(NET "default" CACHE STRING "select net type")
set_property(CACHE NET PROPERTY STRINGS "default" "googlenet" "mobilenet" "yolo" "squeezenet" "FPGAnets")
D
dolphin8 已提交
144
include("${CMAKE_CURRENT_LIST_DIR}/tools/op.cmake")
H
Haipeng Wang 已提交
145

146

L
liuruilong 已提交
147
# build library
D
dolphin8 已提交
148 149
if (ANDROID_NDK_TOOLCHAIN_INCLUDED)
    list(REMOVE_DUPLICATES CMAKE_CXX_FLAGS)
L
liuruilong 已提交
150
    add_library(paddle-mobile SHARED ${PADDLE_MOBILE_CC} ${PADDLE_MOBILE_H})
151
elseif(IS_IOS)
L
liuruilong 已提交
152
    add_library(paddle-mobile STATIC ${PADDLE_MOBILE_CC} ${PADDLE_MOBILE_H})
D
dolphin8 已提交
153
else ()
L
liuruilong 已提交
154 155
    add_library(paddle-mobile SHARED ${PADDLE_MOBILE_CC} ${PADDLE_MOBILE_H})
endif ()
朔-望's avatar
朔-望 已提交
156

L
liuruilong 已提交
157
# unit test
W
wangliu 已提交
158
if(DEBUGING)
L
liuruilong 已提交
159 160 161 162
    if(IS_IOS)
    else()
        add_subdirectory(test)
    endif()
W
wangliu 已提交
163
endif()
W
wangliu 已提交
164

165