Commit 2679675f authored by Martin Heistermann's avatar Martin Heistermann
Browse files

CMake: rewrite gurobi finder:

- find any version of GUROBI based on the GUROBI_HOME env var (suggested
by Gurobi docs).
- compile C++ library ourselves to avoid toolchain/ABI mismatches
parent d24eed09
Pipeline #12047 passed with stages
in 12 minutes and 14 seconds
# - Try to find GUROBI
# GUROBI_BASE - The libraries needed to use Gurobi
# Once done this will define # Once done this will define
# GUROBI_FOUND - System has Gurobi # GUROBI_FOUND - System has Gurobi
# GUROBI_INCLUDE_DIRS - The Gurobi include directories # GUROBI_INCLUDE_DIRS - The Gurobi include directories
# GUROBI_LIBRARIES - The libraries needed to use Gurobi # GUROBI_LIBRARIES - The libraries needed to use Gurobi
set (GUROBI_ENABLE OFF CACHE BOOL "Enable gurobi?") set(GUROBI_ENABLE OFF CACHE BOOL "Enable gurobi?")
if ( GUROBI_ENABLE ) if (GUROBI_ENABLE)
set (GUROBI_BASE "c:" CACHE PATH "Base path of your gurobi installation")
if (GUROBI_INCLUDE_DIR) set(GUROBI_BASE $ENV{GUROBI_HOME} CACHE PATH "GUROBI root directory.")
# in cache already
set(GUROBI_FOUND TRUE)
set(GUROBI_INCLUDE_DIRS "${GUROBI_INCLUDE_DIR}" )
set(GUROBI_LIBRARIES "${GUROBI_CXX_LIBRARY};${GUROBI_LIBRARY}" )
else (GUROBI_INCLUDE_DIR)
find_path(GUROBI_INCLUDE_DIR
find_path(GUROBI_INCLUDE_DIR
NAMES gurobi_c++.h NAMES gurobi_c++.h
PATHS "$ENV{GUROBI_HOME}/include" PATHS
"/Library/gurobi502/mac64/include" "${GUROBI_BASE}/include"
"/Library/gurobi562/mac64/include" "$ENV{GUROBI_HOME}/include"
"C:\\libs\\gurobi502\\include"
"C:\\libs\\gurobi562\\include"
"${GUROBI_BASE}/include"
) )
find_library( GUROBI_LIBRARY get_filename_component(GUROBI_LIB_DIR "${GUROBI_INCLUDE_DIR}/../lib" ABSOLUTE)
NAMES gurobi # GUROBI_BIN_DIR is needed on windows, where it contains the .dll
gurobi60 get_filename_component(GUROBI_BIN_DIR "${GUROBI_INCLUDE_DIR}/../bin" ABSOLUTE)
gurobi56 get_filename_component(GUROBI_SRC_DIR "${GUROBI_INCLUDE_DIR}/../src" ABSOLUTE)
gurobi55
gurobi51
gurobi50 file(GLOB GUROBI_LIBRARY_LIST
gurobi46 RELATIVE ${GUROBI_LIB_DIR}
gurobi45 ${GUROBI_LIB_DIR}/libgurobi*.so
${GUROBI_LIB_DIR}/libgurobi*.dll)
PATHS "$ENV{GUROBI_HOME}/lib"
"/Library/gurobi562/mac64/lib"
"/Library/gurobi502/mac64/lib" # Ignore libgurobiXY_light.so, libgurobi.so (without version):
"C:\\libs\\gurobi562\\lib" string(REGEX MATCHALL
"C:\\libs\\gurobi502\\lib" "libgurobi([0-9]+)\\..*"
"${GUROBI_BASE}/lib" GUROBI_LIBRARY_LIST
) "${GUROBI_LIBRARY_LIST}"
)
string(REGEX REPLACE
"libgurobi([0-9]+)\\..*"
"\\1"
GUROBI_LIBRARY_VERSIONS
"${GUROBI_LIBRARY_LIST}")
list(LENGTH GUROBI_LIBRARY_VERSIONS GUROBI_NUMVER)
#message("GUROBI LIB VERSIONS: ${GUROBI_LIBRARY_VERSIONS}")
if (GUROBI_NUMVER EQUAL 1)
list(GET GUROBI_LIBRARY_VERSIONS 0 GUROBI_LIBRARY_VERSION)
set(GUROBI_LIBRARY_NAME "gurobi${GUROBI_LIBRARY_VERSION}")
else()
# none or more than one versioned library -let's try without suffix,
# maybe the user added a symlink to the desired library
set(GUROBI_LIBRARY_NAME "gurobi")
endif()
#message("GUROBI LIB NAME: ${GUROBI_LIBRARY_NAME}")
find_library(GUROBI_LIBRARY
NAMES ${GUROBI_LIBRARY_NAME}
PATHS
"${GUROBI_BASE}/lib"
"$ENV{GUROBI_HOME}/lib"
)
# Gurobi ships with some compiled versions of its C++ library for specific
# compilers, however it also comes with the source code. We will compile
# the source code outselves -- this is much safer, as it guarantees the same
# compiler version and flags.
# (Note: doing this is motivated by actual sometimes-subtle ABI compatibility bugs)
# The old behaviour can be enabled with GUROBI_USE_PRECOMPILED_CXX)
option(GUROBI_USE_PRECOMPILED_CXX "Use precompiled C++ libraries instead of building it ourselves. Not recommended." OFF)
mark_as_advanced(GUROBI_USE_PRECOMPILED_CXX)
if(GUROBI_USE_PRECOMPILED_CXX)
if ( CMAKE_GENERATOR MATCHES "^Visual Studio 12.*Win64" ) if ( CMAKE_GENERATOR MATCHES "^Visual Studio 12.*Win64" )
SET(GUROBI_LIB_NAME "gurobi_c++md2013") SET(GUROBI_LIB_NAME "gurobi_c++md2013")
endif() endif()
find_library( GUROBI_CXX_LIBRARY find_library(GUROBI_CXX_LIBRARY
NAMES gurobi_c++ NAMES gurobi_c++
${GUROBI_LIB_NAME} ${GUROBI_LIB_NAME}
PATHS "$ENV{GUROBI_HOME}/lib" PATHS "$ENV{GUROBI_HOME}/lib"
"/Library/gurobi562/mac64/lib" "${GUROBI_BASE}/lib"
"/Library/gurobi502/mac64/lib" )
"C:\\libs\\gurobi562\\lib" else()
"C:\\libs\\gurobi502\\lib" file(GLOB GUROBI_CXX_SRC CONFIGURE_DEPENDS ${GUROBI_SRC_DIR}/cpp/*.cpp)
"${GUROBI_BASE}/lib" if(NOT GUROBI_CXX_SRC)
) message(FATAL_ERROR "could not find gurobi c++ sources in GUROBI_SRC_DIR=${GUROBI_SRC_DIR}/cpp/.")
endif()
# Binary dir for DLLs add_library(GurobiCXX STATIC ${GUROBI_CXX_SRC})
find_path(GUROBI_BIN_DIR target_include_directories(GurobiCXX PUBLIC ${GUROBI_INCLUDE_DIR})
NAMES "gurobi60.dll" # We need to be able to link this into a shared library:
PATHS "${GUROBI_INCLUDE_DIR}/../bin" set_target_properties(GurobiCXX PROPERTIES POSITION_INDEPENDENT_CODE ON)
"${GUROBI_BASE}/bin" set(GUROBI_CXX_LIBRARY $<TARGET_FILE:GurobiCXX>)
DOC "Directory containing the GUROBI DLLs" endif(GUROBI_USE_PRECOMPILED_CXX)
)
set(GUROBI_INCLUDE_DIRS "${GUROBI_INCLUDE_DIR}" ) set(GUROBI_INCLUDE_DIRS "${GUROBI_INCLUDE_DIR}" )
set(GUROBI_LIBRARIES "${GUROBI_CXX_LIBRARY};${GUROBI_LIBRARY}" ) set(GUROBI_LIBRARIES "${GUROBI_CXX_LIBRARY};${GUROBI_LIBRARY}" )
...@@ -79,13 +102,10 @@ set(GUROBI_LIBRARIES "${GUROBI_CXX_LIBRARY};${GUROBI_LIBRARY}" ) ...@@ -79,13 +102,10 @@ set(GUROBI_LIBRARIES "${GUROBI_CXX_LIBRARY};${GUROBI_LIBRARY}" )
# set(GUROBI_COMPILER_FLAGS "-DIL_STD" CACHE STRING "Gurobi Compiler Flags") # set(GUROBI_COMPILER_FLAGS "-DIL_STD" CACHE STRING "Gurobi Compiler Flags")
include(FindPackageHandleStandardArgs) include(FindPackageHandleStandardArgs)
# handle the QUIETLY and REQUIRED arguments and set LIBCPLEX_FOUND to TRUE
# if all listed variables are TRUE
find_package_handle_standard_args(GUROBI DEFAULT_MSG find_package_handle_standard_args(GUROBI DEFAULT_MSG
GUROBI_CXX_LIBRARY GUROBI_LIBRARY GUROBI_INCLUDE_DIR) GUROBI_CXX_LIBRARY GUROBI_LIBRARY GUROBI_INCLUDE_DIR)
mark_as_advanced(GUROBI_INCLUDE_DIR GUROBI_LIBRARY GUROBI_CXX_LIBRARY GUROBI_BIN_DIR ) mark_as_advanced(GUROBI_INCLUDE_DIR GUROBI_LIBRARY GUROBI_CXX_LIBRARY GUROBI_BIN_DIR )
endif(GUROBI_INCLUDE_DIR) endif(GUROBI_ENABLE)
endif()
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment