how to change '-march=native' compile flag added by PCL in cmake

171 views Asked by At

I'm new to cmake, recently, my program cannot run on another device and I find that reason is compile flag -march=native silently added (found PCL library do it), I verify it by modifying value of -march from native to x86-64 CXX_FLAGS in flags.make (hacking this file because I cannot find a way to change it within cmake file by setting CMAKE_CXX_FLAGS or add_compile_options).

One word, that compile flag -march=native is added by PCL library by find_package.

QUESTION

I want change it to -march=x86-64 in cmake, How to do it?

Ps: Tried adding -march=x86-64 to CMAKE_CXX_FLAGS or add_compile_options, not working by inspecting flags.make in which CXX_FLAGS is:

CXX_FLAGS = -march=x86-64 -O3 -DNDEBUG -fPIC -march-native -msse4.2 -mfpmath=sse -std=gnu++14

and the letter -march=native wins.

1

There are 1 answers

0
AudioBubble On

First of all, thanks @Tsyvarev and @Lack for useful suggestions.

I solved that problem by recompile PCL from stretch by adding -DPCL_ENABLE_MARCHNATIVE=False -DPCL_ENABLE_SSE=False .. as following command:

cmake -DCMAKE_BUILD_TYPE=Release -DPCL_ENABLE_MARCHNATIVE=False -DPCL_ENABLE_SSE=False ..

This can eliminate -march=native from final flags, which will work on other devices and I test it.

Besides, someone says only -DPCL_ENABLE_SSE=False is needed due to mine PCL version is 1.10.1 and PCL_ENABLE_MARCHNATIVE was not introduced yet. But I haven't tried this.