FindIPOPT.cmake 4.74 KB
Newer Older
David Bommes's avatar
changed  
David Bommes committed
1 2 3 4 5 6 7 8
# - Try to find IPOPT
# Once done this will define
#  IPOPT_FOUND - System has IpOpt
#  IPOPT_INCLUDE_DIRS - The IpOpt include directories
#  IPOPT_LIBRARY_DIRS - The library directories needed to use IpOpt
#  IPOPT_LIBRARIES    - The libraries needed to use IpOpt


9 10 11 12 13 14
if (IPOPT_INCLUDE_DIR)
  # in cache already
  SET(IPOPT_FIND_QUIETLY TRUE)
endif (IPOPT_INCLUDE_DIR)

if (WIN32)
Jan Möbius's avatar
Jan Möbius committed
15 16 17 18 19 20 21

  if ( CMAKE_GENERATOR MATCHES ".*Win64" )
    SET( DIRSUFFIX "lib64" )
  else ()
    SET( DIRSUFFIX "lib" )
  endif()

Jan Möbius's avatar
Jan Möbius committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
  # Check if the base path is set
  if ( NOT CMAKE_WINDOWS_LIBS_DIR )
    # This is the base directory for windows library search used in the finders we shipp.
    set(CMAKE_WINDOWS_LIBS_DIR "c:/libs" CACHE STRING "Default Library search dir on windows." )
  endif()

  if ( CMAKE_GENERATOR MATCHES "^Visual Studio 11.*Win64" )
    SET(VS_SEARCH_PATH "${CMAKE_WINDOWS_LIBS_DIR}/vs2012/x64/")
  elseif ( CMAKE_GENERATOR MATCHES "^Visual Studio 11.*" )
    SET(VS_SEARCH_PATH "${CMAKE_WINDOWS_LIBS_DIR}/vs2012/x32/")
  elseif ( CMAKE_GENERATOR MATCHES "^Visual Studio 12.*Win64" )
    SET(VS_SEARCH_PATH "${CMAKE_WINDOWS_LIBS_DIR}/vs2013/x64/")
  elseif ( CMAKE_GENERATOR MATCHES "^Visual Studio 12.*" )
    SET(VS_SEARCH_PATH "${CMAKE_WINDOWS_LIBS_DIR}/vs2013/x32/")
  elseif ( CMAKE_GENERATOR MATCHES "^Visual Studio 14.*Win64" )
    SET(VS_SEARCH_PATH "${CMAKE_WINDOWS_LIBS_DIR}/vs2015/x64/")
  elseif ( CMAKE_GENERATOR MATCHES "^Visual Studio 14.*" )
    SET(VS_SEARCH_PATH "${CMAKE_WINDOWS_LIBS_DIR}/vs2015/x32/")
  endif()
Jan Möbius's avatar
Jan Möbius committed
41
  
Jan Möbius's avatar
Jan Möbius committed
42
   find_path(IPOPT_INCLUDE_DIR NAMES IpNLP.hpp
43
     PATHS
Jan Möbius's avatar
Jan Möbius committed
44
	 "${VS_SEARCH_PATH}Ipopt-3.12.4/Ipopt/MSVisualStudio/v8-ifort/installed/include/coin"
Jan Möbius's avatar
Jan Möbius committed
45
	 "${VS_SEARCH_PATH}Ipopt-3.11.9/Ipopt/MSVisualStudio/v8-ifort/installed/include/coin"
Jan Möbius's avatar
Jan Möbius committed
46
     "C:\\libs\\Ipopt-3.8.2\\include\\coin"
47 48 49
     ${IPOPT_DIR}/include
   )

50 51
   IF(IPOPT_INCLUDE_DIR)
      find_library( IPOPT_LIBRARY_RELEASE 
Jan Möbius's avatar
Jan Möbius committed
52 53
                    Ipopt ipopt libipopt IpOpt-vc10
                    PATHS "C:\\libs\\Ipopt-3.8.2\\lib\\win32\\release" 
Jan Möbius's avatar
Jan Möbius committed
54 55
			  "${VS_SEARCH_PATH}Ipopt-3.12.4/Ipopt/MSVisualStudio/v8-ifort/installed/lib"
			  "${VS_SEARCH_PATH}Ipopt-3.11.9/Ipopt/MSVisualStudio/v8-ifort/installed/lib"
Jan Möbius's avatar
Jan Möbius committed
56
				   )
57
      find_library( IPOPT_LIBRARY_DEBUG
Jan Möbius's avatar
Jan Möbius committed
58
                    Ipopt ipoptd libipoptd IpOpt-vc10d
Jan Möbius's avatar
Jan Möbius committed
59
                    PATHS "C:\\libs\\Ipopt-3.8.2\\lib\\win32\\debug" 
Jan Möbius's avatar
Jan Möbius committed
60
			  "${VS_SEARCH_PATH}Ipopt-3.12.4/Ipopt/MSVisualStudio/v8-ifort/installed/lib"
Jan Möbius's avatar
Jan Möbius committed
61 62
			  "${VS_SEARCH_PATH}Ipopt-3.11.9/Ipopt/MSVisualStudio/v8-ifort/installed/lib"
		   )
