CMakeLists.txt 6.5 KB
Newer Older
W
wangliu 已提交
1
cmake_minimum_required(VERSION 3.6)
W
wangliu 已提交
2

L
liuruilong 已提交
3
option(USE_OPENMP "openmp support" OFF)
4
option(DEBUGING "enable debug mode" ON)
L
liuruilong 已提交
5
option(USE_EXCEPTION "use std exception" ON)
L
liuruilong 已提交
6
option(LOG_PROFILE "log profile" OFF)
L
liuruilong 已提交
7
# select the platform to build
Y
yangfei 已提交
8
option(CPU "armv7 with neon" OFF)
Z
zhaojiaying01 已提交
9 10
option(GPU_MALI "mali gpu" OFF)
option(GPU_CL "opencl gpu" ON)
Z
zhaojiaying01 已提交
11
option(FPGA "fpga" OFF)
W
wangliu 已提交
12

L
liuruilong 已提交
13 14
project(paddle-mobile)

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 22 23 24
else()
    set(CMAKE_CXX_FLAGS "-std=c++14 -O3 -s ${CMAKE_CXX_FLAGS}")
endif()

L
liuruilong 已提交
25 26
if (DEBUGING)
    message(STATUS "debug")
Z
zhaojiaying01 已提交
27 28
    set(CMAKE_BUILD_TYPE Release)
    set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG")
L
liuruilong 已提交
29
#    add_definitions(-DPADDLE_MOBILE_DEBUG)
L
liuruilong 已提交
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
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()

L
liuruilong 已提交
48
if(USE_OPENMP)
L
liuruilong 已提交
49 50 51 52 53 54 55 56
    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 已提交
57

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

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

Z
zhaojiaying01 已提交
72 73
if (GPU_CL)
    add_definitions(-DPADDLE_MOBILE_CL)
L
liuruilong 已提交
74 75 76 77

    # opencl version
    add_definitions(-DCL_TARGET_OPENCL_VERSION=220)

D
dolphin8 已提交
78
    link_libraries(${CMAKE_CURRENT_LIST_DIR}/third_party/opencl/libOpenCL.so)
L
liuruilong 已提交
79
    include_directories(third_party/opencl/OpenCL-Headers)
Z
zhaojiaying01 已提交
80 81 82 83 84 85 86 87 88 89 90 91 92
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 已提交
93
    add_definitions(-DPADDLE_MOBILE_MALI_GPU)
S
sharper 已提交
94 95 96 97 98 99 100 101 102 103 104
    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 已提交
105
else()
106 107 108 109 110 111 112 113 114
    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 已提交
115 116 117
endif()

if(FPGA)
118 119
    set(DEBUGING ON)
    add_definitions(-DPADDLE_MOBILE_DEBUG)
W
wangliu 已提交
120 121
    add_definitions(-DPADDLE_MOBILE_FPGA)
else()
L
liuruilong 已提交
122 123 124 125 126 127 128 129 130
    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 已提交
131

D
dolphin8 已提交
132

133 134 135 136 137 138 139 140 141 142 143
    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 已提交
144
if (ANDROID_NDK_TOOLCHAIN_INCLUDED)
W
wangliu 已提交
145
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -llog")
W
wangliu 已提交
146
else()
L
liuruilong 已提交
147 148
    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)
149
    list(REMOVE_ITEM PADDLE_MOBILE_H ${CMAKE_CURRENT_SOURCE_DIR}/src/operators/math/math_func_neon.h)
W
wangliu 已提交
150 151
endif ()

L
liuruilong 已提交
152 153
if (IS_IOS)
else()
L
liuruilong 已提交
154 155 156
    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 已提交
157
endif ()
朔-望's avatar
朔-望 已提交
158

D
dolphin8 已提交
159 160 161 162 163
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 已提交
164

165
# NET default
166 167 168 169 170 171
if (FPGA)
    set(NET "FPGAnets" CACHE STRING "select net type")
else()
    set(NET "default" CACHE STRING "select net type")
endif()

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

175

L
liuruilong 已提交
176
# build library
D
dolphin8 已提交
177 178
if (ANDROID_NDK_TOOLCHAIN_INCLUDED)
    list(REMOVE_DUPLICATES CMAKE_CXX_FLAGS)
L
liuruilong 已提交
179
    add_library(paddle-mobile SHARED ${PADDLE_MOBILE_CC} ${PADDLE_MOBILE_H})
180
elseif(IS_IOS)
181 182 183 184 185 186 187 188 189 190 191
    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()
D
dolphin8 已提交
192
else ()
L
liuruilong 已提交
193 194
    add_library(paddle-mobile SHARED ${PADDLE_MOBILE_CC} ${PADDLE_MOBILE_H})
endif ()
朔-望's avatar
朔-望 已提交
195

L
liuruilong 已提交
196
# unit test
W
wangliu 已提交
197
if(DEBUGING)
L
liuruilong 已提交
198 199 200 201
    if(IS_IOS)
    else()
        add_subdirectory(test)
    endif()
W
wangliu 已提交
202
endif()
W
wangliu 已提交
203

204