Skip to content

Commit 77968e3

Browse files
authored
[Build] use different flags for NVCC and CC (dmlc#2342)
1 parent cb2bc69 commit 77968e3

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

CMakeLists.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,11 @@ if(MSVC)
8989
endif()
9090
else(MSVC)
9191
include(CheckCXXCompilerFlag)
92-
check_cxx_compiler_flag("-std=c++14" SUPPORT_CXX14)
92+
check_cxx_compiler_flag("-std=c++11" SUPPORT_CXX11)
9393
set(CMAKE_C_FLAGS "-O2 -Wall -fPIC ${CMAKE_C_FLAGS}")
94-
set(CMAKE_CXX_FLAGS "-O2 -Wall -fPIC -std=c++14 ${CMAKE_CXX_FLAGS}")
94+
# We still use c++11 flag in CPU build because gcc5.4 (our default compiler) is
95+
# not fully compatible with c++14 feature.
96+
set(CMAKE_CXX_FLAGS "-O2 -Wall -fPIC -std=c++11 ${CMAKE_CXX_FLAGS}")
9597
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--warn-common ${CMAKE_SHARED_LINKER_FLAGS}")
9698
endif(MSVC)
9799

cmake/modules/CUDA.cmake

+23-11
Original file line numberDiff line numberDiff line change
@@ -239,18 +239,30 @@ macro(dgl_config_cuda out_variable)
239239
src/geometry/cuda/*.cu
240240
)
241241

242+
# NVCC flags
243+
# Manually set everything
244+
set(CUDA_PROPAGATE_HOST_FLAGS OFF)
245+
246+
# 0. Add host flags
247+
message(STATUS "${CMAKE_CXX_FLAGS}")
248+
string(REGEX REPLACE "[ \t\n\r]" "," CXX_HOST_FLAGS "${CMAKE_CXX_FLAGS}")
249+
list(APPEND CUDA_NVCC_FLAGS "-Xcompiler ,${CXX_HOST_FLAGS}")
250+
251+
# 1. Add arch flags
242252
dgl_select_nvcc_arch_flags(NVCC_FLAGS_ARCH)
243-
string(REPLACE ";" " " NVCC_FLAGS_ARCH "${NVCC_FLAGS_ARCH}")
244-
set(NVCC_FLAGS_EXTRA ${NVCC_FLAGS_ARCH})
245-
# for lambda support in moderngpu
246-
set(NVCC_FLAGS_EXTRA "${NVCC_FLAGS_EXTRA} --expt-extended-lambda")
247-
# suppress deprecated warning in moderngpu
248-
set(NVCC_FLAGS_EXTRA "${NVCC_FLAGS_EXTRA} -Wno-deprecated-declarations")
249-
# for compile with c++14
250-
set(NVCC_FLAGS_EXTRA "${NVCC_FLAGS_EXTRA} --expt-extended-lambda --std=c++14")
251-
message(STATUS "NVCC extra flags: ${NVCC_FLAGS_EXTRA}")
252-
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} ${NVCC_FLAGS_EXTRA}")
253-
list(APPEND CMAKE_CUDA_FLAGS "${NVCC_FLAGS_EXTRA}")
253+
list(APPEND CUDA_NVCC_FLAGS ${NVCC_FLAGS_ARCH})
254+
255+
# 2. flags in third_party/moderngpu
256+
list(APPEND CUDA_NVCC_FLAGS "--expt-extended-lambda;-Wno-deprecated-declarations")
257+
258+
259+
# 3. CUDA 11 requires c++14 by default
260+
include(CheckCXXCompilerFlag)
261+
check_cxx_compiler_flag("-std=c++14" SUPPORT_CXX14)
262+
string(REPLACE "-std=c++11" "" CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS}")
263+
list(APPEND CUDA_NVCC_FLAGS "--std=c++14")
264+
265+
message(STATUS "CUDA flags: ${CUDA_NVCC_FLAGS}")
254266

255267
list(APPEND DGL_LINKER_LIBS
256268
${CUDA_CUDART_LIBRARY}

0 commit comments

Comments
 (0)