Skip to content

Commit a0d8ad6

Browse files
committed
Fix PIC and IPO settings for 32-bit machines
1 parent fc8367a commit a0d8ad6

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

cmake/cmake/Bootstrap.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ endif()
1616

1717
# Check whether to enable interprocedural optimization.
1818
include(PHP/InterproceduralOptimization)
19+
20+
# Set CMAKE_POSITION_INDEPENDENT_CODE.
21+
include(PHP/PositionIndependentCode)

cmake/cmake/CMakeDefaults.cmake

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ if(
2626
set(CMAKE_COLOR_DIAGNOSTICS ON)
2727
endif()
2828

29-
# Disable PIC for all targets. PIC is enabled for shared extensions manually.
30-
set(CMAKE_POSITION_INDEPENDENT_CODE OFF)
31-
3229
# Set empty prefix for targets instead of default "lib".
3330
set(CMAKE_SHARED_LIBRARY_PREFIX_C "")
3431
set(CMAKE_SHARED_MODULE_PREFIX_C "")

cmake/cmake/modules/PHP/InterproceduralOptimization.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ elseif(CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
4242
STATUS
4343
"Interprocedural optimization (IPO) disabled (AppleClang)"
4444
)
45+
elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_SIZEOF_VOID_P EQUAL 4)
46+
# On 32-bit Linux machine, this produced undefined references linker errors.
47+
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION OFF)
48+
49+
message(
50+
STATUS
51+
"Interprocedural optimization (IPO) disabled (Clang on 32-bit)"
52+
)
4553
else()
4654
include(CheckIPOSupported)
4755
check_ipo_supported(RESULT result)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#[=============================================================================[
2+
Check whether to enable the POSITION_INDEPENDENT_CODE or not.
3+
4+
https://cmake.org/cmake/help/latest/variable/CMAKE_POSITION_INDEPENDENT_CODE.html
5+
]=============================================================================]#
6+
7+
if(CMAKE_COMPILER_ID STREQUAL "Clang" AND CMAKE_SIZEOF_VOID_P EQUAL 4)
8+
# On 32-bit Linux and FreeBSD at least when using Clang, the pic is required.
9+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
10+
else()
11+
# Disable PIC for all targets. PIC is enabled for shared extensions manually.
12+
set(CMAKE_POSITION_INDEPENDENT_CODE OFF)
13+
endif()

0 commit comments

Comments
 (0)