From 70db1c1ff6aa7de8cea9ee96dd3769e25a3fe89a Mon Sep 17 00:00:00 2001 From: kyle Date: Fri, 22 Oct 2021 16:00:44 +0200 Subject: [PATCH] Fixed support and documentation for Cmake CPLEX build on Linux --- cmake/FindCPLEX.cmake | 34 ++++++++++++++++++++++------------ cmake/README.md | 16 ++++++++++++++++ 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/cmake/FindCPLEX.cmake b/cmake/FindCPLEX.cmake index 6f940f639d..f45fbcc23e 100644 --- a/cmake/FindCPLEX.cmake +++ b/cmake/FindCPLEX.cmake @@ -37,14 +37,12 @@ else() message(FATAL_ERROR "FindCPLEX only works if either C or CXX language is enabled") endif() -if(APPLE) - message(FATAL_ERROR "CPLEX not yet supported on macOS") -elseif(UNIX) - message(FATAL_ERROR "CPLEX not yet supported on Linux") -endif() - if(NOT CPLEX_ROOT) - set(CPLEX_ROOT $ENV{CPLEX_ROOT}) + if(DEFINED ENV{UNIX_CPLEX_DIR}) + set(CPLEX_ROOT $ENV{UNIX_CPLEX_DIR}) + elseif(DEFINED ENV{CPLEX_ROOT}) + set(CPLEX_ROOT $ENV{CPLEX_ROOT}) + endif() endif() message(STATUS "CPLEX_ROOT: ${CPLEX_ROOT}") if(NOT CPLEX_ROOT) @@ -53,12 +51,24 @@ else() set(CPLEX_FOUND TRUE) endif() +# TODO(mizux) Bump support to CPLEX 20.1.0 +# ref: https://www.ibm.com/docs/en/icos/20.1.0?topic=cplex-setting-up-gnulinuxmacos +# ref: https://www.ibm.com/docs/en/icos/20.1.0?topic=cplex-setting-up-windows + +# ref: https://www.ibm.com/docs/en/icos/12.10.0?topic=cplex-setting-up-gnulinuxmacos if(CPLEX_FOUND AND NOT TARGET CPLEX::CPLEX) add_library(CPLEX::CPLEX UNKNOWN IMPORTED) + target_include_directories(CPLEX::CPLEX SYSTEM INTERFACE "${CPLEX_ROOT}/cplex/include") - set_target_properties(CPLEX::CPLEX PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${CPLEX_INCLUDE_DIRS}") - - set_target_properties(CPLEX::CPLEX PROPERTIES - IMPORTED_LOCATION "${CPLEX_ROOT}/cplex/lib/x64_windows_msvc14/stat_mda/cplex12100.lib") + if(APPLE) # be aware that `UNIX` is `TRUE` on OS X, so this check must be first + # FIXME(mizux) need actual macOS library path + # target_link_libraries(CPLEX::CPLEX INTERFACE "${CPLEX_ROOT}/cplex/lib/libcplex.lib") + message(FATAL_ERROR "CPLEX not yet supported for CMake builds on ${CMAKE_SYSTEM}") + elseif(UNIX) + target_link_libraries(CPLEX::CPLEX INTERFACE "${CPLEX_ROOT}/cplex/lib/x86-64_linux/static_pic/libcplex.a") + elseif(MSVC) + target_link_libraries(CPLEX::CPLEX INTERFACE "${CPLEX_ROOT}/cplex/lib/x64_windows_msvc14/stat_mda/cplex12100.lib") + else() + message(FATAL_ERROR "CPLEX not supported for ${CMAKE_SYSTEM}") + endif() endif() diff --git a/cmake/README.md b/cmake/README.md index 3c050be034..aa946882f7 100644 --- a/cmake/README.md +++ b/cmake/README.md @@ -94,6 +94,22 @@ solvers: **warning: Since these solvers require license and are proprietary, we can't test it on public CI and support can be broken.** +### Enabling CPLEX Support + +To enable CPLEX support, configure with `-DUSE_CPLEX=ON` and `-DCPLEX_ROOT=/absolute/path/to/CPLEX/root/dir`, +replacing `/absolute/path/to/CPLEX/root/dir` with the path to your CPLEX installation. +`CPLEX_ROOT` can also be defined as an environment variable rather than an option at configure time. + +For ease of migration from legacy `make third_party` builds, CMake will also read the CPLEX installation path from the +`UNIX_CPLEX_DIR` environment variable, if defined. + +### Enabling XPRESS Support + +To enable XPRESS support, configure with `-DUSE_XPRESS=ON` and `-DXPRESS_ROOT=/absolute/path/to/XPRESS/root/dir`, +replacing `/absolute/path/to/XPRESS/root/dir` with the path to your XPRESS +installation. `XPRESS_ROOT` can also be defined as an environment variable rather than an option at configure time. + + ## CMake Options