|
| 1 | +#.rst: |
| 2 | +# FindIPOPT |
| 3 | +# --------- |
| 4 | +# |
| 5 | +# Try to locate the IPOPT library |
| 6 | +# |
| 7 | +# First tries to find the library in the standard search path. If this fails |
| 8 | +# it searches where the environmental varialbe IPOPT_DIR is pointing. |
| 9 | +# Set this to the folder in which you built IPOPT, e.g, in your ~/.bashrc: |
| 10 | +# |
| 11 | +# Result variables |
| 12 | +# ^^^^^^^^^^^^^^^^ |
| 13 | +# |
| 14 | +# Create the following variables:: |
| 15 | +# |
| 16 | +# IPOPT_INCLUDE_DIRS - Directories to include to use IPOPT |
| 17 | +# IPOPT_LIBRARIES - Default library to link against to use IPOPT |
| 18 | +# IPOPT_DEFINITIONS - Flags to be added to linker's options |
| 19 | +# IPOPT_LINK_FLAGS - Flags to be added to linker's options |
| 20 | +# IPOPT_FOUND - If false, don't try to use IPOPT |
| 21 | +# |
| 22 | +#============================================================================= |
| 23 | +# This find script is copied from https://github.com/robotology/idyntree. |
| 24 | +# Original copyright notice can be seen below: |
| 25 | +#============================================================================= |
| 26 | +# Copyright (C) 2008-2010 RobotCub Consortium |
| 27 | +# Copyright (C) 2016 iCub Facility - Istituto Italiano di Tecnologia |
| 28 | +# Authors: Ugo Pattacini <ugo.pattacini@iit.it> |
| 29 | +# Authors: Daniele E. Domenichelli <daniele.domenichelli@iit.it> |
| 30 | +# |
| 31 | +# Distributed under the OSI-approved BSD License (the "License"); |
| 32 | +# see accompanying file Copyright.txt for details. |
| 33 | +# |
| 34 | +# This software is distributed WITHOUT ANY WARRANTY; without even the |
| 35 | +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 36 | +# See the License for more information. |
| 37 | +#============================================================================= |
| 38 | +# (To distribute this file outside of YCM, substitute the full |
| 39 | +# License text for the above reference.) |
| 40 | + |
| 41 | +if(NOT WIN32) |
| 42 | + |
| 43 | + # First priority is finding the package using IPOPT_DIR if set |
| 44 | + if(DEFINED ENV{IPOPT_DIR}) |
| 45 | + set(IPOPT_DIR $ENV{IPOPT_DIR} CACHE PATH "Path to IPOPT build directory") |
| 46 | + |
| 47 | + set(IPOPT_INCLUDE_DIRS ${IPOPT_DIR}/include/coin) |
| 48 | + find_library(IPOPT_LIBRARIES ipopt ${IPOPT_DIR}/lib |
| 49 | + ${IPOPT_DIR}/lib/coin |
| 50 | + NO_DEFAULT_PATH) |
| 51 | + |
| 52 | + if(IPOPT_LIBRARIES) |
| 53 | + find_file(IPOPT_DEP_FILE ipopt_addlibs_cpp.txt ${IPOPT_DIR}/share/doc/coin/Ipopt |
| 54 | + ${IPOPT_DIR}/share/coin/doc/Ipopt |
| 55 | + NO_DEFAULT_PATH) |
| 56 | + mark_as_advanced(IPOPT_DEP_FILE) |
| 57 | + |
| 58 | + if(IPOPT_DEP_FILE) |
| 59 | + # parse the file and acquire the dependencies |
| 60 | + file(READ ${IPOPT_DEP_FILE} IPOPT_DEP) |
| 61 | + string(REGEX REPLACE "-[^l][^ ]* " "" IPOPT_DEP ${IPOPT_DEP}) |
| 62 | + string(REPLACE "-l" "" IPOPT_DEP ${IPOPT_DEP}) |
| 63 | + string(REPLACE "\n" "" IPOPT_DEP ${IPOPT_DEP}) |
| 64 | + string(REPLACE "ipopt" "" IPOPT_DEP ${IPOPT_DEP}) # remove any possible auto-dependency |
| 65 | + separate_arguments(IPOPT_DEP) |
| 66 | + |
| 67 | + # use the find_library command in order to prepare rpath correctly |
| 68 | + foreach(LIB ${IPOPT_DEP}) |
| 69 | + find_library(IPOPT_SEARCH_FOR_${LIB} ${LIB} ${IPOPT_DIR}/lib |
| 70 | + ${IPOPT_DIR}/lib/coin |
| 71 | + ${IPOPT_DIR}/lib/coin/ThirdParty |
| 72 | + NO_DEFAULT_PATH) |
| 73 | + if(IPOPT_SEARCH_FOR_${LIB}) |
| 74 | + # handle non-system libraries (e.g. coinblas) |
| 75 | + set(IPOPT_LIBRARIES ${IPOPT_LIBRARIES} ${IPOPT_SEARCH_FOR_${LIB}}) |
| 76 | + else() |
| 77 | + # handle system libraries (e.g. gfortran) |
| 78 | + set(IPOPT_LIBRARIES ${IPOPT_LIBRARIES} ${LIB}) |
| 79 | + endif() |
| 80 | + mark_as_advanced(IPOPT_SEARCH_FOR_${LIB}) |
| 81 | + endforeach() |
| 82 | + endif() |
| 83 | + endif() |
| 84 | + |
| 85 | + set(IPOPT_DEFINITIONS "") |
| 86 | + |
| 87 | + |
| 88 | + # if IPOPT_DIR not set, try finding IPOPT through package manager |
| 89 | + else() |
| 90 | + find_package(PkgConfig QUIET) |
| 91 | + if(PKG_CONFIG_FOUND) |
| 92 | + |
| 93 | + if(IPOPT_FIND_VERSION) |
| 94 | + if(IPOPT_FIND_VERSION_EXACT) |
| 95 | + pkg_check_modules(_PC_IPOPT QUIET ipopt=${IPOPT_FIND_VERSION}) |
| 96 | + else() |
| 97 | + pkg_check_modules(_PC_IPOPT QUIET ipopt>=${IPOPT_FIND_VERSION}) |
| 98 | + endif() |
| 99 | + else() |
| 100 | + pkg_check_modules(_PC_IPOPT QUIET ipopt) |
| 101 | + endif() |
| 102 | + |
| 103 | + |
| 104 | + if(_PC_IPOPT_FOUND) |
| 105 | + set(IPOPT_INCLUDE_DIRS ${_PC_IPOPT_INCLUDE_DIRS} CACHE PATH "IPOPT include directory") |
| 106 | + set(IPOPT_DEFINITIONS ${_PC_IPOPT_CFLAGS_OTHER} CACHE STRING "Additional compiler flags for IPOPT") |
| 107 | + set(IPOPT_LIBRARIES "" CACHE STRING "IPOPT libraries" FORCE) |
| 108 | + foreach(_LIBRARY IN ITEMS ${_PC_IPOPT_LIBRARIES}) |
| 109 | + find_library(${_LIBRARY}_PATH |
| 110 | + NAMES ${_LIBRARY} |
| 111 | + PATHS ${_PC_IPOPT_LIBRARY_DIRS}) |
| 112 | + # Workaround for https://github.com/robotology/icub-main/issues/418 |
| 113 | + if(${_LIBRARY}_PATH) |
| 114 | + list(APPEND IPOPT_LIBRARIES ${${_LIBRARY}_PATH}) |
| 115 | + endif() |
| 116 | + endforeach() |
| 117 | + else() |
| 118 | + set(IPOPT_DEFINITIONS "") |
| 119 | + endif() |
| 120 | + endif() |
| 121 | + endif() |
| 122 | + |
| 123 | + set(IPOPT_LINK_FLAGS "") |
| 124 | + |
| 125 | +# Windows platforms |
| 126 | +else() |
| 127 | + include(SelectLibraryConfigurations) |
| 128 | + |
| 129 | + set(IPOPT_DIR $ENV{IPOPT_DIR} CACHE PATH "Path to IPOPT build directory") |
| 130 | + |
| 131 | + set(IPOPT_INCLUDE_DIRS ${IPOPT_DIR}/include/coin) |
| 132 | + find_library(IPOPT_IPOPT_LIBRARY_RELEASE libipopt ${IPOPT_DIR}/lib |
| 133 | + ${IPOPT_DIR}/lib/coin |
| 134 | + NO_DEFAULT_PATH) |
| 135 | + find_library(IPOPT_IPOPT_LIBRARY_DEBUG libipoptD ${IPOPT_DIR}/lib |
| 136 | + ${IPOPT_DIR}/lib/coin |
| 137 | + NO_DEFAULT_PATH) |
| 138 | + |
| 139 | + select_library_configurations(IPOPT_IPOPT) |
| 140 | + set(IPOPT_LIBRARIES ${IPOPT_IPOPT_LIBRARY}) |
| 141 | + |
| 142 | + # Some old version of binary releases of IPOPT have Intel fortran |
| 143 | + # libraries embedded in the library, newer releases require them to |
| 144 | + # be explicitly linked. |
| 145 | + if(IPOPT_IPOPT_LIBRARY) |
| 146 | + get_filename_component(_MSVC_DIR "${CMAKE_LINKER}" DIRECTORY) |
| 147 | + |
| 148 | + # Find the lib.exe executable |
| 149 | + find_program(LIB_EXECUTABLE |
| 150 | + NAMES lib.exe |
| 151 | + HINTS "${_MSVC_BINDIR}" |
| 152 | + "C:/Program Files/Microsoft Visual Studio 10.0/VC/bin" |
| 153 | + "C:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/bin" |
| 154 | + "C:/Program Files/Microsoft Visual Studio 11.0/VC/bin" |
| 155 | + "C:/Program Files (x86)/Microsoft Visual Studio 11.0/VC/bin" |
| 156 | + "C:/Program Files/Microsoft Visual Studio 12.0/VC/bin" |
| 157 | + "C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin" |
| 158 | + "C:/Program Files/Microsoft Visual Studio 14.0/VC/bin" |
| 159 | + "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin" |
| 160 | + DOC "Path to the lib.exe executable") |
| 161 | + mark_as_advanced(LIB_EXECUTABLE) |
| 162 | + |
| 163 | + # backup PATH environment variable |
| 164 | + set(_path $ENV{PATH}) |
| 165 | + |
| 166 | + # Add th MSVC "Common7/IDE" dir containing the dlls in the PATH when needed. |
| 167 | + get_filename_component(_MSVC_LIBDIR "${_MSVC_BINDIR}/../../Common7/IDE" ABSOLUTE) |
| 168 | + if(NOT EXISTS "${_MSVC_LIBDIR}") |
| 169 | + get_filename_component(_MSVC_LIBDIR "${_MSVC_BINDIR}/../../../Common7/IDE" ABSOLUTE) |
| 170 | + endif() |
| 171 | + |
| 172 | + if(EXISTS "${_MSVC_LIBDIR}") |
| 173 | + set(_MSVC_LIBDIR_FOUND 0) |
| 174 | + file(TO_CMAKE_PATH "$ENV{PATH}" _env_path) |
| 175 | + foreach(_dir ${_env_path}) |
| 176 | + if("${_dir}" STREQUAL ${_MSVC_LIBDIR}) |
| 177 | + set(_MSVC_LIBDIR_FOUND 1) |
| 178 | + endif() |
| 179 | + endforeach() |
| 180 | + if(NOT _MSVC_LIBDIR_FOUND) |
| 181 | + file(TO_NATIVE_PATH "${_MSVC_LIBDIR}" _MSVC_LIBDIR) |
| 182 | + set(ENV{PATH} "$ENV{PATH};${_MSVC_LIBDIR}") |
| 183 | + endif() |
| 184 | + endif() |
| 185 | + |
| 186 | + if(IPOPT_IPOPT_LIBRARY_RELEASE) |
| 187 | + set(_IPOPT_LIB ${IPOPT_IPOPT_LIBRARY_RELEASE}) |
| 188 | + else() |
| 189 | + set(_IPOPT_LIB ${IPOPT_IPOPT_LIBRARY_DEBUG}) |
| 190 | + endif() |
| 191 | + |
| 192 | + execute_process(COMMAND ${LIB_EXECUTABLE} /list "${_IPOPT_LIB}" |
| 193 | + OUTPUT_VARIABLE _lib_output) |
| 194 | + |
| 195 | + set(ENV{PATH} "${_path}") |
| 196 | + unset(_path) |
| 197 | + |
| 198 | + if(NOT "${_lib_output}" MATCHES "libifcoremd.dll") |
| 199 | + get_filename_component(_IPOPT_IPOPT_LIBRARY_DIR "${_IPOPT_LIB}" DIRECTORY) |
| 200 | + |
| 201 | + foreach(_lib ifconsol |
| 202 | + libifcoremd |
| 203 | + libifportmd |
| 204 | + libmmd |
| 205 | + libirc |
| 206 | + svml_dispmd) |
| 207 | + string(TOUPPER "${_lib}" _LIB) |
| 208 | + find_library(IPOPT_${_LIB}_LIBRARY_RELEASE ${_lib} ${_IPOPT_IPOPT_LIBRARY_DIR}) |
| 209 | + find_library(IPOPT_${_LIB}_LIBRARY_DEBUG ${_lib}d ${_IPOPT_IPOPT_LIBRARY_DIR}) |
| 210 | + select_library_configurations(IPOPT_${_LIB}) |
| 211 | + list(APPEND IPOPT_LIBRARIES ${IPOPT_${_LIB}_LIBRARY}) |
| 212 | + endforeach() |
| 213 | + endif() |
| 214 | + endif() |
| 215 | + |
| 216 | + set(IPOPT_DEFINITIONS "") |
| 217 | + if(MSVC) |
| 218 | + set(IPOPT_LINK_FLAGS "/NODEFAULTLIB:libcmt.lib;libcmtd.lib") |
| 219 | + else() |
| 220 | + set(IPOPT_LINK_FLAGS "") |
| 221 | + endif() |
| 222 | + |
| 223 | +endif() |
| 224 | + |
| 225 | +mark_as_advanced(IPOPT_INCLUDE_DIRS |
| 226 | + IPOPT_LIBRARIES |
| 227 | + IPOPT_DEFINITIONS |
| 228 | + IPOPT_LINK_FLAGS) |
| 229 | + |
| 230 | +include(FindPackageHandleStandardArgs) |
| 231 | +find_package_handle_standard_args(IPOPT DEFAULT_MSG IPOPT_LIBRARIES) |
0 commit comments