FindIPOPT.cmake 5.43 KB
Newer Older
David Bommes's avatar
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
  # 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/")
40 41 42 43
  elseif ( CMAKE_GENERATOR MATCHES "^Visual Studio 15.*Win64" )
    SET(VS_SEARCH_PATH "${CMAKE_WINDOWS_LIBS_DIR}/vs2017/x64/")
  elseif ( CMAKE_GENERATOR MATCHES "^Visual Studio 15.*" )
    SET(VS_SEARCH_PATH "${CMAKE_WINDOWS_LIBS_DIR}/vs2017/x32/")
Jan Möbius's avatar
Jan Möbius committed
44
  endif()
Jan Möbius's avatar
Jan Möbius committed
45
  
Jan Möbius's avatar
Jan Möbius committed
46
   find_path(IPOPT_INCLUDE_DIR NAMES IpNLP.hpp
47
     PATHS
48
	 "${VS_SEARCH_PATH}Ipopt-3.12.9/include/coin"
Jan Möbius's avatar
Jan Möbius committed
49
	 "${VS_SEARCH_PATH}Ipopt-3.12.4/Ipopt/MSVisualStudio/v8-ifort/installed/include/coin"
Jan Möbius's avatar
Jan Möbius committed
50
	 "${VS_SEARCH_PATH}Ipopt-3.11.9/Ipopt/MSVisualStudio/v8-ifort/installed/include/coin"
Max Lyon's avatar
Max Lyon committed
51 52
         "C:\\libs\\Ipopt-3.8.2\\include\\coin"
         ${IPOPT_DIR}/include
53 54
   )

55 56
   IF(IPOPT_INCLUDE_DIR)
      find_library( IPOPT_LIBRARY_RELEASE 
Jan Möbius's avatar
Jan Möbius committed
57 58
                    Ipopt ipopt libipopt IpOpt-vc10
                    PATHS "C:\\libs\\Ipopt-3.8.2\\lib\\win32\\release" 
59 60 61
					"${VS_SEARCH_PATH}Ipopt-3.12.9/lib"
                    "${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
62
				   )
63
      find_library( IPOPT_LIBRARY_DEBUG
Jan Möbius's avatar
Jan Möbius committed
64
                    Ipopt ipoptd libipoptd IpOpt-vc10d
Jan Möbius's avatar
Jan Möbius committed
65
                    PATHS "C:\\libs\\Ipopt-3.8.2\\lib\\win32\\debug" 
66 67 68
					"${VS_SEARCH_PATH}Ipopt-3.12.9/lib"
				    "${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
69
		   )
70

71
      set ( IPOPT_LIBRARY "optimized;${IPOPT_LIBRARY_RELEASE};debug;${IPOPT_LIBRARY_DEBUG}" CACHE  STRING "IPOPT Libraries" )
Jan Möbius's avatar
Jan Möbius committed
72
	  
73 74 75
      GET_FILENAME_COMPONENT(IPOPT_LIBRARY_DIR ${IPOPT_LIBRARY_RELEASE} PATH )
      MARK_AS_ADVANCED(IPOPT_LIBRARY_DIR)
     
76

Jan Möbius's avatar
Jan Möbius committed
77
      SET(IPOPT_FOUND TRUE)
78 79
      SET(IPOPT_INCLUDE_DIRS ${IPOPT_INCLUDE_DIR})
      SET(IPOPT_LIBRARY_DIRS ${IPOPT_LIBRARY_DIR})
Max Lyon's avatar
Max Lyon committed
80
      set(IPOPT_LIBRARIES "${IPOPT_LIBRARY}" )
Jan Möbius's avatar
Jan Möbius committed
81
	  # Todo, set right version depending on build type (debug/release)
82
	  #GET_FILENAME_COMPONENT( IPOPT_LIBRARY_DIRS ${GLEW_LIBRARY} PATH )
