CMakeLists.txt 2.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
cmake_minimum_required(VERSION 3.0)

project(cpp_train_demo CXX C)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

if(NOT DEFINED PADDLE_LIB)
  message(FATAL_ERROR "please set PADDLE_LIB with -DPADDLE_LIB=/paddle/lib/dir")
endif()

option(WITH_MKLDNN     "Compile PaddlePaddle with MKLDNN"                                   OFF)
option(WITH_MKL        "Compile PaddlePaddle with MKL support, default use openblas."       OFF)

include_directories("${PADDLE_LIB}")
include_directories("${PADDLE_LIB}/third_party/install/protobuf/include")
include_directories("${PADDLE_LIB}/third_party/install/glog/include")
include_directories("${PADDLE_LIB}/third_party/install/gflags/include")
18
include_directories("${PADDLE_LIB}/third_party/install/xxhash/include")
19 20 21 22 23 24 25 26 27 28 29 30
include_directories("${PADDLE_LIB}/third_party/install/snappy/include")
include_directories("${PADDLE_LIB}/third_party/install/snappystream/include")
include_directories("${PADDLE_LIB}/third_party/install/zlib/include")

include_directories("${PADDLE_LIB}/third_party/boost")
include_directories("${PADDLE_LIB}/third_party/eigen3")

link_directories("${PADDLE_LIB}/third_party/install/snappy/lib")
link_directories("${PADDLE_LIB}/third_party/install/snappystream/lib")
link_directories("${PADDLE_LIB}/third_party/install/protobuf/lib")
link_directories("${PADDLE_LIB}/third_party/install/glog/lib")
link_directories("${PADDLE_LIB}/third_party/install/gflags/lib")
31
link_directories("${PADDLE_LIB}/third_party/install/xxhash/lib")
32 33 34 35 36 37
link_directories("${PADDLE_LIB}/third_party/install/zlib/lib")

add_executable(demo_trainer demo_trainer.cc)

if(WITH_MKLDNN)
  include_directories("${PADDLE_LIB}/third_party/install/mkldnn/include")
P
peizhilin 已提交
38 39 40 41 42 43
  if(WIN32)
    set(MKLDNN_LIB ${PADDLE_LIB}/third_party/install/mkldnn/lib/mkldnn.lib)
  else(WIN32)
    set(MKLDNN_LIB ${PADDLE_LIB}/third_party/install/mkldnn/lib/libmkldnn.so.0)
  endif(WIN32)
endif(WITH_MKLDNN)
44 45 46

if(WITH_MKL)
  include_directories("${PADDLE_LIB}/third_party/install/mklml/include")
P
peizhilin 已提交
47 48 49 50 51
  if(WIN32)
    set(MATH_LIB ${PADDLE_LIB}/third_party/install/mklml/lib/mklml.lib)
  else(WIN32)
    set(MATH_LIB ${PADDLE_LIB}/third_party/install/mklml/lib/libmklml_intel.so)
  endif(WIN32)
52 53 54
else()
  if(APPLE)
    set(MATH_LIB cblas)
P
peizhilin 已提交
55 56 57
  elseif(WIN32)
    set(MATH_LIB ${PADDLE_LIB}/third_party/install/openblas/lib/libopenblas.lib)
  else()
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
    set(MATH_LIB ${PADDLE_LIB}/third_party/install/openblas/lib/libopenblas.a)
  endif(APPLE)
endif()

if(APPLE)
  set(MACOS_LD_FLAGS "-undefined dynamic_lookup -Wl,-all_load -framework CoreFoundation -framework Security")
else(APPLE)
  set(ARCHIVE_START "-Wl,--whole-archive")
  set(ARCHIVE_END "-Wl,--no-whole-archive")
  set(EXTERNAL_LIB "-lrt -ldl -lpthread")
endif(APPLE)

target_link_libraries(demo_trainer
        ${MACOS_LD_FLAGS}
        ${ARCHIVE_START}
73
        ${PADDLE_LIB}/paddle/fluid/inference/libpaddle_fluid.so
74 75 76
        ${ARCHIVE_END}
        ${MATH_LIB}
        ${MKLDNN_LIB}
77
        glog gflags protobuf snappystream snappy z xxhash
78
        ${EXTERNAL_LIB})