Skip to content

Commit

Permalink
microsoft#1015 Add in support for adding i386 slice when building for…
Browse files Browse the repository at this point in the history
… 32-bit targets. Also improve messaging and add means to clean
  • Loading branch information
Benjamin Lee committed Jan 14, 2019
1 parent 21a609b commit bbe6cc9
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 7 deletions.
43 changes: 39 additions & 4 deletions Build_iOS/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ cmake_minimum_required(VERSION 3.1)

enable_testing()

set(LIB_CPPREST libcpprest.a)
set(LIB_CPPREST_LIB_DIR "${CMAKE_CURRENT_BINARY_DIR}/lib")

if (CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET)
set (ENV{CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET} ${CMAKE_XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET})
endif()

set(TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/ios-cmake/ios.toolchain.cmake")

set(SIM_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/build.i386" CACHE INTERNAL "")
set(SIM_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../Release" CACHE INTERNAL "")

set(SIM64_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/build.x86_64" CACHE INTERNAL "")
set(SIM64_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../Release" CACHE INTERNAL "")

Expand All @@ -31,9 +37,25 @@ endif()

add_test(NAME ios_runner
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../Release/tests/common/testrunner/ios
COMMAND xcodebuild test -project ios_runner.xcodeproj -configuration=${CMAKE_BUILD_TYPE} -scheme ios_runner -destination "platform=iOS Simulator,name=iPhone 6" LIBRARY_SEARCH_PATH=${SIM_BINARY_DIR}
COMMAND xcodebuild test -project ios_runner.xcodeproj -configuration=${CMAKE_BUILD_TYPE} -scheme ios_runner -destination "platform=iOS Simulator,name=iPhone 6" LIBRARY_SEARCH_PATH=${SIM64_BINARY_DIR}
)

if (INCLUDE_32BIT)
set (SIM_BINARY_LIB ${SIM_BINARY_DIR}/Binaries/${CMAKE_BUILD_TYPE}/${LIB_CPPREST})
file(MAKE_DIRECTORY ${SIM_BINARY_DIR})
execute_process(WORKING_DIRECTORY ${SIM_BINARY_DIR}
COMMAND ${CMAKE_COMMAND}
-GXcode
-DCMAKE_TOOLCHAIN_FILE=${TOOLCHAIN_FILE}
-DIOS_PLATFORM=SIMULATOR
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
"${DEPLOYMENT_TARGET}"
"${SIM_SOURCE_DIR}"
)
else()
set (SIM_BINARY_LIB "")
endif()

file(MAKE_DIRECTORY ${SIM64_BINARY_DIR})
execute_process(WORKING_DIRECTORY ${SIM64_BINARY_DIR}
COMMAND ${CMAKE_COMMAND}
Expand All @@ -57,6 +79,19 @@ execute_process(WORKING_DIRECTORY ${ARM_BINARY_DIR}
"${ARM_SOURCE_DIR}"
)

if (INCLUDE_32BIT)
set (SIM_TARGET sim)
## Simulator i386 version
add_custom_target(sim
COMMAND ${CMAKE_COMMAND}
--build ${SIM_BINARY_DIR}
--config ${CMAKE_BUILD_TYPE}
COMMENT "Building for i386 (simulator)"
VERBATIM
)
else()
set (SIM_TARGET "")
endif()

## Simulator x86_64 version
add_custom_target(sim64
Expand All @@ -76,20 +111,20 @@ add_custom_target(arm
VERBATIM
)

set(LIB_CPPREST libcpprest.a)
set(LIB_CPPREST_LIB_DIR "${CMAKE_CURRENT_BINARY_DIR}/lib")

add_custom_command(
OUTPUT ${LIB_CPPREST_LIB_DIR}/${LIB_CPPREST}
COMMAND mkdir -p "${LIB_CPPREST_LIB_DIR}"
COMMAND lipo -create
-output "${LIB_CPPREST_LIB_DIR}/${LIB_CPPREST}"
${SIM_BINARY_LIB}
${SIM64_BINARY_DIR}/Binaries/${CMAKE_BUILD_TYPE}/${LIB_CPPREST}
${ARM_BINARY_DIR}/Binaries/${CMAKE_BUILD_TYPE}/${LIB_CPPREST}
COMMAND cp -R "${CMAKE_CURRENT_SOURCE_DIR}/../Release/include" "${CMAKE_CURRENT_BINARY_DIR}"
DEPENDS
${SIM_TARGET}
sim64
arm
${SIM_BINARY_LIB}
"${SIM64_BINARY_DIR}/Binaries/${CMAKE_BUILD_TYPE}/${LIB_CPPREST}"
"${ARM_BINARY_DIR}/Binaries/${CMAKE_BUILD_TYPE}/${LIB_CPPREST}"
VERBATIM
Expand Down
24 changes: 21 additions & 3 deletions Build_iOS/configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ usage() {
echo " -config_only only configures cmake (no make invoked)."
echo " -include_32bit includes the 32-bit arm architectures."
echo " -no_bitcode disables bitcode"
echo " -clean deletes build directory prior to configuring"
}

ABS_PATH="`dirname \"$0\"`" # relative
Expand All @@ -22,6 +23,7 @@ CONFIG_ONLY=0
INCLUDE_32BIT=""
DISABLE_BITCODE=""
DEPLOYMENT_TARGET=""
CLEAN=0

# Command line argument parsing
while (( "$#" )); do
Expand Down Expand Up @@ -58,6 +60,10 @@ while (( "$#" )); do
DISABLE_BITCODE="-DDISABLE_BITCODE=ON"
shift 1
;;
-clean)
CLEAN=1
shift 1
;;
*)
usage
echo "Error: unsupported argument $1"
Expand Down Expand Up @@ -134,14 +140,26 @@ if [ ! -e ${ABS_PATH}/ios-cmake/ios.toolchain.cmake ]; then
fi

## Build CPPRestSDK
if [ -d "${ABS_PATH}/build.${CPPRESTSDK_BUILD_TYPE}.ios" ]; then
if [ "$CLEAN" -eq 1 ]; then
echo "Removing directory ${ABS_PATH}/build.${CPPRESTSDK_BUILD_TYPE}.ios prior to configuring."
rm -rf "${ABS_PATH}/build.${CPPRESTSDK_BUILD_TYPE}.ios"
else
printf "WARNING: Running configure on an already existing configuration.\nAny changes to the existing configuration will not be picked up.\nEither remove the directory and re-run configure or run configure with the -clean flag.\n\n"
fi
fi

mkdir -p ${ABS_PATH}/build.${CPPRESTSDK_BUILD_TYPE}.ios
pushd ${ABS_PATH}/build.${CPPRESTSDK_BUILD_TYPE}.ios
cmake -DCMAKE_BUILD_TYPE=${CPPRESTSDK_BUILD_TYPE} .. ${INCLUDE_32BIT} ${DISABLE_BITCODE} ${DEPLOYMENT_TARGET}
if [ "$CONFIG_ONLY" -eq 0 ]; then
make
printf "\n\n===================================================================================\n"
echo ">>>> The final library is available in 'build.${CPPRESTSDK_BUILD_TYPE}.ios/lib/libcpprest.a'"
printf "===================================================================================\n\n"
else
printf "\n\n===================================================================================\n"
echo ">>>> Configuration complete. Run 'make' in 'build.${CPPRESTSDK_BUILD_TYPE}.ios' to build."
printf "===================================================================================\n\n"
fi
popd
printf "\n\n===================================================================================\n"
echo ">>>> The final library is available in 'build.${CPPRESTSDK_BUILD_TYPE}.ios/lib/libcpprest.a'"
printf "===================================================================================\n\n"

0 comments on commit bbe6cc9

Please sign in to comment.