63

64
      set ( IPOPT_LIBRARY "optimized;${IPOPT_LIBRARY_RELEASE};debug;${IPOPT_LIBRARY_DEBUG}" CACHE  STRING "IPOPT Libraries" )
Jan Möbius's avatar
Jan Möbius committed
65 66 67
	  
	  GET_FILENAME_COMPONENT(IPOPT_LIBRARY_DIR ${IPOPT_LIBRARY_RELEASE} PATH )
	  MARK_AS_ADVANCED(IPOPT_LIBRARY_DIR)
68

Jan Möbius's avatar
Jan Möbius committed
69 70 71 72 73 74 75 76 77
      SET(IPOPT_FOUND TRUE)
      SET(IPOPT_INCLUDE_DIR ${IPOPT_INCLUDE_DIR})
	  # Todo, set right version depending on build type (debug/release)
	  #GET_FILENAME_COMPONENT( IPOPT_LIBRARY_DIR ${GLEW_LIBRARY} PATH )
    ELSE(IPOPT_INCLUDE_DIR)
      SET(IPOPT_FOUND FALSE)
      SET(IPOPT_INCLUDE_DIR ${IPOPT_INCLUDE_DIR})
    ENDIF(IPOPT_INCLUDE_DIR)

78 79
ELSE( WIN32 )
   find_path(IPOPT_INCLUDE_DIR NAMES IpNLP.hpp
David Bommes's avatar
changed  
David Bommes committed
80 81 82
     PATHS  "$ENV{IPOPT_HOME}/include/coin"
            "/usr/include/coin"
    
83 84 85 86
   )

   find_library( IPOPT_LIBRARY 
                 ipopt
David Bommes's avatar
changed  
David Bommes committed
87 88 89 90 91 92
                 PATHS "$ENV{IPOPT_HOME}/lib"
                       "/usr/lib" )   
    
    #wrong config under Debian workaround
    add_definitions( -DHAVE_CSTDDEF )

93
   
94
   # set optional path to HSL Solver for dynamic usage
David Bommes's avatar
David Bommes committed
95 96 97 98 99
   find_path(IPOPT_HSL_LIBRARY_DIR 
             NAMES libhsl.so
                   libhsl.dylib
             PATHS "$ENV{IPOPT_HSL_LIBRARY_PATH}"
                   "$ENV{HOME}/opt/HSL/lib"
100
   )
101 102 103 104 105 106 107

   # find HSL library for fixed linking of solvers   
   find_library( IPOPT_HSL_LIBRARY 
                 coinhsl
                 PATHS "$ENV{IPOPT_HOME}/lib"
                       "/usr/lib" )   
   
108
   
David Bommes's avatar
David Bommes committed
109
   IF( IPOPT_HSL_LIBRARY_DIR)
Jan Möbius's avatar
Jan Möbius committed
110 111 112
     IF( NOT IPOPT_FIND_QUIETLY )
        message ( "IPOPT_HSL_LIBRARY_DIR found at ${IPOPT_HSL_LIBRARY_DIR} ")
     ENDIF()
113
     set(IPOPT_LIBRARY_DIR ${IPOPT_HSL_LIBRARY_DIR})
Jan Möbius's avatar
Jan Möbius committed
114
     LIST( APPEND IPOPT_LIBRARY_DIRS "${IPOPT_HSL_LIBRARY_DIR}")
115
   ENDIF(IPOPT_HSL_LIBRARY_DIR)
David Bommes's avatar
changed  
David Bommes committed
116 117 118 119
   
   
   set(IPOPT_INCLUDE_DIRS "${IPOPT_INCLUDE_DIR}" )
   set(IPOPT_LIBRARIES "${IPOPT_LIBRARY}" )
120 121 122 123
   
   IF(IPOPT_HSL_LIBRARY)
     LIST( APPEND IPOPT_LIBRARIES "${IPOPT_HSL_LIBRARY}")   
   ENDIF(IPOPT_HSL_LIBRARY)
David Bommes's avatar
changed  
David Bommes committed
124 125

   include(FindPackageHandleStandardArgs)
126
   # handle the QUIETLY and REQUIRED arguments and set LIBIPOPT_FOUND to TRUE
David Bommes's avatar
changed  
David Bommes committed
127 128 129 130 131 132
   # if all listed variables are TRUE
   find_package_handle_standard_args(IPOPT  DEFAULT_MSG
                                     IPOPT_LIBRARY IPOPT_INCLUDE_DIR)

   mark_as_advanced(IPOPT_INCLUDE_DIR IPOPT_LIBRARY )
   
133
ENDIF()