Skip to content

Commit 2ccd70d

Browse files
jas0n1eejason
andauthored
修复 GeoTransform.h 中的条件编译指令,添加 MacOS 支持,更新编译说明 (#330)
Co-authored-by: jason <[email protected]>
1 parent f3d6f9c commit 2ccd70d

File tree

7 files changed

+51
-2
lines changed

7 files changed

+51
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ rayon = "1.0"
1212
# serilaze
1313
serde = { version = "1.0", features = ["derive"] }
1414
serde_json = "1.0"
15-
serde-xml-rs = "0.2.1"
15+
serde-xml-rs = "0.4"
1616

1717
# log
1818
log = "0.4"

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ git clone https://github.com/microsoft/vcpkg.git
133133
./vcpkg/vcpkg install gdal:x64-windows-release
134134
cargo build --release
135135
```
136+
## MacOS
137+
```
138+
#install brew first
139+
brew install rust gdal open-scene-graph
140+
git clone https://github.com/fanvanzh/3dtiles
141+
cd 3dtiles
142+
cargo build --release
143+
```
136144
# 使用说明
137145

138146
## ① 命令行格式

build.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,44 @@ fn build_linux_unkonw() {
5555
println!("cargo:rustc-link-lib=gdal");
5656
}
5757

58+
fn build_macos() {
59+
cc::Build::new()
60+
.cpp(true)
61+
.flag("-std=c++11")
62+
.flag("-Wno-deprecated-declarations")
63+
.warnings(false)
64+
.include("./src")
65+
.include("/opt/homebrew/include") // Homebrew include path for M1 Mac
66+
.include("/opt/homebrew/opt/gdal/include") // GDAL include path
67+
.include("/opt/homebrew/opt/open-scene-graph/include") // OSG include path
68+
.file("./src/tileset.cpp")
69+
.file("./src/shp23dtile.cpp")
70+
.file("./src/osgb23dtile.cpp")
71+
.file("./src/dxt_img.cpp")
72+
.file("./src/GeoTransform.cpp")
73+
.compile("_3dtile");
74+
75+
// Link search paths
76+
println!("cargo:rustc-link-search=native=/opt/homebrew/lib");
77+
println!("cargo:rustc-link-search=native=/opt/homebrew/opt/gdal/lib");
78+
println!("cargo:rustc-link-search=native=/opt/homebrew/opt/open-scene-graph/lib");
79+
80+
// OSG libraries
81+
println!("cargo:rustc-link-lib=osg");
82+
println!("cargo:rustc-link-lib=osgDB");
83+
println!("cargo:rustc-link-lib=osgUtil");
84+
println!("cargo:rustc-link-lib=OpenThreads");
85+
86+
// GDAL library
87+
println!("cargo:rustc-link-lib=gdal");
88+
}
89+
5890
fn main() {
5991
match env::var("TARGET") {
6092
Ok(val) => match val.as_str() {
6193
"x86_64-unknown-linux-gnu" => build_linux_unkonw(),
6294
"x86_64-pc-windows-msvc" => build_win_msvc(),
95+
"aarch64-apple-darwin" => build_macos(),
6396
&_ => {}
6497
},
6598
_ => {}

src/GeoTransform.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
#ifdef _WIN32
44
#include <ogr_spatialref.h>
55
#include <ogrsf_frmts.h>
6+
#elif __APPLE__
7+
#include <ogr_spatialref.h>
8+
#include <ogrsf_frmts.h>
69
#else
710
#include <gdal/ogr_spatialref.h>
811
#include <gdal/ogrsf_frmts.h>

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ fn convert_osgb(src: &str, dest: &str, config: &str) {
238238
if let Ok(_) = f.read_to_string(&mut buffer) {
239239
//
240240
if let Ok(metadata) =
241-
serde_xml_rs::deserialize::<_, ModelMetadata>(buffer.as_bytes())
241+
serde_xml_rs::from_str::<ModelMetadata>(&buffer)
242242
{
243243
//println!("{:?}", metadata);
244244
let v: Vec<&str> = metadata.SRS.split(":").collect();

src/shp23dtile.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
/* vcpkg path */
77
#ifdef _WIN32
88
#include <ogrsf_frmts.h>
9+
#elif __APPLE__
10+
#include <ogrsf_frmts.h>
911
#else
1012
#include <gdal/ogrsf_frmts.h>
1113
#endif

src/tileset.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
#ifdef _WIN32
99
#include <ogr_spatialref.h>
1010
#include <ogrsf_frmts.h>
11+
#elif __APPLE__
12+
#include <ogr_spatialref.h>
13+
#include <ogrsf_frmts.h>
1114
#else
1215
#include <gdal/ogrsf_frmts.h>
1316
#include <gdal/ogr_spatialref.h>

0 commit comments

Comments
 (0)