Jan Möbius's avatar
Jan Möbius committed
83 84
    ELSE(IPOPT_INCLUDE_DIR)
      SET(IPOPT_FOUND FALSE)
Max Lyon's avatar
Max Lyon committed
85
      SET(IPOPT_INCLUDE_DIRS ${IPOPT_INCLUDE_DIR})
Jan Möbius's avatar
Jan Möbius committed
86 87
    ENDIF(IPOPT_INCLUDE_DIR)

88 89
ELSE( WIN32 )
   find_path(IPOPT_INCLUDE_DIR NAMES IpNLP.hpp
Max Lyon's avatar
Max Lyon committed
90
     PATHS  "$ENV{IPOPT_HOME}/include/coin"
David Bommes's avatar
David Bommes committed
91
            "/usr/include/coin"
Max Lyon's avatar
Max Lyon committed
92
            "~/sw/Ipopt-3.12.4-installed/include/coin"
93 94 95 96
   )

   find_library( IPOPT_LIBRARY 
                 ipopt
97
                 HINTS "$ENV{IPOPT_HOME}/lib"
Max Lyon's avatar
Max Lyon committed
98 99 100 101
                 PATHS
                       "/usr/lib"
                       "~/sw/Ipopt-3.12.4-installed/lib"
    )
David Bommes's avatar
David Bommes committed
102 103 104 105
    
    #wrong config under Debian workaround
    add_definitions( -DHAVE_CSTDDEF )

Max Lyon's avatar
Max Lyon committed
106

107
   # set optional path to HSL Solver for dynamic usage
108 109 110
   find_path(IPOPT_HSL_LIBRARY_DIR 
             NAMES libhsl.so
                   libhsl.dylib
111
             HINTS "$ENV{IPOPT_HSL_LIBRARY_PATH}"
112
                   "$ENV{HOME}/opt/HSL/lib"
113
   )
114

Max Lyon's avatar
Max Lyon committed
115
   # find HSL library for fixed linking of solvers
116
   find_library( IPOPT_HSL_LIBRARY 
Max Lyon's avatar
Max Lyon committed
117
                 coinhsl hsl
118 119
                 HINTS "$ENV{IPOPT_HSL_LIBRARY_PATH}"
                       "$ENV{IPOPT_HOME}/lib"
Max Lyon's avatar
Max Lyon committed
120 121
                 PATHS "/usr/lib" )
   
122
   
123 124 125 126
   set(IPOPT_LIBRARY_DIRS "${IPOPT_LIBRARY_DIR}" )
   set(IPOPT_INCLUDE_DIRS "${IPOPT_INCLUDE_DIR}" )
   set(IPOPT_LIBRARIES "${IPOPT_LIBRARY}" )

David Bommes's avatar
David Bommes committed
127
   IF( IPOPT_HSL_LIBRARY_DIR)
Jan Möbius's avatar
Jan Möbius committed
128 129 130 131
     IF( NOT IPOPT_FIND_QUIETLY )
        message ( "IPOPT_HSL_LIBRARY_DIR found at ${IPOPT_HSL_LIBRARY_DIR} ")
     ENDIF()
     LIST( APPEND IPOPT_LIBRARY_DIRS "${IPOPT_HSL_LIBRARY_DIR}")
132
   ENDIF(IPOPT_HSL_LIBRARY_DIR)
David Bommes's avatar
David Bommes committed
133
   
Max Lyon's avatar
Max Lyon committed
134
   
135 136 137 138
   
   IF(IPOPT_HSL_LIBRARY)
     LIST( APPEND IPOPT_LIBRARIES "${IPOPT_HSL_LIBRARY}")   
   ENDIF(IPOPT_HSL_LIBRARY)
David Bommes's avatar
David Bommes committed
139 140

   include(FindPackageHandleStandardArgs)
141
   # handle the QUIETLY and REQUIRED arguments and set LIBIPOPT_FOUND to TRUE
David Bommes's avatar
David Bommes committed
142 143 144 145 146 147
   # 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 )
   
148
ENDIF()