Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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")
Expand Down
7 changes: 7 additions & 0 deletions Source/Common/NMR_UUID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ NMR_UUID.cpp implements a datatype and functions to handle UUIDs
#if defined(_WIN32) && !defined(__MINGW32__)
#include <Objbase.h>
#include <iomanip>
#elif defined(ANDROID)
#include <fstream>
#include <sstream>
#else
#include <uuid/uuid.h>
#endif
Expand All @@ -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<char>(t)), std::istreambuf_iterator<char>());
set(str.c_str());
#else
uuid_t uuid;
uuid_generate_random(uuid);
Expand Down
137 changes: 137 additions & 0 deletions cmake/BuildAndroid.ps1
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions nuget/android/FindLib3MF.Android.cmake
Original file line number Diff line number Diff line change
@@ -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()
37 changes: 37 additions & 0 deletions nuget/android/Lib3MF.Android.nuspec.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>lib3mf.android</id>
<version>${LIB3MF_VERSION_MAJOR}.${LIB3MF_VERSION_MINOR}.${LIB3MF_VERSION_MICRO}.${BUILD_NUMBER}</version>
<title>Lib3MF from the 3MF Consortium</title>
<authors>3MF Consortium</authors>
<owners>3MF Consortium</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>A C++ library for decoding and encoding 3mf files.</description>
<copyright>Copyright (C) 2015 Microsoft Corporation Copyright (C) 2015 netfabb GmbH</copyright>
<tags></tags>
<releaseNotes></releaseNotes>
</metadata>
<files>
<!-- android_arm64-v8a|Debug -->
<file src="${CMAKE_CURRENT_SOURCE_DIR}/build/android_arm64-v8a/Debug/lib3MF_s.a" target="/build/native/lib/android_arm64-v8a/Debug/static" />
<!-- android_arm64-v8a|Release -->
<file src="${CMAKE_CURRENT_SOURCE_DIR}/build/android_arm64-v8a/Release/lib3MF_s.a" target="/build/native/lib/android_arm64-v8a/Release/static" />
<!-- android_arm64-v8a|Debug -->
<file src="${CMAKE_CURRENT_SOURCE_DIR}/build/android_armeabi-v7a/Debug/lib3MF_s.a" target="/build/native/lib/android_armeabi-v7a/Debug/static" />
<!-- android_arm64-v8a|Release -->
<file src="${CMAKE_CURRENT_SOURCE_DIR}/build/android_armeabi-v7a/Release/lib3MF_s.a" target="/build/native/lib/android_armeabi-v7a/Release/static" />
<!-- android_arm64-v8a|Debug -->
<file src="${CMAKE_CURRENT_SOURCE_DIR}/build/android_x86/Debug/lib3MF_s.a" target="/build/native/lib/android_x86/Debug/static" />
<!-- android_arm64-v8a|Release -->
<file src="${CMAKE_CURRENT_SOURCE_DIR}/build/android_x86/Release/lib3MF_s.a" target="/build/native/lib/android_x86/Release/static" />
<!-- android_arm64-v8a|Debug -->
<file src="${CMAKE_CURRENT_SOURCE_DIR}/build/android_x86_64/Debug/lib3MF_s.a" target="/build/native/lib/android_x86_64/Debug/static" />
<!-- android_arm64-v8a|Release -->
<file src="${CMAKE_CURRENT_SOURCE_DIR}/build/android_x86_64/Release/lib3MF_s.a" target="/build/native/lib/android_x86_64/Release/static" />
<!-- Build (C++) -->
<file src="${CMAKE_CURRENT_SOURCE_DIR}/include/**/*" target="/build/native/include" />
<!-- CMake Module -->
<file src="${CMAKE_CURRENT_SOURCE_DIR}/nuget/android/FindLib3MF.Android.cmake" target="" />
</files>
</package>