Skip to content

Commit 75386be

Browse files
committed
Re-add LSL_BUILD_EXAMPLES option
Add an opt-in LSL_BUILD_EXAMPLES option (default OFF) to build the examples alongside liblsl. Examples can also still be configured as a standalone project to test the installed CMake package. In standalone mode, the examples use find_package(LSL) and install their targets; when included in the liblsl build, they link directly to the existing LSL::lsl target. The option was added in 70cc090 and removed in 5758c64 because the examples relied on in-tree artifacts, which could mask installation issues.
1 parent 42118f8 commit 75386be

3 files changed

Lines changed: 49 additions & 37 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ if(LSL_UNITTESTS AND NOT IOS)
3232
add_subdirectory(testing)
3333
endif()
3434

35+
if(LSL_BUILD_EXAMPLES)
36+
add_subdirectory(examples)
37+
endif()
38+
3539
# Config for packaging
3640
include(cmake/LSLCMake.cmake)
3741
LSL_get_target_arch()

‎cmake/ProjectOptions.cmake‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ option(LSL_LEGACY_CPP_ABI "Build legacy C++ ABI into lsl-static" OFF)
1111
option(LSL_OPTIMIZATIONS "Enable some more compiler optimizations" ON)
1212
option(LSL_BUNDLED_BOOST "Use the bundled Boost by default" ON)
1313
option(LSL_FETCH_PUGIXML "Fetch pugixml via FetchContent instead of using system package" ON)
14+
option(LSL_BUILD_EXAMPLES "Build example programs in examples/" OFF)
1415
cmake_dependent_option(LSL_TOOLS "Build some experimental tools for in-depth tests" OFF "CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR" OFF)
1516
cmake_dependent_option(LSL_UNITTESTS "Build LSL library unit tests" OFF "CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR" OFF)
1617
cmake_dependent_option(LSL_INSTALL "Generate install targets" ON "CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR" OFF)

‎examples/CMakeLists.txt‎

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,40 @@ project(lslexamples
33
LANGUAGES C CXX
44
VERSION 0.2.0)
55

6-
include(GNUInstallDirs)
6+
if(PROJECT_IS_TOP_LEVEL)
7+
include(GNUInstallDirs)
78

8-
set(LSL_SEARCH_PATHS
9-
${LSL_INSTALL_ROOT}
10-
"${CMAKE_CURRENT_LIST_DIR}/../install" # GHA scripts default install directory
11-
"${CMAKE_CURRENT_LIST_DIR}/../cmake-build-release/install" # CLion default if using -DCMAKE_INSTALL_PREFIX=install
12-
)
13-
if(APPLE)
14-
# Also search in a Frameworks subdirectory for each path
15-
foreach(p IN LISTS LSL_SEARCH_PATHS)
16-
if(p)
17-
list(APPEND LSL_SEARCH_PATHS "${p}/Frameworks")
18-
endif()
19-
endforeach()
20-
else()
21-
# Add MSVC-specific paths if not on Apple
22-
list(APPEND LSL_SEARCH_PATHS
23-
"${CMAKE_CURRENT_LIST_DIR}/../cmake-build-release-visual-studio/install" # CLion default if using VS compiler
24-
"${CMAKE_CURRENT_LIST_DIR}/../out/build/x64-Release/install" # MSVC default if using -DCMAKE_INSTALL_PREFIX=install
9+
set(LSL_SEARCH_PATHS
10+
${LSL_INSTALL_ROOT}
11+
"${CMAKE_CURRENT_LIST_DIR}/../install" # GHA scripts default install directory
12+
"${CMAKE_CURRENT_LIST_DIR}/../cmake-build-release/install" # CLion default if using -DCMAKE_INSTALL_PREFIX=install
2513
)
26-
endif()
14+
if(APPLE)
15+
# Also search in a Frameworks subdirectory for each path
16+
foreach(p IN LISTS LSL_SEARCH_PATHS)
17+
if(p)
18+
list(APPEND LSL_SEARCH_PATHS "${p}/Frameworks")
19+
endif()
20+
endforeach()
21+
else()
22+
# Add MSVC-specific paths if not on Apple
23+
list(APPEND LSL_SEARCH_PATHS
24+
"${CMAKE_CURRENT_LIST_DIR}/../cmake-build-release-visual-studio/install" # CLion default if using VS compiler
25+
"${CMAKE_CURRENT_LIST_DIR}/../out/build/x64-Release/install" # MSVC default if using -DCMAKE_INSTALL_PREFIX=install
26+
)
27+
endif()
2728

28-
find_package(LSL REQUIRED
29-
HINTS ${LSL_SEARCH_PATHS}
30-
PATH_SUFFIXES share/LSL
31-
)
32-
get_filename_component(LSL_PATH ${LSL_CONFIG} DIRECTORY)
33-
message(STATUS "Found LSL lib in ${LSL_PATH}")
29+
find_package(LSL REQUIRED
30+
HINTS ${LSL_SEARCH_PATHS}
31+
PATH_SUFFIXES share/LSL
32+
)
33+
get_filename_component(LSL_PATH ${LSL_CONFIG} DIRECTORY)
34+
message(STATUS "Found LSL lib in ${LSL_PATH}")
3435

35-
# Include the LSLCMake.cmake file, just for testing.
36-
# This doesn't do much for us now that we don't use installLSLApp() anymore.
37-
include("${LSL_PATH}/LSLCMake.cmake")
36+
# Include the LSLCMake.cmake file, just for testing.
37+
# This doesn't do much for us now that we don't use installLSLApp() anymore.
38+
include("${LSL_PATH}/LSLCMake.cmake")
39+
endif()
3840

3941
# convenience function to add an example file
4042
# this creates a target, links the necessary libraries and
@@ -65,10 +67,12 @@ function(addlslexample name extension)
6567
# )
6668
# endif()
6769

68-
install(TARGETS ${name}
69-
COMPONENT ${PROJECT_NAME}
70-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
71-
)
70+
if(PROJECT_IS_TOP_LEVEL)
71+
install(TARGETS ${name}
72+
COMPONENT ${PROJECT_NAME}
73+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
74+
)
75+
endif()
7276
endfunction()
7377

7478
find_package(Threads)
@@ -107,9 +111,12 @@ if(WIN32)
107111
$<TARGET_FILE_DIR:HandleMetaData>
108112
COMMENT "Copying lsl.dll to examples build directory"
109113
)
110-
# Install the lsl.dll to the same directory as the executable.
111-
install(
112-
CODE "file(INSTALL DESTINATION \"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}\" TYPE SHARED_LIBRARY FILES \"$<TARGET_FILE:LSL::lsl>\")"
113-
COMPONENT ${PROJECT_NAME}
114-
)
114+
115+
if(PROJECT_IS_TOP_LEVEL)
116+
# Install the lsl.dll to the same directory as the executable.
117+
install(
118+
CODE "file(INSTALL DESTINATION \"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}\" TYPE SHARED_LIBRARY FILES \"$<TARGET_FILE:LSL::lsl>\")"
119+
COMPONENT ${PROJECT_NAME}
120+
)
121+
endif()
115122
endif()

0 commit comments

Comments
 (0)