iPhone Software Development
Showing posts with label QuantLib. Show all posts
Showing posts with label QuantLib. Show all posts

Monday, November 28, 2016

How to build c++ libraries (boost & QuantLib) for iOS XCode 8/9

It is possible to skip the armv7, armv7s and i386 architectures if these binaries are not required. Just modify the relevant part of the scripts below



Updated Note
The macOS 10.14 SDK no longer contains support for compiling 32-bit applications. If developers need to compile for i386, Xcode 9.4 or earlier is required.


(1) Download boost 1.62.0 and extract source
shell script    Select all
# download boost source cd $HOME/Downloads curl -O https://nchc.dl.sourceforge.net/project/boost/boost/1.62.0/boost_1_62_0.tar.bz2 tar xjvf boost_1_62_0.tar.bz2 cd boost_1_62_0 # create the following user-config.jam at ~/Downloads/boost_1_62_0/tools/build/src/ cat > tools/build/src/user-config.jam << 'EOF' # ------------------ # darwin iphone configuration. # ------------------ local XCODE_ROOT = /Applications/Xcode.app/Contents/Developer ; # xcrun --sdk iphoneos --show-sdk-path local IPHONESDK = iPhoneOS.sdk ; local MACOSXSDK = MacOSX.sdk ; # xcrun --show-sdk-path # xcrun --sdk iphonesimulator --show-sdk-path local IPHONESIMULATORSDK = iPhoneSimulator.sdk ; using darwin : armv7 : $(XCODE_ROOT)/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ : <striper>$(XCODE_ROOT)/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip <root>$(XCODE_ROOT)/Platforms/iPhoneOS.platform/Developer/SDKs/$(IPHONESDK) <compileflags>"-isysroot $(XCODE_ROOT)/Platforms/iPhoneOS.platform/Developer/SDKs/$(IPHONESDK)" <compileflags>"-arch armv7" <compileflags>-fexceptions <compileflags>-frtti <compileflags>-fpic <compileflags>-DBOOST_SP_USE_SPINLOCK <compileflags>-std=c++11 <compileflags>-stdlib=libc++ <compileflags>-miphoneos-version-min=7.0 <compileflags>-fvisibility=hidden <compileflags>-fvisibility-inlines-hidden <compileflags>-O2 <compileflags>-g <compileflags>-Os <compileflags>-Wno-long-long <compileflags>-Wno-missing-field-initializers <compileflags>-Wno-unused-variable <linkflags>-stdlib=libc++ <architecture>arm <address-model>32 <target-os>iphone ; using darwin : armv7s : $(XCODE_ROOT)/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ : <striper>$(XCODE_ROOT)/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip <root>$(XCODE_ROOT)/Platforms/iPhoneOS.platform/Developer/SDKs/$(IPHONESDK) <compileflags>"-isysroot $(XCODE_ROOT)/Platforms/iPhoneOS.platform/Developer/SDKs/$(IPHONESDK)" <compileflags>"-arch armv7s" <compileflags>-fexceptions <compileflags>-frtti <compileflags>-fpic <compileflags>-DBOOST_SP_USE_SPINLOCK <compileflags>-std=c++11 <compileflags>-stdlib=libc++ <compileflags>-miphoneos-version-min=7.0 <compileflags>-fvisibility=hidden <compileflags>-fvisibility-inlines-hidden <compileflags>-O2 <compileflags>-g <compileflags>-Os <compileflags>-Wno-long-long <compileflags>-Wno-missing-field-initializers <compileflags>-Wno-unused-variable <linkflags>-stdlib=libc++ <architecture>arm <address-model>32 <target-os>iphone ; using darwin : arm64 : $(XCODE_ROOT)/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ : <striper>$(XCODE_ROOT)/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip <root>$(XCODE_ROOT)/Platforms/iPhoneOS.platform/Developer/SDKs/$(IPHONESDK) <compileflags>"-isysroot $(XCODE_ROOT)/Platforms/iPhoneOS.platform/Developer/SDKs/$(IPHONESDK)" #lt;root>$(XCODE_ROOT)/Platforms/MacOSX.platform/Developer/SDKs/$(MACOSXSDK) #lt;compileflags>"-isysroot $(XCODE_ROOT)/Platforms/MacOSX.platform/Developer/SDKs/$(MACOSXSDK)" <compileflags>"-arch arm64" <compileflags>-fexceptions <compileflags>-frtti <compileflags>-fpic <compileflags>-DBOOST_SP_USE_SPINLOCK <compileflags>-std=c++11 <compileflags>-stdlib=libc++ <compileflags>-miphoneos-version-min=7.0 #<compileflags>-mmacosx-version-min=10.9 <compileflags>-fvisibility=hidden <compileflags>-fvisibility-inlines-hidden <compileflags>-O2 <compileflags>-g <compileflags>-Os <compileflags>-Wno-long-long <compileflags>-Wno-missing-field-initializers <compileflags>-Wno-unused-variable <linkflags>-stdlib=libc++ <architecture>arm <address-model>64 <target-os>iphone ; using darwin : i386 : $(XCODE_ROOT)/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ : <striper>$(XCODE_ROOT)/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip <root>$(XCODE_ROOT)/Platforms/iPhoneSimulator.platform/Developer/SDKs/$(IPHONESIMULATORSDK) <compileflags>"-arch i386" <compileflags>"-isysroot $(XCODE_ROOT)/Platforms/iPhoneSimulator.platform/Developer/SDKs/$(IPHONESIMULATORSDK)" <compileflags>-fexceptions <compileflags>-frtti <compileflags>-fpic <compileflags>-DBOOST_SP_USE_SPINLOCK <compileflags>-std=c++11 <compileflags>-stdlib=libc++ <compileflags>-miphoneos-version-min=7.0 <compileflags>-fvisibility=hidden <compileflags>-fvisibility-inlines-hidden <compileflags>-O2 <compileflags>-g <compileflags>-Os <compileflags>-Wno-long-long <compileflags>-Wno-missing-field-initializers <compileflags>-Wno-unused-variable <linkflags>-stdlib=libc++ <architecture>x86 <address-model>32 <target-os>iphone ; using darwin : x86_64 : $(XCODE_ROOT)/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ : <striper>$(XCODE_ROOT)/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip <root>$(XCODE_ROOT)/Platforms/iPhoneSimulator.platform/Developer/SDKs/$(IPHONESIMULATORSDK) <compileflags>"-isysroot $(XCODE_ROOT)/Platforms/iPhoneSimulator.platform/Developer/SDKs/$(IPHONESIMULATORSDK)" #lt;root>$(XCODE_ROOT)/Platforms/MacOSX.platform/Developer/SDKs/$(MACOSXSDK) #lt;compileflags>"-isysroot $(XCODE_ROOT)/Platforms/MacOSX.platform/Developer/SDKs/$(MACOSXSDK)" <compileflags>"-arch x86_64" <compileflags>-fexceptions <compileflags>-frtti <compileflags>-fpic <compileflags>-DBOOST_SP_USE_SPINLOCK <compileflags>-std=c++11 <compileflags>-stdlib=libc++ <compileflags>-miphoneos-version-min=7.0 #<compileflags>-mmacosx-version-min=10.9 <compileflags>-fvisibility=hidden <compileflags>-fvisibility-inlines-hidden <compileflags>-O2 <compileflags>-g <compileflags>-Os <compileflags>-Wno-long-long <compileflags>-Wno-missing-field-initializers <compileflags>-Wno-unused-variable <linkflags>-stdlib=libc++ <architecture>x86 <address-model>64 <target-os>iphone ; EOF


(2) patch boost_1_62_0/tools/build/src/tools/darwin.jam
~/Downloads/boost_1_62_0/tools/build/src/tools/darwin.jam    Select all
#change from case arm : { if $(instruction-set) { options = -arch$(_)$(instruction-set) ; } else { options = -arch arm ; } } #to case arm : { if $(instruction-set) { options = -arch$(_)$(instruction-set) ;} else if $(address-model) = 64 { options = -arch arm64 ; } else { options = -arch arm ; } }


(3) build boost libraries for iOS
shell script    Select all
# bootstrap cd $HOME/Downloads/boost_1_62_0 # apply this patch if bootstrap error: pushd tools/build; wget https://github.com/boostorg/build/commit/48e9017139dd94446633480661e5447c7e0d8b1b.patch; patch -p1 < 48e9017139dd94446633480661e5447c7e0d8b1b.patch; popd ./bootstrap.sh --with-libraries=atomic,chrono,date_time,exception,filesystem,graph,iostreams,math,program_options,random,regex,serialization,signals,system,test,thread,wave # clean and build for iOS, j option is num of cores x 1.5 rm -fr ios-build ./b2 -j6 --build-dir=ios-build --stagedir=ios-build/armv7 toolset=darwin-armv7 architecture=arm instruction-set=armv7 address-model=32 target-os=iphone threading=multi link=static stage ./b2 -j6 --build-dir=ios-build --stagedir=ios-build/armv7s toolset=darwin-armv7s architecture=arm instruction-set=armv7s address-model=32 target-os=iphone threading=multi link=static stage ./b2 -j6 --build-dir=ios-build --stagedir=ios-build/arm64 toolset=darwin-arm64 architecture=arm address-model=64 target-os=iphone threading=multi link=static stage ./b2 -j6 --build-dir=ios-build --stagedir=ios-build/i386 toolset=darwin-i386 architecture=x86 address-model=32 target-os=iphone threading=multi link=static stage ./b2 -j6 --build-dir=ios-build --stagedir=ios-build/x86_64 toolset=darwin-x86_64 architecture=x86 address-model=64 target-os=iphone threading=multi link=static stage # create libboost.a archive for each architecture cd $HOME/Downloads/boost_1_62_0 cd ios-build xcrun ar crus armv7/libboost.a boost/bin.v2/libs/*/build/darwin-armv7/release/instruction-set-armv7/link-static/target-os-iphone/threading-multi/*/*.o xcrun ar crus armv7s/libboost.a boost/bin.v2/libs/*/build/darwin-armv7s/release/instruction-set-armv7s/link-static/target-os-iphone/threading-multi/*/*.o xcrun ar crus arm64/libboost.a boost/bin.v2/libs/*/build/darwin-arm64/release/link-static/target-os-iphone/threading-multi/*/*.o xcrun ar crus i386/libboost.a boost/bin.v2/libs/*/build/darwin-i386/release/link-static/target-os-iphone/threading-multi/*/*.o xcrun ar crus x86_64/libboost.a boost/bin.v2/libs/*/build/darwin-x86_64/release/link-static/target-os-iphone/threading-multi/*/*.o # create FAT libboost.a archive mkdir -p lib xcrun lipo \ -arch armv7 "armv7/libboost.a" \ -arch armv7s "armv7s/libboost.a" \ -arch arm64 "arm64/libboost.a" \ -arch i386 "i386/libboost.a" \ -arch x86_64 "x86_64/libboost.a" \ -output "lib/libboost.a" \ -create # create link for include folder mkdir include cd include ln -s ../../boost .


