Skip to content

Commit 39669c0

Browse files
committed
Improve SSE/AVX detection on arm and when cross-compiling
Change check_cxx_source_runs to check_cxx_source_compiles because running the code does not provide any additional information, and is a problem when cross-compiling. When we know that we compile for arm, we set PCL_ENABLE_SSE and PCL_ENABLE_AVX to OFF to skip the checks completely.
1 parent bc88ade commit 39669c0

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

cmake/pcl_find_avx.cmake

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
function(PCL_CHECK_FOR_AVX)
44
set(AVX_FLAGS)
55

6-
include(CheckCXXSourceRuns)
6+
include(CheckCXXSourceCompiles)
77

88
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG)
9-
# Setting -march & -mtune just as required flags for check_cxx_source_runs,
10-
# and CMAKE_REQUIRED_FLAGS will be restored after test runs.
9+
# Setting -march & -mtune just as required flags for check_cxx_source_compiles,
10+
# and CMAKE_REQUIRED_FLAGS will be restored after test compiles.
1111
set(CMAKE_REQUIRED_FLAGS "-march=native -mtune=native")
1212
endif()
1313

14-
check_cxx_source_runs("
14+
check_cxx_source_compiles("
1515
#include <immintrin.h>
1616
int main()
1717
{
@@ -22,7 +22,7 @@ function(PCL_CHECK_FOR_AVX)
2222
HAVE_AVX2)
2323

2424
if(NOT HAVE_AVX2)
25-
check_cxx_source_runs("
25+
check_cxx_source_compiles("
2626
#include <immintrin.h>
2727
int main()
2828
{

cmake/pcl_find_sse.cmake

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ function(PCL_CHECK_FOR_SSE)
1919
# precision). One solution would be to use "-ffloat-store" on 32bit (see
2020
# http://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html), but that slows code down,
2121
# so the preferred solution is to try "-mpfmath=sse" first.
22-
include(CheckCXXSourceRuns)
22+
include(CheckCXXSourceCompiles)
2323
set(CMAKE_REQUIRED_FLAGS)
2424
set(SSE_LEVEL 0)
2525

2626
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG)
2727
set(CMAKE_REQUIRED_FLAGS "-msse4.2")
2828
endif()
2929

30-
check_cxx_source_runs("
30+
check_cxx_source_compiles("
3131
#include <emmintrin.h>
3232
#include <nmmintrin.h>
3333
int main ()
@@ -56,7 +56,7 @@ function(PCL_CHECK_FOR_SSE)
5656
set(CMAKE_REQUIRED_FLAGS "-msse4.1")
5757
endif()
5858

59-
check_cxx_source_runs("
59+
check_cxx_source_compiles("
6060
#include <smmintrin.h>
6161
int main ()
6262
{
@@ -81,7 +81,7 @@ function(PCL_CHECK_FOR_SSE)
8181
set(CMAKE_REQUIRED_FLAGS "-mssse3")
8282
endif()
8383

84-
check_cxx_source_runs("
84+
check_cxx_source_compiles("
8585
#include <tmmintrin.h>
8686
int main ()
8787
{
@@ -104,7 +104,7 @@ function(PCL_CHECK_FOR_SSE)
104104
set(CMAKE_REQUIRED_FLAGS "-msse3")
105105
endif()
106106

107-
check_cxx_source_runs("
107+
check_cxx_source_compiles("
108108
#include <pmmintrin.h>
109109
int main ()
110110
{
@@ -129,7 +129,7 @@ function(PCL_CHECK_FOR_SSE)
129129
set(CMAKE_REQUIRED_FLAGS "/arch:SSE2")
130130
endif()
131131

132-
check_cxx_source_runs("
132+
check_cxx_source_compiles("
133133
#include <emmintrin.h>
134134
int main ()
135135
{
@@ -154,7 +154,7 @@ function(PCL_CHECK_FOR_SSE)
154154
set(CMAKE_REQUIRED_FLAGS "/arch:SSE")
155155
endif()
156156

157-
check_cxx_source_runs("
157+
check_cxx_source_compiles("
158158
#include <xmmintrin.h>
159159
int main ()
160160
{

cmake/pcl_options.cmake

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,15 @@ mark_as_advanced(PCL_ONLY_CORE_POINT_TYPES)
6666
option(PCL_NO_PRECOMPILE "Do not precompile PCL code for any point types at all." OFF)
6767
mark_as_advanced(PCL_NO_PRECOMPILE)
6868

69-
# Enable or Disable the check for SSE optimizations
69+
# Enable or Disable the check for SSE and AVX optimizations
70+
if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm")
71+
option(PCL_ENABLE_SSE "Enable or Disable SSE optimizations." OFF)
72+
option(PCL_ENABLE_AVX "Enable or Disable AVX optimizations." OFF)
73+
else()
7074
option(PCL_ENABLE_SSE "Enable or Disable SSE optimizations." ON)
71-
mark_as_advanced(PCL_ENABLE_SSE)
72-
73-
# Enable or Disable the check for AVX optimizations
7475
option(PCL_ENABLE_AVX "Enable or Disable AVX optimizations." ON)
76+
endif()
77+
mark_as_advanced(PCL_ENABLE_SSE)
7578
mark_as_advanced(PCL_ENABLE_AVX)
7679

7780
if(UNIX)

0 commit comments

Comments
 (0)