Skip to content

Commit f73d2ae

Browse files
committed
Simplify liblsl-finding
1 parent 654578e commit f73d2ae

1 file changed

Lines changed: 29 additions & 96 deletions

File tree

CMakeLists.txt

Lines changed: 29 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -15,112 +15,45 @@ set(CMAKE_CXX_STANDARD 20)
1515
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1616

1717
# =============================================================================
18-
# Options
18+
# Build Options
1919
# =============================================================================
2020
option(EGIAMP_BUILD_GUI "Build the GUI application" ON)
2121
option(EGIAMP_BUILD_CLI "Build the CLI application" ON)
2222
option(EGIAMP_BUILD_MOCK "Build the mock EGI Amp device for testing" ON)
2323

24-
# LSL dependency options
25-
set(LSL_SOURCE_DIR "" CACHE PATH "Path to liblsl source for parallel development (highest priority)")
26-
set(LSL_INSTALL_ROOT "" CACHE PATH "Path to installed liblsl (second priority)")
27-
option(LSL_FETCH_IF_MISSING "Fetch liblsl from GitHub if not found locally" ON)
28-
# TODO: Change back to version tag (e.g., "v1.16.2") once apple_framework branch is merged
29-
set(LSL_FETCH_REF "cboulay/apple_framework" CACHE STRING "liblsl git ref to fetch (tag, branch, or commit)")
30-
3124
# =============================================================================
32-
# Find/Fetch liblsl
33-
# Priority: 1) LSL_SOURCE_DIR, 2) LSL_INSTALL_ROOT, 3) System install, 4) FetchContent
25+
# liblsl Dependency
3426
# =============================================================================
35-
if(LSL_SOURCE_DIR)
36-
# Priority 1: Build from local source (parallel development)
37-
if(NOT EXISTS "${LSL_SOURCE_DIR}/CMakeLists.txt")
38-
message(FATAL_ERROR "LSL_SOURCE_DIR set to '${LSL_SOURCE_DIR}' but no CMakeLists.txt found there")
39-
endif()
40-
message(STATUS "Using local liblsl source: ${LSL_SOURCE_DIR}")
41-
add_subdirectory("${LSL_SOURCE_DIR}" liblsl_bin EXCLUDE_FROM_ALL)
42-
if(NOT TARGET LSL::lsl)
43-
add_library(LSL::lsl ALIAS lsl)
44-
endif()
45-
set(LSL_BUILT_FROM_SOURCE TRUE)
46-
include("${LSL_SOURCE_DIR}/cmake/LSLCMake.cmake")
47-
else()
48-
# Priority 2 & 3: Try to find installed version
49-
set(_lsl_hints)
50-
if(LSL_INSTALL_ROOT)
51-
list(APPEND _lsl_hints "${LSL_INSTALL_ROOT}")
52-
endif()
53-
# Common development layout hints (including CLion cmake-build-* directories)
54-
string(TOLOWER "${CMAKE_BUILD_TYPE}" _build_type_lower)
55-
if(NOT _build_type_lower)
56-
set(_build_type_lower "release")
57-
endif()
58-
if(MSVC)
59-
set(_clion_build_dir "cmake-build-${_build_type_lower}-visual-studio")
60-
else()
61-
set(_clion_build_dir "cmake-build-${_build_type_lower}")
62-
endif()
63-
foreach(_root IN ITEMS "../liblsl" "../../LSL/liblsl")
64-
foreach(_build IN ITEMS "build" "${_clion_build_dir}")
65-
list(APPEND _lsl_hints "${CMAKE_CURRENT_LIST_DIR}/${_root}/${_build}/install")
66-
endforeach()
67-
endforeach()
68-
# Also check Visual Studio layout
69-
list(APPEND _lsl_hints "${CMAKE_CURRENT_LIST_DIR}/../../LSL/liblsl/out/install/x64-Release")
70-
71-
set(_lsl_suffixes
72-
share/LSL
73-
lib/cmake/LSL
74-
cmake
75-
Frameworks/lsl.framework/Resources/CMake
76-
)
27+
# By default, liblsl is fetched automatically from GitHub.
28+
# To use a pre-installed liblsl, set LSL_INSTALL_ROOT.
29+
set(LSL_INSTALL_ROOT "" CACHE PATH "Path to installed liblsl (optional)")
30+
set(LSL_FETCH_REF "v1.17.0" CACHE STRING "liblsl version to fetch from GitHub")
7731

78-
# First try: Search only in hints (prefer local builds over system)
79-
find_package(LSL QUIET
80-
HINTS ${_lsl_hints}
81-
PATH_SUFFIXES ${_lsl_suffixes}
82-
NO_DEFAULT_PATH
32+
if(LSL_INSTALL_ROOT)
33+
# Use pre-installed liblsl
34+
find_package(LSL REQUIRED
35+
HINTS "${LSL_INSTALL_ROOT}"
36+
PATH_SUFFIXES share/LSL lib/cmake/LSL Frameworks/lsl.framework/Resources/CMake
8337
)
84-
85-
# Second try: Search system paths if not found in hints
86-
if(NOT LSL_FOUND)
87-
find_package(LSL QUIET
88-
PATH_SUFFIXES ${_lsl_suffixes}
89-
)
90-
endif()
91-
92-
if(LSL_FOUND)
93-
message(STATUS "Found installed liblsl: ${LSL_DIR}")
94-
set(LSL_BUILT_FROM_SOURCE FALSE)
95-
include("${LSL_DIR}/LSLCMake.cmake")
96-
elseif(LSL_FETCH_IF_MISSING)
97-
# Priority 4: Fetch from GitHub
98-
message(STATUS "liblsl not found locally, fetching ${LSL_FETCH_REF} from GitHub...")
99-
include(FetchContent)
100-
FetchContent_Declare(liblsl
101-
GIT_REPOSITORY https://github.com/sccn/liblsl.git
102-
GIT_TAG ${LSL_FETCH_REF}
103-
GIT_SHALLOW ON
104-
EXCLUDE_FROM_ALL
105-
)
106-
set(LSL_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
107-
set(LSL_BUILD_TESTING OFF CACHE BOOL "" FORCE)
108-
FetchContent_MakeAvailable(liblsl)
109-
if(NOT TARGET LSL::lsl)
110-
add_library(LSL::lsl ALIAS lsl)
111-
endif()
112-
set(LSL_BUILT_FROM_SOURCE TRUE)
113-
include("${liblsl_SOURCE_DIR}/cmake/LSLCMake.cmake")
114-
message(STATUS "liblsl fetched and configured")
115-
else()
116-
message(FATAL_ERROR
117-
"liblsl not found. Options:\n"
118-
" 1. Set LSL_SOURCE_DIR to liblsl source directory\n"
119-
" 2. Set LSL_INSTALL_ROOT to installed liblsl location\n"
120-
" 3. Install liblsl system-wide\n"
121-
" 4. Enable LSL_FETCH_IF_MISSING=ON to auto-fetch from GitHub"
122-
)
38+
message(STATUS "Using installed liblsl: ${LSL_DIR}")
39+
include("${LSL_DIR}/LSLCMake.cmake")
40+
else()
41+
# Fetch liblsl from GitHub
42+
message(STATUS "Fetching liblsl ${LSL_FETCH_REF} from GitHub...")
43+
include(FetchContent)
44+
set(LSL_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
45+
set(LSL_BUILD_TESTING OFF CACHE BOOL "" FORCE)
46+
FetchContent_Declare(liblsl
47+
GIT_REPOSITORY https://github.com/sccn/liblsl.git
48+
GIT_TAG ${LSL_FETCH_REF}
49+
GIT_SHALLOW ON
50+
EXCLUDE_FROM_ALL
51+
)
52+
FetchContent_MakeAvailable(liblsl)
53+
if(NOT TARGET LSL::lsl)
54+
add_library(LSL::lsl ALIAS lsl)
12355
endif()
56+
include("${liblsl_SOURCE_DIR}/cmake/LSLCMake.cmake")
12457
endif()
12558

12659
# =============================================================================

0 commit comments

Comments
 (0)