Skip to content
This repository was archived by the owner on Jan 24, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions Demo/linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,36 @@ cmake_minimum_required(VERSION 3.0)
project(paddle_demo CXX C)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/")
find_package(Paddle)
find_package(Fluid)
if(NOT PADDLE_FOUND)
find_package(Paddle)
endif()
find_package(OpenCV)

set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS)
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -std=c++11")

if(PADDLE_FLUID_FOUND)
set(PADDLE_SRC_FILES paddle_fluid_image_recognizer.cpp)
elseif(PADDLE_FOUND)
set(PADDLE_SRC_FILES paddle_image_recognizer.cpp)
else()
message(FATAL_ERROR "Cannot found PaddlePaddle.")
endif()

add_library(image_recognizer image_io.cpp image_utils.cpp ${PADDLE_SRC_FILES})
include_directories(${CMAKE_CURRENT_SOURCE_DIR})

function(add_paddle_demo TARGET_NAME)
if(NOT ARGN)
message(FATAL_ERROR "Please specify source files for ${TARGET_NAME}")
endif()
set(SRC_FILES ${ARGN})
add_executable(${TARGET_NAME} ${SRC_FILES})
target_link_libraries(${TARGET_NAME}
image_recognizer
${PADDLE_LIBRARIES}
${PADDLE_THIRD_PARTY_LIBRARIES})
if(NOT ANDROID_ABI)
Expand All @@ -41,9 +56,10 @@ function(add_paddle_demo TARGET_NAME)
endif()
endfunction()

set(COMMON_SRC_FILES image_io.cpp image_utils.cpp paddle_image_recognizer.cpp)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})

# ssd
set(SSD_SRC_FILES ${COMMON_SRC_FILES} ssd/main.cpp)
add_paddle_demo(ssd_demo ${SSD_SRC_FILES})
if(NOT PADDLE_FLUID_FOUND)
add_paddle_demo(ssd_demo ssd/main.cpp)
endif()

# image_classification
add_paddle_demo(image_classification_demo image_classification/main.cpp)
66 changes: 66 additions & 0 deletions Demo/linux/FindFluid.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserve.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License

set(PADDLE_FOUND OFF)
set(PADDLE_FLUID_FOUND OFF)

set(PADDLE_ROOT $ENV{PADDLE_ROOT} CACHE PATH "Paddle Path")
if(NOT PADDLE_ROOT)
message(FATAL_ERROR "Set PADDLE_ROOT as your root directory installed PaddlePaddle")
endif()

find_path(PADDLE_INC_DIR NAMES paddle/fluid/inference/io.h PATHS ${PADDLE_ROOT})
find_library(PADDLE_FLUID_SHARED_LIB NAMES "libpaddle_fluid.so" PATHS
${PADDLE_ROOT}/paddle/fluid/inference)
find_library(PADDLE_FLUID_STATIC_LIB NAMES "libpaddle_fluid.a" PATHS
${PADDLE_ROOT}/paddle/fluid/inference)
if(PADDLE_INC_DIR AND PADDLE_FLUID_SHARED_LIB)
set(PADDLE_FOUND ON)
set(PADDLE_FLUID_FOUND ON)
add_definitions(-DUSE_PADDLE_FLUID)
add_library(paddle_fluid_shared SHARED IMPORTED)
set_target_properties(paddle_fluid_shared PROPERTIES IMPORTED_LOCATION
${PADDLE_FLUID_SHARED_LIB})
set(PADDLE_LIBRARIES paddle_fluid_shared)
message(STATUS "Found PaddlePaddle Fluid (include: ${PADDLE_INC_DIR}; "
"library: ${PADDLE_FLUID_SHARED_LIB}")
else()
set(PADDLE_FOUND OFF)
set(PADDLE_FLUID_FOUND OFF)
return()
endif()

include_directories(${PADDLE_INC_DIR})

find_path(PADDLE_GFLAGS_INC_DIR NAMES gflags/gflags.h PATHS
${PADDLE_ROOT}/third_party/install/gflags/include
NO_DEFAULT_PATH)
find_path(PADDLE_GLOG_INC_DIR NAMES glog/logging.h PATHS
${PADDLE_ROOT}/third_party/install/glog/include
NO_DEFAULT_PATH)
find_path(PADDLE_PROTOBUF_INC_DIR google/protobuf/message.h PATHS
${PADDLE_ROOT}/third_party/install/protobuf/include
NO_DEFAULT_PATH)
find_path(PADDLE_EIGEN_INC_DIR NAMES unsupported/Eigen/CXX11/Tensor PATHS
${PADDLE_ROOT}/third_party/eigen3
NO_DEFAULT_PATH)
if(PADDLE_GFLAGS_INC_DIR AND PADDLE_GLOG_INC_DIR AND PADDLE_PROTOBUF_INC_DIR AND PADDLE_EIGEN_INC_DIR)
set(PADDLE_THIRD_PARTY_INC_DIRS
${PADDLE_GFLAGS_INC_DIR}
${PADDLE_GLOG_INC_DIR}
${PADDLE_PROTOBUF_INC_DIR}
${PADDLE_EIGEN_INC_DIR})
message(STATUS "Paddle need to include these third party directories: ${PADDLE_THIRD_PARTY_INC_DIRS}")
include_directories(${PADDLE_THIRD_PARTY_INC_DIRS})
endif()
7 changes: 6 additions & 1 deletion Demo/linux/FindPaddle.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License

set(PADDLE_FOUND OFF)

set(PADDLE_ROOT $ENV{PADDLE_ROOT} CACHE PATH "Paddle Path")
if(NOT PADDLE_ROOT)
message(FATAL_ERROR "Set PADDLE_ROOT as your root directory installed PaddlePaddle")
Expand All @@ -27,6 +29,7 @@ find_library(PADDLE_LAYERS_LIB NAMES paddle_capi_layers PATHS
find_library(PADDLE_ENGINE_LIB NAMES paddle_capi_engine PATHS
${PADDLE_ROOT}/lib/${ANDROID_ABI})
if(PADDLE_INC_DIR AND PADDLE_LAYERS_LIB AND PADDLE_ENGINE_LIB)
set(PADDLE_FOUND ON)
add_library(paddle_capi_layers STATIC IMPORTED)
set_target_properties(paddle_capi_layers PROPERTIES IMPORTED_LOCATION
${PADDLE_LAYERS_LIB})
Expand All @@ -40,12 +43,14 @@ if(PADDLE_INC_DIR AND PADDLE_LAYERS_LIB AND PADDLE_ENGINE_LIB)
message(STATUS "Found PaddlePaddle (include: ${PADDLE_INC_DIR}; "
"library: ${PADDLE_LAYERS_LIB}, ${PADDLE_ENGINE_LIB})")
elseif(PADDLE_INC_DIR AND PADDLE_WHOLE_LIB)
set(PADDLE_FOUND ON)
add_library(paddle_capi_whole STATIC IMPORTED)
set_target_properties(paddle_capi_whole PROPERTIES IMPORTED_LOCATION
${PADDLE_WHOLE_LIB})
set(PADDLE_LIBRARIES -Wl,--whole-archive paddle_capi_whole -Wl,--no-whole-archive)
else()
message(FATAL_ERROR "Cannot find PaddlePaddle on ${PADDLE_ROOT}")
set(PADDLE_FOUND OFF)
return()
endif()

include_directories(${PADDLE_INC_DIR})
Expand Down
Loading