Skip to content

Commit

Permalink
Add SSE/AVX flags, regardless of default CXX flags
Browse files Browse the repository at this point in the history
PCL_ENABLE_SSE and PCL_ENABLE_AVX should be used to choose (by default, both are on)
Previously, the logic made the behaviour quite unclear: if the user has set CMAKE_CXX_FLAGS to a custom value, it was impossible to use SSE_FLAGS/AVX_FLAGS
  • Loading branch information
mvieth committed Feb 10, 2024
1 parent 1033d24 commit 33cee56
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,16 @@ if(CMAKE_TIMING_VERBOSE AND UNIX)
endif()

# check for SSE flags
set(SSE_FLAGS "")
set(SSE_DEFINITIONS "")
include("${PCL_SOURCE_DIR}/cmake/pcl_find_sse.cmake")
if(PCL_ENABLE_SSE AND "${CMAKE_CXX_FLAGS}" STREQUAL "${CMAKE_CXX_FLAGS_DEFAULT}")
if(PCL_ENABLE_SSE)
PCL_CHECK_FOR_SSE()
endif()

# check for AVX flags
if(PCL_ENABLE_AVX AND "${CMAKE_CXX_FLAGS}" STREQUAL "${CMAKE_CXX_FLAGS_DEFAULT}")
set(AVX_FLAGS "")
if(PCL_ENABLE_AVX)
include("${PCL_SOURCE_DIR}/cmake/pcl_find_avx.cmake")
PCL_CHECK_FOR_AVX()
endif()
Expand All @@ -119,8 +122,9 @@ if(CMAKE_COMPILER_IS_GNUCXX)
else()
string(APPEND CMAKE_CXX_FLAGS " -Wabi")
endif()
string(APPEND CMAKE_CXX_FLAGS " -Wall -Wextra -fno-strict-aliasing ${SSE_FLAGS} ${AVX_FLAGS}")
string(APPEND CMAKE_CXX_FLAGS " -Wall -Wextra -fno-strict-aliasing")
endif()
string(APPEND CMAKE_CXX_FLAGS " ${SSE_FLAGS} ${AVX_FLAGS}")

if(PCL_WARNINGS_ARE_ERRORS)
string(APPEND CMAKE_CXX_FLAGS " -Werror -fno-strict-aliasing")
Expand All @@ -147,7 +151,7 @@ if(CMAKE_COMPILER_IS_MSVC)
add_definitions("-DBOOST_ALL_NO_LIB -D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS -DNOMINMAX -DPCL_ONLY_CORE_POINT_TYPES ${SSE_DEFINITIONS}")

if("${CMAKE_CXX_FLAGS}" STREQUAL "${CMAKE_CXX_FLAGS_DEFAULT}")
string(APPEND CMAKE_CXX_FLAGS " /fp:precise ${SSE_FLAGS} ${AVX_FLAGS}")
string(APPEND CMAKE_CXX_FLAGS " /fp:precise")

# Add extra code generation/link optimizations
if(CMAKE_MSVC_CODE_LINK_OPTIMIZATION AND (NOT BUILD_CUDA) AND (NOT BUILD_GPU))
Expand Down Expand Up @@ -203,6 +207,7 @@ if(CMAKE_COMPILER_IS_MSVC)
endif()
endif()
string(APPEND CMAKE_CXX_FLAGS " /bigobj")
string(APPEND CMAKE_CXX_FLAGS " ${SSE_FLAGS} ${AVX_FLAGS}")

if(CMAKE_GENERATOR STREQUAL "Ninja")
string(APPEND CMAKE_C_FLAGS " /FS")
Expand All @@ -224,11 +229,12 @@ if(CMAKE_COMPILER_IS_CLANG)
set(CMAKE_C_FLAGS "-Qunused-arguments")
endif()
if("${CMAKE_CXX_FLAGS}" STREQUAL "")
set(CMAKE_CXX_FLAGS "-ftemplate-depth=1024 -Qunused-arguments -Wno-invalid-offsetof ${SSE_FLAGS} ${AVX_FLAGS}") # Unfortunately older Clang versions do not have this: -Wno-unnamed-type-template-args
set(CMAKE_CXX_FLAGS "-ftemplate-depth=1024 -Qunused-arguments -Wno-invalid-offsetof") # Unfortunately older Clang versions do not have this: -Wno-unnamed-type-template-args
if(APPLE AND WITH_CUDA AND CUDA_FOUND)
string(APPEND CMAKE_CXX_FLAGS " -stdlib=libstdc++")
endif()
endif()
string(APPEND CMAKE_CXX_FLAGS " ${SSE_FLAGS} ${AVX_FLAGS}")
set(CLANG_LIBRARIES "stdc++")
endif()

Expand Down

0 comments on commit 33cee56

Please sign in to comment.