Skip to content

Commit

Permalink
Updates to CXX flags and removal of cmake checks less than 3.16. (#6144)
Browse files Browse the repository at this point in the history
* 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.

* Remove checks for cmake less than 3.16 as that is minimum required.

* Fixed typo.
  • Loading branch information
larshg authored Oct 19, 2024
1 parent 9e48412 commit f8bb3ef
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 78 deletions.
59 changes: 28 additions & 31 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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}")
Expand Down Expand Up @@ -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(PCL_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

Expand All @@ -176,24 +190,13 @@ if(CMAKE_COMPILER_IS_MSVC)
include(ProcessorCount)
ProcessorCount(CPUCores)
set(MSVC_MP ${CPUCores} CACHE STRING "Number of simultaneously running compilers (0 = automatic detection by MSVC). See documentation of /MP flag.")
if (CMAKE_VERSION VERSION_LESS 3.11.0)
# Usage of COMPILE_LANGUAGE generator expression for MSVC in add_compile_options requires at least CMake 3.11, see https://gitlab.kitware.com/cmake/cmake/issues/17435
if(MSVC_MP EQUAL 0)
# MSVC_MP is 0 in case the information cannot be determined by ProcessorCount => fallback
string(APPEND CMAKE_C_FLAGS " /MP")
string(APPEND CMAKE_CXX_FLAGS " /MP")
elseif(MSVC_MP GREATER 1)
string(APPEND CMAKE_C_FLAGS " /MP${MSVC_MP}")
string(APPEND CMAKE_CXX_FLAGS " /MP${MSVC_MP}")
endif()
else()
if(MSVC_MP EQUAL 0)
# MSVC_MP is 0 in case the information cannot be determined by ProcessorCount => fallback
# Generator expression is necessary to limit /MP flag to C/CXX, so flag will be not set to e.g. CUDA (see https://gitlab.kitware.com/cmake/cmake/issues/17535)
add_compile_options($<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:/MP>)
elseif(MSVC_MP GREATER 1)
add_compile_options($<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:/MP${MSVC_MP}>)
endif()

if(MSVC_MP EQUAL 0)
# MSVC_MP is 0 in case the information cannot be determined by ProcessorCount => fallback
# Generator expression is necessary to limit /MP flag to C/CXX, so flag will be not set to e.g. CUDA (see https://gitlab.kitware.com/cmake/cmake/issues/17535)
add_compile_options($<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:/MP>)
elseif(MSVC_MP GREATER 1)
add_compile_options($<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:/MP${MSVC_MP}>)
endif()
endif()
string(APPEND CMAKE_CXX_FLAGS " /bigobj")
Expand Down Expand Up @@ -357,12 +360,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)
Expand Down
13 changes: 3 additions & 10 deletions cmake/Modules/FindSphinx.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,9 @@
find_package(PkgConfig QUIET)
pkg_check_modules(PC_SPHINX sphinx-build)

if(CMAKE_VERSION VERSION_LESS 3.12.0)
find_package(PythonInterp)
if(PYTHONINTERP_FOUND)
get_filename_component(PYTHON_DIR "${PYTHON_EXECUTABLE}" PATH)
endif()
else()
find_package(Python)
if(Python_Interpreter_FOUND)
get_filename_component(PYTHON_DIR "${Python_EXECUTABLE}" PATH)
endif()
find_package(Python)
if(Python_Interpreter_FOUND)
get_filename_component(PYTHON_DIR "${Python_EXECUTABLE}" PATH)
endif()

find_program(SPHINX_EXECUTABLE NAMES sphinx-build
Expand Down
31 changes: 13 additions & 18 deletions cmake/pcl_find_cuda.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,23 @@ if(MSVC)
set(CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE OFF CACHE BOOL "CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE")
endif()

if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.11)
include(CheckLanguage)
check_language(CUDA)
if(CMAKE_CUDA_COMPILER)
enable_language(CUDA)
include(CheckLanguage)
check_language(CUDA)
if(CMAKE_CUDA_COMPILER)
enable_language(CUDA)

