Skip to content

Commit 75c86c5

Browse files
committed
Simplify liblsl-finding
1 parent 3904ef8 commit 75c86c5

1 file changed

Lines changed: 29 additions & 103 deletions

File tree

CMakeLists.txt

Lines changed: 29 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -23,112 +23,38 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
2323
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
2424

2525
# =============================================================================
26-
# LSL Discovery Options
27-
# =============================================================================
28-
# Priority 1: Build from local source (for parallel liblsl development)
29-
set(LSL_SOURCE_DIR "" CACHE PATH "Path to liblsl source directory")
30-
31-
# Priority 2: Use explicit installation path
32-
set(LSL_INSTALL_ROOT "" CACHE PATH "Path to installed liblsl")
33-
34-
# Priority 3: System installation (searched automatically)
35-
36-
# Priority 4: Fetch from GitHub if not found
37-
option(LSL_FETCH_IF_MISSING "Fetch liblsl from GitHub if not found locally" ON)
38-
# TODO: Change back to version tag (e.g., "v1.16.2") once apple_framework branch is merged
39-
set(LSL_FETCH_REF "cboulay/apple_framework" CACHE STRING "liblsl git ref to fetch (tag, branch, or commit)")
40-
41-
# =============================================================================
42-
# Find/Fetch liblsl
43-
# =============================================================================
44-
if(LSL_SOURCE_DIR)
45-
# Priority 1: Build from local source (parallel development)
46-
if(NOT EXISTS "${LSL_SOURCE_DIR}/CMakeLists.txt")
47-
message(FATAL_ERROR "LSL_SOURCE_DIR set to '${LSL_SOURCE_DIR}' but no CMakeLists.txt found there")
48-
endif()
49-
message(STATUS "Using local liblsl source: ${LSL_SOURCE_DIR}")
50-
add_subdirectory("${LSL_SOURCE_DIR}" liblsl_bin EXCLUDE_FROM_ALL)
51-
if(NOT TARGET LSL::lsl)
52-
add_library(LSL::lsl ALIAS lsl)
53-
endif()
54-
set(LSL_FOUND TRUE)
55-
include("${LSL_SOURCE_DIR}/cmake/LSLCMake.cmake")
56-
else()
57-
# Priority 2 & 3: Try to find installed liblsl
58-
set(_lsl_hints)
59-
if(LSL_INSTALL_ROOT)
60-
list(APPEND _lsl_hints "${LSL_INSTALL_ROOT}")
61-
endif()
62-
# Common development layout hints (including CLion cmake-build-* directories)
63-
string(TOLOWER "${CMAKE_BUILD_TYPE}" _build_type_lower)
64-
if(NOT _build_type_lower)
65-
set(_build_type_lower "release")
66-
endif()
67-
if(MSVC)
68-
set(_clion_build_dir "cmake-build-${_build_type_lower}-visual-studio")
69-
else()
70-
set(_clion_build_dir "cmake-build-${_build_type_lower}")
71-
endif()
72-
foreach(_root IN ITEMS "../liblsl" "../../LSL/liblsl")
73-
foreach(_build IN ITEMS "build" "${_clion_build_dir}")
74-
list(APPEND _lsl_hints "${CMAKE_CURRENT_LIST_DIR}/${_root}/${_build}/install")
75-
endforeach()
76-
endforeach()
77-
78-
set(_lsl_suffixes
79-
share/LSL
80-
lib/cmake/LSL
81-
cmake
82-
Frameworks/lsl.framework/Resources/CMake # macOS framework layout
26+
# liblsl Dependency
27+
# =============================================================================
28+
# By default, liblsl is fetched automatically from GitHub.
29+
# To use a pre-installed liblsl, set LSL_INSTALL_ROOT.
30+
set(LSL_INSTALL_ROOT "" CACHE PATH "Path to installed liblsl (optional)")
31+
set(LSL_FETCH_REF "v1.17.0" CACHE STRING "liblsl version to fetch from GitHub")
32+
33+
if(LSL_INSTALL_ROOT)
34+
# Use pre-installed liblsl
35+
find_package(LSL REQUIRED
36+
HINTS "${LSL_INSTALL_ROOT}"
37+
PATH_SUFFIXES share/LSL lib/cmake/LSL Frameworks/lsl.framework/Resources/CMake
8338
)
84-
85-
# First try: Search only in hints (prefer local builds over system)
86-
find_package(LSL QUIET
87-
HINTS ${_lsl_hints}
88-
PATH_SUFFIXES ${_lsl_suffixes}
89-
NO_DEFAULT_PATH
39+
message(STATUS "Using installed liblsl: ${LSL_DIR}")
40+
include("${LSL_DIR}/LSLCMake.cmake")
41+
else()
42+
# Fetch liblsl from GitHub
43+
message(STATUS "Fetching liblsl ${LSL_FETCH_REF} from GitHub...")
44+
include(FetchContent)
45+
set(LSL_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
46+
set(LSL_BUILD_TESTING OFF CACHE BOOL "" FORCE)
47+
FetchContent_Declare(liblsl
48+
GIT_REPOSITORY https://github.com/sccn/liblsl.git
49+
GIT_TAG ${LSL_FETCH_REF}
50+
GIT_SHALLOW ON
51+
EXCLUDE_FROM_ALL
9052
)
91-
92-
# Second try: Search system paths if not found in hints
93-
if(NOT LSL_FOUND)
94-
find_package(LSL QUIET
95-
PATH_SUFFIXES ${_lsl_suffixes}
96-
)
97-
endif()
98-
99-
if(LSL_FOUND)
100-
message(STATUS "Found installed liblsl: ${LSL_DIR}")
101-
include("${LSL_DIR}/LSLCMake.cmake")
102-
elseif(LSL_FETCH_IF_MISSING)
103-
# Priority 4: Fetch from GitHub
104-
message(STATUS "liblsl not found locally, fetching ${LSL_FETCH_REF} from GitHub...")
105-
include(FetchContent)
106-
# Disable liblsl extras we don't need
107-
set(LSL_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
108-
set(LSL_BUILD_TESTING OFF CACHE BOOL "" FORCE)
109-
# EXCLUDE_FROM_ALL prevents liblsl's install rules from running
110-
FetchContent_Declare(liblsl
111-
GIT_REPOSITORY https://github.com/sccn/liblsl.git
112-
GIT_TAG ${LSL_FETCH_REF}
113-
GIT_SHALLOW ON
114-
EXCLUDE_FROM_ALL
115-
)
116-
FetchContent_MakeAvailable(liblsl)
117-
if(NOT TARGET LSL::lsl)
118-
add_library(LSL::lsl ALIAS lsl)
119-
endif()
120-
set(LSL_FOUND TRUE)
121-
include("${liblsl_SOURCE_DIR}/cmake/LSLCMake.cmake")
122-
message(STATUS "liblsl fetched and configured")
123-
else()
124-
message(FATAL_ERROR
125-
"liblsl not found. Options:\n"
126-
" 1. Set LSL_SOURCE_DIR to liblsl source directory\n"
127-
" 2. Set LSL_INSTALL_ROOT to installed liblsl location\n"
128-
" 3. Install liblsl system-wide\n"
129-
" 4. Enable LSL_FETCH_IF_MISSING=ON to auto-fetch from GitHub"
130-
)
53+
FetchContent_MakeAvailable(liblsl)
54+
if(NOT TARGET LSL::lsl)
55+
add_library(LSL::lsl ALIAS lsl)
13156
endif()
57+
include("${liblsl_SOURCE_DIR}/cmake/LSLCMake.cmake")
13258
endif()
13359

13460
# =============================================================================

0 commit comments

Comments
 (0)