-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
122 lines (97 loc) · 4.91 KB
/
CMakeLists.txt
File metadata and controls
122 lines (97 loc) · 4.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
cmake_minimum_required(VERSION 3.18)
project(terra CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# ── pybind11 ────────────────────────────────────────────────────────────────
# Installed via: pip install pybind11
# or via cmake: find_package(pybind11 CONFIG REQUIRED)
find_package(pybind11 CONFIG REQUIRED)
# ── GDAL ────────────────────────────────────────────────────────────────────
find_package(GDAL REQUIRED)
# ── GEOS ────────────────────────────────────────────────────────────────────
# Try cmake config first (GEOS >= 3.9 ships one), fall back to pkg-config.
find_package(GEOS QUIET CONFIG)
if (NOT GEOS_FOUND)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GEOS REQUIRED geos)
endif()
# ── PROJ ────────────────────────────────────────────────────────────────────
find_package(PROJ CONFIG QUIET)
if (NOT PROJ_FOUND)
find_package(PkgConfig REQUIRED)
pkg_check_modules(PROJ REQUIRED proj)
endif()
# ── terra C++ core (mirrored from rspatial/terra src/) ──────────────────────
# Lives in terra_lib/; Python package + extension output live under src/.
# Optional _tappa_cpp_src: legacy CI vendored copy of terra_lib.
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/_tappa_cpp_src")
set(TERRA_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/_tappa_cpp_src")
elseif (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/terra_lib/spatRaster.cpp")
set(TERRA_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/terra_lib")
elseif (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/spatRaster.cpp")
set(TERRA_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src")
else()
set(TERRA_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../src")
endif()
file(GLOB TERRA_SOURCES "${TERRA_SRC_DIR}/*.cpp")
# Drop Rcpp bridge sources (R package only); matches sync excludes on terra_lib/.
list(FILTER TERRA_SOURCES EXCLUDE REGEX ".*/Rcpp[^/]*\\.cpp$")
# GEOS feature macros (GEOS350, GEOS380, …) come from geos_spat.h via GEOS_VERSION_*.
# ── PROJ version flag ────────────────────────────────────────────────────────
if (PROJ_FOUND)
if (DEFINED PROJ_VERSION)
set(_proj_ver "${PROJ_VERSION}")
elseif (DEFINED PROJ_VERSION_STRING)
set(_proj_ver "${PROJ_VERSION_STRING}")
else()
set(_proj_ver "0.0.0")
endif()
if (_proj_ver VERSION_GREATER_EQUAL "6.0")
set(PROJ_CXXFLAGS "HAVE_PROJ_H") # no -D prefix; CMake adds it
endif()
endif()
# ── TBB (optional) ──────────────────────────────────────────────────────────
find_package(TBB QUIET)
if (TBB_FOUND)
set(TBB_LINK_LIBS TBB::tbb)
set(TBB_COMPILE_DEFS HAVE_TBB)
endif()
# ── Build the extension ──────────────────────────────────────────────────────
pybind11_add_module(_terra
native/terra_module.cpp
${TERRA_SOURCES}
)
target_include_directories(_terra PRIVATE
${TERRA_SRC_DIR}
${GDAL_INCLUDE_DIRS}
)
# Absorb GEOS / PROJ include directories whether they came from cmake config
# packages (targets) or from pkg-config (variables).
if (TARGET GEOS::geos_c)
target_link_libraries(_terra PRIVATE GEOS::geos_c)
elseif (DEFINED GEOS_INCLUDE_DIRS)
target_include_directories(_terra PRIVATE ${GEOS_INCLUDE_DIRS})
target_link_directories(_terra PRIVATE ${GEOS_LIBRARY_DIRS})
target_link_libraries(_terra PRIVATE ${GEOS_LIBRARIES})
endif()
if (TARGET PROJ::proj)
target_link_libraries(_terra PRIVATE PROJ::proj)
elseif (DEFINED PROJ_INCLUDE_DIRS)
target_include_directories(_terra PRIVATE ${PROJ_INCLUDE_DIRS})
target_link_directories(_terra PRIVATE ${PROJ_LIBRARY_DIRS})
target_link_libraries(_terra PRIVATE ${PROJ_LIBRARIES})
endif()
target_link_libraries(_terra PRIVATE
GDAL::GDAL
${TBB_LINK_LIBS}
)
target_compile_definitions(_terra PRIVATE
standalone # suppresses useRcpp; keeps useGDAL active
${PROJ_CXXFLAGS}
${TBB_COMPILE_DEFS}
)
# Place the built .so / .pyd directly inside the Python package directory so
# an editable install (pip install -e .) works without further configuration.
set_target_properties(_terra PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/tappa"
)