Skip to content
Permalink
Browse files
[GRASS] multi version build
  • Loading branch information
blazek committed Apr 7, 2015
1 parent 892f142 commit 7d4eb8bce319168862b6847490bda1924bf856eb
@@ -35,11 +35,24 @@ SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
#SET (CMAKE_USE_RELATIVE_PATHS ON)

# try to configure and build GRASS plugin by default
SET (WITH_GRASS TRUE CACHE BOOL "Determines whether GRASS plugin should be built")
IF (WITH_GRASS)
FIND_PACKAGE(GRASS)
SET (GRASS_PREFIX ${GRASS_PREFIX} CACHE PATH "Path to GRASS base directory")
ENDIF (WITH_GRASS)
FOREACH (GRASS_SEARCH_VERSION 6 7)
# For GRASS 6 are used cached variables without version suffix so that existing caches don't have to be reconfigured.
# Cached variables: WITH_GRASS, WITH_GRASS7, GRASS_PREFIX, GRASS_PREFIX7, GRASS_INCLUDE_DIR, GRASS_INCLUDE_DIR7
# Everywhere else each variable has version major appended.
# Normal variables: GRASS_FOUND6, GRASS_FOUND7, GRASS_MAJOR_VERSION6, GRASS_MAJOR_VERSION7, etc.
# In addition there is also GRASS_FOUND, which is TRUE if at least one version of GRASS was found
IF (GRASS_SEARCH_VERSION EQUAL 6)
SET (GRASS_CACHE_VERSION "")
ELSE (GRASS_SEARCH_VERSION EQUAL 6)
SET (GRASS_CACHE_VERSION ${GRASS_SEARCH_VERSION})
ENDIF (GRASS_SEARCH_VERSION EQUAL 6)

SET (WITH_GRASS${GRASS_CACHE_VERSION} TRUE CACHE BOOL "Determines whether GRASS ${GRASS_SEARCH_VERSION} plugin should be built")
IF (WITH_GRASS${GRASS_CACHE_VERSION})
FIND_PACKAGE(GRASS ${GRASS_SEARCH_VERSION})
SET (GRASS_PREFIX${GRASS_CACHE_VERSION} ${GRASS_PREFIX${GRASS_SEARCH_VERSION}} CACHE PATH "Path to GRASS ${GRASS_SEARCH_VERSION} base directory")
ENDIF (WITH_GRASS${GRASS_CACHE_VERSION})
ENDFOREACH (GRASS_SEARCH_VERSION)

SET (WITH_DESKTOP TRUE CACHE BOOL "Determines whether QGIS desktop should be built")

@@ -7,99 +7,130 @@
# macro that checks for grass installation in specified directory

MACRO (CHECK_GRASS G_PREFIX)
#MESSAGE(STATUS "Find GRASS ${GRASS_FIND_VERSION} in ${G_PREFIX}")

FIND_PATH (GRASS_INCLUDE_DIR grass/version.h ${G_PREFIX}/include)
FIND_PATH(GRASS_INCLUDE_DIR${GRASS_CACHE_VERSION} grass/version.h ${G_PREFIX}/include DOC "Path to GRASS ${GRASS_FIND_VERSION} include directory")

IF(GRASS_INCLUDE_DIR)
FILE(READ ${GRASS_INCLUDE_DIR}/grass/version.h VERSIONFILE)
#MESSAGE(STATUS "GRASS_INCLUDE_DIR${GRASS_CACHE_VERSION} = ${GRASS_INCLUDE_DIR${GRASS_CACHE_VERSION}}")

