|
| 1 | +# This file contains helper functions to make finding liblsl as easy as |
| 2 | +# possible for app authors |
| 3 | +# Usage: (optionally) set either LSL_INSTALL_ROOT to the path where liblsl was |
| 4 | +# installed / an install dir was unzipped or set LIBLSLDIR to the path where |
| 5 | +# the liblsl source code and CMakeLists.txt is |
| 6 | +# Then, include Findliblsl.cmake |
| 7 | + |
| 8 | +# Findliblsl.cmake will the look for ${LSL_INSTALL_ROOT}/share/LSL/cmake/LSLConfig.cmake |
| 9 | +# or ${LIBLSLDIR}/LSLCMake.cmake and ${LIBLSLDIR}/CMakeLists.txt and either import |
| 10 | +# the "installed" precompiled liblsl or add the source directory and compile it |
| 11 | + |
| 12 | +macro(lsl_found_liblsl type lslpath) |
| 13 | + message(STATUS "${type} liblsl found in ${lslpath}") |
| 14 | + list(APPEND CMAKE_MODULE_PATH ${lslpath}) |
| 15 | + include(LSLCMake) |
| 16 | + return() |
| 17 | +endmacro() |
| 18 | + |
| 19 | +# set up LSL if not done already |
| 20 | +if(NOT TARGET LSL::lsl) |
| 21 | + # when building out of tree LSL_INSTALL_ROOT should to be specified on the |
| 22 | + # cmd line to find a precompiled liblsl |
| 23 | + file(TO_CMAKE_PATH "${LSL_INSTALL_ROOT}" LSL_INSTALL_ROOT) |
| 24 | + list(APPEND LSL_INSTALL_ROOT "${CMAKE_CURRENT_LIST_DIR}/../../LSL/liblsl/build/install") |
| 25 | + find_package(LSL HINTS ${LSL_INSTALL_ROOT}/share/LSL/ ${LSL_INSTALL_ROOT}/LSL/share/LSL QUIET) |
| 26 | + if(LSL_FOUND) |
| 27 | + lsl_found_liblsl("Precompiled" ${LSL_DIR}) |
| 28 | + endif() |
| 29 | + message(WARNING "Precompiled LSL was not found. See https://github.com/labstreaminglayer/labstreaminglayer/blob/master/doc/BUILD.md#lsl_install_root for more information.") |
| 30 | + |
| 31 | + # Try to find the liblsl source directory otherwise |
| 32 | + file(TO_CMAKE_PATH "${LIBLSLDIR}" LIBLSLDIR) |
| 33 | + find_file(LSLCMAKE_PATH |
| 34 | + "LSLCMake.cmake" |
| 35 | + HINTS ${LIBLSLDIR} "${CMAKE_CURRENT_LIST_DIR}/../../LSL/liblsl" |
| 36 | + ) |
| 37 | + if(LSLCMAKE_PATH) |
| 38 | + get_filename_component(LSLDIR_PATH ${LSLCMAKE_PATH} DIRECTORY CACHE) |
| 39 | + message(STATUS "${LSLCMAKE_PATH} ${LSLDIR_PATH}") |
| 40 | + add_subdirectory(${LSLDIR_PATH} liblsl) |
| 41 | + lsl_found_liblsl("Source dir for" ${LSLDIR_PATH}) |
| 42 | + endif() |
| 43 | + message(WARNING "LSLCMake wasn't found in '${LIBLSLDIR}'") |
| 44 | + message(FATAL_ERROR "Neither precompiled libls nor liblsl source found") |
| 45 | +endif() |
0 commit comments