(4) Create boost Framework for iOS
shell script    Select all
cd $HOME/Downloads/boost_1_62_0 cd ios-build #Create the following shell script for build-boostframework.sh cat > build-boostframework.sh << 'boostFrameworkEOF' #!/bin/bash # build-boostframework.sh VERSION_TYPE=Alpha FRAMEWORK_NAME=boost FRAMEWORK_VERSION=A FRAMEWORKDIR=. FRAMEWORK_CURRENT_VERSION=1.62.0 FRAMEWORK_COMPATIBILITY_VERSION=1.62.0 FRAMEWORK_BUNDLE=${FRAMEWORKDIR}/${FRAMEWORK_NAME}.framework rm -rf ${FRAMEWORK_BUNDLE} mkdir -p ${FRAMEWORK_BUNDLE} mkdir -p ${FRAMEWORK_BUNDLE}/Versions mkdir -p ${FRAMEWORK_BUNDLE}/Versions/${FRAMEWORK_VERSION} mkdir -p ${FRAMEWORK_BUNDLE}/Versions/${FRAMEWORK_VERSION}/Resources mkdir -p ${FRAMEWORK_BUNDLE}/Versions/${FRAMEWORK_VERSION}/Headers mkdir -p ${FRAMEWORK_BUNDLE}/Versions/${FRAMEWORK_VERSION}/Documentation ln -s $FRAMEWORK_VERSION ${FRAMEWORK_BUNDLE}/Versions/Current ln -s Versions/Current/Headers ${FRAMEWORK_BUNDLE}/Headers ln -s Versions/Current/Resources ${FRAMEWORK_BUNDLE}/Resources ln -s Versions/Current/Documentation ${FRAMEWORK_BUNDLE}/Documentation ln -s Versions/Current/$FRAMEWORK_NAME ${FRAMEWORK_BUNDLE}/$FRAMEWORK_NAME FRAMEWORK_INSTALL_NAME=${FRAMEWORK_BUNDLE}/Versions/${FRAMEWORK_VERSION}/${FRAMEWORK_NAME} echo "Framework: Lipoing library into ${FRAMEWORK_INSTALL_NAME}" /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo \ -arch armv7 "armv7/libboost.a" \ -arch armv7s "armv7s/libboost.a" \ -arch arm64 "arm64/libboost.a" \ -arch i386 "i386/libboost.a" \ -arch x86_64 "x86_64/libboost.a" \ -output "${FRAMEWORK_INSTALL_NAME}" \ -create echo "Framework: Copying includes..." cp -r include/${FRAMEWORK_NAME}/* ${FRAMEWORK_BUNDLE}/Headers/ cat > ${FRAMEWORK_BUNDLE}/Resources/Info.plist <<InfoplistEOF <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>CFBundleDevelopmentRegion</key> <string>English</string> <key>CFBundleExecutable</key> <string>${FRAMEWORK_NAME}</string> <key>CFBundleIdentifier</key> <string>${FRAMEWORK_NAME}.org</string> <key>CFBundleInfoDictionaryVersion</key> <string>6.0</string> <key>CFBundlePackageType</key> <string>FMWK</string> <key>CFBundleSignature</key> <string>????</string> <key>CFBundleVersion</key> <string>${FRAMEWORK_CURRENT_VERSION}</string> </dict> </plist> InfoplistEOF echo "Done: ${FRAMEWORK_BUNDLE}" boostFrameworkEOF # build framework sh build-boostframework.sh