IF(GRASS_INCLUDE_DIR${GRASS_CACHE_VERSION})
FILE(READ ${GRASS_INCLUDE_DIR${GRASS_CACHE_VERSION}}/grass/version.h VERSIONFILE)
# We can avoid the following block using version_less version_equal and
# version_greater. Are there compatibility problems?
STRING(REGEX MATCH "[0-9]+\\.[0-9]+\\.[^ ]+" GRASS_VERSION ${VERSIONFILE})
STRING(REGEX REPLACE "^([0-9]*)\\.[0-9]*\\..*$" "\\1" GRASS_MAJOR_VERSION ${GRASS_VERSION})
STRING(REGEX REPLACE "^[0-9]*\\.([0-9]*)\\..*$" "\\1" GRASS_MINOR_VERSION ${GRASS_VERSION})
STRING(REGEX REPLACE "^[0-9]*\\.[0-9]*\\.(.*)$" "\\1" GRASS_MICRO_VERSION ${GRASS_VERSION})
STRING(REGEX MATCH "[0-9]+\\.[0-9]+\\.[^ ]+" GRASS_VERSION${GRASS_FIND_VERSION} ${VERSIONFILE})
STRING(REGEX REPLACE "^([0-9]*)\\.[0-9]*\\..*$" "\\1" GRASS_MAJOR_VERSION${GRASS_FIND_VERSION} ${GRASS_VERSION${GRASS_FIND_VERSION}})
STRING(REGEX REPLACE "^[0-9]*\\.([0-9]*)\\..*$" "\\1" GRASS_MINOR_VERSION${GRASS_FIND_VERSION} ${GRASS_VERSION${GRASS_FIND_VERSION}})
STRING(REGEX REPLACE "^[0-9]*\\.[0-9]*\\.(.*)$" "\\1" GRASS_MICRO_VERSION${GRASS_FIND_VERSION} ${GRASS_VERSION${GRASS_FIND_VERSION}})
# Add micro version too?
# How to numerize RC versions?
MATH( EXPR GRASS_NUM_VERSION "${GRASS_MAJOR_VERSION}*10000 + ${GRASS_MINOR_VERSION}*100")

SET (GRASS_LIBRARIES_FOUND TRUE)
SET (GRASS_LIB_NAMES gis dig2 dbmiclient dbmibase shape dgl rtree datetime linkm gproj)
IF (GRASS_MAJOR_VERSION LESS 7 )
LIST(APPEND GRASS_LIB_NAMES vect)
LIST(APPEND GRASS_LIB_NAMES form)
ELSE (GRASS_MAJOR_VERSION LESS 7 )
LIST(APPEND GRASS_LIB_NAMES vector)
LIST(APPEND GRASS_LIB_NAMES raster)
ENDIF (GRASS_MAJOR_VERSION LESS 7 )

FOREACH (LIB ${GRASS_LIB_NAMES})
MARK_AS_ADVANCED ( GRASS_LIBRARY_${LIB} )

SET(LIB_PATH NOTFOUND)
FIND_LIBRARY(LIB_PATH NAMES grass_${LIB} PATHS ${G_PREFIX}/lib NO_DEFAULT_PATH)

IF (LIB_PATH)
SET (GRASS_LIBRARY_${LIB} ${LIB_PATH})
ELSE (LIB_PATH)
SET (GRASS_LIBRARY_${LIB} NOTFOUND)
SET (GRASS_LIBRARIES_FOUND FALSE)
ENDIF (LIB_PATH)
ENDFOREACH (LIB)

# LIB_PATH is only temporary variable, so hide it (is it possible to delete a variable?)
UNSET(LIB_PATH CACHE)

IF (GRASS_LIBRARIES_FOUND)
SET (GRASS_FOUND TRUE)
SET (GRASS_PREFIX ${G_PREFIX})
ENDIF (GRASS_LIBRARIES_FOUND)
ENDIF( GRASS_INCLUDE_DIR )

MARK_AS_ADVANCED ( GRASS_INCLUDE_DIR )
MATH( EXPR GRASS_NUM_VERSION${GRASS_FIND_VERSION} "${GRASS_MAJOR_VERSION${GRASS_FIND_VERSION}}*10000 + ${GRASS_MINOR_VERSION${GRASS_FIND_VERSION}}*100")

