Skip to content

Commit 05746de

Browse files
committed
fix build of fake grass lib
1 parent 7841975 commit 05746de

File tree

3 files changed

+36
-21
lines changed

3 files changed

+36
-21
lines changed

src/providers/grass/CMakeLists.txt

+27-13
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ INCLUDE_DIRECTORIES(
1010
${GDAL_INCLUDE_DIR}
1111
${PROJ_INCLUDE_DIR}
1212
${GEOS_INCLUDE_DIR}
13+
${CMAKE_CURRENT_BINARY_DIR}
1314
)
1415

1516
#
@@ -53,9 +54,9 @@ ENDIF (APPLE)
5354
# Fake GRASS gis library
5455
#
5556

56-
# Generate functions mapping for funcions used in original version
57+
# Generate function mapping for functions used in original version
5758
# Create list of functions to be mapped
58-
SET ( FUNCTIONS
59+
SET ( FUNCTIONS
5960
"G_add_color_rule"
6061
"G_adjust_Cell_head"
6162
"G_align_window"
@@ -120,27 +121,37 @@ FILE(READ "${GRASS_INCLUDE_DIR}/grass/gisdefs.h" HEADER_FILE)
120121
# Function definitions in gisdefs.h may spread over more lines -> remove comments
121122
# and split by ';'
122123
# Remove comments and directives (some macros are lost)
123-
STRING(REGEX REPLACE "(/\\*([^*]|[\r\n]|(\\*+([^*/]|[\r\n])))*\\*+/)" "" HEADER_FILE "${HEADER_FILE}")
124+
STRING(REGEX REPLACE "(/\\*([^*]|[\r\n]|(\\*+([^*/]|[\r\n])))*\\*+/)" "" HEADER_FILE "${HEADER_FILE}")
124125
STRING(REGEX REPLACE "#[^\r\n]*" "" HEADER_FILE "${HEADER_FILE}")
125126

127+
SET ( PROTOTYPES "// Auto generated by cmake, do not edit\n" )
128+
LIST ( APPEND PROTOTYPES "#define GRASS_GISDEFS_H\n" )
129+
LIST ( APPEND PROTOTYPES "extern \"C\"\n" )
130+
LIST ( APPEND PROTOTYPES "{\n" )
131+
LIST ( APPEND PROTOTYPES "#include <grass/gis.h>\n" )
132+
LIST ( APPEND PROTOTYPES "}\n" )
133+
LIST ( APPEND PROTOTYPES "int GRASS_LIB_EXPORT G_set_error_routine(int (*)(const char *, int))\;\n" )
134+
126135
SET ( FUNCTIONS_MAP "// Auto generated by cmake, do not edit\n" )
136+
LIST ( APPEND FUNCTIONS_MAP "#include \"qgsgrassgislibfunctions.h\"\n" )
127137
LIST ( APPEND FUNCTIONS_MAP "#include \"qgsgrassgislib.h\"\n" )
128138
LIST ( APPEND FUNCTIONS_MAP "#include \"qgslogger.h\"\n" )
129139
LIST ( APPEND FUNCTIONS_MAP "#include \"qgis.h\"\n" )
140+
130141
FOREACH( ROW ${HEADER_FILE} )
131142
STRING(REGEX REPLACE "\n" " " ROW "${ROW}")
132143
STRING(REGEX REPLACE "__attribute__.*" "" ROW "${ROW}")
133-
#MESSAGE (STATUS, "ROW: ${ROW}")
144+
#MESSAGE (STATUS, "ROW: ${ROW}")
134145
# Parse function declaration
135146
STRING( REGEX REPLACE ".*(G_[^\\(]*)\\(.*" "\\1" FUNCTION_NAME "${ROW}" )
136-
FOREACH( FN ${FUNCTIONS} )
137-
IF ( "${FN}" STREQUAL "${FUNCTION_NAME}" )
147+
FOREACH( FN ${FUNCTIONS})
148+
IF ( "${FN}" STREQUAL "${FUNCTION_NAME}" )
138149
LIST ( APPEND FUNCTIONS_MAP "// ${ROW}\n" )
139150
# \\*? and \\** patterns do not work, why?
140-
STRING( REGEX REPLACE "(.*)G_.*" "\\1" FUNCTION_TYPE "${ROW}" )
151+
STRING( REGEX REPLACE "^[ \t]*(.*)G_.*" "\\1" FUNCTION_TYPE "${ROW}" )
141152
STRING( REGEX REPLACE "\\*" "" FUNCTION_TYPE "${FUNCTION_TYPE}" )
142153
STRING( REGEX REPLACE ".*(\\*+) *G_.*" "\\1" POINTER "${ROW}" )
143-
IF ( NOT "${POINTER}" STREQUAL "*" )
154+
IF ( NOT "${POINTER}" STREQUAL "*" )
144155
SET ( POINTER "" )
145156
ENDIF ( NOT "${POINTER}" STREQUAL "*" )
146157
STRING( REGEX REPLACE ".*G_[^\\(]*\\((.*)\\).*" "\\1" PARAM_TYPES "${ROW}" )
@@ -162,16 +173,18 @@ FOREACH( ROW ${HEADER_FILE} )
162173
# Declare function type
163174
LIST ( APPEND FUNCTIONS_MAP "typedef ${FUNCTION_TYPE} ${POINTER} ${FUNCTION_NAME}_type(${PARAM_TYPES})\;\n\n" )
164175
LIST ( APPEND FUNCTIONS_MAP "${FUNCTION_TYPE} GRASS_LIB_EXPORT ${POINTER} ${FUNCTION_NAME} ( ${PARAMS} ) {\n" )
176+
LIST ( APPEND PROTOTYPES "${FUNCTION_TYPE} GRASS_LIB_EXPORT ${POINTER} ${FUNCTION_NAME} ( ${PARAM_TYPES} )\;\n" )
165177
#LIST ( APPEND FUNCTIONS_MAP " QgsDebugMsg( \"Entered\" )\;\n" )
166-
178+
167179
LIST ( APPEND FUNCTIONS_MAP " ${FUNCTION_NAME}_type* fn = (${FUNCTION_NAME}_type*) cast_to_fptr (QgsGrassGisLib::instance()->resolve( \"${FUNCTION_NAME}\" ))\;\n" )
168180
LIST ( APPEND FUNCTIONS_MAP " return fn( ${PARAM_NAMES} )\;\n")
169181
LIST ( APPEND FUNCTIONS_MAP "}\n\n" )
170-
ENDIF ( "${FN}" STREQUAL "${FUNCTION_NAME}" )
182+
ENDIF ( "${FN}" STREQUAL "${FUNCTION_NAME}" )
171183
ENDFOREACH ( FN )
172184
ENDFOREACH( ROW )
173185

174186
FILE(WRITE "${CMAKE_CURRENT_BINARY_DIR}/qgsgrassgislibfunctions.cpp" ${FUNCTIONS_MAP})
187+
FILE(WRITE "${CMAKE_CURRENT_BINARY_DIR}/qgsgrassgislibfunctions.h" ${PROTOTYPES})
175188

176189

177190
# Build fake library
@@ -258,7 +271,7 @@ INSTALL(TARGETS qgisgrass
258271
INSTALL(TARGETS ${FAKE_LIB_GRASS_GIS}
259272
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}
260273
LIBRARY DESTINATION ${QGIS_PLUGIN_DIR})
261-
274+
262275
INSTALL(TARGETS grassprovider
263276
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}
264277
LIBRARY DESTINATION ${QGIS_PLUGIN_DIR})
@@ -268,6 +281,7 @@ INSTALL(TARGETS grassrasterprovider
268281
LIBRARY DESTINATION ${QGIS_PLUGIN_DIR})
269282

270283
INSTALL(TARGETS qgis.d.rast qgis.g.info
271-
RUNTIME DESTINATION ${QGIS_LIBEXEC_DIR}/grass/modules
272-
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
284+
RUNTIME DESTINATION ${QGIS_LIBEXEC_DIR}/grass/modules
285+
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
273286
)
287+

src/providers/grass/qgsgrassgislib.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <stdio.h>
1818
#include <stdarg.h>
1919

20+
#include "qgsgrassgislibfunctions.h"
2021
#include "qgsgrassgislib.h"
2122

2223
#include "qgslogger.h"
@@ -292,7 +293,7 @@ int GRASS_LIB_EXPORT G_done_msg( const char *msg, ... )
292293
return 0;
293294
}
294295

