Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ if(LSL_UNITTESTS AND NOT IOS)
add_subdirectory(testing)
endif()

if(LSL_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

# Config for packaging
include(cmake/LSLCMake.cmake)
LSL_get_target_arch()
Expand Down
1 change: 1 addition & 0 deletions cmake/ProjectOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ option(LSL_LEGACY_CPP_ABI "Build legacy C++ ABI into lsl-static" OFF)
option(LSL_OPTIMIZATIONS "Enable some more compiler optimizations" ON)
option(LSL_BUNDLED_BOOST "Use the bundled Boost by default" ON)
option(LSL_FETCH_PUGIXML "Fetch pugixml via FetchContent instead of using system package" ON)
option(LSL_BUILD_EXAMPLES "Build example programs in examples/" OFF)
cmake_dependent_option(LSL_TOOLS "Build some experimental tools for in-depth tests" OFF "CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR" OFF)
cmake_dependent_option(LSL_UNITTESTS "Build LSL library unit tests" OFF "CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR" OFF)
cmake_dependent_option(LSL_INSTALL "Generate install targets" ON "CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR" OFF)
Expand Down
81 changes: 44 additions & 37 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,40 @@ project(lslexamples
LANGUAGES C CXX
VERSION 0.2.0)

include(GNUInstallDirs)
if(PROJECT_IS_TOP_LEVEL)
include(GNUInstallDirs)

set(LSL_SEARCH_PATHS
${LSL_INSTALL_ROOT}
"${CMAKE_CURRENT_LIST_DIR}/../install" # GHA scripts default install directory
"${CMAKE_CURRENT_LIST_DIR}/../cmake-build-release/install" # CLion default if using -DCMAKE_INSTALL_PREFIX=install
)
if(APPLE)
# Also search in a Frameworks subdirectory for each path
foreach(p IN LISTS LSL_SEARCH_PATHS)
if(p)
list(APPEND LSL_SEARCH_PATHS "${p}/Frameworks")
endif()
endforeach()
else()
# Add MSVC-specific paths if not on Apple
list(APPEND LSL_SEARCH_PATHS
"${CMAKE_CURRENT_LIST_DIR}/../cmake-build-release-visual-studio/install" # CLion default if using VS compiler
"${CMAKE_CURRENT_LIST_DIR}/../out/build/x64-Release/install" # MSVC default if using -DCMAKE_INSTALL_PREFIX=install
set(LSL_SEARCH_PATHS
${LSL_INSTALL_ROOT}
"${CMAKE_CURRENT_LIST_DIR}/../install" # GHA scripts default install directory
"${CMAKE_CURRENT_LIST_DIR}/../cmake-build-release/install" # CLion default if using -DCMAKE_INSTALL_PREFIX=install
)
endif()
if(APPLE)
# Also search in a Frameworks subdirectory for each path
foreach(p IN LISTS LSL_SEARCH_PATHS)
if(p)
list(APPEND LSL_SEARCH_PATHS "${p}/Frameworks")
endif()
endforeach()
else()
# Add MSVC-specific paths if not on Apple
list(APPEND LSL_SEARCH_PATHS
"${CMAKE_CURRENT_LIST_DIR}/../cmake-build-release-visual-studio/install" # CLion default if using VS compiler
"${CMAKE_CURRENT_LIST_DIR}/../out/build/x64-Release/install" # MSVC default if using -DCMAKE_INSTALL_PREFIX=install
)
endif()

find_package(LSL REQUIRED
HINTS ${LSL_SEARCH_PATHS}
PATH_SUFFIXES share/LSL
)
get_filename_component(LSL_PATH ${LSL_CONFIG} DIRECTORY)
message(STATUS "Found LSL lib in ${LSL_PATH}")
find_package(LSL REQUIRED
HINTS ${LSL_SEARCH_PATHS}
PATH_SUFFIXES share/LSL
)
get_filename_component(LSL_PATH ${LSL_CONFIG} DIRECTORY)
message(STATUS "Found LSL lib in ${LSL_PATH}")

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

# convenience function to add an example file
# this creates a target, links the necessary libraries and
Expand Down Expand Up @@ -65,10 +67,12 @@ function(addlslexample name extension)
# )
# endif()

install(TARGETS ${name}
COMPONENT ${PROJECT_NAME}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
if(PROJECT_IS_TOP_LEVEL)
install(TARGETS ${name}
COMPONENT ${PROJECT_NAME}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
endif()
endfunction()

find_package(Threads)
Expand Down Expand Up @@ -107,9 +111,12 @@ if(WIN32)
$<TARGET_FILE_DIR:HandleMetaData>
COMMENT "Copying lsl.dll to examples build directory"
)
# Install the lsl.dll to the same directory as the executable.
install(
CODE "file(INSTALL DESTINATION \"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}\" TYPE SHARED_LIBRARY FILES \"$<TARGET_FILE:LSL::lsl>\")"
COMPONENT ${PROJECT_NAME}
)

if(PROJECT_IS_TOP_LEVEL)
# Install the lsl.dll to the same directory as the executable.
install(
CODE "file(INSTALL DESTINATION \"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}\" TYPE SHARED_LIBRARY FILES \"$<TARGET_FILE:LSL::lsl>\")"
COMPONENT ${PROJECT_NAME}
)
endif()
endif()
Loading