Skip to content

Commit

Permalink
Fix CS and make paths in output messages relative
Browse files Browse the repository at this point in the history
- synced CS
- typo fixed in linking win32
- messages with output files now display paths relative to the top
  project binary directory
  • Loading branch information
petk committed Dec 9, 2024
1 parent 3bfb815 commit 14b8b4d
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 52 deletions.
15 changes: 10 additions & 5 deletions cmake/Zend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -655,12 +655,17 @@ endif()
configure_file(cmake/zend_config.h.in CMakeFiles/zend_config.h)

if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
message(STATUS "Creating Zend/zend_config.h")

cmake_path(
RELATIVE_PATH
CMAKE_CURRENT_BINARY_DIR
BASE_DIRECTORY ${CMAKE_BINARY_DIR}
OUTPUT_VARIABLE relativeDir
)
message(STATUS "Creating ${relativeDir}/zend_config.h")
file(
WRITE
${CMAKE_CURRENT_BINARY_DIR}/zend_config.h
"#include <../main/php_config.h>\n"
CONFIGURE
OUTPUT zend_config.h
CONTENT "#include <../main/php_config.h>\n"
)
endif()

Expand Down
3 changes: 2 additions & 1 deletion cmake/cmake/modules/FindDTrace.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ function(dtrace_target)
]]
)
cmake_path(
RELATIVE_PATH parsed_HEADER
RELATIVE_PATH
parsed_HEADER
BASE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
OUTPUT_VARIABLE header
)
Expand Down
9 changes: 8 additions & 1 deletion cmake/cmake/modules/FindMC.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,17 @@ function(mc_target)
VERBATIM
)

cmake_path(
RELATIVE_PATH
output
BASE_DIRECTORY ${CMAKE_BINARY_DIR}
OUTPUT_VARIABLE relativePath
)

