Skip to content

Commit 662b973

Browse files
authored
Append to cflag and honor CMAKE_POSITION_INDEPENDENT_CODE OFF (#16074)
### Summary With this change we append the _common_compile_options instead of replacing it and only set -fPIC if CMAKE_POSITION_INDEPENDENT_CODE is not set to OFF This fixes a problem when building from other projects like ZephyrOS as it already replaced setup _common_compile_options instead of just appending the flags. It also and always set -fPIC independent of how CMAKE_POSITION_INDEPENDENT_CODE was set. This was causing incompatible build binaries when building the objects files. ### Test plan Tested by invoking the project from ZephyrOS an look at generated build instructions after cmake has been executed. Signed-off-by: Zingo Andersen <Zingo.Andersen@arm.com>
1 parent 8f1a4bc commit 662b973

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

CMakeLists.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,16 @@ if(EXECUTORCH_BUILD_TESTS)
278278
endif()
279279

280280
# TODO(dbort): Fix these warnings and remove this flag.
281-
set(_common_compile_options
282-
$<$<CXX_COMPILER_ID:MSVC>:/wd4996>
283-
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-deprecated-declarations -fPIC>
281+
list(APPEND _common_compile_options $<$<CXX_COMPILER_ID:MSVC>:/wd4996>
282+
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-deprecated-declarations>
284283
)
284+
# Set default CMAKE_POSITION_INDEPENDENT_CODE behavior if ON or not set
285+
# (default) (and not for MSVC compiler)
286+
if(NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE
287+
OR CMAKE_POSITION_INDEPENDENT_CODE
288+
)
289+
list(APPEND _common_compile_options $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-fPIC>)
290+
endif()
285291

286292
# Let files say "include <executorch/path/to/header.h>".
287293
# TODO(#6475): This requires/assumes that the repo lives in a directory named

0 commit comments

Comments
 (0)