Commit 679b112e authored by Martin Heistermann's avatar Martin Heistermann
Browse files

Add simple CI test, finders for GMM and Gurobi.

parent 6856ac85
.DS_Store
*.swp
/build*/
# image: debian:buster-20190812
test:
image: gitlab.inf.unibe.ch:5001/cgg/misc/buildbox-docker:master
tags:
- linux
before_script:
- apt-get install -y cmake libgmm++-dev
script:
- mkdir build
- cd build
- cmake ../CI
# This CMakeLists only does find_package to test our finders.
# We might want to enable some calls based on what is actually installed on the CI runner.
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
project(CMakeLibraryCITest)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../finders")
# find every package *twice* - this way we can see if it handles this robustly, e.g.
# not creating targets that already exist.
# First, find *without* REQUIRED - this way, we can get output from all finders, even if one fails.
find_package(GMM )
find_package(Gurobi )
# Then, repeat *with* REQUIRED:
find_package(GMM REQUIRED)
find_package(Gurobi REQUIRED)
set(GMM_DIR $ENV{GMM_DIR} CACHE PATH "GMM directory (contain gmm/gmm.h).")
find_path(GMM_INCLUDE_DIR
NAMES gmm/gmm.h
PATHS ${GMM_DIR}
${GMM_DIR}/include
/usr/local/include
/usr/include
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GMM DEFAULT_MSG GMM_INCLUDE_DIR)
if(GMM_FOUND AND NOT TARGET GMM::GMM)
add_library(GMM::GMM INTERFACE IMPORTED)
target_include_directories(GMM::GMM INTERFACE ${GMM_INCLUDE_DIR})
if(MSVC)
target_compile_definitions(GMM::GMM INTERFACE "_SCL_SECURE_NO_DEPRECATE")
endif()
endif()
mark_as_advanced(GMM_INCLUDE_DIR)
# Once done this will define
# GUROBI_FOUND - System has Gurobi
# Targets:
# Gurobi::GurobiC - only the C interface
# Gurobi::GurobiCXX - C and C++ interface
# Gurobi::Gurobi - same as GurobiCXX
find_path(GUROBI_HOME
NAMES include/gurobi_c++.h
PATHS
$ENV{GUROBI_HOME}
"/opt/gurobi/linux64/"
)
find_path(GUROBI_INCLUDE_DIR
NAMES gurobi_c++.h
HINTS
"${GUROBI_HOME}/include"
)
set(GUROBI_BIN_DIR "${GUROBI_HOME}/bin")
set(GUROBI_LIB_DIR "${GUROBI_HOME}/lib")
file(GLOB GUROBI_LIBRARY_LIST
RELATIVE ${GUROBI_LIB_DIR}
${GUROBI_LIB_DIR}/libgurobi*.so
${GUROBI_LIB_DIR}/gurobi*.lib
)
# Ignore libgurobiXY_light.so, libgurobi.so (without version):
string(REGEX MATCHALL
"gurobi([0-9]+)\\..*"
GUROBI_LIBRARY_LIST
"${GUROBI_LIBRARY_LIST}"
)
string(REGEX REPLACE
".*gurobi([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 0)
message(STATUS "Found no Gurobi library version in ${GUROBI_LIB_DIR}.")
elseif (GUROBI_NUMVER EQUAL 1)
list(GET GUROBI_LIBRARY_VERSIONS 0 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
message(STATUS "Found more than one Gurobi library version (${GUROBI_LIBRARY_VERSIONS}), trying without suffix. Set GUROBI_LIBRARY if you want to pick a certain one.")
set(GUROBI_LIBRARY_VERSION "")
endif()
find_library(GUROBI_LIBRARY
NAMES "gurobi${GUROBI_LIBRARY_VERSION}"
PATHS
${GUROBI_LIB_DIR}
)
# 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)
find_path(GUROBI_SRC_DIR NAMES "Model.h" PATHS "${GUROBI_HOME}/src/cpp/")
file(GLOB GUROBI_CXX_SRC CONFIGURE_DEPENDS ${GUROBI_SRC_DIR}/*.cpp)
if(NOT TARGET Gurobi::GurobiCXX)
if(GUROBI_CXX_SRC)
add_library(GurobiCXX STATIC EXCLUDE_FROM_ALL ${GUROBI_CXX_SRC})
add_library(Gurobi::GurobiCXX ALIAS GurobiCXX)
if(MSVC)
target_compile_definitions(GurobiCXX PRIVATE "WIN64")
endif()
target_include_directories(GurobiCXX PRIVATE ${GUROBI_INCLUDE_DIR})
# We need to be able to link this into a shared library:
set_target_properties(GurobiCXX PROPERTIES POSITION_INDEPENDENT_CODE ON)
set(GUROBI_CXX_LIBRARY $<TARGET_FILE:GurobiCXX>)
endif()
endif()
# legacy support:
set(GUROBI_INCLUDE_DIRS "${GUROBI_INCLUDE_DIR}" )
set(GUROBI_LIBRARIES "${GUROBI_CXX_LIBRARY};${GUROBI_LIBRARY}" )
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Gurobi DEFAULT_MSG
GUROBI_LIBRARY
GUROBI_INCLUDE_DIR
GUROBI_SRC_DIR
GUROBI_CXX_LIBRARY
)
mark_as_advanced(GUROBI_INCLUDE_DIR GUROBI_LIBRARY GUROBI_CXX_LIBRARY GUROBI_BIN_DIR GUROBI_SRC_DIR)
if(GUROBI_FOUND AND NOT TARGET Gurobi::Gurobi)
add_library(Gurobi::GurobiC INTERFACE IMPORTED)
target_include_directories(Gurobi::GurobiC INTERFACE ${GMM_INCLUDE_DIR})
target_link_libraries(Gurobi::GurobiC INTERFACE ${GUROBI_LIBRARY})
add_library(Gurobi::Gurobi INTERFACE IMPORTED)
target_link_libraries(Gurobi::Gurobi INTERFACE Gurobi::GurobiC)
target_link_libraries(Gurobi::Gurobi INTERFACE Gurobi::GurobiCXX)
endif()
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