CMakeLists.txt 2.4 KB
Newer Older
1 2
cmake_minimum_required (VERSION 2.6)
project (DeepES)
Z
zenghsh3 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
set(TARGET parallel_main)

########## options ##########
option(WITH_PADDLE "Compile DeepES with PaddleLite framework." OFF)
option(WITH_TORCH "Compile DeepES with Torch framework." OFF)

message("WITH_PADDLE: "${WITH_PADDLE})
message("WITH_TORCH: "${WITH_TORCH})

if (NOT (WITH_PADDLE OR WITH_TORCH))
  message("ERROR: You should choose at least one framework to compile DeepES.")
  return()
elseif(WITH_PADDLE AND WITH_TORCH)
  message("ERROR: You cannot choose more than one framework to compile DeepES.")
  return()
endif()

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
23 24 25 26 27 28 29 30 31

find_package(OpenMP)
if (OPENMP_FOUND)
    set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
    set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()


Z
zenghsh3 已提交
32
file(GLOB src "src/*.cc")
33 34 35
include_directories("include")
include_directories("benchmark")

Z
zenghsh3 已提交
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
########## PaddleLite config ##########
if (WITH_PADDLE)
  add_definitions(-g -O3 -pthread)

  include_directories("include/paddle")
  include_directories("${PROJECT_SOURCE_DIR}/inference_lite_lib/cxx/include" 
                   "${PROJECT_SOURCE_DIR}/inference_lite_lib/third_party/mklml/include")
  link_directories("${PROJECT_SOURCE_DIR}/inference_lite_lib/cxx/lib" 
                   "${PROJECT_SOURCE_DIR}/inference_lite_lib/third_party/mklml/lib")
  
  file(GLOB framework_src "src/paddle/*.cc")
  set(demo "${PROJECT_SOURCE_DIR}/demo/paddle/cartpole_solver_parallel.cc")
########## Torch config ##########
elseif (WITH_TORCH)
  list(APPEND CMAKE_PREFIX_PATH "./libtorch")
  find_package(Torch REQUIRED ON)

  include_directories("include/torch")
  include_directories("demo/torch")

  file(GLOB framework_src "src/torch/*.cc")
  set(demo "${PROJECT_SOURCE_DIR}/demo/torch/cartpole_solver_parallel.cc")
else ()
  message("ERROR: You should choose at least one framework to compile DeepES.")
endif()

add_executable(${TARGET} ${demo} ${src} ${framework_src}) 

target_link_libraries(${TARGET} gflags protobuf pthread glog)

########## PaddleLite libraries ##########
if (WITH_PADDLE)
  target_link_libraries(${TARGET} -lpaddle_full_api_shared)
  target_link_libraries(${TARGET} -lmklml_intel)
  target_link_libraries(${TARGET} -ldl)
########## Torch libraries ##########
elseif (WITH_TORCH)
  target_link_libraries(${TARGET} "${TORCH_LIBRARIES}")
endif()