From e711b5a63a04fbb711c3504e03beccefc5cebcff Mon Sep 17 00:00:00 2001 From: Lars Glud Date: Tue, 1 Oct 2024 13:33:23 +0200 Subject: [PATCH] Move check for cuda up to be able to use CUDA_VERSION_STRING. Disable Global optimization if CUDA is version 10 or 11 as they seems to be failing with their thrust version Update how CMAKE_CXX_FLAGS_DEFAULT is set as windows default values has changed. --- CMakeLists.txt | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f2d31d9e010..4409ba5ba0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,7 +72,8 @@ ENDIF() # Create a variable with expected default CXX flags # This will be used further down the road to check if the user explicitly provided CXX flags if(CMAKE_COMPILER_IS_MSVC) - set(CMAKE_CXX_FLAGS_DEFAULT "/DWIN32 /D_WINDOWS /W3 /GR /EHsc") + set(CMAKE_CXX_FLAGS_DEFAULT ${CMAKE_CXX_FLAGS_INIT}) + string(STRIP ${CMAKE_CXX_FLAGS_DEFAULT} CMAKE_CXX_FLAGS_DEFAULT) else() set(CMAKE_CXX_FLAGS_DEFAULT "") endif() @@ -105,6 +106,13 @@ if(PCL_ENABLE_AVX AND "${CMAKE_CXX_FLAGS}" STREQUAL "${CMAKE_CXX_FLAGS_DEFAULT}" PCL_CHECK_FOR_AVX() endif() +# Cuda +option(WITH_CUDA "Build NVIDIA-CUDA support" TRUE) +if(WITH_CUDA) + include("${PCL_SOURCE_DIR}/cmake/pcl_find_cuda.cmake") +endif() + + # ---[ Unix/Darwin/Windows specific flags if(CMAKE_COMPILER_IS_GNUCXX) if("${CMAKE_CXX_FLAGS}" STREQUAL "${CMAKE_CXX_FLAGS_DEFAULT}") @@ -139,19 +147,25 @@ endif() if(CMAKE_COMPILER_IS_MSVC) add_definitions("-DBOOST_ALL_NO_LIB -D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS -DNOMINMAX ${SSE_DEFINITIONS}") - + if("${CMAKE_CXX_FLAGS}" STREQUAL "${CMAKE_CXX_FLAGS_DEFAULT}") + string(APPEND CMAKE_CXX_FLAGS " /fp:precise ${SSE_FLAGS} ${AVX_FLAGS}") + set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler=/bigobj") + + set(PCL_USE_GLOBAL_OPTIMIZATION TRUE) + if(CUDA_FOUND) + if(${CUDA_VERSION_STRING} VERSION_GREATER_EQUAL "10.0" AND ${CUDA_VERSION_STRING} VERSION_LESS "12.0") + set(USE_GLOBAL_OPTIMIZATION FALSE) + message("Global optimizations /GL has been turned off, as it doesn't work with nvcc/thrust in CUDA 10 and 11.") + endif() + endif() # Add extra code generation/link optimizations - if(CMAKE_MSVC_CODE_LINK_OPTIMIZATION AND (NOT BUILD_CUDA) AND (NOT BUILD_GPU)) + if(CMAKE_MSVC_CODE_LINK_OPTIMIZATION AND PCL_USE_GLOBAL_OPTIMIZATION) string(APPEND CMAKE_CXX_FLAGS_RELEASE " /GL") string(APPEND CMAKE_SHARED_LINKER_FLAGS_RELEASE " /LTCG /OPT:REF") string(APPEND CMAKE_EXE_LINKER_FLAGS_RELEASE " /LTCG") - else() - set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler=/bigobj") - - message("Global optimizations /GL has been turned off, as it doesn't work with nvcc/thrust") endif() # /MANIFEST:NO") # please, don't disable manifest generation, otherwise crash at start for vs2008 @@ -357,12 +371,6 @@ if(WITH_QHULL) endif() endif() -# Cuda -option(WITH_CUDA "Build NVIDIA-CUDA support" TRUE) -if(WITH_CUDA) - include("${PCL_SOURCE_DIR}/cmake/pcl_find_cuda.cmake") -endif() - # find GLEW before VTK as it uses custom findGLEW that doesn't work with cmakes findGLEW. option(WITH_GLEW "Support for GLEW" TRUE) if(WITH_GLEW)