Skip to content
Permalink
Browse files
fix build of fake grass lib
  • Loading branch information
jef-n committed Dec 9, 2012
1 parent 7841975 commit 05746deb890ab2a10707e1129a5787cd41c516fc
Showing with 36 additions and 21 deletions.
  1. +27 −13 src/providers/grass/CMakeLists.txt
  2. +7 −6 src/providers/grass/qgsgrassgislib.cpp
  3. +2 −2 src/providers/grass/qgsgrassgislib.h
@@ -10,6 +10,7 @@ INCLUDE_DIRECTORIES(
${GDAL_INCLUDE_DIR}
${PROJ_INCLUDE_DIR}
${GEOS_INCLUDE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
)

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

# Generate functions mapping for funcions used in original version
# Generate function mapping for functions used in original version
# Create list of functions to be mapped
SET ( FUNCTIONS
SET ( FUNCTIONS
"G_add_color_rule"
"G_adjust_Cell_head"
"G_align_window"
@@ -120,27 +121,37 @@ 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]|(\\*+([^*/]|[\r\n])))*\\*+/)" "" HEADER_FILE "${HEADER_FILE}")
STRING(REGEX REPLACE "#[^\r\n]*" "" HEADER_FILE "${HEADER_FILE}")

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 <grass/gis.h>\n" )
LIST ( APPEND PROTOTYPES "}\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}")
#MESSAGE (STATUS, "ROW: ${ROW}")
# Parse function declaration
STRING( REGEX REPLACE ".*(G_[^\\(]*)\\(.*" "\\1" FUNCTION_NAME "${ROW}" )
FOREACH( FN ${FUNCTIONS} )
IF ( "${FN}" STREQUAL "${FUNCTION_NAME}" )
FOREACH( FN ${FUNCTIONS})
IF ( "${FN}" STREQUAL "${FUNCTION_NAME}" )
LIST ( APPEND FUNCTIONS_MAP "// ${ROW}\n" )
# \\*? and \\** patterns do not work, why?
STRING( REGEX REPLACE "(.*)G_.*" "\\1" FUNCTION_TYPE "${ROW}" )
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 "*" )
IF ( NOT "${POINTER}" STREQUAL "*" )
SET ( POINTER "" )
ENDIF ( NOT "${POINTER}" STREQUAL "*" )
STRING( REGEX REPLACE ".*G_[^\\(]*\\((.*)\\).*" "\\1" PARAM_TYPES "${ROW}" )
@@ -162,16 +173,18 @@ FOREACH( ROW ${HEADER_FILE} )
# 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 PROTOTYPES "${FUNCTION_TYPE} GRASS_LIB_EXPORT ${POINTER} ${FUNCTION_NAME} ( ${PARAM_TYPES} )\;\n" )
#LIST ( APPEND FUNCTIONS_MAP " QgsDebugMsg( \"Entered\" )\;\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 ( "${FN}" STREQUAL "${FUNCTION_NAME}" )
ENDIF ( "${FN}" STREQUAL "${FUNCTION_NAME}" )
ENDFOREACH ( FN )
ENDFOREACH( ROW )

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


# Build fake library
@@ -258,7 +271,7 @@ INSTALL(TARGETS qgisgrass
INSTALL(TARGETS ${FAKE_LIB_GRASS_GIS}
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}
LIBRARY DESTINATION ${QGIS_PLUGIN_DIR})

INSTALL(TARGETS grassprovider
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}
LIBRARY DESTINATION ${QGIS_PLUGIN_DIR})
@@ -268,6 +281,7 @@ INSTALL(TARGETS grassrasterprovider
LIBRARY DESTINATION ${QGIS_PLUGIN_DIR})

INSTALL(TARGETS qgis.d.rast qgis.g.info
RUNTIME DESTINATION ${QGIS_LIBEXEC_DIR}/grass/modules
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
RUNTIME DESTINATION ${QGIS_LIBEXEC_DIR}/grass/modules
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)

@@ -17,6 +17,7 @@
#include <stdio.h>
#include <stdarg.h>

#include "qgsgrassgislibfunctions.h"
#include "qgsgrassgislib.h"

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

char * GRASS_LIB_EXPORT QgsGrassGisLib::G_find_cell2( const char * name, const char * mapset )
char GRASS_LIB_EXPORT *QgsGrassGisLib::G_find_cell2( const char * name, const char * mapset )
{
Q_UNUSED( name );
Q_UNUSED( mapset );
@@ -309,12 +310,12 @@ char * GRASS_LIB_EXPORT QgsGrassGisLib::G_find_cell2( const char * name, const c
return qstrdup( ms.toAscii() ); // memory lost
}

char * GRASS_LIB_EXPORT G_find_cell2( const char* name, const char *mapset )
char GRASS_LIB_EXPORT *G_find_cell2( const char* name, const char *mapset )
{
return QgsGrassGisLib::instance()->G_find_cell2( name, mapset );
}

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

char * GRASS_LIB_EXPORT G_tempfile( void )
char GRASS_LIB_EXPORT *G_tempfile( void )
{
QTemporaryFile file( "qgis-grass-temp.XXXXXX" );
QString name = file.fileName();
file.open();
return name.toAscii().data();
}

char * GRASS_LIB_EXPORT G_mapset( void )
char GRASS_LIB_EXPORT *G_mapset( void )
{
return qstrdup( "qgis" );
}

char * GRASS_LIB_EXPORT G_location( void )
char GRASS_LIB_EXPORT *G_location( void )
{
return qstrdup( "qgis" );
}
@@ -70,7 +70,7 @@ class GRASS_LIB_EXPORT QgsGrassGisLib

};

static GRASS_LIB_EXPORT QgsGrassGisLib* instance();
static QgsGrassGisLib* instance();

QgsGrassGisLib();

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

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

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

0 comments on commit 05746de

Please sign in to comment.