11#[=============================================================================[
22# PHP/PositionIndependentCode
33
4- Wrapper module for CMake's `CheckPIESupported` module and
5- `CMAKE_POSITION_INDEPENDENT_CODE` variable.
4+ This module wraps the
5+ [CheckPIESupported](https://cmake.org/cmake/help/latest/module/CheckPIESupported.html)
6+ module and sets the `CMAKE_POSITION_INDEPENDENT_CODE` variable.
67
7- This module checks whether to enable the `POSITION_INDEPENDENT_CODE` target
8- property for all targets globally. The SHARED and MODULE targets have PIC always
9- enabled by default regardless of this module.
8+ With this module, the position-independent code (PIC) and position-independent
9+ executable (PIE) compile-time and link-time options are globally enabled for all
10+ targets. This enables building shared apache2handler, embed, and phpdbg SAPI
11+ libraries without duplicating builds or targets for executables, static and
12+ shared libraries.
1013
11- Position independent code (PIC) and position independent executable (PIE)
12- compile-time and link-time options are for now unconditionally added globally to
13- all targets, to be able to build shared apache2handler, embed, and phpdbg SAPI
14- libraries. This probably could be fine tuned in the future further but it can
15- exponentially complicate the build system code or the build usability.
14+ While finer control over PIC/PIE settings may be possible, doing so
15+ significantly increases build system complexity (two types of library and
16+ extension objects should be built - ones with PIC enabled and those with PIC
17+ disabled - which increases build time) or reduce usability (doing two builds
18+ - one for executable and static SAPIs and one for shared SAPIs).
19+
20+ SHARED and MODULE targets always have PIC enabled by default, regardless of
21+ this module.
1622
1723## Usage
1824
@@ -24,38 +30,11 @@ include(PHP/PositionIndependentCode)
2430
2531include_guard (GLOBAL )
2632
27- block()
28- include (CheckPIESupported)
29-
30- message (CHECK_START "Checking if linker supports PIE" )
31-
32- check_pie_supported(OUTPUT_VARIABLE output )
33-
34- if (CMAKE_C_LINK_PIE_SUPPORTED)
35- message (CHECK_PASS "yes" )
36- else ()
37- message (CHECK_FAIL "no" )
38-
39- if (
40- CMAKE_VERSION VERSION_GREATER_EQUAL 3.26
41- AND NOT DEFINED _PHP_POSITION_INDEPENDENT_CODE_LOGGED
42- )
43- message (
44- CONFIGURE_LOG
45- "Position independent executable (PIE) is not supported at link time:\n "
46- "${output} "
47- "PIE link options will not be passed to linker."
48- )
33+ include (CheckPIESupported)
4934
50- set (
51- _PHP_POSITION_INDEPENDENT_CODE_LOGGED
52- TRUE
53- CACHE INTERNAL
54- "Internal marker whether PIE check has been logged."
55- )
56- endif ()
57- endif ()
58- endblock()
35+ message (CHECK_START "Detecting linker PIE support" )
36+ check_pie_supported()
37+ message (CHECK_PASS "done" )
5938
6039if (NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE )
6140 set (CMAKE_POSITION_INDEPENDENT_CODE ON )
0 commit comments