11include (FeatureSummary)
2+ include (PHP/Install )
23
34option (PHP_PEAR "Whether to install PEAR" OFF )
45
@@ -53,19 +54,16 @@ endif()
5354# TODO: INSTALL_PREFIX here cannot be evaluated during the install phase.
5455set (EXPANDED_PEAR_INSTALLDIR "${_php_pear_dir} " CACHE INTERNAL "PEAR dir" )
5556
56- # TODO: Recheck if _php_pear_dir needs to be manually created here.
57- install (CODE "
58- set(_php_pear_installer_url \" https://pear.php.net/install-pear-nozlib.phar\" )
57+ if (NOT CMAKE_CROSSCOMPILING )
58+ set (PHP_EXECUTABLE "$<TARGET_FILE:php_cli>" )
59+ elseif (CMAKE_CROSSCOMPILING AND CMAKE_CROSSCOMPILING_EMULATOR)
60+ set (PHP_EXECUTABLE "${CMAKE_CROSSCOMPILING_EMULATOR} ;$<TARGET_FILE:php_cli>" )
61+ endif ()
5962
60- # The generator expression $<INSTALL_PREFIX> inside CODE argument is evaluated
61- # in CMake 3.27+.
62- if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.27)
63- set(prefix $<INSTALL_PREFIX>)
64- else()
65- set(prefix \$ {CMAKE_INSTALL_PREFIX})
66- endif()
63+ set (_phpPearInstallerUrl "https://pear.php.net/install-pear-nozlib.phar" )
6764
68- message(STATUS \" Installing PEAR environment: ${_php_pear_dir} \" )
65+ php_install(CODE "
66+ message(STATUS \" Installing PEAR: \$ ENV{DESTDIR}${_php_pear_dir} \" )
6967
7068 if(EXISTS \" ${CMAKE_CURRENT_SOURCE_DIR} /install-pear-nozlib.phar\"
7169 AND NOT \" ${CMAKE_CURRENT_SOURCE_DIR} \" STREQUAL \" ${CMAKE_CURRENT_BINARY_DIR} \"
@@ -80,31 +78,51 @@ install(CODE "
8078 if(NOT EXISTS \" ${CMAKE_CURRENT_BINARY_DIR} /install-pear-nozlib.phar\" )
8179 file(
8280 DOWNLOAD
83- \$ {_php_pear_installer_url }
81+ ${_phpPearInstallerUrl }
8482 \" ${CMAKE_CURRENT_BINARY_DIR} /install-pear-nozlib.phar\"
8583 SHOW_PROGRESS
86- STATUS _php_pear_download
84+ STATUS downloadStatus
8785 )
8886
89- if(NOT _php_pear_download )
87+ if(NOT downloadStatus )
9088 # Download using fetch.php.
9189 execute_process(
92- COMMAND ${PHP_BINARY_DIR} /sapi/cli/php
93- -n
94- ${CMAKE_CURRENT_BINARY_DIR} /fetch.php
95- \"\$ {_php_pear_installer_url}\"
96- ${CMAKE_CURRENT_BINARY_DIR} /install-pear-nozlib.phar
90+ COMMAND ${PHP_EXECUTABLE}
91+ -n
92+ ${CMAKE_CURRENT_BINARY_DIR} /fetch.php
93+ ${_phpPearInstallerUrl}
94+ ${CMAKE_CURRENT_BINARY_DIR} /install-pear-nozlib.phar
95+ OUTPUT_VARIABLE output
96+ ERROR_VARIABLE output
9797 )
98+ if(output)
99+ message(STATUS \"\$ {output}\" )
100+ endif()
98101 endif()
99102 endif()
100103
101104 if(EXISTS ${CMAKE_CURRENT_BINARY_DIR} /install-pear-nozlib.phar)
102- # PEAR reads the INSTALL_ROOT environment variable to install pear.conf.
103- # TODO: Adjust this further.
104- #set(ENV{INSTALL_ROOT} \"\$ {prefix}\" )
105+ # PEAR reads the staging INSTALL_ROOT environment variable if set. However,
106+ # there is a bug where .channels, .registry and temporary dot files are
107+ # duplicated outside of the INSTALL_ROOT into the install prefix. No known
108+ # workaround. See: https://pear.php.net/bugs/bug.php?id=20383
109+ if(DEFINED ENV{DESTDIR})
110+ set(ENV{INSTALL_ROOT} \"\$ ENV{DESTDIR}\" )
111+ endif()
112+
113+ # The PEAR's --config option doesn't seem to install the pear.conf into the
114+ # specified directory, but the sysconf can be also bypassed with the
115+ # environment variable.
116+ set(ENV{PHP_PEAR_SYSCONF_DIR} \$ {CMAKE_INSTALL_FULL_SYSCONFDIR})
117+
118+ file(
119+ MAKE_DIRECTORY
120+ \$ ENV{DESTDIR}${_php_pear_dir}
121+ ${CMAKE_CURRENT_BINARY_DIR} /CMakeFiles/pear
122+ )
105123
106124 execute_process(
107- COMMAND ${PHP_BINARY_DIR} /sapi/cli/php
125+ COMMAND ${PHP_EXECUTABLE}
108126 -n
109127 -dshort_open_tag=0
110128 -dopen_basedir=
@@ -113,19 +131,26 @@ install(CODE "
113131 -ddetect_unicode=0
114132 ${CMAKE_CURRENT_BINARY_DIR} /install-pear-nozlib.phar
115133 --dir \" ${_php_pear_dir} \"
116- --bin \"\$ {prefix}/${CMAKE_INSTALL_BINDIR} \"
117- --config \"\$ {prefix}/${CMAKE_INSTALL_SYSCONFDIR} \"
118- --metadata \"\$ {prefix}/${CMAKE_INSTALL_DATADIR} \"
134+ --bin \"\$ {CMAKE_INSTALL_FULL_BINDIR}\"
135+ --metadata \" ${_php_pear_dir} \"
136+ --data \" ${_php_pear_dir} \"
137+ --temp \" ${CMAKE_CURRENT_BINARY_DIR} /CMakeFiles/pear\"
138+ #--php \$ {CMAKE_INSTALL_FULL_BINDIR}/$<TARGET_FILE_NAME:php_cli>
119139 -dp a${PHP_PROGRAM_PREFIX}
120- -ds a$(PHP_PROGRAM_SUFFIX)
140+ -ds a${PHP_PROGRAM_SUFFIX}
141+ OUTPUT_VARIABLE output
142+ ERROR_VARIABLE output
121143 )
144+ if(output)
145+ message(STATUS \"\$ {output}\" )
146+ endif()
122147 else()
123148 message(
124149 WARNING
125150 \" The installation process is not complete. The following resources \"
126151 \" were not installed:\\ n\"
127152 \" PEAR: PHP Extension and Application Repository\\ n\"
128- \" To install these components, download \$ {_php_pear_installer_url } to \"
153+ \" To install these components, download ${_phpPearInstallerUrl } to \"
129154 \" to php-src/pear/ and repeat the 'cmake --install' command.\"
130155 )
131156 endif()
0 commit comments