CMakeLists.txt 4.6 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" ON)
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
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

D
dolphin8 已提交
13 14 15 16
if (ARM_LINUX)
include("${CMAKE_CURRENT_LIST_DIR}/tools/arm-platform.cmake")
endif ()

17
file(GLOB_RECURSE PADDLE_MOBILE_CC src/*.cc src/*.cpp src/*.c src/*.mm)
W
wangliu 已提交
18 19
file(GLOB_RECURSE PADDLE_MOBILE_H src/*.h)

L
for  
liuruilong 已提交
20
if (CPU)
D
dolphin8 已提交
21
  add_definitions(-DPADDLE_MOBILE_CPU)
W
wangliu 已提交
22
else()
23 24 25
    list(REMOVE_ITEM PADDLE_MOBILE_CC ./src/operators/kernel/arm/*.h)
    list(REMOVE_ITEM PADDLE_MOBILE_CC ./src/operators/kernel/arm/*.cc)
    list(REMOVE_ITEM PADDLE_MOBILE_CC ./src/operators/kernel/arm/*.cpp)
W
wangliu 已提交
26

L
liuruilong 已提交
27 28 29
endif()

if (MALI_GPU)
L
for  
liuruilong 已提交
30
    add_definitions(-DPADDLE_MOBILE_MALI_GPU)
S
sharper 已提交
31 32 33 34 35 36 37 38 39 40 41
    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 已提交
42
else()
43 44 45 46 47 48 49 50 51
    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 已提交
52 53 54
endif()

if(FPGA)
W
wangliu 已提交
55 56 57 58 59
    add_definitions(-DPADDLE_MOBILE_FPGA)
else()
    list(REMOVE_ITEM PADDLE_MOBILE_CC ${CMAKE_CURRENT_SOURCE_DIR}/src/operators/kernel/fpga/*.h)
    list(REMOVE_ITEM PADDLE_MOBILE_CC ${CMAKE_CURRENT_SOURCE_DIR}/src/operators/kernel/fpga/*.cc)
    list(REMOVE_ITEM PADDLE_MOBILE_CC ${CMAKE_CURRENT_SOURCE_DIR}/src/operators/kernel/fpga/*.cpp)
L
for  
liuruilong 已提交
60 61
endif()

D
dolphin8 已提交
62

Z
zhaojiaying01 已提交
63
set(CMAKE_CXX_FLAGS "-std=c++14 -O3 -s ${CMAKE_CXX_FLAGS}")
D
dolphin8 已提交
64 65 66
if (DEBUGING)
  message(STATUS "debug")
  set(CMAKE_BUILD_TYPE Debug)
D
dolphin8 已提交
67
  set(CMAKE_CXX_FLAGS_DEBUG "-g -DNDEBUG")
D
dolphin8 已提交
68 69 70
  add_definitions(-DPADDLE_MOBILE_DEBUG)
  if (ANDROID_NDK_TOOLCHAIN_INCLUDED)
    add_definitions(-DARMV7)
W
wangliu 已提交
71
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -llog")
D
dolphin8 已提交
72 73 74
  endif ()
else ()
  set(CMAKE_BUILD_TYPE Release)
D
dolphin8 已提交
75
  set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG")
D
dolphin8 已提交
76 77
  add_definitions(-fvisibility=hidden -fvisibility-inlines-hidden)
endif ()
朔-望's avatar
朔-望 已提交
78

W
wangliu 已提交
79
if (USE_EXCEPTION)
W
wangliu 已提交
80
    message(STATUS "use exception")
W
wangliu 已提交
81 82 83 84 85 86
    add_definitions(-DENABLE_EXCEPTION)
    add_definitions(-fexceptions)
else()
    add_definitions(-fno-exceptions)
endif ()

L
liuruilong 已提交
87 88 89 90
if (LOG_PROFILE)
    add_definitions(-DPADDLE_MOBILE_PROFILE)
endif()

D
dolphin8 已提交
91 92 93
if(USE_OPENMP)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
    add_definitions(-DPADDLE_MOBILE_USE_OPENMP)
94
endif()
Z
zhaojiaying01 已提交
95

朔-望's avatar
朔-望 已提交
96

W
wangliu 已提交
97

朔-望's avatar
朔-望 已提交
98

D
dolphin8 已提交
99
if (NOT ANDROID_NDK_TOOLCHAIN_INCLUDED)
100 101 102
    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 已提交
103 104
endif ()

朔-望's avatar
朔-望 已提交
105 106
include_directories(src/)

D
dolphin8 已提交
107 108 109 110 111
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 已提交
112

113 114 115 116
# NET default
set(NET "defult" CACHE STRING "select net type")
set_property(CACHE NET PROPERTY STRINGS "defult" "googlenet" "mobilenet" "yolo" "squeezenet")

D
dolphin8 已提交
117
include("${CMAKE_CURRENT_LIST_DIR}/tools/op.cmake")
H
Haipeng Wang 已提交
118

119 120 121 122 123 124 125 126
if (IS_IOS)
    add_library(paddle-mobile STATIC ${PADDLE_MOBILE_CC} ${PADDLE_MOBILE_H})
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 ()

D
dolphin8 已提交
127 128
if (ANDROID_NDK_TOOLCHAIN_INCLUDED)
    list(REMOVE_DUPLICATES CMAKE_CXX_FLAGS)
L
liuruilong 已提交
129
    add_library(paddle-mobile SHARED ${PADDLE_MOBILE_CC} ${PADDLE_MOBILE_H})
130
elseif(IS_IOS)
D
dolphin8 已提交
131
else ()
L
liuruilong 已提交
132 133
    add_library(paddle-mobile SHARED ${PADDLE_MOBILE_CC} ${PADDLE_MOBILE_H})
endif ()
朔-望's avatar
朔-望 已提交
134

W
wangliu 已提交
135
if(DEBUGING)
L
liuruilong 已提交
136 137 138 139
    if(IS_IOS)
    else()
        add_subdirectory(test)
    endif()
W
wangliu 已提交
140
endif()
W
wangliu 已提交
141