Created
October 7, 2019 01:21
-
-
Save jasny/61c3eafa25c2d316932cda436124c34c to your computer and use it in GitHub Desktop.
CMake configuration for php-src
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 3.8) | |
project(php C) | |
# 32bit or 64bit | |
set(BITNESS 32) | |
if(CMAKE_SIZEOF_VOID_P EQUAL 8) | |
set(BITNESS 64) | |
endif() | |
# Global definitions | |
add_compile_definitions(HAVE_CONFIG_H) | |
# Use autoconf to generate system specific source and header files. | |
execute_process( | |
COMMAND ./buildconf | |
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} | |
) | |
execute_process( | |
COMMAND ./configure --disable-all | |
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} | |
) | |
# SHA3 lib | |
add_compile_definitions(KeccakP200_excluded KeccakP400_excluded KeccakP800_excluded) | |
file(GLOB SHA3_FILES "ext/hash/sha3/generic${BITNESS}lc/*.h" "ext/hash/sha3/generic${BITNESS}lc/*.c") | |
add_library(sha3 ${SHA3_FILES}) | |
target_include_directories(sha3 PRIVATE ${PROJECT_SOURCE_DIR}/ext/hash/sha3/generic${BITNESS}lc) | |
# Date lib | |
file(GLOB DATE_FILES "ext/date/lib/*.c") | |
add_library(date ${DATE_FILES}) | |
target_include_directories(date PRIVATE ${PROJECT_SOURCE_DIR}/ext/date/lib) | |
# PCRE lib | |
file(GLOB PCRE_FILES "ext/pcre/pcre2lib/*.c") | |
list(FILTER PCRE_FILES EXCLUDE REGEX "pcre2_(jit_match|jit_misc|printint)") | |
add_library(pcre ${PCRE_FILES}) | |
target_include_directories(pcre PRIVATE ${PROJECT_SOURCE_DIR}/main ${PROJECT_SOURCE_DIR}/ext/pcre/pcre2lib) | |
# Generate .c and .h files with yacc and re2c via make | |
file(GLOB_RECURSE YACC_FILES | |
${PROJECT_SOURCE_DIR}/Zend/*.y | |
${PROJECT_SOURCE_DIR}/Zend/*.l | |
${PROJECT_SOURCE_DIR}/ext/standard/*.re | |
) | |
foreach (SOURCE IN LISTS YACC_FILES) | |
string(REGEX REPLACE "\\.[a-z]+$" ".c" TARGET_C ${SOURCE}) | |
unset(TARGET_H) | |
if (SOURCE MATCHES "\\.y$") | |
string(REGEX REPLACE "\\.y$" ".h" TARGET_H ${SOURCE}) | |
endif() | |
message("${SOURCE} => ${TARGET_C} ${TARGET_H}") | |
list(APPEND YACC_TARGETS ${TARGET_C} ${TARGET_H}) | |
add_custom_command( | |
OUTPUT ${TARGET_C} ${TARGET_H} | |
MAIN_DEPENDENCY ${SOURCE} | |
COMMAND make ${TARGET_C} | |
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} | |
) | |
endforeach() | |
add_custom_target(generated_source DEPENDS ${YACC_TARGETS}) | |
# PHP | |
file(GLOB SOURCE_FILES | |
"sapi/cli/*.h" "sapi/cli/*.c" | |
"ext/ctype/*.h" "ext/ctype/*.c" | |
"ext/date/*.h" "ext/date/*.c" | |
"ext/date/*.h" "ext/date/*.c" | |
"ext/hash/*.h" "ext/hash/*.c" | |
"ext/pcre/*.h" "ext/pcre/*.c" | |
"ext/reflection/*.h" "ext/reflection/*.c" | |
"ext/spl/*.h" "ext/spl/*.c" | |
"ext/standard/*.h" "ext/standard/*.c" | |
"main/*.h" "main/*.c" | |
"main/*/*.h" "main/*/*.c" | |
"Zend/*.h" "Zend/*.c" | |
) | |
list(FILTER SOURCE_FILES EXCLUDE REGEX "_win") | |
list(FILTER SOURCE_FILES EXCLUDE REGEX "internal_functions_.+\\.c") | |
add_executable(php ${SOURCE_FILES} ${YACC_TARGETS}) | |
target_include_directories(php PRIVATE | |
${PROJECT_SOURCE_DIR} | |
${PROJECT_SOURCE_DIR}/main | |
${PROJECT_SOURCE_DIR}/TSRM | |
${PROJECT_SOURCE_DIR}/Zend | |
${PROJECT_SOURCE_DIR}/ext/hash/sha3/generic${BITNESS}lc | |
${PROJECT_SOURCE_DIR}/ext/date/lib | |
${PROJECT_SOURCE_DIR}/ext/pcre/pcre2lib | |
) | |
add_dependencies(php sha3 date pcre) | |
target_link_libraries(php crypt resolv rt m dl sha3 date pcre) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment