-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
74 lines (66 loc) · 2.61 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
cmake_minimum_required(VERSION 2.8)
project(pdlite-llm)
set(TARGET pdlite-llm)
# 1. path to Paddle-Lite lib and mklml lib
set(LITE_DIR "${PROJECT_SOURCE_DIR}/cxx")
set(MKLML_DIR "${PROJECT_SOURCE_DIR}/mklml")
if (WIN32)
add_definitions("/DGOOGLE_GLOG_DLL_DECL=")
set(MSVC_STATIC_CRT )
if(MSVC_STATIC_CRT)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /bigobj /MTd")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /bigobj /MT")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /bigobj /MTd")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /bigobj /MT")
else(MSVC_STATIC_CRT)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /bigobj /MDd")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /bigobj /MD")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /bigobj /MDd")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /bigobj /MD")
endif(MSVC_STATIC_CRT)
endif()
if (APPLE AND METAL)
message(STATUS "set METAL=ON")
add_definitions("-DMETAL")
find_library(METAL_LIBRARY Metal REQUIRED)
find_library(GRAPHIC CoreGraphics REQUIRED)
find_library(MPS_LIBRARY MetalPerformanceShaders REQUIRED)
endif()
# 2. link mklml and Paddle-Lite directory
link_directories(${LITE_DIR}/lib ${MKLML_DIR}/lib)
include_directories(${LITE_DIR}/include/ ${MKLML_DIR}/include)
include_directories(include)
# 3. compile options
if (NOT WIN32)
add_definitions(-std=c++11 -g -O3 -pthread)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR})
endif()
# 4.add executable output
add_executable(${TARGET} ${TARGET}.cc)
if (WIN32)
set(WITH_STATIC_MKL OFF)
if(WITH_STATIC_MKL)
set(MATH_LIB ${MKLML_DIR}/lib/libiomp5md${CMAKE_STATIC_LIBRARY_SUFFIX})
else()
set(MATH_LIB ${MKLML_DIR}/lib/mklml${CMAKE_STATIC_LIBRARY_SUFFIX}
${MKLML_DIR}/lib/libiomp5md${CMAKE_STATIC_LIBRARY_SUFFIX})
endif()
target_link_libraries(${TARGET} libpaddle_api_light_bundled.lib)
target_link_libraries(${TARGET} shlwapi.lib)
target_link_libraries(${TARGET} ${MATH_LIB})
add_custom_command(TARGET ${TARGET} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${MKLML_DIR}/lib/libiomp5md.dll ${CMAKE_CURRENT_BINARY_DIR}/Release
)
if(NOT WITH_STATIC_MKL)
add_custom_command(TARGET ${TARGET} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${MKLML_DIR}/lib/mklml.dll ${CMAKE_CURRENT_BINARY_DIR}/Release
)
endif()
else()
if (APPLE AND METAL)
target_link_libraries(${TARGET} ${METAL_LIBRARY} ${GRAPHIC} ${MPS_LIBRARY})
endif()
target_link_libraries(${TARGET} -lpaddle_light_api_shared)
target_link_libraries(${TARGET} -liomp5)
target_link_libraries(${TARGET} -ldl)
endif()