if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.17)
find_package(CUDAToolkit QUIET)
set(CUDA_TOOLKIT_INCLUDE ${CUDAToolkit_INCLUDE_DIRS})
else()
set(CUDA_FIND_QUIETLY TRUE)
find_package(CUDA 9.0)
endif()

set(CUDA_FOUND TRUE)
set(CUDA_VERSION_STRING ${CMAKE_CUDA_COMPILER_VERSION})
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.17)
find_package(CUDAToolkit QUIET)
set(CUDA_TOOLKIT_INCLUDE ${CUDAToolkit_INCLUDE_DIRS})
else()
message(STATUS "No CUDA compiler found")
set(CUDA_FIND_QUIETLY TRUE)
find_package(CUDA 9.0)
endif()

set(CUDA_FOUND TRUE)
set(CUDA_VERSION_STRING ${CMAKE_CUDA_COMPILER_VERSION})
else()
set(CUDA_FIND_QUIETLY TRUE)
find_package(CUDA 9.0)
message(STATUS "No CUDA compiler found")
endif()

if(CUDA_FOUND)
Expand Down
27 changes: 8 additions & 19 deletions cmake/pcl_targets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -421,16 +421,10 @@ macro(PCL_ADD_TEST _name _exename)

#Only applies to MSVC
if(MSVC)
#Requires CMAKE version 3.13.0
if(CMAKE_VERSION VERSION_LESS "3.13.0" AND (NOT ArgumentWarningShown))
message(WARNING "Arguments for unit test projects are not added - this requires at least CMake 3.13. Can be added manually in \"Project settings -> Debugging -> Command arguments\"")
SET (ArgumentWarningShown TRUE PARENT_SCOPE)
else()
#Only add if there are arguments to test
if(ARGS_ARGUMENTS)
string (REPLACE ";" " " ARGS_ARGUMENTS_STR "${ARGS_ARGUMENTS}")
set_target_properties(${_exename} PROPERTIES VS_DEBUGGER_COMMAND_ARGUMENTS ${ARGS_ARGUMENTS_STR})
endif()
#Only add if there are arguments to test
if(ARGS_ARGUMENTS)
string (REPLACE ";" " " ARGS_ARGUMENTS_STR "${ARGS_ARGUMENTS}")
set_target_properties(${_exename} PROPERTIES VS_DEBUGGER_COMMAND_ARGUMENTS ${ARGS_ARGUMENTS_STR})
endif()
endif()

Expand Down Expand Up @@ -471,15 +465,10 @@ function(PCL_ADD_BENCHMARK _name)
if(MSVC)
#Requires CMAKE version 3.13.0
get_target_property(BenchmarkArgumentWarningShown run_benchmarks PCL_BENCHMARK_ARGUMENTS_WARNING_SHOWN)
if(CMAKE_VERSION VERSION_LESS "3.13.0" AND (NOT BenchmarkArgumentWarningShown))
message(WARNING "Arguments for benchmark projects are not added - this requires at least CMake 3.13. Can be added manually in \"Project settings -> Debugging -> Command arguments\"")
set_target_properties(run_benchmarks PROPERTIES PCL_BENCHMARK_ARGUMENTS_WARNING_SHOWN TRUE)
else()
#Only add if there are arguments to test
if(ARGS_ARGUMENTS)
string (REPLACE ";" " " ARGS_ARGUMENTS_STR "${ARGS_ARGUMENTS}")
set_target_properties(benchmark_${_name} PROPERTIES VS_DEBUGGER_COMMAND_ARGUMENTS ${ARGS_ARGUMENTS_STR})
endif()
#Only add if there are arguments to test
if(ARGS_ARGUMENTS)
string (REPLACE ";" " " ARGS_ARGUMENTS_STR "${ARGS_ARGUMENTS}")
set_target_properties(benchmark_${_name} PROPERTIES VS_DEBUGGER_COMMAND_ARGUMENTS ${ARGS_ARGUMENTS_STR})
endif()
endif()

Expand Down

0 comments on commit f8bb3ef

Please sign in to comment.