Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
define extern C also functions implemented in qgsgrassgislib.cpp, it …
…should make functions visible on Windows
  • Loading branch information
blazek committed Dec 11, 2012
1 parent c4d8e5a commit c84408e
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 11 deletions.
86 changes: 76 additions & 10 deletions src/providers/grass/CMakeLists.txt
Expand Up @@ -116,6 +116,67 @@ SET ( FUNCTIONS
"G_zero"
)

# List of functions which are implemented in qgsgrassgislib.cpp and
# thus we only need prototype
SET ( FUNCTION_PROTOTYPES
"G__gisinit"
"G_parser"
"G_set_error_routine"
"G_warning"
"G_fatal_error"
"G_done_msg"
"*G_find_cell2"
"*G_find_cell"
"G_open_cell_old"
"G_close_cell"
"G_open_raster_new"
"G_open_cell_new"
"G_raster_map_is_fp"
"G_read_fp_range"
"G_read_range"
"G_debug"
"G_message"
"G_verbose_message"
"G_set_quant_rules"
"G_get_raster_row"
"G_get_raster_row_nomask"
"G_get_c_raster_row"
"G_get_c_raster_row_nomask"
"G_get_f_raster_row"
"G_get_f_raster_row_nomask"
"G_get_d_raster_row"
"G_get_d_raster_row_nomask"
"G_get_map_row"
"G_get_map_row_nomask"
"G_put_raster_row"
"G_check_input_output_name"
"G_get_cellhd"
"G_database_units_to_meters_factor"
"G_begin_distance_calculations"
"G_distance"
"G_legal_filename"
"G_tempfile"
"G_mapset"
"G_location"
"G_write_colors"
"G_quantize_fp_map_range"
"G_read_raster_cats"
"G_write_raster_cats"
"G_short_history"
"G_write_history"
"G_maskfd"
"G_command_history"
"G_set_cats_title"
"G_read_history"
"G_read_colors"
"G_make_aspect_fp_colors"
)

SET ( FUNCTIONS_ALL
${FUNCTIONS}
${FUNCTION_PROTOTYPES}
)

# Read GRASS header file and create functions mapping
FILE(READ "${GRASS_INCLUDE_DIR}/grass/gisdefs.h" HEADER_FILE)

Expand All @@ -130,7 +191,7 @@ 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 "int GRASS_LIB_EXPORT G_set_error_routine(int (*)(const char *, int))\;\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" )
Expand All @@ -144,9 +205,8 @@ FOREACH( ROW ${HEADER_FILE} )
#MESSAGE (STATUS, "ROW: ${ROW}")
# Parse function declaration
STRING( REGEX REPLACE ".*(G_[^\\(]*)\\(.*" "\\1" FUNCTION_NAME "${ROW}" )
FOREACH( FN ${FUNCTIONS})
FOREACH( FN ${FUNCTIONS_ALL})
IF ( "${FN}" STREQUAL "${FUNCTION_NAME}" )
LIST ( APPEND FUNCTIONS_MAP "// ${ROW}\n" )
# \\*? and \\** patterns do not work, why?
STRING( REGEX REPLACE "^[ \t]*(.*)G_.*" "\\1" FUNCTION_TYPE "${ROW}" )
STRING( REGEX REPLACE "\\*" "" FUNCTION_TYPE "${FUNCTION_TYPE}" )
Expand All @@ -170,15 +230,21 @@ FOREACH( ROW ${HEADER_FILE} )
STRING( REPLACE ";" ", " PARAM_NAMES "${PARAM_NAMES}" )
STRING( REPLACE ";" ", " PARAMS "${PARAMS}" )

# 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" )
# Declare all
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" )
# 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 " 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 ( ${FUNCTION_IDX} GREATER -1 )
ENDIF ( "${FN}" STREQUAL "${FUNCTION_NAME}" )
ENDFOREACH ( FN )
ENDFOREACH( ROW )
Expand Down
5 changes: 5 additions & 0 deletions src/providers/grass/qgsgrassgislib.cpp
Expand Up @@ -18,6 +18,9 @@
#include <stdarg.h>
#include <QtGlobal>

// If qgsgrassgislibfunctions.h is included on Linux, symbols defined here
// cannot be found (undefined symbol error) even if they are present in
// the library (in code section) - why?
#ifdef Q_OS_WIN
#include "qgsgrassgislibfunctions.h"
#endif
Expand All @@ -41,6 +44,7 @@

#include <QTextCodec>

#if 0
extern "C"
{
#ifndef _MSC_VER
Expand All @@ -50,6 +54,7 @@ extern "C"
#include <grass/Vect.h>
#include <grass/version.h>
}
#endif

#if !defined(GRASS_VERSION_MAJOR) || \
!defined(GRASS_VERSION_MINOR) || \
Expand Down
1 change: 0 additions & 1 deletion src/providers/grass/qgsgrassgislib.h
Expand Up @@ -20,7 +20,6 @@
extern "C"
{
#include <grass/gis.h>
#include <grass/form.h>
}

#include <stdexcept>
Expand Down

0 comments on commit c84408e

Please sign in to comment.