(5) Download and build QuantLib 1.12 for iOS
shell script    Select all
# download quantlib source cd $HOME/Downloads # latest is https://jaist.dl.sourceforge.net/project/quantlib/QuantLib/1.12/QuantLib-1.12.tar.gz (February 1st, 2018) export QL_VERSION=1.12 curl -O https://jaist.dl.sourceforge.net/project/quantlib/QuantLib/${QL_VERSION}/QuantLib-${QL_VERSION}.tar.gz # curl -O https://jaist.dl.sourceforge.net/project/quantlib/QuantLib/1.9/QuantLib-1.9.tar.gz tar xzvf QuantLib-${QL_VERSION}.tar.gz cd QuantLib-${QL_VERSION} #Create the following shell script for armv7 cat > ~/Downloads/QuantLib-${QL_VERSION}/build-armv7.sh << 'armv7EOF' #!/bin/bash # build-armv7.sh BUILD_DIR=ios-build mkdir -p ${BUILD_DIR} INSTALL_DIR="`pwd`/${BUILD_DIR}" YOUR_PATH_TO_INSTALL_DIR="`cd "${INSTALL_DIR}";pwd`" # XCODE_VERSION=Xcode-9.0 # XCODE_ROOT=/Applications/${XCODE_VERSION}.app/Contents/Developer XCODE_ROOT=/Applications/Xcode.app/Contents/Developer YOUR_TOOLCHAIN=${XCODE_ROOT}/Toolchains/XcodeDefault.xctoolchain/usr/bin # xcrun --sdk iphoneos --show-sdk-path # sysroot=${XCODE_ROOT}/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk sysroot="`xcrun --sdk iphoneos --show-sdk-path`" export CC=${YOUR_TOOLCHAIN}/clang export CXX=${YOUR_TOOLCHAIN}/clang++ export CPP=${YOUR_TOOLCHAIN}/cpp export AR=${YOUR_TOOLCHAIN}/ar export RANLIB=${YOUR_TOOLCHAIN}/ranlib export LD=${YOUR_TOOLCHAIN}/ld export CFLAGS="-arch armv7 -std=c99 -miphoneos-version-min=7.0 -isysroot ${sysroot}" export CXXFLAGS="-arch armv7 -fexceptions -frtti -fpic -std=c++11 -stdlib=libc++ -miphoneos-version-min=7.0 -O2 -g -fvisibility=hidden -fvisibility-inlines-hidden -Os -isysroot ${sysroot}" export LDFLAGS="-stdlib=libc++" boost_include="`cd "../boost_1_62_0/${BUILD_DIR}/include";pwd`" boost_lib="`cd "../boost_1_62_0/${BUILD_DIR}/armv7/lib";pwd`" make distclean ./configure --prefix=/armv7 --host=arm-apple-darwin10 --with-sysroot=${sysroot} --with-boost-include=${boost_include} --with-boost-lib=${boost_lib} --enable-static --enable-shared=no --disable-examples make -j6 make install DESTDIR=${YOUR_PATH_TO_INSTALL_DIR} armv7EOF #Create the following shell script for armv7s cat > ~/Downloads/QuantLib-${QL_VERSION}/build-armv7s.sh << 'armv7sEOF' #!/bin/bash # build-armv7s.sh BUILD_DIR=ios-build mkdir -p ${BUILD_DIR} INSTALL_DIR="`pwd`/${BUILD_DIR}" YOUR_PATH_TO_INSTALL_DIR="`cd "${INSTALL_DIR}";pwd`" # XCODE_VERSION=Xcode-9.0 # XCODE_ROOT=/Applications/${XCODE_VERSION}.app/Contents/Developer XCODE_ROOT=/Applications/Xcode.app/Contents/Developer YOUR_TOOLCHAIN=${XCODE_ROOT}/Toolchains/XcodeDefault.xctoolchain/usr/bin # xcrun --sdk iphoneos --show-sdk-path # sysroot=${XCODE_ROOT}/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk sysroot="`xcrun --sdk iphoneos --show-sdk-path`" export CC=${YOUR_TOOLCHAIN}/clang export CXX=${YOUR_TOOLCHAIN}/clang++ export CPP=${YOUR_TOOLCHAIN}/cpp export AR=${YOUR_TOOLCHAIN}/ar export RANLIB=${YOUR_TOOLCHAIN}/ranlib export LD=${YOUR_TOOLCHAIN}/ld export CFLAGS="-arch armv7s -std=c99 -miphoneos-version-min=7.0 -isysroot ${sysroot}" export CXXFLAGS="-arch armv7s -fexceptions -frtti -fpic -std=c++11 -stdlib=libc++ -miphoneos-version-min=7.0 -O2 -g -fvisibility=hidden -fvisibility-inlines-hidden -Os -isysroot ${sysroot}" export LDFLAGS="-stdlib=libc++" boost_include="`cd "../boost_1_62_0/${BUILD_DIR}/include";pwd`" boost_lib="`cd "../boost_1_62_0/${BUILD_DIR}/armv7s/lib";pwd`" make distclean ./configure --prefix=/armv7s --host=arm-apple-darwin10 --with-sysroot=${sysroot} --with-boost-include=${boost_include} --with-boost-lib=${boost_lib} --enable-static --enable-shared=no --disable-examples make -j6 make install DESTDIR=${YOUR_PATH_TO_INSTALL_DIR} armv7sEOF #Create the following shell script for arm64 cat > ~/Downloads/QuantLib-${QL_VERSION}/build-arm64.sh << 'arm64EOF' #!/bin/bash # build-arm64.sh ARCH=arm64 BOOST_FOLDER=boost_1_62_0 BUILD_DIR=ios-build mkdir -p ${BUILD_DIR} INSTALL_DIR="`pwd`/${BUILD_DIR}" YOUR_PATH_TO_INSTALL_DIR="`cd "${INSTALL_DIR}";pwd`" XCODE_ROOT=/Applications/Xcode.app/Contents/Developer YOUR_TOOLCHAIN=${XCODE_ROOT}/Toolchains/XcodeDefault.xctoolchain/usr/bin # xcrun --sdk iphoneos --show-sdk-path # sysroot=${XCODE_ROOT}/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk # sysroot="`xcrun --show-sdk-path`" sysroot="`xcrun --sdk iphoneos --show-sdk-path`" export CC=${YOUR_TOOLCHAIN}/clang export CXX=${YOUR_TOOLCHAIN}/clang++ export CPP=${YOUR_TOOLCHAIN}/cpp export AR=${YOUR_TOOLCHAIN}/ar export RANLIB=${YOUR_TOOLCHAIN}/ranlib export LD=${YOUR_TOOLCHAIN}/ld export CFLAGS="-arch ${ARCH} -std=c99 -miphoneos-version-min=7.0 -isysroot ${sysroot}" export CXXFLAGS="-arch ${ARCH} -fexceptions -frtti -fpic -std=c++11 -stdlib=libc++ -miphoneos-version-min=7.0 -O2 -g -fvisibility=hidden -fvisibility-inlines-hidden -Os -isysroot ${sysroot}" export LDFLAGS="-stdlib=libc++" boost_include="`cd "../${BOOST_FOLDER}/${BUILD_DIR}/include";pwd`" boost_lib="`cd "../${BOOST_FOLDER}/${BUILD_DIR}/arm64/lib";pwd`" make distclean ./configure --prefix=/${ARCH} --host=${ARCH}-apple-darwin10 --with-sysroot=${sysroot} --with-boost-include=${boost_include} --with-boost-lib=${boost_lib} --enable-static --enable-shared=no --disable-examples make -j6 make install DESTDIR=${YOUR_PATH_TO_INSTALL_DIR} arm64EOF #Create the following shell script for i386 cat > ~/Downloads/QuantLib-${QL_VERSION}/build-i386.sh << 'i386EOF' #!/bin/bash # build-i386.sh BUILD_DIR=ios-build mkdir -p ${BUILD_DIR} INSTALL_DIR="`pwd`/${BUILD_DIR}" YOUR_PATH_TO_INSTALL_DIR="`cd "${INSTALL_DIR}";pwd`" # XCODE_VERSION=Xcode-9.0 # XCODE_ROOT=/Applications/${XCODE_VERSION}.app/Contents/Developer XCODE_ROOT=/Applications/Xcode.app/Contents/Developer YOUR_TOOLCHAIN=${XCODE_ROOT}/Toolchains/XcodeDefault.xctoolchain/usr/bin # xcrun --sdk iphonesimulator --show-sdk-path # sysroot=${XCODE_ROOT}/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk sysroot="`xcrun --sdk iphonesimulator --show-sdk-path`" export CC=${YOUR_TOOLCHAIN}/clang export CXX=${YOUR_TOOLCHAIN}/clang++ export CPP=${YOUR_TOOLCHAIN}/cpp export AR=${YOUR_TOOLCHAIN}/ar export RANLIB=${YOUR_TOOLCHAIN}/ranlib export LD=${YOUR_TOOLCHAIN}/ld export CFLAGS="-arch i386 -std=c99 -miphoneos-version-min=7.0 -isysroot ${sysroot}" export CXXFLAGS="-arch i386 -fexceptions -frtti -fpic -std=c++11 -stdlib=libc++ -miphoneos-version-min=7.0 -O2 -g -fvisibility=hidden -fvisibility-inlines-hidden -Os -isysroot ${sysroot}" export LDFLAGS="-stdlib=libc++" boost_include="`cd "../boost_1_62_0/${BUILD_DIR}/include";pwd`" boost_lib="`cd "../boost_1_62_0/${BUILD_DIR}/i386/lib";pwd`" make distclean ./configure --prefix=/i386 --host=i386-apple-darwin10 --with-sysroot=${sysroot} --with-boost-include=${boost_include} --with-boost-lib=${boost_lib} --enable-static --enable-shared=no --disable-examples make -j6 make install DESTDIR=${YOUR_PATH_TO_INSTALL_DIR} i386EOF #Create the following shell script for x86_64 cat > ~/Downloads/QuantLib-${QL_VERSION}/build-x86_64.sh << 'x86_64EOF' #!/bin/bash # build-x86_64.sh ARCH=x86_64 BOOST_FOLDER=boost_1_62_0 BUILD_DIR=ios-build mkdir -p ${BUILD_DIR} INSTALL_DIR="`pwd`/${BUILD_DIR}" YOUR_PATH_TO_INSTALL_DIR="`cd "${INSTALL_DIR}";pwd`" XCODE_ROOT=/Applications/Xcode.app/Contents/Developer YOUR_TOOLCHAIN=${XCODE_ROOT}/Toolchains/XcodeDefault.xctoolchain/usr/bin # xcrun --sdk iphonesimulator --show-sdk-path # sysroot=${XCODE_ROOT}/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk # sysroot="`xcrun --show-sdk-path`" sysroot="`xcrun --sdk iphonesimulator --show-sdk-path`" export CC=${YOUR_TOOLCHAIN}/clang export CXX=${YOUR_TOOLCHAIN}/clang++ export CPP=${YOUR_TOOLCHAIN}/cpp export AR=${YOUR_TOOLCHAIN}/ar export RANLIB=${YOUR_TOOLCHAIN}/ranlib export LD=${YOUR_TOOLCHAIN}/ld export CFLAGS="-arch ${ARCH} -std=c99 -miphoneos-version-min=7.0 -isysroot ${sysroot}" export CXXFLAGS="-arch ${ARCH} -fexceptions -frtti -fpic -std=c++11 -stdlib=libc++ -miphoneos-version-min=7.0 -O2 -g -fvisibility=hidden -fvisibility-inlines-hidden -Os -isysroot ${sysroot}" export LDFLAGS="-stdlib=libc++" boost_include="`cd "../${BOOST_FOLDER}/${BUILD_DIR}/include";pwd`" boost_lib="`cd "../${BOOST_FOLDER}/${BUILD_DIR}/x86_64/lib";pwd`" make distclean ./configure --prefix=/${ARCH} --host=${ARCH}-apple-darwin10 --with-sysroot=${sysroot} --with-boost-include=${boost_include} --with-boost-lib=${boost_lib} --enable-static --enable-shared=no --disable-examples make -j6 make install DESTDIR=${YOUR_PATH_TO_INSTALL_DIR} x86_64EOF #run shell scripts to clean and build for iOS cd $HOME/Downloads cd QuantLib-${QL_VERSION} rm -fr ios-build sh build-armv7.sh sh build-armv7s.sh sh build-arm64.sh sh build-i386.sh sh build-x86_64.sh # create FAT libQuantLib.a archive cd $HOME/Downloads/QuantLib-${QL_VERSION} cd ios-build mkdir -p lib /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo \ -arch armv7 "armv7/lib/libQuantLib.a" \ -arch armv7s "armv7s/lib/libQuantLib.a" \ -arch arm64 "arm64/lib/libQuantLib.a" \ -arch i386 "i386/lib/libQuantLib.a" \ -arch x86_64 "x86_64/lib/libQuantLib.a" \ -output "lib/libQuantLib.a" \ -create # create link for include folder mkdir include cd include ln -s ../arm64/include/ql .


(6) Create QuantLib Framework for iOS
shell script    Select all
export QL_VERSION=1.12 cd $HOME/Downloads/QuantLib-${QL_VERSION} cd ios-build #Create the following shell script for build-qlframework.sh cat > build-qlframework.sh << 'qlFrameworkEOF' #!/bin/bash # build-qlframework.sh VERSION_TYPE=Alpha FRAMEWORK_NAME=ql FRAMEWORK_VERSION=A FRAMEWORKDIR=. FRAMEWORK_CURRENT_VERSION=${QL_VERSION} FRAMEWORK_COMPATIBILITY_VERSION=${QL_VERSION} FRAMEWORK_BUNDLE=${FRAMEWORKDIR}/${FRAMEWORK_NAME}.framework rm -rf ${FRAMEWORK_BUNDLE} mkdir -p ${FRAMEWORK_BUNDLE} mkdir -p ${FRAMEWORK_BUNDLE}/Versions mkdir -p ${FRAMEWORK_BUNDLE}/Versions/${FRAMEWORK_VERSION} mkdir -p ${FRAMEWORK_BUNDLE}/Versions/${FRAMEWORK_VERSION}/Resources mkdir -p ${FRAMEWORK_BUNDLE}/Versions/${FRAMEWORK_VERSION}/Headers mkdir -p ${FRAMEWORK_BUNDLE}/Versions/${FRAMEWORK_VERSION}/Documentation ln -s $FRAMEWORK_VERSION ${FRAMEWORK_BUNDLE}/Versions/Current ln -s Versions/Current/Headers ${FRAMEWORK_BUNDLE}/Headers ln -s Versions/Current/Resources ${FRAMEWORK_BUNDLE}/Resources ln -s Versions/Current/Documentation ${FRAMEWORK_BUNDLE}/Documentation ln -s Versions/Current/$FRAMEWORK_NAME ${FRAMEWORK_BUNDLE}/$FRAMEWORK_NAME FRAMEWORK_INSTALL_NAME=${FRAMEWORK_BUNDLE}/Versions/${FRAMEWORK_VERSION}/${FRAMEWORK_NAME} echo "Framework: Lipoing library into ${FRAMEWORK_INSTALL_NAME}" /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo \ -arch armv7 "armv7/lib/libQuantLib.a" \ -arch armv7s "armv7s/lib/libQuantLib.a" \ -arch arm64 "arm64/lib/libQuantLib.a" \ -arch i386 "i386/lib/libQuantLib.a" \ -arch x86_64 "x86_64/lib/libQuantLib.a" \ -output "${FRAMEWORK_INSTALL_NAME}" \ -create echo "Framework: Copying includes..." cp -r include/${FRAMEWORK_NAME}/* ${FRAMEWORK_BUNDLE}/Headers/ cat > ${FRAMEWORK_BUNDLE}/Resources/Info.plist <<InfoplistEOF <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>CFBundleDevelopmentRegion</key> <string>English</string> <key>CFBundleExecutable</key> <string>${FRAMEWORK_NAME}</string> <key>CFBundleIdentifier</key> <string>quantlib.org</string> <key>CFBundleInfoDictionaryVersion</key> <string>6.0</string> <key>CFBundlePackageType</key> <string>FMWK</string> <key>CFBundleSignature</key> <string>????</string> <key>CFBundleVersion</key> <string>${FRAMEWORK_CURRENT_VERSION}</string> </dict> </plist> InfoplistEOF echo "Done: ${FRAMEWORK_BUNDLE}" qlFrameworkEOF # build framework sh build-qlframework.sh


