Skip to content

Commit 4fd5eb2

Browse files
authored
"refine cmake" (#13546)
1 parent eb1aeb1 commit 4fd5eb2

File tree

1 file changed

+40
-9
lines changed

1 file changed

+40
-9
lines changed

paddle/fluid/inference/api/demo_ci/CMakeLists.txt

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,32 @@
11
cmake_minimum_required(VERSION 3.0)
2-
32
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()
416

5-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
617
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")
825
else()
9-
set(CMAKE_STATIC_LIBRARY_PREFIX "")
26+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
27+
set(CMAKE_STATIC_LIBRARY_PREFIX "")
1028
endif()
29+
message("flags" ${CMAKE_CXX_FLAGS})
1130

1231
if(NOT DEFINED PADDLE_LIB)
1332
message(FATAL_ERROR "please set PADDLE_LIB with -DPADDLE_LIB=/path/paddle/lib")
@@ -16,14 +35,18 @@ if(NOT DEFINED DEMO_NAME)
1635
message(FATAL_ERROR "please set DEMO_NAME with -DDEMO_NAME=demo_name")
1736
endif()
1837

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)
2238

2339
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)
2547
endif()
2648

49+
include_directories("D:/Paddle/")
2750
include_directories("${PADDLE_LIB}")
2851
include_directories("${PADDLE_LIB}/third_party/install/protobuf/include")
2952
include_directories("${PADDLE_LIB}/third_party/install/glog/include")
@@ -83,10 +106,18 @@ set(DEPS ${DEPS}
83106
${MATH_LIB} ${MKLDNN_LIB}
84107
${CMAKE_STATIC_LIBRARY_PREFIX}glog ${CMAKE_STATIC_LIBRARY_PREFIX}gflags ${CMAKE_STATIC_LIBRARY_PREFIX}protobuf
85108
${EXTERNAL_LIB})
109+
# NOTE(dzhwinter) shlwapi is deprecated.
110+
set(DEPS ${DEPS} libcmt shlwapi)
86111
endif(NOT WIN32)
87112

88113
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()
90121
endif()
91122

92123
target_link_libraries(${DEMO_NAME} ${DEPS})

0 commit comments

Comments
 (0)