Skip to content

Commit

Permalink
Add various improvements
Browse files Browse the repository at this point in the history
- Reduced warnings when checking for re2c computed GCC goto extension
- Synced test program main prototypes
- Fixed CS
- Fixed musl libc determination
- Added OpenSSL::Crypto target to crypto locking callbacks include
  header check
  • Loading branch information
petk committed May 19, 2024
1 parent a889d2e commit 3497c1f
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 58 deletions.
12 changes: 6 additions & 6 deletions cmake/cmake/modules/FindRE2C.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,17 @@ if(RE2C_USE_COMPUTED_GOTOS)

cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_QUIET TRUE)
check_source_compiles(C "
int main(int argc, const char **argv) {
argc = argc;
argv = argv;
check_source_compiles(C [[
int main(void) {
label1:
;
label2:
static void *adr[] = { &&label1, &&label2};
;
static void *adr[] = { &&label1, &&label2 };
goto *adr[0];
return 0;
}
" _RE2C_HAVE_COMPUTED_GOTOS)
]] _RE2C_HAVE_COMPUTED_GOTOS)
cmake_pop_check_state()

if(_RE2C_HAVE_COMPUTED_GOTOS)
Expand Down
2 changes: 1 addition & 1 deletion cmake/cmake/modules/PHP/CheckFlushIo.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ if(NOT CMAKE_CROSSCOMPILING)
#endif
#include <string.h>

int main(int argc, char **argv) {
int main(void) {
char *filename = tmpnam(NULL);
char buffer[64];
int result = 1;
Expand Down
13 changes: 6 additions & 7 deletions cmake/cmake/modules/PHP/CheckFopencookie.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,21 @@ if(NOT HAVE_FOPENCOOKIE)
endif()

# GNU C library can have a different seeker definition using off64_t.
message(
CHECK_START
"Checking whether fopencookie seeker uses off64_t"
)
message(CHECK_START "Checking whether fopencookie seeker uses off64_t")

if(
CMAKE_CROSSCOMPILING
AND CMAKE_SYSTEM_NAME STREQUAL "Linux"
AND PHP_C_STANDARD_LIBRARY STREQUAL "glibc"
)
message(CHECK_PASS "yes (cross-compiling)")

set(
COOKIE_SEEKER_USES_OFF64_T 1
CACHE INTERNAL "Whether fopencookie seeker uses off64_t"
)

return()
else()
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
Expand Down Expand Up @@ -107,9 +108,7 @@ else()
cmake_pop_check_state()
endif()

if(CMAKE_CROSSCOMPILING AND COOKIE_SEEKER_USES_OFF64_T)
message(CHECK_PASS "yes (cross-compiling)")
elseif(COOKIE_SEEKER_USES_OFF64_T)
if(COOKIE_SEEKER_USES_OFF64_T)
message(CHECK_PASS "yes")
else()
message(CHECK_FAIL "no")
Expand Down
50 changes: 25 additions & 25 deletions cmake/cmake/modules/PHP/StandardLibrary.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[=============================================================================[
Determine C standard library that will be used for the build.
Determine the C standard library used for the build.
Result variables:
PHP_C_STANDARD_LIBRARY
Expand All @@ -19,9 +19,9 @@ include(CMakePushCheckState)

message(CHECK_START "Checking C standard library")

# Initial uClibc and its maintained fork uClibc-ng behave like minimalistic GNU
# C but aren't. These can be determined by the __UCLIBC__ symbol. They must be
# checked first because they also define the __GLIBC__ symbol.
# The uClibc and its maintained fork uClibc-ng behave like minimalistic GNU C
# library but have differences. They can be determined by the __UCLIBC__ symbol
# and must be checked first because they also define the __GLIBC__ symbol.
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_QUIET TRUE)
check_symbol_exists(__UCLIBC__ features.h _PHP_C_STANDARD_LIBRARY_UCLIBC)
Expand All @@ -32,8 +32,8 @@ if(_PHP_C_STANDARD_LIBRARY_UCLIBC)
return()
endif()

# GNU C standard library has __GLIBC__ and __GLIBC_MINOR__ symbols synce the
# very early versions 2.0.
# The GNU C standard library has __GLIBC__ and __GLIBC_MINOR__ symbols since the
# very early version 2.0.
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_QUIET TRUE)
check_symbol_exists(__GLIBC__ features.h _PHP_C_STANDARD_LIBRARY_GLIBC)
Expand All @@ -44,33 +44,33 @@ if(_PHP_C_STANDARD_LIBRARY_GLIBC)
return()
endif()

# The musl libc doesn't advertise itself specifically via symbols, so it must
# be guessed.
# The musl libc doesn't advertise itself with symbols, so it must be determined
# heuristically.
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_QUIET TRUE)
check_symbol_exists(__DEFINED_va_list stdarg.h _PHP_C_STANDARD_LIBRARY_MUSL)
cmake_pop_check_state()
if(_PHP_C_STANDARD_LIBRARY_MUSL)
set(PHP_C_STANDARD_LIBRARY "musl")
else()
# Otherwise, try determining musl libc with ldd.
block(PROPAGATE PHP_C_STANDARD_LIBRARY)
execute_process(
COMMAND ldd --version
OUTPUT_VARIABLE version
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)

if(version MATCHES ".*musl libc.*")
set(PHP_C_STANDARD_LIBRARY "musl")
endif()
endblock()
endif()
if(PHP_C_STANDARD_LIBRARY STREQUAL "musl")
set(__MUSL__ 1 CACHE INTERNAL "Whether musl libc is used.")
message(CHECK_PASS "musl")
return()
endif()

# Otherwise, try using ldd.
block(PROPAGATE PHP_C_STANDARD_LIBRARY)
execute_process(
COMMAND ldd --version
OUTPUT_VARIABLE version
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)

if(version MATCHES ".*musl libc.*")
set(__MUSL__ 1 CACHE INTERNAL "Whether musl libc is used")
set(PHP_C_STANDARD_LIBRARY "musl")
message(CHECK_PASS "musl")
return()
endif()
endblock()

message(CHECK_FAIL "unknown")
47 changes: 32 additions & 15 deletions cmake/ext/curl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,33 +70,40 @@ if(PHP_THREAD_SAFETY AND CURL_SSL_FOUND)
#include <strings.h>
#include <curl/curl.h>

int main(int argc, char *argv[]) {
int main(void) {
curl_version_info_data *data = curl_version_info(CURLVERSION_NOW);

if (data && data->ssl_version && *data->ssl_version) {
const char *ptr = data->ssl_version;

while(*ptr == ' ') ++ptr;
while(*ptr == ' ') {
++ptr;
}

int major, minor;
if (sscanf(ptr, "OpenSSL/%d", &major) == 1) {
if (major >= 3) {
/* OpenSSL version 3 or later */
return 4;
}

/* OpenSSL >= 3 */
if (sscanf(ptr, "OpenSSL/%d", &major) == 1 && major >= 3) {
return 4;
}
if (sscanf(ptr, "OpenSSL/%d.%d", &major, &minor) == 2) {
if (major > 1 || (major == 1 && minor >= 1)) {
/* OpenSSL version 1.1 or later */
return 3;
}

/* OpenSSL >= 1.1 */
if (
sscanf(ptr, "OpenSSL/%d.%d", &major, &minor) == 2 &&
(major > 1 || (major == 1 && minor >= 1))
) {
return 3;
}

/* OpenSSL < 1.1 */
if (strncasecmp(ptr, "OpenSSL", sizeof("OpenSSL")-1) == 0) {
/* Old OpenSSL version */
return 0;
}

/* Different SSL library */
return 2;
}

/* No SSL support */
return 1;
}
Expand All @@ -118,13 +125,23 @@ if(PHP_THREAD_SAFETY AND CURL_SSL_FOUND)

target_link_libraries(php_curl PRIVATE OpenSSL::Crypto)

check_include_file(openssl/crypto.h HAVE_OPENSSL_CRYPTO_H)
if(TARGET OpenSSL::Crypto)
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_LIBRARIES OpenSSL::Crypto)
check_include_file(openssl/crypto.h HAVE_OPENSSL_CRYPTO_H)
cmake_pop_check_state()
endif()
endif()
endif()

# Sanity check.
if(TARGET CURL::libcurl)
check_library_exists(CURL::libcurl curl_easy_perform "" HAVE_CURL_EASY_PERFORM)
check_library_exists(
CURL::libcurl
curl_easy_perform
""
HAVE_CURL_EASY_PERFORM
)

if(NOT HAVE_CURL_EASY_PERFORM)
message(
Expand Down
16 changes: 12 additions & 4 deletions cmake/ext/gd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,10 @@ if(NOT EXT_GD_EXTERNAL)
cmake_pop_check_state()

if(NOT _GD_SANITY_CHECK_COMPILES)
message(FATAL_ERROR "GD build test failed. Please check logs for details.")
message(
FATAL_ERROR
"GD build test failed. Please check logs for details."
)
endif()
endif()
endblock()
Expand Down Expand Up @@ -443,8 +446,8 @@ else()
void exit1(int priority, const char *format, va_list args) {
_exit(1);
}
/* Override the default gd_error_method with one that actually causes
the program to return an error. */
/* Override the default gd_error_method with one that actually
causes the program to return an error. */
int main(int argc, char** argv) {
${declaration};
gdSetErrorMethod(exit1);
Expand All @@ -465,6 +468,11 @@ else()

check_library_exists(GD::GD gdFontCacheShutdown "" HAVE_GD_FREETYPE)
check_library_exists(GD::GD gdVersionString "" HAVE_GD_LIBVERSION)
check_library_exists(GD::GD gdImageGetInterpolationMethod "" HAVE_GD_GET_INTERPOLATION)
check_library_exists(
GD::GD
gdImageGetInterpolationMethod
""
HAVE_GD_GET_INTERPOLATION
)
endif()
endif()

0 comments on commit 3497c1f

Please sign in to comment.