(7) Test build x86_64 for iOS frameworks with
shell script    Select all
#Create testql.cpp cd $HOME/Downloads cat > testql.cpp << 'testqlEOF' #include <ql/quantlib.hpp> int main() { std::cout << "BOOST version is " << BOOST_VERSION << std::endl; std::cout << "QL version is " << QL_VERSION << std::endl; #if __x86_64__ || __WORDSIZE == 64 std::cout << "This is 64 bits" << std::endl; #elif __i386__ || __WORDSIZE == 32 std::cout << "This is 32 bits" << std::endl; #else std::cout << "This is something else" << std::endl; #endif return 0; } testqlEOF # test build example using iOS frameworks export QL_VERSION=1.12 xcrun clang++ -std=c++11 -stdlib=libc++ -F $HOME/Downloads/QuantLib-${QL_VERSION}/ios-build -F $HOME/Downloads/boost_1_62_0/ios-build -framework ql -isysroot `xcrun --sdk iphonesimulator --show-sdk-path` -arch x86_64 -miphoneos-version-min=7.0 -fvisibility=hidden -o testql testql.cpp ./testql


(8) Build frameworks for macosx and build RQuantLib package from source
shell script    Select all
cd $HOME/Downloads/boost_1_62_0 # Append the following user-config.jam at ~/Downloads/boost_1_62_0/tools/build/src/ cat >> tools/build/src/user-config.jam << 'EOF' # ------------------ # darwin macosx configuration. # ------------------ local XCODE_ROOT = /Applications/Xcode.app/Contents/Developer ; # xcrun --sdk macosx --show-sdk-path local MACOSXSDK = MacOSX.sdk ; using darwin : i386~macosx : $(XCODE_ROOT)/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ : <striper>$(XCODE_ROOT)/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip <root>$(XCODE_ROOT)/Platforms/MacOSX.platform/Developer/SDKs/$(MACOSXSDK) <compileflags>"-arch i386" <compileflags>"-isysroot $(XCODE_ROOT)/Platforms/MacOSX.platform/Developer/SDKs/$(MACOSXSDK)" <compileflags>-fexceptions <compileflags>-frtti <compileflags>-fpic <compileflags>-DBOOST_SP_USE_SPINLOCK <compileflags>-std=c++11 <compileflags>-stdlib=libc++ <compileflags>-mmacosx-version-min=10.9 <compileflags>-O2 <compileflags>-g <compileflags>-Os <compileflags>-Wno-long-long <compileflags>-Wno-missing-field-initializers <compileflags>-Wno-unused-variable <linkflags>-stdlib=libc++ <linkflags>-mmacosx-version-min=10.9 <architecture>x86 <address-model>32 <target-os>darwin ; using darwin : x86_64~macosx : $(XCODE_ROOT)/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ : <striper>$(XCODE_ROOT)/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip <root>$(XCODE_ROOT)/Platforms/MacOSX.platform/Developer/SDKs/$(MACOSXSDK) <compileflags>"-arch x86_64" <compileflags>"-isysroot $(XCODE_ROOT)/Platforms/MacOSX.platform/Developer/SDKs/$(MACOSXSDK)" <compileflags>-fexceptions <compileflags>-frtti <compileflags>-fpic <compileflags>-DBOOST_SP_USE_SPINLOCK <compileflags>-std=c++11 <compileflags>-stdlib=libc++ <compileflags>-mmacosx-version-min=10.9 <compileflags>-O2 <compileflags>-g <compileflags>-Os <compileflags>-Wno-long-long <compileflags>-Wno-missing-field-initializers <compileflags>-Wno-unused-variable <linkflags>-stdlib=libc++ <linkflags>-mmacosx-version-min=10.9 <architecture>x86 <address-model>64 <target-os>darwin ; EOF # build boost libraries for macosx ./bootstrap.sh --with-libraries=atomic,chrono,date_time,exception,filesystem,graph,iostreams,math,program_options,random,regex,serialization,signals,system,test,thread,wave # clean and build for macosx, j option is num of cores x 1.5 rm -fr macosx-build ./b2 -j6 --build-dir=macosx-build --stagedir=macosx-build/i386 toolset=darwin-i386~macosx architecture=x86 address-model=32 target-os=darwin threading=multi link=static stage ./b2 -j6 --build-dir=macosx-build --stagedir=macosx-build/x86_64 toolset=darwin-x86_64~macosx architecture=x86 address-model=64 target-os=darwin threading=multi link=static stage # create libboost.a archive for each architecture cd $HOME/Downloads/boost_1_62_0/macosx-build xcrun --sdk macosx ar crus i386/libboost.a boost/bin.v2/libs/*/build/darwin-i386~macosx/release/link-static/threading-multi/*/*.o xcrun --sdk macosx ar crus x86_64/libboost.a boost/bin.v2/libs/*/build/darwin-x86_64~macosx/release/link-static/threading-multi/*/*.o # create FAT libboost.a archive mkdir -p lib /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo \ -arch i386 "i386/libboost.a" \ -arch x86_64 "x86_64/libboost.a" \ -output "lib/libboost.a" \ -create # create link for include folder mkdir include cd include ln -s ../../boost . # build Boost Framework for macosx #Create the following shell script for build-boostframework.sh cd $HOME/Downloads/boost_1_62_0/macosx-build cat > build-boostframework.sh << 'boostFrameworkEOF' #!/bin/bash # build-boostframework.sh VERSION_TYPE=Alpha FRAMEWORK_NAME=boost FRAMEWORK_VERSION=A FRAMEWORKDIR=. FRAMEWORK_CURRENT_VERSION=1.62.0 FRAMEWORK_COMPATIBILITY_VERSION=1.62.0 FRAMEWORK_BUNDLE=${FRAMEWORKDIR}/${FRAMEWORK_NAME}.framework rm -rf ${FRAMEWORK_BUNDLE} mkdir -p ${FRAMEWORK_BUNDLE} mkdir -p ${FRAMEWORK_BUNDLE}/Versions mkdir -p ${FRAMEWORK_BUNDLE}/Versions/${FRAMEWORK_VERSION} mkdir -p ${FRAMEWORK_BUNDLE}/Versions/${FRAMEWORK_VERSION}/Resources mkdir -p ${FRAMEWORK_BUNDLE}/Versions/${FRAMEWORK_VERSION}/Headers mkdir -p ${FRAMEWORK_BUNDLE}/Versions/${FRAMEWORK_VERSION}/Documentation ln -s $FRAMEWORK_VERSION ${FRAMEWORK_BUNDLE}/Versions/Current ln -s Versions/Current/Headers ${FRAMEWORK_BUNDLE}/Headers ln -s Versions/Current/Resources ${FRAMEWORK_BUNDLE}/Resources ln -s Versions/Current/Documentation ${FRAMEWORK_BUNDLE}/Documentation ln -s Versions/Current/$FRAMEWORK_NAME ${FRAMEWORK_BUNDLE}/$FRAMEWORK_NAME FRAMEWORK_INSTALL_NAME=${FRAMEWORK_BUNDLE}/Versions/${FRAMEWORK_VERSION}/${FRAMEWORK_NAME} echo "Framework: Lipoing library into ${FRAMEWORK_INSTALL_NAME}" /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo \ -arch i386 "i386/libboost.a" \ -arch x86_64 "x86_64/libboost.a" \ -output "${FRAMEWORK_INSTALL_NAME}" \ -create echo "Framework: Copying includes..." cp -r include/${FRAMEWORK_NAME}/* ${FRAMEWORK_BUNDLE}/Headers/ cat > ${FRAMEWORK_BUNDLE}/Resources/Info.plist <<InfoplistEOF <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>CFBundleDevelopmentRegion</key> <string>English</string> <key>CFBundleExecutable</key> <string>${FRAMEWORK_NAME}</string> <key>CFBundleIdentifier</key> <string>${FRAMEWORK_NAME}.org</string> <key>CFBundleInfoDictionaryVersion</key> <string>6.0</string> <key>CFBundlePackageType</key> <string>FMWK</string> <key>CFBundleSignature</key> <string>????</string> <key>CFBundleVersion</key> <string>${FRAMEWORK_CURRENT_VERSION}</string> </dict> </plist> InfoplistEOF echo "Done: ${FRAMEWORK_BUNDLE}" boostFrameworkEOF # build framework sh build-boostframework.sh # build QuantLib libraries for macosx export QL_VERSION=1.12 cd $HOME/Downloads/QuantLib-${QL_VERSION} #Create the following shell script for i386 cat > ~/Downloads/QuantLib-${QL_VERSION}/build-i386-macosx.sh << 'i386EOF' #!/bin/bash # build-i386-macosx.sh BUILD_DIR=macosx-build mkdir -p ${BUILD_DIR} INSTALL_DIR="`pwd`/${BUILD_DIR}" YOUR_PATH_TO_INSTALL_DIR="`cd "${INSTALL_DIR}";pwd`" # XCODE_VERSION=Xcode-9.0 # XCODE_ROOT=/Applications/${XCODE_VERSION}.app/Contents/Developer XCODE_ROOT=/Applications/Xcode.app/Contents/Developer YOUR_TOOLCHAIN=${XCODE_ROOT}/Toolchains/XcodeDefault.xctoolchain/usr/bin # xcrun --sdk macosx --show-sdk-path # sysroot=${XCODE_ROOT}/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk sysroot="`xcrun --sdk macosx --show-sdk-path`" export CC=${YOUR_TOOLCHAIN}/clang export CXX=${YOUR_TOOLCHAIN}/clang++ export CPP=${YOUR_TOOLCHAIN}/cpp export AR=${YOUR_TOOLCHAIN}/ar export RANLIB=${YOUR_TOOLCHAIN}/ranlib export LD=${YOUR_TOOLCHAIN}/ld export CFLAGS="-arch i386 -std=c99 -mmacosx-version-min=10.7 -isysroot ${sysroot}" export CXXFLAGS="-arch i386 -fexceptions -frtti -fpic -std=c++11 -stdlib=libc++ -mmacosx-version-min=10.9 -O2 -g -Os -isysroot ${sysroot}" export LDFLAGS="-stdlib=libc++ -mmacosx-version-min=10.9" boost_include="`cd "../boost_1_62_0/${BUILD_DIR}/include";pwd`" boost_lib="`cd "../boost_1_62_0/${BUILD_DIR}/i386/lib";pwd`" make distclean ./configure --prefix=/i386 --host=i386-apple-darwin10 --with-sysroot=${sysroot} --with-boost-include=${boost_include} --with-boost-lib=${boost_lib} --enable-intraday --enable-static --enable-shared=no --disable-examples make -j6 make install DESTDIR=${YOUR_PATH_TO_INSTALL_DIR} i386EOF #Create the following shell script for x86_64 cat > ~/Downloads/QuantLib-${QL_VERSION}/build-x86_64-macosx.sh << 'x86_64EOF' #!/bin/bash # build-x86_64-macosx.sh BUILD_DIR=macosx-build mkdir -p ${BUILD_DIR} INSTALL_DIR="`pwd`/${BUILD_DIR}" YOUR_PATH_TO_INSTALL_DIR="`cd "${INSTALL_DIR}";pwd`" XCODE_ROOT=/Applications/Xcode.app/Contents/Developer YOUR_TOOLCHAIN=${XCODE_ROOT}/Toolchains/XcodeDefault.xctoolchain/usr/bin # xcrun --sdk macosx --show-sdk-path # sysroot=${XCODE_ROOT}/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk sysroot="`xcrun --sdk macosx --show-sdk-path`" export CC=${YOUR_TOOLCHAIN}/clang export CXX=${YOUR_TOOLCHAIN}/clang++ export CPP=${YOUR_TOOLCHAIN}/cpp export AR=${YOUR_TOOLCHAIN}/ar export RANLIB=${YOUR_TOOLCHAIN}/ranlib export LD=${YOUR_TOOLCHAIN}/ld export CFLAGS="-arch x86_64 -std=c99 -mmacosx-version-min=10.7 -isysroot ${sysroot}" export CXXFLAGS="-arch x86_64 -fexceptions -frtti -fpic -std=c++11 -stdlib=libc++ -mmacosx-version-min=10.9 -O2 -g -Os -isysroot ${sysroot}" export LDFLAGS="-stdlib=libc++ -mmacosx-version-min=10.9" boost_include="`cd "../boost_1_62_0/${BUILD_DIR}/include";pwd`" boost_lib="`cd "../boost_1_62_0/${BUILD_DIR}/x86_64/lib";pwd`" make distclean ./configure --prefix=/x86_64 --host=x86_64-apple-darwin10 --with-sysroot=${sysroot} --with-boost-include=${boost_include} --with-boost-lib=${boost_lib} --enable-intraday --enable-static --enable-shared=no --disable-examples make -j6 make install DESTDIR=${YOUR_PATH_TO_INSTALL_DIR} x86_64EOF #run shell scripts to clean and build for macosx cd $HOME/Downloads/QuantLib-${QL_VERSION} rm -fr macosx-build sh build-i386-macosx.sh sh build-x86_64-macosx.sh # create FAT libQuantLib.a archive cd $HOME/Downloads/QuantLib-${QL_VERSION} cd macosx-build mkdir -p lib /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo \ -arch i386 "i386/lib/libQuantLib.a" \ -arch x86_64 "x86_64/lib/libQuantLib.a" \ -output "lib/libQuantLib.a" \ -create # create link for include folder mkdir include cd include ln -s ../x86_64/include/ql . cd $HOME/Downloads/QuantLib-${QL_VERSION}/macosx-build # build QuantLib Framework for macosx #Create the following shell script for build-qlframework.sh cat > build-qlframework.sh << 'qlFrameworkEOF' #!/bin/bash # build-qlframework.sh VERSION_TYPE=Alpha FRAMEWORK_NAME=ql FRAMEWORK_VERSION=A FRAMEWORKDIR=. FRAMEWORK_CURRENT_VERSION=${QL_VERSION} FRAMEWORK_COMPATIBILITY_VERSION=${QL_VERSION} FRAMEWORK_BUNDLE=${FRAMEWORKDIR}/${FRAMEWORK_NAME}.framework rm -rf ${FRAMEWORK_BUNDLE} mkdir -p ${FRAMEWORK_BUNDLE} mkdir -p ${FRAMEWORK_BUNDLE}/Versions mkdir -p ${FRAMEWORK_BUNDLE}/Versions/${FRAMEWORK_VERSION} mkdir -p ${FRAMEWORK_BUNDLE}/Versions/${FRAMEWORK_VERSION}/Resources mkdir -p ${FRAMEWORK_BUNDLE}/Versions/${FRAMEWORK_VERSION}/Headers mkdir -p ${FRAMEWORK_BUNDLE}/Versions/${FRAMEWORK_VERSION}/Documentation ln -s $FRAMEWORK_VERSION ${FRAMEWORK_BUNDLE}/Versions/Current ln -s Versions/Current/Headers ${FRAMEWORK_BUNDLE}/Headers ln -s Versions/Current/Resources ${FRAMEWORK_BUNDLE}/Resources ln -s Versions/Current/Documentation ${FRAMEWORK_BUNDLE}/Documentation ln -s Versions/Current/$FRAMEWORK_NAME ${FRAMEWORK_BUNDLE}/$FRAMEWORK_NAME FRAMEWORK_INSTALL_NAME=${FRAMEWORK_BUNDLE}/Versions/${FRAMEWORK_VERSION}/${FRAMEWORK_NAME} echo "Framework: Lipoing library into ${FRAMEWORK_INSTALL_NAME}" /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo \ -arch i386 "i386/lib/libQuantLib.a" \ -arch x86_64 "x86_64/lib/libQuantLib.a" \ -output "${FRAMEWORK_INSTALL_NAME}" \ -create echo "Framework: Copying includes..." cp -r include/${FRAMEWORK_NAME}/* ${FRAMEWORK_BUNDLE}/Headers/ cat > ${FRAMEWORK_BUNDLE}/Resources/Info.plist <<InfoplistEOF <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>CFBundleDevelopmentRegion</key> <string>English</string> <key>CFBundleExecutable</key> <string>${FRAMEWORK_NAME}</string> <key>CFBundleIdentifier</key> <string>quantlib.org</string> <key>CFBundleInfoDictionaryVersion</key> <string>6.0</string> <key>CFBundlePackageType</key> <string>FMWK</string> <key>CFBundleSignature</key> <string>????</string> <key>CFBundleVersion</key> <string>${FRAMEWORK_CURRENT_VERSION}</string> </dict> </plist> InfoplistEOF echo "Done: ${FRAMEWORK_BUNDLE}" qlFrameworkEOF # build framework sh build-qlframework.sh # Test build example using macosx frameworks export QL_VERSION=1.12 clang++ -std=c++11 -stdlib=libc++ -F $HOME/Downloads/QuantLib-${QL_VERSION}/macosx-build -F $HOME/Downloads/boost_1_62_0/macosx-build -framework ql -arch x86_64 -o testql testql.cpp ./testql # Build RQuantLib for Mac OSX 10.12.6 (1) Build the above macosx x86_64 libraries for QuantLib and Boost. For Quantlib, it should be version >=1.8 and with --enable-intraday option. For Boost and QuantLib, should remove -fvisibility=hidden -fvisibility-inlines-hidden (2) Install R 3.4.4 from https://cran.r-project.org/bin/macosx/ and optionally install RStudio (3) Install clang 4.0 from http://r.research.att.com/libs/ sudo tar xzvf ${HOME}/Downloads/clang-4.0.0-darwin15.6-Release.tar.gz -C / (4) Create R/Makevars mkdir -p ${HOME}/.R cat > ${HOME}/.R/Makevars << 'EOF' CC=/usr/local/clang4/bin/clang CXX=/usr/local/clang4/bin/clang++ CXXFLAGS=-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -Wno-nonportable-include-path -Wno-unused-variable -I${HOME}/Downloads/QuantLib-1.12/macosx-build/x86_64/include LDFLAGS=-L/usr/local/clang4/lib -L${HOME}/Downloads/QuantLib-1.12/macosx-build/x86_64/lib EOF # if compile using clang6 under the latest R 3.5.0, should change path to /usr/local/clang6 accordingly. (5) Install QuantLib 1.12 to /usr/local export QL_VERSION=1.12 cd ${HOME}/Downloads/QuantLib-${QL_VERSION}/macosx-build/x86_64; tar czvf ../ql-${QL_VERSION}.tgz bin include lib share cd ${HOME}/Downloads/QuantLib-${QL_VERSION}/macosx-build sudo tar xzvf ql-${QL_VERSION}.tgz -C /usr/local (6) Build RQuantLib with R terminal session from source and install R install.packages("RQuantLib", configure.args = "--with-boost-include=${HOME}/Downloads/boost_1_62_0/macosx-build/include --with-boost-lib=${HOME}/Downloads/boost_1_62_0/macosx-build/x86_64/lib", type = "source") # installing to /Library/Frameworks/R.framework/Versions/3.4/Resources/library/RQuantLib/libs # build binary package (should install dependencies Rcpp and zoo first) using the following # curl -O https://cran.cnr.berkeley.edu/src/contrib/RQuantLib_0.4.4.tar.gz # R CMD INSTALL --build --configure-args="--with-boost-include=${HOME}/Downloads/boost_1_62_0/macosx-build/include --with-boost-lib=${HOME}/Downloads/boost_1_62_0/macosx-build/x86_64/lib" RQuantLib_0.4.4.tar.gz (7) Optionally, install https://www.xquartz.org/ if want to remove warning on : unable to load shared object '/Library/Frameworks/R.framework/Resources/modules//R_X11.so' # Install dependencies for testing RQuantLib R install.packages(c("Rcpp","zoo")) install.packages(c("rgl","RUnit"))


