Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Install.cmake with InstallDirs.cmake #33

Open
wants to merge 1 commit into
base: PHP-8.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion bin/check-cmake.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ function getProjectModules(): array
],
'PHP/CheckCompilerFlag' => ['php_check_compiler_flag'],
'PHP/ConfigureFile' => ['php_configure_file'],
'PHP/Install' => ['php_install'],
'PHP/PkgConfigGenerator' => ['pkgconfig_generate_pc'],
'PHP/Re2c' => ['php_re2c', '/find_package\([\n ]*RE2C/'],
'PHP/SearchLibraries' => ['php_search_libraries'],
Expand Down
4 changes: 2 additions & 2 deletions cmake/cmake/Platform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ include(PHP/SystemExtensions)
# _GNU_SOURCE.
target_link_libraries(php_config INTERFACE PHP::SystemExtensions)

# Define GNU standard installation directories.
include(GNUInstallDirs)
# Define standard installation directories.
include(PHP/InstallDirs)

# Detect C standard library implementation.
include(PHP/StandardLibrary)
Expand Down
15 changes: 8 additions & 7 deletions cmake/cmake/modules/PHP/ConfigureFile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -250,20 +250,21 @@ function(php_configure_file)
)
endblock()

install(CODE "
string(CONFIGURE [[
block()
set(variables ${variables})
set(valuesInCode \"${valuesInCode}\")
set(variables @variables@)
set(valuesInCode "@valuesInCode@")

foreach(var value IN ZIP_LISTS variables valuesInCode)
set(\${var} \"\${value}\")
set(${var} "${value}")
endforeach()

configure_file(
${___phpConfigureFileTemplate}
${___phpConfigureFileOutput}
"@___phpConfigureFileTemplate@"
"@___phpConfigureFileOutput@"
@ONLY
)
endblock()
")
]] code @ONLY)
install(CODE "${code}")
endfunction()
144 changes: 0 additions & 144 deletions cmake/cmake/modules/PHP/Install.cmake

This file was deleted.

144 changes: 144 additions & 0 deletions cmake/cmake/modules/PHP/InstallDirs.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
#[=============================================================================[
# PHP/InstallDirs

This module is built on top of the CMake's GNUInstallDirs module and bypasses
some of its known issues when the GNU standards special cases are applied based
on the installation prefix (`CMAKE_INSTALL_PREFIX`). For example, when the
installation prefix is set to `/usr`, the `CMAKE_INSTALL_FULL_SYSCONF` variable
should be set to `/etc` and not `/usr/etc`, or the `CMAKE_INSTALL_LIBDIR`
variable on Debian-based machines should be `lib/<multiarch-tuple>` and not only
`lib` or `lib64`. And similar.

See: https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html

This module solves the following issues:

* When setting the installation prefix in the installation phase (after the
configuration and build phases) with the `--prefix` option:

```sh
cmake --install <build-dir> --prefix <installation-prefix>
```

the installation variables are adjusted according to GNU standards.

* It provides additional installation variables, for using them in the CMake's
`install()` commands. The following variables:

* `CMAKE_INSTALL_LIBDIR`
* `CMAKE_INSTALL_LOCALSTATEDIR`
* `CMAKE_INSTALL_RUNSTATEDIR`
* `CMAKE_INSTALL_SYSCONF`

can be replaced with their `PHP_INSTALL_*` substitutes, and the paths will be
set according to the GNU standards.

For example:

```cmake
install(TARGETS foo LIBRARY DESTINATION ${PHP_INSTALL_LIBDIR})
install(DIRECTORY DESTINATION ${PHP_INSTALL_LOCALSTATEDIR}/log)
install(DIRECTORY DESTINATION ${PHP_INSTALL_RUNSTATEDIR})
install(FILES foo.conf DESTINATION ${PHP_INSTALL_SYSCONFDIR})
```

* It enables `CMAKE_INSTALL_*` variables of the `GNUInstallDirs` module in the
`install(CODE)` and `install(SCRIPT)`.

## Basic usage

```cmake
# CMakeLists.txt

include(PHP/InstallDirs)

install(TARGETS foo LIBRARY DESTINATION ${PHP_INSTALL_LIBDIR})
install(DIRECTORY DESTINATION ${PHP_INSTALL_LOCALSTATEDIR}/log)
install(DIRECTORY DESTINATION ${PHP_INSTALL_RUNSTATEDIR})
install(FILES foo.conf DESTINATION ${PHP_INSTALL_SYSCONFDIR})
install(CODE [[
# Here the absolute libdir path is available, based on the platform and
# installation prefix.
message(STATUS "CMAKE_INSTALL_FULL_LIBDIR=${CMAKE_INSTALL_FULL_LIBDIR}")
]])
#]=============================================================================]

include_guard(GLOBAL)

if(IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}")
set(PHP_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}")
else()
set(PHP_INSTALL_LIBDIR "\${CMAKE_INSTALL_LIBDIR}")
endif()

if(IS_ABSOLUTE "${CMAKE_INSTALL_LOCALSTATEDIR}")
set(PHP_INSTALL_LOCALSTATEDIR "${CMAKE_INSTALL_LOCALSTATEDIR}")
else()
set(PHP_INSTALL_LOCALSTATEDIR "/\${PHP_INSTALL_LOCALSTATEDIR}")
endif()

if(IS_ABSOLUTE "${CMAKE_INSTALL_RUNSTATEDIR}")
set(PHP_INSTALL_RUNSTATEDIR "${CMAKE_INSTALL_RUNSTATEDIR}")
else()
set(PHP_INSTALL_RUNSTATEDIR "/\${PHP_INSTALL_RUNSTATEDIR}")
endif()

if(IS_ABSOLUTE "${CMAKE_INSTALL_SYSCONFDIR}")
set(PHP_INSTALL_SYSCONFDIR "${CMAKE_INSTALL_SYSCONFDIR}")
else()
set(PHP_INSTALL_SYSCONFDIR "/\${PHP_INSTALL_SYSCONFDIR}")
endif()

set(code "")
foreach(
var
BINDIR
DATADIR
DATAROOTDIR
DOCDIR
INCLUDEDIR
INFODIR
LIBDIR
LIBEXECDIR
LOCALEDIR
LOCALSTATEDIR
MANDIR
OLDINCLUDEDIR
RUNSTATEDIR
SBINDIR
SHAREDSTATEDIR
SYSCONFDIR
)
get_property(helpString CACHE CMAKE_INSTALL_${var} PROPERTY HELPSTRING)
if(helpString STREQUAL "No help, variable specified on the command line.")
string(CONFIGURE [[
@code@
set(CMAKE_INSTALL_@var@ "${CMAKE_INSTALL_@var@}")
]] code)
endif()
endforeach()

# Define GNU standard installation directories.
include(GNUInstallDirs)

string(CONFIGURE [[
######################## Added by PHP/InstallDirs.cmake ########################
@code@
set(CMAKE_SYSTEM_NAME "@CMAKE_SYSTEM_NAME@")
set(CMAKE_SIZEOF_VOID_P "@CMAKE_SIZEOF_VOID_P@")
set(CMAKE_LIBRARY_ARCHITECTURE "@CMAKE_LIBRARY_ARCHITECTURE@")
include(GNUInstallDirs)

set(PHP_INSTALL_LOCALSTATEDIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}")
cmake_path(GET PHP_INSTALL_LOCALSTATEDIR RELATIVE_PART PHP_INSTALL_LOCALSTATEDIR)

set(PHP_INSTALL_RUNSTATEDIR "${CMAKE_INSTALL_FULL_RUNSTATEDIR}")
cmake_path(GET PHP_INSTALL_RUNSTATEDIR RELATIVE_PART PHP_INSTALL_RUNSTATEDIR)

set(PHP_INSTALL_SYSCONFDIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}")
cmake_path(GET PHP_INSTALL_SYSCONFDIR RELATIVE_PART PHP_INSTALL_SYSCONFDIR)
############################ PHP/InstallDirs.cmake #############################
]] code @ONLY)
install(CODE "${code}" ALL_COMPONENTS)

unset(code)
Loading
Loading