diff --git a/CMakeLists.txt b/CMakeLists.txt index decab635f..d0b3408d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,7 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/Include/Model/COM/NMR_COMVersion.h.i configure_file("${CMAKE_CURRENT_SOURCE_DIR}/nuget/ios/lib3mf.iOS.nuspec.in" "${CMAKE_CURRENT_BINARY_DIR}/nuget/ios/lib3mf.iOS.nuspec") configure_file("${CMAKE_CURRENT_SOURCE_DIR}/nuget/macos/lib3mf.macOS.nuspec.in" "${CMAKE_CURRENT_BINARY_DIR}/nuget/macos/lib3mf.macOS.nuspec") configure_file("${CMAKE_CURRENT_SOURCE_DIR}/nuget/windows/lib3mf.windows.nuspec.in" "${CMAKE_CURRENT_BINARY_DIR}/nuget/windows/lib3mf.windows.nuspec") +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/nuget/android/lib3mf.android.nuspec.in" "${CMAKE_CURRENT_BINARY_DIR}/nuget/android/lib3mf.android.nuspec") include(Source/CMakeLists.txt) @@ -108,7 +109,7 @@ if (UNIX OR MINGW) if (NOT APPLE) SET_TARGET_PROPERTIES(${PROJECT_NAME}_s PROPERTIES LINK_FLAGS -s) endif() - if(NOT IOS_PLATFORM) + if(NOT IOS_PLATFORM AND NOT ANDROID_PLATFORM) find_library(LIBUUID_PATH uuid) if(NOT LIBUUID_PATH) message(FATAL_ERROR "libuuid not found") diff --git a/Source/Common/NMR_UUID.cpp b/Source/Common/NMR_UUID.cpp index 65b89887b..10ee94dc4 100644 --- a/Source/Common/NMR_UUID.cpp +++ b/Source/Common/NMR_UUID.cpp @@ -40,6 +40,9 @@ NMR_UUID.cpp implements a datatype and functions to handle UUIDs #if defined(_WIN32) && !defined(__MINGW32__) #include #include +#elif defined(ANDROID) +#include +#include #else #include #endif @@ -56,6 +59,10 @@ namespace NMR if (StringFromCLSID(guid, &str) != S_OK) throw CNMRException(NMR_ERROR_UUIDGENERATIONFAILED); set(str); +#elif defined(ANDROID) + std::ifstream t("/proc/sys/kernel/random/uuid"); + std::string str((std::istreambuf_iterator(t)), std::istreambuf_iterator()); + set(str.c_str()); #else uuid_t uuid; uuid_generate_random(uuid); diff --git a/cmake/BuildAndroid.ps1 b/cmake/BuildAndroid.ps1 new file mode 100644 index 000000000..32ce0438c --- /dev/null +++ b/cmake/BuildAndroid.ps1 @@ -0,0 +1,137 @@ +<# +/************************************************************** +* * +# Copyright (c) Microsoft Corporation. All rights reserved. * +# Licensed under the MIT License. * +* * +**************************************************************/ +.SYNOPSIS +Invokes CMake to build Canvas3d for android targets. + +.DESCRIPTION +It first creates ninja files as native build target. Then invokes ninja to kick off +actual build process. +Assumes, CMake, ninja and Android-ndk are available. + +.EXAMPLE +androidbuild.ps1 -arm64 +#> + +[CmdletBinding()] +param( + [switch]$Clean, + [switch]$Rebuild, + [switch]$arm64, + [switch]$arm32, + [switch]$x86, + [switch]$x86_64, + [switch]$NoDebug +) + +$ErrorActionPreference = "stop" +if($NoDebug) {$BuildType = "Release"} else { $BuildType = "Debug"} + +function GenerateNinjaFiles() +{ + $AndroidABI = findABI + $BuildDirName = getBuildDirName + Write-Host "Generating Android ninja files for $AndroidABI" + New-Item -Path "$PSScriptRoot\..\build" -Name $BuildDirName -ItemType Directory -Force | Out-Null + New-Item -Path "$PSScriptRoot\..\build\$BuildDirName" -Name $BuildType -ItemType Directory -Force | Out-Null + Push-Location "$PSScriptRoot\..\build\$BuildDirName\$BuildType" | Out-Null + + try + { + if (Test-Path Env:ANDROID_HOME) + { + $AndroidNDKRoot = "$Env:ANDROID_HOME\ndk-bundle" + } + else + { + $Appdata = [Environment]::GetFolderPath('ApplicationData') + $AndroidNDKRoot = "$Appdata\..\Local\Android\Sdk\ndk-bundle" + } + $AndroidToolChain = "$AndroidNDKRoot\build\cmake\android.toolchain.cmake" + $AndroidPlatform = "android-21" + + # A path with back-slash as separator can be passed to cmake via commandline but cannot be used in any cmake file. + # So, to avoid any confusion changing path separator to forward slash. + $AndroidToolChain = $AndroidToolChain -replace "\\", "/" + cmake ..\..\.. -DANDROID_ABI="$AndroidABI" -DANDROID_PLATFORM="$AndroidPlatform" -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=intermediates -DCMAKE_BUILD_TYPE="$BuildType" -DCMAKE_TOOLCHAIN_FILE="$AndroidToolChain" -DCMAKE_CXX_FLAGS="-fexceptions -DGTEST_HAS_STD_WSTRING" -DANDROID_STL=c++_static -GNinja -DANDROID_OS_PLATFORM=ANDROID -DLIB3MF_TESTS=TRUE | Write-Host + } + finally + { + Pop-Location | Out-Null + } +} + +function BuildTarget() +{ + $BuildDirName = getBuildDirName + Push-Location "$PSScriptRoot\..\build\$BuildDirName\$BuildType" | Out-Null + try + { + cmake --build . --config "$BuildType" | Write-Host + } + finally + { + Pop-Location | Out-Null + } +} + +function cleanAllTargets() +{ + Remove-Item "$PSScriptRoot\Built" -Recurse -Force -ErrorAction Ignore | Write-Host +} + +function cleanTarget() +{ + # Delete both compilation and installation directories. + $BuildDirName = getBuildDirName + Remove-Item "$PSScriptRoot\build\$BuildDirName\$BuildType" -Recurse -Force -ErrorAction Ignore | Write-Host +} + +function findABI() +{ + $ABI = "x86" + if($arm32) + { + $ABI = "armeabi-v7a" + } + elseif($arm64) + { + $ABI = "arm64-v8a" + } + elseif($x86_64) + { + $abi = "x86_64" + } + return $ABI +} + +function getBuildDirName() +{ + $AndroidABI = findABI + $BuildDirName = "android_$AndroidABI" + return $BuildDirName +} + +function Main() +{ + if($Clean) + { + cleanTarget + } + else + { + if($Rebuild) + { + cleanTarget + } + + GenerateNinjaFiles + BuildTarget + } +} + +Main diff --git a/nuget/android/FindLib3MF.Android.cmake b/nuget/android/FindLib3MF.Android.cmake new file mode 100644 index 000000000..ad564f7eb --- /dev/null +++ b/nuget/android/FindLib3MF.Android.cmake @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.9) + +if (NOT Lib3MF_ANDROID_FOUND) + set(Lib3MF_ANDROID_FOUND TRUE) + add_library(Lib3MF STATIC IMPORTED GLOBAL) + set_target_properties(Lib3MF PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_LIST_DIR}/build/native/include") + set_target_properties(Lib3MF PROPERTIES IMPORTED_LOCATION_DEBUG "${CMAKE_CURRENT_LIST_DIR}/build/native/lib/${ANDROID_ABI}/Debug/static/lib3MF_s.a") + set_target_properties(Lib3MF PROPERTIES IMPORTED_LOCATION_RELEASE "${CMAKE_CURRENT_LIST_DIR}/build/native/lib/${ANDROID_ABI}/Release/static/lib3MF_s.a") + set_target_properties(Lib3MF PROPERTIES IMPORTED_LOCATION_RELWITHDEBINFO "${CMAKE_CURRENT_LIST_DIR}/build/native/lib/${ANDROID_ABI}/Release/static/lib3MF_s.a") + set_target_properties(Lib3MF PROPERTIES IMPORTED_LOCATION_MINSIZEREL "${CMAKE_CURRENT_LIST_DIR}/build/native/lib/${ANDROID_ABI}/Release/static/lib3MF_s.a") + # Default location for other build configurations defaults to Debug + set_target_properties(Lib3MF PROPERTIES IMPORTED_LOCATION "${CMAKE_CURRENT_LIST_DIR}/build/native/lib/${ANDROID_ABI}/Debug/static/lib3MF_s.a") +endif() \ No newline at end of file diff --git a/nuget/android/Lib3MF.Android.nuspec.in b/nuget/android/Lib3MF.Android.nuspec.in new file mode 100644 index 000000000..a83296f7e --- /dev/null +++ b/nuget/android/Lib3MF.Android.nuspec.in @@ -0,0 +1,37 @@ + + + + lib3mf.android + ${LIB3MF_VERSION_MAJOR}.${LIB3MF_VERSION_MINOR}.${LIB3MF_VERSION_MICRO}.${BUILD_NUMBER} + Lib3MF from the 3MF Consortium + 3MF Consortium + 3MF Consortium + false + A C++ library for decoding and encoding 3mf files. + Copyright (C) 2015 Microsoft Corporation Copyright (C) 2015 netfabb GmbH + + + + + + + + + + + + + + + + + + + + + + + + + +