BASIS  version 1.2.3 (revision 2104)
FindMOSEK.cmake
Go to the documentation of this file.
00001 ##############################################################################
00002 # @file  FindMOSEK.cmake
00003 # @brief Find MOSEK (http://www.mosek.com) package.
00004 #
00005 # @par Input variables:
00006 # <table border="0">
00007 #   <tr>
00008 #     @tp @b MOSEK_DIR @endtp
00009 #     <td>The MOSEK package files are searched under the specified root
00010 #         directory. If they are not found there, the default search paths
00011 #         are considered. This variable can also be set as environment variable.</td>
00012 #   </tr>
00013 #   <tr>
00014 #     @tp @b MOSEK_NO_OMP @endtp
00015 #     <td>Whether to use the link libraries build without OpenMP, i.e.,
00016 #         multi-threading, enabled. By default, the multi-threaded libraries
00017 #         are used.</td>
00018 #   </tr>
00019 #   <tr>
00020 #     @tp @b MOSEK_MATLAB @endtp
00021 #     <td>Whether the MATLAB components of the MOSEK packages should be found.
00022 #         Defaults to 1, if @c MATLAB_FOUND evaluates to true and 0 otherwise.</td>
00023 #   </tr>
00024 #   <tr>
00025 #     @tp @b MOSEK_JAVA @endtp
00026 #     <td>Whether the Java components of the MOSEK package should be found.
00027 #         Defaults to 0.</td>
00028 #   </tr>
00029 #   <tr>
00030 #     @tp @b MOSEK_PYTHON @endtp
00031 #     <td>Whether the Python components of the MOSEK package should be found.
00032 #         Defaults to 0.</td>
00033 #   </tr>
00034 #   <tr>
00035 #     @tp @b MOSEK_TOOLS_SUFFIX @endtp
00036 #     <td>Platform specific path suffix for tools, i.e., "tools/platform/linux64x86"
00037 #         on 64-bit Linux systems. If not specified, this module determines the
00038 #         right suffix depending on the CMake system variables.</td>
00039 #   </tr>
00040 #   <tr>
00041 #     @tp @b MATLAB_RELEASE @endtp
00042 #     <td>Release of MATLAB installation. Set to the 'Release' return value of
00043 #         the "ver ('MATLAB')" command of MATLAB without brackets. If this
00044 #         variable is not set and the basis_get_matlab_release() command is
00045 #         available, it is invoked to determine the release version automatically.
00046 #         Otherwise, the release version defaults to "R2009b".</td>
00047 #   </tr>
00048 #   <tr>
00049 #     @tp @b MEX_EXT @endtp
00050 #     <td>The extension of MEX-files. If this variable is not set and the
00051 #         basis_mexext() command is available, it is invoked to determine the
00052 #         extension automatically. Otherwise, the MEX extension defaults to "mexa64".</td>
00053 #   </tr>
00054 #   <tr>
00055 #     @tp @b PYTHON_VERSION @endtp
00056 #     <td>Version of Python installation. Set to first two or three return values of
00057 #         "sys.version_info" separated by a period (.). If this variable is not set
00058 #         and the basis_get_python_version() command is available, it is invoked to
00059 #         determine the version automatically. Otherwise, the Python version
00060 #         defaults to 2.6.</td>
00061 #   </tr>
00062 # </table>
00063 #
00064 # @par Output variables:
00065 # <table border="0">
00066 #   <tr>
00067 #     @tp @b MOSEK_FOUND @endtp
00068 #     <td>Whether the package was found and the following CMake variables are valid.</td>
00069 #   </tr>
00070 #   <tr>
00071 #     @tp @b MOSEK_INCLUDE_DIR @endtp
00072 #     <td>Package include directories.</td>
00073 #   </tr>
00074 #   <tr>
00075 #     @tp @b MOSEK_INCLUDES @endtp
00076 #     <td>Include directories including prerequisite libraries (non-cached).</td>
00077 #   </tr>
00078 #   <tr>
00079 #     @tp @b MOSEK_LIBRARY @endtp
00080 #     <td>Package libraries.</td>
00081 #   </tr>
00082 #   <tr>
00083 #     @tp @b MOSEK_LIBRARIES @endtp
00084 #     <td>Package libraries and prerequisite libraries (non-cached).</td>
00085 #   </tr>
00086 #   <tr>
00087 #     @tp @b MOSEK_mosekopt_MEX @endtp
00088 #     <td>Package mosekopt MEX-file.</td>
00089 #   </tr>
00090 #   <tr>
00091 #     @tp @b MOSEK_MEX_FILES @endtp
00092 #     <td>List of MEX-files (non-cached).</td>
00093 #   </tr>
00094 #   <tr>
00095 #     @tp @b MOSEK_mosek_JAR @endtp
00096 #     <td>Package mosek Java library (.jar file).</td>
00097 #   </tr>
00098 #   <tr>
00099 #     @tp @b MOSEK_CLASSPATH @endtp
00100 #     <td>List of Java package libraries and prerequisite libraries (non-cached).</td>
00101 #   </tr>
00102 #   <tr>
00103 #     @tp @b MOSEK_PYTHONPATH @endtp
00104 #     <td>Path to Python modules of this package.</td>
00105 #   </tr>
00106 # </table>
00107 #
00108 # Copyright (c) 2011, 2012 University of Pennsylvania. All rights reserved.<br />
00109 # See https://www.cbica.upenn.edu/sbia/software/license.html or COPYING file.
00110 #
00111 # Contact: SBIA Group <sbia-software at uphs.upenn.edu>
00112 #
00113 # @ingroup CMakeFindModules
00114 ##############################################################################
00115 
00116 # ----------------------------------------------------------------------------
00117 # initialize search
00118 if (NOT MOSEK_DIR)
00119   set (MOSEK_DIR "$ENV{MOSEK_DIR}" CACHE PATH "Installation prefix for MOSEK." FORCE)
00120 endif ()
00121 
00122 # MATLAB components
00123 if (NOT DEFINED MOSEK_MATLAB)
00124   set (MOSEK_MATLAB ${MATLAB_FOUND})
00125 endif ()
00126 
00127 if (MOSEK_MATLAB)
00128   # MATLAB version
00129   if (NOT MATLAB_RELEASE)
00130     if (COMMAND basis_get_matlab_release)
00131       basis_get_matlab_release ()
00132       if (NOT MATLAB_RELEASE)
00133         message (FATAL_ERROR "Failed to determine release version of MATLAB installation. "
00134                              "This information is required to be able to find the right MOSEK MEX-files. "
00135                              "Set MATLAB_RELEASE manually and try again.")
00136       endif ()
00137     else ()
00138       set (MATLAB_RELEASE "R2009b")
00139     endif ()
00140   endif ()
00141   string (TOLOWER "${MATLAB_RELEASE}" MATLAB_RELEASE_LOWER)
00142   # search path for MOSEK MATLAB toolbox
00143   if (NOT MOSEK_TOOLBOX_SUFFIX)
00144     if (MOSEK_DIR)
00145       file (
00146         GLOB_RECURSE
00147           MOSEK_TOOLBOX_SUFFIXES
00148         RELATIVE "${MOSEK_DIR}"
00149         "${MOSEK_DIR}/toolbox/*/*.mex*"
00150       )
00151       set (MOSEK_TOOLBOX_VERSIONS)
00152       foreach (MOSEK_MEX_FILE IN LISTS MOSEK_TOOLBOX_SUFFIXES)
00153         get_filename_component (MOSEK_TOOLBOX_SUFFIX  "${MOSEK_MEX_FILE}" PATH)
00154         get_filename_component (MOSEK_TOOLBOX_VERSION "${MOSEK_TOOLBOX_SUFFIX}" NAME)
00155         list (APPEND MOSEK_TOOLBOX_VERSIONS "${MOSEK_TOOLBOX_VERSION}")
00156         set (MOSEK_TOOLBOX_SUFFIX)
00157       endforeach ()
00158       list (SORT MOSEK_TOOLBOX_VERSIONS)
00159       list (REVERSE MOSEK_TOOLBOX_VERSIONS)
00160       string (REGEX MATCH "[0-9][0-9]*" MATLAB_RELEASE_YEAR "${MATLAB_RELEASE}")
00161       foreach (MOSEK_TOOLBOX_VERSION IN LISTS MOSEK_TOOLBOX_VERSIONS)
00162         if (MOSEK_TOOLBOX_VERSION MATCHES "[rR]([0-9][0-9]*)[ab]")
00163           if (CMAKE_MATCH_1 EQUAL MATLAB_RELEASE_VERSION OR
00164               CMAKE_MATCH_1 LESS  MATLAB_RELEASE_VERSION)
00165             set (MATLAB_TOOLBOX_SUFFIX "toolbox/${MOSEK_TOOLBOX_VERSION}")
00166             break ()
00167           endif ()
00168         endif ()
00169       endforeach ()
00170     endif ()
00171     if (NOT MOSEK_TOOLBOX_SUFFIX)
00172       set (MOSEK_TOOLBOX_SUFFIX "toolbox/${MATLAB_RELEASE_LOWER}")
00173     endif ()
00174   endif ()
00175   # extension of MEX-files
00176   if (NOT MEX_EXT)
00177     if (COMMAND basis_mexext)
00178       basis_mexext ()
00179     else ()
00180       set (MEX_EXT "mexa64")
00181     endif ()
00182   endif ()
00183 endif ()
00184 
00185 # Java components
00186 if (NOT DEFINED MOSEK_JAVA)
00187   set (MOSEK_JAVA 0)
00188 endif ()
00189 
00190 # Python components
00191 if (NOT DEFINED MOSEK_PYTHON)
00192   set (MOSEK_PYTHON 0)
00193 endif ()
00194 
00195 if (MOSEK_PYTHON)
00196   # Python version
00197   if (NOT PYTHON_VERSION)
00198     if (COMMAND basis_get_python_version)
00199       basis_get_python_version ()
00200       if (NOT PYTHON_VERSION)
00201         message (FATAL_ERROR "Failed to determine version of Python installation. "
00202                              "This information is required to be able to find the right MOSEK Python modules. "
00203                              "Set PYTHON_VERSION manually and try again.")
00204       endif ()
00205     else ()
00206       set (PYTHON_VERSION "2.6")
00207     endif ()
00208   endif ()
00209   # major version of Python
00210   string (REGEX REPLACE "^([0-9]+)" "\\1" PYTHON_VERSION_MAJOR "${PYTHON_VERSION}")
00211 endif ()
00212 
00213 # library name
00214 set (MOSEK_LIBRARY_NAME "mosek")
00215 if (MOSEK_NO_OMP)
00216   set (MOSEK_LIBRARY_NAME "${MOSEK_LIBRARY_NAME}noomp")
00217 endif ()
00218 if (UNIX)
00219   if (NOT CMAKE_SIZE_OF_VOID_P EQUAL 4)
00220     set (MOSEK_LIBRARY_NAME "${MOSEK_LIBRARY_NAME}64")
00221   endif ()
00222 endif ()
00223 set (MOSEK_LIBRARY_NAMES "${MOSEK_LIBRARY_NAME}")
00224 if (WIN32)
00225   foreach (VERSION_SUFFIX "6_0")
00226     list (APPEND MOSEK_LIBRARY_NAMES "${MOSEK_LIBRARY_NAME}${VERSION_SUFFIX}")
00227   endforeach ()
00228 endif ()
00229 
00230 # search path for MOSEK tools
00231 if (NOT MOSEK_TOOLS_SUFFIX)
00232   set (MOSEK_TOOLS_SUFFIX "tools/platform/")
00233   if (WIN32)
00234     set (MOSEK_TOOLS_SUFFIX "${MOSEK_TOOLS_SUFFIX}win")
00235   elseif (APPLE)
00236     set (MOSEK_TOOLS_SUFFIX "${MOSEK_TOOLS_SUFFIX}osx")
00237   else ()
00238     set (MOSEK_TOOLS_SUFFIX "${MOSEK_TOOLS_SUFFIX}linux")
00239   endif ()
00240   if (CMAKE_SIZE_OF_VOID_P EQUAL 4)
00241     set (MOSEK_TOOLS_SUFFIX "${MOSEK_TOOLS_SUFFIX}32")
00242   else ()
00243     set (MOSEK_TOOLS_SUFFIX "${MOSEK_TOOLS_SUFFIX}64")
00244   endif ()
00245   set (MOSEK_TOOLS_SUFFIX "${MOSEK_TOOLS_SUFFIX}x86")
00246 endif ()
00247 
00248 #-------------------------------------------------------------
00249 # find paths/files
00250 if (MOSEK_DIR)
00251 
00252   find_path (
00253     MOSEK_INCLUDE_DIR
00254       NAMES         mosek.h
00255       HINTS         "${MOSEK_DIR}"
00256       PATH_SUFFIXES "${MOSEK_TOOLS_SUFFIX}/h"
00257       DOC           "Include directory for MOSEK libraries."
00258       NO_DEFAULT_PATH
00259   )
00260 
00261   find_library (
00262     MOSEK_LIBRARY
00263       NAMES         ${MOSEK_LIBRARY_NAMES}
00264       HINTS         "${MOSEK_DIR}"
00265       PATH_SUFFIXES "${MOSEK_TOOLS_SUFFIX}/bin"
00266       DOC           "MOSEK link library."
00267       NO_DEFAULT_PATH
00268   )
00269 
00270 else ()
00271 
00272   find_path (
00273     MOSEK_INCLUDE_DIR
00274       NAMES mosek.h
00275       HINTS ENV C_INCLUDE_PATH ENV CXX_INCLUDE_PATH
00276       DOC   "Include directory for MOSEK libraries."
00277   )
00278 
00279   find_library (
00280     MOSEK_LIBRARY
00281       NAMES ${MOSEK_LIBRARY_NAMES}
00282       HINTS ENV LD_LIBRARY_PATH
00283       DOC   "MOSEK link library."
00284   )
00285 
00286 endif ()
00287 
00288 mark_as_advanced (MOSEK_INCLUDE_DIR)
00289 mark_as_advanced (MOSEK_LIBRARY)
00290 
00291 # MATLAB components
00292 if (MOSEK_MATLAB)
00293   if (MOSEK_DIR)
00294 
00295     find_file (
00296       MOSEK_mosekopt_MEX
00297         NAMES         mosekopt.${MEX_EXT}
00298         HINTS         "${MOSEK_DIR}"
00299         PATH_SUFFIXES "${MOSEK_TOOLBOX_SUFFIX}"
00300         DOC           "The mosekopt MEX-file of the MOSEK package."
00301         NO_DEFAULT_PATH
00302     )
00303 
00304   else ()
00305 
00306     find_file (
00307       MOSEK_mosekopt_MEX
00308         NAMES         mosekopt.${MEX_EXT}
00309         PATH_SUFFIXES "${MOSEK_TOOLBOX_SUFFIX}"
00310         DOC           "The mosekopt MEX-file of the MOSEK package."
00311     )
00312 
00313   endif ()
00314 
00315   if (MOSEK_mosekopt_MEX)
00316     set (MOSEK_MEX_FILES "${MOSEK_mosekopt_MEX}")
00317   endif ()
00318 
00319   mark_as_advanced (MOSEK_mosekopt_MEX)
00320 endif ()
00321 
00322 # Java components
00323 if (MOSEK_JAVA)
00324   if (MOSEK_DIR)
00325 
00326     find_file (
00327       MOSEK_mosek_JAR
00328         NAMES         mosek.jar
00329         HINTS         "${MOSEK_DIR}"
00330         PATH_SUFFIXES "${MOSEK_TOOLS_SUFFIX}/bin"
00331         DOC           "The Java library (.jar file) of the MOSEK package."
00332         NO_DEFAULT_PATH
00333     )
00334 
00335   else ()
00336 
00337     find_file (
00338       MOSEK_mosek_JAR
00339         NAMES mosek.jar
00340         HINTS ENV CLASSPATH
00341         DOC   "The Java library (.jar file) of the MOSEK package."
00342     )
00343 
00344   endif ()
00345 
00346   if (MOSEK_mosek_JAR)
00347     set (MOSEK_CLASSPATH "${MOSEK_mosek_JAR}")
00348   endif ()
00349 
00350   mark_as_advanced (MOSEK_mosek_JAR)
00351 endif ()
00352 
00353 # Python components
00354 if (MOSEK_PYTHON)
00355   if (MOSEK_DIR)
00356 
00357     find_path (
00358       MOSEK_PYTHONPATH
00359         NAMES "mosek/array.py"
00360         HINTS ENV PYTHONPATH
00361         DOC   "Path to MOSEK Python module."
00362     )
00363 
00364   else ()
00365 
00366     find_path (
00367       MOSEK_PYTHONPATH
00368         NAMES "mosek/array.py"
00369         HINTS "${MOSEK_DIR}/${MOSEK_PATH_SUFFIX}/python/${PYTHON_VERSION_MAJOR}"
00370         DOC   "Path to MOSEK Python module."
00371         NO_DEFAULT_PATH
00372     )
00373 
00374   endif ()
00375 
00376   mark_as_advanced (MOSEK_PYTHONPATH)
00377 endif ()
00378 
00379 # ----------------------------------------------------------------------------
00380 # prerequisite libraries
00381 set (MOSEK_INCLUDES  "${MOSEK_INCLUDE_DIR}")
00382 set (MOSEK_LIBRARIES "${MOSEK_LIBRARY}")
00383 
00384 # ----------------------------------------------------------------------------
00385 # aliases / backwards compatibility
00386 set (MOSEK_INCLUDE_DIRS "${MOSEK_INCLUDES}")
00387 
00388 # ----------------------------------------------------------------------------
00389 # debugging
00390 if (BASIS_DEBUG AND COMMAND basis_dump_variables)
00391   basis_dump_variables ("${CMAKE_CURRENT_BINARY_DIR}/FindMOSEKVariables.cmake")
00392 endif ()
00393 
00394 # ----------------------------------------------------------------------------
00395 # handle the QUIETLY and REQUIRED arguments and set *_FOUND to TRUE
00396 # if all listed variables are found or TRUE
00397 include (FindPackageHandleStandardArgs)
00398 
00399 set (MOSEK_REQUIRED_VARS
00400   MOSEK_INCLUDE_DIR
00401   MOSEK_LIBRARY
00402 )
00403 
00404 if (MOSEK_MATLAB)
00405   list (APPEND MOSEK_REQUIRED_VARS MOSEK_mosekopt_MEX)
00406 endif ()
00407 if (MOSEK_JAVA)
00408   list (APPEND MOSEK_REQUIRED_VARS MOSEK_mosek_JAR)
00409 endif ()
00410 if (MOSEK_PYTHON)
00411   list (APPEND MOSEK_REQUIRED_VARS MOSEK_PYTHONPATH)
00412 endif ()
00413 
00414 find_package_handle_standard_args (
00415   MOSEK
00416 # MESSAGE
00417     DEFAULT_MSG
00418 # VARIABLES
00419     ${MOSEK_REQUIRED_VARS}
00420 )
00421 
00422 # ----------------------------------------------------------------------------
00423 # set MOSEK_DIR
00424 if (NOT MOSEK_DIR AND MOSEK_FOUND)
00425   string (REGEX REPLACE "${MOSEK_TOOLS_SUFFIX}/h/?" "" MOSEK_PREFIX "${MOSEK_INCLUDE_DIR}")
00426   set (MOSEK_DIR "${MOSEK_PREFIX}" CACHE PATH "Installation prefix for MOSEK." FORCE)
00427   unset (MOSEK_PREFIX)
00428 endif ()