1
1
cmake_minimum_required (VERSION 3.0 )
2
-
3
2
project (cpp_inference_demo CXX C )
3
+ option (WITH_MKL "Compile demo with MKL/OpenBlas support, default use MKL." ON )
4
+ option (WITH_GPU "Compile demo with GPU/CPU, default use CPU." OFF )
5
+ option (WITH_STATIC_LIB "Compile demo with static/shared library, default use static." ON )
6
+
7
+ macro (safe_set_static_flag )
8
+ foreach (flag_var
9
+ CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
10
+ CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO )
11
+ if (${flag_var} MATCHES "/MD" )
12
+ string (REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var} }" )
13
+ endif (${flag_var} MATCHES "/MD" )
14
+ endforeach (flag_var )
15
+ endmacro ()
4
16
5
- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
6
17
if (WIN32 )
7
- set (CMAKE_STATIC_LIBRARY_PREFIX "lib" )
18
+ if (WITH_STATIC_LIB )
19
+ safe_set_static_flag ()
20
+ add_definitions (-DSTATIC_LIB )
21
+ set (CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "/w" )
22
+ set (CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE} "/w" )
23
+ endif ()
24
+ set (CMAKE_STATIC_LIBRARY_PREFIX "lib" )
8
25
else ()
9
- set (CMAKE_STATIC_LIBRARY_PREFIX "" )
26
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
27
+ set (CMAKE_STATIC_LIBRARY_PREFIX "" )
10
28
endif ()
29
+ message ("flags" ${CMAKE_CXX_FLAGS} )
11
30
12
31
if (NOT DEFINED PADDLE_LIB )
13
32
message (FATAL_ERROR "please set PADDLE_LIB with -DPADDLE_LIB=/path/paddle/lib" )
@@ -16,14 +35,18 @@ if(NOT DEFINED DEMO_NAME)
16
35
message (FATAL_ERROR "please set DEMO_NAME with -DDEMO_NAME=demo_name" )
17
36
endif ()
18
37
19
- option (WITH_MKL "Compile demo with MKL/OpenBlas support, default use MKL." ON )
20
- option (WITH_GPU "Compile demo with GPU/CPU, default use CPU." OFF )
21
- option (WITH_STATIC_LIB "Compile demo with static/shared library, default use static." ON )
22
38
23
39
if (WITH_GPU )
24
- set (CUDA_LIB "/usr/local/cuda/lib64/" CACHE STRING "CUDA Library" )
40
+ if (NOT WIN32 )
41
+ set (CUDA_LIB "/usr/local/cuda/lib64/" CACHE STRING "CUDA Library" )
42
+ else ()
43
+ if (CUDA_LIB STREQUAL "" )
44
+ set (CUDA_LIB "C:\\ Program\ Files\\ NVIDIA GPU Computing Toolkit\\ CUDA\\ v8.0\\ lib\\ x64" )
45
+ endif ()
46
+ endif (NOT WIN32 )
25
47
endif ()
26
48
49
+ include_directories ("D:/Paddle/" )
27
50
include_directories ("${PADDLE_LIB} " )
28
51
include_directories ("${PADDLE_LIB} /third_party/install/protobuf/include" )
29
52
include_directories ("${PADDLE_LIB} /third_party/install/glog/include" )
@@ -83,10 +106,18 @@ set(DEPS ${DEPS}
83
106
${MATH_LIB} ${MKLDNN_LIB}
84
107
${CMAKE_STATIC_LIBRARY_PREFIX} glog ${CMAKE_STATIC_LIBRARY_PREFIX} gflags ${CMAKE_STATIC_LIBRARY_PREFIX} protobuf
85
108
${EXTERNAL_LIB} )
109
+ # NOTE(dzhwinter) shlwapi is deprecated.
110
+ set (DEPS ${DEPS} libcmt shlwapi )
86
111
endif (NOT WIN32 )
87
112
88
113
if (WITH_GPU )
89
- set (DEPS ${DEPS} ${CUDA_LIB} /libcudart${CMAKE_SHARED_LIBRARY_SUFFIX} )
114
+ if (NOT WIN32 )
115
+ set (DEPS ${DEPS} ${CUDA_LIB} /libcudart${CMAKE_SHARED_LIBRARY_SUFFIX} )
116
+ else ()
117
+ set (DEPS ${DEPS} ${CUDA_LIB} /cudart${CMAKE_STATIC_LIBRARY_SUFFIX} )
118
+ set (DEPS ${DEPS} ${CUDA_LIB} /cublas${CMAKE_STATIC_LIBRARY_SUFFIX} )
119
+ set (DEPS ${DEPS} ${CUDA_LIB} /cudnn${CMAKE_STATIC_LIBRARY_SUFFIX} )
120
+ endif ()
90
121
endif ()
91
122
92
123
target_link_libraries (${DEMO_NAME} ${DEPS} )
0 commit comments