-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
CMakeLists.txt
802 lines (739 loc) · 23.4 KB
/
CMakeLists.txt
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
#add_definitions(-DGRASS_BASE="${GRASS_PREFIX}")
########################################################
# Build
include_directories(
${CMAKE_BINARY_DIR}/src/providers/grass
${CMAKE_CURRENT_BINARY_DIR}
)
include_directories (SYSTEM
${POSTGRES_INCLUDE_DIR}
)
#
# GRASS library
#
macro(ADD_GRASSLIB GRASS_BUILD_VERSION)
set(GRASS_PREFIX ${GRASS_PREFIX${GRASS_BUILD_VERSION}})
set(GRASS_MAJOR_VERSION ${GRASS_MAJOR_VERSION${GRASS_BUILD_VERSION}})
set(GRASS_MINOR_VERSION ${GRASS_MINOR_VERSION${GRASS_BUILD_VERSION}})
set(GRASS_OFF_T_SIZE ${GRASS_OFF_T_SIZE${GRASS_BUILD_VERSION}})
set (GRASS_LIBRARY_SRCS
../qgsgrass.cpp
../qgsgrasswin.cpp
../qgsgrassdatafile.cpp
../qgsgrassfeatureiterator.cpp
../qgsgrassimport.cpp
../qgsgrassprovider.cpp
../qgsgrassrasterprovider.cpp
../qgsgrassundocommand.cpp
../qgsgrassvector.cpp
../qgsgrassvectormap.cpp
../qgsgrassvectormaplayer.cpp
)
if (WITH_GUI)
set(GRASS_LIBRARY_SRCS ${GRASS_LIBRARY_SRCS}
../qgsgrassoptions.cpp
)
endif()
if(MSVC)
# 4611 setjmp
set_source_files_properties(
../qgsgrassimport.cpp
../qgsgrassprovider.cpp
../qgsgrassvector.cpp
../qgsgrassvectormap.cpp
../qgsgrassvectormaplayer.cpp
PROPERTIES COMPILE_FLAGS "-wd4611"
)
# 4611 setjmp
# 4702 unreachable code
set_source_files_properties(
../qgsgrass.cpp
PROPERTIES COMPILE_FLAGS "-wd4611 -wd4702"
)
endif()
qt_wrap_ui(GRASS_LIBRARY_UIS_H ../qgsgrassoptionsbase.ui)
add_library(qgisgrass${GRASS_BUILD_VERSION} SHARED
${GRASS_LIBRARY_SRCS}
${GRASS_LIBRARY_UIS_H}
)
# require c++17
target_compile_features(qgisgrass${GRASS_BUILD_VERSION} PRIVATE cxx_std_17)
if(GRASS_OFF_T_SIZE)
set(GRASS_OFF_T_SIZE_DEF "\"-DGRASS_OFF_T_SIZE=${GRASS_OFF_T_SIZE}\"")
else()
set(GRASS_OFF_T_SIZE_DEF "")
endif()
if(QGIS_MACAPP_FRAMEWORK)
set_target_properties(qgisgrass${GRASS_BUILD_VERSION} PROPERTIES
CLEAN_DIRECT_OUTPUT 1
FRAMEWORK 1
FRAMEWORK_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}"
MACOSX_FRAMEWORK_INFO_PLIST "${CMAKE_SOURCE_DIR}/mac/framework.info.plist.in"
MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${COMPLETE_VERSION}
MACOSX_FRAMEWORK_IDENTIFIER org.qgis.qgis3_grass
COMPILE_FLAGS "-DGRASS_BASE=\\\"${GRASS_PREFIX}\\\" ${GRASS_OFF_T_SIZE_DEF}"
)
else()
set_target_properties(qgisgrass${GRASS_BUILD_VERSION} PROPERTIES
CLEAN_DIRECT_OUTPUT 1
FRAMEWORK 0
COMPILE_FLAGS "-DGRASS_BASE=\\\"${GRASS_PREFIX}\\\" ${GRASS_OFF_T_SIZE_DEF}"
)
endif()
if (APPLE)
set_target_properties(qgisgrass${GRASS_BUILD_VERSION} PROPERTIES
LINK_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}"
)
endif()
#generate unversioned libs for android
if (NOT ANDROID)
set_target_properties(qgisgrass${GRASS_BUILD_VERSION} PROPERTIES
VERSION ${COMPLETE_VERSION}
SOVERSION ${COMPLETE_VERSION}
)
endif()
if (GRASS_MAJOR_VERSION LESS 7 )
set(GRASS_TARGET_LINK_LIBRARIES${GRASS_BUILD_VERSION}
qgis_core
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_gis}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_vect}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_I}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_dbmibase}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_dbmiclient}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_gproj}
GDAL::GDAL
)
else()
set(GRASS_TARGET_LINK_LIBRARIES${GRASS_BUILD_VERSION}
qgis_core
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_gis}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_vector}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_raster}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_imagery}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_dbmibase}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_dbmiclient}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_gproj}
GDAL::GDAL
)
endif()
target_link_libraries(qgisgrass${GRASS_BUILD_VERSION} ${GRASS_TARGET_LINK_LIBRARIES${GRASS_BUILD_VERSION}} PostgreSQL::PostgreSQL)
if (WITH_GUI)
target_link_libraries(qgisgrass${GRASS_BUILD_VERSION}
qgis_gui
)
endif()
if (APPLE)
set_target_properties(qgisgrass${GRASS_BUILD_VERSION} PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE)
endif()
GENERATE_EXPORT_HEADER(
qgisgrass${GRASS_BUILD_VERSION}
BASE_NAME GRASS_LIB
EXPORT_FILE_NAME qgis_grass_lib.h
)
#
# GRASS vector provider
#
set (GRASS_VECTOR_PROVIDER_SRCS ../qgsgrassprovidermodule.cpp)
add_library(provider_grass${GRASS_BUILD_VERSION} MODULE ${GRASS_VECTOR_PROVIDER_SRCS})
# require c++17
target_compile_features(provider_grass${GRASS_BUILD_VERSION} PRIVATE cxx_std_17)
set_target_properties(provider_grass${GRASS_BUILD_VERSION} PROPERTIES
COMPILE_FLAGS "-DGRASS_BASE=\\\"${GRASS_PREFIX}\\\""
)
target_link_libraries(provider_grass${GRASS_BUILD_VERSION}
qgisgrass${GRASS_BUILD_VERSION}
)
if (WITH_GUI)
target_link_libraries(provider_grass${GRASS_BUILD_VERSION}
qgis_gui
)
add_dependencies(provider_grass${GRASS_BUILD_VERSION} ui)
endif()
#
# grass raster provider
#
set (GRASS_RASTER_PROVIDER_SRCS
../qgsgrassrasterprovidermodule.cpp
)
add_library(provider_grassraster${GRASS_BUILD_VERSION} MODULE ${GRASS_RASTER_PROVIDER_SRCS})
# require c++17
target_compile_features(provider_grassraster${GRASS_BUILD_VERSION} PRIVATE cxx_std_17)
set_target_properties(provider_grassraster${GRASS_BUILD_VERSION} PROPERTIES
COMPILE_FLAGS "-DGRASS_BASE=\\\"${GRASS_PREFIX}\\\""
)
target_link_libraries(provider_grassraster${GRASS_BUILD_VERSION}
qgisgrass${GRASS_BUILD_VERSION}
qgis_core
)
# override default path where built files are put to allow running qgis without installing
# the modules go under libexec subdir
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${QGIS_OUTPUT_DIRECTORY}/${QGIS_LIBEXEC_SUBDIR}/grass/modules)
#
# grass raster display module
#
add_executable(qgis.d.rast${GRASS_BUILD_VERSION} ../qgis.d.rast.c)
if (GRASS_MAJOR_VERSION LESS 7 )
target_link_libraries(qgis.d.rast${GRASS_BUILD_VERSION}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_gis}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_datetime}
GDAL::GDAL
)
else()
target_link_libraries(qgis.d.rast${GRASS_BUILD_VERSION}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_gis}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_datetime}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_raster}
GDAL::GDAL
)
endif()
#
# grass info module
#
add_executable(qgis.g.info${GRASS_BUILD_VERSION} ../qgis.g.info.c)
if (GRASS_MAJOR_VERSION LESS 7 )
target_link_libraries(qgis.g.info${GRASS_BUILD_VERSION}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_gis}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_datetime}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_gproj}
GDAL::GDAL
)
else()
target_link_libraries(qgis.g.info${GRASS_BUILD_VERSION}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_gis}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_datetime}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_gproj}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_raster}
GDAL::GDAL
)
endif()
if (UNIX)
target_link_libraries(qgis.g.info${GRASS_BUILD_VERSION} m)
endif()
#
# grass raster import module
#
add_executable(qgis.r.in${GRASS_BUILD_VERSION} ../qgis.r.in.cpp)
set_target_properties(qgis.r.in${GRASS_BUILD_VERSION} PROPERTIES
COMPILE_FLAGS "-DGRASS_BASE=\\\"${GRASS_PREFIX}\\\""
)
if (GRASS_MAJOR_VERSION LESS 7 )
target_link_libraries(qgis.r.in${GRASS_BUILD_VERSION}
qgisgrass${GRASS_BUILD_VERSION}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_gis}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_datetime}
GDAL::GDAL
qgis_core
)
else()
target_link_libraries(qgis.r.in${GRASS_BUILD_VERSION}
qgisgrass${GRASS_BUILD_VERSION}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_gis}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_datetime}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_raster}
GDAL::GDAL
qgis_core
)
endif()
#
# grass vector import module
#
add_executable(qgis.v.in${GRASS_BUILD_VERSION} ../qgis.v.in.cpp)
set_target_properties(qgis.v.in${GRASS_BUILD_VERSION} PROPERTIES
COMPILE_FLAGS "-DGRASS_BASE=\\\"${GRASS_PREFIX}\\\""
)
target_link_libraries(qgis.v.in${GRASS_BUILD_VERSION}
qgisgrass${GRASS_BUILD_VERSION}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_gis}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_datetime}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_vect}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_dbmibase}
${GRASS_LIBRARY${GRASS_BUILD_VERSION}_dbmiclient}
GDAL::GDAL
qgis_core
)
########################################################
# Install
install(TARGETS qgisgrass${GRASS_BUILD_VERSION}
RUNTIME DESTINATION ${QGIS_BIN_DIR}
LIBRARY DESTINATION ${QGIS_LIB_DIR}
FRAMEWORK DESTINATION ${QGIS_FW_SUBDIR})
install(TARGETS provider_grass${GRASS_BUILD_VERSION}
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}
LIBRARY DESTINATION ${QGIS_PLUGIN_DIR})
install(TARGETS provider_grassraster${GRASS_BUILD_VERSION}
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}
LIBRARY DESTINATION ${QGIS_PLUGIN_DIR})
install(TARGETS
qgis.d.rast${GRASS_BUILD_VERSION}
qgis.g.info${GRASS_BUILD_VERSION}
qgis.r.in${GRASS_BUILD_VERSION}
qgis.v.in${GRASS_BUILD_VERSION}
RUNTIME DESTINATION ${QGIS_LIBEXEC_DIR}/grass/modules
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
endmacro(ADD_GRASSLIB)
foreach(GRASS_BUILD_VERSION 6 7 8)
if(GRASS_FOUND${GRASS_BUILD_VERSION})
add_subdirectory(${GRASS_BUILD_VERSION})
endif()
endforeach(GRASS_BUILD_VERSION)
#
# Fake GRASS gis library
#
set(WITH_GRASS_DIRECT FALSE) # currently disabled
if(WITH_GRASS_DIRECT)
# only process functions if qgsgrassgislibfunctions.cpp/h not present
# or gisdefs.h is newer
if("${GRASS_INCLUDE_DIR}/grass/gisdefs.h" IS_NEWER_THAN "${CMAKE_CURRENT_BINARY_DIR}/qgsgrassgislibfunctions.cpp" OR "${GRASS_INCLUDE_DIR}/grass/gisdefs.h" IS_NEWER_THAN "${CMAKE_CURRENT_BINARY_DIR}/qgsgrassgislibfunctions.h")
# Generate function mapping for functions used in original version
# Create list of functions to be mapped
set ( FUNCTIONS
"G_add_color_rule"
"G_add_c_raster_color_rule"
"G_add_d_raster_color_rule"
"G_add_f_raster_color_rule"
"G_add_modular_color_rule"
"G_add_raster_color_rule"
"G_adjust_Cell_head"
"G_adjust_easting"
"G_adjust_east_longitude"
"G_align_window"
"G__allocate_null_bits"
"G_allocate_cell_buf"
"G_allocate_c_raster_buf"
"G_allocate_d_raster_buf"
"G_allocate_f_raster_buf"
"G_allocate_null_buf"
"G_allocate_raster_buf"
"G_ask_any"
"G_ask_in_mapset"
"G_ask_new"
"G_ask_old"
"G__calloc"
"G_chop"
"G_chrcat"
"G_chrcpy"
"G_chrmov"
"G_colors_count"
"G_col_to_easting"
"G_convert_dirseps_to_host"
"G_copy"
"G_copy_file"
"G_create_key_value"
"G_database_projection_name"
"G_date"
"G_define_flag"
"G_define_module"
"G_define_option"
"G_define_standard_option"
"G_easting_to_col"
"G_find_key_value"
"G_find_cell_stat"
"G_fopen_new"
"G_format_easting"
"G_format_northing"
"G_format_resolution"
"G_format_timestamp"
"G__write_timestamp"
"G_free"
"G_free_cats"
"G_free_cell_stats"
"G_free_colors"
"G_free_histogram"
"G_free_key_value"
"G_free_raster_cats"
"G_free_reclass"
"G_free_tokens"
"G_fseek"
"G_ftell"
"G_get_cat"
"G_get_cats_title"
"G_get_color"
"G_get_color_range"
"G_get_c_raster_cat"
"G_get_c_raster_color"
"G_get_d_raster_color"
"G_get_f_raster_color"
"G_get_d_color_range"
"G_get_d_raster_cat"
"G__getenv"
"G__getenv2"
"G_get_fp_range_min_max"
"G_get_f_raster_cat"
"G_get_gisrc_mode"
"G_get_histogram_cat"
"G_getl"
"G_getl2"
"G_get_next_marked_raster_cat"
"G_get_range_min_max"
"G_get_raster_cat"
"G_get_raster_cats_title"
"G_get_raster_color"
"G_get_raster_row_colors"
"G_get_raster_value_c"
"G_get_raster_value_d"
"G_get_raster_value_f"
"G_gets"
"G_get_set_window"
"G_gettext"
"G_get_window"
"G_gisbase"
"G_home"
"G_incr_void_ptr"
"G_index"
"G_info_format"
"G_init_cats"
"G_init_cell_stats"
"G_init_colors"
"G_init_fp_range"
"G__init_null_patterns"
"G_init_range"
"G_init_raster_cats"
"G__insert_color_into_lookup"
"G_interp_bicubic"
"G_interp_bilinear"
"G_interp_cubic"
"G_interp_linear"
"G_is_absolute_path"
"G_is_c_null_value"
"G_is_d_null_value"
"G_is_f_null_value"
"G_is_null_value"
"G_lat_scan"
"G_llres_scan"
"G_lon_scan"
"G_lookup_colors"
"G_lookup_c_raster_colors"
"G_lookup_d_raster_colors"
"G_lookup_f_raster_colors"
"G_lookup_raster_colors"
"G__ls"
"G_ls"
"G_ls_format"
"G__malloc"
"G_make_fp_colors"
"G_make_gyr_fp_colors"
"G_make_random_colors"
"G_mark_colors_as_fp"
"G_mark_raster_cats"
"G_mkdir"
"G_next_cell_stat"
"G_northing_to_row"
"G_num_standard_colors"
"G_number_of_tokens"
"G__null_bitstream_size"
"G__projection_name"
"G_percent"
"G_program_name"
"G_projection"
"G_quant_add_rule"
"G_quant_free"
"G_quant_get_limits"
"G_quant_init"
"G_quant_round"
"G_quant_set_neg_infinite_rule"
"G_putenv"
"G_raster_cmp"
"G_raster_cpy"
"G_raster_size"
"G_read_key_value_file"
"G__realloc"
"G_recreate_command"
"G_rewind_cell_stats"
"G_rewind_raster_cats"
"G_rindex"
"G_row_to_northing"
"G_row_update_fp_range"
"G_row_update_range"
"G_scan_easting"
"G_scan_northing"
"G_scan_timestamp"
"G_set_cat"
"G_set_c_null_value"
"G_set_d_null_value"
"G_set_d_raster_cat"
"G_set_color"
"G_set_color_range"
"G_setenv"
"G_setenv2"
"G_set_cats_fmt"
"G_set_f_null_value"
"G_set_gisrc_mode"
"G_set_key_value"
"G_set_null_value"
"G_set_raster_cat"
"G_set_raster_cats_title"
"G_set_raster_value_d"
"G_set_window"
"G_sleep"
"G_sleep_on_error"
"G_store"
"G_strcasecmp"
"G_strcat"
"G_strchg"
"G_strcpy"
"G_strdup"
"G_strend"
"G_strip"
"G_strmov"
"G_strncpy"
"G_str_replace"
"G_strstr"
"G_str_to_lower"
"G_str_to_sql"
"G_str_to_upper"
"G_suppress_masking"
"G_suppress_warnings"
"G_system"
"G_tokenize"
"G_trim_decimal"
"G_unmark_raster_cats"
"G_unset_error_routine"
"G_update_cell_stats"
"G_update_fp_range"
"G_update_key_value_file"
"G_update_range"
"G_usage"
"G_verbose"
"G_verbose_min"
"G_verbose_max"
"G_wait"
"G_whoami"
"G_window_cols"
"G_window_overlap"
"G_window_rows"
"G_write_key_value_file"
"G_yes"
"G_zero"
"G_zero_cell_buf"
"G_zero_raster_buf"
)
# List of functions which are implemented in qgsgrassgislib.cpp and
# thus we only need prototype
set ( FUNCTION_PROTOTYPES
"G_area_of_cell_at_row"
"G_area_of_polygon"
"G_ask_cell_new"
"G_ask_cell_old"
"G_asprintf"
"G_begin_cell_area_calculations"
"G_begin_distance_calculations"
"G_begin_geodesic_distance"
"G_begin_polygon_area_calculations"
"G_check_input_output_name"
"G_check_overwrite"
"G_clear_screen"
"G_close_cell"
"G_command_history"
"G_database_units_to_meters_factor"
"G_debug"
"G_distance"
"G_done_msg"
"G_fatal_error"
"G__file_name"
"G__file_name_misc"
"G_find_cell"
"G_find_cell2"
"G_find_file"
"G_find_file2"
"G_find_file_misc"
"G_find_file2_misc"
"G_find_vector"
"G_find_vector2"
"G_fopen_modify"
"G_fopen_old"
"G_fully_qualified_name"
"G_geodesic_distance_lon_to_lon"
"G_geodesic_distance"
"G_get_cellhd"
"G_get_cell_title"
"G_get_c_raster_row"
"G_get_c_raster_row_nomask"
"G_get_d_raster_row"
"G_get_d_raster_row_nomask"
"G_get_ellipsoid_parameters"
"G_get_f_raster_row"
"G_get_f_raster_row_nomask"
"G_get_map_row"
"G_get_map_row_nomask"
"G_get_null_value_row"
"G_get_projinfo"
"G_get_projunits"
"G_get_raster_map_type"
"G_get_raster_row"
"G_get_raster_row_nomask"
"G_get_reclass"
"G__gisinit"
"G_gisdbase"
"G_important_message"
"G_legal_filename"
"G_location"
"G_location_path"
"G_lookup_key_value_from_file"
"G_make_aspect_fp_colors"
"G__make_mapset_element"
"G_mapset"
"G_maskfd"
"G_mask_info"
"G_message"
"G__name_is_fully_qualified"
"G_number_of_cats"
"G_open_cell_new"
"G_open_cell_old"
"G_open_fp_cell_new"
"G_open_new"
"G_open_raster_new"
"G_open_update"
"G_parser"
"G_put_cell_title"
"G_put_c_raster_row"
"G_put_f_raster_row"
"G_put_d_raster_row"
"G_put_raster_row"
"G_quantize_fp_map_range"
"G_raster_map_is_fp"
"G_raster_map_type"
"G_read_cats"
"G_read_colors"
"G_read_fp_range"
"G_read_history"
"G_read_quant"
"G_read_range"
"G_read_raster_cats"
"G_remove"
"G_rename"
"G_round_fp_map"
"G_set_cats_title"
"G_set_error_routine"
"G_set_geodesic_distance_lat1"
"G_set_geodesic_distance_lat2"
"G_set_quant_rules"
"G_short_history"
"G_snprintf"
"G_spawn"
"G_spawn_ex"
"G__temp_element"
"G_tempfile"
"G_unopen_cell"
"G_vasprintf"
"G_verbose_message"
"G_warning"
"G_write_cats"
"G__write_colors"
"G_write_colors"
"G_write_fp_range"
"G_write_history"
"G_write_range"
"G_write_raster_cats"
"G_write_raster_units"
)
set ( FUNCTIONS_ALL
${FUNCTIONS}
${FUNCTION_PROTOTYPES}
)
# Read GRASS header file and create functions mapping
file(READ "${GRASS_INCLUDE_DIR}/grass/gisdefs.h" HEADER_FILE)
# Function definitions in gisdefs.h may spread over more lines -> remove comments
# and split by ';'
# Remove comments and directives (some macros are lost)
string(REGEX REPLACE "(/\\*([^*]|[\r\n]|(\\*+([^*/]|[\r\n])))*\\*+/)" "" HEADER_FILE "${HEADER_FILE}")
string(REGEX REPLACE "#[^\r\n]*" "" HEADER_FILE "${HEADER_FILE}")
# Add functions defined in glocale.h, colors.h and spawn.h
set ( HEADER_FILE
${HEADER_FILE}
"char *G_gettext(const char *, const char *);"
"int G_num_standard_colors(void);"
"int G_spawn(const char *, ...);"
"int G_spawn_ex(const char *, ...);"
"int G_wait(int);"
)
set ( PROTOTYPES "// Auto generated by cmake, do not edit\n" )
list ( APPEND PROTOTYPES "#define GRASS_GISDEFS_H\n" )
list ( APPEND PROTOTYPES "extern \"C\"\n" )
list ( APPEND PROTOTYPES "{\n" )
list ( APPEND PROTOTYPES "#include <sys/types.h>\n" )
list ( APPEND PROTOTYPES "#include <grass/gis.h>\n" )
#list ( APPEND PROTOTYPES "int GRASS_LIB_EXPORT G_set_error_routine(int (*)(const char *, int))\;\n" )
set ( FUNCTIONS_MAP "// Auto generated by cmake, do not edit\n" )
list ( APPEND FUNCTIONS_MAP "#include \"qgsgrassgislibfunctions.h\"\n" )
list ( APPEND FUNCTIONS_MAP "#include \"qgsgrassgislib.h\"\n" )
list ( APPEND FUNCTIONS_MAP "#include \"qgslogger.h\"\n" )
list ( APPEND FUNCTIONS_MAP "#include \"qgis.h\"\n" )
foreach( ROW ${HEADER_FILE} )
string(REGEX REPLACE "\n" " " ROW "${ROW}")
string(REGEX REPLACE "__attribute__.*" "" ROW "${ROW}")
#message (STATUS, "ROW: ${ROW}")
# Parse function declaration
string( REGEX REPLACE ".*(G_[^\\(]*)\\(.*" "\\1" FUNCTION_NAME "${ROW}" )
foreach( FN ${FUNCTIONS_ALL})
if ( "${FN}" STREQUAL "${FUNCTION_NAME}" )
# \\*? and \\** patterns do not work, why?
string( REGEX REPLACE "^[ \t]*(.*)G_.*" "\\1" FUNCTION_TYPE "${ROW}" )
string( REGEX REPLACE "\\*" "" FUNCTION_TYPE "${FUNCTION_TYPE}" )
string( REGEX REPLACE "[^*]*(\\*+) *G_.*" "\\1" POINTER "${ROW}" )
if ( (NOT "${POINTER}" STREQUAL "*") AND (NOT "${POINTER}" STREQUAL "**") )
set ( POINTER "" )
endif()
string( REGEX REPLACE ".*G_[^\\(]*\\((.*)\\).*" "\\1" PARAM_TYPES "${ROW}" )
set ( PARAM_NAMES "" )
set ( PARAMS "" )
if ( NOT "${PARAM_TYPES}" STREQUAL "void" )
string ( REGEX MATCHALL "[^,]+" PARAM_TYPE_LIST ${PARAM_TYPES} )
set ( I 0 )
foreach( PARAM_TYPE ${PARAM_TYPE_LIST} )
list ( APPEND PARAM_NAMES "p${I}" )
list ( APPEND PARAMS "${PARAM_TYPE} p${I}" )
math(EXPR I "${I} + 1")
endforeach ( PARAM_TYPE )
endif()
string( REPLACE ";" ", " PARAM_NAMES "${PARAM_NAMES}" )
string( REPLACE ";" ", " PARAMS "${PARAMS}" )
# Declare all
list ( APPEND PROTOTYPES "${FUNCTION_TYPE} GRASS_LIB_EXPORT ${POINTER} ${FUNCTION_NAME} ( ${PARAM_TYPES} )\;\n" )
# Define only those not implemented in qgsgrassgislib.cpp
list (FIND FUNCTIONS "${FUNCTION_NAME}" FUNCTION_IDX)
if( ${FUNCTION_IDX} GREATER -1 )
list ( APPEND FUNCTIONS_MAP "// ${ROW}\n" )
# Declare function type
list ( APPEND FUNCTIONS_MAP "typedef ${FUNCTION_TYPE} ${POINTER} ${FUNCTION_NAME}_type(${PARAM_TYPES})\;\n\n" )
list ( APPEND FUNCTIONS_MAP "${FUNCTION_TYPE} GRASS_LIB_EXPORT ${POINTER} ${FUNCTION_NAME} ( ${PARAMS} ) {\n" )
#list ( APPEND FUNCTIONS_MAP " QgsDebugMsgLevel( \"Entered\", 4 )\;\n" )
list ( APPEND FUNCTIONS_MAP " ${FUNCTION_NAME}_type* fn = (${FUNCTION_NAME}_type*) cast_to_fptr (QgsGrassGisLib::instance()->resolve( \"${FUNCTION_NAME}\" ))\;\n" )
list ( APPEND FUNCTIONS_MAP " return fn( ${PARAM_NAMES} )\;\n")
list ( APPEND FUNCTIONS_MAP "}\n\n" )
endif()
endif()
endforeach ( FN )
endforeach( ROW )
list ( APPEND PROTOTYPES "}\n" )
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/qgsgrassgislibfunctions.cpp" ${FUNCTIONS_MAP})
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/qgsgrassgislibfunctions.h" ${PROTOTYPES})
endif() # process functions
# Build fake library
if(MSVC)
set (FAKE_LIB_GRASS_GIS "libgrass_gis.${GRASS_VERSION}")
else()
set (FAKE_LIB_GRASS_GIS "grass_gis.${GRASS_VERSION}")
endif()
add_library(${FAKE_LIB_GRASS_GIS} MODULE qgsgrassgislib.cpp qgsgrassgislibfunctions.cpp )
# require c++17
target_compile_features(${FAKE_LIB_GRASS_GIS} PRIVATE cxx_std_17)
# GRASS_LIBRARY_gis is path to the GRASS library used for compilation, it is the same
# on runtime on Linux and Mac but on Windows with OSGEO4W the GRASS may be installed
# in different directory
set_target_properties(${FAKE_LIB_GRASS_GIS} PROPERTIES
CLEAN_DIRECT_OUTPUT 1
COMPILE_FLAGS "-DGRASS_VERSION=\\\"${GRASS_VERSION}\\\" -DGRASS_LIBRARY_GIS=\\\"${GRASS_LIBRARY_gis}\\\" \"-I${CMAKE_CURRENT_SOURCE_DIR}\" ")
if (NOT APPLE)
set_target_properties(${FAKE_LIB_GRASS_GIS} PROPERTIES
VERSION ${COMPLETE_VERSION}
SOVERSION ${COMPLETE_VERSION}
)
endif()
target_link_libraries(${FAKE_LIB_GRASS_GIS}
qgis_core
)
install(TARGETS ${FAKE_LIB_GRASS_GIS}
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}
LIBRARY DESTINATION ${QGIS_PLUGIN_DIR})
endif()