(9) Test RQuantLib binary package for R version 3.4.4 on Mac OSX 10.12.6
bond1.R  Select all
#Simple call with a flat curve require(RQuantLib) bond <- list(faceAmount=100, settlementDays=1, issueDate=as.Date("2014-11-30"), redemption=100)
scheduleparams <- list(effectiveDate=as.Date("2014-11-30"), maturityDate=as.Date("2018-11-30"), period=2, calendar="UnitedStates", businessDayConvention = 4, terminationDateConvention=4, dateGeneration=1, endOfMonth=1, dayCounter = 'Thirty360')
coupon.rate <- c(0.02875)
params <- list(tradeDate=as.Date('2014-2-15'), settleDate=as.Date('2014-2-19'), dt=.25, interpWhat="discount", interpHow="loglinear")
setEvaluationDate(as.Date("2014-11-22"))
discountCurve.flat <- DiscountCurve(params, list(flat=0.05))
FixedRateBond(bond=bond, rates=coupon.rate, schedule=scheduleparams, calc=list(dayCounter='ActualActual.ISMA',compounding='Compounded', freq='Annual', durationType='Modified'),discountCurve=discountCurve.flat)

FixedRateBondPriceByYield( settlementDays=1, yield=0.05127, faceAmount=100, effectiveDate=as.Date("2014-11-30"), maturityDate=as.Date("2018-11-30"), period=2, calendar="UnitedStates", rates=c(0.05), dayCounter=2, businessDayConvention=4, compound=0, redemption=100, issueDate=as.Date("2014-11-30"))