#MESSAGE(STATUS "GRASS_MAJOR_VERSION${GRASS_FIND_VERSION} = ${GRASS_MAJOR_VERSION${GRASS_FIND_VERSION}}")
IF(GRASS_MAJOR_VERSION${GRASS_FIND_VERSION} EQUAL GRASS_FIND_VERSION)
SET(GRASS_LIBRARIES_FOUND${GRASS_FIND_VERSION} TRUE)
SET(GRASS_LIB_NAMES${GRASS_FIND_VERSION} gis dig2 dbmiclient dbmibase shape dgl rtree datetime linkm gproj)
IF(GRASS_MAJOR_VERSION${GRASS_FIND_VERSION} LESS 7 )
LIST(APPEND GRASS_LIB_NAMES${GRASS_FIND_VERSION} vect)
LIST(APPEND GRASS_LIB_NAMES${GRASS_FIND_VERSION} form)
ELSE(GRASS_MAJOR_VERSION${GRASS_FIND_VERSION} LESS 7 )
LIST(APPEND GRASS_LIB_NAMES${GRASS_FIND_VERSION} vector)
LIST(APPEND GRASS_LIB_NAMES${GRASS_FIND_VERSION} raster)
ENDIF(GRASS_MAJOR_VERSION${GRASS_FIND_VERSION} LESS 7 )

FOREACH(LIB ${GRASS_LIB_NAMES${GRASS_FIND_VERSION}})
MARK_AS_ADVANCED ( GRASS_LIBRARY${GRASS_FIND_VERSION}_${LIB} )

SET(LIB_PATH NOTFOUND)
FIND_LIBRARY(LIB_PATH NAMES grass_${LIB} PATHS ${G_PREFIX}/lib NO_DEFAULT_PATH)

IF(LIB_PATH)
SET(GRASS_LIBRARY${GRASS_FIND_VERSION}_${LIB} ${LIB_PATH})
ELSE(LIB_PATH)
SET(GRASS_LIBRARY${GRASS_FIND_VERSION}_${LIB} NOTFOUND)
SET(GRASS_LIBRARIES_FOUND${GRASS_FIND_VERSION} FALSE)
ENDIF (LIB_PATH)
ENDFOREACH(LIB)

# LIB_PATH is only temporary variable, so hide it (is it possible to delete a variable?)
UNSET(LIB_PATH CACHE)

IF(GRASS_LIBRARIES_FOUND${GRASS_FIND_VERSION})
SET(GRASS_FOUND${GRASS_FIND_VERSION} TRUE)
SET(GRASS_FOUND TRUE) # GRASS_FOUND is true if at least one version was found
SET(GRASS_PREFIX${GRASS_CACHE_VERSION} ${G_PREFIX})
IF(GRASS_FIND_VERSION EQUAL 6)
# Set also normal variable with number
SET(GRASS_INCLUDE_DIR${GRASS_FIND_VERSION} ${GRASS_INCLUDE_DIR${GRASS_CACHE_VERSION}})
SET(GRASS_PREFIX${GRASS_FIND_VERSION} ${G_PREFIX})
ENDIF(GRASS_FIND_VERSION EQUAL 6)
ENDIF(GRASS_LIBRARIES_FOUND${GRASS_FIND_VERSION})
ENDIF(GRASS_MAJOR_VERSION${GRASS_FIND_VERSION} EQUAL GRASS_FIND_VERSION)
ENDIF(GRASS_INCLUDE_DIR${GRASS_CACHE_VERSION})

MARK_AS_ADVANCED ( GRASS_INCLUDE_DIR${GRASS_CACHE_VERSION} )
ENDMACRO (CHECK_GRASS)

###################################
# search for grass installations

#MESSAGE(STATUS "GRASS_FIND_VERSION = ${GRASS_FIND_VERSION}")

# list of paths which to search - user's choice as first
SET (GRASS_PATHS ${GRASS_PREFIX} /usr/lib/grass /usr/lib64/grass64 /usr/lib/grass64 c:/msys/local /opt/grass $ENV{GRASS_PREFIX})
SET (GRASS_PATHS ${GRASS_PREFIX${GRASS_CACHE_VERSION}} /usr/lib/grass /opt/grass $ENV{GRASS_PREFIX${GRASS_CACHE_VERSION}})

# os specific paths
IF (WIN32)
LIST(APPEND GRASS_PATHS c:/msys/local)
ENDIF (WIN32)

