Skip to content

Commit

Permalink
[futurepress#84][futurepress#67] PCRE2 linking fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
birdofpreyru committed Nov 8, 2023
1 parent ef95720 commit 22ae60b
Showing 1 changed file with 13 additions and 29 deletions.
42 changes: 13 additions & 29 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ if(CMAKE_SYSTEM_NAME MATCHES "Android")
# Mac Catalyst build is the only scenario we have where the target system name
# is Darwin.
elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
set(PCRE2_TARGET --target pcre2-8-static)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -target x86_64-apple-ios-macabi")
set(
EXTRA_BUILD_ARGS
Expand All @@ -55,7 +54,6 @@ elseif(CMAKE_SYSTEM_NAME MATCHES "iOS")
-DCMAKE_IOS_INSTALL_COMBINED=${CMAKE_IOS_INSTALL_COMBINED}
-GXcode
)
set(PCRE2_TARGET --target pcre2-8-static)
endif()

if(CMAKE_SYSTEM_NAME MATCHES "Android|Windows")
Expand All @@ -76,20 +74,14 @@ execute_process(
execute_process(
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR}/pcre2
--config Release
${PCRE2_TARGET}
)

if(
NOT CMAKE_SYSTEM_NAME MATCHES "iOS"

# TODO: We wanna say "and not Mac Catalyst build", for which the current
# condition is not specific enough, but will do for now, as Mac Catalyst
# build is the only scenario we gonna have Darwin as the target platform
# as of now.
AND NOT CMAKE_SYSTEM_NAME MATCHES "Darwin"
# This allows to not sign compiled PCRE2 executables for iOS / macOS builds,
# we don't really use them anyway, but we need them build for the install
# command below to work.
-- CODE_SIGNING_ALLOWED=NO
)
execute_process(COMMAND ${CMAKE_COMMAND} --install ${CMAKE_BINARY_DIR}/pcre2)
endif()

execute_process(COMMAND ${CMAKE_COMMAND} --install ${CMAKE_BINARY_DIR}/pcre2)

# Copies shared PCRE2 library into the folder from where Gradle automatically
# will bundle it in the host app package.
Expand All @@ -104,21 +96,13 @@ if(CMAKE_SYSTEM_NAME MATCHES "Android|Windows")
set(BUILD_SHARED_LIBS 1)
endif()

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPCRE2_CODE_UNIT_WIDTH=8 -I${CMAKE_BINARY_DIR}/sysroot/include -L${CMAKE_BINARY_DIR}/sysroot/lib")

# To find PCRE2 Lighttpd first of all tries to use pkg_check_modules().
# It seems that on Linux it ends up relying on pkg-config utility of the host
# system, which find the host's version of PCRE2. With CMake 3.18.1 it was fine,
# as it used to output the linker flag for PCRE2 just as "-lpcre2-8",
# and just above we set the correct -L flag with the path of PCRE2
# cross-compiled for Android. However, with CMake 3.22.1 the CMake's default
# output is "-L/usr/lib/x86_64-linux-gnu;-lpcre2-8", which ends up forcing
# Lighttpd to try linking against the host's PCRE2, which fails. The flag set
# below instructs pkg-config to not include -L flag into outputs,
# thus restoring the correct linking. However, it is not the best fix,
# I guess.
# TODO: Find a better fix.
set(PKG_CONFIG_ARGN --libs-only-l)
# These enforce pkg_check_modules(), find_program(), etc. in Lighttpd CMake
# config to look for local build of PCRE2 in the location it was installed to.
set(CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}/sysroot")

# TODO: Not sure now, whether this is needed, or already covered by the variable
# above.
set(CMAKE_FIND_ROOT_PATH "${CMAKE_BINARY_DIR}/sysroot")

add_subdirectory(lighttpd1.4)

Expand Down

0 comments on commit 22ae60b

Please sign in to comment.