set(GUROBI_ROOT_DIR "" CACHE PATH "GUROBI root directory.")

set(GUROBI_LIBRARY_POSSIBLE_NAMES libgurobi.so)
foreach(i RANGE 9 0 -1)
  list(APPEND GUROBI_LIBRARY_POSSIBLE_NAMES libgurobi7${i}.so)
endforeach(i)

MESSAGE(STATUS ${GUROBI_VERSION})
find_path(GUROBI_INCLUDE_DIR gurobi_c++.h HINTS "${GUROBI_ROOT_DIR}/include")
find_library(GUROBI_LIBRARY NAMES ${GUROBI_LIBRARY_POSSIBLE_NAMES} HINTS ${GUROBI_ROOT_DIR}/lib)
find_library(GUROBI_CPP_LIBRARY libgurobi_g++5.2.a HINTS ${GUROBI_ROOT_DIR}/lib)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GUROBI DEFAULT_MSG GUROBI_LIBRARY GUROBI_CPP_LIBRARY GUROBI_INCLUDE_DIR)

if(GUROBI_FOUND)
  add_library(GUROBI_C SHARED IMPORTED GLOBAL)
  set_property(TARGET GUROBI_C PROPERTY IMPORTED_LOCATION ${GUROBI_LIBRARY})
  add_library(GUROBI_CPP STATIC IMPORTED GLOBAL)
  set_property(TARGET GUROBI_CPP PROPERTY IMPORTED_LOCATION ${GUROBI_CPP_LIBRARY})

  add_library(GUROBI INTERFACE)
  target_link_libraries(GUROBI INTERFACE GUROBI_CPP GUROBI_C) # this order of gurobi libraries must be preserved
endif(GUROBI_FOUND)

mark_as_advanced(GUROBI_LIBRARY GUROBI_CPP_LIBRARY GUROBI_INCLUDE_DIR)
