Skip to content

Commit

Permalink
[#20] Fixes Example app build for Android (Old Arch) on Windows...
Browse files Browse the repository at this point in the history
to be tested / corrected for other build environments / targets
  • Loading branch information
birdofpreyru committed Mar 13, 2023
1 parent 3bd511d commit 36a894e
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 29 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ StaticServerExample/my-release-key.keystore
.project
.settings/
android/.project
/android/**/jniLibs/*/*.so

# generated by bob
lib/
Expand All @@ -66,6 +67,7 @@ lib/

# MSBuild Binary and Structured Log
*.binlog
*.tlog

# Other
/dr.pogodin-react-native-static-server-*.tgz
Expand Down
68 changes: 41 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,57 @@ cmake_minimum_required(VERSION 3.7.0 FATAL_ERROR)
# Lighttpd CMakeLists.txt miss BUNDLE DESTINATION.
set(CMAKE_MACOSX_BUNDLE OFF)

# These ensure pkg-config, if present, attempts to link Lighttpd against our
# local build of PCRE2, rather than the host system's one, if present. Though,
# we don't really install PCRE2 into this location, we just add extra include
# and link directories to ensure that compiler and linker will find the library
# without installation.
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/sysroot")
set(ENV{PKG_CONFIG_PATH} "${CMAKE_BINARY_DIR}/pcre2")
# Pre-build of PCRE2 for the target system from sources.

add_subdirectory(pcre2)
if(CMAKE_CROSSCOMPILING AND CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
file(
COPY ${CMAKE_CURRENT_SOURCE_DIR}/windows/ReactNativeStaticServer/lighttpd/lemon.exe
DESTINATION ${CMAKE_BINARY_DIR}/lighttpd1.4/build
)
set(LEMON_PATH ${CMAKE_BINARY_DIR}/lighttpd1.4/build/lemon.exe)
endif()

if(CMAKE_SYSTEM_NAME MATCHES "Android|Windows")
set(BUILD_SHARED_LIBS 1)
if(CMAKE_SYSTEM_NAME MATCHES "Android")
set(
EXTRA_BUILD_ARGS
-DANDROID_ABI=${ANDROID_ABI}
-DANDROID_PLATFORM=${ANDROID_PLATFORM}
-DANDROID_STL=${ANDROID_STL}
-GNinja
)
endif()

# set(CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/pcre2)
execute_process(
COMMAND cmake ${CMAKE_CURRENT_SOURCE_DIR}/pcre2
-B ${CMAKE_BINARY_DIR}/pcre2
-DBUILD_SHARED_LIBS=ON
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/sysroot
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
${EXTRA_BUILD_ARGS}
)

add_subdirectory(lighttpd1.4)
execute_process(COMMAND cmake --build ${CMAKE_BINARY_DIR}/pcre2 --config Release)
execute_process(COMMAND cmake --install ${CMAKE_BINARY_DIR}/pcre2)

add_dependencies(lighttpd pcre2-8-static)

# TODO:
# When building for Windows using MSYS/MinGW with pre-installed
# PCRE2 library these commands below confuse the linker, failing
# the build. Should revisit, if these are really needed/correct
# for Android and iOS builds.
if(NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
target_include_directories(lighttpd
PRIVATE ${CMAKE_BINARY_DIR}/lighttpd1.4/build
PRIVATE ${CMAKE_BINARY_DIR}/pcre2
# Copies shared PCRE2 library into the folder from where Gradle automatically
# will bundle it in the host app package.
if(CMAKE_SYSTEM_NAME MATCHES "Android")
file(
COPY ${CMAKE_BINARY_DIR}/sysroot/lib/libpcre2-8.so
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/android/src/main/jniLibs/${ANDROID_ABI}
)
endif()

target_link_directories(lighttpd
PRIVATE ${CMAKE_BINARY_DIR}/lighttpd1.4/build
PRIVATE ${CMAKE_BINARY_DIR}/pcre2
)
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")

add_subdirectory(lighttpd1.4)

file(WRITE ${CMAKE_BINARY_DIR}/lighttpd1.4/build/plugin-static.h
PLUGIN_INIT(mod_indexfile)\n
PLUGIN_INIT(mod_dirlisting)\n
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ android {
externalNativeBuild {
cmake {
arguments "-DWITH_ANDROID_NDK_SYSLOG_INTERCEPT=ON", "-DWITH_JAVA_NATIVE_INTERFACE=ON", "-DBUILD_STATIC=ON"
targets "pcre2-8-static", "mod_indexfile", "mod_dirlisting", "mod_staticfile", "lighttpd"
targets "mod_indexfile", "mod_dirlisting", "mod_staticfile", "lighttpd"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lighttpd1.4
Binary file not shown.
Binary file modified windows/ReactNativeStaticServer/lighttpd/lighttpd.dll
Binary file not shown.
Binary file modified windows/ReactNativeStaticServer/lighttpd/mod_dirlisting.dll
Binary file not shown.
Binary file modified windows/ReactNativeStaticServer/lighttpd/mod_indexfile.dll
Binary file not shown.
Binary file modified windows/ReactNativeStaticServer/lighttpd/mod_staticfile.dll
Binary file not shown.
3 changes: 3 additions & 0 deletions windows/mingw.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@ mkdir -p $OUTPUT_FOLDER
cd $BUILD_FOLDER/lighttpd1.4/build
cp *.dll $OUTPUT_FOLDER

# NOTE: The Lemon binary created here is used by Android builds on Windows.
cp lemon.exe $OUTPUT_FOLDER

cd $MSYS2_PATH/bin
cp libpcre2-8-0.dll libwinpthread-1.dll $OUTPUT_FOLDER

0 comments on commit 36a894e

Please sign in to comment.