Skip to content

Commit 575168b

Browse files
authored
Detect alignment when pcl_find_sse is not called & fix detection of Eigen (#6261)
* Set HAVE_POSIX_MEMALIGN and HAVE_MM_MALLOC even if PCL_CHECK_FOR_SSE() is not used. This ensures the methods are used when SSE is enabled by setting CMAKE_CXX_FLAGS. * Ensure try_compile (CHECK_CXX_SOURCE_COMPILES) sets the include paths (e.g. for Eigen3)
1 parent 27fb1f5 commit 575168b

File tree

3 files changed

+38
-23
lines changed

3 files changed

+38
-23
lines changed

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ elseif(MINGW)
6565
set(CMAKE_COMPILER_IS_MINGW 1)
6666
endif()
6767

68+
# Ensure try_compile sets the include paths (e.g. for Eigen3)
69+
set(CMAKE_TRY_COMPILE_CONFIGURATION ${CMAKE_BUILD_TYPE})
70+
6871
# https://github.com/fish-shell/fish-shell/issues/5865
6972
include(CheckCXXSourceCompiles)
7073
CHECK_CXX_SOURCE_COMPILES("
@@ -104,6 +107,10 @@ if(CMAKE_TIMING_VERBOSE AND UNIX)
104107
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CMAKE_SOURCE_DIR}/cmake/custom_output.sh")
105108
endif()
106109

110+
# check for allocation functions that return aligned memory
111+
include("${PCL_SOURCE_DIR}/cmake/pcl_alignment.cmake")
112+
PCL_CHECK_FOR_ALIGNMENT()
113+
107114
# check for SSE flags
108115
include("${PCL_SOURCE_DIR}/cmake/pcl_find_sse.cmake")
109116
if(PCL_ENABLE_SSE AND "${CMAKE_CXX_FLAGS}" STREQUAL "${CMAKE_CXX_FLAGS_DEFAULT}")

cmake/pcl_alignment.cmake

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
###############################################################################
2+
# Check for the presence of _mm_malloc() and posix_memalign()
3+
function(PCL_CHECK_FOR_ALIGNMENT)
4+
include(CheckCXXSourceCompiles)
5+
if(NOT DEFINED HAVE_MM_MALLOC)
6+
check_cxx_source_compiles("
7+
// Intel compiler defines an incompatible _mm_malloc signature
8+
#if defined(__INTEL_COMPILER)
9+
#include <malloc.h>
10+
#else
11+
#include <mm_malloc.h>
12+
#endif
13+
int main()
14+
{
15+
void* mem = _mm_malloc (100, 16);
16+
return 0;
17+
}"
18+
HAVE_MM_MALLOC)
19+
endif()
20+
21+
if(NOT DEFINED HAVE_POSIX_MEMALIGN)
22+
check_cxx_source_compiles("
23+
#include <stdlib.h>
24+
int main()
25+
{
26+
void* mem;
27+
return posix_memalign (&mem, 16, 100);
28+
}"
29+
HAVE_POSIX_MEMALIGN)
30+
endif()
31+
endfunction()

cmake/pcl_find_sse.cmake

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,6 @@ function(PCL_CHECK_FOR_SSE)
2323
set(CMAKE_REQUIRED_FLAGS)
2424
set(SSE_LEVEL 0)
2525

26-
check_cxx_source_runs("
27-
// Intel compiler defines an incompatible _mm_malloc signature
28-
#if defined(__INTEL_COMPILER)
29-
#include <malloc.h>
30-
#else
31-
#include <mm_malloc.h>
32-
#endif
33-
int main()
34-
{
35-
void* mem = _mm_malloc (100, 16);
36-
return 0;
37-
}"
38-
HAVE_MM_MALLOC)
39-
40-
check_cxx_source_runs("
41-
#include <stdlib.h>
42-
int main()
43-
{
44-
void* mem;
45-
return posix_memalign (&mem, 16, 100);
46-
}"
47-
HAVE_POSIX_MEMALIGN)
48-
4926
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG)
5027
set(CMAKE_REQUIRED_FLAGS "-msse4.2")
5128
endif()

0 commit comments

Comments
 (0)