add_custom_target(
${parsed_NAME}
SOURCES "${parsed_INPUT}"
DEPENDS "${output}"
COMMENT "[MC][${parsed_NAME}] Generating ${output}"
COMMENT "[MC][${parsed_NAME}] Generating ${relativePath}"
)
endfunction()
61 changes: 33 additions & 28 deletions cmake/cmake/modules/PHP/PkgConfigGenerator.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pkgconfig_generate_pc(
)
```
Generate pkgconfig `<pc-file-output>` from the given pc `<pc-template-file>`
Generate pkg-config `<pc-file-output>` from the given pc `<pc-template-file>`
template.
* `TARGET`
Expand Down Expand Up @@ -72,20 +72,20 @@ function(_pkgconfig_parse_variables variables)
)
endif()

set(is_value FALSE)
set(variables_options "")
set(result_variables "")
set(result_values "")
set(isValue FALSE)
set(variablesOptions "")
set(resultVariables "")
set(resultValues "")
foreach(variable IN LISTS variables)
if(is_value)
set(is_value FALSE)
if(isValue)
set(isValue FALSE)
continue()
endif()
list(POP_FRONT variables var value)

list(APPEND result_variables ${var})
list(APPEND resultVariables ${var})

# The result_values are for the install(CODE) and generator expression
# The resultValues are for the install(CODE) and generator expression
# $<INSTALL_PREFIX> works since CMake 3.27, for earlier versions the escaped
# variable CMAKE_INSTALL_PREFIX can be used.
if(
Expand All @@ -96,16 +96,16 @@ function(_pkgconfig_parse_variables variables)
REPLACE
"$<INSTALL_PREFIX>"
"\${CMAKE_INSTALL_PREFIX}"
replaced_value
replacedValue
"${value}"
)
list(APPEND result_values "${replaced_value}")
list(APPEND resultValues "${replacedValue}")
else()
list(APPEND result_values "${value}")
list(APPEND resultValues "${value}")
endif()

# Replace possible INSTALL_PREFIX in value for usage in add_custom_command,
# in the result_values above the intact genex is left for enabling the
# in the resultValues above the intact genex is left for enabling the
# possible 'cmake --install --prefix ...' override.
if(value MATCHES [[.*\$<INSTALL_PREFIX>.*]])
string(
Expand All @@ -117,14 +117,14 @@ function(_pkgconfig_parse_variables variables)
)
endif()

list(APPEND variables_options -D ${var}="${value}")
list(APPEND variablesOptions -D ${var}="${value}")

set(is_value TRUE)
set(isValue TRUE)
endforeach()

set(variables_options "${variables_options}" PARENT_SCOPE)
set(result_variables "${result_variables}" PARENT_SCOPE)
set(result_values "${result_values}" PARENT_SCOPE)
set(variablesOptions "${variablesOptions}" PARENT_SCOPE)
set(resultVariables "${resultVariables}" PARENT_SCOPE)
set(resultValues "${resultValues}" PARENT_SCOPE)
endfunction()

function(pkgconfig_generate_pc)
Expand Down Expand Up @@ -209,36 +209,41 @@ function(pkgconfig_generate_pc)
)

if(parsed_TARGET)
set(target_option -D TARGET_FILE="$<TARGET_FILE:${parsed_TARGET}>")
set(targetOption -D TARGET_FILE="$<TARGET_FILE:${parsed_TARGET}>")
endif()

if(parsed_VARIABLES)
_pkgconfig_parse_variables("${parsed_VARIABLES}")
endif()

cmake_path(GET template FILENAME filename)
cmake_path(
RELATIVE_PATH
output
BASE_DIRECTORY ${CMAKE_BINARY_DIR}
OUTPUT_VARIABLE outputRelativePath
)

string(MAKE_C_IDENTIFIER "${filename}" target_name)
string(MAKE_C_IDENTIFIER "${outputRelativePath}" targetName)

add_custom_target(
pkgconfig_generate_${target_name}
pkgconfig_${targetName}
ALL
COMMAND ${CMAKE_COMMAND}
-D PKGCONFIG_OBJDUMP_EXECUTABLE=${PKGCONFIG_OBJDUMP_EXECUTABLE}
-D TEMPLATE=${template}
-D OUTPUT=${output}
${target_option}
${variables_options}
${targetOption}
${variablesOptions}
-P CMakeFiles/PkgConfigGeneratePc.cmake
COMMENT "[PkgConfig] Generating pkg-config ${filename} file"
COMMENT "[PkgConfig] Generating ${outputRelativePath}"
)

install(CODE "
block()
set(result_variables ${result_variables})
set(result_values \"${result_values}\")
set(resultVariables ${resultVariables})
set(resultValues \"${resultValues}\")
foreach(var value IN ZIP_LISTS result_variables result_values)
foreach(var value IN ZIP_LISTS resultVariables resultValues)
set(\${var} \"\${value}\")
endforeach()
Expand Down
26 changes: 15 additions & 11 deletions cmake/cmake/platforms/Windows.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,28 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
# these are always known on Windows systems.
# TODO: Update and fix this better.

# PHP has custom syslog.h for Windows platform.
set(HAVE_SYSLOG_H TRUE)
set(HAVE_FNMATCH TRUE)

# PHP has custom usleep for Windows platform.
set(HAVE_USLEEP TRUE)
# PHP has unconditional getaddrinfo() support on Windows for now.
set(HAVE_GETADDRINFO TRUE)

# PHP defines getpid as _getpid on Windows.
set(HAVE_GETPID TRUE)

# PHP has custom nanosleep for Windows platform.
set(HAVE_NANOSLEEP TRUE)

# PHP supports socketpair by the emulation in win32/sockets.c
set(HAVE_NICE TRUE)

# PHP supports socketpair by the emulation in win32/sockets.c.
set(HAVE_SOCKETPAIR TRUE)

# PHP has unconditional getaddrinfo() support on Windows for now.
set(HAVE_GETADDRINFO TRUE)
# PHP defines strcasecmp in zend_config.w32.h.
set(HAVE_STRCASECMP TRUE)

set(HAVE_NICE TRUE)
set(HAVE_FNMATCH TRUE)
# PHP has custom syslog.h for Windows platform.
set(HAVE_SYSLOG_H TRUE)

# PHP defines getpid as _getpid on Windows.
set(HAVE_GETPID TRUE)
# PHP has custom usleep for Windows platform.
set(HAVE_USLEEP TRUE)
endif()
8 changes: 7 additions & 1 deletion cmake/ext/date/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ target_compile_definitions(

set(HAVE_TIMELIB_CONFIG_H TRUE)

message(STATUS "Creating ext/date/lib/timelib_config.h")
cmake_path(
RELATIVE_PATH
CMAKE_CURRENT_BINARY_DIR
BASE_DIRECTORY ${CMAKE_BINARY_DIR}
OUTPUT_VARIABLE relativeDir
)
message(STATUS "Creating ${relativeDir}/lib/timelib_config.h")
file(CONFIGURE OUTPUT lib/timelib_config.h CONTENT [[
#ifdef PHP_WIN32
# include "config.w32.h"
Expand Down
9 changes: 8 additions & 1 deletion cmake/ext/opcache/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ if(EXT_OPCACHE_JIT)
# Help minilua create a jit build directory.
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/jit)

cmake_path(
RELATIVE_PATH
CMAKE_CURRENT_BINARY_DIR
BASE_DIRECTORY ${CMAKE_BINARY_DIR}
OUTPUT_VARIABLE relativeDir
)

# Generate Jit for architecture.
add_custom_command(
OUTPUT jit/zend_jit_${DASM_ARCH}.c
Expand All @@ -213,7 +220,7 @@ if(EXT_OPCACHE_JIT)
${DASM_FLAGS}
-o ${CMAKE_CURRENT_BINARY_DIR}/jit/zend_jit_${DASM_ARCH}.c
${CMAKE_CURRENT_SOURCE_DIR}/jit/zend_jit_${DASM_ARCH}.dasc
COMMENT "[ext/opcache] Generating ext/opcache/jit/zend_jit_${DASM_ARCH}.c"
COMMENT "[ext/opcache] Generating ${relativeDir}/jit/zend_jit_${DASM_ARCH}.c"
DEPENDS
jit/dynasm/dynasm.lua
jit/zend_jit_${DASM_ARCH}.dasc
Expand Down
13 changes: 10 additions & 3 deletions cmake/ext/phar/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ if(EXT_PHAR_SHARED OR BUILD_SHARED_LIBS)
)
endif()

cmake_path(
RELATIVE_PATH
CMAKE_CURRENT_BINARY_DIR
BASE_DIRECTORY ${CMAKE_BINARY_DIR}
OUTPUT_VARIABLE relativeDir
)

add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/phar.php
COMMAND
Expand All @@ -153,7 +160,7 @@ add_custom_command(
-d phar.readonly=0
${CMAKE_CURRENT_SOURCE_DIR}/build_precommand.php
> ${CMAKE_CURRENT_BINARY_DIR}/phar.php
COMMENT "[ext/phar] Generating phar.php"
COMMENT "[ext/phar] Generating ${relativeDir}/phar.php"
VERBATIM
)

Expand All @@ -179,7 +186,7 @@ add_custom_command(
${CMAKE_CURRENT_SOURCE_DIR}/phar
DEPENDS
${CMAKE_CURRENT_BINARY_DIR}/phar.php
COMMENT "[ext/phar] Generating phar.phar"
COMMENT "[ext/phar] Generating ${relativeDir}/phar.phar"
VERBATIM
)

Expand Down Expand Up @@ -210,7 +217,7 @@ add_custom_command(
${CMAKE_COMMAND} -P CMakeFiles/PharPermissions.cmake
DEPENDS
${CMAKE_CURRENT_BINARY_DIR}/phar.phar
COMMENT "[ext/phar] Generating phar"
COMMENT "[ext/phar] Generating ${relativeDir}/phar"
)

file(
Expand Down
2 changes: 1 addition & 1 deletion cmake/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ target_link_libraries(
php_main
# If Zend is STATIC library link as whole archive, otherwise link normally.
$<IF:$<STREQUAL:$<TARGET_PROPERTY:Zend::Zend,TYPE>,STATIC_LIBRARY>,$<LINK_LIBRARY:WHOLE_ARCHIVE,Zend::Zend>,Zend::Zend>
$<$<TARGET_EXISTS:PHP::windows>::PHP::windows>
$<$<TARGET_EXISTS:PHP::windows>:PHP::windows>
PHP::extensions
)

Expand Down

0 comments on commit 14b8b4d

Please sign in to comment.