295-
char * GRASS_LIB_EXPORT QgsGrassGisLib::G_find_cell2( const char * name, const char * mapset )
296+
char GRASS_LIB_EXPORT *QgsGrassGisLib::G_find_cell2( const char * name, const char * mapset )
296297
{
297298
Q_UNUSED( name );
298299
Q_UNUSED( mapset );
@@ -309,12 +310,12 @@ char * GRASS_LIB_EXPORT QgsGrassGisLib::G_find_cell2( const char * name, const c
309310
return qstrdup( ms.toAscii() ); // memory lost
310311
}
311312

312-
char * GRASS_LIB_EXPORT G_find_cell2( const char* name, const char *mapset )
313+
char GRASS_LIB_EXPORT *G_find_cell2( const char* name, const char *mapset )
313314
{
314315
return QgsGrassGisLib::instance()->G_find_cell2( name, mapset );
315316
}
316317

317-
char * GRASS_LIB_EXPORT G_find_cell( char * name, const char * mapset )
318+
char GRASS_LIB_EXPORT *G_find_cell( char * name, const char * mapset )
318319
{
319320
// Not really sure about differences between G_find_cell and G_find_cell2
320321
return G_find_cell2( name, mapset );
@@ -966,20 +967,20 @@ RASTER_MAP_TYPE QgsGrassGisLib::grassRasterType( QgsRasterBlock::DataType qgisTy
966967
return -1; // not reached
967968
}
968969

969-
char * GRASS_LIB_EXPORT G_tempfile( void )
970+
char GRASS_LIB_EXPORT *G_tempfile( void )
970971
{
971972
QTemporaryFile file( "qgis-grass-temp.XXXXXX" );
972973
QString name = file.fileName();
973974
file.open();
974975
return name.toAscii().data();
975976
}
976977

977-
char * GRASS_LIB_EXPORT G_mapset( void )
978+
char GRASS_LIB_EXPORT *G_mapset( void )
978979
{
979980
return qstrdup( "qgis" );
980981
}
981982

982-
char * GRASS_LIB_EXPORT G_location( void )
983+
char GRASS_LIB_EXPORT *G_location( void )
983984
{
984985
return qstrdup( "qgis" );
985986
}

src/providers/grass/qgsgrassgislib.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class GRASS_LIB_EXPORT QgsGrassGisLib
7070

7171
};
7272

73-
static GRASS_LIB_EXPORT QgsGrassGisLib* instance();
73+
static QgsGrassGisLib* instance();
7474

7575
QgsGrassGisLib();
7676

@@ -107,7 +107,7 @@ class GRASS_LIB_EXPORT QgsGrassGisLib
107107
void * resolve( const char * symbol );
108108

109109
// Print error function set to be called by GRASS lib
110-
static GRASS_LIB_EXPORT int errorRoutine( const char *msg, int fatal );
110+
static int errorRoutine( const char *msg, int fatal );
111111

112112
// Error called by fake lib
113113
void fatal( QString msg );

0 commit comments

Comments
 (0)