Skip to content

Commit 748e31b

Browse files
authored
cmake: use imported GDAL target and clean up dependencies (#5263)
- Use CMake's FindGDAL.cmake and use imported GDAL::GDAL target. - Include GDAL include dir with public scope to grass_vector, grass_interpfl and grass_gproj targets enabling the use of those libraries as dependencies without adding GDAL::GDAL as dependency. - Remove dependency of GDAL::GDAL from targets which do not need it.
1 parent 50f6b97 commit 748e31b

File tree

18 files changed

+261
-289
lines changed

18 files changed

+261
-289
lines changed

.github/workflows/cmake.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ jobs:
5959
- name: Configure
6060
run: |
6161
cmake ${CMAKE_OPTIONS} -S $GITHUB_WORKSPACE -B $GITHUB_WORKSPACE/build -G Ninja \
62-
-DCMAKE_C_FLAGS="-I/usr/include -I/usr/include/gdal" \
63-
-DCMAKE_CXX_FLAGS="-I/usr/include -I/usr/include/gdal" \
62+
-DCMAKE_C_FLAGS="-I/usr/include" -DCMAKE_CXX_FLAGS="-I/usr/include" \
6463
-DCMAKE_INSTALL_PREFIX=$HOME/install -DWITH_NLS=OFF -DWITH_GUI=OFF -DWITH_DOCS=OFF
6564
- name: Print CMakeCache.txt
6665
shell: bash -el {0}

cmake/find_scripts/FindGDAL.cmake

-25
This file was deleted.

cmake/modules/CheckDependentLibraries.cmake

+2-8
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ if(PROJ_FOUND)
3030
endif()
3131

3232
find_package(GDAL REQUIRED)
33-
if(GDAL_FOUND)
34-
add_library(GDAL INTERFACE IMPORTED GLOBAL)
35-
set_property(TARGET GDAL PROPERTY INTERFACE_LINK_LIBRARIES ${GDAL_LIBRARY})
36-
set_property(TARGET GDAL PROPERTY INTERFACE_INCLUDE_DIRECTORIES
37-
${GDAL_INCLUDE_DIR})
38-
endif()
3933

4034
find_package(ZLIB REQUIRED)
4135
if(ZLIB_FOUND)
@@ -369,8 +363,8 @@ if(Python3_FOUND)
369363
endif()
370364

371365
check_target(PROJ HAVE_PROJ_H)
372-
check_target(GDAL HAVE_GDAL)
373-
check_target(GDAL HAVE_OGR)
366+
check_target(GDAL::GDAL HAVE_GDAL)
367+
check_target(GDAL::GDAL HAVE_OGR)
374368
check_target(ZLIB HAVE_ZLIB_H)
375369
check_target(ICONV HAVE_ICONV_H)
376370
check_target(LIBPNG HAVE_PNG_H)

db/drivers/CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ build_program_in_subdir(
6464
grass_dbmibase
6565
grass_dbmidriver
6666
grass_sqlp
67-
GDAL
67+
PRIMARY_DEPENDS
68+
GDAL::GDAL
6869
DEFS
6970
"${grass_dbstubs_DEFS}"
7071
HTML_FILE_NAME

display/CMakeLists.txt

+23-12
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,33 @@ if(WITH_DOCS)
8080
install(FILES ${OUTDIR}/${GRASS_INSTALL_DOCDIR}/grass_logo.txt
8181
DESTINATION ${GRASS_INSTALL_DOCDIR})
8282
endif()
83-
build_program_in_subdir(d.grid DEPENDS grass_gis grass_symb grass_gproj
84-
grass_display GDAL ${LIBM})
83+
build_program_in_subdir(
84+
d.grid
85+
DEPENDS
86+
grass_gis
87+
grass_symb
88+
grass_gproj
89+
grass_display
90+
${LIBM})
8591
build_program_in_subdir(d.his DEPENDS grass_gis grass_display grass_raster)
8692
build_program_in_subdir(d.histogram DEPENDS grass_gis grass_display
8793
grass_raster ${LIBM})
8894
build_program_in_subdir(d.info DEPENDS grass_gis grass_display)
8995
build_program_in_subdir(d.labels DEPENDS grass_gis grass_display ${LIBM})
90-
build_program_in_subdir(d.legend DEPENDS grass_gis grass_display grass_raster
91-
grass_raster3d ${LIBM})
96+
build_program_in_subdir(
97+
d.legend
98+
DEPENDS
99+
grass_gis
100+
grass_display
101+
grass_raster
102+
grass_raster3d
103+
${LIBM})
92104
build_program_in_subdir(d.legend.vect DEPENDS grass_gis grass_display
93105
grass_symb ${LIBM})
94106
build_program_in_subdir(d.linegraph DEPENDS grass_gis grass_display grass_symb
95107
grass_raster)
96-
build_program_in_subdir(d.northarrow DEPENDS grass_gis grass_display grass_symb ${LIBM})
108+
build_program_in_subdir(d.northarrow DEPENDS grass_gis grass_display grass_symb
109+
${LIBM})
97110
if(WITH_DOCS)
98111
file(MAKE_DIRECTORY ${OUTDIR}/${GRASS_INSTALL_DOCDIR}/northarrows)
99112
file(GLOB d_northarrow_png
@@ -103,8 +116,9 @@ if(WITH_DOCS)
103116
install(DIRECTORY ${OUTDIR}/${GRASS_INSTALL_DOCDIR}/northarrows
104117
DESTINATION ${GRASS_INSTALL_DOCDIR})
105118
endif()
106-
build_program_in_subdir(d.path DEPENDS grass_gis grass_display grass_vector GDAL)
107-
build_program_in_subdir(d.profile DEPENDS grass_gis grass_display grass_raster ${LIBM})
119+
build_program_in_subdir(d.path DEPENDS grass_gis grass_display grass_vector)
120+
build_program_in_subdir(d.profile DEPENDS grass_gis grass_display grass_raster
121+
${LIBM})
108122
build_program_in_subdir(d.rast DEPENDS grass_gis grass_display grass_raster)
109123
build_program_in_subdir(d.rast.arrow DEPENDS grass_gis grass_raster
110124
grass_display ${LIBM})
@@ -125,7 +139,6 @@ build_program_in_subdir(
125139
grass_raster
126140
grass_symb
127141
grass_vector
128-
GDAL
129142
${LIBM})
130143
build_program_in_subdir(
131144
d.vect.chart
@@ -137,7 +150,6 @@ build_program_in_subdir(
137150
grass_gis
138151
grass_symb
139152
grass_vector
140-
GDAL
141153
${LIBM})
142154
build_program_in_subdir(
143155
d.vect.thematic
@@ -149,6 +161,5 @@ build_program_in_subdir(
149161
grass_display
150162
grass_gis
151163
grass_symb
152-
grass_vector
153-
GDAL)
154-
build_program_in_subdir(d.where DEPENDS grass_gis grass_display grass_gproj GDAL)
164+
grass_vector)
165+
build_program_in_subdir(d.where DEPENDS grass_gis grass_display grass_gproj)

general/CMakeLists.txt

+6-9
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ build_program_in_subdir(g.pnmcomp DEPENDS grass_gis)
2222
if(WITH_LIBPNG)
2323
build_program_in_subdir(g.ppmtopng DEPENDS grass_gis LIBPNG)
2424
endif()
25-
build_program_in_subdir(g.proj DEPENDS grass_gis grass_gproj GDAL PROJ)
26-
# LIBES = $(GPROJLIB) $(VECTORLIB) $(DIG2LIB) $(RASTER3DLIB) $(RASTERLIB)
27-
# $(GISLIB) $(MATHLIB) $(PROJLIB)
25+
build_program_in_subdir(g.proj DEPENDS grass_gis grass_gproj PROJ OPTIONAL_DEPENDS GDAL::GDAL)
26+
2827
build_program_in_subdir(
2928
g.region
3029
DEPENDS
@@ -36,7 +35,6 @@ build_program_in_subdir(
3635
grass_gmath
3736
grass_parson
3837
PROJ
39-
GDAL
4038
${LIBM})
4139

4240
build_program_in_subdir(g.rename DEPENDS grass_gis grass_manage grass_raster)
@@ -46,11 +44,11 @@ build_program_in_subdir(
4644
g.version
4745
DEPENDS
4846
grass_gis
49-
PROJ
50-
GDAL
51-
SQLITE
5247
OPTIONAL_DEPENDS
48+
GDAL::GDAL
5349
GEOS::geos_c
50+
PROJ
51+
SQLITE
5452
DEFS
5553
"-DGRASS_VERSION_NUMBER=\"${GRASS_VERSION_NUMBER}\""
5654
"-DGRASS_VERSION_GIT=\"${GRASS_VERSION_GIT}\""
@@ -74,8 +72,7 @@ build_program_in_subdir(
7472
grass_manage
7573
grass_raster
7674
grass_raster3d
77-
grass_vector
78-
GDAL)
75+
grass_vector)
7976
add_dependencies(g.list cell vector)
8077

8178
build_program_in_subdir(g.remove DEPENDS grass_gis grass_manage grass_raster)

general/manage/lister/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ build_program(
2222
grass_dbmibase
2323
grass_gis
2424
grass_raster
25-
GDAL
2625
RUNTIME_OUTPUT_DIR
2726
"${GRASS_INSTALL_ETCDIR}/lister"
2827
NO_DOCS)

lib/CMakeLists.txt

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ build_library_in_subdir(
2727
DEFS
2828
"-DGDAL_LINK=1"
2929
DEPENDS
30-
GDAL
30+
GDAL::GDAL
3131
PROJ
3232
grass_gis
3333
grass_gproj
@@ -137,7 +137,7 @@ add_subdirectory(fonts)
137137

138138
add_subdirectory(vector)
139139

140-
build_library_in_subdir(imagery DEPENDS grass_gis grass_vector grass_raster GDAL)
140+
build_library_in_subdir(imagery DEPENDS grass_gis grass_vector grass_raster GDAL::GDAL)
141141

142142
build_library_in_subdir(cluster DEPENDS grass_imagery grass_gis grass_raster)
143143

@@ -159,7 +159,7 @@ build_library_in_subdir(
159159
grass_dbmidriver
160160
grass_gmath
161161
grass_segment
162-
GDAL
162+
GDAL::GDAL
163163
HEADERS
164164
"lidar.h")
165165

@@ -174,7 +174,7 @@ build_program_in_subdir(
174174
grass_gis
175175
grass_raster3d
176176
grass_raster
177-
GDAL)
177+
GDAL::GDAL)
178178

179179
build_library_in_subdir(
180180
gpde
@@ -222,7 +222,7 @@ if(WITH_OPENGL)
222222
grass_raster
223223
grass_raster3d
224224
grass_vector
225-
GDAL
225+
GDAL::GDAL
226226
OPENGL
227227
TIFF)
228228

@@ -244,7 +244,7 @@ add_subdirectory(temporal)
244244
build_library_in_subdir(iostream SRC_REGEX "*.cpp" DEPENDS grass_gis)
245245

246246
build_library_in_subdir(manage DEPENDS grass_gis grass_raster grass_vector
247-
grass_raster3d GDAL)
247+
grass_raster3d GDAL::GDAL)
248248
file(COPY manage/element_list DESTINATION ${OUTDIR}/${GRASS_INSTALL_ETCDIR})
249249
install(FILES ${OUTDIR}/${GRASS_INSTALL_ETCDIR}/element_list
250250
DESTINATION ${GRASS_INSTALL_ETCDIR})

lib/proj/CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ build_module(
1313
DEPENDS
1414
grass_driver
1515
grass_gis
16-
GDAL
16+
GDAL::GDAL
1717
ZLIB
1818
PROJ
1919
SOURCES
2020
"${grass_gproj_SOURCES}"
2121
INCLUDES
2222
"../driver")
23+
24+
target_include_directories(grass_gproj PUBLIC ${GDAL_INCLUDE_DIR})

lib/rst/CMakeLists.txt

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# add_subdirectory(data) add_subdirectory(qtree) add_subdirectory(interp_float)
2-
31
build_library_in_subdir(
42
data
53
NAME
@@ -33,9 +31,10 @@ build_library_in_subdir(
3331
grass_vector
3432
grass_qtree
3533
grass_interpdata
36-
GDAL
3734
${LIBM}
3835
OPTIONAL_DEPENDS
3936
OPENMP
4037
HEADERS
4138
"interpf.h")
39+
40+
target_include_directories(grass_interpfl PUBLIC ${GDAL_INCLUDE_DIR})

lib/vector/CMakeLists.txt

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ build_library_in_subdir(
88
NAME
99
grass_vector
1010
DEPENDS
11-
GDAL
11+
GDAL::GDAL
1212
grass_btree2
1313
grass_dbmibase
1414
grass_dbmiclient
@@ -23,6 +23,8 @@ build_library_in_subdir(
2323
OPTIONAL_DEPENDS
2424
GEOS::geos_c)
2525

26+
target_include_directories(grass_vector PUBLIC ${GDAL_INCLUDE_DIR})
27+
2628
if(TARGET POSTGRES)
2729
# target_include_directories(grass_vector SYSTEM PUBLIC
2830
# ${PostgreSQL_INCLUDE_DIR})
@@ -43,7 +45,7 @@ build_library_in_subdir(
4345
grass_dbmibase
4446
grass_dbmiclient
4547
grass_dbmidriver
46-
GDAL)
48+
GDAL::GDAL)
4749

4850
build_library_in_subdir(
4951
neta
@@ -56,7 +58,7 @@ build_library_in_subdir(
5658
grass_gis
5759
grass_dgl
5860
grass_vector
59-
GDAL)
61+
GDAL::GDAL)
6062

6163
if(WITH_DOCS)
6264
generate_html(TARGET grass_vector NAME vectorascii)

lib/vector/diglib/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ build_module(
3434
grass_gmath
3535
grass_gis
3636
grass_rtree
37-
GDAL
37+
GDAL::GDAL
3838
${LIBM})

ps/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ build_program_in_subdir(
1111
grass_dbmiclient
1212
grass_dbmidriver
1313
grass_symb
14-
GDAL
1514
${LIBM})
1615

1716
add_custom_command(

0 commit comments

Comments
 (0)