IF (UNIX)
IF (GRASS_FIND_VERSION EQUAL 6)
LIST(APPEND GRASS_PATHS /usr/lib64/grass64 /usr/lib/grass64)
ELSEIF (GRASS_FIND_VERSION EQUAL 7)
LIST(APPEND GRASS_PATHS /usr/lib64/grass70 /usr/lib/grass70 /usr/lib64/grass71 /usr/lib/grass71)
ENDIF ()
ENDIF (UNIX)

# mac-specific path
IF (APPLE)
SET (GRASS_PATHS ${GRASS_PATHS}
/Applications/GRASS-6.3.app/Contents/MacOS
/Applications/GRASS-6.4.app/Contents/MacOS
/Applications/GRASS.app/Contents/Resources
)
IF (GRASS_FIND_VERSION EQUAL 6)
LIST(APPEND GRASS_PATHS
/Applications/GRASS-6.3.app/Contents/MacOS
/Applications/GRASS-6.4.app/Contents/MacOS
)
ELSEIF (GRASS_FIND_VERSION EQUAL 7)
LIST(APPEND GRASS_PATHS
/Applications/GRASS-7.0.app/Contents/MacOS
/Applications/GRASS-7.1.app/Contents/MacOS
)
ENDIF ()
LIST(APPEND GRASS_PATHS /Applications/GRASS.app/Contents/Resources)
ENDIF (APPLE)

IF (WITH_GRASS)

IF (WITH_GRASS${GRASS_CACHE_VERSION})
FOREACH (G_PREFIX ${GRASS_PATHS})
IF (NOT GRASS_FOUND)
IF (NOT GRASS_FOUND${GRASS_FIND_VERSION})
CHECK_GRASS(${G_PREFIX})
ENDIF (NOT GRASS_FOUND)
ENDIF (NOT GRASS_FOUND${GRASS_FIND_VERSION})
ENDFOREACH (G_PREFIX)

ENDIF (WITH_GRASS)
ENDIF (WITH_GRASS${GRASS_CACHE_VERSION})

###################################

IF (GRASS_FOUND)
IF (GRASS_FOUND${GRASS_FIND_VERSION})
IF (NOT GRASS_FIND_QUIETLY)
MESSAGE(STATUS "Found GRASS: ${GRASS_PREFIX} (${GRASS_VERSION})")
MESSAGE(STATUS "Found GRASS ${GRASS_FIND_VERSION}: ${GRASS_PREFIX${GRASS_CACHE_VERSION}} (${GRASS_VERSION${GRASS_FIND_VERSION}})")
ENDIF (NOT GRASS_FIND_QUIETLY)

ELSE (GRASS_FOUND)
ELSE (GRASS_FOUND${GRASS_FIND_VERSION})

IF (WITH_GRASS)
IF (WITH_GRASS${GRASS_CACHE_VERSION})

IF (GRASS_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find GRASS")
MESSAGE(FATAL_ERROR "Could not find GRASS ${GRASS_FIND_VERSION}")
ELSE (GRASS_FIND_REQUIRED)
MESSAGE(STATUS "Could not find GRASS")
MESSAGE(STATUS "Could not find GRASS ${GRASS_FIND_VERSION}")
ENDIF (GRASS_FIND_REQUIRED)

ENDIF (WITH_GRASS)
ENDIF (WITH_GRASS${GRASS_CACHE_VERSION})

ENDIF (GRASS_FOUND)
ENDIF (GRASS_FOUND${GRASS_FIND_VERSION})
@@ -22,9 +22,7 @@ IF (POSTGRES_FOUND)
ENDIF (POSTGRES_FOUND)

IF (GRASS_FOUND)
IF (GRASS_MAJOR_VERSION LESS 7 )
ADD_SUBDIRECTORY(grass)
ENDIF (GRASS_MAJOR_VERSION LESS 7 )
ADD_SUBDIRECTORY(grass)
ENDIF (GRASS_FOUND)

IF (WITH_GLOBE)

0 comments on commit 7d4eb8b

Please sign in to comment.