|
3 | 3 | # ============================================================================= |
4 | 4 | # This is the reference template for building Lab Streaming Layer applications. |
5 | 5 | # It demonstrates: |
6 | | -# - 4-tier liblsl discovery (source, install_root, system, FetchContent) |
| 6 | +# - Automatic liblsl fetching via FetchContent |
7 | 7 | # - CLI and GUI application separation with shared core library |
8 | 8 | # - Qt6 integration |
9 | 9 | # - Cross-platform packaging with CPack |
10 | | -# - macOS entitlements for network capabilities |
| 10 | +# - macOS code signing with entitlements |
11 | 11 | # |
12 | 12 | # Copy this template to start a new LSL application. |
13 | 13 | # ============================================================================= |
@@ -37,113 +37,38 @@ option(LSLTEMPLATE_BUILD_GUI "Build the GUI application (requires Qt6)" ON) |
37 | 37 | option(LSLTEMPLATE_BUILD_CLI "Build the CLI application" ON) |
38 | 38 |
|
39 | 39 | # ============================================================================= |
40 | | -# LSL Discovery Options |
| 40 | +# liblsl Dependency |
41 | 41 | # ============================================================================= |
42 | | -# Priority 1: Build from local source (for parallel liblsl development) |
43 | | -set(LSL_SOURCE_DIR "" CACHE PATH "Path to liblsl source directory") |
| 42 | +# By default, liblsl is fetched automatically from GitHub. |
| 43 | +# To use a pre-installed liblsl, set LSL_INSTALL_ROOT. |
| 44 | +set(LSL_INSTALL_ROOT "" CACHE PATH "Path to installed liblsl (optional)") |
| 45 | +set(LSL_FETCH_REF "v1.17.0" CACHE STRING "liblsl version to fetch from GitHub") |
44 | 46 |
|
45 | | -# Priority 2: Use explicit installation path |
46 | | -set(LSL_INSTALL_ROOT "" CACHE PATH "Path to installed liblsl") |
47 | | - |
48 | | -# Priority 3: System installation (searched automatically) |
49 | | - |
50 | | -# Priority 4: Fetch from GitHub if not found |
51 | | -option(LSL_FETCH_IF_MISSING "Fetch liblsl from GitHub if not found locally" ON) |
52 | | -# TODO: Change back to version tag (e.g., "v1.16.2") once apple_framework branch is merged |
53 | | -set(LSL_FETCH_REF "cboulay/apple_framework" CACHE STRING "liblsl git ref to fetch (tag, branch, or commit)") |
54 | | - |
55 | | -# ============================================================================= |
56 | | -# Find/Fetch liblsl |
57 | | -# ============================================================================= |
58 | | -if(LSL_SOURCE_DIR) |
59 | | - # Priority 1: Build from local source (parallel development) |
60 | | - if(NOT EXISTS "${LSL_SOURCE_DIR}/CMakeLists.txt") |
61 | | - message(FATAL_ERROR "LSL_SOURCE_DIR set to '${LSL_SOURCE_DIR}' but no CMakeLists.txt found there") |
62 | | - endif() |
63 | | - message(STATUS "Using local liblsl source: ${LSL_SOURCE_DIR}") |
64 | | - add_subdirectory("${LSL_SOURCE_DIR}" liblsl_bin EXCLUDE_FROM_ALL) |
65 | | - if(NOT TARGET LSL::lsl) |
66 | | - add_library(LSL::lsl ALIAS lsl) |
67 | | - endif() |
68 | | - set(LSL_FOUND TRUE) |
69 | | - include("${LSL_SOURCE_DIR}/cmake/LSLCMake.cmake") |
70 | | -else() |
71 | | - # Priority 2 & 3: Try to find installed liblsl |
72 | | - set(_lsl_hints) |
73 | | - if(LSL_INSTALL_ROOT) |
74 | | - list(APPEND _lsl_hints "${LSL_INSTALL_ROOT}") |
75 | | - endif() |
76 | | - # Common development layout hints (including CLion cmake-build-* directories) |
77 | | - string(TOLOWER "${CMAKE_BUILD_TYPE}" _build_type_lower) |
78 | | - if(NOT _build_type_lower) |
79 | | - set(_build_type_lower "release") |
80 | | - endif() |
81 | | - if(MSVC) |
82 | | - set(_clion_build_dir "cmake-build-${_build_type_lower}-visual-studio") |
83 | | - else() |
84 | | - set(_clion_build_dir "cmake-build-${_build_type_lower}") |
85 | | - endif() |
86 | | - foreach(_root IN ITEMS "../liblsl" "../../LSL/liblsl") |
87 | | - foreach(_build IN ITEMS "build" "${_clion_build_dir}") |
88 | | - list(APPEND _lsl_hints "${CMAKE_CURRENT_LIST_DIR}/${_root}/${_build}/install") |
89 | | - endforeach() |
90 | | - endforeach() |
91 | | - |
92 | | - set(_lsl_suffixes |
93 | | - share/LSL |
94 | | - lib/cmake/LSL |
95 | | - cmake |
96 | | - Frameworks/lsl.framework/Resources/CMake # macOS framework layout |
| 47 | +if(LSL_INSTALL_ROOT) |
| 48 | + # Use pre-installed liblsl |
| 49 | + find_package(LSL REQUIRED |
| 50 | + HINTS "${LSL_INSTALL_ROOT}" |
| 51 | + PATH_SUFFIXES share/LSL lib/cmake/LSL Frameworks/lsl.framework/Resources/CMake |
97 | 52 | ) |
98 | | - |
99 | | - # First try: Search only in hints (prefer local builds over system) |
100 | | - find_package(LSL QUIET |
101 | | - HINTS ${_lsl_hints} |
102 | | - PATH_SUFFIXES ${_lsl_suffixes} |
103 | | - NO_DEFAULT_PATH |
| 53 | + message(STATUS "Using installed liblsl: ${LSL_DIR}") |
| 54 | + include("${LSL_DIR}/LSLCMake.cmake") |
| 55 | +else() |
| 56 | + # Fetch liblsl from GitHub |
| 57 | + message(STATUS "Fetching liblsl ${LSL_FETCH_REF} from GitHub...") |
| 58 | + include(FetchContent) |
| 59 | + set(LSL_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) |
| 60 | + set(LSL_BUILD_TESTING OFF CACHE BOOL "" FORCE) |
| 61 | + FetchContent_Declare(liblsl |
| 62 | + GIT_REPOSITORY https://github.com/sccn/liblsl.git |
| 63 | + GIT_TAG ${LSL_FETCH_REF} |
| 64 | + GIT_SHALLOW ON |
| 65 | + EXCLUDE_FROM_ALL |
104 | 66 | ) |
105 | | - |
106 | | - # Second try: Search system paths if not found in hints |
107 | | - if(NOT LSL_FOUND) |
108 | | - find_package(LSL QUIET |
109 | | - PATH_SUFFIXES ${_lsl_suffixes} |
110 | | - ) |
111 | | - endif() |
112 | | - |
113 | | - if(LSL_FOUND) |
114 | | - message(STATUS "Found installed liblsl: ${LSL_DIR}") |
115 | | - include("${LSL_DIR}/LSLCMake.cmake") |
116 | | - elseif(LSL_FETCH_IF_MISSING) |
117 | | - # Priority 4: Fetch from GitHub |
118 | | - message(STATUS "liblsl not found locally, fetching ${LSL_FETCH_REF} from GitHub...") |
119 | | - include(FetchContent) |
120 | | - # Disable liblsl extras we don't need |
121 | | - set(LSL_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) |
122 | | - set(LSL_BUILD_TESTING OFF CACHE BOOL "" FORCE) |
123 | | - # EXCLUDE_FROM_ALL prevents liblsl's install rules from running |
124 | | - # (we handle liblsl bundling ourselves) |
125 | | - FetchContent_Declare(liblsl |
126 | | - GIT_REPOSITORY https://github.com/sccn/liblsl.git |
127 | | - GIT_TAG ${LSL_FETCH_REF} |
128 | | - GIT_SHALLOW ON |
129 | | - EXCLUDE_FROM_ALL |
130 | | - ) |
131 | | - FetchContent_MakeAvailable(liblsl) |
132 | | - if(NOT TARGET LSL::lsl) |
133 | | - add_library(LSL::lsl ALIAS lsl) |
134 | | - endif() |
135 | | - set(LSL_FOUND TRUE) |
136 | | - include("${liblsl_SOURCE_DIR}/cmake/LSLCMake.cmake") |
137 | | - message(STATUS "liblsl fetched and configured") |
138 | | - else() |
139 | | - message(FATAL_ERROR |
140 | | - "liblsl not found. Options:\n" |
141 | | - " 1. Set LSL_SOURCE_DIR to liblsl source directory\n" |
142 | | - " 2. Set LSL_INSTALL_ROOT to installed liblsl location\n" |
143 | | - " 3. Install liblsl system-wide\n" |
144 | | - " 4. Enable LSL_FETCH_IF_MISSING=ON to auto-fetch from GitHub" |
145 | | - ) |
| 67 | + FetchContent_MakeAvailable(liblsl) |
| 68 | + if(NOT TARGET LSL::lsl) |
| 69 | + add_library(LSL::lsl ALIAS lsl) |
146 | 70 | endif() |
| 71 | + include("${liblsl_SOURCE_DIR}/cmake/LSLCMake.cmake") |
147 | 72 | endif() |
148 | 73 |
|
149 | 74 | # ============================================================================= |
|
0 commit comments