FixedRateBondYield( settlementDays=1, price=99.54593, faceAmount=100, effectiveDate=as.Date("2014-11-30"), maturityDate=as.Date("2018-11-30"), period=2, calendar="UnitedStates", rates=c(0.05), dayCounter=2, businessDayConvention=4, compound=0, redemption=100, issueDate=as.Date("2014-11-30"))





Thursday, July 7, 2016

Wrapping C++ classes and extending for Swift 3.0

Wrapping C++ classes or libraries for Swift requires the following files

(1) Wrapper.h
(2) Wrapper.mm
(3) Bridging-Header.h, this will include all header files (e.g. #include "Wrapper.h") for bridging to Swift
(4) pre-compiled libraries preferably in a framework. E.g. QuantLib and Boost frameworks for macOS and iOS which can be downloaded from the previous post here


The following example code uses the pre-built QuantLib and Boost frameworks to demonstrate a working C++ Wrapper for Swift.

(1) Wrapper.h
Wrapper.h is the header file for the wrapper classes of QuantLib for Swift. Important points for writing header file when wrapping C++ classes to Swift are:
(a) No C++ header files, no C++ classes nor other C++ syntax stuff here, use void* to point to shared_ptr object instead. This header file Wrapper.h will be included in the bridging header file, so avoid c++ stuffs and use only C and Objective C stuffs when compiling in Swift.
(b) Avoid using C++ typedef here, define them in the implementation .mm source files.
(c) Use NS_ENUM macro to replace c++ enum or struct enum here, cast them to c++ enum in the implementation .mm source files. This helps when bridging to Swift enum
(d) use NS_ASSUME_NONNULL macro here and put nullable for optional variable (when bridging to Swift).
(e) use the new lightweight generic <ClassName*> feature in Objective C for NSArray and other collection types e.g. (NSArray<QLRateHelper*>*)rateHelpers
(f) Use the following Objective C types for conversion to Swift
Objective C TypeSwift Type
boolBool
char,unsigned charUInt8, UInt8
short, unsigned shortInt16, UInt16
long, unsigned longInt, UInt
long long, unsigned long longInt64, UInt64
double, floatDouble, Float
NSStringString
NSArray, NSDictionaryArray, Dictionary
Void *UnsafePointer<Void>

Wrapper.h    Select all
// // Wrapper.h // #import <Foundation/Foundation.h> NS_ASSUME_NONNULL_BEGIN @interface QLDate : NSObject typedef NS_ENUM(int, QLMonth) { QLMonthJan=1, QLMonthFeb=2, QLMonthMar=3, QLMonthApr=4, QLMonthMay=5, QLMonthJun=6, QLMonthJul=7, QLMonthAug=8, QLMonthSep=9, QLMonthOct=10, QLMonthNov=11, QLMonthDec=12, QLMonthJanuary=1, QLMonthFebruary=2, QLMonthMarch=3, QLMonthApril=4, QLMonthJune=6, QLMonthJuly=7, QLMonthAugust=8, QLMonthSeptember=9, QLMonthOctober=10, QLMonthNovember=11, QLMonthDecember=12 }; @property (unsafe_unretained, nonatomic, readonly, nullable) void *impl; -(instancetype) initWithD:(long)day Month:(QLMonth)month Y:(long)year; -(instancetype) initWithD:(long)dy M:(long)mn Y:(long)yr; -(instancetype) initWithYear:(long)year Month:(long)month Day:(long)day; -(instancetype) initWithSerialNumber:(long) serialNumber; -(NSString *) weekday; -(NSString *) description; @end typedef NS_ENUM(int, QLTimeUnit) { QLTimeUnitDays, QLTimeUnitWeeks, QLTimeUnitMonths, QLTimeUnitYears }; @interface QLCalendar : NSObject @property (unsafe_unretained, nonatomic, readonly, nullable) void *impl; +(instancetype) TARGET; +(instancetype) UnitedStatesGovernmentBond; +(instancetype) UnitedStatesNYSE; -(QLDate *) adjust:(QLDate *)settlementDate; -(QLDate *) advance:(QLDate *)settlementDate fixingDays:(long)fixingDays timeUnit:(QLTimeUnit)timeUnit; -(NSString *) description; @end // TODO: Other Classes definition here NS_ASSUME_NONNULL_END


(2) Wrapper.mm
Wrapper.mm is the Objective-C++ implementation file for the Wrapper Classes of QuantLib for Swift
(a) Put all the required C++ header files here.
(b) Use boost::shared_ptr<QuantLib::ClassName> or std::shared_ptr<QuantLib::ClassName> in the implementation and point to the C++ objects.
(c) Use static_cast to cast the shared_ptr impl back to QuantLib C++ object. For example
    // cast void* back to QuantLib::ClassName
    QuantLib::Date tmpSettlementDate = *static_cast<QuantLib::Date *>(settlementDate.impl);
    // cast boost::shared_ptr<QuantLib::ClassName> back to QuantLib::ClassName
    static_cast<QuantLib::Date>(*(self._impl));
(d) Use pointer function to access the QuantLib member function. For example
    [[QLDate alloc] initWithSerialNumber:((long)self._impl->adjust(tmpSettlementDate).serialNumber())] ;
(e) Should implement description method for Swift.
    -(NSString *) description

Wrapper.mm    Select all
#import "Wrapper.h" #include <memory> #include <iostream> #include <boost/shared_ptr.hpp> #include <ql/quantlib.hpp> // MARK: QLDate @interface QLDate() @property (unsafe_unretained, nonatomic) boost::shared_ptr<QuantLib::Date> _impl; @end @implementation QLDate -(instancetype) init { self = [super init]; if (self) { self._impl = boost::shared_ptr<QuantLib::Date>(new QuantLib::Date()); } return self; } -(instancetype) initWithD:(long)day Month:(QLMonth)month Y:(long)year { self = [super init]; if (self) { self._impl = boost::shared_ptr<QuantLib::Date>(new QuantLib::Date((int)day, static_cast<QuantLib::Month>(month), (int)year)); } return self; } -(instancetype) initWithD:(long)dy M:(long)mn Y:(long)yr { self = [super init]; if (self) { self._impl = boost::shared_ptr<QuantLib::Date>(new QuantLib::Date((int)dy, static_cast<QuantLib::Month>(mn), (int)yr)); } return self; } -(instancetype) initWithYear:(long)year Month:(long)month Day:(long)day { self = [super init]; if (self) { self._impl = boost::shared_ptr<QuantLib::Date>(new QuantLib::Date((int)day, static_cast<QuantLib::Month>((int)month), (int)year)); } return self; } -(instancetype) initWithSerialNumber:(long) serialNumber { self = [super init]; if (self) { self._impl = boost::shared_ptr<QuantLib::Date>(new QuantLib::Date((QuantLib::BigInteger)serialNumber)); } return self; } -(void *) impl { return static_cast<void *>(self._impl.get()); } -(NSString *) description { std::ostringstream stream; stream << static_cast<QuantLib::Date>(*(self._impl)); std::string name = stream.str(); return [NSString stringWithUTF8String:name.c_str()]; } -(NSString *) weekday { std::ostringstream stream; stream << static_cast<QuantLib::Weekday>(self._impl->weekday()); std::string name = stream.str(); return [NSString stringWithUTF8String:name.c_str()]; } @end // MARK: QLCalendar @implementation QLCalendar -(instancetype) init { self = [super init]; if (self) { self._impl = boost::shared_ptr<QuantLib::Calendar>(new QuantLib::Calendar()); } return self; } -(instancetype) initWithTarget { self = [super init]; if (self) { self._impl = boost::shared_ptr<QuantLib::Calendar>(new QuantLib::TARGET()); } return self; } -(instancetype) initWithUnitedStatesGovernmentBond { self = [super init]; if (self) { self._impl = boost::shared_ptr<QuantLib::Calendar>(new QuantLib::UnitedStates(QuantLib::UnitedStates::GovernmentBond)); } return self; } -(instancetype) initWithUnitedStatesNYSE { self = [super init]; if (self) { self._impl = boost::shared_ptr<QuantLib::Calendar>(new QuantLib::UnitedStates(QuantLib::UnitedStates::NYSE)); } return self; } +(instancetype) TARGET { return [[QLCalendar alloc] initWithTarget]; } +(instancetype) UnitedStatesGovernmentBond { return [[QLCalendar alloc] initWithUnitedStatesGovernmentBond]; } +(instancetype) UnitedStatesNYSE { return [[QLCalendar alloc] initWithUnitedStatesNYSE]; } -(void *) impl { return static_cast<void *>(self._impl.get()); } -(NSString *) description { std::string name = self._impl->name(); return [NSString stringWithUTF8String:name.c_str()]; } -(QLDate *) adjust:(QLDate *)settlementDate { // cast void* to std::shared_ptr<mytype> QuantLib::Date tmpSettlementDate = *static_cast<QuantLib::Date *>(settlementDate.impl); return [[QLDate alloc] initWithSerialNumber:((long)self._impl->adjust(tmpSettlementDate).serialNumber())] ; } -(QLDate *) advance:(QLDate *)settlementDate fixingDays:(long)fixingDays timeUnit:(QLTimeUnit)timeUnit { // cast void* to std::shared_ptr<mytype> QuantLib::Date tmpSettlementDate = *static_cast<QuantLib::Date *>(settlementDate.impl); return [[QLDate alloc] initWithSerialNumber:((long)self._impl->advance(tmpSettlementDate,QuantLib::Integer((int)fixingDays), static_cast<QuantLib::TimeUnit>(timeUnit)).serialNumber())] ; } @end // TODO: Other Classes definition here


(3) main.swift
This is the swift 3.0 example source file (Xcode 8.0) for extending and using the QuantLib C++ classes after wrapping. This example use the calculation method of zeroCouponBond in Bonds.cpp from QuantLib Example source repo.
main.swift    Select all
// // main.swift // import Foundation public extension QLDate { public class func parse(_ string : String, format : String = "yyyy-mm-dd") -> QLDate { var slist : [String] var flist : [String] var d : Int = 0 var m : Int = 0 var y : Int = 0 var delim : String if string.range(of:"/") != nil { delim = "/" } else { delim = "-" } slist = string.components(separatedBy: delim) flist = format.components(separatedBy: delim) for i in 0..<flist.count { let sub = flist[i] if sub.lowercased() == "dd" { d = Int(slist[i])! } else if sub.lowercased() == "mm" { m = Int(slist[i])! } else if sub.lowercased() == "yyyy" { y = Int(slist[i])! } } if y < 100 { y += 2000 } return QLDate(year: y, month: m, day: d) } } public func char2TimeUnit(_ unit:String) -> QLTimeUnit { switch unit { case "D", "d": return .days case "W", "w": return .weeks case "M", "m": return .months case "Y", "y": return .years default: return .months } } /********************* *** MARKET DATA *** *********************/ let calendar = QLCalendar.target() var settlementDate = QLDate.parse("2008-09-18") settlementDate = calendar.adjust(settlementDate); let fixingDays = 3 let settlementDays = 3 let todaysDate = calendar.advance(settlementDate, fixingDays: -(fixingDays), timeUnit: .days) print("Today: \(todaysDate.weekday()), \(todaysDate)") print("Settlement date: \(settlementDate.weekday()), \(settlementDate)") // TODO: Other implementations /*********************************************** ** CURVE BUILDING DEPOSIT + FIXED RATE BOND ** ***********************************************/ var rateHelpers = [QLRateHelper]() /********************* ** DEPOSIT DATA ** *********************/ let depositData: [(Double, Int, String)] = [(0.0096, 3, "M"), (0.0145, 6, "M"), (0.0194, 1, "Y")] for (rate, num, unit) in depositData { let timeunit:QLTimeUnit = char2TimeUnit(unit) let ratehandle = QLHandleQuote(simpleQuoteRate: QLRate(rate:rate)) let depositehelper = QLDepositRateHelper(handle: ratehandle, tenor: QLPeriod(num: num, of: timeunit), fixingDays: fixingDays, calendar: calendar, convention: .modifiedFollowing, endOfMonth: true, dayCounter: QLDayCounter.actual365Fixed()) rateHelpers.append(depositehelper) } /**************************** ** FIXED RATE BOND DATA ** ****************************/ let faceAmount = 100.0 let redemption = 100.0 let tolerance = 1.0e-15 let fixedRateBondData:[(Double, Double, String, String, Double, Double )] = [(faceAmount, redemption, "2005-03-15", "2010-08-31", 0.02375, 100.390625), (faceAmount, redemption, "2005-06-15", "2011-08-31", 0.04625, 106.21875), (faceAmount, redemption, "2006-06-30", "2013-08-31", 0.03125, 100.59375), (faceAmount, redemption, "2002-11-15", "2018-08-15", 0.04000, 101.6875), (faceAmount, redemption, "1987-05-15", "2038-05-15", 0.04500, 102.140625)] for (faceamount, redemption, issuedate, maturitydate, couponrate, marketquote) in fixedRateBondData { let schedule = QLSchedule(issueDate: QLDate.parse(issuedate), maturityDate: QLDate.parse(maturitydate), frequency: QLPeriod(frequency:QLFrequency.semiannual), calendar: QLCalendar.unitedStatesGovernmentBond(), convention: .unadjusted, terminationConvention: .unadjusted, dateGenerationRule: .backward, endOfMonth: false) let quoteHandle = QLRelinkableHandleQuote(marketQuote: marketquote) let bondHelper = QLFixedRateBondHelper(handle: quoteHandle, settlementDays: settlementDays, faceAmount: faceamount, schedule: schedule, couponRate: couponrate, dayCounter: QLDayCounter.actualActualBond(), convention: .unadjusted, redemption: redemption, issueDate: QLDate.parse(issuedate)) rateHelpers.append(bondHelper) } let bondEngine = QLBondPricingEngine(rateHelpers: rateHelpers, settlementDate: settlementDate, tolerance: tolerance) print("bondEngine: \(bondEngine)") /********************* * BONDS TO BE PRICED * **********************/ let zeroCouponBond = QLZeroCouponBond(bondPricingEngine: bondEngine, settlementDays: settlementDays, calendar: QLCalendar.unitedStatesGovernmentBond(), faceAmount: 100.0, maturityDate: QLDate.parse("2013-08-15"), convention: .following, price: 116.92, issueDate: QLDate.parse("2003-08-15")) print("\(zeroCouponBond) NPV = \(String(format: "%.2f", zeroCouponBond.npv()))") print("\(zeroCouponBond) Clean price = \(String(format: "%.2f", zeroCouponBond.cleanPrice()))") print("\(zeroCouponBond) Dirty price = \(String(format: "%.2f", zeroCouponBond.dirtyPrice()))") print("\(zeroCouponBond) Yield = \(String(format: "%.2f%%", zeroCouponBond.yield()*100))")





example xcode project file will be posted here once ready


Thursday, June 25, 2015

QuantLib 1.6 framework (libc++) for iOS and Mac OS X

QuantLib 1.6 framework (compile with -std=c++11 -stdlib=libc++) and prefix pre-built binary.
Architectures in the fat file: framework/ql.framework/ql are: armv7 i386 x86_64 arm64

Pre-built framework and libraries prefix for QuantLib 1.6 can be downloaded from here.

Below is the bash script (modified from http://github.com/philipbarnes/quantlib-on-iOS) to build the framework (compile with -std=c++11 -stdlib=libc++).
Requires Boost 1.58.0 pre-built binary which can be downloaded from here.

build-ql.sh    Select all
#!/bin/bash #=============================================================================== # Filename: build-ql.sh #=============================================================================== # Changes: # # Builds a quantlib framework for iOS & MacOSX # # Requires a pre-built version of boost built using the boost.sh script by # Pete Goodliffe. The structure of this script is based on Pete's boost.sh # # This takes a brute-force approach to the build and builds the arm6, arm7, arm64 and # i386 and x86_64 versions of quantlib one after the other. It makes clean between builds. # # To configure the script, change the variables below to point to the build of # boost lib, include and SYSROOT #=============================================================================== : ${CURRENTDIR:=`pwd`/} : ${BOOST_HOME:=$CURRENTDIR/../ofxiOSBoost-master/usr/local/lib} : ${BOOST_SRC:=$CURRENTDIR/../ofxiOSBoost-master/usr/local/include} : ${ARMV6_SYSROOT:=/Applications/Xcode431.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk} : ${ARMV7_SYSROOT:=/Applications/Xcode501.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk} : ${ARMV7S_SYSROOT:=/Applications/Xcode501.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk} : ${ARM64_SYSROOT:=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk} : ${iPhoneSimulator_SYSROOT:=/Applications/Xcode501.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk} : ${MacOSX_SYSROOT:=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk} #=============================================================================== # The number of jobs for make to run. On a 2.8 Mac Pro 8 core it takes around # 31 minutes with 9 jobs to build all the libraries and framework. #=============================================================================== : ${JOBS:=3} #=============================================================================== # No need to change these variables. # Xcode 4.x and 5.x are used to build the libraries. This now resides in # /Applications/Xcode???.app/Contents #=============================================================================== : ${ARM_DEV_DIR:=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer} : ${SIM_DEV_DIR:=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer} : ${SRCDIR:=`pwd`/src} : ${BUILDDIR:=`pwd`/build} : ${PREFIXDIR:=`pwd`/prefix} : ${FRAMEWORKDIR:=`pwd`/framework} #=============================================================================== # Utility functions for reporting #=============================================================================== displayConfiguration() { echo echo " =================================================================" echo echo " Configuration" echo " SRCDIR :" $SRCDIR echo " BUILDDIR :" $BUILDDIR echo " PREFIXDIR :" $PREFIXDIR echo " FRAMEWORKDIR :" $FRAMEWORKDIR echo echo " BOOST_HOME :" $BOOST_HOME echo " BOOST_SRC :" $BOOST_SRC echo echo " JOBS :" $JOBS echo echo " ARM_DEV_DIR :" $ARM_DEV_DIR echo " SIM_DEV_DIR :" $SIM_DEV_DIR } displayMessage() { echo echo " =================================================================" echo " $@" echo } doneSection() { echo echo " =================================================================" echo " Done: $@" echo } abort() { echo echo "Aborted: $@" exit 1 } #=============================================================================== # Prepare the directory structures #=============================================================================== cleanEverythingReadyToStart() { displayMessage "Cleaning everything ready to start" rm -rf $BUILDDIR #rm -rf $PREFIXDIR #rm -rf $FRAMEWORKDIR doneSection } #=============================================================================== # Prepare the directory structures #=============================================================================== createDirectoryStructure() { displayMessage "Creating directory structure" [ -d $BUILDDIR ] || mkdir -p $BUILDDIR [ -d $PREFIXDIR ] || mkdir -p $PREFIXDIR [ -d $FRAMEWORKDIR ] || mkdir -p $FRAMEWORKDIR doneSection } #=============================================================================== # Build the armv6 quantlib libraries #=============================================================================== buildArmv6() { displayMessage "Configuring armv6 libraries" rm -rf $PREFIXDIR/armv6 make distclean > /dev/null # requires clang 3.1 lib in Xcode 4.3.1 for building armv6 binary CC="/Applications/Xcode431.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" \ CXX="/Applications/Xcode431.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++" \ CPP="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cpp" \ CXXCPP="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cpp" \ CXXFLAGS="-arch armv6 -std=c++11 -stdlib=libc++ -isysroot $ARMV6_SYSROOT" \ CFLAGS="-arch armv6 -std=c99 -isysroot $ARMV6_SYSROOT" \ LDFLAGS="-stdlib=libc++" \ ./configure --with-boost-include=$BOOST_SRC \ --with-boost-lib=$BOOST_HOME \ --host=arm-apple-darwin10 \ --target=arm-apple-darwin10 \ --with-sysroot=$ARMV6_SYSROOT \ --prefix=/usr/local \ --disable-shared --enable-static displayMessage "Making Armv6 libraries" make -j $JOBS && make DESTDIR=$PREFIXDIR/armv6 install || abort "make armv6 failed" doneSection "armv6 done" } #=============================================================================== # Build the armv7 quantlib libraries #=============================================================================== buildArmv7() { displayMessage "Configuring armv7 libraries" rm -rf $PREFIXDIR/armv7 make distclean > /dev/null CC="xcrun --sdk iphoneos clang" \ CXX="xcrun --sdk iphoneos clang++" \ CPP="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cpp" \ CXXCPP="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cpp" \ CXXFLAGS="-arch armv7 -std=c++11 -stdlib=libc++ -isysroot $ARMV7_SYSROOT" \ CFLAGS="-arch armv7 -std=c99 -isysroot $ARMV7_SYSROOT" \ LDFLAGS="-stdlib=libc++" \ ./configure --with-boost-include=$BOOST_SRC \ --with-boost-lib=$BOOST_HOME \ --host=arm-apple-darwin10 \ --target=arm-apple-darwin10 \ --with-sysroot=$ARMV7_SYSROOT \ --prefix=/usr/local \ --disable-shared --enable-static displayMessage "making armv7 libraries" make -j $JOBS && make DESTDIR=$PREFIXDIR/armv7 install || abort "make armv7 failed" doneSection "armv7 done" } #=============================================================================== # Build the armv7s quantlib libraries #=============================================================================== buildArmv7s() { displayMessage "Configuring armv7s libraries" rm -rf $PREFIXDIR/armv7s make distclean > /dev/null CC="xcrun --sdk iphoneos clang" \ CXX="xcrun --sdk iphoneos clang++" \ CPP="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cpp" \ CXXCPP="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cpp" \ CXXFLAGS="-arch armv7s -std=c++11 -stdlib=libc++ -isysroot $ARMV7S_SYSROOT" \ CFLAGS="-arch armv7s -std=c99 -isysroot $ARMV7S_SYSROOT" \ LDFLAGS="-stdlib=libc++" \ ./configure --with-boost-include=$BOOST_SRC \ --with-boost-lib=$BOOST_HOME \ --host=arm-apple-darwin10 \ --target=arm-apple-darwin10 \ --with-sysroot=$ARMV7S_SYSROOT \ --prefix=/usr/local \ --disable-shared --enable-static displayMessage "making armv7s libraries" make -j $JOBS && make DESTDIR=$PREFIXDIR/armv7s install || abort "make armv7s failed" doneSection "armv7s done" } #=============================================================================== # Build the arm64 quantlib libraries #=============================================================================== buildArm64() { displayMessage "Configuring arm64 libraries" rm -rf $PREFIXDIR/arm64 make distclean > /dev/null CC="xcrun --sdk iphoneos clang" \ CXX="xcrun --sdk iphoneos clang++" \ CPP="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cpp" \ CXXCPP="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cpp" \ CXXFLAGS="-arch arm64 -std=c++11 -stdlib=libc++ -isysroot $ARM64_SYSROOT" \ CFLAGS="-arch arm64 -std=c99 -isysroot $ARM64_SYSROOT" \ LDFLAGS="-stdlib=libc++" \ ./configure --with-boost-include=$BOOST_SRC \ --with-boost-lib=$BOOST_HOME \ --host=arm-apple-darwin10 \ --target=arm-apple-darwin10 \ --with-sysroot=$ARM64_SYSROOT \ --prefix=/usr/local \ --disable-shared --enable-static displayMessage "making arm64 libraries" make -j $JOBS && make DESTDIR=$PREFIXDIR/arm64 install || abort "make arm64 failed" doneSection "arm64 done" } #=============================================================================== # Build the i386 quantlib libraries #=============================================================================== buildi386() { displayMessage "Configuring i386 libraries" rm -rf $PREFIXDIR/i386 make distclean > /dev/null CC="xcrun --sdk iphonesimulator clang" \ CXX="xcrun --sdk iphonesimulator clang++" \ CPP="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cpp" \ CXXCPP="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cpp" \ CXXFLAGS="-arch i386 -std=c++11 -stdlib=libc++ -isysroot $iPhoneSimulator_SYSROOT" \ CFLAGS="-arch i386 -isysroot $iPhoneSimulator_SYSROOT" \ LDFLAGS="-stdlib=libc++" \ ./configure --with-boost-include=$BOOST_SRC \ --with-boost-lib=$BOOST_HOME \ --with-sysroot=$iPhoneSimulator_SYSROOT \ --prefix=/usr/local \ --disable-shared --enable-static displayMessage "Building i386 libraries" make -j $JOBS && make DESTDIR=$PREFIXDIR/i386 install || abort "make i386 failed" doneSection "i386 done" } #=============================================================================== # Build the x86_64 quantlib libraries #=============================================================================== buildx86_64() { displayMessage "Configuring x86_64 libraries" rm -rf $PREFIXDIR/x86_64 make distclean > /dev/null CC="xcrun --sdk macosx clang" \ CXX="xcrun --sdk macosx clang++" \ CPP="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cpp" \ CXXCPP="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cpp" \ CXXFLAGS="-arch x86_64 -std=c++11 -stdlib=libc++ -mmacosx-version-min=10.7 -isysroot $MacOSX_SYSROOT" \ CFLAGS="-arch x86_64 -mmacosx-version-min=10.7 -isysroot $MacOSX_SYSROOT" \ LDFLAGS="-stdlib=libc++" \ ./configure --with-boost-include=$BOOST_SRC \ --with-boost-lib=$BOOST_HOME \ --with-sysroot=$MacOSX_SYSROOT \ --prefix=/usr/local \ --disable-shared --enable-static displayMessage "Building x86_64 libraries" make -j $JOBS && make DESTDIR=$PREFIXDIR/x86_64 install || abort "make x86_64 failed" doneSection "x86_64 done" } #=============================================================================== # Build the framework # # Unlike the boost build by Pete Goodliffe, all the libraries are created # individually and so do not need to be unpacked and scrunched together. # # Create the framework libraries in-site #=============================================================================== buildFramework() { VERSION_TYPE=Alpha FRAMEWORK_NAME=ql FRAMEWORK_VERSION=A FRAMEWORK_CURRENT_VERSION=1.6 FRAMEWORK_COMPATIBILITY_VERSION=1.6 FRAMEWORK_BUNDLE=$FRAMEWORKDIR/$FRAMEWORK_NAME.framework rm -rf $FRAMEWORKDIR displayMessage "Framework: Setting up directories..." mkdir -p $FRAMEWORK_BUNDLE mkdir -p $FRAMEWORK_BUNDLE/Versions mkdir -p $FRAMEWORK_BUNDLE/Versions/$FRAMEWORK_VERSION mkdir -p $FRAMEWORK_BUNDLE/Versions/$FRAMEWORK_VERSION/Resources mkdir -p $FRAMEWORK_BUNDLE/Versions/$FRAMEWORK_VERSION/Headers mkdir -p $FRAMEWORK_BUNDLE/Versions/$FRAMEWORK_VERSION/Documentation displayMessage "Framework: Creating symlinks..." ln -s $FRAMEWORK_VERSION $FRAMEWORK_BUNDLE/Versions/Current ln -s Versions/Current/Headers $FRAMEWORK_BUNDLE/Headers ln -s Versions/Current/Resources $FRAMEWORK_BUNDLE/Resources ln -s Versions/Current/Documentation $FRAMEWORK_BUNDLE/Documentation ln -s Versions/Current/$FRAMEWORK_NAME $FRAMEWORK_BUNDLE/$FRAMEWORK_NAME FRAMEWORK_INSTALL_NAME=$FRAMEWORK_BUNDLE/Versions/$FRAMEWORK_VERSION/$FRAMEWORK_NAME displayMessage "Framework: Lipoing library into $FRAMEWORK_INSTALL_NAME" /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo \ -arch armv7 "$PREFIXDIR/armv7/usr/local/lib/libQuantLib.a" \ -arch armv7s "$PREFIXDIR/armv7s/usr/local/lib/libQuantLib.a" \ -arch arm64 "$PREFIXDIR/arm64/usr/local/lib/libQuantLib.a" \ -arch i386 "$PREFIXDIR/i386/usr/local/lib/libQuantLib.a" \ -arch x86_64 "$PREFIXDIR/x86_64/usr/local/lib/libQuantLib.a" \ -output "$FRAMEWORK_INSTALL_NAME" \ -create || abort "Lipo $1 failed" displayMessage "Framework: Copying includes..." cp -r $PREFIXDIR/x86_64/usr/local/include/ql/* $FRAMEWORK_BUNDLE/Headers/ displayMessage "Framework: Creating plist..." cat > $FRAMEWORK_BUNDLE/Resources/Info.plist <<EOF <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>CFBundleDevelopmentRegion</key> <string>English</string> <key>CFBundleExecutable</key> <string>${FRAMEWORK_NAME}</string> <key>CFBundleIdentifier</key> <string>org.quantlib</string> <key>CFBundleInfoDictionaryVersion</key> <string>6.0</string> <key>CFBundlePackageType</key> <string>FMWK</string> <key>CFBundleSignature</key> <string>????</string> <key>CFBundleVersion</key> <string>${FRAMEWORK_CURRENT_VERSION}</string> </dict> </plist> EOF doneSection "$FRAMEWORK_BUNDLE" } #=============================================================================== # Execution starts here #=============================================================================== displayConfiguration cleanEverythingReadyToStart createDirectoryStructure buildArmv7 buildArm64 buildi386 buildx86_64 buildFramework displayMessage "Completed successfully"


Note: QuantLib 1.5 is incompatible with Boost 1.58. Use Boost 1.57 instead.

Here is the framework and prefix for Quantlib 1.6+1.5

Here is the framework and prefix for Boost 1.58+1.57

 
close