Skip to content

Commit b644e8c

Browse files
committed
Handle PIC flags by cmake in wamrc
1 parent d1eb64a commit b644e8c

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

wamr-compiler/CMakeLists.txt

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -132,23 +132,11 @@ endif ()
132132

133133
message ("-- Build as target ${WAMR_BUILD_TARGET}")
134134

135-
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
136-
if (WAMR_BUILD_TARGET STREQUAL "X86_64" OR WAMR_BUILD_TARGET STREQUAL "AMD_64"
137-
OR WAMR_BUILD_TARGET MATCHES "AARCH64.*" OR WAMR_BUILD_TARGET MATCHES "RISCV64.*")
138-
if (NOT WAMR_BUILD_PLATFORM STREQUAL "windows")
139-
# Add -fPIC flag if build as 64-bit
140-
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
141-
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
142-
set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -fPIC")
143-
set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS} -fPIC")
144-
endif ()
145-
else ()
146-
# Add -m32 flag if compiling on 64-bit system for 32-bit x86 target
147-
if (WAMR_BUILD_TARGET STREQUAL "X86_32")
148-
add_definitions (-m32)
149-
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
150-
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
151-
endif ()
135+
# Add -m32 flag if compiling on 64-bit system for 32-bit x86 target
136+
if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND WAMR_BUILD_TARGET STREQUAL "X86_32")
137+
add_definitions (-m32)
138+
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
139+
set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -m32")
152140
endif ()
153141

154142
if (NOT CMAKE_BUILD_TYPE)
@@ -378,7 +366,7 @@ add_library (aotclib ${IWASM_COMPL_SOURCE})
378366

379367
add_executable (wamrc main.c)
380368
check_pie_supported()
381-
set_target_properties (wamrc PROPERTIES POSITION_INDEPENDENT_CODE ON)
369+
set_target_properties (wamrc vmlib aotclib PROPERTIES POSITION_INDEPENDENT_CODE ON)
382370
set_version_info (wamrc)
383371

384372
if (LLVM_LINK_LLVM_DYLIB)

0 commit comments

Comments
 (0)