cmake/FindGLPK.cmake
author Alpar Juttner <alpar@cs.elte.hu>
Wed, 17 Oct 2018 18:56:39 +0200
changeset 1395 f425c93848fa
parent 1230 caf16813b1e8
permissions -rw-r--r--
Merge #1.3 related bugfix heads
ladanyi@684
     1
SET(GLPK_ROOT_DIR "" CACHE PATH "GLPK root directory")
ladanyi@684
     2
ladanyi@496
     3
SET(GLPK_REGKEY "[HKEY_LOCAL_MACHINE\\SOFTWARE\\GnuWin32\\Glpk;InstallPath]")
ladanyi@496
     4
GET_FILENAME_COMPONENT(GLPK_ROOT_PATH ${GLPK_REGKEY} ABSOLUTE)
ladanyi@496
     5
ladanyi@496
     6
FIND_PATH(GLPK_INCLUDE_DIR
ladanyi@496
     7
  glpk.h
ladanyi@684
     8
  PATHS ${GLPK_REGKEY}/include
ladanyi@684
     9
  HINTS ${GLPK_ROOT_DIR}/include
ladanyi@684
    10
)
ladanyi@496
    11
FIND_LIBRARY(GLPK_LIBRARY
ladanyi@684
    12
  glpk
ladanyi@684
    13
  PATHS ${GLPK_REGKEY}/lib
ladanyi@684
    14
  HINTS ${GLPK_ROOT_DIR}/lib
ladanyi@684
    15
)
ladanyi@496
    16
ladanyi@685
    17
IF(GLPK_INCLUDE_DIR AND GLPK_LIBRARY)
ladanyi@685
    18
  FILE(READ ${GLPK_INCLUDE_DIR}/glpk.h GLPK_GLPK_H)
ladanyi@685
    19
ladanyi@685
    20
  STRING(REGEX MATCH "define[ ]+GLP_MAJOR_VERSION[ ]+[0-9]+" GLPK_MAJOR_VERSION_LINE "${GLPK_GLPK_H}")
ladanyi@685
    21
  STRING(REGEX REPLACE "define[ ]+GLP_MAJOR_VERSION[ ]+([0-9]+)" "\\1" GLPK_VERSION_MAJOR "${GLPK_MAJOR_VERSION_LINE}")
ladanyi@685
    22
ladanyi@685
    23
  STRING(REGEX MATCH "define[ ]+GLP_MINOR_VERSION[ ]+[0-9]+" GLPK_MINOR_VERSION_LINE "${GLPK_GLPK_H}")
ladanyi@685
    24
  STRING(REGEX REPLACE "define[ ]+GLP_MINOR_VERSION[ ]+([0-9]+)" "\\1" GLPK_VERSION_MINOR "${GLPK_MINOR_VERSION_LINE}")
ladanyi@685
    25
ladanyi@685
    26
  SET(GLPK_VERSION_STRING "${GLPK_VERSION_MAJOR}.${GLPK_VERSION_MINOR}")
ladanyi@685
    27
ladanyi@685
    28
  IF(GLPK_FIND_VERSION)
ladanyi@685
    29
    IF(GLPK_FIND_VERSION_COUNT GREATER 2)
ladanyi@685
    30
      MESSAGE(SEND_ERROR "unexpected version string")
ladanyi@685
    31
    ENDIF(GLPK_FIND_VERSION_COUNT GREATER 2)
ladanyi@685
    32
ladanyi@685
    33
    MATH(EXPR GLPK_REQUESTED_VERSION "${GLPK_FIND_VERSION_MAJOR}*100 + ${GLPK_FIND_VERSION_MINOR}")
ladanyi@685
    34
    MATH(EXPR GLPK_FOUND_VERSION "${GLPK_VERSION_MAJOR}*100 + ${GLPK_VERSION_MINOR}")
ladanyi@685
    35
ladanyi@685
    36
    IF(GLPK_FOUND_VERSION LESS GLPK_REQUESTED_VERSION)
ladanyi@685
    37
      SET(GLPK_PROPER_VERSION_FOUND FALSE)
ladanyi@685
    38
    ELSE(GLPK_FOUND_VERSION LESS GLPK_REQUESTED_VERSION)
ladanyi@685
    39
      SET(GLPK_PROPER_VERSION_FOUND TRUE)
ladanyi@685
    40
    ENDIF(GLPK_FOUND_VERSION LESS GLPK_REQUESTED_VERSION)
ladanyi@685
    41
  ELSE(GLPK_FIND_VERSION)
ladanyi@685
    42
    SET(GLPK_PROPER_VERSION_FOUND TRUE)
ladanyi@685
    43
  ENDIF(GLPK_FIND_VERSION)
ladanyi@685
    44
ENDIF(GLPK_INCLUDE_DIR AND GLPK_LIBRARY)
ladanyi@685
    45
ladanyi@496
    46
INCLUDE(FindPackageHandleStandardArgs)
ladanyi@685
    47
FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLPK DEFAULT_MSG GLPK_LIBRARY GLPK_INCLUDE_DIR GLPK_PROPER_VERSION_FOUND)
ladanyi@496
    48
ladanyi@496
    49
IF(GLPK_FOUND)
ladanyi@666
    50
  SET(GLPK_INCLUDE_DIRS ${GLPK_INCLUDE_DIR})
ladanyi@496
    51
  SET(GLPK_LIBRARIES ${GLPK_LIBRARY})
ladanyi@496
    52
  SET(GLPK_BIN_DIR ${GLPK_ROOT_PATH}/bin)
ladanyi@496
    53
ENDIF(GLPK_FOUND)
ladanyi@496
    54
ladanyi@496
    55
MARK_AS_ADVANCED(GLPK_LIBRARY GLPK_INCLUDE_DIR GLPK_BIN_DIR)