From f7adf54be3262c9e803311d3ded638c660b2fe9f Mon Sep 17 00:00:00 2001 From: PBerger Date: Sun, 1 Feb 2015 03:30:01 +0100 Subject: [PATCH] Added A FindGurobi file for CMake. Adapted build process to use the new file to support all version of the library (upgrading to 6.0 breaks everything). Former-commit-id: 820ad029683d00dc67c335c370bf1729d6eb0bef --- CMakeLists.txt | 16 +++++--- resources/cmake/FindGurobi.cmake | 66 ++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 6 deletions(-) create mode 100644 resources/cmake/FindGurobi.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a7c1758c..f67e8ad19 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,6 +57,7 @@ set(TBB_INSTALL_DIR "${PROJECT_SOURCE_DIR}/resources/3rdparty/tbb42_20140122_mer find_package(Boost REQUIRED) find_package(Doxygen REQUIRED) +find_package(Gurobi) find_package(TBB) find_package(Threads REQUIRED) find_package(GMP) @@ -69,7 +70,7 @@ else() endif() message(STATUS "StoRM - Building ${CMAKE_BUILD_TYPE} version.") -if ("${GUROBI_ROOT}" STREQUAL "") +if ("${GUROBI_ROOT}" STREQUAL "" AND NOT GUROBI_FOUND) set(ENABLE_GUROBI OFF) else() set(ENABLE_GUROBI ON) @@ -330,7 +331,10 @@ endif(ADDITIONAL_LINK_DIRS) ## ############################################################# if (ENABLE_GUROBI) - link_directories("${GUROBI_ROOT}/lib") + if (NOT GUROBI_FOUND) + message(FATAL_ERROR "Gurobi was requested, but not found!") + endif() + #link_directories("${GUROBI_ROOT}/lib") endif() if (ENABLE_Z3) link_directories("${Z3_ROOT}/bin") @@ -413,10 +417,10 @@ target_link_libraries(storm ltl2dstar) ############################################################# if (ENABLE_GUROBI) message (STATUS "StoRM - Linking with Gurobi") - include_directories("${GUROBI_ROOT}/include") - target_link_libraries(storm "gurobi56") - target_link_libraries(storm-functional-tests "gurobi56") - target_link_libraries(storm-performance-tests "gurobi56") + include_directories(GUROBI_INCLUDE_DIRS) + target_link_libraries(storm GUROBI_LIBRARY) + target_link_libraries(storm-functional-tests GUROBI_LIBRARY) + target_link_libraries(storm-performance-tests GUROBI_LIBRARY) endif(ENABLE_GUROBI) ############################################################# diff --git a/resources/cmake/FindGurobi.cmake b/resources/cmake/FindGurobi.cmake new file mode 100644 index 000000000..93de74af7 --- /dev/null +++ b/resources/cmake/FindGurobi.cmake @@ -0,0 +1,66 @@ +#### Taken from http://www.openflipper.org/svnrepo/CoMISo/trunk/CoMISo/cmake/FindGUROBI.cmake + + +# - Try to find GUROBI +# Once done this will define +# GUROBI_FOUND - System has Gurobi +# GUROBI_INCLUDE_DIRS - The Gurobi include directories +# GUROBI_LIBRARIES - The libraries needed to use Gurobi + +if (GUROBI_INCLUDE_DIR) + # in cache already + set(GUROBI_FOUND TRUE) + set(GUROBI_INCLUDE_DIRS "${GUROBI_INCLUDE_DIR}" ) + set(GUROBI_LIBRARIES "${GUROBI_LIBRARY};${GUROBI_CXX_LIBRARY}" ) +else (GUROBI_INCLUDE_DIR) + +find_path(GUROBI_INCLUDE_DIR + NAMES gurobi_c++.h + PATHS "$ENV{GUROBI_HOME}/include" + "/Library/gurobi502/mac64/include" + "C:\\libs\\gurobi502\\include" + "C:\\gurobi600\\win64\\include" + "${GUROBI_ROOT}/include" + ) + +find_library( GUROBI_LIBRARY + NAMES gurobi + gurobi45 + gurobi46 + gurobi50 + gurobi51 + gurobi52 + gurobi55 + gurobi56 + gurobi60 + PATHS "$ENV{GUROBI_HOME}/lib" + "/Library/gurobi502/mac64/lib" + "C:\\libs\\gurobi502\\lib" + "C:\\gurobi600\\win64\\lib" + "${GUROBI_ROOT}/lib" + ) + +find_library( GUROBI_CXX_LIBRARY + NAMES gurobi_c++ + PATHS "$ENV{GUROBI_HOME}/lib" + "/Library/gurobi502/mac64/lib" + "C:\\libs\\gurobi502\\lib" + "C:\\gurobi600\\win64\\lib" + "${GUROBI_ROOT}/lib" + ) + +set(GUROBI_INCLUDE_DIRS "${GUROBI_INCLUDE_DIR}" ) +set(GUROBI_LIBRARIES "${GUROBI_LIBRARY};${GUROBI_CXX_LIBRARY}" ) + +# use c++ headers as default +# set(GUROBI_COMPILER_FLAGS "-DIL_STD" CACHE STRING "Gurobi Compiler Flags") + +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 + GUROBI_LIBRARY GUROBI_CXX_LIBRARY GUROBI_INCLUDE_DIR) + +mark_as_advanced(GUROBI_INCLUDE_DIR GUROBI_LIBRARY GUROBI_CXX_LIBRARY) + +endif(GUROBI_INCLUDE_DIR) \ No newline at end of file